public ActionResult Edit(int pid, int wid) { try { if (db.ProductWashings.Any(A => A.ProductID == pid && A.WashingID == wid)) { return(Json(new { Status = false, Message = "洗滌條件重覆選取 !", })); } ProductWashing _PW = new ProductWashing() { WashingID = wid, ProductID = pid, }; db.ProductWashings.Add(_PW); db.SaveChanges(); return(Json(new { Status = true, Message = "清洗方式新增成功", })); } catch (Exception) { throw; } }
private void btnInsert_Click(object sender, EventArgs e) { if (cbWashing.SelectedIndex < 0) { MessageBox.Show($"尚未選取 [洗滌方式] , 無法存檔"); return; } //判斷洗滌方式是否重覆 int washingID = (int)cbWashing.SelectedValue; if (dbContext.ProductWashings.Any(x => x.ProductID == cProd.ProductID && x.WashingID == washingID)) { MessageBox.Show($"產品的 [洗滌方式] 重覆 , 無法存檔"); return; } try //寫入ProductWashing { ProductWashing pw = new ProductWashing(); pw.ProductID = cProd.ProductID; pw.WashingID = (int)cbWashing.SelectedValue; pw.CreateDate = DateTime.Now; dbContext.ProductWashings.Add(pw); dbContext.SaveChanges(); int i = pw.ProductWashingID; //取得資料庫自增ID MessageBox.Show($"洗滌方式 [新增] 資料成功 => ID: {i} "); ResetData(); } catch (Exception ex) { Debug.WriteLine(ex); MessageBox.Show("洗滌方式 [新增] 資料失敗, 請檢查欄位資料後再試一下, 或找系統管理員協助處理 !"); } }
public ActionResult Create(int pid, int wid) { try { if (db.ProductWashings.Any(x => x.ProductID == pid && x.WashingID == wid)) { return(Json(new { Status = false, Message = "洗滌條件重覆選取 !", })); } ProductWashing pw = new ProductWashing { ProductID = pid, WashingID = wid }; db.ProductWashings.Add(pw); db.SaveChanges(); } catch (Exception ex) { return(Json(new { Status = false, Message = ex.ToString(), })); } return(Json(new { Status = true, })); }
public void Update(ProductWashing _productwashing) { throw new NotImplementedException(); }
public void Delete(ProductWashing _productwashing) { db.ProductWashings.Remove(_productwashing); db.SaveChanges(); }
public void Create(ProductWashing _productwashing) { db.ProductWashings.Add(_productwashing); db.SaveChanges(); }