public bool judge(tb_DamagedDrug damagedDrug, int flag) { var Drug = drugBLL.GetList(en => en.Id == damagedDrug.DrugId).FirstOrDefault(); if (Drug == null) { ModelState.AddModelError("DrugId", "药品不存在,请重新输入"); return(false); } else { var depotDrug = depotDrugBLL.GetList(en => en.Id == damagedDrug.DepotDrugId).FirstOrDefault(); if (depotDrug == null) { ModelState.AddModelError("DepotDrugId", "药品存放信息不存在,请重新输入"); return(false); } else { if (depotDrug.DrugId != damagedDrug.DrugId) { ModelState.AddModelError("DepotDrugId", "药品存放信息不存在,请重新输入"); return(false); } else { int m = damagedDrug.Num; int n = depotDrug.Num; if (flag == 1) { depotDrug.Num = n - m; } else { BLL.DamagedDrugBLL DamagedDrugBLL = new BLL.DamagedDrugBLL(); var da = DamagedDrugBLL.GetList(en => en.Id == damagedDrug.Id).FirstOrDefault(); int j = da.Num; depotDrug.Num = n + j - m; } if (depotDrug.Num < 0) { ModelState.AddModelError("Num", "所报药品库存不足,请重新输入"); return(false); } else { depotDrugBLL.Modify(depotDrug); return(true); } } } } }
public ActionResult Create(tb_DamagedDrug damagedDrug, FormCollection form) { if (ModelState.IsValid) { if (judge(damagedDrug, 1) == false) { return(View("Create", damagedDrug)); } else { damagedDrugBLL.Add(damagedDrug); return(RedirectToAction("Damaged")); } } else { return(View("Create", damagedDrug)); } }
public ActionResult Edit(tb_DamagedDrug damagedDrug, FormCollection form) { if (ModelState.IsValid) { if (judge(damagedDrug, 0) == false) { return(View("Edit", damagedDrug)); } else { UpdateModel(damagedDrug, new[] { "DrugId", "DepotDrugId", "DamagedDate", "Num", "Reason" }); damagedDrugBLL.Modify(damagedDrug); return(RedirectToAction("Damaged")); } } else { return(View("Edit", damagedDrug)); } }