/// <summary>
        /// Upadate Outsole Material
        /// </summary>
        /// <param name="model">Material Update</param>
        /// <param name="updateReject">Update Reject?</param>
        /// <param name="updateQuantity">Update Quantity?</param>
        /// <param name="updateRejectAssembly">Update Reject Assembly?</param>
        /// <returns></returns>
        public static bool Update(OutsoleMaterialModel model, bool updateReject, bool updateQuantity, bool updateRejectAssembly, bool updateRejectStockfit)
        {
            var @ProductNo         = new SqlParameter("@ProductNo", model.ProductNo);
            var @OutsoleSupplierId = new SqlParameter("@OutsoleSupplierId", model.OutsoleSupplierId);
            var @SizeNo            = new SqlParameter("@SizeNo", model.SizeNo);
            var @Quantity          = new SqlParameter("@Quantity", model.Quantity);
            var @QuantityReject    = new SqlParameter("@QuantityReject", model.QuantityReject);
            var @RejectAssembly    = new SqlParameter("@RejectAssembly", model.RejectAssembly);
            var @RejectStockfit    = new SqlParameter("@RejectStockfit", model.RejectStockfit);

            var @UpdateQuantity       = new SqlParameter("@UpdateQuantity", updateQuantity);
            var @UpdateReject         = new SqlParameter("@UpdateReject", updateReject);
            var @UpdateRejectAssembly = new SqlParameter("@UpdateRejectAssembly", updateRejectAssembly);
            var @UpdateRejectStockfit = new SqlParameter("@UpdateRejectStockfit", updateRejectStockfit);

            using (var db = new SaovietMasterScheduleEntities())
            {
                if (db.ExecuteStoreCommand("EXEC spm_UpdateOutsoleMaterial_2    @ProductNo, @OutsoleSupplierId, @SizeNo, @Quantity, @QuantityReject, @RejectAssembly, @RejectStockfit, @UpdateReject, @UpdateQuantity, @UpdateRejectAssembly, @UpdateRejectStockfit",
                                           @ProductNo, @OutsoleSupplierId, @SizeNo, @Quantity, @QuantityReject, @RejectAssembly, @RejectStockfit, @UpdateReject, @UpdateQuantity, @UpdateRejectAssembly, @UpdateRejectStockfit) >= 1)
                {
                    return(true);
                }
                return(false);
            }
        }
        public static bool UpdateRejectFromOutsoleMaterialDetail(OutsoleMaterialModel model)
        {
            var @ProductNo         = new SqlParameter("@ProductNo", model.ProductNo);
            var @OutsoleSupplierId = new SqlParameter("@OutsoleSupplierId", model.OutsoleSupplierId);
            var @SizeNo            = new SqlParameter("@SizeNo", model.SizeNo);
            var @QuantityReject    = new SqlParameter("@QuantityReject", model.QuantityReject);

            SaovietMasterScheduleEntities db = new SaovietMasterScheduleEntities();

            if (db.ExecuteStoreCommand("EXEC spm_UpdateOutsoleMaterialFromOutsoleMaterialDetail @ProductNo,@OutsoleSupplierId,@SizeNo,@QuantityReject", @ProductNo, @OutsoleSupplierId, @SizeNo, @QuantityReject) >= 1)
            {
                return(true);
            }
            return(false);
        }
        public static bool Insert(OutsoleMaterialModel model)
        {
            var @ProductNo         = new SqlParameter("@ProductNo", model.ProductNo);
            var @OutsoleSupplierId = new SqlParameter("@OutsoleSupplierId", model.OutsoleSupplierId);
            var @SizeNo            = new SqlParameter("@SizeNo", model.SizeNo);
            var @Quantity          = new SqlParameter("@Quantity", model.Quantity);
            var @QuantityReject    = new SqlParameter("@QuantityReject", model.QuantityReject);
            var @RejectAssembly    = new SqlParameter("@RejectAssembly", model.RejectAssembly);

            SaovietMasterScheduleEntities db = new SaovietMasterScheduleEntities();

            if (db.ExecuteStoreCommand("EXEC spm_InsertOutsoleMaterial_3 @ProductNo,@OutsoleSupplierId,@SizeNo,@Quantity,@QuantityReject,@RejectAssembly", @ProductNo, @OutsoleSupplierId, @SizeNo, @Quantity, @QuantityReject, @RejectAssembly) >= 1)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        private void bwUpdateOutsoleMaterial_DoWork(object sender, DoWorkEventArgs e)
        {
            outsoleMaterialRejectUpdateList = new List <OutsoleMaterialModel>();
            var outsoleMaterialDetailAferInsertList = OutsoleMaterialDetailController.Select(productNo).Where(w => w.OutsoleSupplierId == supplierClicked.OutsoleSupplierId).ToList();
            var sizeNoList = outsoleMaterialDetailAferInsertList.Select(s => s.SizeNo).Distinct().ToList();

            foreach (var sizeNo in sizeNoList)
            {
                var firstModel = outsoleMaterialDetailAferInsertList.FirstOrDefault();
                var outsoleMaterialUpdateReject = new OutsoleMaterialModel()
                {
                    ProductNo         = firstModel.ProductNo,
                    OutsoleSupplierId = firstModel.OutsoleSupplierId,
                    SizeNo            = sizeNo,
                    QuantityReject    = outsoleMaterialDetailAferInsertList.Where(w => w.SizeNo == sizeNo).Sum(s => s.Reject),
                };
                outsoleMaterialRejectUpdateList.Add(outsoleMaterialUpdateReject);
            }
            foreach (var updateModel in outsoleMaterialRejectUpdateList)
            {
                OutsoleMaterialController.UpdateRejectFromOutsoleMaterialDetail(updateModel);
            }

            // Update Outsole RawMaterial. If Reject > 0 => Remove Actual Date
            var POAndSupplierHasRejectList = outsoleMaterialRejectUpdateList.Where(w => w.QuantityReject > 0).Select(s => new { ProductNo = s.ProductNo, OutsoleSupplierId = s.OutsoleSupplierId }).Distinct().ToList();

            foreach (var p in POAndSupplierHasRejectList)
            {
                var updateModel = new OutsoleRawMaterialModel()
                {
                    ProductNo         = p.ProductNo,
                    OutsoleSupplierId = p.OutsoleSupplierId,
                    ActualDate        = dtDefault
                };
                OutsoleRawMaterialController.UpdateActualDate(updateModel);
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Confirm Save?", this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
            {
                return;
            }
            dt = ((DataView)dgOutsoleMaterial.ItemsSource).ToTable();
            for (int r = 0; r <= dt.Rows.Count - 1; r = r + 3)
            {
                DataRow dr               = dt.Rows[r];
                DataRow drReject         = dt.Rows[r + 1];
                DataRow drRejectAssembly = dt.Rows[r + 2];
                var     outsoleSupplier  = (OutsoleSuppliersModel)dr["Supplier"];
                if (outsoleSupplier != null)
                {
                    int      outsoleSupplierId = outsoleSupplier.OutsoleSupplierId;
                    string   actualDate        = dr["ActualDate"] as String;
                    DateTime dtActualDate      = TimeHelper.Convert(actualDate);
                    if (String.IsNullOrEmpty(actualDate) == false && dtActualDate != dtNothing)
                    {
                        OutsoleRawMaterialModel outsoleRawMaterial = new OutsoleRawMaterialModel
                        {
                            ProductNo         = productNo,
                            OutsoleSupplierId = outsoleSupplierId,
                            ActualDate        = dtActualDate,
                        };

                        outsoleRawMaterialToInsertList.Add(outsoleRawMaterial);
                    }
                    for (int i = 0; i <= sizeRunList.Count - 1; i++)
                    {
                        string sizeNo   = sizeRunList[i].SizeNo;
                        int    quantity = 0;
                        Int32.TryParse(dr[String.Format("Column{0}", i)].ToString(), out quantity);

                        int quantityReject = 0;
                        Int32.TryParse(drReject[String.Format("Column{0}", i)].ToString(), out quantityReject);

                        int quantityRejectAssembly = 0;
                        Int32.TryParse(drRejectAssembly[String.Format("Column{0}", i)].ToString(), out quantityRejectAssembly);

                        if (quantity >= 0 && quantityReject >= 0)
                        {
                            var model = new OutsoleMaterialModel
                            {
                                ProductNo         = productNo,
                                OutsoleSupplierId = outsoleSupplierId,
                                SizeNo            = sizeNo,
                                Quantity          = quantity,
                                QuantityReject    = quantityReject,
                                RejectAssembly    = quantityRejectAssembly
                            };
                            outsoleMaterialToInsertList.Add(model);
                        }
                    }
                }
            }
            if (threadInsert.IsBusy == false)
            {
                this.Cursor       = Cursors.Wait;
                btnSave.IsEnabled = false;
                threadInsert.RunWorkerAsync();
            }
        }
Esempio n. 6
0
        private void BwInsert_DoWork(object sender, DoWorkEventArgs e)
        {
            var par                       = e.Argument as object[];
            var osmCheckCurrent           = par[0] as OutsoleMaterialCheckingModel;
            var currentOSMCheckListBySupp = par[1] as List <OutsoleMaterialCheckingModel>;

            try
            {
                OutsoleMaterialCheckingController.Insert(osmCheckCurrent);
                // Update Reject to WHMasterFile.
                var osMaterialCheckByPO = OutsoleMaterialCheckingController.SelectByPOSumBySize(osmCheckCurrent.ProductNo).ToList();
                foreach (var sizeRun in sizeRunList)
                {
                    var osMaterialCheckByPOBySupplier = osMaterialCheckByPO.Where(w => w.OutsoleSupplierId == osmCheckCurrent.OutsoleSupplierId).ToList();

                    var sizeCompare      = String.IsNullOrEmpty(sizeRun.OutsoleSize) == false ? sizeRun.OutsoleSize : sizeRun.SizeNo;
                    var osMatCheckBySize = osMaterialCheckByPOBySupplier.FirstOrDefault(f => f.SizeNo == sizeCompare);

                    int rejectUpdate = 0;
                    if (osMatCheckBySize != null)
                    {
                        rejectUpdate = osMatCheckBySize.Reject - osMatCheckBySize.ReturnReject > 0 ? osMatCheckBySize.Reject - osMatCheckBySize.ReturnReject : 0;
                    }
                    var osMaterialUpdate = new OutsoleMaterialModel()
                    {
                        ProductNo         = osmCheckCurrent.ProductNo,
                        OutsoleSupplierId = osmCheckCurrent.OutsoleSupplierId,
                        SizeNo            = sizeRun.SizeNo,
                        QuantityReject    = rejectUpdate
                    };
                    OutsoleMaterialController.UpdateByOSCheck(osMaterialUpdate);
                }

                // Tranfer to mainwindow sum order by size
                // Update current list
                currentOSMCheckListBySupp.RemoveAll(r => r.SizeNo == osmCheckCurrent.SizeNo &&
                                                    r.CheckingDate == osmCheckCurrent.CheckingDate &&
                                                    r.WorkingCard == osmCheckCurrent.WorkingCard);

                currentOSMCheckListBySupp.Add(osmCheckCurrent);
                if (modeReject == false && modeReturnReject == false)
                {
                    osmCheckCurrent.Quantity = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                               w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.Quantity);
                }
                else if (modeReject == true && modeReturnReject == false)
                {
                    osmCheckCurrent.Reject = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                             w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.Reject);
                }
                if (modeReturnReject == true)
                {
                    osmCheckCurrent.ReturnReject = currentOSMCheckListBySupp.Where(w => w.SizeNo == osmCheckCurrent.SizeNo &&
                                                                                   w.CheckingDate == osmCheckCurrent.CheckingDate).Sum(s => s.ReturnReject);
                }
                outsoleMaterialCheckingUpdatedBySizeList.Add(osmCheckCurrent);
            }
            catch
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    MessageBox.Show("An error occured when execute data !\nPlease try again !", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                }));
            }
        }