Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取已提交参数
            string id = Request.QueryString["goodsId"];
            //根据商品ID获取商品信息
            Goods goods = gb.FindGoodsByGoodsId(Convert.ToInt32(id));

            bigimg.ImageUrl = "../../" + goods.Thumbnail;
            subImg.ImageUrl = "../../" + goods.Thumbnail;
            gName.Text      = goods.GoodsName.ToString();
            gPrice.Text     = "¥" + goods.ShopPrice.ToString();
            gStock.Text     = goods.GoodsStock.ToString();
            gID.Text        = "商品编号:" + goods.GoodsID.ToString();

            //将商品信息存储到session域中
            Session.Add("goods", goods);
            //查询用户评论
            int            cid      = Convert.ToInt32(Request.QueryString["goodsID"]);
            List <Comment> comments = cb.getCommentByGoodsID(cid);

            Session.Add("comments", comments);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取提交的参数
            string id = Request.QueryString["goodsID"];

            System.Diagnostics.Debug.Write("id::" + id);
            //根据商品id获取商品信息
            Goods goods = gb.FindGoodsByGoodsId(Convert.ToInt32(id));

            //取出Session域中的Goods对象
            //Goods goods = (Goods)Session["goods"];

            if (goods != null)
            {
                //将数据赋值给页面文本框
                goodsID.Text     = goods.GoodsID + "";
                cartID.Text      = goods.CartID + "";
                goodsName.Text   = goods.GoodsName;
                shopPrice.Text   = goods.ShopPrice + "";
                goodsStock.Text  = goods.GoodsStock + "";
                photo.ImageUrl   = "../../" + goods.Thumbnail;
                description.Text = goods.Description;
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取session域中当前登录的用户
            User user = (User)Session["LoginUser"];

            //判断用户是否登录
            if (user == null)
            {
                //提示信息
                Response.Write("<script>alert('请先登录');</script>");
                //重定向到用户登录页面
                Response.Redirect("/PTUsers/Login.aspx");
            }
            else
            {
                //用户已登录
                //获取商品的编号和数量
                int goodsId  = Convert.ToInt32(Request.QueryString["goodsId"]);
                int goodsNum = Convert.ToInt32(Request.QueryString["num"]);

                //判断商品编号是否为0
                if (goodsId != 0)
                {
                    System.Diagnostics.Debug.WriteLine("ID:::" + goodsId + "数量:::" + goodsNum);

                    //查询购物车中商品已添加
                    Cart isExistCart = cb.FindCartByGoodsId(goodsId);
                    if (isExistCart != null)
                    {//购物车已添加该商品,修改该商品的数量
                        int rows = cb.UpdateGoodsNumber(goodsId, goodsNum);
                        //显示购物车中的所有商品
                        List <CartTemp> cartTemp = cb.showCart(user.UserID);
                        //将集合存储到session域中
                        Session.Add("cartTemp", cartTemp);
                    }
                    else
                    {//不存在该商品,添加商品完整信息
                        //根据商品编号,获取商品信息
                        Goods goods = gb.FindGoodsByGoodsId(goodsId);

                        //将商品信息封装到购物车中
                        Cart cart = new Cart();
                        cart.GoodsID     = goodsId;
                        cart.GoodsPrice  = goods.ShopPrice;
                        cart.GoodsNumber = goodsNum;
                        cart.UserID      = user.UserID;

                        //将数据加入数据库
                        int rows = cb.addCart(cart);
                        //判断是否添加成功
                        if (rows > 0)
                        {//添加成功
                            Response.Write("<script>alert('添加成功!');</script>");
                            //显示购物车中的所有商品
                            List <CartTemp> cartTemp = cb.showCart(user.UserID);
                            //将集合存储到session域中
                            Session.Add("cartTemp", cartTemp);
                        }
                        else
                        {//添加失败
                            Response.Write("<script>alert('添加失败!');</script>");
                        }
                    }
                }
                else
                {//如果goodsId为0
                    //显示购物车中的所有商品
                    List <CartTemp> cartTemp = cb.showCart(user.UserID);
                    //将集合存储到session域中
                    Session.Add("cartTemp", cartTemp);
                }
            }
        }