/// <summary> /// 添加物品 /// </summary> /// <param name="userFromCookie"></param> /// <param name="context"></param> private void AddGoods(DriveMgr.Model.User userFromCookie, HttpContext context) { if (userFromCookie != null && new DriveMgr.BLL.Authority().IfAuthority("goods", "add", userFromCookie.Id)) { string ui_goods_GoodsName_add = context.Request.Params["ui_goods_GoodsName_add"] ?? ""; int ui_goods_GoodsCategory_add = Int32.Parse(context.Request.Params["ui_goods_GoodsCategory_add"]); int ui_goods_MinQuantity_add = Int32.Parse(context.Request.Params["ui_goods_MinQuantity_add"]); int ui_goods_MaxQuantity_add = Int32.Parse(context.Request.Params["ui_goods_MaxQuantity_add"]); int ui_goods_RealQuantity_add = Int32.Parse(context.Request.Params["ui_goods_RealQuantity_add"]); string ui_goods_Specification_add = context.Request.Params["ui_goods_Specification_add"] ?? ""; string ui_goods_Remark_add = context.Request.Params["ui_goods_Remark_add"] ?? ""; DriveMgr.Model.GoodsModel goodsAdd = new Model.GoodsModel(); goodsAdd.GoodsName = ui_goods_GoodsName_add.Trim(); goodsAdd.GoodsCategoryID = ui_goods_GoodsCategory_add; goodsAdd.MinQuantity = ui_goods_MinQuantity_add; goodsAdd.MaxQuantity = ui_goods_MaxQuantity_add; goodsAdd.RealQuantity = ui_goods_RealQuantity_add; goodsAdd.Specification = ui_goods_Specification_add.Trim(); goodsAdd.Remark = ui_goods_Remark_add.Trim(); goodsAdd.CreateDate = DateTime.Now; goodsAdd.CreatePerson = userFromCookie.UserId; goodsAdd.UpdatePerson = userFromCookie.UserId; goodsAdd.UpdateDate = DateTime.Now; if (!goodsBll.IsExistGoods(goodsAdd.GoodsName)) { if (goodsBll.AddGoods(goodsAdd)) { userOperateLog.OperateInfo = "添加物品"; userOperateLog.IfSuccess = true; userOperateLog.Description = "添加成功,物品:" + ui_goods_GoodsName_add.Trim(); context.Response.Write("{\"msg\":\"添加成功!\",\"success\":true}"); } else { userOperateLog.OperateInfo = "添加物品"; userOperateLog.IfSuccess = false; userOperateLog.Description = "添加失败"; context.Response.Write("{\"msg\":\"添加失败!\",\"success\":false}"); } } else { context.Response.Write("{\"msg\":\"该物品已经存在!\",\"success\":true}"); } } else { userOperateLog.OperateInfo = "添加物品"; userOperateLog.IfSuccess = false; userOperateLog.Description = "无权限,请联系管理员"; context.Response.Write("{\"msg\":\"无权限,请联系管理员!\",\"success\":false}"); } DriveMgr.BLL.UserOperateLog.InsertOperateInfo(userOperateLog); }
public ActionResult AddnewGoods(string Imgurl, string input_field, string messagetext, decimal price, int num, int uid) { JsonModel jm = new JsonModel(); Goods n = new Goods(); n.Gpicture = Imgurl; n.Gname = input_field; n.Gprice = price; n.Gintroduce = messagetext; n.Gnumber = num; int m = bll.AddGoods(n); if (m > 0) { jm.status = 1; } else { jm.status = 0; jm.msg = "添加失败!"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
protected void subbtn_Click(object sender, EventArgs e) { Goods goods = new Goods(); //获取表单数据 string gName = goodsName.Text.Trim(); double gPrice = Convert.ToDouble(shopPrice.Text.Trim()); int gStock = Convert.ToInt32(goodsStock.Text.Trim()); string gDescription = description.Text.Trim(); string SavePath = ""; //判断缩略图是否是文件 if (thumbnail.HasFile) { //是文件,需要上传,并且保存路径到数据库中 //通过随机字符串,指定文件的名称 string FileName = System.Guid.NewGuid().ToString("N"); //由纯数字和字母组成的随机字符串 //获取文件的类型 string FileType = thumbnail.PostedFile.ContentType; System.Diagnostics.Debug.Write("文件类型:::::" + FileType); //.jpg image/jpeg .png image/png //获取字符串中最后一个/的索引 int index = FileType.LastIndexOf("/"); //截取字符串,获取文件的后缀名 string suffix = FileType.Substring(index + 1); //指定上传路径 //获取当前项目的绝对路径 string path = System.AppDomain.CurrentDomain.BaseDirectory.ToString(); System.Diagnostics.Debug.WriteLine("path::" + path); string ImgPath = path + "/images/" + FileName + "." + suffix; //string ImgPath = Server.MapPath("../../images/" + FileName + "." + suffix); //指定数据库中的存储路径 SavePath = "images/" + FileName + "." + suffix; System.Diagnostics.Debug.Write("上传路径:::::" + ImgPath); //上传 thumbnail.SaveAs(ImgPath); thuMsg.Visible = true; thuMsg.Text = "文件上传成功,文件上传路径是:" + ImgPath; } else //不是文件 { thuMsg.Visible = true; thuMsg.Text = "请上传文件或图片"; } //将所有数据封装到Goods中 goods.GoodsName = gName; goods.ShopPrice = gPrice; goods.GoodsStock = gStock; goods.Description = gDescription; goods.Thumbnail = SavePath; //调用添加商品的方法 int rows = gb.AddGoods(goods); //判断受影响的行数 if (rows > 0) //添加成功 { //返回到首页 Response.Redirect("/Admin/Wares/SpList.aspx"); } else { //添加不成功 //重定向到商品添加页面 Response.Redirect("/Admin/Wares/AddGoods.aspx"); } }
protected void btnSubmit_Click(object sender, EventArgs e) { int id = GetGoodsID(); string name = tbName.Text.Trim(); int cid = ddlCat.SelectedValue.ToArrowInt(); int point = tbPoints.Text.Trim().ToArrowInt(); int num = tbNum.Text.Trim().ToArrowInt(); string cover = tbCoverPath.Text.Trim(); string remarks = tbRemarks.Text.Trim(); if (name.ValidateIsNullOrEmpty("请输入商品名称!")) { return; } if ((cid == 0).ValidateSuccess("请先选择分类!")) { return; } if ((point == 0).ValidateSuccess("兑换点数必须大于0!")) { return; } if ((num == 0).ValidateSuccess("数量必须大于0!")) { return; } if (id == 0) { var model = new TMS.GoodsInfo(); model.AddTime = DateTime.Now; model.AddUserName = CurrentAdmin.UserName; model.AddUserRealName = CurrentAdmin.RealName; model.BigPicPath = ""; model.CatID = cid; model.CoverPath = cover; model.IsOut = 0; model.Name = name; model.Num = num; model.Points = point; model.Remarks = remarks; GoodsBLL.AddGoods(model); tbName.Text = ""; tbPoints.Text = ""; tbNum.Text = ""; tbCoverPath.Text = ""; tbRemarks.Text = ""; MessageBox.Show("添加成功!"); } else { var model = GoodsBLL.SelectGoods(id); if (model != null) { model.Name = name; model.CatID = cid; model.CoverPath = cover; model.Num = num; model.Points = point; model.Remarks = remarks; GoodsBLL.UpdateGoods(model); MessageBox.Show("修改成功!"); } } }