Beispiel #1
0
        //添加商品
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Random rd = new Random();
            //要判断一下,是否有图片
            //如果用户选择了图片,那么,就要上传图片,保存图片
            string filepath = string.Empty;

            if (goodsimg.HasFile)
            {
                //表示选择了图片,那么用户就要保存图片
                //判断存放图片的文件夹是否存在,如果不存在,我就要创建文件夹
                if (!Directory.Exists(Server.MapPath(@"\goodsimg")))
                {
                    //不存在,则创建
                    Directory.CreateDirectory(Server.MapPath(@"\goodsimg"));
                }
                //为了防止文件的重名,我们加随机数

                filepath = @"\goodsimg\" + DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(10000).ToString() + goodsimg.FileName;
                //图片就保存到图务器上面去了
                goodsimg.SaveAs(Server.MapPath(filepath));
            }
            Model.eb_goods model = new Model.eb_goods();
            model.gname       = this.gname.Text.Trim();
            model.cid         = int.Parse(this.Dropcategory.SelectedValue.ToString());
            model.offset      = decimal.Parse(this.offset.Text.Trim());
            model.price       = decimal.Parse(this.price.Text.Trim()); //只留2位小数
            model.publishTime = DateTime.Now;                          //发布时间就是现在的时间
            model.total       = int.Parse(this.total.Text.Trim());
            if (!string.IsNullOrEmpty(this.hiddenGid.Value))
            {
                //修改
            }
            else
            {
                //新增
                model.goodsimg = filepath;
                int gid = new BLL.eb_goods().Add(model);
                if (gid > 0)
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this.Page, "添加成功", "GoodsList.aspx");
                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this.Page, "添加失败,请重试或联系管理员", "GoodsList.aspx");
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(MyEasyBuy.Model.eb_goods model)
 {
     return(dal.Update(model));
 }
Beispiel #3
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(MyEasyBuy.Model.eb_goods model)
 {
     return(dal.Add(model));
 }