private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            assemblyMasterList          = AssemblyMasterController.Select();
            sewingOutputList            = SewingOutputController.SelectByAssemblyMaster();
            outsoleOutputList           = OutsoleOutputController.SelectByAssemblyMaster();
            assemblyReleaseList         = AssemblyReleaseController.SelectByAssemblyMaster();
            orderList                   = OrdersController.Select();
            sockliningInputList         = SockliningInputController.SelectByAssemblyMaster();
            sizeRunList                 = SizeRunController.SelectIsEnable();
            rawMaterialViewModelNewList = RawMaterialController.Select_1();

            List <UpperWHInventoryViewModel> upperWHInventoryList   = new List <UpperWHInventoryViewModel>();
            List <UpperWHInventoryViewModel> upperWHInventoryList_1 = new List <UpperWHInventoryViewModel>();
            var POList = orderList.Select(s => s.ProductNo).Distinct().ToList();

            foreach (var productNo in POList)
            {
                var assemblyMaster_PO  = assemblyMasterList.FirstOrDefault(w => w.ProductNo == productNo);
                var assemblyRelease_PO = assemblyReleaseList.Where(w => w.ProductNo == productNo).ToList();
                var sewingOutput_PO    = sewingOutputList.Where(w => w.ProductNo == productNo).ToList();
                var outsoleOutput_PO   = outsoleOutputList.Where(w => w.ProductNo == productNo).ToList();
                var sockliningInput_PO = sockliningInputList.Where(w => w.ProductNo == productNo).ToList();
                var sizeNoList         = sizeRunList.Where(w => w.ProductNo == productNo).Select(s => s.SizeNo).ToList();

                int qtyUpper_PO = 0, qtyOutsole_PO = 0, qtySocklining_PO = 0, qtyMatch_PO = 0, qtyMatchWithSocklining_PO = 0;
                foreach (var sizeNo in sizeNoList)
                {
                    int qtyAssemblyRelease_Size = assemblyRelease_PO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Quantity);
                    int qtySewingOutput_Size    = sewingOutput_PO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Quantity);
                    int qtyOutsoleOutput_Size   = outsoleOutput_PO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Quantity);
                    int qtySocklining_Size      = sockliningInput_PO.Where(w => w.SizeNo == sizeNo).Sum(s => s.Quantity);

                    int qtyUpper = qtySewingOutput_Size - qtyAssemblyRelease_Size;
                    if (qtyUpper < 0)
                    {
                        qtyUpper = 0;
                    }
                    qtyUpper_PO += qtyUpper;

                    int qtyOutsole = qtyOutsoleOutput_Size - qtyAssemblyRelease_Size;
                    if (qtyOutsole < 0)
                    {
                        qtyOutsole = 0;
                    }
                    qtyOutsole_PO += qtyOutsole;

                    int qtySocklining = qtySocklining_Size - qtyAssemblyRelease_Size;
                    if (qtySocklining < 0)
                    {
                        qtySocklining = 0;
                    }
                    qtySocklining_PO += qtySocklining;

                    int qtyMatch = Math.Min(qtySewingOutput_Size, qtyOutsoleOutput_Size) - qtyAssemblyRelease_Size;
                    if (qtyMatch < 0)
                    {
                        qtyMatch = 0;
                    }
                    qtyMatch_PO += qtyMatch;

                    List <Int32> materialList = new List <Int32>();
                    materialList.Add(qtySewingOutput_Size > 0 ? qtySewingOutput_Size : 0);
                    materialList.Add(qtyOutsoleOutput_Size > 0 ? qtyOutsoleOutput_Size : 0);
                    materialList.Add(qtySocklining_Size > 0 ? qtySocklining_Size : 0);

                    int qtyMatchWithSocklining = materialList.Min() - qtyAssemblyRelease_Size;
                    if (qtyMatchWithSocklining < 0)
                    {
                        qtyMatchWithSocklining = 0;
                    }
                    qtyMatchWithSocklining_PO += qtyMatchWithSocklining;
                }

                string assemblyLine_PO   = assemblyMaster_PO != null ? assemblyMaster_PO.AssemblyLine : "";
                var    upperInventory_PO = new UpperWHInventoryViewModel()
                {
                    AssemblyLine           = assemblyLine_PO,
                    SewingOutput           = qtyUpper_PO,
                    OutsoleOutput          = qtyOutsole_PO,
                    SockliningInput        = qtySocklining_PO,
                    Matching               = qtyMatch_PO,
                    MatchingWithSocklining = qtyMatchWithSocklining_PO,
                };
                upperWHInventoryList.Add(upperInventory_PO);
            }

            var assemblyLineList = upperWHInventoryList.Select(s => s.AssemblyLine).Distinct().ToList();

            if (assemblyLineList.Count() > 0)
            {
                assemblyLineList = assemblyLineList.OrderBy(o => o).ToList();
            }
            var regex = new Regex(@"\D");
            var assemblyLineCustomList = assemblyLineList.Select(s => new { Line = s, LineNumber = regex.IsMatch(s) ? regex.Replace(s, "") : s }).ToList();

            if (assemblyLineCustomList.Count() > 0)
            {
                assemblyLineCustomList = assemblyLineCustomList.OrderBy(o => String.IsNullOrEmpty(o.LineNumber) ? 100 : Int32.Parse(o.LineNumber)).ThenBy(th => th.Line).ToList();
            }

            foreach (var assemblyLineCustom in assemblyLineCustomList)
            {
                var assemblyLine = assemblyLineCustom.Line;
                var upperWHInventoryByAssemblyLine = upperWHInventoryList.Where(w => w.AssemblyLine == assemblyLine).ToList();
                var productNoList_Assembly         = assemblyMasterList.Where(w => w.AssemblyLine == assemblyLine).Select(s => s.ProductNo).Distinct().ToList();
                var upperInventory = new UpperWHInventoryViewModel()
                {
                    AssemblyLine    = assemblyLine,
                    ProductNoList   = productNoList_Assembly,
                    SewingOutput    = upperWHInventoryByAssemblyLine.Sum(s => s.SewingOutput),
                    OutsoleOutput   = upperWHInventoryByAssemblyLine.Sum(s => s.OutsoleOutput),
                    SockliningInput = upperWHInventoryByAssemblyLine.Sum(s => s.SockliningInput),
                    Matching        = upperWHInventoryByAssemblyLine.Sum(s => s.Matching),
                };
                upperWHInventoryViewList.Add(upperInventory);

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

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

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

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

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

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

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

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

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

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

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

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

                SockliningMasterModel sockliningMaster = sockliningMasterList.Where(o => o.ProductNo == assemblyMaster.ProductNo).FirstOrDefault();
                if (sockliningMaster != null)
                {
                    assemblyMasterExportView.InsoleBalance = sockliningMaster.InsoleBalance;
                    assemblyMasterExportView.InsockBalance = sockliningMaster.InsockBalance;
                }
                else
                {
                    assemblyMasterExportView.InsoleBalance = "";
                    assemblyMasterExportView.InsockBalance = "";
                }
                assemblyMasterExportViewList.Add(assemblyMasterExportView);
            }
        }
 private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
 {
     orderList          = OrdersController.Select();
     assemblyMasterList = AssemblyMasterController.Select();
     sewingMasterList   = SewingMasterController.Select();
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataTable dt = new UpperWHInventoryDetailDataSet().Tables["UpperWHInventoryDetailTable"];

            assemblyMasterList  = AssemblyMasterController.Select();
            sewingOutputList    = SewingOutputController.SelectByAssemblyMaster();
            outsoleOutputList   = OutsoleOutputController.SelectByAssemblyMaster();
            assemblyReleaseList = AssemblyReleaseController.SelectByAssemblyMaster();
            orderList           = OrdersController.SelectByAssemblyMaster();

            List <UpperWHInventoryViewModel> upperWHInventoryViewList = new List <UpperWHInventoryViewModel>();

            assemblyLineList = assemblyMasterList.Where(a => String.IsNullOrEmpty(a.AssemblyLine) == false).Select(a => a.AssemblyLine).Distinct().OrderBy(l => l).ToList();

            // Total value
            //int upperTotal = 0;
            //int outsoleTotal = 0;
            //int matchingTotal = 0;
            // Sum value
            int upperSum, outsoleSum, matchingSum;

            foreach (string assemblyLine in assemblyLineList)
            {
                List <String> productNoList = assemblyMasterList.Where(a => a.AssemblyLine == assemblyLine).Select(o => o.ProductNo).OrderBy(l => l).Distinct().ToList();
                List <UpperWHInventoryDetailViewModel> upperWHInventoryDetailViewList = new List <UpperWHInventoryDetailViewModel>();
                foreach (string productNo in productNoList)
                {
                    UpperWHInventoryDetailViewModel upperWHInventoryDetailView = new UpperWHInventoryDetailViewModel();
                    OrdersModel order = orderList.Where(o => o.ProductNo == productNo).FirstOrDefault();
                    if (order != null)
                    {
                        upperWHInventoryDetailView.ProductNo = productNo;
                        upperWHInventoryDetailView.ShoeName  = order.ShoeName;
                        upperWHInventoryDetailView.ArticleNo = order.ArticleNo;
                    }
                    int qtyUpperTotal   = 0;
                    int qtyOutsoleTotal = 0;
                    int qtyMatchTotal   = 0;
                    int qtyQuantity     = order.Quantity;
                    int qtyReleaseTotal = 0;
                    List <AssemblyReleaseModel> assemblyReleaseList_D1 = assemblyReleaseList.Where(a => a.ProductNo == productNo).ToList();
                    List <SewingOutputModel>    sewingOutputList_D1    = sewingOutputList.Where(s => s.ProductNo == productNo).ToList();
                    List <OutsoleOutputModel>   outsoleOutputList_D1   = outsoleOutputList.Where(o => o.ProductNo == productNo).ToList();

                    List <String> sizeNoList = sewingOutputList_D1.Select(s => s.SizeNo).Distinct().ToList();
                    if (sizeNoList.Count == 0)
                    {
                        sizeNoList = outsoleOutputList_D1.Select(o => o.SizeNo).Distinct().ToList();
                    }
                    foreach (string sizeNo in sizeNoList)
                    {
                        int qtyRelease = assemblyReleaseList_D1.Where(a => a.SizeNo == sizeNo).Sum(a => a.Quantity);
                        int qtyUpper   = sewingOutputList_D1.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity)
                                         - qtyRelease;
                        int qtyOutsole = outsoleOutputList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity)
                                         - qtyRelease;
                        int qtyMatch =
                            MatchingHelper.Calculate(sewingOutputList_D1.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity),
                                                     outsoleOutputList_D1.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity), sizeNo)
                            - qtyRelease;
                        if (qtyUpper < 0)
                        {
                            qtyUpper = 0;
                        }
                        qtyUpperTotal += qtyUpper;
                        if (qtyOutsole < 0)
                        {
                            qtyOutsole = 0;
                        }
                        qtyOutsoleTotal += qtyOutsole;
                        if (qtyMatch < 0)
                        {
                            qtyMatch = 0;
                        }
                        qtyMatchTotal += qtyMatch;
                        if (qtyRelease < 0)
                        {
                            qtyRelease = 0;
                        }
                        qtyReleaseTotal += qtyRelease;
                    }
                    upperWHInventoryDetailView.Quantity        = qtyQuantity;
                    upperWHInventoryDetailView.ReleaseQuantity = qtyReleaseTotal;
                    upperWHInventoryDetailView.SewingOutput    = qtyUpperTotal;
                    upperWHInventoryDetailView.OutsoleOutput   = qtyOutsoleTotal;
                    upperWHInventoryDetailView.Matching        = qtyMatchTotal;

                    //UpperWHInventoryViewModel upperWHInventoryView = new UpperWHInventoryViewModel
                    //{
                    //    AssemblyLine = assemblyLine,
                    //    ProductNoList = productNoList,
                    //    SewingOutput = qtyUpperTotal,
                    //    OutsoleOutput = qtyOutsoleTotal,
                    //    Matching = qtyMatchTotal,
                    //};
                    //upperWHInventoryViewList.Add(upperWHInventoryView);


                    if (upperWHInventoryDetailView.SewingOutput != 0 || upperWHInventoryDetailView.OutsoleOutput != 0)
                    {
                        upperWHInventoryDetailViewList.Add(upperWHInventoryDetailView);
                    }
                }

                Int32.TryParse(upperWHInventoryDetailViewList.Sum(o => o.SewingOutput).ToString(), out upperSum);
                Int32.TryParse(upperWHInventoryDetailViewList.Sum(o => o.OutsoleOutput).ToString(), out outsoleSum);
                Int32.TryParse(upperWHInventoryDetailViewList.Sum(o => o.Matching).ToString(), out matchingSum);

                //List<int> upperSumList = upperWHInventoryDetailViewList.Where(o => o.SewingOutput != 0).Select(p => p.SewingOutput).ToList();
                //List<int> ousoleSumList = upperWHInventoryDetailViewList.Where(o => o.OutsoleOutput != 0).Select(p => p.OutsoleOutput).ToList();
                //List<int> matchingSumList = upperWHInventoryDetailViewList.Where(o => o.Matching != 0).Select(p => p.Matching).ToList();

                foreach (UpperWHInventoryDetailViewModel print in upperWHInventoryDetailViewList)
                {
                    DataRow dr = dt.NewRow();
                    dr["ProductNo"]    = print.ProductNo;
                    dr["ShoeName"]     = print.ShoeName;
                    dr["ArticleNo"]    = print.ArticleNo;
                    dr["AssemblyLine"] = assemblyLine;
                    //dr["AssemblyLineSum"] = assemblyLine;
                    dr["Quantity"] = print.Quantity;
                    dr["Release"]  = print.ReleaseQuantity;
                    dr["Upper"]    = print.SewingOutput;
                    dr["OutSole"]  = print.OutsoleOutput;
                    dr["Matching"] = print.Matching;

                    //dr["UpperSum"] = upperWHInventoryDetailViewList.Sum(o => o.SewingOutput).ToString();
                    //dr["OutSoleSum"] = upperWHInventoryDetailViewList.Sum(o => o.OutsoleOutput).ToString();
                    //dr["MatchingSum"] = upperWHInventoryDetailViewList.Sum(o => o.Matching).ToString();
                    dr["UpperSum"]    = upperSum;
                    dr["OutSoleSum"]  = outsoleSum;
                    dr["MatchingSum"] = matchingSum;

                    dt.Rows.Add(dr);
                }
            }


            ReportDataSource rds = new ReportDataSource();

            rds.Name = "UpperWHInventoryDetail_DataSetV9";
            //rds.Name = "UpperWHInventoryDetailFinal";
            rds.Value = dt;
            //reportViewer.LocalReport.ReportPath = @"C:\Users\IT02\Documents\Visual Studio 2010\Projects\Saoviet Master Schedule Solution\MasterSchedule\Reports\DelayReport.rdlc";
            reportViewer.LocalReport.ReportPath = @"Reports\UpperWHInventoryDetailReport.rdlc";
            //reportViewer.LocalReport.ReportPath = @"Reports\UpperWHInventoryDetailReportV11.rdlc";
            reportViewer.LocalReport.DataSources.Add(rds);
            reportViewer.RefreshReport();
            this.Cursor = null;
        }
        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);
            }
        }
Ejemplo n.º 10
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
        {
            assemblyMasterList  = AssemblyMasterController.Select();
            sewingOutputList    = SewingOutputController.SelectByAssemblyMaster();
            outsoleOutputList   = OutsoleOutputController.SelectByAssemblyMaster();
            assemblyReleaseList = AssemblyReleaseController.SelectByAssemblyMaster();
            orderList           = OrdersController.SelectByAssemblyMaster();

            List <UpperWHInventoryViewModel> upperWHInventoryViewList = new List <UpperWHInventoryViewModel>();

            assemblyLineList = assemblyMasterList.Where(a => String.IsNullOrEmpty(a.AssemblyLine) == false).Select(a => a.AssemblyLine).Distinct().OrderBy(l => l).ToList();
            foreach (string assemblyLine in assemblyLineList)
            {
                List <String> productNoList = assemblyMasterList.Where(a => a.AssemblyLine == assemblyLine).Select(o => o.ProductNo).Distinct().ToList();

                List <AssemblyReleaseModel> assemblyReleaseList_D1 = assemblyReleaseList.Where(a => productNoList.Contains(a.ProductNo) == true).ToList();
                List <SewingOutputModel>    sewingOutputList_D1    = sewingOutputList.Where(s => productNoList.Contains(s.ProductNo) == true).ToList();
                List <OutsoleOutputModel>   outsoleOutputList_D1   = outsoleOutputList.Where(o => productNoList.Contains(o.ProductNo) == true).ToList();

                int qtyUpperTotal   = 0;
                int qtyOutsoleTotal = 0;
                int qtyMatchTotal   = 0;
                foreach (string productNo in productNoList)
                {
                    List <AssemblyReleaseModel> assemblyReleaseList_D2 = assemblyReleaseList_D1.Where(a => a.ProductNo == productNo).ToList();
                    List <SewingOutputModel>    sewingOutputList_D2    = sewingOutputList_D1.Where(s => s.ProductNo == productNo).ToList();
                    List <OutsoleOutputModel>   outsoleOutputList_D2   = outsoleOutputList_D1.Where(o => o.ProductNo == productNo).ToList();

                    List <String> sizeNoList = sewingOutputList_D2.Select(s => s.SizeNo).Distinct().ToList();
                    if (sizeNoList.Count == 0)
                    {
                        sizeNoList = outsoleOutputList_D2.Select(o => o.SizeNo).Distinct().ToList();
                    }
                    foreach (string sizeNo in sizeNoList)
                    {
                        int qtyRelease = assemblyReleaseList_D2.Where(a => a.SizeNo == sizeNo).Sum(a => a.Quantity);
                        int qtyUpper   = sewingOutputList_D2.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity)
                                         - qtyRelease;
                        int qtyOutsole = outsoleOutputList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity)
                                         - qtyRelease;
                        int qtyMatch =
                            MatchingHelper.Calculate(sewingOutputList_D2.Where(s => s.SizeNo == sizeNo).Sum(s => s.Quantity),
                                                     outsoleOutputList_D2.Where(o => o.SizeNo == sizeNo).Sum(o => o.Quantity), sizeNo)
                            - qtyRelease;
                        if (qtyUpper < 0)
                        {
                            qtyUpper = 0;
                        }
                        qtyUpperTotal += qtyUpper;
                        if (qtyOutsole < 0)
                        {
                            qtyOutsole = 0;
                        }
                        qtyOutsoleTotal += qtyOutsole;
                        if (qtyMatch < 0)
                        {
                            qtyMatch = 0;
                        }
                        qtyMatchTotal += qtyMatch;
                    }
                }
                UpperWHInventoryViewModel upperWHInventoryView = new UpperWHInventoryViewModel
                {
                    AssemblyLine  = assemblyLine,
                    ProductNoList = productNoList,
                    SewingOutput  = qtyUpperTotal,
                    OutsoleOutput = qtyOutsoleTotal,
                    Matching      = qtyMatchTotal,
                };

                upperWHInventoryViewList.Add(upperWHInventoryView);
            }

            e.Result = upperWHInventoryViewList;
        }