Exemple #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");
                }
            }
        }
Exemple #2
0
        //上一页

        protected void LbuttonPrePage_Click(object sender, EventArgs e)
        {
            int pageIndex = int.Parse(this.hiddenPageIndex.Value);

            pageIndex--;
            if (pageIndex <= 0)
            {
                pageIndex = 1;
            }
            double  sumCount = new BLL.eb_goods().GetRecordCount(""); //拿到总记录数
            double  pageSize = 10;                                    //页容量
            double  sumPage  = Math.Ceiling(sumCount / pageSize);     //计算总页数
            DataSet ds       = new BLL.eb_goods().GetListByPage("", "gid", Convert.ToInt32((pageIndex - 1) * pageSize) + 1, Convert.ToInt32(pageIndex * pageSize));

            this.rp_goodsList.DataSource = ds.Tables[0];
            this.rp_goodsList.DataBind();
            this.lbPageIndex.Text = pageIndex.ToString();
            this.lbSumPage.Text   = sumPage.ToString();
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            base.CheckLogin();
            //查询数据
            if (!Page.IsPostBack)
            {
                #region 通过数据库内联查询
                //DataTable dt = new BLL.eb_goods().GetTableWidthCname("");
                //this.rp_goodsList.DataSource = dt;
                //this.rp_goodsList.DataBind();
                #endregion

                List <Model.eb_goods> listGoods = new BLL.eb_goods().GetModelList("");
                this.rp_goodsList.DataSource = listGoods.OrderBy(g => g.gid).Take(10);
                this.rp_goodsList.DataBind();
                this.lbPageIndex.Text = "1";
                this.lbSumPage.Text   = Math.Ceiling(Convert.ToDouble(listGoods.Count) / Convert.ToDouble(10)).ToString();
            }
        }