private void dgInventory_MouseDoubleClick(object sender, MouseButtonEventArgs e) { UpperWHInventoryViewModel upperWHInventoryView = (UpperWHInventoryViewModel)dgInventory.CurrentItem; if (upperWHInventoryView != null) { List <String> productNoList = upperWHInventoryView.ProductNoList; UpperWHInventoryDetailWindow window = new UpperWHInventoryDetailWindow( productNoList, sewingOutputList.Where(s => productNoList.Contains(s.ProductNo) == true).ToList(), outsoleOutputList.Where(o => productNoList.Contains(o.ProductNo) == true).ToList(), assemblyReleaseList.Where(a => productNoList.Contains(a.ProductNo) == true).ToList(), orderList.Where(o => productNoList.Contains(o.ProductNo) == true).ToList() ); window.Title = String.Format("{0} for {1}", window.Title, upperWHInventoryView.AssemblyLine); window.Show(); } }
private void bwLoadData_DoWork(object sender, DoWorkEventArgs e) { assemblyMasterList = AssemblyMasterController.Select(); sewingOutputList = SewingOutputController.SelectByAssemblyMaster(); outsoleOutputList = OutsoleOutputController.SelectByAssemblyMaster(); assemblyReleaseList = AssemblyReleaseController.SelectByAssemblyMaster(); orderList = OrdersController.Select(); sockliningInputList = SockliningInputController.SelectByAssemblyMaster(); sizeRunList = SizeRunController.SelectIsEnable(); rawMaterialViewModelNewList = RawMaterialController.Select_1(); List <UpperWHInventoryViewModel> upperWHInventoryList = new List <UpperWHInventoryViewModel>(); List <UpperWHInventoryViewModel> upperWHInventoryList_1 = new List <UpperWHInventoryViewModel>(); var POList = orderList.Select(s => s.ProductNo).Distinct().ToList(); foreach (var productNo in POList) { var assemblyMaster_PO = assemblyMasterList.FirstOrDefault(w => w.ProductNo == productNo); var assemblyRelease_PO = assemblyReleaseList.Where(w => w.ProductNo == productNo).ToList(); var sewingOutput_PO = sewingOutputList.Where(w => w.ProductNo == productNo).ToList(); var outsoleOutput_PO = outsoleOutputList.Where(w => w.ProductNo == productNo).ToList(); var sockliningInput_PO = sockliningInputList.Where(w => w.ProductNo == productNo).ToList(); var sizeNoList = sizeRunList.Where(w => w.ProductNo == productNo).Select(s => s.SizeNo).ToList(); int qtyUpper_PO = 0, qtyOutsole_PO = 0, qtySocklining_PO = 0, qtyMatch_PO = 0, qtyMatchWithSocklining_PO = 0; foreach (var sizeNo in sizeNoList) { int qtyAssemblyRelease_Size = assemblyRelease_PO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Quantity); int qtySewingOutput_Size = sewingOutput_PO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Quantity); int qtyOutsoleOutput_Size = outsoleOutput_PO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Quantity); int qtySocklining_Size = sockliningInput_PO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Quantity); int qtyUpper = qtySewingOutput_Size - qtyAssemblyRelease_Size; if (qtyUpper < 0) { qtyUpper = 0; } qtyUpper_PO += qtyUpper; int qtyOutsole = qtyOutsoleOutput_Size - qtyAssemblyRelease_Size; if (qtyOutsole < 0) { qtyOutsole = 0; } qtyOutsole_PO += qtyOutsole; int qtySocklining = qtySocklining_Size - qtyAssemblyRelease_Size; if (qtySocklining < 0) { qtySocklining = 0; } qtySocklining_PO += qtySocklining; int qtyMatch = Math.Min(qtySewingOutput_Size, qtyOutsoleOutput_Size) - qtyAssemblyRelease_Size; if (qtyMatch < 0) { qtyMatch = 0; } qtyMatch_PO += qtyMatch; List <Int32> materialList = new List <Int32>(); materialList.Add(qtySewingOutput_Size > 0 ? qtySewingOutput_Size : 0); materialList.Add(qtyOutsoleOutput_Size > 0 ? qtyOutsoleOutput_Size : 0); materialList.Add(qtySocklining_Size > 0 ? qtySocklining_Size : 0); int qtyMatchWithSocklining = materialList.Min() - qtyAssemblyRelease_Size; if (qtyMatchWithSocklining < 0) { qtyMatchWithSocklining = 0; } qtyMatchWithSocklining_PO += qtyMatchWithSocklining; } string assemblyLine_PO = assemblyMaster_PO != null ? assemblyMaster_PO.AssemblyLine : ""; var upperInventory_PO = new UpperWHInventoryViewModel() { AssemblyLine = assemblyLine_PO, SewingOutput = qtyUpper_PO, OutsoleOutput = qtyOutsole_PO, SockliningInput = qtySocklining_PO, Matching = qtyMatch_PO, MatchingWithSocklining = qtyMatchWithSocklining_PO, }; upperWHInventoryList.Add(upperInventory_PO); } var assemblyLineList = upperWHInventoryList.Select(s => s.AssemblyLine).Distinct().ToList(); if (assemblyLineList.Count() > 0) { assemblyLineList = assemblyLineList.OrderBy(o => o).ToList(); } var regex = new Regex(@"\D"); var assemblyLineCustomList = assemblyLineList.Select(s => new { Line = s, LineNumber = regex.IsMatch(s) ? regex.Replace(s, "") : s }).ToList(); if (assemblyLineCustomList.Count() > 0) { assemblyLineCustomList = assemblyLineCustomList.OrderBy(o => String.IsNullOrEmpty(o.LineNumber) ? 100 : Int32.Parse(o.LineNumber)).ThenBy(th => th.Line).ToList(); } foreach (var assemblyLineCustom in assemblyLineCustomList) { var assemblyLine = assemblyLineCustom.Line; var upperWHInventoryByAssemblyLine = upperWHInventoryList.Where(w => w.AssemblyLine == assemblyLine).ToList(); var productNoList_Assembly = assemblyMasterList.Where(w => w.AssemblyLine == assemblyLine).Select(s => s.ProductNo).Distinct().ToList(); var upperInventory = new UpperWHInventoryViewModel() { AssemblyLine = assemblyLine, ProductNoList = productNoList_Assembly, SewingOutput = upperWHInventoryByAssemblyLine.Sum(s => s.SewingOutput), OutsoleOutput = upperWHInventoryByAssemblyLine.Sum(s => s.OutsoleOutput), SockliningInput = upperWHInventoryByAssemblyLine.Sum(s => s.SockliningInput), Matching = upperWHInventoryByAssemblyLine.Sum(s => s.Matching), }; upperWHInventoryViewList.Add(upperInventory); var upperInventory_1 = new UpperWHInventoryViewModel() { AssemblyLine = assemblyLine, ProductNoList = productNoList_Assembly, SewingOutput = upperWHInventoryByAssemblyLine.Sum(s => s.SewingOutput), OutsoleOutput = upperWHInventoryByAssemblyLine.Sum(s => s.OutsoleOutput), SockliningInput = upperWHInventoryByAssemblyLine.Sum(s => s.SockliningInput), Matching = upperWHInventoryByAssemblyLine.Sum(s => s.MatchingWithSocklining), }; upperWHInventoryViewList_WithSocklining.Add(upperInventory_1); } }
private void bwLoadData_DoWork(object sender, DoWorkEventArgs e) { assemblyMasterList = AssemblyMasterController.Select(); sewingOutputList = SewingOutputController.SelectByAssemblyMaster(); outsoleOutputList = OutsoleOutputController.SelectByAssemblyMaster(); assemblyReleaseList = AssemblyReleaseController.SelectByAssemblyMaster(); orderList = OrdersController.SelectByAssemblyMaster(); List <UpperWHInventoryViewModel> upperWHInventoryViewList = new List <UpperWHInventoryViewModel>(); assemblyLineList = assemblyMasterList.Where(a => String.IsNullOrEmpty(a.AssemblyLine) == false).Select(a => a.AssemblyLine).Distinct().OrderBy(l => l).ToList(); foreach (string assemblyLine in assemblyLineList) { List <String> productNoList = assemblyMasterList.Where(a => a.AssemblyLine == assemblyLine).Select(o => o.ProductNo).Distinct().ToList(); List <AssemblyReleaseModel> assemblyReleaseList_D1 = assemblyReleaseList.Where(a => productNoList.Contains(a.ProductNo) == true).ToList(); List <SewingOutputModel> sewingOutputList_D1 = sewingOutputList.Where(s => productNoList.Contains(s.ProductNo) == true).ToList(); List <OutsoleOutputModel> outsoleOutputList_D1 = outsoleOutputList.Where(o => productNoList.Contains(o.ProductNo) == true).ToList(); int qtyUpperTotal = 0; int qtyOutsoleTotal = 0; int qtyMatchTotal = 0; foreach (string productNo in productNoList) { List <AssemblyReleaseModel> assemblyReleaseList_D2 = assemblyReleaseList_D1.Where(a => a.ProductNo == productNo).ToList(); List <SewingOutputModel> sewingOutputList_D2 = sewingOutputList_D1.Where(s => s.ProductNo == productNo).ToList(); List <OutsoleOutputModel> outsoleOutputList_D2 = outsoleOutputList_D1.Where(o => o.ProductNo == productNo).ToList(); List <String> sizeNoList = sewingOutputList_D2.Select(s => s.SizeNo).Distinct().ToList(); if (sizeNoList.Count == 0) { sizeNoList = outsoleOutputList_D2.Select(o => o.SizeNo).Distinct().ToList(); } foreach (string sizeNo in sizeNoList) { int qtyRelease = assemblyReleaseList_D2.Where(a => a.SizeNo == sizeNo).Sum(a => a.Quantity); int qtyUpper = sewingOutputList_D2.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity) - qtyRelease; int qtyOutsole = outsoleOutputList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity) - qtyRelease; int qtyMatch = MatchingHelper.Calculate(sewingOutputList_D2.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity), outsoleOutputList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity), sizeNo) - qtyRelease; if (qtyUpper < 0) { qtyUpper = 0; } qtyUpperTotal += qtyUpper; if (qtyOutsole < 0) { qtyOutsole = 0; } qtyOutsoleTotal += qtyOutsole; if (qtyMatch < 0) { qtyMatch = 0; } qtyMatchTotal += qtyMatch; } } UpperWHInventoryViewModel upperWHInventoryView = new UpperWHInventoryViewModel { AssemblyLine = assemblyLine, ProductNoList = productNoList, SewingOutput = qtyUpperTotal, OutsoleOutput = qtyOutsoleTotal, Matching = qtyMatchTotal, }; upperWHInventoryViewList.Add(upperWHInventoryView); } e.Result = upperWHInventoryViewList; }