/// <summary> /// 修改商品信息 /// </summary> /// <param name="goodsfile">商品图片(多选)</param> /// <param name="good">商品对象</param> /// <param name="pageindex">当前页</param> /// <param name="typeid">分类id</param> /// <param name="text">查询内容</param> /// <returns></returns> public ActionResult GoodsUpdate(GoodsTable good, int?pageindex, int typeid, string text = "") { //添加商品图片 if (Request.Files.Count > 0) { string[] fileTypeStr = { "image/gif", "image/png", "image/jpeg", "image/jpg", "image/bmp" }; List <string> strlist = new List <string>(); for (int i = 0; i < Request.Files.Count; i++) { if (fileTypeStr.Contains(Request.Files[i].ContentType)) { string fileName = Path.GetFileName(Request.Files[i].FileName); strlist.Add(fileName); } } if (GoodsPhotoBll.AddGoodsPhoto(good.GoodsID, strlist)) { //保存文件 //应用程序需要有服务器UploadFile文件夹的读写权限 for (int i = 0; i < Request.Files.Count; i++) { Request.Files[i].SaveAs(Server.MapPath("~/Content/GoodImgs/" + Request.Files[i].FileName)); } } } //修改商品信息 GoodsBll.UpdateGoods(good); return(RedirectToAction("GoodsIndexPartial", "BacksTage", new { pageindex = pageindex, text = text, typeid = typeid })); }
protected void Page_Load(object sender, EventArgs e) { Goods goodsObj = new Goods(); goodsObj.GoodsId = Int32.Parse(Request.Form["formGooodsId"]); goodsObj.GoodsName = Request.Form["formGoodsName"]; goodsObj.SortId = Int32.Parse(Request.Form["formSortId"]); goodsObj.Price = Double.Parse(Request.Form["formGoodsPrice"]); goodsObj.Cost = Double.Parse(Request.Form["formGoodsCost"]); goodsObj.Onsale = Int32.Parse(Request.Form["formGoodsOnsale"]) == 1 ? true : false; GoodsBll gb = new GoodsBll(); bool success = false; if (goodsObj.GoodsId == 0) { success = gb.InsertGoods(goodsObj); if (success) { Msg.Text = "添加成功!"; } else { Msg.Text = "添加失败!该商品已存在。"; } } else { success = gb.UpdateGoods(goodsObj); if (success) { Msg.Text = "修改成功!"; } else { Msg.Text = "修改失败!"; } } }