public static bool UpdateRejectToOutsoleMaterialDetail(OutsoleMaterialDetailModel model) { var @ProductNo = new SqlParameter("@ProductNo", model.ProductNo); var @OutsoleSupplierId = new SqlParameter("@OutsoleSupplierId", model.OutsoleSupplierId); var @SizeNo = new SqlParameter("@SizeNo", model.SizeNo); var @Reject = new SqlParameter("@Reject", model.Reject); var @CreatedBy = new SqlParameter("@CreatedBy", model.CreatedBy); var @IndexNo = new SqlParameter("@IndexNo", model.IndexNo); var @Round = new SqlParameter("@Round", model.Round); if (db.ExecuteStoreCommand("EXEC spm_UpdateOutsoleMaterialDetailFromOutsoleMaterialRejectDetail @ProductNo, @OutsoleSupplierId, @SizeNo, @Reject, @CreatedBy, @IndexNo, @Round", @ProductNo, @OutsoleSupplierId, @SizeNo, @Reject, @CreatedBy, @IndexNo, @Round) > 0) { return(true); } return(false); }
public static bool Insert(OutsoleMaterialDetailModel model, AccountModel account) { 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 @Reject = new SqlParameter("@Reject", model.Reject); var @QuantityExcess = new SqlParameter("@QuantityExcess", model.QuantityExcess); var @CreatedBy = new SqlParameter("@CreatedBy", account.UserName); var @IndexNo = new SqlParameter("@IndexNo", model.IndexNo); var @Round = new SqlParameter("@Round", model.Round); if (db.ExecuteStoreCommand("EXEC spm_InsertOutsoleMaterialDetail @ProductNo, @OutsoleSupplierId, @SizeNo, @Quantity, @Reject, @QuantityExcess,@CreatedBy,@IndexNo,@Round", @ProductNo, @OutsoleSupplierId, @SizeNo, @Quantity, @Reject, @QuantityExcess, @CreatedBy, @IndexNo, @Round) >= 1) { return(true); } return(false); }
private void bwInsert_DoWork(object sender, DoWorkEventArgs e) { foreach (var insertModel in rejectDetailFromTableList) { OutsoleMaterialRejectDetailController.Insert(insertModel); } // create OutsoleMaterialDetail and Update var updateRejectToOutsoleMaterialDetailList = new List <OutsoleMaterialDetailModel>(); var ousoleMaterialRejectDetailModel = rejectDetailFromTableList.FirstOrDefault(); if (ousoleMaterialRejectDetailModel != null) { var sizeNoList = rejectDetailFromTableList.Select(s => s.SizeNo).Distinct().ToList(); foreach (var sizeNo in sizeNoList) { var osMaterialDetail = new OutsoleMaterialDetailModel() { ProductNo = ousoleMaterialRejectDetailModel.ProductNo, OutsoleSupplierId = ousoleMaterialRejectDetailModel.OutsoleSupplierId, SizeNo = sizeNo, CreatedBy = ousoleMaterialRejectDetailModel.CreatedBy, IndexNo = ousoleMaterialRejectDetailModel.IndexNo, Round = ousoleMaterialRejectDetailModel.Round, Reject = rejectDetailFromTableList.Where(w => w.SizeNo == sizeNo).Select(s => s.QuantityReject).Sum() }; updateRejectToOutsoleMaterialDetailList.Add(osMaterialDetail); } } foreach (var updateModel in updateRejectToOutsoleMaterialDetailList) { OutsoleMaterialRejectDetailController.UpdateRejectToOutsoleMaterialDetail(updateModel); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { var outsoleMaterialDetailQuantityList = new List <OutsoleMaterialDetailModel>(); var outsoleMaterialDetailRejectList = new List <OutsoleMaterialDetailModel>(); DataTable dtInsert = ((DataView)dgAdd.ItemsSource).ToTable(); if (dtInsert == null) { return; } foreach (DataRow dr in dtInsert.Rows) { string status = dr["Status"].ToString(); if (status.Contains(_ARRIVAL)) { continue; } for (int i = 0; i <= sizeRunList.Count - 1; i++) { var sizeRun = sizeRunList[i]; var materialDetailQty = new OutsoleMaterialDetailModel() { ProductNo = productNo, OutsoleSupplierId = supplierClicked.OutsoleSupplierId, SizeNo = sizeRun.SizeNo, CreatedBy = account.UserName, IndexNo = INDEXNO, Round = ROUND, }; int qty = 0, reject = 0; if (status.Contains(_QUANTITY)) { Int32.TryParse(dr[String.Format("Column{0}", i)].ToString(), out qty); materialDetailQty.Quantity = qty; outsoleMaterialDetailQuantityList.Add(materialDetailQty); } if (status.Contains(_REJECT)) { Int32.TryParse(dr[String.Format("Column{0}", i)].ToString(), out reject); materialDetailQty.Reject = reject; outsoleMaterialDetailRejectList.Add(materialDetailQty); } } } foreach (var outsoleMaterial in outsoleMaterialDetailQuantityList) { var outsoleMaterialDetailInsert = outsoleMaterial; var reject = outsoleMaterialDetailRejectList.FirstOrDefault(f => f.SizeNo == outsoleMaterial.SizeNo).Reject; var quantity = outsoleMaterial.Quantity; if (outsoleMaterial.Quantity == 0 && reject == 0) { continue; } outsoleMaterialDetailInsert.Quantity = quantity; outsoleMaterialDetailInsert.Reject = reject; outsoleMaterialDetailToInsertList.Add(outsoleMaterialDetailInsert); } if (bwInsert.IsBusy == false) { this.Cursor = Cursors.Wait; btnSave.IsEnabled = false; bwInsert.RunWorkerAsync(); } }