两种状态显示处理. enum , Linq AsEnumerable

1.ENUM

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

    GridViewRow row = e.Row;

    if (e.Row.RowIndex < 0)

    {

        return;

    }

    string statusNum = row.Cells[5].Text;

    int tempStatusNum = int.Parse(statusNum);

    ShipStatus temp2 = (ShipStatus)tempStatusNum;

    row.Cells[5].Text = temp2.ToString();

} 

 

enum ShipStatus

{

    初始 = 0, 审核通过 = 1, 已发送 = 2

}

 

2. AsEnumerable 思路,先把所有状态 放到一张临时表,再进行连接.

     var dt = DataTableA

     var dtstatus = DtStatus();

            var res = from a in dt.AsEnumerable()

                      join s in DtStatus().AsEnumerable() on a["status"] equals s["statusEN"] into dtjoin

                      from dj in dtjoin.DefaultIfEmpty()

                      select new

                      {

                          orderCode = a["orderCode"],

                          status = dj["statusCN"]

                          //...................

                      };



            var dtres = Functions.EnumerableToDataTable(res);



            GVorderStatus.DataSource = dtres;

            

        public DataTable DtStatus()

        {

            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("statusEN", typeof(System.String)));

            dt.Columns.Add(new DataColumn("statusCN", typeof(System.String)));



            dt.Rows.Add("WMS_ARRIVAL", "SS");

            dt.Rows.Add("WMS_RECEIVED", "AA");

            dt.Rows.Add("WMS_REJECT", "FF");

            dt.Rows.Add("WMS_FAILED", "HH");

             //.......................

            return dt;

        }    

 

你可能感兴趣的:(LINQ)