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); } } } }