private void bwLoadSupplier_DoWork(object sender, DoWorkEventArgs e)
 {
     outsoleSupplierList    = OutsoleSuppliersController.Select();
     orderList              = OrdersController.Select();
     outsoleRawMaterialList = OutsoleRawMaterialController.Select();
     outsoleMaterialList    = OutsoleMaterialController.Select();
 }
 private void MiCancel_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show(string.Format("Confirm Cancel ?\nBạn có chắc muốn hủy ?"), this.Title, MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK)
     {
         return;
     }
     try
     {
         var confirmListByPO = btnConfirm.Tag as List <OutsoleMaterialConfirmWorkingCartModel>;
         if (confirmListByPO == null)
         {
             return;
         }
         confirmListByPO.ForEach(f => f.IsConfirm = false);
         foreach (var model in confirmListByPO)
         {
             OutsoleMaterialController.UpdateOSMaterial(model, 1);
         }
         loadSizeNoList(confirmListByPO);
         txtIndexNo.Focus();
         txtIndexNo.SelectAll();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
 }
 private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
 {
     outsoleReleaseMaterialAllList = OutsoleReleaseMaterialController.Select(reportId, null);
     orderAllList           = OrdersController.SelectByOutsoleReleaseMaterial(reportId);
     outsoleMaterialAllList = OutsoleMaterialController.SelectByOutsoleReleaseMaterial(reportId);
     sizeRunAllList         = SizeRunController.SelectByOutsoleReleaseMaterial(reportId);
 }
 private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
 {
     outsoleSupplierList             = OutsoleSuppliersController.Select();
     outsoleMaterialList             = OutsoleMaterialController.Select(productNo);
     sizeRunList                     = SizeRunController.Select(productNo);
     outsoleRawMaterialList          = OutsoleRawMaterialController.Select(productNo);
     outsoleMaterialRackPositionList = OutsoleMaterialRackPositionController.Select(productNo);
 }
Exemplo n.º 5
0
 private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
 {
     sizeRunList               = SizeRunController.Select(productNo);
     outsoleMaterialList       = OutsoleMaterialController.Select(productNo);
     outsoleSupplierList       = OutsoleSuppliersController.Select();
     outsoleMaterialDetailList = OutsoleMaterialDetailController.Select(productNo);
     orderSearch               = OrdersController.SelectTop1(productNo);
     accountList               = AccountController.SelectAccount();
 }
Exemplo n.º 6
0
        private void bwAddMore_DoWork(object sender, DoWorkEventArgs e)
        {
            string productNo = "";

            txtProductNo.Dispatcher.Invoke((Action)(() =>
            {
                productNo = txtProductNo.Text;
            }));
            orderSearch       = OrdersController.SelectTop1(productNo);
            sizeRunSearchList = SizeRunController.Select(productNo);
            outsoleReleaseMaterialSearchList = OutsoleReleaseMaterialController.Select(productNo);
            outsoleMaterialSearchList        = OutsoleMaterialController.Select(productNo);
        }
        private void bwReport_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleRawMaterialList = OutsoleRawMaterialController.Select();
            outsoleMaterialList    = OutsoleMaterialController.SelectByOutsoleRawMaterial();
            sizeRunList            = SizeRunController.SelectByOutsoleRawMaterial();
            outsoleSupplierList    = OutsoleSuppliersController.Select();
            ordersList             = OrdersController.SelectByOutsoleRawMaterial();

            DataTable dt = new OutsoleDeliveryDataSet().Tables["OutsoleDeliveryTable"];

            List <String> productNoList = outsoleRawMaterialList.Select(r => r.ProductNo).Distinct().ToList();

            foreach (string productNo in productNoList)
            {
                OrdersModel order = ordersList.Where(o => o.ProductNo == productNo).FirstOrDefault();
                List <OutsoleRawMaterialModel> outsoleRawMaterialOfProductNoList = outsoleRawMaterialList.Where(o => o.ProductNo == productNo).ToList();
                List <SizeRunModel>            sizeRunOfProductNoList            = sizeRunList.Where(s => s.ProductNo == productNo).ToList();
                List <OutsoleMaterialModel>    outsoleMaterialOfProductNoList    = outsoleMaterialList.Where(o => o.ProductNo == productNo).ToList();
                foreach (OutsoleRawMaterialModel outsoleRawMaterial in outsoleRawMaterialOfProductNoList)
                {
                    DateTime etd    = outsoleRawMaterial.ETD.Date;
                    bool     isFull = OutsoleRawMaterialController.IsFull(sizeRunOfProductNoList, new List <OutsoleRawMaterialModel>()
                    {
                        outsoleRawMaterial,
                    }, outsoleMaterialOfProductNoList);
                    if (etd != new DateTime(2000, 1, 1) && etd == dateSearch.Date && isFull == false)
                    {
                        DataRow dr = dt.NewRow();
                        dr["ProductNo"] = productNo;
                        if (order != null)
                        {
                            dr["ArticleNo"]   = order.ArticleNo;
                            dr["OutsoleCode"] = order.OutsoleCode;
                            dr["Quantity"]    = order.Quantity;
                            dr["ETD"]         = order.ETD;
                        }
                        dr["SupplierETD"] = etd;
                        dr["Remarks"]     = sizeRunOfProductNoList.Sum(s => (s.Quantity - outsoleMaterialOfProductNoList.Where(o => o.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId && o.SizeNo == s.SizeNo).Sum(o => (o.Quantity - o.QuantityReject)))).ToString();
                        OutsoleSuppliersModel outsoleSupplier = outsoleSupplierList.Where(o => o.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId).FirstOrDefault();
                        if (outsoleSupplier != null)
                        {
                            dr["Supplier"] = outsoleSupplier.Name;
                        }

                        dt.Rows.Add(dr);
                    }
                }
            }
            e.Result = dt;
        }
        private void bwInsert_DoWork(object sender, DoWorkEventArgs e)
        {
            // Delete RackPosition
            foreach (var rackModelDetele in outsoleMaterialRackPositionToDeleteList)
            {
                OutsoleMaterialRackPositionController.Delete(rackModelDetele);
            }

            // Update RackPosition
            foreach (var rackModelInsert in outsoleMaterialRackPositionToInsertList)
            {
                OutsoleMaterialRackPositionController.Insert(rackModelInsert);
            }

            foreach (OutsoleRawMaterialModel model in outsoleRawMaterialToInsertList)
            {
                OutsoleRawMaterialController.UpdateActualDate(model);
            }
            foreach (OutsoleMaterialModel model in outsoleMaterialToInsertList)
            {
                var osMaterialDB = OutsoleMaterialController.Select(model.ProductNo).Where(w => w.SizeNo == model.SizeNo && w.OutsoleSupplierId == model.OutsoleSupplierId).FirstOrDefault();
                // Insert
                if (osMaterialDB == null)
                {
                    OutsoleMaterialController.Insert(model);
                }

                // Update
                else
                {
                    // Update Quantity
                    if (osMaterialDB.Quantity != model.Quantity)
                    {
                        OutsoleMaterialController.Update(model, false, true, false);
                    }

                    // Update Reject
                    if (osMaterialDB.QuantityReject != model.QuantityReject)
                    {
                        OutsoleMaterialController.Update(model, true, false, false);
                    }

                    // Update Reject Assembly
                    if (osMaterialDB.RejectAssembly != model.RejectAssembly)
                    {
                        OutsoleMaterialController.Update(model, true, false, true);
                    }
                }
            }
        }
Exemplo n.º 9
0
 private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
 {
     if (releaseTo == ERelease.ReleaseToOutsole)
     {
         outsoleReleaseMaterialAllList = OutsoleReleaseMaterialController.Select(reportId, null);
         orderAllList           = OrdersController.SelectByOutsoleReleaseMaterial(reportId);
         outsoleMaterialAllList = OutsoleMaterialController.SelectByOutsoleReleaseMaterial(reportId);
         sizeRunAllList         = SizeRunController.SelectByOutsoleReleaseMaterial(reportId);
     }
     else
     {
         outsoleReleaseMaterialAllList = OutsoleReleaseWHInspectionController.Select(reportId, null);
         orderAllList           = OrdersController.SelectByOutsoleReleaseMaterialToWHInspection(reportId);
         outsoleMaterialAllList = OutsoleMaterialController.SelectByOutsoleReleaseMaterialToWHInspection(reportId);
         sizeRunAllList         = SizeRunController.SelectByOutsoleReleaseMaterialToWHInspection(reportId);
     }
 }
Exemplo n.º 10
0
        private void bwUpdateOutsoleMaterial_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleMaterialRejectUpdateList = new List <OutsoleMaterialModel>();
            var outsoleMaterialDetailAferInsertList = OutsoleMaterialDetailController.Select(productNo).Where(w => w.OutsoleSupplierId == supplierClicked.OutsoleSupplierId).ToList();
            var sizeNoList = outsoleMaterialDetailAferInsertList.Select(s => s.SizeNo).Distinct().ToList();

            foreach (var sizeNo in sizeNoList)
            {
                var firstModel = outsoleMaterialDetailAferInsertList.FirstOrDefault();
                var outsoleMaterialUpdateReject = new OutsoleMaterialModel()
                {
                    ProductNo         = firstModel.ProductNo,
                    OutsoleSupplierId = firstModel.OutsoleSupplierId,
                    SizeNo            = sizeNo,
                    QuantityReject    = outsoleMaterialDetailAferInsertList.Where(w => w.SizeNo == sizeNo).Sum(s => s.Reject),
                };
                outsoleMaterialRejectUpdateList.Add(outsoleMaterialUpdateReject);
            }
            foreach (var updateModel in outsoleMaterialRejectUpdateList)
            {
                OutsoleMaterialController.UpdateRejectFromOutsoleMaterialDetail(updateModel);
            }

            // Update Outsole RawMaterial. If Reject > 0 => Remove Actual Date
            var POAndSupplierHasRejectList = outsoleMaterialRejectUpdateList.Where(w => w.QuantityReject > 0).Select(s => new { ProductNo = s.ProductNo, OutsoleSupplierId = s.OutsoleSupplierId }).Distinct().ToList();

            foreach (var p in POAndSupplierHasRejectList)
            {
                var updateModel = new OutsoleRawMaterialModel()
                {
                    ProductNo         = p.ProductNo,
                    OutsoleSupplierId = p.OutsoleSupplierId,
                    ActualDate        = dtDefault
                };
                OutsoleRawMaterialController.UpdateActualDate(updateModel);
            }
        }
        private void BwSearch_DoWork(object sender, DoWorkEventArgs e)
        {
            var searchWhat = e.Argument as String;

            try
            {
                if (doMode == DoMode.Confirm)
                {
                    osmConfirmList = OutsoleMaterialController.GetOSConfirmByIndexNo(int.Parse(searchWhat));
                }
                else if (doMode == DoMode.Release)
                {
                    osmConfirmList = OutsoleMaterialController.GetOSConfirmByPO(searchWhat);
                    sizeRunList    = SizeRunController.Select(searchWhat);
                }
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                }));
            }
        }
        private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleMaterialList        = OutsoleMaterialController.Select();
            outsoleReleaseMaterialList = OutsoleReleaseMaterialController.SelectByOutsoleMaterial();
            outsoleOutputList          = OutsoleOutputController.SelectByAssemblyMaster();
            outsoleMasterList          = OutsoleMasterController.Select();
            orderList           = OrdersController.Select();
            outsoleSupplierList = OutsoleSuppliersController.Select();
            assemblyReleaseList = AssemblyReleaseController.SelectByAssemblyMaster();
            sizeRunList         = SizeRunController.SelectIsEnable();

            inventoryByOSCodeList = ReportController.InventoryByOutsoleCode();
            inventoryByOSLineList = ReportController.InventoryByOutsoleLine();

            foreach (var inven in inventoryByOSCodeList)
            {
                inven.ProductNoList = orderList.Where(w => w.OutsoleCode == inven.OutsoleCode).Select(s => s.ProductNo).Distinct().ToList();
            }
            foreach (var inven in inventoryByOSLineList)
            {
                inven.ProductNoList = outsoleMasterList.Where(w => w.OutsoleLine == inven.OutsoleLine).Select(s => s.ProductNo).Distinct().ToList();
                inven.OutsoleCode   = inven.OutsoleLine;
            }
        }
        void threadLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            //outsoleRawMaterialList = OutsoleRawMaterialController.Select();
            outsoleRawMaterialList = OutsoleRawMaterialController.SelectFull(etdStartSelect, etdEndSelect);
            outsoleMaterialList    = OutsoleMaterialController.SelectByOutsoleRawMaterialFull(etdStartSelect, etdEndSelect);
            sizeRunList            = SizeRunController.SelectByOutsoleRawMaterialFull(etdStartSelect, etdEndSelect);
            outsoleSupplierList    = OutsoleSuppliersController.Select();
            orderList        = OrdersController.SelectByOutsoleRawMaterialFull(etdStartSelect, etdEndSelect);
            sewingMasterList = SewingMasterController.SelectFull(etdStartSelect, etdEndSelect);

            List <String> productNoList = outsoleRawMaterialList.Select(r => r.ProductNo).Distinct().ToList();

            foreach (string productNo in productNoList)
            {
                OrdersModel order = orderList.FirstOrDefault(f => f.ProductNo == productNo);
                List <OutsoleRawMaterialModel> outsoleRawMaterialList_D1 = outsoleRawMaterialList.Where(o => o.ProductNo == productNo).ToList();
                List <SizeRunModel>            sizeRunList_D1            = sizeRunList.Where(s => s.ProductNo == productNo).ToList();
                List <OutsoleMaterialModel>    outsoleMaterialList_D1    = outsoleMaterialList.Where(o => o.ProductNo == productNo).ToList();
                var sewingMasterList_D1 = sewingMasterList.Where(w => w.ProductNo == productNo).ToList();
                foreach (OutsoleRawMaterialModel outsoleRawMaterial in outsoleRawMaterialList_D1)
                {
                    // 108a-2279
                    //bool isFull = OutsoleRawMaterialController.IsFull(sizeRunList_D1, new List<OutsoleRawMaterialModel>() { outsoleRawMaterial, }, outsoleMaterialList_D1);
                    if (
                        //isFull == false &&
                        outsoleRawMaterial.ETD.Date != dtDefault
                        //&& outsoleRawMaterial.ActualDate.Date == dtDefault
                        )
                    {
                        OutsoleDeliveryStatusViewModel outsoleDeliveryStatusView = new OutsoleDeliveryStatusViewModel();
                        outsoleDeliveryStatusView.ProductNo = productNo;
                        if (order != null)
                        {
                            outsoleDeliveryStatusView.Country     = order.Country;
                            outsoleDeliveryStatusView.ShoeName    = order.ShoeName;
                            outsoleDeliveryStatusView.ArticleNo   = order.ArticleNo;
                            outsoleDeliveryStatusView.OutsoleCode = order.OutsoleCode;
                            outsoleDeliveryStatusView.Quantity    = order.Quantity;
                            outsoleDeliveryStatusView.ETD         = order.ETD;
                        }

                        OutsoleSuppliersModel outsoleSupplier = outsoleSupplierList.FirstOrDefault(f => f.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId);
                        if (outsoleSupplier != null)
                        {
                            outsoleDeliveryStatusView.Supplier = outsoleSupplier.Name;
                        }

                        outsoleDeliveryStatusView.SupplierETD = outsoleRawMaterial.ETD;
                        //outsoleDeliveryStatusView.Actual = sizeRunList_D1.Sum(s => (s.Quantity - outsoleMaterialList_D1.Where(o => o.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId && o.SizeNo == s.SizeNo).Sum(o => (o.Quantity - o.QuantityReject)))).ToString();

                        //int actualQty = sizeRunList_D1.Sum(s => (outsoleMaterialList_D1.Where(o => o.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId && o.SizeNo == s.SizeNo).Sum(o => (o.Quantity - o.QuantityReject))));
                        //int actualQty = outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId).Sum(s => s.Quantity - s.QuantityReject);
                        int actualQty = outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId).Sum(s => s.Quantity);
                        if (actualQty > 0)
                        {
                            outsoleDeliveryStatusView.ActualQuantity = actualQty.ToString();
                        }

                        int rejectQty = outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId).Sum(s => s.QuantityReject);
                        if (rejectQty > 0)
                        {
                            outsoleDeliveryStatusView.RejectQuantity = rejectQty.ToString();
                        }

                        outsoleDeliveryStatusView.IsFinished = true;
                        int balance = order.Quantity - actualQty + rejectQty;
                        if (balance > 0)
                        {
                            //outsoleDeliveryStatusView.Balance = balance.ToString();
                            outsoleDeliveryStatusView.IsFinished = false;
                        }

                        if (outsoleRawMaterial.ActualDate != dtDefault)
                        {
                            outsoleDeliveryStatusView.Actual = string.Format("{0:M/d}", outsoleRawMaterial.ActualDate);
                        }

                        outsoleDeliveryStatusView.SewingStartDate = dtDefault;
                        var sewingMasterModel = sewingMasterList_D1.FirstOrDefault();
                        if (sewingMasterModel != null)
                        {
                            outsoleDeliveryStatusView.SewingStartDate = sewingMasterModel.SewingStartDate;
                        }

                        outsoleDeliveryStatusViewList.Add(outsoleDeliveryStatusView);
                    }
                }
            }
        }
Exemplo n.º 14
0
        private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleMaterialList        = OutsoleMaterialController.Select();
            outsoleReleaseMaterialList = OutsoleReleaseMaterialController.SelectByOutsoleMaterial();
            outsoleOutputList          = OutsoleOutputController.SelectByAssemblyMaster();
            // lay ra nhung order co outsolematerial roi.
            orderList = OrdersController.SelectByOutsoleMaterial();

            outsoleSupplierList = OutsoleSuppliersController.Select();
            assemblyReleaseList = AssemblyReleaseController.SelectByAssemblyMaster();

            var outsoleWHInventoryViewList = new List <OutsoleWHInventoryViewModel>();
            // lay ra outsolecode tu orderlist(la nhung order co outsolematerial roi)
            var outsoleCodeList = orderList.Select(o => o.OutsoleCode).Distinct().ToList();

            foreach (string outsoleCode in outsoleCodeList)
            {
                var productNoList                 = orderList.Where(o => o.OutsoleCode == outsoleCode).Select(o => o.ProductNo).Distinct().ToList();
                var outsoleMaterialList_D1        = outsoleMaterialList.Where(o => productNoList.Contains(o.ProductNo)).ToList();
                var outsoleReleaseMaterialList_D1 = outsoleReleaseMaterialList.Where(o => productNoList.Contains(o.ProductNo)).ToList();
                var supplierIdList                = outsoleMaterialList_D1.Select(o => o.OutsoleSupplierId).Distinct().ToList();
                var qtyTotalList = new List <Int32>();

                var outsoleOutputList_D1   = outsoleOutputList.Where(o => productNoList.Contains(o.ProductNo) == true).ToList();
                var assemblyReleaseList_D1 = assemblyReleaseList.Where(a => productNoList.Contains(a.ProductNo) == true).ToList();

                // add Finished Outsole Column
                int qtyOutsoleTotal = 0;
                foreach (string productNo in productNoList)
                {
                    var sizeNoList             = outsoleMaterialList.Where(o => o.ProductNo == productNo).Select(o => o.SizeNo).Distinct().ToList();
                    var outsoleOutputList_D2   = outsoleOutputList_D1.Where(o => o.ProductNo == productNo).ToList();
                    var assemblyReleaseList_D2 = assemblyReleaseList_D1.Where(a => a.ProductNo == productNo).ToList();
                    foreach (string sizeNo in sizeNoList)
                    {
                        int qtyRelease = assemblyReleaseList_D2.Where(a => a.SizeNo == sizeNo).Sum(a => a.Quantity);
                        int qtyOutsole = outsoleOutputList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity) - qtyRelease;
                        qtyOutsoleTotal += qtyOutsole;
                    }
                }
                foreach (Int32 supplierId in supplierIdList)
                {
                    var outsoleMaterialList_D2 = outsoleMaterialList_D1.Where(o => o.OutsoleSupplierId == supplierId).ToList();
                    int qtyTotal = 0;
                    foreach (string productNo in productNoList)
                    {
                        var outsoleMaterialList_D3        = outsoleMaterialList_D2.Where(o => o.ProductNo == productNo).ToList();
                        var outsoleReleaseMaterialList_D3 = outsoleReleaseMaterialList_D1.Where(o => o.ProductNo == productNo).ToList();
                        var sizeNoList = outsoleMaterialList.Where(o => o.ProductNo == productNo).Select(o => o.SizeNo).Distinct().ToList();
                        foreach (string sizeNo in sizeNoList)
                        {
                            int qtyMax     = outsoleMaterialList_D3.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity - o.QuantityReject);
                            int qtyRelease = outsoleReleaseMaterialList_D3.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity);
                            int qty        = qtyMax - qtyRelease;
                            if (qty < 0)
                            {
                                qty = 0;
                            }
                            qtyTotal += qty;
                        }
                    }
                    qtyTotalList.Add(qtyTotal);
                }

                int qtyMatchTotal = 0;
                foreach (string productNo in productNoList)
                {
                    var outsoleMaterialList_D2        = outsoleMaterialList_D1.Where(o => o.ProductNo == productNo).ToList();
                    var outsoleReleaseMaterialList_D2 = outsoleReleaseMaterialList_D1.Where(o => o.ProductNo == productNo).ToList();
                    var sizeNoList = outsoleMaterialList.Where(o => o.ProductNo == productNo).Select(o => o.SizeNo).Distinct().ToList();
                    foreach (string sizeNo in sizeNoList)
                    {
                        int qtyMin     = outsoleMaterialList_D2.Where(o => o.SizeNo == sizeNo).Select(o => o.Quantity - o.QuantityReject).Min();
                        int qtyRelease = outsoleReleaseMaterialList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity);
                        int qtyMatch   = qtyMin - qtyRelease;
                        if (qtyMatch < 0)
                        {
                            qtyMatch = 0;
                        }
                        qtyMatchTotal += qtyMatch;
                    }
                }
                var outsoleWHInventoryView = new OutsoleWHInventoryViewModel
                {
                    OutsoleCode             = outsoleCode,
                    ProductNoList           = productNoList,
                    SupplierIdList          = supplierIdList,
                    Quantity                = qtyTotalList.Max(),
                    Matching                = qtyMatchTotal,
                    FinishedOutsoleQuantity = qtyOutsoleTotal,
                };
                if (outsoleWHInventoryView.Quantity != 0)
                {
                    outsoleWHInventoryViewList.Add(outsoleWHInventoryView);
                }
            }

            e.Result = outsoleWHInventoryViewList;
        }
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleSupplierList = OutsoleSuppliersController.Select();
            sizeRunList         = SizeRunController.SelectByOutsoleRawMaterial();
            sewingMasterList    = SewingMasterController.Select();
            outsoleMaterialList = OutsoleMaterialController.Select().Where(w => productNoList.Contains(w.ProductNo) && w.OutsoleSupplierId == supplierID).ToList();

            DataTable dt = new DataTable();

            Dispatcher.Invoke(new Action(() =>
            {
                dt.Columns.Add("ProductNo", typeof(String));
                DataGridTextColumn columnProductNo = new DataGridTextColumn();
                columnProductNo.Header             = "PO No.";

                //Style
                Style styleColumnProductNo = new Style(typeof(DataGridCell));

                Setter setterColumnProductNoForeground   = new Setter();
                setterColumnProductNoForeground.Property = DataGridCell.ForegroundProperty;
                setterColumnProductNoForeground.Value    = Brushes.Black;
                styleColumnProductNo.Setters.Add(setterColumnProductNoForeground);

                Setter setterColumnProductNoBackground   = new Setter();
                setterColumnProductNoBackground.Property = DataGridCell.BackgroundProperty;
                setterColumnProductNoBackground.Value    = new Binding("ProductNoBackground");
                styleColumnProductNo.Setters.Add(setterColumnProductNoBackground);

                columnProductNo.CellStyle = styleColumnProductNo;

                columnProductNo.Binding    = new Binding("ProductNo");
                columnProductNo.FontWeight = FontWeights.Bold;

                DataColumn columnProductNoBackground   = new DataColumn("ProductNoBackground", typeof(SolidColorBrush));
                columnProductNoBackground.DefaultValue = Brushes.Transparent;
                dt.Columns.Add(columnProductNoBackground);

                dgInventory.Columns.Add(columnProductNo);

                Binding bindingWidth1 = new Binding();
                bindingWidth1.Source  = columnProductNo;
                bindingWidth1.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1  = new ColumnDefinition();
                cd1.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1);
                gridTotal.ColumnDefinitions.Add(cd1);

                dt.Columns.Add("ArticleNo", typeof(String));
                DataGridTextColumn column1_1_1 = new DataGridTextColumn();
                column1_1_1.Header             = "Article No.";
                column1_1_1.Binding            = new Binding("ArticleNo");
                //column1_1_1.FontWeight = FontWeights.Bold;
                dgInventory.Columns.Add(column1_1_1);
                Binding bindingWidth1_1_1 = new Binding();
                bindingWidth1_1_1.Source  = column1_1_1;
                bindingWidth1_1_1.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_1_1  = new ColumnDefinition();
                cd1_1_1.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_1_1);
                gridTotal.ColumnDefinitions.Add(cd1_1_1);

                dt.Columns.Add("OrderETD", typeof(DateTime));
                DataGridTextColumn column1_1 = new DataGridTextColumn();
                column1_1.Header             = "Order EFD";
                // Style
                Style styleOrderETD = new Style(typeof(DataGridCell));
                styleOrderETD.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
                column1_1.CellStyle = styleOrderETD;

                Binding binding      = new Binding();
                binding.Path         = new PropertyPath("OrderETD");
                binding.StringFormat = "dd-MMM";
                column1_1.Binding    = binding;
                column1_1.FontWeight = FontWeights.Bold;
                dgInventory.Columns.Add(column1_1);
                Binding bindingWidth1_1 = new Binding();
                bindingWidth1_1.Source  = column1_1;
                bindingWidth1_1.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_1  = new ColumnDefinition();
                cd1_1.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_1);
                gridTotal.ColumnDefinitions.Add(cd1_1);

                dt.Columns.Add("DeliveryETD", typeof(DateTime));
                DataGridTextColumn column1_1_A = new DataGridTextColumn();
                column1_1_A.Header             = "Delivery EFD";
                Binding bindingEDTSupp         = new Binding();
                bindingEDTSupp.Path            = new PropertyPath("DeliveryETD");
                bindingEDTSupp.StringFormat    = "dd-MMM";
                column1_1_A.Binding            = bindingEDTSupp;
                column1_1_A.FontWeight         = FontWeights.Bold;

                // Style
                Style styleDeliveryETD = new Style(typeof(DataGridCell));
                styleDeliveryETD.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
                column1_1_A.CellStyle = styleDeliveryETD;

                dgInventory.Columns.Add(column1_1_A);
                Binding bindingWidth1_1_A = new Binding();
                bindingWidth1_1_A.Source  = column1_1_A;
                bindingWidth1_1_A.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_1_A  = new ColumnDefinition();
                cd1_1_A.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_1_A);
                gridTotal.ColumnDefinitions.Add(cd1_1_A);


                dt.Columns.Add("SewingStartDate", typeof(DateTime));
                DataGridTextColumn column1_1_B  = new DataGridTextColumn();
                column1_1_B.Header              = "Sewing Start";
                Binding bindingSewingStart      = new Binding();
                bindingSewingStart.Path         = new PropertyPath("SewingStartDate");
                bindingSewingStart.StringFormat = "dd-MMM";
                column1_1_B.Binding             = bindingSewingStart;
                column1_1_B.FontWeight          = FontWeights.Bold;

                // Style
                Style styleSewingStart = new Style(typeof(DataGridCell));
                styleDeliveryETD.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
                column1_1_B.CellStyle = styleDeliveryETD;

                dgInventory.Columns.Add(column1_1_B);
                Binding bindingWidthSewingStart = new Binding();
                bindingWidthSewingStart.Source  = column1_1_B;
                bindingWidthSewingStart.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cdSewingStart  = new ColumnDefinition();
                cdSewingStart.SetBinding(ColumnDefinition.WidthProperty, bindingWidthSewingStart);
                gridTotal.ColumnDefinitions.Add(cdSewingStart);

                dt.Columns.Add("Quantity", typeof(Int32));
                DataGridTextColumn column1_2 = new DataGridTextColumn();
                column1_2.Header             = "Quantity";
                Binding bindingQuantity      = new Binding();
                bindingQuantity.Path         = new PropertyPath("Quantity");
                //binding.StringFormat = "dd-MMM";
                column1_2.Binding = bindingQuantity;
                //column1_2.FontWeight = FontWeights.Bold;
                dgInventory.Columns.Add(column1_2);
                Binding bindingWidth1_2 = new Binding();
                bindingWidth1_2.Source  = column1_2;
                bindingWidth1_2.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_2  = new ColumnDefinition();
                cd1_2.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_2);
                gridTotal.ColumnDefinitions.Add(cd1_2);


                dt.Columns.Add("Release", typeof(Int32));
                DataGridTextColumn column1_3 = new DataGridTextColumn();
                column1_3.Header             = "Release";
                Binding bindingRelease       = new Binding();
                bindingRelease.Path          = new PropertyPath("Release");
                column1_3.Binding            = bindingRelease;
                dgInventory.Columns.Add(column1_3);
                Binding bindingWidth1_3 = new Binding();
                bindingWidth1_3.Source  = column1_3;
                bindingWidth1_3.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_3  = new ColumnDefinition();
                cd1_3.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_3);
                gridTotal.ColumnDefinitions.Add(cd1_3);


                dt.Columns.Add("QuantityDelivery", typeof(Int32));
                DataGridTextColumn column1_4 = new DataGridTextColumn();
                column1_4.Header             = "Delivery Qty";
                // Style
                Style styleQtyDelivery = new Style(typeof(DataGridCell));
                styleQtyDelivery.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
                Setter setterBackgroundDelivery   = new Setter();
                setterBackgroundDelivery.Property = DataGridCell.ForegroundProperty;
                setterBackgroundDelivery.Value    = new Binding("QuantityDeliveryForeground");
                styleQtyDelivery.Setters.Add(setterBackgroundDelivery);
                column1_4.CellStyle = styleQtyDelivery;

                Binding bindingQtyDelivery = new Binding();
                bindingQtyDelivery.Path    = new PropertyPath("QuantityDelivery");
                column1_4.Binding          = bindingQtyDelivery;
                dgInventory.Columns.Add(column1_4);
                Binding bindingWidth1_4 = new Binding();
                bindingWidth1_4.Source  = column1_4;
                bindingWidth1_4.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_4  = new ColumnDefinition();
                cd1_4.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_4);
                gridTotal.ColumnDefinitions.Add(cd1_4);

                DataColumn columnDeliveryForeground   = new DataColumn("QuantityDeliveryForeground", typeof(SolidColorBrush));
                columnDeliveryForeground.DefaultValue = Brushes.Black;
                dt.Columns.Add(columnDeliveryForeground);

                dgInventory.FrozenColumnCount = 8;

                var regex  = new Regex("[a-z]|[A-Z]");
                sizeNoList = outsoleMaterialList.Select(s => s.SizeNo).Distinct().OrderBy(s => regex.IsMatch(s) ? Double.Parse(regex.Replace(s, "")) : Double.Parse(s)).ToList();
                for (int i = 0; i <= sizeNoList.Count - 1; i++)
                {
                    //OutsoleSuppliersModel outsoleSupplier = outsoleSupplierList[i];
                    string sizeNoBinding = sizeNoList[i].Contains(".") ? sizeNoList[i].Replace(".", "") : sizeNoList[i];
                    dt.Columns.Add(String.Format("Column{0}", sizeNoBinding), typeof(Int32));
                    DataGridTextColumn column = new DataGridTextColumn();
                    //column.SetValue(TagProperty, sizeRun.SizeNo);
                    column.Header  = sizeNoList[i];
                    column.Width   = 35;
                    column.Binding = new Binding(String.Format("Column{0}", sizeNoBinding));

                    Style style = new Style(typeof(DataGridCell));
                    style.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));

                    Setter setterBackground   = new Setter();
                    setterBackground.Property = DataGridCell.BackgroundProperty;
                    setterBackground.Value    = new Binding(String.Format("Column{0}Background", sizeNoBinding));

                    Setter setterForeground   = new Setter();
                    setterForeground.Property = DataGridCell.ForegroundProperty;
                    setterForeground.Value    = new Binding(String.Format("Column{0}Foreground", sizeNoBinding));

                    Setter setterToolTip   = new Setter();
                    setterToolTip.Property = DataGridCell.ToolTipProperty;
                    setterToolTip.Value    = new Binding(String.Format("Column{0}ToolTip", sizeNoBinding));

                    style.Setters.Add(setterBackground);
                    style.Setters.Add(setterForeground);
                    style.Setters.Add(setterToolTip);

                    column.CellStyle = style;
                    dgInventory.Columns.Add(column);
                    Binding bindingWidth = new Binding();
                    bindingWidth.Source  = column;
                    bindingWidth.Path    = new PropertyPath("ActualWidth");
                    ColumnDefinition cd  = new ColumnDefinition();
                    cd.SetBinding(ColumnDefinition.WidthProperty, bindingWidth);
                    gridTotal.ColumnDefinitions.Add(cd);

                    DataColumn columnBackground   = new DataColumn(String.Format("Column{0}Background", sizeNoBinding), typeof(SolidColorBrush));
                    columnBackground.DefaultValue = Brushes.Transparent;

                    DataColumn columnForeground   = new DataColumn(String.Format("Column{0}Foreground", sizeNoBinding), typeof(SolidColorBrush));
                    columnForeground.DefaultValue = Brushes.Black;

                    DataColumn columnToolTip = new DataColumn(String.Format("Column{0}ToolTip", sizeNoBinding), typeof(String));

                    dt.Columns.Add(columnBackground);
                    dt.Columns.Add(columnForeground);
                    dt.Columns.Add(columnToolTip);
                }

                dt.Columns.Add("TotalBalance", typeof(Int32));
                DataGridTextColumn columnTotalBalance = new DataGridTextColumn();
                columnTotalBalance.Header             = "Total";
                columnTotalBalance.Binding            = new Binding("TotalBalance");
                dgInventory.Columns.Add(columnTotalBalance);
                Binding bindingWidthTotalBalance = new Binding();
                bindingWidthTotalBalance.Source  = columnTotalBalance;
                bindingWidthTotalBalance.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cdTotalBalance  = new ColumnDefinition();
                cdTotalBalance.SetBinding(ColumnDefinition.WidthProperty, bindingWidthTotalBalance);
                gridTotal.ColumnDefinitions.Add(cdTotalBalance);
            }));

            foreach (string productNo in productNoList)
            {
                var outsoleMaterialDetailList = OutsoleMaterialDetailController.Select(productNo).Where(w => w.OutsoleSupplierId == supplierID).ToList();
                var order = orderList.FirstOrDefault(f => f.ProductNo == productNo);

                var dr = dt.NewRow();

                if (order == null)
                {
                    continue;
                }
                dr["ProductNo"] = productNo;

                //HighLightPO
                int qtyOutsoleMaterialDetail = outsoleMaterialDetailList.Sum(s => s.Quantity);
                if (qtyOutsoleMaterialDetail >= order.Quantity)
                {
                    dr["ProductNoBackground"] = Brushes.Green;
                }
                else if (qtyOutsoleMaterialDetail != 0 && qtyOutsoleMaterialDetail < order.Quantity)
                {
                    dr["ProductNoBackground"] = Brushes.Yellow;
                }

                dr["ArticleNo"] = order.ArticleNo;
                dr["Quantity"]  = order.Quantity;
                dr["OrderETD"]  = order.ETD;

                var sewingMasterModel = sewingMasterList.Where(w => w.ProductNo == productNo).FirstOrDefault();
                if (sewingMasterModel != null)
                {
                    dr["SewingStartDate"] = sewingMasterModel.SewingStartDate;
                }

                var outsoleRawMaterialModel = outsoleRawMaterialList.Where(w => w.ProductNo == productNo && w.OutsoleSupplierId == supplierID).FirstOrDefault();
                var dtTemp = new DateTime(2000, 01, 01);
                if (outsoleRawMaterialModel != null)
                {
                    dr["DeliveryETD"] = outsoleRawMaterialModel.ETD;
                    dtTemp            = outsoleRawMaterialModel.ETD;
                }

                int qtyDelivery = 0;
                foreach (string sizeNo in sizeNoList)
                {
                    string sizeNoBinding          = sizeNo.Contains(".") ? sizeNo.Replace(".", "") : sizeNo;
                    var    outsoleMaterialRecieve = outsoleMaterialList.Where(w => w.ProductNo == productNo && w.SizeNo == sizeNo).FirstOrDefault();

                    int qtyDeliveryPerSize = 0;
                    int qtyRejectPerSize   = 0;
                    if (outsoleMaterialRecieve != null)
                    {
                        qtyDeliveryPerSize = outsoleMaterialRecieve.Quantity;
                        qtyRejectPerSize   = outsoleMaterialRecieve.QuantityReject;
                    }
                    int qtyPerSize = 0;
                    if (sizeRunList.Where(w => w.ProductNo == productNo).Count() > 0)
                    {
                        qtyPerSize = sizeRunList.Where(w => w.ProductNo == productNo && w.SizeNo == sizeNo).Select(s => s.Quantity).FirstOrDefault();
                    }

                    if (qtyRejectPerSize > 0)
                    {
                        dr[String.Format("Column{0}", sizeNoBinding)]           = qtyRejectPerSize;
                        dr[String.Format("Column{0}Foreground", sizeNoBinding)] = Brushes.Red;
                    }

                    int qtyBalance = qtyPerSize - qtyDeliveryPerSize;
                    if (qtyBalance > 0 && dtTemp != dtDefault)
                    {
                        dr[String.Format("Column{0}", sizeNoBinding)] = qtyBalance + qtyRejectPerSize;
                        var dtNow = DateTime.Now;
                        if (outsoleMaterialRecieve != null)
                        {
                            if (outsoleMaterialRecieve.ModifiedTime.Date < dtNow.Date)
                            {
                                dr[String.Format("Column{0}Background", sizeNoBinding)] = Brushes.Tomato;
                            }
                            if (outsoleMaterialRecieve.ModifiedTime.Date == dtNow.Date)
                            {
                                dr[String.Format("Column{0}Background", sizeNoBinding)] = Brushes.Green;
                            }
                            dr[String.Format("Column{0}Foreground", sizeNoBinding)] = Brushes.Black;
                        }

                        if (qtyRejectPerSize > 0)
                        {
                            dr[String.Format("Column{0}Background", sizeNoBinding)] = Brushes.Yellow;
                            dr[String.Format("Column{0}ToolTip", sizeNoBinding)]    = String.Format("Balance: {0}\nReject: {1}", qtyBalance, qtyRejectPerSize);
                        }
                    }
                    qtyDelivery += qtyDeliveryPerSize;
                }
                int totalRelease = outsoleReleaseMaterialList.Where(w => w.ProductNo == productNo).Sum(s => s.Quantity);

                if (order.Quantity != qtyDelivery && qtyDelivery != 0)
                {
                    dr["QuantityDeliveryForeground"] = Brushes.Red;
                }

                dr["Release"]          = totalRelease;
                dr["QuantityDelivery"] = qtyDelivery;


                int totalQty    = outsoleMaterialList.Where(w => w.ProductNo == productNo).Sum(s => s.Quantity);
                int totalReject = outsoleMaterialList.Where(w => w.ProductNo == productNo).Sum(s => s.QuantityReject);

                if (order.Quantity - totalQty + totalReject > 0)
                {
                    dr["TotalBalance"] = order.Quantity - totalQty + totalReject;
                }

                dt.Rows.Add(dr);
            }

            Dispatcher.Invoke(new Action(() =>
            {
                TextBlock lblTotal  = new TextBlock();
                lblTotal.Text       = "TOTAL";
                lblTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblTotal.FontWeight = FontWeights.Bold;
                Border bdrTotal     = new Border();
                Grid.SetColumn(bdrTotal, 2);
                Grid.SetColumnSpan(bdrTotal, 5);
                bdrTotal.BorderThickness = new Thickness(1, 0, 1, 1);
                bdrTotal.BorderBrush     = Brushes.Black;
                bdrTotal.Child           = lblTotal;
                gridTotal.Children.Add(bdrTotal);

                TextBlock lblQuantityTotal     = new TextBlock();
                lblQuantityTotal.Text          = dt.Compute("Sum(Quantity)", "").ToString();
                lblQuantityTotal.Margin        = new Thickness(1, 0, 0, 0);
                lblQuantityTotal.FontWeight    = FontWeights.Bold;
                lblQuantityTotal.TextAlignment = TextAlignment.Center;

                Border bdrQuantityTotal = new Border();
                Grid.SetColumn(bdrQuantityTotal, 7);
                bdrQuantityTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrQuantityTotal.BorderBrush     = Brushes.Black;
                bdrQuantityTotal.Child           = lblQuantityTotal;
                gridTotal.Children.Add(bdrQuantityTotal);
                dgInventory.ItemsSource = dt.AsDataView();

                TextBlock lblReleaseTotal     = new TextBlock();
                lblReleaseTotal.Text          = dt.Compute("Sum(Release)", "").ToString();
                lblReleaseTotal.Margin        = new Thickness(1, 0, 0, 0);
                lblReleaseTotal.FontWeight    = FontWeights.Bold;
                lblReleaseTotal.TextAlignment = TextAlignment.Center;

                Border bdrReleaseTotal = new Border();
                Grid.SetColumn(bdrReleaseTotal, 8);
                bdrReleaseTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrReleaseTotal.BorderBrush     = Brushes.Black;
                bdrReleaseTotal.Child           = lblReleaseTotal;
                gridTotal.Children.Add(bdrReleaseTotal);
                dgInventory.ItemsSource = dt.AsDataView();

                TextBlock lblQuantityDelivery     = new TextBlock();
                lblQuantityDelivery.Text          = dt.Compute("Sum(QuantityDelivery)", "").ToString();
                lblQuantityDelivery.Margin        = new Thickness(1, 0, 0, 0);
                lblQuantityDelivery.FontWeight    = FontWeights.Bold;
                lblQuantityDelivery.TextAlignment = TextAlignment.Center;

                Border bdrQuantityDeliveryTotal = new Border();
                Grid.SetColumn(bdrQuantityDeliveryTotal, 9);
                bdrQuantityDeliveryTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrQuantityDeliveryTotal.BorderBrush     = Brushes.Black;
                bdrQuantityDeliveryTotal.Child           = lblQuantityDelivery;
                gridTotal.Children.Add(bdrQuantityDeliveryTotal);
                dgInventory.ItemsSource = dt.AsDataView();

                for (int i = 0; i <= sizeNoList.Count - 1; i++)
                {
                    Border brTemp = new Border();
                    Grid.SetColumn(brTemp, 10 + i);
                    gridTotal.Children.Add(brTemp);
                }

                TextBlock txtTotalBalance     = new TextBlock();
                txtTotalBalance.Text          = dt.Compute("Sum(TotalBalance)", "").ToString();
                txtTotalBalance.Margin        = new Thickness(1, 0, 0, 0);
                txtTotalBalance.FontWeight    = FontWeights.Bold;
                txtTotalBalance.TextAlignment = TextAlignment.Center;

                Border brTotalBalance = new Border();
                Grid.SetColumn(brTotalBalance, 11 + sizeNoList.Count());
                brTotalBalance.BorderThickness = new Thickness(1, 0, 1, 1);
                brTotalBalance.BorderBrush     = Brushes.Black;
                brTotalBalance.Child           = txtTotalBalance;
                gridTotal.Children.Add(brTotalBalance);
                dgInventory.ItemsSource = dt.AsDataView();
            }));
            dtExportExcel = dt;
        }
Exemplo n.º 16
0
        // Notifications
        private void bwLoadDelivery_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleSupplierList        = OutsoleSuppliersController.Select();
            outsoleMaterialList        = OutsoleMaterialController.Select();
            outsoleReleaseMaterialList = OutsoleReleaseMaterialController.SelectByOutsoleMaterial();
            outsoleOutputList          = OutsoleOutputController.SelectByAssemblyMaster();
            sewingMasterList           = SewingMasterController.Select();
            assemblyMasterList         = AssemblyMasterController.Select();
            outsoleMasterList          = OutsoleMasterController.Select();
            orderList = OrdersController.Select();
            outsoleRawMaterialList = OutsoleRawMaterialController.Select();

            var      outsoleCodeList = orderList.Select(o => o.OutsoleCode).Distinct().ToList();
            DateTime dtNow           = DateTime.Now;
            DateTime dtDefault       = new DateTime(2000, 1, 1);
            DateTime deliveryEFDDate = dtDefault;

            // Delay Shipment Notifications
            foreach (var order in orderList)
            {
                bool needToShow = false;
                int  assemblyBalance = 0, sewingBalance = 0, outsoleBalance = 0;
                var  assemblyMaster = assemblyMasterList.FirstOrDefault(f => f.ProductNo == order.ProductNo);
                var  sewingMaster   = sewingMasterList.FirstOrDefault(f => f.ProductNo == order.ProductNo);
                var  outsoleMaster  = outsoleMasterList.FirstOrDefault(f => f.ProductNo == order.ProductNo);
                if (assemblyMaster == null || sewingMaster == null || outsoleMaster == null)
                {
                    continue;
                }

                if (assemblyMaster.AssemblyBalance != "")
                {
                    Int32.TryParse(assemblyMaster.AssemblyBalance, out assemblyBalance);
                }
                else
                {
                    assemblyBalance = order.Quantity;
                }

                if (sewingMaster.SewingBalance != "")
                {
                    Int32.TryParse(sewingMaster.SewingBalance, out sewingBalance);
                }
                else
                {
                    sewingBalance = order.Quantity;
                }

                if (outsoleMaster.OutsoleBalance != "")
                {
                    Int32.TryParse(outsoleMaster.OutsoleBalance, out outsoleBalance);
                }
                else
                {
                    outsoleBalance = order.Quantity;
                }

                if (dtNow.AddDays(5) < order.ETD)
                {
                    needToShow = false;
                }
                else
                {
                    if (assemblyBalance > 0 || sewingBalance > 0 || outsoleBalance > 0)
                    {
                        needToShow = true;
                    }
                    if (assemblyBalance > 0 && sewingBalance == 0 && outsoleBalance == 0)
                    {
                        needToShow = false;
                    }
                }

                if (needToShow == true)
                {
                    var delayShipment = new DelayShipmentViewModel();
                    delayShipment.Style     = order.ShoeName;
                    delayShipment.ProductNo = order.ProductNo;
                    delayShipment.OrderCSD  = order.ETD.AddDays(10);
                    if (assemblyBalance > 0)
                    {
                        delayShipment.AssemblyBalance = assemblyBalance;
                    }
                    if (sewingBalance > 0)
                    {
                        delayShipment.SewingBalance = sewingBalance;
                    }
                    if (outsoleBalance > 0)
                    {
                        delayShipment.OutsoleBalance = outsoleBalance;
                    }
                    if (delayShipment.OrderCSD < DateTime.Now.Date)
                    {
                        delayShipmentList.Add(delayShipment);
                    }
                }
            }

            // OSWH Notifications
            foreach (string outsoleCode in outsoleCodeList)
            {
                var productNoList = orderList.Where(o => o.OutsoleCode == outsoleCode && o.IsEnable == true).Select(o => o.ProductNo).Distinct().ToList();
                foreach (var productNo in productNoList)
                {
                    var sewingMasterModel = sewingMasterList.Where(w => w.ProductNo == productNo).FirstOrDefault();
                    var orderModel        = orderList.Where(w => w.ProductNo == productNo).FirstOrDefault();
                    if (sewingMasterModel == null || orderModel == null)
                    {
                        continue;
                    }
                    var outsoleMaterialList_D1 = outsoleMaterialList.Where(w => w.ProductNo == productNo).ToList();
                    var supplierIdList         = outsoleMaterialList_D1.Select(s => s.OutsoleSupplierId).Distinct().ToList();

                    foreach (var supplierId in supplierIdList)
                    {
                        int quantityDelivery        = outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == supplierId).Sum(s => s.Quantity) - outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == supplierId).Sum(s => s.QuantityReject);
                        int quantityDelivery1       = outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == supplierId).Sum(s => s.Quantity - s.QuantityReject);
                        var outsoleMaterialDelivery = outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == supplierId).FirstOrDefault();
                        if (quantityDelivery > 0)
                        {
                            var outsoleRawMaterialModel = outsoleRawMaterialList.Where(w => w.ProductNo == productNo && w.OutsoleSupplierId == supplierId).FirstOrDefault();
                            if (outsoleRawMaterialModel != null)
                            {
                                deliveryEFDDate = outsoleRawMaterialModel.ETD;
                            }
                            if (deliveryEFDDate != dtDefault && deliveryEFDDate > dtNow.AddDays(15) && sewingMasterModel.SewingStartDate > dtNow.AddDays(25))
                            {
                                var deliveryEarly = new NoticeOutsoleWHInventoryViewModel()
                                {
                                    Style            = orderModel.ShoeName,
                                    ProductNo        = productNo,
                                    QuantityDelivery = quantityDelivery,
                                    Supplier         = outsoleSupplierList.Where(w => w.OutsoleSupplierId == supplierId).Select(s => s.Name).FirstOrDefault(),
                                    OutsoleCode      = outsoleCode,
                                    DeliveryEFDDate  = deliveryEFDDate,
                                    SewingStartDate  = sewingMasterModel.SewingStartDate,
                                };
                                noticeOSWHInventoryDeliveryEarlyList.Add(deliveryEarly);
                            }
                        }

                        var outsoleRawMaterialLateModel = outsoleRawMaterialList.Where(w => w.ETD <= dtNow && w.ProductNo == productNo && w.OutsoleSupplierId == supplierId).FirstOrDefault();
                        if (outsoleRawMaterialLateModel != null)
                        {
                            int quantityOrder = orderModel.Quantity;
                            if (quantityOrder - quantityDelivery > 0)
                            {
                                var notDelivery = new NoticeOutsoleWHInventoryViewModel()
                                {
                                    Style               = orderModel.ShoeName,
                                    ProductNo           = productNo,
                                    QuantityNotDelivery = quantityOrder - quantityDelivery,
                                    Supplier            = outsoleSupplierList.Where(w => w.OutsoleSupplierId == supplierId).Select(s => s.Name).FirstOrDefault(),
                                    OutsoleCode         = outsoleCode,
                                    DeliveryEFDDate     = outsoleRawMaterialLateModel.ETD,
                                    OrderCSD            = orderModel.ETD.AddDays(10)
                                };
                                noticeOSWHInventoryNotDeliveryList.Add(notDelivery);
                            }
                        }

                        int quantityReject           = outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == supplierId).Sum(s => s.QuantityReject);
                        var outsoleMaterialReject    = outsoleMaterialList_D1.Where(w => w.OutsoleSupplierId == supplierId).FirstOrDefault(); // allways not null
                        var outsoleRawMaterialReject = outsoleRawMaterialList.Where(w => w.ETD <= dtNow && w.ProductNo == productNo && w.OutsoleSupplierId == supplierId).FirstOrDefault();
                        if (quantityReject > 0 && outsoleMaterialReject.ModifiedTimeReject < dtNow.AddDays(-2) && outsoleRawMaterialReject != null)
                        {
                            var reject = new NoticeOutsoleWHInventoryViewModel()
                            {
                                Style           = orderModel.ShoeName,
                                ProductNo       = productNo,
                                OrderEFD        = orderModel.ETD,
                                QuantityReject  = quantityReject,
                                Supplier        = outsoleSupplierList.Where(w => w.OutsoleSupplierId == supplierId).Select(s => s.Name).FirstOrDefault(),
                                OutsoleCode     = outsoleCode,
                                DeliveryEFDDate = outsoleRawMaterialReject.ETD
                            };

                            noticeOSWHInventoryRejectList.Add(reject);
                        }
                    }
                }
            }
        }
        private void BwSearch_DoWork(object sender, DoWorkEventArgs e)
        {
            var searchFrom = DateTime.Now;
            var searchTo   = DateTime.Now;

            Dispatcher.Invoke(new Action(() => {
                searchFrom = dpFrom.SelectedDate.Value.Date;
                searchTo   = dpTo.SelectedDate.Value.Date;
            }));

            reportOSMWHCheckingList = ReportController.GetOSMWHCheckingFromTo(searchFrom, searchTo);
            var productNoList = reportOSMWHCheckingList.Select(s => s.ProductNo).Distinct().ToList();

            if (productNoList.Count() > 0)
            {
                productNoList = productNoList.OrderBy(o => o).ToList();
            }
            // Outole Material
            foreach (var po in productNoList)
            {
                outsoleMaterialList.AddRange(OutsoleMaterialController.Select(po));
            }

            DataTable dt = new OSMWHCheckingDetailDataset().Tables["OSMWHCheckingDetailTable"];

            var supplierIdList = reportOSMWHCheckingList.Select(s => s.OutsoleSupplierId).Distinct().ToList();

            foreach (var suppId in supplierIdList)
            {
                var reportOSMWHCheckingListBySuppId = reportOSMWHCheckingList.Where(w => w.OutsoleSupplierId == suppId).ToList();
                var osCodeListBySuppId = reportOSMWHCheckingListBySuppId.Select(s => s.OutsoleCode).Distinct().ToList();

                foreach (var osCode in osCodeListBySuppId)
                {
                    var reportOSMWHCheckingListBySuppIdByOSCode = reportOSMWHCheckingListBySuppId.Where(w => w.OutsoleCode == osCode).ToList();
                    var poListBySuppByOSCode = reportOSMWHCheckingListBySuppIdByOSCode.Select(s => s.ProductNo).Distinct().ToList();
                    foreach (var productNo in poListBySuppByOSCode)
                    {
                        var reportOSMWHCheckingListByPO = reportOSMWHCheckingListBySuppIdByOSCode.Where(w => w.ProductNo == productNo).ToList();
                        var errorIdListByPO             = reportOSMWHCheckingListByPO.Select(s => s.ErrorId).Distinct().ToList();
                        var xReport = reportOSMWHCheckingListByPO.FirstOrDefault();

                        var totalQtyOrder = reportOSMWHCheckingListByPO.FirstOrDefault().Quantity;
                        var totalChecked  = reportOSMWHCheckingListByPO.Sum(s => s.QuantityDelivery + s.Reject);

                        if (poStatus == POStatus.POFinished && totalQtyOrder != totalChecked)
                        {
                            continue;
                        }
                        if (poStatus == POStatus.PONotYetFinish && totalQtyOrder == totalChecked)
                        {
                            continue;
                        }

                        int index = 1;
                        foreach (var errorId in errorIdListByPO)
                        {
                            DataRow dr    = dt.NewRow();
                            var     regex = new Regex("[a-z]|[A-Z]");

                            dr["SupplierAndOutsoleCode"] = String.Format("{0}@{1}", xReport.Name, xReport.OutsoleCode);
                            dr["SupplierName"]           = String.Format("To: {0}", xReport.Name);
                            dr["OutsoleCode"]            = xReport.OutsoleCode;
                            dr["ProductNo"] = xReport.ProductNo;
                            dr["WorkerId"]  = String.Join(", ", reportOSMWHCheckingListByPO.Select(s => s.WorkerId).Distinct().ToList());
                            dr["ArticleNo"] = xReport.ArticleNo;
                            dr["EFD"]       = String.Format("{0: MM/dd}", xReport.EFD);

                            var sizeNoListContainsError = reportOSMWHCheckingListByPO.Where(w => w.ErrorId > 0).Select(s => s.SizeNo).Distinct().ToList();
                            if (sizeNoListContainsError.Count() > 0)
                            {
                                sizeNoListContainsError = sizeNoListContainsError.OrderBy(s => regex.IsMatch(s) ? Double.Parse(regex.Replace(s, "100")) : Double.Parse(s)).ToList();
                            }

                            List <String> detailViewList = new List <string>();
                            foreach (var sizeNo in sizeNoListContainsError)
                            {
                                var totalRejectBySize = reportOSMWHCheckingListByPO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Reject);
                                detailViewList.Add(String.Format("#{0} = {1}", sizeNo, totalRejectBySize));
                            }
                            if (detailViewList.Count() > 0)
                            {
                                dr["Detail"] = String.Join("; ", detailViewList);
                            }


                            string fromTo = "";
                            if (searchFrom != searchTo)
                            {
                                fromTo = String.Format("From: {0: MM/dd/yyyy} to {1: MM/dd/yyyy}", searchFrom, searchTo);
                            }
                            else
                            {
                                fromTo = String.Format("From: {0: MM/dd/yyyy}", searchFrom);
                            }
                            dr["FromTo"] = fromTo;

                            // Delivery From MasterFile
                            int qtyDelivery = outsoleMaterialList.Where(w => w.ProductNo == productNo && w.OutsoleSupplierId == suppId).Sum(s => s.Quantity);
                            if (qtyDelivery > 0)
                            {
                                dr["QuantityDelivery"] = qtyDelivery;
                            }

                            // Qty Check = QtyDelivery at Outsole WH
                            int qtyChecked = reportOSMWHCheckingListByPO.Where(w => w.ErrorId == 0).Sum(s => s.QuantityDelivery);
                            if (qtyChecked > 0)
                            {
                                dr["QuantityCheck"] = qtyChecked;
                            }


                            var reportByErrorIdList  = reportOSMWHCheckingListByPO.Where(w => w.ErrorId == errorId && w.ErrorId > 0).ToList();
                            var reportByErrorIdFirst = reportByErrorIdList.FirstOrDefault();

                            List <string> errorAndQtyViewList = new List <string>();
                            if (errorId > 0)
                            {
                                dr["ErrorId"]   = errorId;
                                dr["ErrorName"] = String.Format("{0}\n{1}", reportByErrorIdFirst.ErrorName, reportByErrorIdFirst.ErrorVietNamese);

                                var sizeNoListHasError = reportByErrorIdList.Select(s => s.SizeNo).Distinct().ToList();
                                if (sizeNoListHasError.Count() > 0)
                                {
                                    sizeNoListHasError = sizeNoListHasError.OrderBy(s => regex.IsMatch(s) ? Double.Parse(regex.Replace(s, "100")) : Double.Parse(s)).ToList();
                                }
                                foreach (var sizeNo in sizeNoListHasError)
                                {
                                    int errorQtyBySizeNo = reportByErrorIdList.Where(w => w.SizeNo == sizeNo).Sum(s => s.Reject);
                                    if (errorQtyBySizeNo > 0)
                                    {
                                        errorAndQtyViewList.Add(String.Format("#{0} = {1}", sizeNo, errorQtyBySizeNo));
                                    }
                                }
                                if (errorAndQtyViewList.Count() > 0)
                                {
                                    dr["ErrorView"] = String.Join("; ", errorAndQtyViewList);
                                }
                            }

                            dt.Rows.Add(dr);
                            index++;
                        }
                    }
                }
            }

            e.Result = dt;
        }
        private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleMaterialRejectList = OutsoleMaterialController.SelectReject();
            outsoleSupplierList       = OutsoleSuppliersController.Select();
            orderList = OrdersController.SelectByOutsoleMaterialReject();
            outsoleRawMaterialList = OutsoleRawMaterialController.Select();
            sizeRunList            = SizeRunController.SelectIsEnable();
            def = PrivateDefineController.GetDefine();

            DataTable dt  = new OutsoleMaterialRejectDataSet().Tables["OutsoleMaterialRejectTable"];
            DataTable dt1 = new OutsoleMaterialRejectDataSet().Tables["OutsoleMaterialRejectTable"];

            var regex = new Regex(@"[a-z]|[A-Z]");

            foreach (OutsoleMaterialModel outsoleMaterialReject in outsoleMaterialRejectList)
            {
                var     outsoleSupplier    = outsoleSupplierList.FirstOrDefault(f => f.OutsoleSupplierId == outsoleMaterialReject.OutsoleSupplierId);
                var     order              = orderList.FirstOrDefault(f => f.ProductNo == outsoleMaterialReject.ProductNo);
                var     outsoleRawMaterial = outsoleRawMaterialList.FirstOrDefault(f => f.ProductNo == outsoleMaterialReject.ProductNo && f.OutsoleSupplierId == outsoleMaterialReject.OutsoleSupplierId);
                DataRow dr  = dt.NewRow();
                DataRow dr1 = dt1.NewRow();

                dr["ProductNo"]  = outsoleMaterialReject.ProductNo;
                dr1["ProductNo"] = outsoleMaterialReject.ProductNo;
                var productNoList = new List <String>();
                if (order != null)
                {
                    dr["OutsoleCode"]  = order.OutsoleCode;
                    dr1["OutsoleCode"] = order.OutsoleCode;
                    dr["ETD"]          = order.ETD;
                    dr1["ETD"]         = order.ETD;
                    dr["ArticleNo"]    = order.ArticleNo;
                    dr1["ArticleNo"]   = order.ArticleNo;
                    productNoList      = orderList.Where(w => w.OutsoleCode == order.OutsoleCode).Select(s => s.ProductNo).ToList();
                }
                if (outsoleRawMaterial != null)
                {
                    dr["SupplierETD"]  = outsoleRawMaterial.ETD;
                    dr1["SupplierETD"] = outsoleRawMaterial.ETD;
                }
                if (outsoleSupplier != null)
                {
                    dr["OutsoleSupplier"]  = outsoleSupplier.Name;
                    dr1["OutsoleSupplier"] = outsoleSupplier.Name;
                }

                string sizeNoOutsole      = outsoleMaterialReject.SizeNo;
                var    sizeNo_OutsoleCode = sizeRunList.Where(w => productNoList.Contains(w.ProductNo) && w.SizeNo == sizeNoOutsole).FirstOrDefault();
                if (sizeNo_OutsoleCode != null)
                {
                    if (String.IsNullOrEmpty(sizeNo_OutsoleCode.OutsoleSize) == false)
                    {
                        sizeNoOutsole = sizeNo_OutsoleCode.OutsoleSize;
                    }
                }

                string sizeNoString = regex.IsMatch(sizeNoOutsole) == true?regex.Replace(sizeNoOutsole, "") : sizeNoOutsole;

                double sizeNoDouble = 0;
                Double.TryParse(sizeNoString, out sizeNoDouble);
                dr["SizeNoDouble"]  = sizeNoDouble;
                dr1["SizeNoDouble"] = sizeNoDouble;

                dr["SizeNo"]  = outsoleMaterialReject.SizeNo;
                dr1["SizeNo"] = outsoleMaterialReject.SizeNo;
                if (def.ShowOSSizeValue)
                {
                    dr["SizeOutsole"]  = sizeNoOutsole;
                    dr1["SizeOutsole"] = sizeNoOutsole;
                }


                if (outsoleMaterialReject.QuantityReject > 0)
                {
                    dr["QuantityReject"] = outsoleMaterialReject.QuantityReject;
                    dt.Rows.Add(dr);
                }

                if (outsoleMaterialReject.RejectAssembly > 0)
                {
                    dr1["QuantityReject"] = outsoleMaterialReject.RejectAssembly;
                    dt1.Rows.Add(dr1);
                }
            }
            dtRejectAssemblyStockfit = dt1;
            e.Result = dt;
        }
        private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleMaterialList        = OutsoleMaterialController.Select();
            outsoleReleaseMaterialList = OutsoleReleaseMaterialController.SelectByOutsoleMaterial();
            //lay ra nhung order co outsolematerial roi

            orderList              = OrdersController.SelectByOutsoleMaterial();
            outsoleSupplierList    = OutsoleSuppliersController.Select();
            outsoleRawMaterialList = OutsoleRawMaterialController.Select();

            var outsoleCodeList = orderList.Select(o => o.OutsoleCode).Distinct().ToList();

            // Group By ProductNo
            //var outsoleMaterialGroupBy_ProductNo = from p in outsoleMaterialList
            //                                       group p.Quantity by p.ProductNo into g
            //                                       select new { ProductNo = g.Key, Quantities = g.ToList() };

            //var productNoList_Test = outsoleMaterialGroupBy_ProductNo.OrderBy(o => o.ProductNo).Select(s => s.ProductNo).ToList();

            //// PO has Quantity > 0
            //var productNoList = outsoleMaterialGroupBy_ProductNo.Where(w => w.Quantities.Sum() > 0).OrderBy(o => o.ProductNo).Select(s => s.ProductNo).Distinct().ToList();
            //var outsoleCodeList = orderList.Where(w => productNoList.Contains(w.ProductNo)).Select(s => s.OutsoleCode).Distinct().ToList();

            foreach (string outsoleCode in outsoleCodeList)
            {
                var productNoList          = orderList.Where(w => w.OutsoleCode == outsoleCode).Select(s => s.ProductNo).Distinct().ToList();
                var outsoleMaterialList_D1 = outsoleMaterialList.Where(o => productNoList.Contains(o.ProductNo)).ToList();
                var supplierId_OutsoleCode = outsoleMaterialList_D1.Select(o => o.OutsoleSupplierId).Distinct().ToList();
                supplierIdShowList.AddRange(supplierId_OutsoleCode);
            }

            supplierIdShowList = supplierIdShowList.Distinct().OrderBy(s => s).ToList();

            var dt = new DataTable();

            Dispatcher.Invoke(new Action(() =>
            {
                dt.Columns.Add("OutsoleCode", typeof(String));
                DataGridTextColumn column1 = new DataGridTextColumn();
                column1.Header             = "O/S Code";
                column1.Binding            = new Binding("OutsoleCode");
                column1.FontWeight         = FontWeights.Bold;
                dgInventory.Columns.Add(column1);
                Binding bindingWidth1 = new Binding();
                bindingWidth1.Source  = column1;
                bindingWidth1.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1  = new ColumnDefinition();
                cd1.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1);
                gridTotal.ColumnDefinitions.Add(cd1);

                dt.Columns.Add("Quantity", typeof(Int32));
                DataGridTextColumn column2 = new DataGridTextColumn();
                column2.Header             = "Quantity";
                column2.Binding            = new Binding("Quantity");
                dgInventory.Columns.Add(column2);
                Binding bindingWidth2 = new Binding();
                bindingWidth2.Source  = column2;
                bindingWidth2.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd2  = new ColumnDefinition();
                cd2.SetBinding(ColumnDefinition.WidthProperty, bindingWidth2);
                gridTotal.ColumnDefinitions.Add(cd2);

                dt.Columns.Add("Matching", typeof(Int32));
                DataGridTextColumn column3 = new DataGridTextColumn();
                column3.Header             = "Matching";
                column3.Binding            = new Binding("Matching");
                dgInventory.Columns.Add(column3);
                Binding bindingWidth3 = new Binding();
                bindingWidth3.Source  = column3;
                bindingWidth3.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd3  = new ColumnDefinition();
                cd3.SetBinding(ColumnDefinition.WidthProperty, bindingWidth3);
                gridTotal.ColumnDefinitions.Add(cd3);

                dt.Columns.Add("RejectMaximum", typeof(Int32));
                DataGridTextColumn column4 = new DataGridTextColumn();
                column4.Header             = "Reject";
                column4.Binding            = new Binding("RejectMaximum");

                //Style headerRejectStyle = new Style(typeof(DataGridColumnHeader));
                //Setter setterHRS = new Setter();
                //setterHRS.Property = DataGridColumnHeader.ToolTipProperty;
                //setterHRS.Value = "RejectListMax()";
                //headerRejectStyle.Setters.Add(setterHRS);
                //column4.HeaderStyle = headerRejectStyle;

                dgInventory.Columns.Add(column4);

                Binding bindingWidth4 = new Binding();
                bindingWidth4.Source  = column4;
                bindingWidth4.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd4  = new ColumnDefinition();
                cd4.SetBinding(ColumnDefinition.WidthProperty, bindingWidth4);
                gridTotal.ColumnDefinitions.Add(cd4);

                dgInventory.FrozenColumnCount = 4;

                for (int i = 0; i < supplierIdShowList.Count; i++)
                {
                    var outsoleSupplier = outsoleSupplierList.FirstOrDefault(f => f.OutsoleSupplierId == supplierIdShowList[i]);
                    if (outsoleSupplier != null)
                    {
                        dt.Columns.Add(String.Format("Column{0}", supplierIdShowList[i]), typeof(String));
                        DataGridTextColumn column = new DataGridTextColumn();

                        string supplierNameDisplay = outsoleSupplier.Name.Contains(" ") ? outsoleSupplier.Name.Replace(' ', '\n') : outsoleSupplier.Name;
                        column.Header = supplierNameDisplay;

                        //column.Width = 30;
                        column.Binding    = new Binding(String.Format("Column{0}", supplierIdShowList[i]));
                        column.FontWeight = FontWeights.Bold;

                        Style style = new Style(typeof(DataGridCell));
                        style.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));

                        Setter setterBackground   = new Setter();
                        setterBackground.Property = DataGridCell.BackgroundProperty;
                        setterBackground.Value    = new Binding(String.Format("Column{0}Background", supplierIdShowList[i]));
                        style.Setters.Add(setterBackground);

                        Setter setterToolTip   = new Setter();
                        setterToolTip.Property = DataGridCell.ToolTipProperty;
                        setterToolTip.Value    = new Binding(String.Format("Column{0}ToolTip", supplierIdShowList[i]));
                        style.Setters.Add(setterToolTip);

                        column.CellStyle = style;

                        dgInventory.Columns.Add(column);
                        Binding bindingWidth = new Binding();
                        bindingWidth.Source  = column;
                        bindingWidth.Path    = new PropertyPath("ActualWidth");
                        ColumnDefinition cd  = new ColumnDefinition();
                        cd.SetBinding(ColumnDefinition.WidthProperty, bindingWidth);
                        gridTotal.ColumnDefinitions.Add(cd);

                        DataColumn columnBackground   = new DataColumn(String.Format("Column{0}Background", supplierIdShowList[i]), typeof(SolidColorBrush));
                        DataColumn columnToolTip      = new DataColumn(String.Format("Column{0}ToolTip", supplierIdShowList[i]), typeof(String));
                        columnBackground.DefaultValue = Brushes.Transparent;

                        dt.Columns.Add(columnBackground);
                        dt.Columns.Add(columnToolTip);
                    }
                }
            }));

            // Load Data
            foreach (string outsoleCode in outsoleCodeList)
            {
                var dr = dt.NewRow();

                dr["OutsoleCode"] = outsoleCode;
                var productNoList_OutsoleCode     = orderList.Where(o => o.OutsoleCode == outsoleCode).Select(o => o.ProductNo).Distinct().ToList();
                var outsoleMaterialList_D1        = outsoleMaterialList.Where(o => productNoList_OutsoleCode.Contains(o.ProductNo)).ToList();
                var outsoleReleaseMaterialList_D1 = outsoleReleaseMaterialList.Where(o => productNoList_OutsoleCode.Contains(o.ProductNo)).ToList();
                var supplierIdList = outsoleMaterialList_D1.Select(o => o.OutsoleSupplierId).Distinct().ToList();
                var qtyTotalList   = new List <Int32>();
                var qtyRejectList  = new List <Int32>();

                // Create one more SupplierIDList
                foreach (Int32 supplierId in supplierIdList)
                {
                    var outsoleMaterialList_D2 = outsoleMaterialList_D1.Where(o => o.OutsoleSupplierId == supplierId).ToList();
                    int qtyTotal       = 0;
                    int qtyRejectTotal = 0;
                    foreach (string productNo in productNoList_OutsoleCode)
                    {
                        var outsoleMaterialList_D3        = outsoleMaterialList_D2.Where(o => o.ProductNo == productNo).ToList();
                        var outsoleReleaseMaterialList_D3 = outsoleReleaseMaterialList_D1.Where(o => o.ProductNo == productNo).ToList();
                        var sizeNoList = outsoleMaterialList.Where(o => o.ProductNo == productNo).Select(o => o.SizeNo).Distinct().ToList();
                        foreach (string sizeNo in sizeNoList)
                        {
                            int qtyMax     = outsoleMaterialList_D3.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity - o.QuantityReject);
                            int qtyRelease = outsoleReleaseMaterialList_D3.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity);
                            int qtyReject  = outsoleMaterialList_D3.Where(o => o.SizeNo == sizeNo).Sum(s => s.QuantityReject);
                            int qty        = qtyMax - qtyRelease;
                            if (qty < 0)
                            {
                                qty = 0;
                            }
                            qtyTotal       += qty;
                            qtyRejectTotal += qtyReject;
                        }
                    }
                    dr[String.Format("Column{0}", supplierId)]           = "x";
                    dr[String.Format("Column{0}Background", supplierId)] = Brushes.Green;
                    //var suppName = outsoleSupplierList.Where(w => w.OutsoleSupplierId == supplierId).Select(s => s.Name).FirstOrDefault();
                    var suppName = outsoleSupplierList.FirstOrDefault(f => f.OutsoleSupplierId == supplierId).Name;
                    if (suppName != null)
                    {
                        //string toolTipDisplay   = string.Format("{0}\n{1}", suppName, qtyRejectTotal.ToString());
                        //string toolTipShow      = string.Format("Supplier: {0}\nQuantity Delivery {1}", suppName, qtyTotal.ToString());

                        dr[String.Format("Column{0}ToolTip", supplierId)] =
                            string.Format("{0}{1}", suppName, qtyRejectTotal > 0 ? String.Format("\nQtyReject: {0}", qtyRejectTotal.ToString()) : "");
                        //suppName + "/n" + "Qty Reject: " + qtyRejectTotal.ToString();
                    }
                    qtyTotalList.Add(qtyTotal);
                    qtyRejectList.Add(qtyRejectTotal);
                }

                int qtyMatchTotal = 0;
                foreach (string productNo in productNoList_OutsoleCode)
                {
                    var outsoleMaterialList_D2        = outsoleMaterialList_D1.Where(o => o.ProductNo == productNo).ToList();
                    var outsoleReleaseMaterialList_D2 = outsoleReleaseMaterialList_D1.Where(o => o.ProductNo == productNo).ToList();
                    var sizeNoList = outsoleMaterialList.Where(o => o.ProductNo == productNo).Select(o => o.SizeNo).Distinct().ToList();
                    foreach (string sizeNo in sizeNoList)
                    {
                        int qtyMin     = outsoleMaterialList_D2.Where(o => o.SizeNo == sizeNo).Select(o => o.Quantity - o.QuantityReject).Min();
                        int qtyRelease = outsoleReleaseMaterialList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity);
                        int qtyMatch   = qtyMin - qtyRelease;
                        if (qtyMatch < 0)
                        {
                            qtyMatch = 0;
                        }
                        qtyMatchTotal += qtyMatch;
                    }
                }

                //if (qtyTotalList.Sum() == 0 && qtyMatchTotal == 0 && qtyRejectList.Sum() == 0)
                //    continue;

                dr["RejectMaximum"] = qtyRejectList.Max();
                dr["Quantity"]      = qtyTotalList.Max();
                dr["Matching"]      = qtyMatchTotal;

                dt.Rows.Add(dr);
            }

            Dispatcher.Invoke(new Action(() =>
            {
                dgInventory.ItemsSource = dt.AsDataView();

                TextBlock lblTotal  = new TextBlock();
                lblTotal.Text       = "TOTAL";
                lblTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblTotal.FontWeight = FontWeights.Bold;
                Border bdrTotal     = new Border();
                Grid.SetColumn(bdrTotal, 1);
                Grid.SetColumnSpan(bdrTotal, 2);
                bdrTotal.BorderThickness = new Thickness(1, 0, 1, 1);
                bdrTotal.BorderBrush     = Brushes.Black;
                bdrTotal.Child           = lblTotal;
                gridTotal.Children.Add(bdrTotal);

                TextBlock lblQuantityTotal  = new TextBlock();
                lblQuantityTotal.Text       = dt.Compute("Sum(Quantity)", "").ToString();
                lblQuantityTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblQuantityTotal.FontWeight = FontWeights.Bold;
                Border bdrQuantityTotal     = new Border();
                Grid.SetColumn(bdrQuantityTotal, 3);
                bdrQuantityTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrQuantityTotal.BorderBrush     = Brushes.Black;
                bdrQuantityTotal.Child           = lblQuantityTotal;
                gridTotal.Children.Add(bdrQuantityTotal);
                dgInventory.ItemsSource = dt.AsDataView();

                TextBlock lblMatchingTotal  = new TextBlock();
                lblMatchingTotal.Text       = dt.Compute("Sum(Matching)", "").ToString();
                lblMatchingTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblMatchingTotal.FontWeight = FontWeights.Bold;
                Border bdrMatchingTotal     = new Border();
                Grid.SetColumn(bdrMatchingTotal, 4);
                bdrMatchingTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrMatchingTotal.BorderBrush     = Brushes.Black;
                bdrMatchingTotal.Child           = lblMatchingTotal;
                gridTotal.Children.Add(bdrMatchingTotal);
                dgInventory.ItemsSource = dt.AsDataView();

                TextBlock lblRejectMaximunTotal  = new TextBlock();
                lblRejectMaximunTotal.Text       = dt.Compute("Sum(RejectMaximum)", "").ToString();
                lblRejectMaximunTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblRejectMaximunTotal.FontWeight = FontWeights.Bold;
                Border bdrRejectMaximumTotal     = new Border();
                Grid.SetColumn(bdrRejectMaximumTotal, 5);
                bdrRejectMaximumTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrRejectMaximumTotal.BorderBrush     = Brushes.Black;
                bdrRejectMaximumTotal.Child           = lblRejectMaximunTotal;
                gridTotal.Children.Add(bdrRejectMaximumTotal);
                dgInventory.ItemsSource = dt.AsDataView();

                TextBlock lblTemporary      = new TextBlock();
                lblTemporary.Text           = dt.Compute("Sum(Matching)", "").ToString();
                lblTemporary.Margin         = new Thickness(2, 2, 2, 2);
                lblTemporary.FontWeight     = FontWeights.Bold;
                Border bdrMatching          = new Border();
                bdrMatching.BorderBrush     = Brushes.Black;
                bdrMatching.BorderThickness = new Thickness(1, 1, 1, 1);
                bdrMatching.Child           = lblTemporary;
            }));
        }
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                lblStatus.Text = String.Format("Creating Columns");
            }));

            outsoleMaterialList        = OutsoleMaterialController.Select();
            outsoleReleaseMaterialList = OutsoleReleaseMaterialController.SelectByOutsoleMaterial();
            supplierList = OutsoleSuppliersController.Select();
            ordersList   = OrdersController.Select();
            sizeRunList  = SizeRunController.SelectIsEnable();

            osDeliverySummaryList = ReportController.GetOSDeliverySummary();

            var productNoList   = ordersList.Select(s => s.ProductNo).Distinct().ToList();
            var outsoleCodeList = osDeliverySummaryList.Select(s => s.OutsoleCode).Distinct().ToList();

            // Create Column
            DataTable dt = new DataTable();

            Dispatcher.Invoke(new Action(() =>
            {
                // Column OutsoleCode
                dt.Columns.Add("OutsoleCode", typeof(String));
                DataGridTemplateColumn colOutsoleCode = new DataGridTemplateColumn();
                colOutsoleCode.Header       = String.Format("Outsole Code");
                DataTemplate templateOSCode = new DataTemplate();
                FrameworkElementFactory tblOSCodeFactory = new FrameworkElementFactory(typeof(TextBlock));
                templateOSCode.VisualTree = tblOSCodeFactory;
                tblOSCodeFactory.SetValue(TextBlock.TextProperty, "");
                tblOSCodeFactory.SetBinding(TextBlock.TextProperty, new Binding(String.Format("OutsoleCode")));
                tblOSCodeFactory.SetValue(TextBlock.FontWeightProperty, FontWeights.SemiBold);
                tblOSCodeFactory.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblOSCodeFactory.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colOutsoleCode.CellTemplate            = templateOSCode;
                colOutsoleCode.ClipboardContentBinding = new Binding(String.Format("OutsoleCode"));
                dgWHDelivery.Columns.Add(colOutsoleCode);

                // Column OutsoleCode
                dt.Columns.Add("OrderQuantity", typeof(String));
                DataGridTemplateColumn colOrderQty = new DataGridTemplateColumn();
                colOrderQty.Header                 = String.Format("Order Quantity");
                DataTemplate templateOrderQty      = new DataTemplate();
                FrameworkElementFactory tblOderQty = new FrameworkElementFactory(typeof(TextBlock));
                templateOrderQty.VisualTree        = tblOderQty;
                tblOderQty.SetValue(TextBlock.TextProperty, "");
                tblOderQty.SetBinding(TextBlock.TextProperty, new Binding(String.Format("OrderQuantity")));
                tblOderQty.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblOderQty.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colOrderQty.CellTemplate            = templateOrderQty;
                colOrderQty.ClipboardContentBinding = new Binding(String.Format("OrderQuantity"));
                dgWHDelivery.Columns.Add(colOrderQty);

                // Column WHQuantity
                dt.Columns.Add("WHQuantity", typeof(String));
                DataGridTemplateColumn colWHQuantity = new DataGridTemplateColumn();
                colWHQuantity.Header                  = String.Format("WH Quantity");
                DataTemplate templateWHQuantity       = new DataTemplate();
                FrameworkElementFactory tblWHQuantity = new FrameworkElementFactory(typeof(TextBlock));
                templateWHQuantity.VisualTree         = tblWHQuantity;
                tblWHQuantity.SetBinding(TextBlock.TextProperty, new Binding(String.Format("WHQuantity")));
                tblWHQuantity.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblWHQuantity.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colWHQuantity.CellTemplate            = templateWHQuantity;
                colWHQuantity.ClipboardContentBinding = new Binding(String.Format("WHQuantity"));
                dgWHDelivery.Columns.Add(colWHQuantity);

                // Column WHQuantity
                dt.Columns.Add("Reject", typeof(String));
                DataGridTemplateColumn colReject = new DataGridTemplateColumn();
                colReject.Header                  = String.Format("Reject");
                DataTemplate templateReject       = new DataTemplate();
                FrameworkElementFactory tblReject = new FrameworkElementFactory(typeof(TextBlock));
                templateReject.VisualTree         = tblReject;
                tblReject.SetBinding(TextBlock.TextProperty, new Binding(String.Format("Reject")));
                tblReject.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                tblReject.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                colReject.CellTemplate            = templateReject;
                colReject.ClipboardContentBinding = new Binding(String.Format("Reject"));
                dgWHDelivery.Columns.Add(colReject);

                // Column Matching
                dt.Columns.Add("Matching", typeof(String));
                DataGridTemplateColumn colMatching = new DataGridTemplateColumn();
                colMatching.Header                  = String.Format("Matching");
                DataTemplate templateMatching       = new DataTemplate();
                FrameworkElementFactory tblMatching = new FrameworkElementFactory(typeof(TextBlock));
                templateMatching.VisualTree         = tblMatching;
                tblMatching.SetBinding(TextBlock.TextProperty, new Binding(String.Format("Matching")));
                tblMatching.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                tblMatching.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                colMatching.CellTemplate            = templateMatching;
                colMatching.ClipboardContentBinding = new Binding(String.Format("Matching"));
                dgWHDelivery.Columns.Add(colMatching);

                // Column Release
                dt.Columns.Add("Release", typeof(String));
                DataGridTemplateColumn colRelease = new DataGridTemplateColumn();
                colRelease.Header                  = String.Format("Release");
                DataTemplate templateRelease       = new DataTemplate();
                FrameworkElementFactory tblRelease = new FrameworkElementFactory(typeof(TextBlock));
                templateRelease.VisualTree         = tblRelease;
                tblRelease.SetBinding(TextBlock.TextProperty, new Binding(String.Format("Release")));
                tblRelease.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                tblRelease.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                colRelease.CellTemplate            = templateRelease;
                colRelease.ClipboardContentBinding = new Binding(String.Format("Release"));
                dgWHDelivery.Columns.Add(colRelease);

                // Column Suppliers
                int maxNumberOfSupplier = osDeliverySummaryList.Max(m => m.NoOfSupp);
                for (int i = 0; i < maxNumberOfSupplier; i++)
                {
                    dt.Columns.Add(String.Format("Column{0}", i), typeof(String));
                    dt.Columns.Add(String.Format("ColumnSupplierID{0}", i), typeof(Int32));
                    DataGridTemplateColumn colSupplier = new DataGridTemplateColumn();
                    colSupplier.Header                  = String.Format("Supplier {0}", i + 1);
                    DataTemplate templateSupplier       = new DataTemplate();
                    FrameworkElementFactory tblSupplier = new FrameworkElementFactory(typeof(TextBlock));
                    templateSupplier.VisualTree         = tblSupplier;
                    tblSupplier.SetBinding(TextBlock.TextProperty, new Binding(String.Format("Column{0}", i)));
                    tblSupplier.SetValue(TextBlock.PaddingProperty, new Thickness(3, 3, 3, 3));
                    tblSupplier.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);

                    colSupplier.CellTemplate            = templateSupplier;
                    colSupplier.ClipboardContentBinding = new Binding(String.Format("Column{0}", i));
                    dgWHDelivery.Columns.Add(colSupplier);
                }
            }));

            // Binding Data
            int indexProgressBar = 1;

            Dispatcher.Invoke(new Action(() => {
                progressBar.Maximum = outsoleCodeList.Count();
            }));
            int totalQtyOrder = 0, totalQtyWH = 0, totalQtyReject = 0, totalQtyMatch = 0, totalQtyRelease = 0;

            foreach (var outsoleCode in outsoleCodeList)
            {
                DataRow dr = dt.NewRow();

                var osDeliveryByOScode = osDeliverySummaryList.Where(w => w.OutsoleCode == outsoleCode).ToList();

                dr["OutsoleCode"]   = outsoleCode;
                dr["OrderQuantity"] = string.Format("{0:#,0}", osDeliveryByOScode.Max(m => m.QtyOrder));
                dr["WHQuantity"]    = string.Format("{0:#,0}", osDeliveryByOScode.Max(m => m.QtyWH));
                dr["Reject"]        = string.Format("{0:#,0}", osDeliveryByOScode.Max(m => m.QtyReject));
                dr["Matching"]      = string.Format("{0:#,0}", osDeliveryByOScode.Max(m => m.QtyMatch));
                dr["Release"]       = string.Format("{0:#,0}", osDeliveryByOScode.Max(m => m.QtyRelease));

                totalQtyOrder   += osDeliveryByOScode.Max(m => m.QtyOrder);
                totalQtyWH      += osDeliveryByOScode.Max(m => m.QtyWH);
                totalQtyReject  += osDeliveryByOScode.Max(m => m.QtyReject);
                totalQtyMatch   += osDeliveryByOScode.Max(m => m.QtyMatch);
                totalQtyRelease += osDeliveryByOScode.Max(m => m.QtyRelease);

                var supplierIDList_OSCode = osDeliverySummaryList.Where(w => w.OutsoleCode == outsoleCode).Select(s => s.OutsoleSupplierId).Distinct().ToList();

                for (int i = 0; i < supplierIDList_OSCode.Count(); i++)
                {
                    int supplierID = supplierIDList_OSCode[i];
                    var osDeliverySummaryByOSCodeBySupplier = osDeliverySummaryList.FirstOrDefault(w => w.OutsoleCode == outsoleCode && w.OutsoleSupplierId == supplierID);

                    string numberOfPO = osDeliverySummaryByOSCodeBySupplier.NoOfPO > 0 ?
                                        string.Format("({0:#,0})", osDeliverySummaryByOSCodeBySupplier.NoOfPO) :
                                        "";
                    string quantityDelivery_SupplierString = osDeliverySummaryByOSCodeBySupplier.QtyDelivery > 0 ? string.Format("\nDelivery: {0:#,0}", osDeliverySummaryByOSCodeBySupplier.QtyDelivery)   : "";
                    string reject_SupplierString           = osDeliverySummaryByOSCodeBySupplier.QtyReject > 0 ?   string.Format("\nReject:     {0:#,0}", osDeliverySummaryByOSCodeBySupplier.QtyReject)   : "";
                    string balance_SupplierString          = osDeliverySummaryByOSCodeBySupplier.QtyBalance > 0 ?  string.Format("\nBalance:  {0:#,0}", osDeliverySummaryByOSCodeBySupplier.QtyBalance)    : "";

                    dr[String.Format("Column{0}", i)] = String.Format("{0} {1}{2}{3}{4}",
                                                                      osDeliverySummaryByOSCodeBySupplier.Name,
                                                                      numberOfPO,
                                                                      quantityDelivery_SupplierString,
                                                                      reject_SupplierString,
                                                                      balance_SupplierString);

                    dr[String.Format("ColumnSupplierID{0}", i)] = supplierIDList_OSCode[i];
                }
                dt.Rows.Add(dr);
                Dispatcher.Invoke(new Action(() =>
                {
                    progressBar.Value = indexProgressBar;
                    lblStatus.Text    = String.Format("Writing  {0} rows / {1}", indexProgressBar, outsoleCodeList.Count());
                    Thread.Sleep(50);
                }));
                indexProgressBar++;
            }

            DataRow drTotal = dt.NewRow();

            drTotal["OutsoleCode"]   = "Total";
            drTotal["OrderQuantity"] = string.Format("{0:#,0}", totalQtyOrder);
            drTotal["WHQuantity"]    = string.Format("{0:#,0}", totalQtyWH);
            drTotal["Reject"]        = string.Format("{0:#,0}", totalQtyReject);
            drTotal["Matching"]      = string.Format("{0:#,0}", totalQtyMatch);
            drTotal["Release"]       = string.Format("{0:#,0}", totalQtyRelease);

            dt.Rows.Add(drTotal);
            e.Result = dt;
        }
Exemplo n.º 21
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList                   = OrdersController.Select();
            rawMaterialList             = RawMaterialController.Select();
            sewingMasterList            = SewingMasterController.Select();
            outsoleMasterList           = OutsoleMasterController.Select();
            outsoleRawMaterialList      = OutsoleRawMaterialController.Select();
            outsoleReleaseMaterialList  = OutsoleReleaseMaterialController.SelectByOutsoleMaster();
            productionMemoList          = ProductionMemoController.Select();
            outsoleMaterialList         = OutsoleMaterialController.Select();
            rawMaterialViewModelNewList = RawMaterialController.Select_1();

            //sewingMasterList.RemoveAll(s => DateTimeHelper.Create(s.SewingBalance) != dtDefault && DateTimeHelper.Create(s.SewingBalance) != dtNothing);
            outsoleMasterList = outsoleMasterList.OrderBy(s => s.Sequence).ToList();

            int[] materialIdUpperArray   = { 1, 2, 3, 4, 10 };
            int[] materialIdSewingArray  = { 5, 7 };
            int[] materialIdOutsoleArray = { 6 };

            foreach (OutsoleMasterModel outsoleMaster in outsoleMasterList)
            {
                OutsoleMasterExportViewModel outsoleMasterExportView = new OutsoleMasterExportViewModel();
                outsoleMasterExportView.Sequence  = outsoleMaster.Sequence;
                outsoleMasterExportView.ProductNo = outsoleMaster.ProductNo;
                OrdersModel order  = orderList.FirstOrDefault(f => f.ProductNo == outsoleMaster.ProductNo);
                string      memoId = "";
                if (order != null)
                {
                    outsoleMasterExportView.Country     = order.Country;
                    outsoleMasterExportView.ShoeName    = order.ShoeName;
                    outsoleMasterExportView.ArticleNo   = order.ArticleNo;
                    outsoleMasterExportView.OutsoleCode = order.OutsoleCode;
                    outsoleMasterExportView.PatternNo   = order.PatternNo;
                    outsoleMasterExportView.Quantity    = order.Quantity;
                    outsoleMasterExportView.ETD         = order.ETD;


                    List <ProductionMemoModel> productionMemoByProductionNumberList = productionMemoList.Where(p => p.ProductionNumbers.Contains(order.ProductNo) == true).ToList();
                    for (int p = 0; p <= productionMemoByProductionNumberList.Count - 1; p++)
                    {
                        ProductionMemoModel productionMemo = productionMemoByProductionNumberList[p];
                        memoId += productionMemo.MemoId;
                        if (p < productionMemoByProductionNumberList.Count - 1)
                        {
                            memoId += "\n";
                        }
                    }
                    outsoleMasterExportView.MemoId = memoId;
                }

                //MaterialArrivalViewModel materialArrivalOutsole = MaterialArrival(order.ProductNo, materialIdOutsoleArray);
                //outsoleMasterExportView.IsOutsoleMatsArrivalOk = false;
                //if (materialArrivalOutsole != null)
                //{
                //    outsoleMasterExportView.OutsoleMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalOutsole.Date);
                //    outsoleMasterExportView.IsOutsoleMatsArrivalOk = materialArrivalOutsole.IsMaterialArrivalOk;
                //}

                // Update follow OutsoleRawMaterial
                //var osRawMaterial = outsoleRawMaterialList.Where(w => w.ProductNo == order.ProductNo).ToList();
                //var actualDateList = osRawMaterial.Select(s => s.ActualDate).ToList();
                //outsoleMasterExportView.IsOutsoleMatsArrivalOk = false;

                //if (actualDateList.Count() > 0 && actualDateList.Contains(dtDefault) == false)
                //{
                //    outsoleMasterExportView.OutsoleMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", actualDateList.Max());
                //    outsoleMasterExportView.IsOutsoleMatsArrivalOk = true;
                //}
                //else
                //{
                //    var etdDateList = osRawMaterial.Select(s => s.ETD).ToList();
                //    if (etdDateList.Count() > 0)
                //    {
                //        outsoleMasterExportView.OutsoleMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", etdDateList.Max());
                //    }
                //}
                outsoleMasterExportView.IsOutsoleMatsArrivalOk = false;
                var rawMaterialViewModelNew = rawMaterialViewModelNewList.FirstOrDefault(f => f.ProductNo == order.ProductNo);
                if (String.IsNullOrEmpty(rawMaterialViewModelNew.OUTSOLE_Remarks) &&
                    !String.IsNullOrEmpty(rawMaterialViewModelNew.OUTSOLE_ActualDate))
                {
                    outsoleMasterExportView.OutsoleMatsArrival     = rawMaterialViewModelNew.OUTSOLE_ActualDate;
                    outsoleMasterExportView.IsOutsoleMatsArrivalOk = true;
                }
                else
                {
                    outsoleMasterExportView.OutsoleMatsArrival = rawMaterialViewModelNew.OUTSOLE_ETD;
                }


                outsoleMasterExportView.OutsoleLine       = outsoleMaster.OutsoleLine;
                outsoleMasterExportView.OutsoleStartDate  = outsoleMaster.OutsoleStartDate;
                outsoleMasterExportView.OutsoleFinishDate = outsoleMaster.OutsoleFinishDate;
                outsoleMasterExportView.OutsoleQuota      = outsoleMaster.OutsoleQuota;
                outsoleMasterExportView.OutsoleBalance    = outsoleMaster.OutsoleBalance;

                //RawMaterialModel outsoleRawMaterial = rawMaterialList.FirstOrDefault(f => f.ProductNo == outsoleMaster.ProductNo && materialIdOutsoleArray.Contains(f.MaterialTypeId));
                //if (outsoleRawMaterial != null)
                //{
                //    outsoleMasterExportView.OutsoleWHBalance = outsoleRawMaterial.Remarks;
                //}
                //else
                //{
                //    outsoleMasterExportView.OutsoleWHBalance = "";
                //}

                // Load Outsole_Remarks from OutsoleMaterial
                var outsoleMaterial_PO      = outsoleMaterialList.Where(w => w.ProductNo == order.ProductNo).ToList();
                var osMaterialSumBySupplier = outsoleMaterial_PO.GroupBy(
                    g => g.OutsoleSupplierId)
                                              .Select(s => new
                {
                    PO             = order.ProductNo,
                    Supplier       = s.Key,
                    ActualDelivery = outsoleMaterial_PO.Where(w => w.OutsoleSupplierId == s.Key)
                                     .Sum(su => su.Quantity - su.QuantityReject)
                }).ToList();

                // if pot no one delivery. not show the balance quantity.
                if (osMaterialSumBySupplier.Count > 0 && order.Quantity - osMaterialSumBySupplier.Min(m => m.ActualDelivery) > 0)
                {
                    // show the balance
                    outsoleMasterExportView.OutsoleWHBalance = (order.Quantity - osMaterialSumBySupplier.Min(m => m.ActualDelivery)).ToString();
                    // if no one delivery, show blank
                    if (outsoleMaterial_PO.Sum(s => s.Quantity) == 0)
                    {
                        outsoleMasterExportView.OutsoleWHBalance = "";
                    }
                }

                SewingMasterModel sewingMaster = sewingMasterList.FirstOrDefault(f => f.ProductNo == outsoleMaster.ProductNo);
                if (sewingMaster != null)
                {
                    outsoleMasterExportView.SewingStartDate  = sewingMaster.SewingStartDate;
                    outsoleMasterExportView.SewingFinishDate = sewingMaster.SewingFinishDate;
                    outsoleMasterExportView.SewingQuota      = sewingMaster.SewingQuota;
                    outsoleMasterExportView.SewingBalance    = sewingMaster.SewingBalance;
                }
                else
                {
                    outsoleMasterExportView.SewingStartDate  = dtDefault;
                    outsoleMasterExportView.SewingFinishDate = dtDefault;
                    outsoleMasterExportView.SewingQuota      = 0;
                    outsoleMasterExportView.SewingBalance    = "";
                }

                List <OutsoleReleaseMaterialModel> outsoleReleaseMaterialList_D1 = outsoleReleaseMaterialList.Where(o => o.ProductNo == outsoleMaster.ProductNo).ToList();
                int qtyReleased = outsoleReleaseMaterialList_D1.Sum(o => o.Quantity);
                outsoleMasterExportView.ReleasedQuantity = qtyReleased.ToString();
                if (qtyReleased <= 0)
                {
                    outsoleMasterExportView.ReleasedQuantity = "";
                }
                if (qtyReleased >= outsoleMasterExportView.Quantity && outsoleReleaseMaterialList_D1.Count > 0)
                {
                    DateTime releasedDate = outsoleReleaseMaterialList_D1.FirstOrDefault().ModifiedTime;
                    outsoleMasterExportView.ReleasedQuantity = string.Format("{0:M/d}", releasedDate);
                }

                outsoleMasterExportViewList.Add(outsoleMasterExportView);
            }
        }
Exemplo n.º 22
0
        private void BwInsert_DoWork(object sender, DoWorkEventArgs e)
        {
            var par                       = e.Argument as object[];
            var osmCheckCurrent           = par[0] as OutsoleMaterialCheckingModel;
            var currentOSMCheckListBySupp = par[1] as List <OutsoleMaterialCheckingModel>;

            try
            {
                OutsoleMaterialCheckingController.Insert(osmCheckCurrent);
                // Update Reject to WHMasterFile.
                var osMaterialCheckByPO = OutsoleMaterialCheckingController.SelectByPOSumBySize(osmCheckCurrent.ProductNo).ToList();
                foreach (var sizeRun in sizeRunList)
                {
                    var osMaterialCheckByPOBySupplier = osMaterialCheckByPO.Where(w => w.OutsoleSupplierId == osmCheckCurrent.OutsoleSupplierId).ToList();

                    var sizeCompare      = String.IsNullOrEmpty(sizeRun.OutsoleSize) == false ? sizeRun.OutsoleSize : sizeRun.SizeNo;
                    var osMatCheckBySize = osMaterialCheckByPOBySupplier.FirstOrDefault(f => f.SizeNo == sizeCompare);

                    int rejectUpdate = 0;
                    if (osMatCheckBySize != null)
                    {
                        rejectUpdate = osMatCheckBySize.Reject - osMatCheckBySize.ReturnReject > 0 ? osMatCheckBySize.Reject - osMatCheckBySize.ReturnReject : 0;
                    }
                    var osMaterialUpdate = new OutsoleMaterialModel()
                    {
                        ProductNo         = osmCheckCurrent.ProductNo,
                        OutsoleSupplierId = osmCheckCurrent.OutsoleSupplierId,
                        SizeNo            = sizeRun.SizeNo,
                        QuantityReject    = rejectUpdate
                    };
                    OutsoleMaterialController.UpdateByOSCheck(osMaterialUpdate);
                }

                // Tranfer to mainwindow sum order by size
                // Update current list
                currentOSMCheckListBySupp.RemoveAll(r => r.SizeNo == osmCheckCurrent.SizeNo &&
                                                    r.CheckingDate == osmCheckCurrent.CheckingDate &&
                                                    r.WorkingCard == osmCheckCurrent.WorkingCard);

                currentOSMCheckListBySupp.Add(osmCheckCurrent);
                if (modeReject == false && modeReturnReject == false)
                {
                    osmCheckCurrent.Quantity = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                               w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.Quantity);
                }
                else if (modeReject == true && modeReturnReject == false)
                {
                    osmCheckCurrent.Reject = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                             w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.Reject);
                }
                if (modeReturnReject == true)
                {
                    osmCheckCurrent.ReturnReject = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                                   w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.ReturnReject);
                }
                outsoleMaterialCheckingUpdatedBySizeList.Add(osmCheckCurrent);
            }
            catch
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    MessageBox.Show("An error occured when execute data !\nPlease try again !", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                }));
            }
        }
        private void Confirm()
        {
            try
            {
                if (doMode == DoMode.Confirm)
                {
                    var confirmList = btnConfirm.Tag as List <OutsoleMaterialConfirmWorkingCartModel>;
                    if (confirmList == null || confirmList.Count() == 0)
                    {
                        return;
                    }
                    confirmList.ForEach(f => f.IsConfirm = true);
                    foreach (var model in confirmList)
                    {
                        OutsoleMaterialController.UpdateOSMaterial(model, 1);
                    }
                    MessageBox.Show("Confirmed !\nĐã xác nhận !", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                    loadSizeNoList(confirmList);
                    loadReadyToRelease(confirmList);
                }
                else if (doMode == DoMode.Release)
                {
                    var obj = btnConfirm.Tag as object[];
                    if (obj == null)
                    {
                        return;
                    }

                    var confirmByPOList     = obj[0] as List <OutsoleMaterialConfirmWorkingCartModel>;
                    var releaseSelectedList = obj[1] as List <OutsoleMaterialConfirmWorkingCartModel>;

                    if (releaseSelectedList.Count() == 0)
                    {
                        return;
                    }

                    foreach (var cf in confirmByPOList)
                    {
                        var rlItem = releaseSelectedList.FirstOrDefault(f => f.OSCheckingID == cf.OSCheckingID);
                        if (rlItem != null)
                        {
                            cf.IsRelease    = true;
                            cf.ReleasedTime = rlItem.ReleasedTime;
                        }
                    }
                    foreach (var updateModel in releaseSelectedList)
                    {
                        OutsoleMaterialController.UpdateOSMaterial(updateModel, 2);
                    }

                    MessageBox.Show("Released !\nĐã phát hàng !", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                    loadWorkingCart(confirmByPOList);
                    releaseSelectedList.Clear();
                }
                txtIndexNo.Focus();
                txtIndexNo.SelectAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
Exemplo n.º 24
0
        private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            var regex = new Regex(@"[a-z]|[A-Z]");

            outsoleRawMaterialList = OutsoleRawMaterialController.Select();
            outsoleMaterialList    = OutsoleMaterialController.SelectByOutsoleRawMaterial();
            sizeRunList            = SizeRunController.SelectByOutsoleRawMaterial();
            outsoleSupplierList    = OutsoleSuppliersController.Select();
            ordersList             = OrdersController.SelectByOutsoleRawMaterial();

            DataTable dt = new OutsoleDelayDataSet().Tables["OutsoleDelayTable"];

            List <String> productNoList = outsoleRawMaterialList.Select(r => r.ProductNo).Distinct().ToList();

            foreach (string productNo in productNoList)
            {
                OrdersModel order = ordersList.Where(o => o.ProductNo == productNo).FirstOrDefault();
                List <OutsoleRawMaterialModel> outsoleRawMaterialList_D1 = outsoleRawMaterialList.Where(o => o.ProductNo == productNo).ToList();
                List <SizeRunModel>            sizeRunList_D1            = sizeRunList.Where(s => s.ProductNo == productNo).OrderBy(o => Double.Parse(regex.IsMatch(o.SizeNo) ? regex.Replace(o.SizeNo, "") : o.SizeNo)).ToList();
                List <OutsoleMaterialModel>    outsoleMaterialList_D1    = outsoleMaterialList.Where(o => o.ProductNo == productNo).ToList();
                foreach (OutsoleRawMaterialModel outsoleRawMaterial in outsoleRawMaterialList_D1)
                {
                    List <OutsoleMaterialModel> outsoleMaterialList_D2 = outsoleMaterialList_D1.Where(o => o.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId).ToList();
                    OutsoleSuppliersModel       outsoleSupplier        = outsoleSupplierList.Where(o => o.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId).FirstOrDefault();
                    DateTime etd = outsoleRawMaterial.ETD.Date;
                    //bool isFull = OutsoleRawMaterialController.IsFull(sizeRunList_D1, new List<OutsoleRawMaterialModel>() { outsoleRawMaterial }, outsoleMaterialList_D1);
                    //if (etd != new DateTime(2000, 1, 1) && etd < DateTime.Now.Date && isFull == false)
                    if (etd != new DateTime(2000, 1, 1) && etd < DateTime.Now.Date)
                    {
                        foreach (SizeRunModel sizeRun in sizeRunList_D1)
                        {
                            int qtyDelay = sizeRun.Quantity -
                                           outsoleMaterialList_D2.Where(o => o.SizeNo == sizeRun.SizeNo).Sum(o => o.Quantity);
                            if (qtyDelay > 0)
                            {
                                DataRow dr = dt.NewRow();
                                dr["ProductNo"] = productNo;

                                string sizeNoString = regex.IsMatch(sizeRun.SizeNo) == true?regex.Replace(sizeRun.SizeNo, "") : sizeRun.SizeNo;

                                double sizeNoDouble = 0;
                                Double.TryParse(sizeNoString, out sizeNoDouble);
                                dr["SizeNoDouble"] = sizeNoDouble;

                                dr["SizeNo"] = sizeRun.SizeNo;

                                dr["SupplierETD"] = outsoleRawMaterial.ETD;
                                if (order != null)
                                {
                                    dr["OutsoleCode"] = order.OutsoleCode;
                                    dr["ArticleNo"]   = order.ArticleNo;
                                    dr["ETD"]         = order.ETD;
                                }
                                if (outsoleSupplier != null)
                                {
                                    dr["OutsoleSupplier"] = outsoleSupplier.Name;
                                }
                                dr["QuantityDelay"] = qtyDelay;
                                dt.Rows.Add(dr);
                            }
                        }
                    }
                }
            }
            e.Result = dt;
        }
Exemplo n.º 25
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleMaterialList = OutsoleMaterialController.Select().Where(w => productNoList.Contains(w.ProductNo)).ToList();

            Dispatcher.Invoke(new Action(() => {
                DataTable dt = new DataTable();
                dt.Columns.Add("ProductNo", typeof(String));
                DataGridTextColumn column1 = new DataGridTextColumn();
                column1.Header             = "PO No.";
                column1.Binding            = new Binding("ProductNo");
                column1.FontWeight         = FontWeights.Bold;
                dgInventory.Columns.Add(column1);
                Binding bindingWidth1 = new Binding();
                bindingWidth1.Source  = column1;
                bindingWidth1.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1  = new ColumnDefinition();
                cd1.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1);
                gridTotal.ColumnDefinitions.Add(cd1);

                dt.Columns.Add("ArticleNo", typeof(String));
                DataGridTextColumn column1_1_1 = new DataGridTextColumn();
                column1_1_1.Header             = "Article No.";
                column1_1_1.Binding            = new Binding("ArticleNo");
                //column1_1_1.FontWeight = FontWeights.Bold;
                dgInventory.Columns.Add(column1_1_1);
                Binding bindingWidth1_1_1 = new Binding();
                bindingWidth1_1_1.Source  = column1_1_1;
                bindingWidth1_1_1.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_1_1  = new ColumnDefinition();
                cd1_1_1.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_1_1);
                gridTotal.ColumnDefinitions.Add(cd1_1_1);

                dt.Columns.Add("ETD", typeof(DateTime));
                DataGridTextColumn column1_1 = new DataGridTextColumn();
                column1_1.Header             = "EFD";
                Binding binding      = new Binding();
                binding.Path         = new PropertyPath("ETD");
                binding.StringFormat = "dd-MMM";
                column1_1.Binding    = binding;
                column1_1.FontWeight = FontWeights.Bold;
                dgInventory.Columns.Add(column1_1);
                Binding bindingWidth1_1 = new Binding();
                bindingWidth1_1.Source  = column1_1;
                bindingWidth1_1.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_1  = new ColumnDefinition();
                cd1_1.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_1);
                gridTotal.ColumnDefinitions.Add(cd1_1);

                dt.Columns.Add("Quantity", typeof(Int32));
                DataGridTextColumn column1_2 = new DataGridTextColumn();
                column1_2.Header             = "Quantity";
                Binding bindingQuantity      = new Binding();
                bindingQuantity.Path         = new PropertyPath("Quantity");
                //binding.StringFormat = "dd-MMM";
                column1_2.Binding = bindingQuantity;
                //column1_2.FontWeight = FontWeights.Bold;
                dgInventory.Columns.Add(column1_2);
                Binding bindingWidth1_2 = new Binding();
                bindingWidth1_2.Source  = column1_2;
                bindingWidth1_2.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_2  = new ColumnDefinition();
                cd1_2.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_2);
                gridTotal.ColumnDefinitions.Add(cd1_2);

                dt.Columns.Add("Release", typeof(Int32));
                DataGridTextColumn column1_3 = new DataGridTextColumn();
                column1_3.Header             = "Release";
                Binding bindingRelease       = new Binding();
                bindingRelease.Path          = new PropertyPath("Release");
                //binding.StringFormat = "dd-MMM";
                column1_3.Binding = bindingRelease;
                //column1_2.FontWeight = FontWeights.Bold;
                dgInventory.Columns.Add(column1_3);
                Binding bindingWidth1_3 = new Binding();
                bindingWidth1_3.Source  = column1_3;
                bindingWidth1_3.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd1_3  = new ColumnDefinition();
                cd1_3.SetBinding(ColumnDefinition.WidthProperty, bindingWidth1_3);
                gridTotal.ColumnDefinitions.Add(cd1_3);

                for (int i = 0; i <= outsoleSupplierList.Count - 1; i++)
                {
                    OutsoleSuppliersModel outsoleSupplier = outsoleSupplierList[i];
                    dt.Columns.Add(String.Format("Column{0}", i), typeof(Int32));
                    DataGridTextColumn column = new DataGridTextColumn();
                    //column.SetValue(TagProperty, sizeRun.SizeNo);
                    column.Header  = outsoleSupplier.Name;
                    column.Binding = new Binding(String.Format("Column{0}", i));

                    Style style = new Style(typeof(DataGridCell));
                    style.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));

                    Setter setterForeground   = new Setter();
                    setterForeground.Property = DataGridCell.ForegroundProperty;
                    setterForeground.Value    = Brushes.Black;
                    style.Setters.Add(setterForeground);

                    Setter setterBackground   = new Setter();
                    setterBackground.Property = DataGridCell.BackgroundProperty;
                    setterBackground.Value    = new Binding(String.Format("Column{0}Background", i));
                    style.Setters.Add(setterBackground);

                    column.CellStyle = style;

                    dgInventory.Columns.Add(column);

                    Binding bindingWidth = new Binding();
                    bindingWidth.Source  = column;
                    bindingWidth.Path    = new PropertyPath("ActualWidth");
                    ColumnDefinition cd  = new ColumnDefinition();
                    cd.SetBinding(ColumnDefinition.WidthProperty, bindingWidth);
                    gridTotal.ColumnDefinitions.Add(cd);

                    DataColumn columnBackground   = new DataColumn(String.Format("Column{0}Background", i), typeof(SolidColorBrush));
                    columnBackground.DefaultValue = Brushes.Transparent;

                    dt.Columns.Add(columnBackground);
                }

                dt.Columns.Add("Matching", typeof(Int32));
                DataGridTextColumn column2 = new DataGridTextColumn();
                column2.Header             = "Matching";
                column2.Binding            = new Binding("Matching");
                dgInventory.Columns.Add(column2);
                Binding bindingWidth2 = new Binding();
                bindingWidth2.Source  = column2;
                bindingWidth2.Path    = new PropertyPath("ActualWidth");
                ColumnDefinition cd2  = new ColumnDefinition();
                cd2.SetBinding(ColumnDefinition.WidthProperty, bindingWidth2);
                gridTotal.ColumnDefinitions.Add(cd2);

                foreach (string productNo in productNoList)
                {
                    var outsoleMaterialDetailPerPOList = OutsoleMaterialDetailController.Select(productNo).ToList();

                    if (productNo == "105-5900")
                    {
                    }
                    List <OutsoleMaterialModel> outsoleMaterialList_D1 = outsoleMaterialList.Where(o => o.ProductNo == productNo).ToList();
                    List <OutsoleReleaseMaterialModel> outsoleReleaseMaterialList_D1 = outsoleReleaseMaterialList.Where(o => o.ProductNo == productNo).ToList();

                    DataRow dr        = dt.NewRow();
                    dr["ProductNo"]   = productNo;
                    OrdersModel order = orderList.Where(o => o.ProductNo == productNo).FirstOrDefault();

                    if (order != null)
                    {
                        dr["ETD"]       = order.ETD;
                        dr["ArticleNo"] = order.ArticleNo;
                        dr["Quantity"]  = order.Quantity;
                    }

                    List <String> sizeNoList    = outsoleMaterialList.Where(o => o.ProductNo == productNo).Select(o => o.SizeNo).Distinct().ToList();
                    int qtyMaterialTotalToCheck = 0;

                    for (int i = 0; i <= outsoleSupplierList.Count - 1; i++)
                    {
                        OutsoleSuppliersModel outsoleSupplier = outsoleSupplierList[i];
                        List <OutsoleMaterialModel> outsoleMaterialList_D2 = outsoleMaterialList_D1.Where(o => o.OutsoleSupplierId == outsoleSupplier.OutsoleSupplierId).ToList();

                        int qtyMaterialTotal = 0;
                        int qtyReleaseTotal  = 0;
                        foreach (string sizeNo in sizeNoList)
                        {
                            int qtyMax     = outsoleMaterialList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => (o.Quantity - o.QuantityReject));
                            int qtyRelease = outsoleReleaseMaterialList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity);

                            int qtyMaterial = qtyMax - qtyRelease;
                            if (qtyMaterial < 0)
                            {
                                qtyMaterial = 0;
                            }
                            qtyMaterialTotal        += qtyMaterial;
                            qtyMaterialTotalToCheck += qtyMaterial;
                            qtyReleaseTotal         += qtyRelease;
                        }
                        dr["Release"] = qtyReleaseTotal;
                        dr[String.Format("Column{0}", i)] = qtyMaterialTotal;

                        var outsoleMaterialDetailPerPOPerSupplierList = outsoleMaterialDetailPerPOList.Where(w => w.OutsoleSupplierId == outsoleSupplierList[i].OutsoleSupplierId).ToList();
                        if (outsoleMaterialDetailPerPOPerSupplierList.Count > 0)
                        {
                            int qtyMaterialDetail = outsoleMaterialDetailPerPOPerSupplierList.Sum(s => s.Quantity);
                            if (qtyMaterialDetail != 0 && qtyMaterialDetail < order.Quantity)
                            {
                                dr[String.Format("Column{0}Background", i)] = Brushes.Yellow;
                            }
                            if (qtyMaterialDetail != 0 && qtyMaterialDetail >= order.Quantity)
                            {
                                dr[String.Format("Column{0}Background", i)] = Brushes.Green;
                            }
                        }
                    }
                    int qtyMatchingTotal = 0;
                    foreach (string sizeNo in sizeNoList)
                    {
                        int qtyMin      = outsoleMaterialList_D1.Where(o => o.SizeNo == sizeNo).Select(o => (o.Quantity - o.QuantityReject)).Min();
                        int qtyRelease  = outsoleReleaseMaterialList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity);
                        int qtyMatching = qtyMin - qtyRelease;
                        if (qtyMatching < 0)
                        {
                            qtyMatching = 0;
                        }
                        qtyMatchingTotal += qtyMatching;
                    }
                    dr["Matching"] = qtyMatchingTotal;
                    if (qtyMaterialTotalToCheck != 0)
                    {
                        dt.Rows.Add(dr);
                    }
                }

                TextBlock lblTotal  = new TextBlock();
                lblTotal.Text       = "TOTAL";
                lblTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblTotal.FontWeight = FontWeights.Bold;
                Border bdrTotal     = new Border();
                Grid.SetColumn(bdrTotal, 2);
                Grid.SetColumnSpan(bdrTotal, 3);
                bdrTotal.BorderThickness = new Thickness(1, 0, 1, 1);
                bdrTotal.BorderBrush     = Brushes.Black;
                bdrTotal.Child           = lblTotal;
                gridTotal.Children.Add(bdrTotal);

                TextBlock lblQuantityTotal  = new TextBlock();
                lblQuantityTotal.Text       = dt.Compute("Sum(Quantity)", "").ToString();
                lblQuantityTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblQuantityTotal.FontWeight = FontWeights.Bold;
                Border bdrQuantityTotal     = new Border();
                Grid.SetColumn(bdrQuantityTotal, 5);
                bdrQuantityTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrQuantityTotal.BorderBrush     = Brushes.Black;
                bdrQuantityTotal.Child           = lblQuantityTotal;
                gridTotal.Children.Add(bdrQuantityTotal);
                dgInventory.ItemsSource = dt.AsDataView();

                TextBlock lblReleaseTotal  = new TextBlock();
                lblReleaseTotal.Text       = dt.Compute("Sum(Release)", "").ToString();
                lblReleaseTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblReleaseTotal.FontWeight = FontWeights.Bold;
                Border bdrReleaseTotal     = new Border();
                Grid.SetColumn(bdrReleaseTotal, 6);
                bdrReleaseTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrReleaseTotal.BorderBrush     = Brushes.Black;
                bdrReleaseTotal.Child           = lblReleaseTotal;
                gridTotal.Children.Add(bdrReleaseTotal);
                dgInventory.ItemsSource = dt.AsDataView();

                for (int i = 0; i <= outsoleSupplierList.Count - 1; i++)
                {
                    TextBlock lblSupplierTotal  = new TextBlock();
                    lblSupplierTotal.Text       = dt.Compute(String.Format("Sum(Column{0})", i), "").ToString();
                    lblSupplierTotal.Margin     = new Thickness(1, 0, 0, 0);
                    lblSupplierTotal.FontWeight = FontWeights.Bold;
                    Border bdrSupplierTotal     = new Border();
                    Grid.SetColumn(bdrSupplierTotal, 7 + i);
                    bdrSupplierTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                    bdrSupplierTotal.BorderBrush     = Brushes.Black;
                    bdrSupplierTotal.Child           = lblSupplierTotal;
                    gridTotal.Children.Add(bdrSupplierTotal);
                }

                TextBlock lblMatchingTotal  = new TextBlock();
                lblMatchingTotal.Text       = dt.Compute("Sum(Matching)", "").ToString();
                lblMatchingTotal.Margin     = new Thickness(1, 0, 0, 0);
                lblMatchingTotal.FontWeight = FontWeights.Bold;
                Border bdrMatchingTotal     = new Border();
                Grid.SetColumn(bdrMatchingTotal, 7 + outsoleSupplierList.Count());
                bdrMatchingTotal.BorderThickness = new Thickness(0, 0, 1, 1);
                bdrMatchingTotal.BorderBrush     = Brushes.Black;
                bdrMatchingTotal.Child           = lblMatchingTotal;
                gridTotal.Children.Add(bdrMatchingTotal);
                dgInventory.ItemsSource = dt.AsDataView();
            }));
        }