Ejemplo n.º 1
0
        public ActionResult SpecEdit(int id, FormCollection collection)
        {
            FoodMaterialType t;
            FoodMaterialSpec s;
            int materialid;
            if (id == 0)
            {
                int.TryParse(Request["materialid"], out materialid);
                s = new FoodMaterialSpec();
                s.TypeId = materialid;
                db.FoodMaterialSpecs.Add(s);
            }
            else
            {
                s = db.FoodMaterialSpecs.Find(id);
                if (s == null)
                {
                    return View("ShowError", "", "找不到规格信息");
                }
                materialid = s.TypeId;
            }
            t = db.FoodMaterialType.Find(materialid);
            if (t == null)
            {
                return View("ShowError", "", "找不到原料");
            }
            //collection.Remove("");
            TryUpdateModel(s, "", new string[] { }, new string[] { "TypeId" }, collection);

            if (ModelState.IsValid)
            {

                db.SaveChanges();
                if (id == 0)
                {
                    BLL.Utilities.AddLog(materialid, FoodMaterialType.LogClass, "创建新规格" + s.Id.ToString(), "");

                }
                else
                {
                    BLL.Utilities.AddLog(materialid, FoodMaterialType.LogClass, "修改规格" + s.Id.ToString(), "");
                }
                return Redirect("~/content/close.htm");
            }
            ViewBag.Material = t;
            return View(s);
        }
Ejemplo n.º 2
0
        public ActionResult _Instock(int id, int? _purchaseid, FormCollection collection)
        {
            FoodMaterialInstock instock = null;
            FoodMaterialPurchase purchase = new FoodMaterialPurchase();
            FoodMaterialRequest req = new FoodMaterialRequest();
            FoodMaterialType food = new FoodMaterialType();
            FoodMaterialSpec spec=new FoodMaterialSpec();
            int purchaseid = 0;

            if (id == 0)
            {
                if (_purchaseid == null)
                {
                    instock = new FoodMaterialInstock
                    {
                        PurchaseId = purchaseid
                        ,
                        QualityLevel = (int)QualityLevel.合格
                        ,
                        PersonId = UserInfo.CurUser.Id
                        ,
                        Code = "自动产生"
                        ,ProductDate = DateTime.Today
                    };
                }
                else
                {
                    purchaseid = (int)_purchaseid;
                    purchase = db.FoodMaterialPurchases.Find(purchaseid);
                    if (purchase == null)
                    {
                        return View("ShowError", "", "找不到采购单");
                    }
                    instock = new FoodMaterialInstock
                    {
                        TypeId = purchase.TypeId
                        ,
                        SpecId = purchase.SpecId
                        ,
                        SupplierId = purchase.SupplierId
                        ,
                        PurchaseId = purchaseid
                        ,
                        QualityLevel = (int)QualityLevel.合格
                        ,
                        PersonId = UserInfo.CurUser.Id
                        ,
                        Code = "自动产生"
                        ,
                        InstockDate = DateTime.Today
                        ,
                        InstockUnit = purchase.InstockUnit
                        ,
                        InstockUnitNum = purchase.InstockUnitNum
                        ,ProductDate = DateTime.Today
                    };
                }
            }
            else
            {
                instock = db.FoodMaterialInstocks.Find(id);
                if (instock == null)
                {
                    return View("ShowError", "", "找不到入库单");
                }
                purchase = db.FoodMaterialPurchases.Find(instock.PurchaseId);
            }

            if (collection != null)//POST
            {
                TryUpdateModel(instock, "", null, new string[] { "TypeId","SpecId","SupplierId", "State", "InstockUnit", "InstockUnitNum", "Payed", "PersonId", "PriceNum", "QualityLevel", "QualityRemark" }, collection);
                if (ModelState.IsValid)
                {
                    if (instock.Id == 0)
                    {
                        instock.Code = SysCode.GetCode_ByDate(db, FoodMaterialInstock.LogClass, DateTime.Today);
                        db.FoodMaterialInstocks.Add(instock);
                    }
                    instock.TypeId = purchase.TypeId;
                    instock.SpecId = purchase.SpecId;
                    instock.SupplierId = purchase.SupplierId;
                    instock.InstockUnit = purchase.InstockUnit;
                    instock.InstockUnitNum = purchase.InstockUnitNum;
                    decimal instocknum = (from o in db.FoodMaterialInstocks where o.PurchaseId == instock.PurchaseId select o.PriceNum).ToList().Sum();
                    if (purchase.Num <= instocknum)
                    {
                        purchase.State = (int)FoodMaterialPurchaseState.完成入库;
                    }
                    else
                    {
                        purchase.State = (int)FoodMaterialPurchaseState.未完成入库;
                    }
                    instock.PersonId = UserInfo.CurUser.Id;
                    db.SaveChanges();
                    BLL.Utilities.AddLog(instock.Id, FoodMaterialInstock.LogClass, "添加或修改", "");
                    return Redirect("../InstockView/" + instock.Id);
                }
            }
            if (purchase.Id != 0)
            {
                req = db.FoodMaterialRequests.Find(purchase.RequestId);
                if (req == null)
                {
                    return View("ShowError", "", "找不到申购单");
                }
                //food = db.FoodMaterialType.Find(req.TypeId);
                //if (food == null)
                //{
                //    return View("ShowError", "", "找不到原料");
                //}
            }
            if(instock.TypeId>0)
            {
                food = db.FoodMaterialType.Find(instock.TypeId);
            }
            if(instock.SpecId>0)
            {
                spec = db.FoodMaterialSpecs.Find(instock.SpecId);
            }
            ViewBag.Purchase = purchase;
            ViewBag.Request = req;
            ViewBag.Food = food;
            ViewBag.Spec = spec;
            if(food.StorePlace!=null&&instock.StorePlace==null)
            {
                instock.StorePlace = food.StorePlace;
            }
            if (instock.Id != 0)
            {
                ViewBag.ReturnList = (from o in db.FoodMaterialInstockReturns where o.InstockId == instock.Id select o).ToList();
            }
            return View(instock);
        }
Ejemplo n.º 3
0
 public ActionResult SpecEdit(int id)
 {
     FoodMaterialType t;
     FoodMaterialSpec s;
     int materialid;
     if (id == 0)
     {
         int.TryParse(Request["materialid"], out materialid);
         s = new FoodMaterialSpec();
         s.InstockUnitNum = 1;
         s.PriceUnitNum = 1;
         s.TypeId = materialid;
     }
     else
     {
         s = db.FoodMaterialSpecs.Find(id);
         if (s == null)
         {
             return View("ShowError", "", "找不到规格信息");
         }
         materialid = s.TypeId;
     }
     t = db.FoodMaterialType.Find(materialid);
     if (t == null)
     {
         return View("ShowError", "", "找不到原料");
     }
     ViewBag.Material = t;
     return View(s);
 }