コード例 #1
0
        public ActionResult SpecPriceEdit(int id, FormCollection collection)
        {
            FoodMaterialType f;
            FoodMaterialPrice p;
            FoodMaterialSpec s;
            int specid;
            if (id == 0)
            {
                int.TryParse(Request["specid"], out specid);
                p = new FoodMaterialPrice();
                p.SpecId = specid;
                db.FoodMaterialPrice.Add(p);
            }
            else
            {
                p = db.FoodMaterialPrice.Find(id);
                if (p == null)
                {
                    return View("ShowError", "", "找不到价格信息");
                }
                specid = p.SpecId;
            }
            s = db.FoodMaterialSpecs.Find(specid);
            if (s == null)
            {
                return View("ShowError", "", "找不到原料规格");
            }
            f = db.FoodMaterialType.Find(s.TypeId);
            TryUpdateModel(p, "", new string[] { }, new string[] { "SpecId" }, collection);
            if (p.SupplierId == 0)
            {
                ModelState.AddModelError("SupplierId", "请选择供应商");
            }
            if (p.Price == decimal.Zero)
            {
                ModelState.AddModelError("Price", "价格不能为0");
            }
            if (ModelState.IsValid)
            {
                if (collection["defaultSupplier"] == "1")
                {
                    BLL.Utilities.AddLog(s.TypeId, FoodMaterialType.LogClass, "修改默认供应商", "原供应商id" + f.SupplierId.ToString());
                    f.SupplierId = p.SupplierId;
                }
                db.SaveChanges();
                if (id == 0)
                {
                    string sql = string.Format("update foodmaterialprices set state={2} where state={3} and specid={0} and supplierid={1} and id!={2}", p.SpecId, p.SupplierId, p.Id,(int)FoodPriceState.历史,(int)FoodPriceState.当前);
                    db.Database.ExecuteSqlCommand(sql);
                }
                if (id == 0)
                {
                    BLL.Utilities.AddLog(s.TypeId, FoodMaterialType.LogClass, "添加报价" + p.Id.ToString(), "");

                }
                else
                {
                    BLL.Utilities.AddLog(s.TypeId, FoodMaterialType.LogClass, "修改报价" + p.Id.ToString(), "");
                }

                return Redirect("~/content/close.htm");
            }

            ViewBag.Food = f;
            ViewBag.Spec = s;
            return View(p);
        }
コード例 #2
0
 public ActionResult SpecPriceEdit(int id)
 {
     FoodMaterialType f;
     FoodMaterialPrice p;
     FoodMaterialSpec s;
     int specid;
     if (id == 0)
     {
         int.TryParse(Request["specid"], out specid);
         p = new FoodMaterialPrice();
         p.PriceDate = DateTime.Today;
         p.SpecId = specid;
     }
     else
     {
         p = db.FoodMaterialPrice.Find(id);
         if (p == null)
         {
             return View("ShowError", "", "找不到价格信息");
         }
         specid = p.SpecId;
     }
     s = db.FoodMaterialSpecs.Find(specid);
     if (s == null)
     {
         return View("ShowError", "", "找不到原料规格");
     }
     f = db.FoodMaterialType.Find(s.TypeId);
     ViewBag.Food = f;
     ViewBag.Spec = s;
     return View(p);
 }