private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList                  = OrdersController.Select();
            rawMaterialList            = RawMaterialController.Select();
            sewingMasterList           = SewingMasterController.Select();
            outsoleMasterList          = OutsoleMasterController.Select();
            outsoleReleaseMaterialList = OutsoleReleaseMaterialController.SelectByOutsoleMaster();
            productionMemoList         = ProductionMemoController.Select();

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

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

            foreach (OutsoleMasterModel outsoleMaster in outsoleMasterList)
            {
                OutsoleMasterExportViewModel outsoleMasterExportView = new OutsoleMasterExportViewModel();
                outsoleMasterExportView.Sequence  = outsoleMaster.Sequence;
                outsoleMasterExportView.ProductNo = outsoleMaster.ProductNo;
                OrdersModel order  = orderList.Where(o => o.ProductNo == outsoleMaster.ProductNo).FirstOrDefault();
                string      memoId = "";
                if (order != null)
                {
                    outsoleMasterExportView.Country     = order.Country;
                    outsoleMasterExportView.ShoeName    = order.ShoeName;
                    outsoleMasterExportView.ArticleNo   = order.ArticleNo;
                    outsoleMasterExportView.OutsoleCode = order.OutsoleCode;
                    outsoleMasterExportView.Quantity    = order.Quantity;
                    outsoleMasterExportView.ETD         = order.ETD;


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

                MaterialArrivalViewModel materialArrivalOutsole = MaterialArrival(order.ProductNo, materialIdOutsoleArray);
                outsoleMasterExportView.IsOutsoleMatsArrivalOk = false;
                if (materialArrivalOutsole != null)
                {
                    outsoleMasterExportView.OutsoleMatsArrival     = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", materialArrivalOutsole.Date);
                    outsoleMasterExportView.IsOutsoleMatsArrivalOk = materialArrivalOutsole.IsMaterialArrivalOk;
                }
                outsoleMasterExportView.OutsoleLine       = outsoleMaster.OutsoleLine;
                outsoleMasterExportView.OutsoleStartDate  = outsoleMaster.OutsoleStartDate;
                outsoleMasterExportView.OutsoleFinishDate = outsoleMaster.OutsoleFinishDate;
                outsoleMasterExportView.OutsoleQuota      = outsoleMaster.OutsoleQuota;
                outsoleMasterExportView.OutsoleBalance    = outsoleMaster.OutsoleBalance;

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

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

                List <OutsoleReleaseMaterialModel> outsoleReleaseMaterialList_D1 = outsoleReleaseMaterialList.Where(o => o.ProductNo == outsoleMaster.ProductNo).ToList();
                int qtyReleased = outsoleReleaseMaterialList_D1.Sum(o => o.Quantity);
                outsoleMasterExportView.ReleasedQuantity = qtyReleased.ToString();
                if (qtyReleased <= 0)
                {
                    outsoleMasterExportView.ReleasedQuantity = "";
                }
                if (qtyReleased >= outsoleMasterExportView.Quantity && outsoleReleaseMaterialList_D1.Count > 0)
                {
                    DateTime releasedDate = outsoleReleaseMaterialList_D1.FirstOrDefault().ModifiedTime;
                    outsoleMasterExportView.ReleasedQuantity = string.Format("{0:M/d}", releasedDate);
                }

                outsoleMasterExportViewList.Add(outsoleMasterExportView);
            }
        }
Example #2
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            orderList                   = OrdersController.Select();
            rawMaterialList             = RawMaterialController.Select();
            sewingMasterList            = SewingMasterController.Select();
            outsoleMasterList           = OutsoleMasterController.Select();
            outsoleRawMaterialList      = OutsoleRawMaterialController.Select();
            outsoleReleaseMaterialList  = OutsoleReleaseMaterialController.SelectByOutsoleMaster();
            productionMemoList          = ProductionMemoController.Select();
            outsoleMaterialList         = OutsoleMaterialController.Select();
            rawMaterialViewModelNewList = RawMaterialController.Select_1();

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

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

            foreach (OutsoleMasterModel outsoleMaster in outsoleMasterList)
            {
                OutsoleMasterExportViewModel outsoleMasterExportView = new OutsoleMasterExportViewModel();
                outsoleMasterExportView.Sequence  = outsoleMaster.Sequence;
                outsoleMasterExportView.ProductNo = outsoleMaster.ProductNo;
                OrdersModel order  = orderList.FirstOrDefault(f => f.ProductNo == outsoleMaster.ProductNo);
                string      memoId = "";
                if (order != null)
                {
                    outsoleMasterExportView.Country     = order.Country;
                    outsoleMasterExportView.ShoeName    = order.ShoeName;
                    outsoleMasterExportView.ArticleNo   = order.ArticleNo;
                    outsoleMasterExportView.OutsoleCode = order.OutsoleCode;
                    outsoleMasterExportView.PatternNo   = order.PatternNo;
                    outsoleMasterExportView.Quantity    = order.Quantity;
                    outsoleMasterExportView.ETD         = order.ETD;


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

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

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

                //if (actualDateList.Count() > 0 && actualDateList.Contains(dtDefault) == false)
                //{
                //    outsoleMasterExportView.OutsoleMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", actualDateList.Max());
                //    outsoleMasterExportView.IsOutsoleMatsArrivalOk = true;
                //}
                //else
                //{
                //    var etdDateList = osRawMaterial.Select(s => s.ETD).ToList();
                //    if (etdDateList.Count() > 0)
                //    {
                //        outsoleMasterExportView.OutsoleMatsArrival = String.Format(new CultureInfo("en-US"), "{0:dd-MMM}", etdDateList.Max());
                //    }
                //}
                outsoleMasterExportView.IsOutsoleMatsArrivalOk = false;
                var rawMaterialViewModelNew = rawMaterialViewModelNewList.FirstOrDefault(f => f.ProductNo == order.ProductNo);
                if (String.IsNullOrEmpty(rawMaterialViewModelNew.OUTSOLE_Remarks) &&
                    !String.IsNullOrEmpty(rawMaterialViewModelNew.OUTSOLE_ActualDate))
                {
                    outsoleMasterExportView.OutsoleMatsArrival     = rawMaterialViewModelNew.OUTSOLE_ActualDate;
                    outsoleMasterExportView.IsOutsoleMatsArrivalOk = true;
                }
                else
                {
                    outsoleMasterExportView.OutsoleMatsArrival = rawMaterialViewModelNew.OUTSOLE_ETD;
                }


                outsoleMasterExportView.OutsoleLine       = outsoleMaster.OutsoleLine;
                outsoleMasterExportView.OutsoleStartDate  = outsoleMaster.OutsoleStartDate;
                outsoleMasterExportView.OutsoleFinishDate = outsoleMaster.OutsoleFinishDate;
                outsoleMasterExportView.OutsoleQuota      = outsoleMaster.OutsoleQuota;
                outsoleMasterExportView.OutsoleBalance    = outsoleMaster.OutsoleBalance;

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

                // Load Outsole_Remarks from OutsoleMaterial
                var outsoleMaterial_PO      = outsoleMaterialList.Where(w => w.ProductNo == order.ProductNo).ToList();
                var osMaterialSumBySupplier = outsoleMaterial_PO.GroupBy(
                    g => g.OutsoleSupplierId)
                                              .Select(s => new
                {
                    PO             = order.ProductNo,
                    Supplier       = s.Key,
                    ActualDelivery = outsoleMaterial_PO.Where(w => w.OutsoleSupplierId == s.Key)
                                     .Sum(su => su.Quantity - su.QuantityReject)
                }).ToList();

                // if pot no one delivery. not show the balance quantity.
                if (osMaterialSumBySupplier.Count > 0 && order.Quantity - osMaterialSumBySupplier.Min(m => m.ActualDelivery) > 0)
                {
                    // show the balance
                    outsoleMasterExportView.OutsoleWHBalance = (order.Quantity - osMaterialSumBySupplier.Min(m => m.ActualDelivery)).ToString();
                    // if no one delivery, show blank
                    if (outsoleMaterial_PO.Sum(s => s.Quantity) == 0)
                    {
                        outsoleMasterExportView.OutsoleWHBalance = "";
                    }
                }

                SewingMasterModel sewingMaster = sewingMasterList.FirstOrDefault(f => f.ProductNo == outsoleMaster.ProductNo);
                if (sewingMaster != null)
                {
                    outsoleMasterExportView.SewingStartDate  = sewingMaster.SewingStartDate;
                    outsoleMasterExportView.SewingFinishDate = sewingMaster.SewingFinishDate;
                    outsoleMasterExportView.SewingQuota      = sewingMaster.SewingQuota;
                    outsoleMasterExportView.SewingBalance    = sewingMaster.SewingBalance;
                }
                else
                {
                    outsoleMasterExportView.SewingStartDate  = dtDefault;
                    outsoleMasterExportView.SewingFinishDate = dtDefault;
                    outsoleMasterExportView.SewingQuota      = 0;
                    outsoleMasterExportView.SewingBalance    = "";
                }

                List <OutsoleReleaseMaterialModel> outsoleReleaseMaterialList_D1 = outsoleReleaseMaterialList.Where(o => o.ProductNo == outsoleMaster.ProductNo).ToList();
                int qtyReleased = outsoleReleaseMaterialList_D1.Sum(o => o.Quantity);
                outsoleMasterExportView.ReleasedQuantity = qtyReleased.ToString();
                if (qtyReleased <= 0)
                {
                    outsoleMasterExportView.ReleasedQuantity = "";
                }
                if (qtyReleased >= outsoleMasterExportView.Quantity && outsoleReleaseMaterialList_D1.Count > 0)
                {
                    DateTime releasedDate = outsoleReleaseMaterialList_D1.FirstOrDefault().ModifiedTime;
                    outsoleMasterExportView.ReleasedQuantity = string.Format("{0:M/d}", releasedDate);
                }

                outsoleMasterExportViewList.Add(outsoleMasterExportView);
            }
        }