Example #1
0
 public ActionResult InstockReturn(int id, FormCollection collection)
 {
     FoodMaterialInstockReturn ret = new FoodMaterialInstockReturn();
     if (id == 0)
     {
         int instockid = 0;
         int.TryParse(Request["instockid"], out instockid);
         ret.InstockId = instockid;
         db.FoodMaterialInstockReturns.Add(ret);
     }
     else
     {
         ret = (from o in db.FoodMaterialInstockReturns where o.Id == id select o).FirstOrDefault();
     }
     TryUpdateModel(ret, "", null, new string[] { "InstockId" }, collection);
     if (ret.Num <= 0)
     {
         ModelState.AddModelError("Num", "数量必须大于0");
     }
     if (ModelState.IsValid)
     {
         ret.PersonId = UserInfo.CurUser.Id;
         db.SaveChanges();
         db.Database.ExecuteSqlCommand(string.Format("update foodmaterialinstocks set num={0} where id={1}", ret.BeforeNum - ret.Num, ret.InstockId));
         return Redirect("~/content/close.htm");
     }
     return View(ret);
 }
Example #2
0
 public ActionResult InstockReturn(int id)
 {
     FoodMaterialInstockReturn ret = new FoodMaterialInstockReturn();
     if (id != 0)
     {
         ret = (from o in db.FoodMaterialInstockReturns where o.Id == id select o).FirstOrDefault();
     }
     else
     {
         int instockid = 0;
         int.TryParse(Request["instockid"], out instockid);
         FoodMaterialInstock instock = (from o in db.FoodMaterialInstocks where o.Id == instockid select o).FirstOrDefault();
         if (instock == null)
         {
             return View("ShowError", "", "找不到入库单");
         }
         ret.BeforeNum = instock.Num;
         ret.ReturnDate = DateTime.Today;
     }
     return View(ret);
 }