예제 #1
0
        //单个领料单录入功能未完成
        public ActionResult _Outstock(int id, bool isview, FormCollection collection)
        {
            FoodMaterialOutstock stock = null;
            if (id == 0)
            {
                stock = new FoodMaterialOutstock { OutstockDate = DateTime.Today, Code = "自动生成" };
            }
            else
            {
                stock = db.FoodMaterialOutstocks.Find(id);
                if (stock == null)
                {
                    return View("ShowError", "", "找不到出库记录");
                }
            }
            if (collection != null)//Post
            {
                TryUpdateModel(stock, "", null, new string[] { "State", "InstockUnit", "InstockUnitNum", "PersonalId" }, collection);
                if (stock.SpecId == 0)
                {
                    ModelState.AddModelError("", "请选择原料类型");
                }
                if (stock.Num == 0)
                {
                    ModelState.AddModelError("Num", "领料数量不能为0");
                }
                if (ModelState.IsValid)
                {

                        if (stock.Id == 0)
                        {
                            db.FoodMaterialOutstocks.Add(stock);
                            stock.Code = SysCode.GetCode_ByDate(db, FoodMaterialOutstock.LogClass, DateTime.Today);
                        }
                        else
                        {

                        }
                        stock.PersonId = UserInfo.CurUser.Id;

                        BLL.Utilities.AddLog(stock.Id, FoodMaterialOutstock.LogClass, "添加或修改", "");
                        db.SaveChanges();
                        return Redirect("../OutstockView/" + stock.Id);

                }
            }
            FoodMaterialType food = db.FoodMaterialType.Find(stock.TypeId);
            FoodMaterialSpec spec = db.FoodMaterialSpecs.Find(stock.SpecId);
            ViewBag.Food = food;
            ViewBag.Spec = spec;
            if (isview)
            {

                if (food == null) return View("ShowError", "", "找不到原料信息");
            }
            return View(stock);
        }
예제 #2
0
 public ActionResult OutstocksEdit(int departmentId,int personId,string SpecList,string NumList,string IndexList, FormCollection collection)
 {
     string[] specList = SpecList.Split(',');
     string[] numList = NumList.Split(',');
     string[] indexList = IndexList.Split(',');
     List<IdName> itemResult=new List<IdName>();
     for(int i=0;i<specList.Length;i++)
     {
         int specId = 0;
         if(int.TryParse(specList[i],out specId))
         {
             decimal num = 0;
             decimal.TryParse(numList[i], out num);
             int index = 0;
             int.TryParse(indexList[i], out index);
             FoodMaterialSpec spec =
                 (from o in db.FoodMaterialSpecs where o.Id == specId select o).FirstOrDefault();
             if(spec!=null)
             {
                 string code = SysCode.GetCode_ByDate(db, FoodMaterialOutstock.LogClass, DateTime.Today);
                 FoodMaterialOutstock outstock = new FoodMaterialOutstock
                                                     {
                                                         TypeId = spec.TypeId,
                                                         SpecId = spec.Id,
                                                         Code = code,
                                                         DepartmentId = departmentId,
                                                         PersonId = personId,
                                                         Num = num,
                                                         OutstockDate = DateTime.Today
                                                     };
                 db.FoodMaterialOutstocks.Add(outstock);
                 itemResult.Add(new IdName{Id=index,Name="提交成功"});
             }
             db.SaveChanges();
         }
     }
     return Json(itemResult);
 }