private void LoadOrder_Material()
 {
     try
     {
         int OrderId = Utils.CIntDef(ddlOrder.SelectedValue);
         List <OrderMaterial> list = new List <OrderMaterial>();
         var listOrderDetail       = _OrderDetailRepo.GetByOrderId(OrderId);
         foreach (var item in listOrderDetail)
         {
             if (Utils.CIntDef(item.PRODUCT_DETAIL_SIZE_ID) == -1)
             {
                 var listProductDetail_Material = _ProductDetailMaterialRepo.GetByProductDetailId(Utils.CIntDef(item.PRODUCT_DETAIL_ID));
                 foreach (var item2 in listProductDetail_Material)
                 {
                     var orderMaterial = list.Find(n => n.MATERIAL_ID == item2.MATERIAL_ID);
                     if (orderMaterial != null)
                     {
                         decimal quantity = Utils.CDecDef(item.QUANTITY) * Utils.CDecDef(item2.QUANTITY);
                         orderMaterial.QUANTITY = orderMaterial.QUANTITY + quantity;
                     }
                     else
                     {
                         orderMaterial             = new OrderMaterial();
                         orderMaterial.MATERIAL_ID = Utils.CIntDef(item2.MATERIAL_ID);
                         orderMaterial.QUANTITY    = Utils.CDecDef(item.QUANTITY) * Utils.CDecDef(item2.QUANTITY);
                         list.Add(orderMaterial);
                     }
                 }
             }
             else
             {
                 var listProductDetail_Material = _ProductDetailMaterialRepo.GetByProductDetailId(Utils.CIntDef(item.PRODUCT_DETAIL_ID), Utils.CIntDef(item.PRODUCT_DETAIL_SIZE_ID));
                 foreach (var item2 in listProductDetail_Material)
                 {
                     var orderMaterial = list.Find(n => n.MATERIAL_ID == item2.MATERIAL_ID);
                     if (orderMaterial != null)
                     {
                         decimal quantity = Utils.CDecDef(item.QUANTITY) * Utils.CDecDef(item2.QUANTITY);
                         orderMaterial.QUANTITY = orderMaterial.QUANTITY + quantity;
                     }
                     else
                     {
                         orderMaterial             = new OrderMaterial();
                         orderMaterial.MATERIAL_ID = Utils.CIntDef(item2.MATERIAL_ID);
                         orderMaterial.QUANTITY    = Utils.CDecDef(item.QUANTITY) * Utils.CDecDef(item2.QUANTITY);
                         list.Add(orderMaterial);
                     }
                 }
             }
         }
         HttpContext.Current.Session["listOrderMaterial"] = list;
         ASPxGridView1_Order_Material.DataSource          = list;
         ASPxGridView1_Order_Material.DataBind();
     }
     catch //(Exception)
     {
         //throw;
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            bool isPermission = _UnitDataRepo.checkPermissionPage("nguyen-lieu-can-cho-don-hang.aspx", Utils.CIntDef(Session["groupId"]), Utils.CIntDef(Session["groupType"]));

            if (!isPermission)
            {
                Response.Write("<script>alert('Bạn không có quyền truy cập vào trang này');location.href='trang-chu.aspx';</script>");
            }
            id = Utils.CIntDef(Request.QueryString["id"]);
            if (!IsPostBack)
            {
                LoadOrder();
                LoadOrder_Material();
            }
            else
            {
                ASPxGridView1_Order_Material.DataSource = HttpContext.Current.Session["listOrderMaterial"];
                ASPxGridView1_Order_Material.DataBind();
            }
        }