private void bwLoadSupplier_DoWork(object sender, DoWorkEventArgs e)
 {
     outsoleSupplierList    = OutsoleSuppliersController.Select();
     orderList              = OrdersController.Select();
     outsoleRawMaterialList = OutsoleRawMaterialController.Select();
     outsoleMaterialList    = OutsoleMaterialController.Select();
 }
 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);
 }
        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;
        }
Example #4
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList                   = OrdersController.Select();
            rawMaterialList             = RawMaterialController.Select();
            sewingMasterList            = SewingMasterController.Select();
            outsoleMasterList           = OutsoleMasterController.Select();
            sockliningMasterList        = SockliningMasterController.Select();
            assemblyMasterList          = AssemblyMasterController.Select();
            productionMemoList          = ProductionMemoController.Select();
            outsoleRawMaterialList      = OutsoleRawMaterialController.Select();
            rawMaterialViewModelNewList = RawMaterialController.Select_1();
            //sewingMasterList.RemoveAll(s => DateTimeHelper.Create(s.SewingBalance) != dtDefault && DateTimeHelper.Create(s.SewingBalance) != dtNothing);
            assemblyMasterList = assemblyMasterList.OrderBy(s => s.Sequence).ToList();
            int[] materialIdUpperArray    = { 1, 2, 3, 4, 10 };
            int[] materialIdSewingArray   = { 5, 7 };
            int[] materialIdOutsoleArray  = { 6 };
            int[] materialIdAssemblyArray = { 8, 9 };
            int[] materialIdCartonArray   = { 11 };

            foreach (AssemblyMasterModel assemblyMaster in assemblyMasterList)
            {
                AssemblyMasterExportViewModel assemblyMasterExportView = new AssemblyMasterExportViewModel();
                assemblyMasterExportView.Sequence  = assemblyMaster.Sequence;
                assemblyMasterExportView.ProductNo = assemblyMaster.ProductNo;
                OrdersModel order  = orderList.Where(o => o.ProductNo == assemblyMaster.ProductNo).FirstOrDefault();
                string      memoId = "";
                if (order != null)
                {
                    assemblyMasterExportView.Country   = order.Country;
                    assemblyMasterExportView.ShoeName  = order.ShoeName;
                    assemblyMasterExportView.ArticleNo = order.ArticleNo;
                    assemblyMasterExportView.LastCode  = order.LastCode;
                    assemblyMasterExportView.Quantity  = order.Quantity;
                    assemblyMasterExportView.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";
                        }
                    }
                    assemblyMasterExportView.MemoId = memoId;
                }

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

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

                //if (actualDateList.Count() > 0 && actualDateList.Contains(dtDefault) == false)
                //{
                //    assemblyMasterExportView.OutsoleMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", actualDateList.Max());
                //    assemblyMasterExportView.IsOutsoleMatsArrivalOk = true;
                //}
                //else
                //{
                //    var etdDateList = osRawMaterial.Select(s => s.ETD).ToList();
                //    if (etdDateList.Count() > 0)
                //    {
                //        assemblyMasterExportView.OutsoleMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", etdDateList.Max());
                //    }
                //}

                assemblyMasterExportView.IsOutsoleMatsArrivalOk = false;
                var rawMaterialViewModelNew = rawMaterialViewModelNewList.FirstOrDefault(f => f.ProductNo == order.ProductNo);
                if (String.IsNullOrEmpty(rawMaterialViewModelNew.OUTSOLE_Remarks) &&
                    !String.IsNullOrEmpty(rawMaterialViewModelNew.OUTSOLE_ActualDate))
                {
                    assemblyMasterExportView.OutsoleMatsArrival     = rawMaterialViewModelNew.OUTSOLE_ActualDate;
                    assemblyMasterExportView.IsOutsoleMatsArrivalOk = true;
                }
                else
                {
                    assemblyMasterExportView.OutsoleMatsArrival = rawMaterialViewModelNew.OUTSOLE_ETD;
                }

                MaterialArrivalViewModel materialArrivalAssembly = MaterialArrival(order.ProductNo, materialIdAssemblyArray);
                assemblyMasterExportView.IsAssemblyMatsArrivalOk = false;
                if (materialArrivalAssembly != null)
                {
                    assemblyMasterExportView.AssemblyMatsArrival     = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalAssembly.Date);
                    assemblyMasterExportView.IsAssemblyMatsArrivalOk = materialArrivalAssembly.IsMaterialArrivalOk;
                }

                MaterialArrivalViewModel materialArrivalCarton = MaterialArrival(order.ProductNo, materialIdCartonArray);
                if (materialArrivalCarton != null)
                {
                    assemblyMasterExportView.CartonMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalCarton.Date);
                }

                assemblyMasterExportView.AssemblyLine       = assemblyMaster.AssemblyLine;
                assemblyMasterExportView.AssemblyStartDate  = assemblyMaster.AssemblyStartDate;
                assemblyMasterExportView.AssemblyFinishDate = assemblyMaster.AssemblyFinishDate;
                assemblyMasterExportView.AssemblyQuota      = assemblyMaster.AssemblyQuota;
                assemblyMasterExportView.AssemblyBalance    = assemblyMaster.AssemblyBalance;

                SewingMasterModel sewingMaster = sewingMasterList.Where(o => o.ProductNo == assemblyMaster.ProductNo).FirstOrDefault();
                if (sewingMaster != null)
                {
                    assemblyMasterExportView.SewingStartDate  = sewingMaster.SewingStartDate;
                    assemblyMasterExportView.SewingFinishDate = sewingMaster.SewingFinishDate;
                    assemblyMasterExportView.SewingBalance    = sewingMaster.SewingBalance;
                }
                else
                {
                    assemblyMasterExportView.SewingStartDate  = dtDefault;
                    assemblyMasterExportView.SewingFinishDate = dtDefault;
                    assemblyMasterExportView.SewingBalance    = "";
                }

                OutsoleMasterModel outsoleMaster = outsoleMasterList.Where(o => o.ProductNo == assemblyMaster.ProductNo).FirstOrDefault();
                if (outsoleMaster != null)
                {
                    assemblyMasterExportView.OutsoleBalance = outsoleMaster.OutsoleBalance;
                }
                else
                {
                    assemblyMasterExportView.OutsoleBalance = "";
                }

                SockliningMasterModel sockliningMaster = sockliningMasterList.Where(o => o.ProductNo == assemblyMaster.ProductNo).FirstOrDefault();
                if (sockliningMaster != null)
                {
                    assemblyMasterExportView.InsoleBalance = sockliningMaster.InsoleBalance;
                    assemblyMasterExportView.InsockBalance = sockliningMaster.InsockBalance;
                }
                else
                {
                    assemblyMasterExportView.InsoleBalance = "";
                    assemblyMasterExportView.InsockBalance = "";
                }
                assemblyMasterExportViewList.Add(assemblyMasterExportView);
            }
        }
        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;
            }));
        }
Example #6
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;
        }
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            sewingMasterList   = SewingMasterController.Select();
            outsoleRawMaterial = OutsoleRawMaterialController.Select();
            var productNoList = orderList.Select(s => s.ProductNo).Distinct().ToList();

            sewingMasterList   = sewingMasterList.Where(w => productNoList.Contains(w.ProductNo)).ToList();
            outsoleRawMaterial = outsoleRawMaterial.Where(w => productNoList.Contains(w.ProductNo) && w.OutsoleSupplierId == supplier.OutsoleSupplierId).ToList();
            def = PrivateDefineController.GetDefine();

            var regex      = new Regex("[a-z]|[A-Z]");
            var sizeNoList = sizeRunList.Select(s => s.SizeNo).Distinct().OrderBy(s => regex.IsMatch(s) ? Double.Parse(regex.Replace(s, "100")) : Double.Parse(s)).ToList();

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

            Dispatcher.Invoke(new Action(() =>
            {
                // Column OutsoleCode
                dt.Columns.Add("ProductNo", typeof(String));
                DataGridTemplateColumn colPO = new DataGridTemplateColumn();
                colPO.Header                  = String.Format("ProductNo");
                DataTemplate tplPO            = new DataTemplate();
                FrameworkElementFactory tblPO = new FrameworkElementFactory(typeof(TextBlock));
                tplPO.VisualTree              = tblPO;
                tblPO.SetBinding(TextBlock.TextProperty, new Binding(String.Format("ProductNo")));
                tblPO.SetValue(TextBlock.FontWeightProperty, FontWeights.SemiBold);
                tblPO.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblPO.SetValue(TextBlock.PaddingProperty, new Thickness(3, 2, 3, 2));
                colPO.CellTemplate            = tplPO;
                colPO.SortMemberPath          = "ProductNo";
                colPO.ClipboardContentBinding = new Binding(String.Format("ProductNo"));
                dgWHDeliveryDetail.Columns.Add(colPO);

                // Column ArticleNo
                dt.Columns.Add("ArticleNo", typeof(String));
                DataGridTemplateColumn colArticleNo = new DataGridTemplateColumn();
                colArticleNo.Header                  = String.Format("ArticleNo");
                DataTemplate tplArticleNo            = new DataTemplate();
                FrameworkElementFactory tblArticleNo = new FrameworkElementFactory(typeof(TextBlock));
                tplArticleNo.VisualTree              = tblArticleNo;
                tblArticleNo.SetBinding(TextBlock.TextProperty, new Binding(String.Format("ArticleNo")));
                tblArticleNo.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblArticleNo.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colArticleNo.CellTemplate            = tplArticleNo;
                colArticleNo.SortMemberPath          = "ArticleNo";
                colArticleNo.ClipboardContentBinding = new Binding(String.Format("ArticleNo"));
                dgWHDeliveryDetail.Columns.Add(colArticleNo);

                // Column OrderEFD
                dt.Columns.Add("OrderEFD", typeof(DateTime));
                DataGridTemplateColumn colEFDOrder = new DataGridTemplateColumn();
                colEFDOrder.Header                  = String.Format("Order\nEFD");
                DataTemplate tplEFDOrder            = new DataTemplate();
                FrameworkElementFactory tblEFDOrder = new FrameworkElementFactory(typeof(TextBlock));
                tplEFDOrder.VisualTree              = tblEFDOrder;

                Binding bindingOrderEFD      = new Binding();
                bindingOrderEFD.Path         = new PropertyPath("OrderEFD");
                bindingOrderEFD.StringFormat = "dd-MMM";

                //tblEFDOrder.SetBinding(TextBlock.TextProperty, new Binding(String.Format("OrderEFD")));
                tblEFDOrder.SetBinding(TextBlock.TextProperty, bindingOrderEFD);
                tblEFDOrder.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblEFDOrder.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colEFDOrder.SortMemberPath          = "OrderEFD";
                colEFDOrder.ClipboardContentBinding = bindingOrderEFD;
                colEFDOrder.CellTemplate            = tplEFDOrder;
                dgWHDeliveryDetail.Columns.Add(colEFDOrder);

                // Column DeliveryEFD
                dt.Columns.Add("DeliveryEFD", typeof(DateTime));
                DataGridTemplateColumn colEFDDelivery = new DataGridTemplateColumn();
                colEFDDelivery.Header                  = String.Format("Delivery\nEFD");
                DataTemplate tplEFDDelivery            = new DataTemplate();
                FrameworkElementFactory tblEFDDelivery = new FrameworkElementFactory(typeof(TextBlock));
                tplEFDDelivery.VisualTree              = tblEFDDelivery;

                Binding bindingDeliveryEFD      = new Binding();
                bindingDeliveryEFD.Path         = new PropertyPath("DeliveryEFD");
                bindingDeliveryEFD.StringFormat = "dd-MMM";

                //tblEFDDelivery.SetBinding(TextBlock.TextProperty, new Binding(String.Format("DeliveryEFD")));
                tblEFDDelivery.SetBinding(TextBlock.TextProperty, bindingDeliveryEFD);
                tblEFDDelivery.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblEFDDelivery.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colEFDDelivery.SortMemberPath          = "DeliveryEFD";
                colEFDDelivery.ClipboardContentBinding = bindingDeliveryEFD;
                colEFDDelivery.CellTemplate            = tplEFDDelivery;
                dgWHDeliveryDetail.Columns.Add(colEFDDelivery);

                // Column SewingStart
                dt.Columns.Add("SewingStartDate", typeof(DateTime));
                DataGridTemplateColumn colSewingStart = new DataGridTemplateColumn();
                colSewingStart.Header                  = String.Format("Sewing\nStart");
                DataTemplate tplSewingStart            = new DataTemplate();
                FrameworkElementFactory tblSewingStart = new FrameworkElementFactory(typeof(TextBlock));
                tplSewingStart.VisualTree              = tblSewingStart;

                Binding bindingSewingStart      = new Binding();
                bindingSewingStart.Path         = new PropertyPath("SewingStartDate");
                bindingSewingStart.StringFormat = "dd-MMM";

                //tblSewingStart.SetBinding(TextBlock.TextProperty, new Binding(String.Format("SewingStartDate")));
                tblSewingStart.SetBinding(TextBlock.TextProperty, bindingSewingStart);
                tblSewingStart.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblSewingStart.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colSewingStart.SortMemberPath          = "SewingStartDate";
                colSewingStart.ClipboardContentBinding = bindingSewingStart;
                colSewingStart.CellTemplate            = tplSewingStart;
                dgWHDeliveryDetail.Columns.Add(colSewingStart);

                // Column QuantityOrder
                dt.Columns.Add("QuantityOrder", typeof(Int32));
                DataGridTemplateColumn colQtyOrder = new DataGridTemplateColumn();
                colQtyOrder.Header                  = String.Format("Quantity\nOrder");
                DataTemplate tplQtyOrder            = new DataTemplate();
                FrameworkElementFactory tblQtyOrder = new FrameworkElementFactory(typeof(TextBlock));
                tplQtyOrder.VisualTree              = tblQtyOrder;
                tblQtyOrder.SetBinding(TextBlock.TextProperty, new Binding(String.Format("QuantityOrder")));
                tblQtyOrder.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                tblQtyOrder.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblQtyOrder.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colQtyOrder.CellTemplate            = tplQtyOrder;
                colQtyOrder.SortMemberPath          = "QuantityOrder";
                colQtyOrder.ClipboardContentBinding = new Binding(String.Format("QuantityOrder"));
                dgWHDeliveryDetail.Columns.Add(colQtyOrder);

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

                // Column Delivery
                dt.Columns.Add("Delivery", typeof(Int32));
                DataGridTemplateColumn colDelivery = new DataGridTemplateColumn();
                colDelivery.Header                  = String.Format("Delivery");
                DataTemplate tplDelivery            = new DataTemplate();
                FrameworkElementFactory tblDelivery = new FrameworkElementFactory(typeof(TextBlock));
                tplDelivery.VisualTree              = tblDelivery;
                tblDelivery.SetBinding(TextBlock.TextProperty, new Binding(String.Format("Delivery")));
                tblDelivery.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                tblDelivery.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblDelivery.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colDelivery.CellTemplate            = tplDelivery;
                colDelivery.SortMemberPath          = "Delivery";
                colDelivery.ClipboardContentBinding = new Binding(String.Format("Delivery"));
                dgWHDeliveryDetail.Columns.Add(colDelivery);

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

                // Column SizeNo
                for (int i = 0; i < sizeNoList.Count(); i++)
                {
                    var sizeRun_Size = sizeRunList.FirstOrDefault(w => w.SizeNo == sizeNoList[i]);
                    if (sizeRun_Size == null)
                    {
                        continue;
                    }
                    string outsoleSize = "", midsoleSize = "";
                    if (sizeRun_Size != null)
                    {
                        outsoleSize = sizeRun_Size.OutsoleSize;
                        midsoleSize = sizeRun_Size.MidsoleSize;
                    }

                    string sizeID = sizeRun_Size.SizeNo.Contains(".") == true ? sizeRun_Size.SizeNo.Replace(".", "@") : sizeRun_Size.SizeNo;

                    dt.Columns.Add(String.Format("Column{0}", sizeID), typeof(String));
                    dt.Columns.Add(String.Format("ColumnBackground{0}", sizeID), typeof(SolidColorBrush));
                    dt.Columns.Add(String.Format("ColumnForeground{0}", sizeID), typeof(SolidColorBrush));
                    dt.Columns.Add(String.Format("ColumnTooltip{0}", sizeID), typeof(String));
                    DataGridTemplateColumn colSize = new DataGridTemplateColumn();

                    if (def.ShowOSSizeValue)
                    {
                        colSize.Header = String.Format("{0}\n{1}\n", sizeNoList[i], outsoleSize);
                    }
                    else
                    {
                        colSize.Header = String.Format("\n{0}\n", sizeNoList[i], "");
                    }

                    colSize.MinWidth                = 35;
                    DataTemplate tplSize            = new DataTemplate();
                    FrameworkElementFactory tblSize = new FrameworkElementFactory(typeof(TextBlock));
                    tplSize.VisualTree              = tblSize;
                    tblSize.SetBinding(TextBlock.TextProperty, new Binding(String.Format("Column{0}", sizeID)));
                    tblSize.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                    tblSize.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                    tblSize.SetValue(TextBlock.PaddingProperty, new Thickness(3, 3, 3, 3));

                    tblSize.SetValue(TextBlock.BackgroundProperty, new Binding(String.Format("ColumnBackground{0}", sizeID)));
                    tblSize.SetValue(TextBlock.ForegroundProperty, new Binding(String.Format("ColumnForeground{0}", sizeID)));
                    tblSize.SetValue(TextBlock.ToolTipProperty, new Binding(String.Format("ColumnTooltip{0}", sizeID)));

                    colSize.CellTemplate            = tplSize;
                    colSize.ClipboardContentBinding = new Binding(String.Format("Column{0}", sizeID));
                    dgWHDeliveryDetail.Columns.Add(colSize);
                }
                // Column Balance
                dt.Columns.Add("TotalBalance", typeof(Int32));
                DataGridTemplateColumn colBalance = new DataGridTemplateColumn();
                colBalance.Header                  = String.Format("Total\nBalance");
                DataTemplate tplBalance            = new DataTemplate();
                FrameworkElementFactory tblBalance = new FrameworkElementFactory(typeof(TextBlock));
                tplBalance.VisualTree              = tblBalance;
                tblBalance.SetBinding(TextBlock.TextProperty, new Binding(String.Format("TotalBalance")));
                tblBalance.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                tblBalance.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblBalance.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colBalance.CellTemplate            = tplBalance;
                colBalance.SortMemberPath          = "TotalBalance";
                colBalance.ClipboardContentBinding = new Binding(String.Format("TotalBalance"));
                dgWHDeliveryDetail.Columns.Add(colBalance);

                // Column Reject
                dt.Columns.Add("ReleasePainting", typeof(Int32));
                DataGridTemplateColumn colReleasePainting = new DataGridTemplateColumn();
                colReleasePainting.Header                  = String.Format("Release\nPainting");
                DataTemplate tplReleasePainting            = new DataTemplate();
                FrameworkElementFactory tblReleasePainting = new FrameworkElementFactory(typeof(TextBlock));
                tplReleasePainting.VisualTree              = tblReleasePainting;
                tblReleasePainting.SetBinding(TextBlock.TextProperty, new Binding(String.Format("ReleasePainting")));
                tblReleasePainting.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                tblReleasePainting.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
                tblReleasePainting.SetValue(TextBlock.PaddingProperty, new Thickness(3, 0, 0, 0));
                colReleasePainting.CellTemplate            = tplReleasePainting;
                colReleasePainting.SortMemberPath          = "ReleasePainting";
                colReleasePainting.ClipboardContentBinding = new Binding(String.Format("ReleasePainting"));
                dgWHDeliveryDetail.Columns.Add(colReleasePainting);
            }));

            // Binding Data
            if (productNoList.Count > 0)
            {
                productNoList = productNoList.OrderBy(o => o).ToList();
            }

            foreach (var productNo in productNoList)
            {
                DataRow dr = dt.NewRow();

                var order_PO         = orderList.FirstOrDefault(w => w.ProductNo == productNo);
                var osMaterial_PO    = outsoleMaterialList.Where(w => w.ProductNo == productNo).ToList();
                var osRawMaterial_PO = outsoleRawMaterial.FirstOrDefault(w => w.ProductNo == productNo);
                var sewingMaster_PO  = sewingMasterList.FirstOrDefault(w => w.ProductNo == productNo);
                var osRelease_PO     = outsoleReleaseList.Where(w => w.ProductNo == productNo).ToList();

                var contentStatusList = new List <ContentStatus>();
                var sizeRunList_PO    = sizeRunList.Where(w => w.ProductNo == productNo).ToList();
                for (int i = 0; i < sizeNoList.Count(); i++)
                {
                    string sizeNo        = sizeNoList[i];
                    var    contentStatus = new ContentStatus();
                    var    sizeRun_Size  = sizeRunList_PO.FirstOrDefault(w => w.SizeNo == sizeNo);
                    string sizeID        = sizeNo.Contains(".") == true?sizeNo.Replace(".", "@") : sizeNo;

                    // if has balance, show balance = qty - delivery + reject
                    // if contains reject highlight
                    int qtyOrder_Size    = sizeRun_Size != null ? sizeRun_Size.Quantity : 0;
                    int qtyDelivery_Size = osMaterial_PO.FirstOrDefault(w => w.SizeNo == sizeNo) != null?osMaterial_PO.FirstOrDefault(w => w.SizeNo == sizeNo).Quantity : 0;

                    int qtyReject_Size = osMaterial_PO.FirstOrDefault(w => w.SizeNo == sizeNo) != null?osMaterial_PO.FirstOrDefault(w => w.SizeNo == sizeNo).QuantityReject : 0;

                    // Default Color
                    contentStatus.WidthDefaultCell = 5;
                    contentStatus.BorderColorCell  = System.Drawing.Color.LightGray;
                    contentStatus.ForegroundCell   = System.Drawing.Color.Black;
                    contentStatus.BackgroundCell   = System.Drawing.Color.Transparent;

                    int qtyBalance_Size = qtyOrder_Size - qtyDelivery_Size;
                    if (qtyBalance_Size > 0)
                    {
                        dr[String.Format("Column{0}", sizeID)]           = qtyBalance_Size;
                        dr[String.Format("ColumnBackground{0}", sizeID)] = Brushes.Tomato;
                        contentStatus.Quantity = qtyBalance_Size;
                    }
                    if (qtyReject_Size > 0)
                    {
                        dr[String.Format("Column{0}", sizeID)]           = qtyReject_Size;
                        dr[String.Format("ColumnForeground{0}", sizeID)] = Brushes.Red;

                        contentStatus.Quantity       = qtyReject_Size;
                        contentStatus.ForegroundCell = System.Drawing.Color.Red;
                        if (qtyBalance_Size > 0)
                        {
                            int qtyBalanceTotal = qtyBalance_Size + qtyReject_Size;

                            dr[String.Format("Column{0}", sizeID)]           = qtyBalanceTotal;
                            dr[String.Format("ColumnBackground{0}", sizeID)] = Brushes.Yellow;
                            dr[String.Format("ColumnTooltip{0}", sizeID)]    = String.Format("Balance: {0}\nReject : {1}", qtyBalance_Size, qtyReject_Size);

                            contentStatus.Quantity       = qtyBalanceTotal;
                            contentStatus.BackgroundCell = System.Drawing.Color.Yellow;
                        }
                    }
                    //
                    //if (qtyBalance_Size > 0 || qtyReject_Size > 0)
                    contentStatusList.Add(contentStatus);
                }

                var articleNo          = order_PO != null ? order_PO.ArticleNo : "";
                var orderEFD           = order_PO != null ? order_PO.ETD : new DateTime(2000, 1, 1);
                var delEFD             = osRawMaterial_PO != null ? osRawMaterial_PO.ETD : new DateTime(2000, 1, 1);
                var sewStart           = sewingMaster_PO != null ? sewingMaster_PO.SewingStartDate : new DateTime(2000, 1, 1);
                var release            = osRelease_PO.Sum(s => s.Quantity);
                var qtyOrder           = sizeRunList_PO.Sum(s => s.Quantity);
                var qtyDelivery        = osMaterial_PO.Sum(s => s.Quantity);
                var qtyReject          = osMaterial_PO.Sum(s => s.QuantityReject);
                var qtyReleasePainting = osMaterial_PO.FirstOrDefault().TotalReleasePainting;

                dr["ProductNo"]       = productNo;
                dr["ArticleNo"]       = articleNo;
                dr["OrderEFD"]        = orderEFD;
                dr["DeliveryEFD"]     = delEFD;
                dr["SewingStartDate"] = sewStart;
                dr["QuantityOrder"]   = qtyOrder;
                dr["Release"]         = release;
                dr["Delivery"]        = qtyDelivery;
                dr["Reject"]          = qtyReject;
                dr["TotalBalance"]    = qtyOrder - qtyDelivery + qtyReject;
                dr["ReleasePainting"] = qtyReleasePainting;


                dt.Rows.Add(dr);
                var excelExportModel = new ExportExcelModel()
                {
                    ProductNo            = productNo,
                    ArticleNo            = articleNo,
                    OrderEFD             = orderEFD,
                    DeliveryEFD          = delEFD,
                    SewingStartDate      = sewStart,
                    QuantityOrder        = qtyOrder,
                    Release              = release,
                    Delivery             = qtyDelivery,
                    Reject               = qtyReject,
                    ContentStatusList    = contentStatusList,
                    TotalBalance         = qtyOrder - qtyDelivery + qtyReject,
                    TotalReleasePainting = qtyReleasePainting,
                };
                excelExportList.Add(excelExportModel);
            }
            DataRow drTotal = dt.NewRow();

            drTotal["ProductNo"]       = "Total";
            drTotal["QuantityOrder"]   = string.Format("{0:#,0}", dt.Compute("Sum(QuantityOrder)", "").ToString());
            drTotal["Release"]         = string.Format("{0:#,0}", dt.Compute("Sum(Release)", "").ToString());
            drTotal["Delivery"]        = string.Format("{0:#,0}", dt.Compute("Sum(Delivery)", "").ToString());
            drTotal["Reject"]          = string.Format("{0:#,0}", dt.Compute("Sum(Reject)", "").ToString());
            drTotal["TotalBalance"]    = string.Format("{0:#,0}", dt.Compute("Sum(TotalBalance)", "").ToString());
            drTotal["ReleasePainting"] = string.Format("{0:#,0}", dt.Compute("Sum(ReleasePainting)", "").ToString());

            dt.Rows.Add(drTotal);
            e.Result = dt;
        }
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList         = OrdersController.Select();
            rawMaterialList   = RawMaterialController.Select();
            sewingMasterList  = SewingMasterController.Select();
            outsoleMasterList = OutsoleMasterController.Select();

            productionMemoList          = ProductionMemoController.Select();
            outsoleRawMaterialList      = OutsoleRawMaterialController.Select();
            rawMaterialViewModelNewList = RawMaterialController.Select_1();

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

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

            foreach (SewingMasterModel sewingMaster in sewingMasterList)
            {
                SewingMasterExportViewModel sewingMasterExportView = new SewingMasterExportViewModel();
                sewingMasterExportView.Sequence  = sewingMaster.Sequence;
                sewingMasterExportView.ProductNo = sewingMaster.ProductNo;
                OrdersModel order = orderList.Where(o => o.ProductNo == sewingMaster.ProductNo).FirstOrDefault();

                string memoId = "";

                if (order != null)
                {
                    sewingMasterExportView.Country   = order.Country;
                    sewingMasterExportView.ShoeName  = order.ShoeName;
                    sewingMasterExportView.ArticleNo = order.ArticleNo;
                    sewingMasterExportView.PatternNo = order.PatternNo;
                    sewingMasterExportView.Quantity  = order.Quantity;
                    sewingMasterExportView.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";
                        }
                    }
                    sewingMasterExportView.MemoId = memoId;
                }

                MaterialArrivalViewModel materialArrivalUpper = MaterialArrival(order.ProductNo, materialIdUpperArray);
                sewingMasterExportView.IsUpperMatsArrivalOk = false;
                if (materialArrivalUpper != null)
                {
                    sewingMasterExportView.UpperMatsArrival     = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalUpper.Date);
                    sewingMasterExportView.IsUpperMatsArrivalOk = materialArrivalUpper.IsMaterialArrivalOk;
                }

                MaterialArrivalViewModel materialArrivalSewing = MaterialArrival(order.ProductNo, materialIdSewingArray);
                sewingMasterExportView.IsSewingMatsArrivalOk = false;
                if (materialArrivalSewing != null)
                {
                    sewingMasterExportView.SewingMatsArrival     = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalSewing.Date);
                    sewingMasterExportView.IsSewingMatsArrivalOk = materialArrivalSewing.IsMaterialArrivalOk;
                }

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

                // For Outsole Material
                //var osRawMaterial = outsoleRawMaterialList.Where(w => w.ProductNo == order.ProductNo).ToList();
                //var actualDateList = osRawMaterial.Select(s => s.ActualDate).ToList();
                //sewingMasterExportView.IsOSMatsArrivalOk = false;

                //if (actualDateList.Count() > 0 && actualDateList.Contains(dtDefault) == false)
                //{
                //    sewingMasterExportView.OSMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", actualDateList.Max());
                //    sewingMasterExportView.IsOSMatsArrivalOk = true;
                //}
                //else
                //{
                //    var etdDateList = osRawMaterial.Select(s => s.ETD).ToList();
                //    if (etdDateList.Count() > 0)
                //    {
                //        sewingMasterExportView.OSMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", etdDateList.Max());
                //    }
                //}

                var rawMaterialViewModelNew = rawMaterialViewModelNewList.FirstOrDefault(f => f.ProductNo == order.ProductNo);
                sewingMasterExportView.IsOSMatsArrivalOk = false;
                if (String.IsNullOrEmpty(rawMaterialViewModelNew.OUTSOLE_Remarks) &&
                    !String.IsNullOrEmpty(rawMaterialViewModelNew.OUTSOLE_ActualDate))
                {
                    sewingMasterExportView.OSMatsArrival     = rawMaterialViewModelNew.OUTSOLE_ActualDate;
                    sewingMasterExportView.IsOSMatsArrivalOk = true;
                }
                else
                {
                    sewingMasterExportView.OSMatsArrival = rawMaterialViewModelNew.OUTSOLE_ETD;
                }

                sewingMasterExportView.SewingLine       = sewingMaster.SewingLine;
                sewingMasterExportView.CutAStartDate    = sewingMaster.CutAStartDate;
                sewingMasterExportView.SewingStartDate  = sewingMaster.SewingStartDate;
                sewingMasterExportView.SewingFinishDate = sewingMaster.SewingFinishDate;
                sewingMasterExportView.SewingQuota      = sewingMaster.SewingQuota;
                sewingMasterExportView.SewingBalance    = sewingMaster.SewingBalance;
                sewingMasterExportView.CutABalance      = sewingMaster.CutABalance;
                sewingMasterExportView.CutBBalance      = sewingMaster.CutBBalance;

                OutsoleMasterModel outsoleMaster = outsoleMasterList.Where(o => o.ProductNo == sewingMaster.ProductNo).FirstOrDefault();
                if (outsoleMaster != null)
                {
                    sewingMasterExportView.OSBalance = outsoleMaster.OutsoleBalance;
                }
                else
                {
                    sewingMasterExportView.OSBalance = "";
                }

                sewingMasterExportViewList.Add(sewingMasterExportView);
            }
        }
Example #9
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);
            }
        }
        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;
        }
Example #11
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);
                        }
                    }
                }
            }
        }
Example #12
0
        void threadLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            //outsoleRawMaterialList = OutsoleRawMaterialController.Select();
            outsoleRawMaterialList = OutsoleRawMaterialController.Select();
            outsoleMaterialList    = OutsoleMaterialController.SelectByOutsoleRawMaterial();
            sizeRunList            = SizeRunController.SelectByOutsoleRawMaterial();
            outsoleSupplierList    = OutsoleSuppliersController.Select();
            orderList        = OrdersController.SelectByOutsoleRawMaterial();
            sewingMasterList = SewingMasterController.Select();

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

            foreach (string productNo in productNoList)
            {
                OrdersModel order = orderList.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).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)
                {
                    //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.Where(o => o.OutsoleSupplierId == outsoleRawMaterial.OutsoleSupplierId).FirstOrDefault();
                        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))));
                        outsoleDeliveryStatusView.ActualQuantity = actualQty.ToString();

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

                        outsoleDeliveryStatusView.IsFinished = false;
                        if (actualQty >= order.Quantity) // && outsoleRawMaterial.ActualDate != dtDefault
                        {
                            outsoleDeliveryStatusView.IsFinished = true;
                        }

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

                        outsoleDeliveryStatusViewList.Add(outsoleDeliveryStatusView);
                    }
                }
            }
        }