private void bwInsert_DoWork(object sender, DoWorkEventArgs e) { foreach (InsockRawMaterialModel model in insockRawMaterialToInsertList) { InsockRawMaterialController.UpdateActualDate(model); } foreach (InsockMaterialModel model in insockMaterialToInsertList) { InsockMaterialModel insockMaterialDB = InsockMaterialController.Select(model.ProductNo).Where(w => w.SizeNo == model.SizeNo && w.InsockSupplierId == model.InsockSupplierId).FirstOrDefault(); // Insert if (insockMaterialDB == null) { InsockMaterialController.Insert(model); } // Update else { // Update quantity if (insockMaterialDB.Quantity != model.Quantity) { InsockMaterialController.Update(model, false, true); } // Update Reject if (insockMaterialDB.QuantityReject != model.QuantityReject) { InsockMaterialController.Update(model, true, false); } } } }
private void btnSave_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Confirm Save?", this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } dt = ((DataView)dgInsockMaterial.ItemsSource).ToTable(); for (int r = 0; r <= dt.Rows.Count - 1; r = r + 2) { DataRow dr = dt.Rows[r]; DataRow dr1 = dt.Rows[r + 1]; InsockSuppliersModel insockSupplier = (InsockSuppliersModel)dr["Supplier"]; if (insockSupplier != null) { int insockSupplierId = insockSupplier.InsockSupplierId; string actualDate = dr["ActualDate"] as String; DateTime dtActualDate = TimeHelper.Convert(actualDate); if (String.IsNullOrEmpty(actualDate) == false && dtActualDate != dtNothing) { InsockRawMaterialModel insockRawMaterial = new InsockRawMaterialModel { ProductNo = productNo, InsockSupplierId = insockSupplierId, ActualDate = dtActualDate, }; insockRawMaterialToInsertList.Add(insockRawMaterial); } for (int i = 0; i <= sizeRunList.Count - 1; i++) { string sizeNo = sizeRunList[i].SizeNo; int quantity = (Int32)dr[String.Format("Column{0}", i)]; int quantityReject = (Int32)dr1[String.Format("Column{0}", i)]; if (quantity >= 0 && quantityReject >= 0) { InsockMaterialModel model = new InsockMaterialModel { ProductNo = productNo, InsockSupplierId = insockSupplierId, SizeNo = sizeNo, Quantity = quantity, QuantityReject = quantityReject, }; insockMaterialToInsertList.Add(model); } } } } if (threadInsert.IsBusy == false) { this.Cursor = Cursors.Wait; btnSave.IsEnabled = false; threadInsert.RunWorkerAsync(); } }
public static bool Insert(InsockMaterialModel model) { var @ProductNo = new SqlParameter("@ProductNo", model.ProductNo); var @InsockSupplierId = new SqlParameter("@InsockSupplierId", model.InsockSupplierId); var @SizeNo = new SqlParameter("@SizeNo", model.SizeNo); var @Quantity = new SqlParameter("@Quantity", model.Quantity); var @QuantityReject = new SqlParameter("@QuantityReject", model.QuantityReject); SaovietMasterScheduleEntities db = new SaovietMasterScheduleEntities(); if (db.ExecuteStoreCommand("EXEC spm_InsertInsockMaterial @ProductNo, @InsockSupplierId, @SizeNo, @Quantity, @QuantityReject", @ProductNo, @InsockSupplierId, @SizeNo, @Quantity, @QuantityReject) >= 1) { return(true); } return(false); }