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

            foreach (AssemblyMasterModel assemblyMaster in assemblyMasterList)
            {
                AssemblyMasterExportViewModel assemblyMasterExportView = new AssemblyMasterExportViewModel();
                assemblyMasterExportView.Sequence  = assemblyMaster.Sequence;
                assemblyMasterExportView.ProductNo = assemblyMaster.ProductNo;
                OrdersModel order  = orderList.Where(o => o.ProductNo == assemblyMaster.ProductNo).FirstOrDefault();
                string      memoId = "";
                if (order != null)
                {
                    assemblyMasterExportView.Country   = order.Country;
                    assemblyMasterExportView.ShoeName  = order.ShoeName;
                    assemblyMasterExportView.ArticleNo = order.ArticleNo;
                    assemblyMasterExportView.LastCode  = order.LastCode;
                    assemblyMasterExportView.Quantity  = order.Quantity;
                    assemblyMasterExportView.ETD       = order.ETD;

                    List <ProductionMemoModel> productionMemoByProductionNumberList = productionMemoList.Where(p => p.ProductionNumbers.Contains(order.ProductNo) == true).ToList();
                    for (int p = 0; p <= productionMemoByProductionNumberList.Count - 1; p++)
                    {
                        ProductionMemoModel productionMemo = productionMemoByProductionNumberList[p];
                        memoId += productionMemo.MemoId;
                        if (p < productionMemoByProductionNumberList.Count - 1)
                        {
                            memoId += "\n";
                        }
                    }
                    assemblyMasterExportView.MemoId = memoId;
                }

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

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

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

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

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

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

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

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

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

                SockliningMasterModel sockliningMaster = sockliningMasterList.Where(o => o.ProductNo == assemblyMaster.ProductNo).FirstOrDefault();
                if (sockliningMaster != null)
                {
                    assemblyMasterExportView.InsoleBalance = sockliningMaster.InsoleBalance;
                    assemblyMasterExportView.InsockBalance = sockliningMaster.InsockBalance;
                }
                else
                {
                    assemblyMasterExportView.InsoleBalance = "";
                    assemblyMasterExportView.InsockBalance = "";
                }
                assemblyMasterExportViewList.Add(assemblyMasterExportView);
            }
        }