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