Exemple #1
0
        private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            materialTypeList = MaterialTypeController.Select().Where(w => w.MaterialGroup.Contains("UPPER")).ToList();
            orderList        = OrdersController.Select();
            rawMaterialList  = RawMaterialController.Select();
            sewingMasterList = SewingMasterController.SelectByProductNo();

            DataTable dt = new DelayDataSet().Tables["DelayTable"];

            List <String> productNoList       = rawMaterialList.Select(r => r.ProductNo).Distinct().ToList();
            var           materialUpperIdList = materialTypeList.Select(s => s.MaterialTypeId).Distinct().ToList();

            foreach (string productNo in productNoList)
            {
                OrdersModel order = orderList.Where(o => o.ProductNo == productNo).FirstOrDefault();

                List <Int32> materialTypeIdList = rawMaterialList.Where(w => materialUpperIdList.Contains(w.MaterialTypeId)).Select(r => r.MaterialTypeId).Distinct().ToList();
                // get assemblyline from productNo
                //AssemblyMasterModel assemblyMaster = assemblyMasterList.Where(o => o.ProductNo == productNo).FirstOrDefault();

                // get sewingLing from productNo
                SewingMasterModel sewingMaster = sewingMasterList.Where(o => o.ProductNo == productNo).FirstOrDefault();
                //materialTypeIdList.Remove(6);
                //materialTypeIdList.Remove(11);
                //materialTypeIdList.Remove(12);
                //materialTypeIdList.Remove(13);
                //materialTypeIdList.Remove(14);

                foreach (int materialTypeId in materialTypeIdList)
                {
                    RawMaterialModel rawMaterial = rawMaterialList.Where(r => r.ProductNo == productNo && r.MaterialTypeId == materialTypeId).FirstOrDefault();
                    if (rawMaterial != null && rawMaterial.ETD.Date != new DateTime(2000, 1, 1) && rawMaterial.ETD.Date < DateTime.Now.Date &&
                        rawMaterial.ActualDate.Date == new DateTime(2000, 1, 1))
                    {
                        DataRow dr = dt.NewRow();
                        // binding data to reportviewer
                        dr["SewingLine"] = sewingMaster.SewingLine;
                        dr["ProductNo"]  = productNo;
                        if (order != null)
                        {
                            dr["ArticleNo"] = order.ArticleNo;
                            dr["ShoeName"]  = order.ShoeName;
                            dr["Quantity"]  = order.Quantity;
                            dr["ETD"]       = order.ETD;
                        }

                        dr["SupplierETD"] = rawMaterial.ETD;
                        dr["Remarks"]     = rawMaterial.Remarks;
                        MaterialTypeModel materialType = materialTypeList.Where(m => m.MaterialTypeId == rawMaterial.MaterialTypeId).FirstOrDefault();
                        if (materialType != null)
                        {
                            dr["Supplier"] = materialType.Name;
                        }

                        dt.Rows.Add(dr);
                    }
                }
            }
            e.Result = dt;
        }
Exemple #2
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList            = OrdersController.Select();
            rawMaterialList      = RawMaterialController.Select();
            sockliningMasterList = SockliningMasterController.Select();
            sewingMasterList     = SewingMasterController.Select();
            outsoleMasterList    = OutsoleMasterController.Select();
            assemblyMasterList   = AssemblyMasterController.Select();

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

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

            foreach (SockliningMasterModel sockliningMaster in sockliningMasterList)
            {
                SockliningMasterExportViewModel sockliningMasterExportView = new SockliningMasterExportViewModel();
                sockliningMasterExportView.Sequence  = sockliningMaster.Sequence;
                sockliningMasterExportView.ProductNo = sockliningMaster.ProductNo;
                OrdersModel order = orderList.Where(o => o.ProductNo == sockliningMaster.ProductNo).FirstOrDefault();
                if (order != null)
                {
                    sockliningMasterExportView.Country   = order.Country;
                    sockliningMasterExportView.ShoeName  = order.ShoeName;
                    sockliningMasterExportView.ArticleNo = order.ArticleNo;
                    sockliningMasterExportView.PatternNo = order.PatternNo;
                    sockliningMasterExportView.Quantity  = order.Quantity;
                    sockliningMasterExportView.ETD       = order.ETD;
                }

                MaterialArrivalViewModel materialArrivalSocklining = MaterialArrival(order.ProductNo, materialIdSockliningArray);
                sockliningMasterExportView.IsSockliningMatsArrivalOk = false;
                if (materialArrivalSocklining != null)
                {
                    sockliningMasterExportView.SockliningMatsArrival     = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalSocklining.Date);
                    sockliningMasterExportView.IsSockliningMatsArrivalOk = materialArrivalSocklining.IsMaterialArrivalOk;
                }

                sockliningMasterExportView.SockliningLine       = sockliningMaster.SockliningLine;
                sockliningMasterExportView.SockliningQuota      = sockliningMaster.SockliningQuota;
                sockliningMasterExportView.SockliningStartDate  = sockliningMaster.SockliningStartDate;
                sockliningMasterExportView.SockliningFinishDate = sockliningMaster.SockliningFinishDate;
                sockliningMasterExportView.InsoleBalance        = sockliningMaster.InsoleBalance;
                sockliningMasterExportView.InsockBalance        = sockliningMaster.InsockBalance;

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

                OutsoleMasterModel outsoleMaster = outsoleMasterList.Where(o => o.ProductNo == sockliningMaster.ProductNo).FirstOrDefault();
                if (outsoleMaster != null)
                {
                    sockliningMasterExportView.OutsoleStartDate = outsoleMaster.OutsoleStartDate;
                    sockliningMasterExportView.OutsoleBalance   = outsoleMaster.OutsoleBalance;
                }
                else
                {
                    sockliningMasterExportView.OutsoleStartDate = dtDefault;
                    sockliningMasterExportView.OutsoleBalance   = "";
                }

                AssemblyMasterModel assemblyMaster = assemblyMasterList.Where(o => o.ProductNo == sockliningMaster.ProductNo).FirstOrDefault();
                if (assemblyMaster != null)
                {
                    sockliningMasterExportView.AssemblyStartDate = assemblyMaster.AssemblyStartDate;
                }
                else
                {
                    sockliningMasterExportView.AssemblyStartDate = dtDefault;
                }

                sockliningMasterExportViewList.Add(sockliningMasterExportView);
            }
        }
Exemple #3
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                orderList          = OrdersController.Select();
                rawMaterialList    = RawMaterialController.Select();
                sewingMasterList   = SewingMasterController.Select();
                productionMemoList = ProductionMemoController.Select();
                offDayList         = OffDayController.Select();
                privateDefine      = PrivateDefineController.GetDefine();
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(new Action(() => {
                    MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                }));
                return;
            }

            _SEW_VS_OTHERS_CUT_A = privateDefine.SewingVsOthersCutTypeA;
            _SEW_VS_OTHERS_CUT_B = privateDefine.SewingVsOthersCutTypeB;

            //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)
            {
                CutprepMasterExportViewModel cutprepMasterExportView = new CutprepMasterExportViewModel();
                cutprepMasterExportView.Sequence  = sewingMaster.Sequence;
                cutprepMasterExportView.ProductNo = sewingMaster.ProductNo;
                OrdersModel order  = orderList.FirstOrDefault(f => f.ProductNo == sewingMaster.ProductNo);
                string      memoId = "";
                if (order != null)
                {
                    cutprepMasterExportView.Country   = order.Country;
                    cutprepMasterExportView.ShoeName  = order.ShoeName;
                    cutprepMasterExportView.ArticleNo = order.ArticleNo;
                    cutprepMasterExportView.PatternNo = order.PatternNo;
                    cutprepMasterExportView.Quantity  = order.Quantity;
                    cutprepMasterExportView.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";
                        }
                    }
                    cutprepMasterExportView.MemoId = memoId;
                }

                MaterialArrivalViewModel materialArrivalUpper = MaterialArrival(order.ProductNo, materialIdUpperArray);
                cutprepMasterExportView.IsUpperMatsArrivalOk = false;
                if (materialArrivalUpper != null)
                {
                    cutprepMasterExportView.UpperMatsArrival     = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalUpper.Date);
                    cutprepMasterExportView.IsUpperMatsArrivalOk = materialArrivalUpper.IsMaterialArrivalOk;
                }
                cutprepMasterExportView.SewingLine        = sewingMaster.SewingLine;
                cutprepMasterExportView.SewingStartDate   = sewingMaster.SewingStartDate;
                cutprepMasterExportView.SewingQuota       = sewingMaster.SewingQuota;
                cutprepMasterExportView.SewingBalance     = sewingMaster.SewingBalance;
                cutprepMasterExportView.CutAStartDate     = sewingMaster.CutAStartDate;
                cutprepMasterExportView.CutAFinishDate    = sewingMaster.CutAFinishDate;
                cutprepMasterExportView.CutAQuota         = sewingMaster.CutAQuota;
                cutprepMasterExportView.AutoCut           = sewingMaster.AutoCut;
                cutprepMasterExportView.LaserCut          = sewingMaster.LaserCut;
                cutprepMasterExportView.HuasenCut         = sewingMaster.HuasenCut;
                cutprepMasterExportView.CutABalance       = sewingMaster.CutABalance;
                cutprepMasterExportView.PrintingBalance   = sewingMaster.PrintingBalance;
                cutprepMasterExportView.H_FBalance        = sewingMaster.H_FBalance;
                cutprepMasterExportView.EmbroideryBalance = sewingMaster.EmbroideryBalance;
                cutprepMasterExportView.CutBBalance       = sewingMaster.CutBBalance;

                // Cut type A before sewing 18days
                var cutTypeABeforeSewing       = sewingMaster.SewingStartDate.AddDays(-_SEW_VS_OTHERS_CUT_A);
                var dtCheckOffDateCutTypeAList = CheckOffDay(cutTypeABeforeSewing, sewingMaster.SewingStartDate);

                // Cut type B before sewing 10days
                var cutTypeBBeforeSewing       = sewingMaster.SewingStartDate.AddDays(-_SEW_VS_OTHERS_CUT_B);
                var dtCheckOffDateCutTypeBList = CheckOffDay(cutTypeBBeforeSewing, sewingMaster.SewingStartDate);

                var firstDateCheckOffCutTypeA = String.Format("{0:M/d}", dtCheckOffDateCutTypeAList.FirstOrDefault());
                var firstDateCheckOffCutTypeB = String.Format("{0:M/d}", dtCheckOffDateCutTypeBList.FirstOrDefault());

                if (!String.IsNullOrEmpty(sewingMaster.CutBStartDate))
                {
                    cutprepMasterExportView.CutBStartDate = sewingMaster.CutBStartDate;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.CutBStartDate = firstDateCheckOffCutTypeB;
                }
                else
                {
                    cutprepMasterExportView.CutBStartDate = "";
                }


                if (!String.IsNullOrEmpty(sewingMaster.AtomCutA))
                {
                    cutprepMasterExportView.AtomCutA = sewingMaster.AtomCutA;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.AtomCutA = firstDateCheckOffCutTypeA;
                }
                else
                {
                    cutprepMasterExportView.AtomCutA = "";
                }


                if (!String.IsNullOrEmpty(sewingMaster.AtomCutB))
                {
                    cutprepMasterExportView.AtomCutB = sewingMaster.AtomCutB;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.AtomCutB = firstDateCheckOffCutTypeB;
                }
                else
                {
                    cutprepMasterExportView.AtomCutB = "";
                }


                if (!String.IsNullOrEmpty(sewingMaster.LaserCutA))
                {
                    cutprepMasterExportView.LaserCutA = sewingMaster.LaserCutA;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.LaserCutA = firstDateCheckOffCutTypeA;
                }
                else
                {
                    cutprepMasterExportView.LaserCutA = "";
                }

                if (!String.IsNullOrEmpty(sewingMaster.LaserCutB))
                {
                    cutprepMasterExportView.LaserCutB = sewingMaster.LaserCutB;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.LaserCutB = firstDateCheckOffCutTypeB;
                }
                else
                {
                    cutprepMasterExportView.LaserCutB = "";
                }


                if (!String.IsNullOrEmpty(sewingMaster.HuasenCutA))
                {
                    cutprepMasterExportView.HuasenCutA = sewingMaster.HuasenCutA;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.HuasenCutA = firstDateCheckOffCutTypeA;
                }
                else
                {
                    cutprepMasterExportView.HuasenCutA = "";
                }


                if (!String.IsNullOrEmpty(sewingMaster.HuasenCutB))
                {
                    cutprepMasterExportView.HuasenCutB = sewingMaster.HuasenCutB;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.HuasenCutB = firstDateCheckOffCutTypeB;
                }
                else
                {
                    cutprepMasterExportView.HuasenCutB = "";
                }

                if (!String.IsNullOrEmpty(sewingMaster.ComelzCutA))
                {
                    cutprepMasterExportView.ComelzCutA = sewingMaster.ComelzCutA;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.ComelzCutA = firstDateCheckOffCutTypeA;
                }
                else
                {
                    cutprepMasterExportView.ComelzCutA = "";
                }

                if (!String.IsNullOrEmpty(sewingMaster.ComelzCutB))
                {
                    cutprepMasterExportView.ComelzCutB = sewingMaster.ComelzCutB;
                }
                else if (sewingMaster.SewingStartDate != dtDefault)
                {
                    cutprepMasterExportView.ComelzCutB = firstDateCheckOffCutTypeB;
                }
                else
                {
                    cutprepMasterExportView.ComelzCutB = "";
                }


                cutprepMasterExportViewList.Add(cutprepMasterExportView);
            }
        }
        private void bwSearch_DoWork(object sender, DoWorkEventArgs e)
        {
            if (modePerStyle == "PM")
            {
                reportTitle = pm;
                orderList   = OrdersController.Select().Where(w => w.PatternNo == pm).ToList();
            }
            if (modePerStyle == "Article")
            {
                reportTitle = "Article: " + articleNo;
                orderList   = OrdersController.Select().Where(w => w.ArticleNo.Contains(articleNo)).ToList();
            }
            sewingMasterList     = SewingMasterController.Select();
            sockliningMasterList = SockliningMasterController.Select();
            outsoleMasterList    = OutsoleMasterController.Select();
            assemblyMasterList   = AssemblyMasterController.Select();

            DataTable     dt            = new LeadTimePerStyleDataSet().Tables["LeadTimePerStyleTable"];
            List <string> productNoList = orderList.Select(s => s.ProductNo).Distinct().ToList();

            double timeAverage = 0;

            foreach (string phase in phaseList)
            {
                int qtyXDay = 0, qtyQuota = 0;
                timeAverage = 0;
                // Sewing
                if (phase == phaseList[0])
                {
                    foreach (string productNo in productNoList)
                    {
                        var sewingModel = sewingMasterList.Where(w => w.ProductNo == productNo &&
                                                                 TimeHelper.Convert(w.SewingActualStartDateAuto) != dtNothing &&
                                                                 TimeHelper.Convert(w.SewingActualStartDateAuto) != dtDefault &&
                                                                 TimeHelper.Convert(w.SewingActualFinishDateAuto) != dtNothing &&
                                                                 TimeHelper.Convert(w.SewingActualFinishDateAuto) != dtDefault).FirstOrDefault();
                        if (sewingModel != null)
                        {
                            DateTime sewingActualStartDate  = TimeHelper.Convert(sewingModel.SewingActualStartDateAuto);
                            DateTime sewingActualFinishDate = TimeHelper.Convert(sewingModel.SewingActualFinishDateAuto);
                            qtyXDay  += CalculateDateRange(sewingActualStartDate, sewingActualFinishDate) * sewingModel.SewingQuota;
                            qtyQuota += sewingModel.SewingQuota;
                        }
                    }
                    timeAverage = (double)qtyXDay / (double)qtyQuota;
                }

                // Socklining
                if (phase == phaseList[1])
                {
                    timeAverage = 0;
                    foreach (string productNo in productNoList)
                    {
                        var sockliningModel = sockliningMasterList.Where(w => w.ProductNo == productNo &&
                                                                         TimeHelper.Convert(w.SockliningActualStartDate) != dtNothing &&
                                                                         TimeHelper.Convert(w.SockliningActualStartDate) != dtDefault &&
                                                                         TimeHelper.Convert(w.SockliningActualFinishDate) != dtNothing &&
                                                                         TimeHelper.Convert(w.SockliningActualFinishDate) != dtDefault).FirstOrDefault();
                        if (sockliningModel != null)
                        {
                            DateTime sockliningActualStartDate  = TimeHelper.Convert(sockliningModel.SockliningActualStartDate);
                            DateTime sockliningActualFinishDate = TimeHelper.Convert(sockliningModel.SockliningActualFinishDate);
                            qtyXDay  += CalculateDateRange(sockliningActualStartDate, sockliningActualFinishDate) * sockliningModel.SockliningQuota;
                            qtyQuota += sockliningModel.SockliningQuota;
                        }
                    }
                    timeAverage = (double)qtyXDay / (double)qtyQuota;
                }


                // Outsole
                if (phase == phaseList[2])
                {
                    timeAverage = 0;
                    foreach (string productNo in productNoList)
                    {
                        var outsoleModel = outsoleMasterList.Where(w => w.ProductNo == productNo &&
                                                                   TimeHelper.Convert(w.OutsoleActualStartDateAuto) != dtNothing &&
                                                                   TimeHelper.Convert(w.OutsoleActualStartDateAuto) != dtDefault &&
                                                                   TimeHelper.Convert(w.OutsoleActualFinishDateAuto) != dtNothing &&
                                                                   TimeHelper.Convert(w.OutsoleActualFinishDateAuto) != dtDefault).FirstOrDefault();
                        if (outsoleModel != null)
                        {
                            DateTime outsoleActualStartDate  = TimeHelper.Convert(outsoleModel.OutsoleActualStartDateAuto);
                            DateTime outsoleActualFinishDate = TimeHelper.Convert(outsoleModel.OutsoleActualFinishDateAuto);
                            qtyXDay  += CalculateDateRange(outsoleActualStartDate, outsoleActualFinishDate) * outsoleModel.OutsoleQuota;
                            qtyQuota += outsoleModel.OutsoleQuota;
                        }
                    }
                    timeAverage = (double)qtyXDay / (double)qtyQuota;
                }

                // Assembly
                if (phase == phaseList[3])
                {
                    timeAverage = 0;
                    foreach (string productNo in productNoList)
                    {
                        var assemblyModel = assemblyMasterList.Where(w => w.ProductNo == productNo &&
                                                                     TimeHelper.Convert(w.AssemblyActualStartDate) != dtNothing &&
                                                                     TimeHelper.Convert(w.AssemblyActualStartDate) != dtDefault &&
                                                                     TimeHelper.Convert(w.AssemblyActualFinishDate) != dtNothing &&
                                                                     TimeHelper.Convert(w.AssemblyActualFinishDate) != dtDefault).FirstOrDefault();
                        if (assemblyModel != null)
                        {
                            DateTime assemblyActualStartDate  = TimeHelper.Convert(assemblyModel.AssemblyActualStartDate);
                            DateTime assemblyActualFinishDate = TimeHelper.Convert(assemblyModel.AssemblyActualFinishDate);
                            qtyXDay  += CalculateDateRange(assemblyActualStartDate, assemblyActualFinishDate) * assemblyModel.AssemblyQuota;
                            qtyQuota += assemblyModel.AssemblyQuota;
                        }
                    }
                    timeAverage = (double)qtyXDay / (double)qtyQuota;
                }

                // Cut A To Box
                if (phase == phaseList[4])
                {
                    timeAverage = 0;
                    foreach (string productNo in productNoList)
                    {
                        var sewingModel = sewingMasterList.Where(w => w.ProductNo == productNo &&
                                                                 TimeHelper.Convert(w.CutAActualStartDate) != dtNothing &&
                                                                 TimeHelper.Convert(w.CutAActualStartDate) != dtDefault).FirstOrDefault();

                        var assemblyModel = assemblyMasterList.Where(w => w.ProductNo == productNo &&
                                                                     TimeHelper.Convert(w.AssemblyActualFinishDate) != dtNothing &&
                                                                     TimeHelper.Convert(w.AssemblyActualFinishDate) != dtDefault).FirstOrDefault();

                        if (sewingModel != null && assemblyModel != null)
                        {
                            DateTime cutAActualStartDate    = TimeHelper.Convert(sewingModel.CutAActualStartDate);
                            DateTime sewingActualFinishDate = TimeHelper.Convert(sewingModel.SewingActualFinishDateAuto);
                            DateTime assyActualStartDate    = TimeHelper.Convert(assemblyModel.AssemblyActualStartDate);
                            DateTime assyActualFinishDate   = TimeHelper.Convert(assemblyModel.AssemblyActualFinishDate);

                            int timeRange = 0;
                            if (assyActualStartDate != dtDefault && assyActualStartDate != dtNothing && sewingActualFinishDate != dtDefault && sewingActualFinishDate != dtNothing && assyActualStartDate > sewingActualFinishDate)
                            {
                                //timeRange = TimeHelper.CalculateDate(sewingActualFinishDate, assyActualStartDate);
                                timeRange = (Int32)((assyActualStartDate - sewingActualFinishDate).TotalDays);
                                qtyXDay  += (CalculateDateRange(cutAActualStartDate, assyActualFinishDate) - timeRange) * sewingModel.CutAQuota;
                                qtyQuota += sewingModel.CutAQuota;
                            }
                            else
                            {
                                qtyXDay  += CalculateDateRange(cutAActualStartDate, assyActualFinishDate) * sewingModel.CutAQuota;
                                qtyQuota += sewingModel.CutAQuota;
                            }
                        }
                    }
                    timeAverage = (double)qtyXDay / (double)qtyQuota;
                }

                // Cut B To Box
                if (phase == phaseList[4])
                {
                    timeAverage = 0;
                    foreach (string productNo in productNoList)
                    {
                        var sewingModel = sewingMasterList.Where(w => w.ProductNo == productNo &&
                                                                 TimeHelper.Convert(w.CutBActualStartDate) != dtNothing &&
                                                                 TimeHelper.Convert(w.CutBActualStartDate) != dtDefault).FirstOrDefault();

                        var assemblyModel = assemblyMasterList.Where(w => w.ProductNo == productNo &&
                                                                     TimeHelper.Convert(w.AssemblyActualFinishDate) != dtNothing &&
                                                                     TimeHelper.Convert(w.AssemblyActualFinishDate) != dtDefault).FirstOrDefault();

                        if (sewingModel != null && assemblyModel != null)
                        {
                            DateTime cutBActualStartDate    = TimeHelper.Convert(sewingModel.CutBActualStartDate);
                            DateTime sewingActualFinishDate = TimeHelper.Convert(sewingModel.SewingActualFinishDateAuto);
                            DateTime assyActualStartDate    = TimeHelper.Convert(assemblyModel.AssemblyActualStartDate);
                            DateTime assyActualFinishDate   = TimeHelper.Convert(assemblyModel.AssemblyActualFinishDate);

                            int timeRange = 0;
                            if (assyActualStartDate != dtDefault && assyActualStartDate != dtNothing && sewingActualFinishDate != dtDefault && sewingActualFinishDate != dtNothing && assyActualStartDate > sewingActualFinishDate)
                            {
                                //timeRange = TimeHelper.CalculateDate(sewingActualFinishDate, assyActualStartDate);
                                timeRange = (Int32)((assyActualStartDate - sewingActualFinishDate).TotalDays);
                                qtyXDay  += (CalculateDateRange(cutBActualStartDate, assyActualFinishDate) - timeRange) * sewingModel.CutAQuota;
                                qtyQuota += sewingModel.CutAQuota;
                            }
                            else
                            {
                                qtyXDay  += CalculateDateRange(cutBActualStartDate, assyActualFinishDate) * sewingModel.CutAQuota;
                                qtyQuota += sewingModel.CutAQuota;
                            }
                        }
                    }
                    timeAverage = (double)qtyXDay / (double)qtyQuota;
                }

                string timeAverageString = "";
                if (timeAverage > 0)
                {
                    timeAverageString = string.Format("{0:0.00}", timeAverage);
                }

                DataRow dr = dt.NewRow();
                dr["Phase"]       = phase;
                dr["TimeAverage"] = timeAverageString;
                dt.Rows.Add(dr);
            }

            e.Result = dt;
        }
Exemple #5
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);
            }
        }
Exemple #6
0
        private void threadLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            //Get offdate
            offDateList = OffDayController.SelectDate();

            int[] materialIdUpperArray    = { 1, 2, 3, 4, 10 };
            int[] materialIdAssemblyArray = { 8 };
            int[] materialIdOutsoleArray  = { 6 };

            object[] args      = e.Argument as object[];
            DateTime dateFrom  = (args[0] as DateTime?).Value;
            DateTime dateTo    = (args[1] as DateTime?).Value;
            string   sectionId = args[2] as string;

            if (orderList.Count <= 0)
            {
                orderList = OrdersController.Select();
            }

            if (sectionId == sewing && sewingMasterList.Count <= 0)
            {
                sewingMasterList = SewingMasterController.Select();
            }
            if (sectionId == assembly && assemblyMasterList.Count <= 0)
            {
                assemblyMasterList = AssemblyMasterController.Select();
            }
            if (sectionId == outsole && outsoleMasterList.Count <= 0)
            {
                outsoleMasterList = OutsoleMasterController.Select();
            }

            if (rawMaterialList.Count <= 0)
            {
                rawMaterialList = RawMaterialController.Select();
            }

            string[] lineArray = null;
            string[] tempArray = null;
            if (sectionId == sewing)
            {
                //lineArray = sewingMasterList.Select(s => s.SewingLine).Distinct().OrderBy(s => s).ToArray();
                tempArray = sewingMasterList.Select(s => s.SewingLine).Distinct().ToArray();
                SortArray(tempArray);
                lineArray = tempArray;
            }
            if (sectionId == assembly)
            {
                //lineArray = assemblyMasterList.Select(s => s.AssemblyLine).Distinct().OrderBy(s => s).ToArray();
                tempArray = assemblyMasterList.Select(s => s.AssemblyLine).Distinct().ToArray();
                SortArray(tempArray);
                lineArray = tempArray;
            }
            if (sectionId == outsole)
            {
                lineArray = outsoleMasterList.Select(s => s.OutsoleLine).Distinct().OrderBy(s => s).ToArray();
            }

            foreach (string line in lineArray)
            {
                DataRow dr = dt.NewRow();
                dr["Line"] = line;
                if (sectionId == sewing)
                {
                    List <SewingMasterModel> sewingMasterTempList = sewingMasterList.Where(s => s.SewingLine == line && ((dateFrom <= s.SewingStartDate && s.SewingStartDate <= dateTo) || (dateFrom <= s.SewingFinishDate && s.SewingFinishDate <= dateTo))).ToList();
                    foreach (SewingMasterModel sewingMaster in sewingMasterTempList)
                    {
                        OrdersModel order = orderList.Where(o => o.ProductNo == sewingMaster.ProductNo).FirstOrDefault();
                        CompareDate(order, dateFrom, dateTo, sewingMaster.SewingStartDate, sewingMaster.SewingFinishDate, ref dr, materialIdUpperArray);
                    }
                }

                if (sectionId == assembly)
                {
                    List <AssemblyMasterModel> sewingMasterTempList = assemblyMasterList.Where(s => s.AssemblyLine == line && ((dateFrom <= s.AssemblyStartDate && s.AssemblyStartDate <= dateTo) || (dateFrom <= s.AssemblyFinishDate && s.AssemblyFinishDate <= dateTo))).ToList();
                    foreach (AssemblyMasterModel sewingMaster in sewingMasterTempList)
                    {
                        OrdersModel order = orderList.Where(o => o.ProductNo == sewingMaster.ProductNo).FirstOrDefault();
                        CompareDate(order, dateFrom, dateTo, sewingMaster.AssemblyStartDate, sewingMaster.AssemblyFinishDate, ref dr, materialIdAssemblyArray);
                    }
                }

                if (sectionId == outsole)
                {
                    List <OutsoleMasterModel> sewingMasterTempList = outsoleMasterList.Where(s => s.OutsoleLine == line && ((dateFrom <= s.OutsoleStartDate && s.OutsoleStartDate <= dateTo) || (dateFrom <= s.OutsoleFinishDate && s.OutsoleFinishDate <= dateTo))).ToList();
                    foreach (OutsoleMasterModel sewingMaster in sewingMasterTempList)
                    {
                        OrdersModel order = orderList.Where(o => o.ProductNo == sewingMaster.ProductNo).FirstOrDefault();
                        CompareDate(order, dateFrom, dateTo, sewingMaster.OutsoleStartDate, sewingMaster.OutsoleFinishDate, ref dr, materialIdOutsoleArray);
                    }
                }

                dt.Rows.Add(dr);
            }
        }
        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;
        }
        void threadLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            //outsoleRawMaterialList = OutsoleRawMaterialController.Select();
            outsoleRawMaterialList = OutsoleRawMaterialController.SelectFull(etdStartSelect, etdEndSelect);
            outsoleMaterialList    = OutsoleMaterialController.SelectByOutsoleRawMaterialFull(etdStartSelect, etdEndSelect);
            sizeRunList            = SizeRunController.SelectByOutsoleRawMaterialFull(etdStartSelect, etdEndSelect);
            outsoleSupplierList    = OutsoleSuppliersController.Select();
            orderList        = OrdersController.SelectByOutsoleRawMaterialFull(etdStartSelect, etdEndSelect);
            sewingMasterList = SewingMasterController.SelectFull(etdStartSelect, etdEndSelect);

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

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

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

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

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

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

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

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

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

                        outsoleDeliveryStatusViewList.Add(outsoleDeliveryStatusView);
                    }
                }
            }
        }
 private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
 {
     orderList          = OrdersController.Select();
     assemblyMasterList = AssemblyMasterController.Select();
     sewingMasterList   = SewingMasterController.Select();
 }
        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);
            }
        }
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList                  = OrdersController.Select();
            rawMaterialList            = RawMaterialController.Select();
            sewingMasterList           = SewingMasterController.Select();
            outsoleMasterList          = OutsoleMasterController.Select();
            outsoleReleaseMaterialList = OutsoleReleaseMaterialController.SelectByOutsoleMaster();
            productionMemoList         = ProductionMemoController.Select();

            //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.Where(o => o.ProductNo == outsoleMaster.ProductNo).FirstOrDefault();
                string      memoId = "";
                if (order != null)
                {
                    outsoleMasterExportView.Country     = order.Country;
                    outsoleMasterExportView.ShoeName    = order.ShoeName;
                    outsoleMasterExportView.ArticleNo   = order.ArticleNo;
                    outsoleMasterExportView.OutsoleCode = order.OutsoleCode;
                    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;
                }
                outsoleMasterExportView.OutsoleLine       = outsoleMaster.OutsoleLine;
                outsoleMasterExportView.OutsoleStartDate  = outsoleMaster.OutsoleStartDate;
                outsoleMasterExportView.OutsoleFinishDate = outsoleMaster.OutsoleFinishDate;
                outsoleMasterExportView.OutsoleQuota      = outsoleMaster.OutsoleQuota;
                outsoleMasterExportView.OutsoleBalance    = outsoleMaster.OutsoleBalance;

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

                SewingMasterModel sewingMaster = sewingMasterList.Where(o => o.ProductNo == outsoleMaster.ProductNo).FirstOrDefault();
                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);
            }
        }
Exemple #12
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);
            }
        }
Exemple #13
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList          = OrdersController.Select();
            rawMaterialList    = RawMaterialController.Select();
            sewingMasterList   = SewingMasterController.Select();
            productionMemoList = ProductionMemoController.Select();
            //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)
            {
                CutprepMasterExportViewModel cutprepMasterExportView = new CutprepMasterExportViewModel();
                cutprepMasterExportView.Sequence  = sewingMaster.Sequence;
                cutprepMasterExportView.ProductNo = sewingMaster.ProductNo;
                OrdersModel order  = orderList.Where(o => o.ProductNo == sewingMaster.ProductNo).FirstOrDefault();
                string      memoId = "";
                if (order != null)
                {
                    cutprepMasterExportView.Country   = order.Country;
                    cutprepMasterExportView.ShoeName  = order.ShoeName;
                    cutprepMasterExportView.ArticleNo = order.ArticleNo;
                    cutprepMasterExportView.PatternNo = order.PatternNo;
                    cutprepMasterExportView.Quantity  = order.Quantity;
                    cutprepMasterExportView.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";
                        }
                    }
                    cutprepMasterExportView.MemoId = memoId;
                }

                MaterialArrivalViewModel materialArrivalUpper = MaterialArrival(order.ProductNo, materialIdUpperArray);
                cutprepMasterExportView.IsUpperMatsArrivalOk = false;
                if (materialArrivalUpper != null)
                {
                    cutprepMasterExportView.UpperMatsArrival     = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalUpper.Date);
                    cutprepMasterExportView.IsUpperMatsArrivalOk = materialArrivalUpper.IsMaterialArrivalOk;
                }
                cutprepMasterExportView.SewingLine        = sewingMaster.SewingLine;
                cutprepMasterExportView.SewingStartDate   = sewingMaster.SewingStartDate;
                cutprepMasterExportView.SewingQuota       = sewingMaster.SewingQuota;
                cutprepMasterExportView.SewingBalance     = sewingMaster.SewingBalance;
                cutprepMasterExportView.CutAStartDate     = sewingMaster.CutAStartDate;
                cutprepMasterExportView.CutAFinishDate    = sewingMaster.CutAFinishDate;
                cutprepMasterExportView.CutAQuota         = sewingMaster.CutAQuota;
                cutprepMasterExportView.AutoCut           = sewingMaster.AutoCut;
                cutprepMasterExportView.LaserCut          = sewingMaster.LaserCut;
                cutprepMasterExportView.HuasenCut         = sewingMaster.HuasenCut;
                cutprepMasterExportView.CutABalance       = sewingMaster.CutABalance;
                cutprepMasterExportView.PrintingBalance   = sewingMaster.PrintingBalance;
                cutprepMasterExportView.H_FBalance        = sewingMaster.H_FBalance;
                cutprepMasterExportView.EmbroideryBalance = sewingMaster.EmbroideryBalance;
                cutprepMasterExportView.CutBBalance       = sewingMaster.CutBBalance;

                cutprepMasterExportViewList.Add(cutprepMasterExportView);
            }
        }
        void threadLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList          = OrdersController.Select();
            sewingMasterList   = SewingMasterController.Select();
            outsoleMasterList  = OutsoleMasterController.Select();
            assemblyMasterList = AssemblyMasterController.Select();
            orderExtraList     = OrderExtraController.Select();

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

            foreach (string productNo in productNoList)
            {
                var order = orderList.FirstOrDefault(f => f.ProductNo == productNo);

                //var order1 = orderList.Where(w => w.ProductNo == productNo).FirstOrDefault();

                var sewingMaster   = sewingMasterList.FirstOrDefault(f => f.ProductNo == productNo);
                var outsoleMaster  = outsoleMasterList.FirstOrDefault(f => f.ProductNo == productNo);
                var assemblyMaster = assemblyMasterList.FirstOrDefault(f => f.ProductNo == productNo);
                var orderExtra     = orderExtraList.FirstOrDefault(f => f.ProductNo == productNo);

                CompletionStatusViewModel completionStatusView = new CompletionStatusViewModel
                {
                    ProductNo = order.ProductNo,
                    Country   = order.Country,
                    ShoeName  = order.ShoeName,
                    ArticleNo = order.ArticleNo,
                    ETD       = order.ETD,
                    Quantity  = order.Quantity,
                };

                if (orderExtra != null)
                {
                    DateTime loadingDate = dtDefault;
                    if (DateTime.TryParse(orderExtra.LoadingDate, out loadingDate) == true)
                    {
                        completionStatusView.LoadingDate = string.Format(new CultureInfo("en-US"), "{0:dd-MMM}", loadingDate);
                    }
                    else
                    {
                        completionStatusView.LoadingDate = "";
                    }
                }

                if (sewingMaster != null)
                {
                    completionStatusView.SewingLine       = sewingMaster.SewingLine;
                    completionStatusView.CutAFinishDate   = sewingMaster.CutBBalance;
                    completionStatusView.SewingFinishDate = sewingMaster.SewingActualFinishDate;

                    if (string.IsNullOrEmpty(sewingMaster.SewingActualFinishDate.Trim()) == true)
                    {
                        completionStatusView.SewingFinishDate = sewingMaster.SewingBalance;
                    }
                }
                else
                {
                    completionStatusView.SewingLine       = "";
                    completionStatusView.CutAFinishDate   = "";
                    completionStatusView.SewingFinishDate = "";
                }

                if (outsoleMaster != null)
                {
                    completionStatusView.OutsoleLine       = outsoleMaster.OutsoleLine;
                    completionStatusView.OutsoleFinishDate = outsoleMaster.OutsoleActualFinishDate;
                    if (string.IsNullOrEmpty(outsoleMaster.OutsoleActualFinishDate.Trim()) == true)
                    {
                        completionStatusView.OutsoleFinishDate = outsoleMaster.OutsoleBalance;
                    }
                }
                else
                {
                    completionStatusView.OutsoleLine       = "";
                    completionStatusView.OutsoleFinishDate = "";
                }

                completionStatusView.IsFinished = false;
                if (assemblyMaster != null)
                {
                    completionStatusView.AssemblyLine       = assemblyMaster.AssemblyLine;
                    completionStatusView.AssemblyFinishDate =
                        assemblyMaster.AssemblyActualFinishDate.Contains("/")? TimeHelper.ConvertDateToView(assemblyMaster.AssemblyActualFinishDate)
                        : assemblyMaster.AssemblyActualFinishDate;

                    if (string.IsNullOrEmpty(assemblyMaster.AssemblyActualFinishDate.Trim()) == true)
                    {
                        completionStatusView.AssemblyFinishDate = assemblyMaster.AssemblyBalance;
                    }

                    if (string.IsNullOrEmpty(assemblyMaster.AssemblyActualFinishDate.Trim()) == false || assemblyMaster.AssemblyBalance.ToLower() == "OK".ToLower())
                    {
                        completionStatusView.IsFinished = true;
                    }
                }
                else
                {
                    completionStatusView.AssemblyLine       = "";
                    completionStatusView.AssemblyFinishDate = "";
                }
                completionStatusViewList.Add(completionStatusView);
            }
        }
Exemple #15
0
        // Notifications
        private void bwLoadDelivery_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleSupplierList        = OutsoleSuppliersController.Select();
            outsoleMaterialList        = OutsoleMaterialController.Select();
            outsoleReleaseMaterialList = OutsoleReleaseMaterialController.SelectByOutsoleMaterial();
            outsoleOutputList          = OutsoleOutputController.SelectByAssemblyMaster();
            sewingMasterList           = SewingMasterController.Select();
            assemblyMasterList         = AssemblyMasterController.Select();
            outsoleMasterList          = OutsoleMasterController.Select();
            orderList = OrdersController.Select();
            outsoleRawMaterialList = OutsoleRawMaterialController.Select();

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

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

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

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

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

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

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

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

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

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

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

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

            DataTable dt = new DataTable();

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

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

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

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

                columnProductNo.CellStyle = styleColumnProductNo;

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

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

                dgInventory.Columns.Add(columnProductNo);

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

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

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

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

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

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

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


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

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

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

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


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


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

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

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

                dgInventory.FrozenColumnCount = 8;

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

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

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

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

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

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

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

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

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

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

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

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

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

                var dr = dt.NewRow();

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

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

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

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

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

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

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

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

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

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

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

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


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

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

                dt.Rows.Add(dr);
            }

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

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

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

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

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

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

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

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

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

                Border brTotalBalance = new Border();
                Grid.SetColumn(brTotalBalance, 11 + sizeNoList.Count());
                brTotalBalance.BorderThickness = new Thickness(1, 0, 1, 1);
                brTotalBalance.BorderBrush     = Brushes.Black;
                brTotalBalance.Child           = txtTotalBalance;
                gridTotal.Children.Add(brTotalBalance);
                dgInventory.ItemsSource = dt.AsDataView();
            }));
            dtExportExcel = dt;
        }
        private void threadLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            object[] args      = e.Argument as object[];
            string   sectionId = args[2] as string;

            if ((sectionId == sewing || sectionId == cuta || sectionId == cutb) && sewingMasterList.Count <= 0)
            {
                sewingMasterList = SewingMasterController.Select();
            }
            if (sectionId == assembly || sectionId == cuta || sectionId == cutb && assemblyMasterList.Count <= 0)
            {
                assemblyMasterList = AssemblyMasterController.Select();
            }
            if (sectionId == outsole && outsoleMasterList.Count <= 0)
            {
                outsoleMasterList = OutsoleMasterController.Select();
            }
            if (sectionId == socklining && sockliningMasterList.Count <= 0)
            {
                sockliningMasterList = SockliningMasterController.Select();
            }

            var   lineList       = new List <string>();
            Regex regex          = new Regex(@"\D");
            var   regexNotString = new Regex("[^a-zA-Z]");

            dt = new LeadTimeReportDataSet().Tables["LeadTimeTable"];

            #region SEWING
            if (currentSection == sewing)
            {
                //var sewingLineList = sewingMasterList
                //    .Where(w => w.SewingLine.Contains("sewing"))
                //    .Select(s => new { line = s.SewingLine, sort = Int32.Parse(regex.Replace(s.SewingLine, "0")) })
                //    .OrderBy(o => o.sort)
                //    .ThenBy(t => t.line)
                //    .Distinct()
                //    .ToList();

                lineList = sewingMasterList.Where(w => w.SewingLine.Contains("sew")).Select(s => s.SewingLine).Distinct().ToList();
                var lineCustomList = lineList.Select(s => new { Line = s, LineNumber = regex.IsMatch(s) ? regex.Replace(s, "") : s }).ToList();
                if (lineCustomList.Count() > 0)
                {
                    lineCustomList = lineCustomList//.OrderBy(o => regexNotString.IsMatch(o.Line) ? regexNotString.Replace(o.Line, "") : o.Line)
                                     .OrderBy(o => String.IsNullOrEmpty(o.LineNumber) ? 100 : Int64.Parse(o.LineNumber))
                                     .ThenBy(th => th.Line).ToList();
                }

                foreach (var line in lineCustomList)
                {
                    int qtyXDay       = 0;
                    int qtyQuota      = 0;
                    var productNoList = sewingMasterList.Where(w => w.SewingLine == line.Line).Select(s => s.ProductNo).ToList();
                    foreach (string productNo in productNoList)
                    {
                        var sewingModel = sewingMasterList.FirstOrDefault(f => f.ProductNo == productNo &&
                                                                          TimeHelper.Convert(f.SewingActualFinishDateAuto) >= dateFrom &&
                                                                          TimeHelper.Convert(f.SewingActualFinishDateAuto) < dateTo);

                        if (sewingModel != null)
                        {
                            DateTime sewingActualStartDate  = TimeHelper.Convert(sewingModel.SewingActualStartDateAuto);
                            DateTime sewingActualFinishDate = TimeHelper.Convert(sewingModel.SewingActualFinishDateAuto);
                            if (sewingActualStartDate != dtDefault && sewingActualStartDate != dtNothing &&
                                sewingActualFinishDate != dtDefault && sewingActualFinishDate != dtNothing)
                            {
                                qtyXDay  += CalculateDateRange(sewingActualStartDate, sewingActualFinishDate) * sewingModel.SewingQuota;
                                qtyQuota += sewingModel.SewingQuota;
                            }
                        }
                    }
                    CreateData(qtyXDay, qtyQuota, line.Line);
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    ExportReport();
                }));
            }
            #endregion

            #region ASSEMBLY
            if (currentSection == assembly)
            {
                var assyLineList = assemblyMasterList
                                   .Where(w => w.AssemblyLine.Contains("assy"))
                                   .Select(s => new { line = s.AssemblyLine, sort = Int32.Parse(regex.Replace(s.AssemblyLine, "")) })
                                   .OrderBy(o => o.sort)
                                   .ThenBy(t => t.line)
                                   .Distinct()
                                   .ToList();
                lineList = assyLineList.Select(s => s.line).ToList();

                foreach (string line in lineList)
                {
                    int qtyXDay  = 0;
                    int qtyQuota = 0;
                    var assemblyMasterListPerLine = assemblyMasterList.Where(w => w.AssemblyLine == line).ToList();
                    var productNoList             = assemblyMasterList.Where(w => w.AssemblyLine == line).Select(s => s.ProductNo).ToList();
                    foreach (string productNo in productNoList)
                    {
                        var assemblyModel = assemblyMasterList.Where(w => w.ProductNo == productNo &&
                                                                     TimeHelper.Convert(w.AssemblyActualFinishDate) >= dateFrom &&
                                                                     TimeHelper.Convert(w.AssemblyActualFinishDate) < dateTo)
                                            .FirstOrDefault();
                        if (assemblyModel != null)
                        {
                            DateTime assemblyActualStartDate  = TimeHelper.Convert(assemblyModel.AssemblyActualStartDate);
                            DateTime assemblyActualFinishDate = TimeHelper.Convert(assemblyModel.AssemblyActualFinishDate);
                            if (assemblyActualStartDate != dtDefault && assemblyActualStartDate != dtNothing &&
                                assemblyActualFinishDate != dtDefault && assemblyActualFinishDate != dtNothing)
                            {
                                qtyXDay  += CalculateDateRange(assemblyActualStartDate, assemblyActualFinishDate) * assemblyModel.AssemblyQuota;
                                qtyQuota += assemblyModel.AssemblyQuota;
                            }
                        }
                    }
                    CreateData(qtyXDay, qtyQuota, line);
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    ExportReport();
                }));
            }
            #endregion

            #region OUTSOLE
            if (currentSection == outsole)
            {
                var outSoleLineList = outsoleMasterList
                                      .Where(w => w.OutsoleLine.Contains("stockfit"))
                                      .Select(s => new { line = s.OutsoleLine, sort = Int32.Parse(regex.Replace(s.OutsoleLine, "")) })
                                      .OrderBy(o => o.sort)
                                      .ThenBy(t => t.line)
                                      .Distinct()
                                      .ToList();
                lineList = outSoleLineList.Select(s => s.line).ToList();
                foreach (string line in lineList)
                {
                    int qtyXDay       = 0;
                    int qtyQuota      = 0;
                    var productNoList = outsoleMasterList.Where(w => w.OutsoleLine == line).Select(s => s.ProductNo).ToList();
                    foreach (string productNo in productNoList)
                    {
                        var outsoleModel = outsoleMasterList
                                           .Where(w => w.ProductNo == productNo &&
                                                  TimeHelper.Convert(w.OutsoleActualFinishDateAuto) >= dateFrom &&
                                                  TimeHelper.Convert(w.OutsoleActualFinishDateAuto) < dateTo)
                                           .FirstOrDefault();
                        if (outsoleModel != null)
                        {
                            DateTime outsoleModelActualStartDate  = TimeHelper.Convert(outsoleModel.OutsoleActualStartDateAuto);
                            DateTime outsoleModelActualFinishDate = TimeHelper.Convert(outsoleModel.OutsoleActualFinishDateAuto);
                            if (outsoleModelActualStartDate != dtDefault && outsoleModelActualStartDate != dtNothing &&
                                outsoleModelActualFinishDate != dtDefault && outsoleModelActualFinishDate != dtNothing)
                            {
                                qtyXDay  += CalculateDateRange(outsoleModelActualStartDate, outsoleModelActualFinishDate) * outsoleModel.OutsoleQuota;
                                qtyQuota += outsoleModel.OutsoleQuota;
                            }
                        }
                    }
                    CreateData(qtyXDay, qtyQuota, line);
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    ExportReport();
                }));
            }
            #endregion

            #region SOCKLINING
            if (currentSection == socklining)
            {
                var sockliningLineList = sockliningMasterList
                                         .Where(w => w.SockliningLine.Contains("insock cell"))
                                         .Select(s => new { line = s.SockliningLine, sort = Int32.Parse(regex.Replace(s.SockliningLine, "")) })
                                         .OrderBy(o => o.sort)
                                         .ThenBy(t => t.line)
                                         .Distinct()
                                         .ToList();
                lineList = sockliningLineList.Select(s => s.line).ToList();
                foreach (string line in lineList)
                {
                    int qtyXDay       = 0;
                    int qtyQuota      = 0;
                    var productNoList = sockliningMasterList.Where(w => w.SockliningLine == line).Select(s => s.ProductNo).ToList();
                    foreach (string productNo in productNoList)
                    {
                        var sockliningModel = sockliningMasterList
                                              .Where(w => w.ProductNo == productNo &&
                                                     TimeHelper.Convert(w.SockliningActualFinishDate) >= dateFrom &&
                                                     TimeHelper.Convert(w.SockliningActualFinishDate) < dateTo)
                                              .FirstOrDefault();
                        if (sockliningModel != null)
                        {
                            DateTime sockliningModelActualStartDate  = TimeHelper.Convert(sockliningModel.SockliningActualStartDate);
                            DateTime sockliningModelActualFinishDate = TimeHelper.Convert(sockliningModel.SockliningActualFinishDate);
                            if (sockliningModelActualStartDate != dtDefault && sockliningModelActualStartDate != dtNothing &&
                                sockliningModelActualFinishDate != dtDefault && sockliningModelActualFinishDate != dtNothing)
                            {
                                qtyXDay  += CalculateDateRange(sockliningModelActualStartDate, sockliningModelActualFinishDate) * sockliningModel.SockliningQuota;
                                qtyQuota += sockliningModel.SockliningQuota;
                            }
                        }
                    }
                    CreateData(qtyXDay, qtyQuota, line);
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    ExportReport();
                }));
            }
            #endregion

            #region CUTA
            if (currentSection == cuta)
            {
                var cutALineList = sewingMasterList
                                   .Where(w => w.SewingLine.Contains("sewing"))
                                   .Select(s => new { line = s.SewingLine, sort = Int32.Parse(regex.Replace(s.SewingLine, "")) })
                                   .OrderBy(o => o.sort)
                                   .ThenBy(t => t.line)
                                   .Distinct()
                                   .ToList();
                lineList = cutALineList.Select(s => s.line).ToList();
                foreach (string line in lineList)
                {
                    var productNoList = sewingMasterList.Where(w => w.SewingLine == line).Select(s => s.ProductNo).ToList();

                    int qtyXDay  = 0;
                    int qtyQuota = 0;
                    foreach (var productNo in productNoList)
                    {
                        var sewingModel = sewingMasterList.Where(w => w.ProductNo == productNo).FirstOrDefault();
                        var assyModel   = assemblyMasterList
                                          .Where(w => w.ProductNo == productNo &&
                                                 TimeHelper.Convert(w.AssemblyActualFinishDate) >= dateFrom &&
                                                 TimeHelper.Convert(w.AssemblyActualFinishDate) < dateTo)
                                          .FirstOrDefault();
                        if (sewingModel != null && assyModel != null)
                        {
                            DateTime cutAActualStartDate    = TimeHelper.Convert(sewingModel.CutAActualStartDate);
                            DateTime sewingActualFinishDate = TimeHelper.Convert(sewingModel.SewingActualFinishDate);
                            DateTime assyActualStartDate    = TimeHelper.Convert(assyModel.AssemblyActualStartDate);
                            DateTime assyActualFinishDate   = TimeHelper.Convert(assyModel.AssemblyActualFinishDate);

                            int timeRange = 0;
                            if (cutAActualStartDate != dtNothing && cutAActualStartDate != dtDefault && assyActualFinishDate != dtNothing && assyActualFinishDate != dtDefault)
                            {
                                if (assyActualStartDate != dtDefault && assyActualStartDate != dtNothing && sewingActualFinishDate != dtDefault && sewingActualFinishDate != dtNothing && assyActualStartDate > sewingActualFinishDate)
                                {
                                    //timeRange = TimeHelper.CalculateDate(sewingActualFinishDate, assyActualStartDate);
                                    timeRange = (Int32)((assyActualStartDate - sewingActualFinishDate).TotalDays);
                                    qtyXDay  += (CalculateDateRange(cutAActualStartDate, assyActualFinishDate) - timeRange) * sewingModel.CutAQuota;
                                    qtyQuota += sewingModel.CutAQuota;
                                }
                                else
                                {
                                    qtyXDay  += CalculateDateRange(cutAActualStartDate, assyActualFinishDate) * sewingModel.CutAQuota;
                                    qtyQuota += sewingModel.CutAQuota;
                                }
                            }
                        }
                    }
                    CreateData(qtyXDay, qtyQuota, line);
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    ExportReport();
                }));
            }
            #endregion

            #region CUTB
            if (currentSection == cutb)
            {
                var cutBLineList = sewingMasterList
                                   .Where(w => w.SewingLine.Contains("sewing"))
                                   .Select(s => new { line = s.SewingLine, sort = Int32.Parse(regex.Replace(s.SewingLine, "")) })
                                   .OrderBy(o => o.sort)
                                   .ThenBy(t => t.line)
                                   .Distinct()
                                   .ToList();
                lineList = cutBLineList.Select(s => s.line).ToList();
                foreach (string line in lineList)
                {
                    var productNoList = sewingMasterList.Where(w => w.SewingLine == line).Select(s => s.ProductNo).ToList();

                    int qtyXDay  = 0;
                    int qtyQuota = 0;
                    foreach (var productNo in productNoList)
                    {
                        var sewingModel = sewingMasterList.Where(w => w.ProductNo == productNo).FirstOrDefault();
                        var assyModel   = assemblyMasterList
                                          .Where(w => w.ProductNo == productNo &&
                                                 TimeHelper.Convert(w.AssemblyActualFinishDate) >= dateFrom &&
                                                 TimeHelper.Convert(w.AssemblyActualFinishDate) < dateTo)
                                          .FirstOrDefault();
                        if (sewingModel != null && assyModel != null)
                        {
                            DateTime cutBActualStartDate    = TimeHelper.Convert(sewingModel.CutBActualStartDate);
                            DateTime sewingActualFinishDate = TimeHelper.Convert(sewingModel.SewingActualFinishDateAuto);
                            DateTime assyActualStartDate    = TimeHelper.Convert(assyModel.AssemblyActualStartDate);
                            DateTime assyActualFinishDate   = TimeHelper.Convert(assyModel.AssemblyActualFinishDate);

                            int timeRange = 0;
                            if (cutBActualStartDate != dtNothing && cutBActualStartDate != dtDefault && assyActualFinishDate != dtNothing && assyActualFinishDate != dtDefault)
                            {
                                if (assyActualStartDate != dtDefault && assyActualStartDate != dtNothing && sewingActualFinishDate != dtDefault && sewingActualFinishDate != dtNothing && assyActualStartDate > sewingActualFinishDate)
                                {
                                    //timeRange = TimeHelper.CalculateDate(sewingActualFinishDate, assyActualStartDate);
                                    timeRange = (Int32)((assyActualStartDate - sewingActualFinishDate).TotalDays);
                                    qtyXDay  += (CalculateDateRange(cutBActualStartDate, assyActualFinishDate) - timeRange) * sewingModel.CutAQuota;
                                    qtyQuota += sewingModel.CutAQuota;
                                }
                                else
                                {
                                    qtyXDay  += CalculateDateRange(cutBActualStartDate, assyActualFinishDate) * sewingModel.CutAQuota;
                                    qtyQuota += sewingModel.CutAQuota;
                                }
                            }
                        }
                    }
                    CreateData(qtyXDay, qtyQuota, line);
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    ExportReport();
                }));
            }
            #endregion

            #region None
            //#region ARTICLE
            //if (currentSection == article)
            //{
            //    var articleNoList = ordersList.Select(s => new { article = s.ArticleNo.Contains("-") ? s.ArticleNo.Split('-')[0] : s.ArticleNo }).OrderBy(o => o.article).Distinct().Select(s => s.article).ToList();
            //    foreach (var articleNo in articleNoList)
            //    {
            //        int qtyXDay = 0;
            //        int qtyQuota = 0;
            //        var productNoList = ordersList.Where(w => w.ArticleNo.Contains(articleNo)).Select(s => s.ProductNo).ToList();
            //        foreach (var productNo in productNoList)
            //        {
            //            var sewingModel = sewingMasterList.Where(w => w.ProductNo == productNo).FirstOrDefault();
            //            var assyModel = assemblyMasterList
            //                .Where(w => w.ProductNo == productNo
            //                    && TimeHelper.ConvertOldData(w.AssemblyActualFinishDate) >= dateFrom
            //                    && TimeHelper.ConvertOldData(w.AssemblyActualFinishDate) < dateTo)
            //                .FirstOrDefault();
            //            if (sewingModel != null && assyModel != null)
            //            {
            //                DateTime cutAActualStartDate = TimeHelper.ConvertOldData(sewingModel.CutAActualStartDate);
            //                DateTime sewingActualFinishDate = TimeHelper.ConvertOldData(sewingModel.SewingActualFinishDate);
            //                DateTime assyActualStartDate = TimeHelper.ConvertOldData(assyModel.AssemblyActualStartDate);
            //                DateTime assyActualFinishDate = TimeHelper.ConvertOldData(assyModel.AssemblyActualFinishDate);

            //                int timeRange = 0;
            //                if (cutAActualStartDate != dtNothing && cutAActualStartDate != dtDefault && assyActualFinishDate != dtNothing && assyActualFinishDate != dtDefault)
            //                {
            //                    if (assyActualStartDate != dtDefault && assyActualStartDate != dtNothing && sewingActualFinishDate != dtDefault && sewingActualFinishDate != dtNothing && assyActualStartDate > sewingActualFinishDate)
            //                    {
            //                        timeRange = TimeHelper.CalculateDate(sewingActualFinishDate, assyActualStartDate);
            //                        qtyXDay += (CalculateDateRange(cutAActualStartDate, assyActualFinishDate) - timeRange) * sewingModel.CutAQuota;
            //                        qtyQuota += sewingModel.CutAQuota;
            //                    }
            //                    else
            //                    {
            //                        qtyXDay += CalculateDateRange(cutAActualStartDate, assyActualFinishDate) * sewingModel.CutAQuota;
            //                        qtyQuota += sewingModel.CutAQuota;
            //                    }
            //                }
            //            }
            //        }

            //        if (qtyXDay > 0)
            //        {
            //            CreateData(qtyXDay, qtyQuota, "", articleNo);
            //        }
            //    }
            //    ExportReport();
            //}
            //#endregion

            //#region PM
            //if (currentSection == pm)
            //{
            //    var pmNoList = ordersList.Select(s => s.PatternNo).Distinct().ToList();
            //    foreach (var pmNo in pmNoList)
            //    {
            //        int qtyXDay = 0;
            //        int qtyQuota = 0;
            //        var productNoList = ordersList.Where(w => w.PatternNo == pmNo).Select(s => s.ProductNo).ToList();
            //        foreach (var productNo in productNoList)
            //        {
            //            var sewingModel = sewingMasterList.Where(w => w.ProductNo == productNo).FirstOrDefault();
            //            var assyModel = assemblyMasterList
            //                .Where(w => w.ProductNo == productNo
            //                    && TimeHelper.ConvertOldData(w.AssemblyActualFinishDate) >= dateFrom
            //                    && TimeHelper.ConvertOldData(w.AssemblyActualFinishDate) < dateTo)
            //                .FirstOrDefault();
            //            if (sewingModel != null && assyModel != null)
            //            {
            //                DateTime cutAActualStartDate = TimeHelper.ConvertOldData(sewingModel.CutAActualStartDate);
            //                DateTime sewingActualFinishDate = TimeHelper.ConvertOldData(sewingModel.SewingActualFinishDate);
            //                DateTime assyActualStartDate = TimeHelper.ConvertOldData(assyModel.AssemblyActualStartDate);
            //                DateTime assyActualFinishDate = TimeHelper.ConvertOldData(assyModel.AssemblyActualFinishDate);

            //                int timeRange = 0;
            //                if (cutAActualStartDate != dtNothing && cutAActualStartDate != dtDefault && assyActualFinishDate != dtNothing && assyActualFinishDate != dtDefault)
            //                {
            //                    if (assyActualStartDate != dtDefault && assyActualStartDate != dtNothing && sewingActualFinishDate != dtDefault && sewingActualFinishDate != dtNothing && assyActualStartDate > sewingActualFinishDate)
            //                    {
            //                        timeRange = TimeHelper.CalculateDate(sewingActualFinishDate, assyActualStartDate);
            //                        qtyXDay += (CalculateDateRange(cutAActualStartDate, assyActualFinishDate) - timeRange) * sewingModel.CutAQuota;
            //                        qtyQuota += sewingModel.CutAQuota;
            //                    }
            //                    else
            //                    {
            //                        qtyXDay += CalculateDateRange(cutAActualStartDate, assyActualFinishDate) * sewingModel.CutAQuota;
            //                        qtyQuota += sewingModel.CutAQuota;
            //                    }
            //                }
            //            }
            //        }

            //        if (qtyXDay > 0)
            //        {
            //            CreateData(qtyXDay, qtyQuota, "", pmNo);
            //        }
            //    }
            //    ExportReport();
            //}
            //#endregion
            #endregion
        }
Exemple #18
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            DataTable     dt         = new DataTable();
            var           regex      = new Regex("[a-z]|[A-Z]");
            List <String> sizeNoList = upperComponentMaterialList.Select(s => s.SizeNo).Distinct().OrderBy(s => regex.IsMatch(s) ? Double.Parse(regex.Replace(s, "")) : Double.Parse(s)).ToList();

            DateTime dtDefault        = new DateTime(2000, 01, 01);
            var      sewingMasterList = SewingMasterController.Select().ToList();

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

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

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

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

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

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



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



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

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

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

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


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


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

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

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



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

                dgInventory.FrozenColumnCount = 8;
                for (int i = 0; i <= sizeNoList.Count - 1; i++)
                {
                    //OutsoleSuppliersModel outsoleSupplier = outsoleSupplierList[i];
                    string sizeNoBinding = sizeNoList[i].Contains(".") ? sizeNoList[i].Replace(".", "") : sizeNoList[i];
                    dt.Columns.Add(String.Format("Column{0}", sizeNoBinding), typeof(Int32));
                    DataGridTextColumn column = new DataGridTextColumn();
                    //column.SetValue(TagProperty, sizeRun.SizeNo);
                    column.Header  = sizeNoList[i];
                    column.Width   = 35;
                    column.Binding = new Binding(String.Format("Column{0}", sizeNoBinding));

                    Style style = new Style(typeof(DataGridCell));
                    style.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
                    Setter setterBackground   = new Setter();
                    setterBackground.Property = DataGridCell.BackgroundProperty;
                    setterBackground.Value    = new Binding(String.Format("Column{0}Background", sizeNoBinding));
                    style.Setters.Add(setterBackground);
                    column.CellStyle = style;

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

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

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

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

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

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

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

            foreach (string productNo in productNoList)
            {
                sizeRunList = SizeRunController.Select(productNo);
                var     upperComponentMaterialList_D1 = upperComponentMaterialList.Where(w => w.ProductNo == productNo).ToList();
                DataRow dr = dt.NewRow();
                dr["ProductNo"] = productNo;
                OrdersModel order = orderList.Where(w => w.ProductNo == productNo).FirstOrDefault();
                if (order != null)
                {
                    dr["ArticleNo"] = order.ArticleNo;
                    dr["Quantity"]  = order.Quantity;
                    dr["OrderETD"]  = order.ETD;
                }

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

                UpperComponentRawMaterialModel upperComponentRawMaterialModel = upperComponentRawMaterialList.Where(w => w.ProductNo == productNo && w.UpperComponentID == upperComponentID).FirstOrDefault();
                DateTime dtTemp = new DateTime(2000, 01, 01);
                if (upperComponentRawMaterialModel != null)
                {
                    dr["DeliveryETD"] = upperComponentRawMaterialModel.ETD;
                    dtTemp            = upperComponentRawMaterialModel.ETD;
                }

                int qtyDelivery = 0;
                //int qtyMatchTotal = 0;
                foreach (string sizeNo in sizeNoList)
                {
                    string sizeNoBinding = sizeNo.Contains(".") ? sizeNo.Replace(".", "") : sizeNo;
                    int    qtyPerSize    = 0;
                    if (sizeRunList.Count > 0)
                    {
                        qtyPerSize = sizeRunList.Where(w => w.SizeNo == sizeNo).Select(s => s.Quantity).FirstOrDefault();
                    }

                    var upperComponentRecieve = upperComponentMaterialList.Where(w => w.ProductNo == productNo && w.SizeNo == sizeNo).FirstOrDefault();
                    int qtyRejectPerSize      = 0;
                    int qtyDeliveryPerSize    = 0;
                    if (upperComponentRecieve != null)
                    {
                        qtyDeliveryPerSize = upperComponentRecieve.Quantity;
                        qtyRejectPerSize   = upperComponentRecieve.QuantityReject;
                    }

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

                    //int qtyDeliveryPerSize = upperComponentMaterialList.Where(w => w.ProductNo == productNo && w.SizeNo == sizeNo).Select(s => s.Quantity).FirstOrDefault();
                    int qtyBalance = qtyPerSize - qtyDeliveryPerSize;
                    if (qtyBalance > 0 && dtTemp != dtDefault)
                    {
                        dr[String.Format("Column{0}", sizeNoBinding)] = qtyBalance + qtyRejectPerSize;
                        DateTime dtNow = DateTime.Now;
                        UpperComponentMaterialModel upperComponentMaterialRecieve = upperComponentMaterialList.Where(w => w.ProductNo == productNo && w.SizeNo == sizeNo).FirstOrDefault();
                        if (upperComponentMaterialRecieve != null)
                        {
                            if (upperComponentMaterialRecieve.ModifiedTime.Date < dtNow.Date)
                            {
                                dr[String.Format("Column{0}Background", sizeNoBinding)] = Brushes.Tomato;
                            }
                            if (upperComponentMaterialRecieve.ModifiedTime.Date == dtNow.Date)
                            {
                                dr[String.Format("Column{0}Background", sizeNoBinding)] = Brushes.Green;
                            }
                        }
                        if (qtyRejectPerSize > 0)
                        {
                            dr[String.Format("Column{0}Background", sizeNoBinding)] = Brushes.Yellow;
                            dr[String.Format("Column{0}ToolTip", sizeNoBinding)]    = String.Format("Balance: {0}\nReject: {1}", qtyBalance, qtyRejectPerSize);
                        }
                    }
                    qtyDelivery += qtyDeliveryPerSize;

                    // Matching
                    //if (upperComponentMaterialList_D1.Count > 0)
                    //{
                    //    int qtyMin = upperComponentMaterialList_D1.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;
                    //    int qtyMatch = qtyMin;
                    //    if (qtyMatch < 0)
                    //    {
                    //        qtyMatch = 0;
                    //    }
                    //    qtyMatchTotal += qtyMatch;
                    //}
                }
                int totalQty = upperComponentMaterialList.Where(w => w.ProductNo == productNo).Sum(s => s.Quantity - s.QuantityReject);
                //int totalRelease = outsoleReleaseMaterialList.Where(w => w.ProductNo == productNo).Sum(s => s.Quantity);

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

                //dr["Release"] = totalRelease;
                dr["QuantityDelivery"] = qtyDelivery;
                //dr["Matching"] = qtyMatchTotal;
                dt.Rows.Add(dr);
            }

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

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

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

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

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