Exemple #1
0
        public int InsertShoppingCart(MallItemcart MallItemcart)
        {
            string sql = "insert into MallItemCart(UserID,GoodsID,Unit_price,Qty,Tot_amt)values(@UserID,@GoodsID,@Unit_price,@Qty,@Tot_amt)";

            SqlParameter[] para =
            {
                new SqlParameter("@UserID",     MallItemcart.UserID),
                new SqlParameter("@GoodsID",    MallItemcart.GoodsID),
                new SqlParameter("@Unit_price", MallItemcart.Unit_price),
                new SqlParameter("@Qty",        MallItemcart.Qty),
                new SqlParameter("@Tot_amt",    MallItemcart.Tot_amt)
            };
            return(DBHelper.GetExcuteNonQuery(sql, para));
        }
Exemple #2
0
 public static int InsertShoppingCart(MallItemcart Mallitemcart)
 {
     return(igoods.InsertShoppingCart(Mallitemcart));
 }
Exemple #3
0
        protected void AddShoppingCart_Click(object sender, EventArgs e)
        {
            int num = int.Parse(ViewState["Rest_num"].ToString());

            if (num > 0)
            {
                if (Session["UserName"] != null)//判断用户是否登录
                {
                    int Qty = Convert.ToInt32(ViewState["ShoppingCartNumber"]);

                    if (Qty > 0) //判断购买商品数量是否>0
                    {
                        if ((int)Session["UserID"] != 0)
                        {
                            int UserID = Convert.ToInt32(Session["UserID"]);

                            int       GoodsID = Convert.ToInt32(ViewState["GoodsID"]);
                            DataTable goods   = GoodsManager.JudgeMallYorN(UserID, GoodsID);
                            if (goods != null && goods.Rows.Count != 0) //判断购物车是否被创建
                            {
                                //若购物车已经创建 里面有商品 则更新购物车
                                decimal Tot_amt = ((decimal)(ViewState["Price"])) * (Convert.ToInt32(ViewState["ShoppingCartNumber"]));//单价乘数量
                                int     Result  = GoodsManager.UpdateShoppingCart(UserID, GoodsID, Qty, Tot_amt);
                                if (Result >= 1)
                                {
                                    Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('加入购物车成功!');</script>");
                                    BindUserMallCart();
                                }
                            }
                            else //若没有 则新建购物车
                            {
                                MallItemcart mallitemcart = new MallItemcart();
                                mallitemcart.UserID     = Convert.ToInt32(Session["UserID"]);
                                mallitemcart.GoodsID    = Convert.ToInt32(ViewState["GoodsID"]);
                                mallitemcart.Unit_price = Convert.ToDecimal((ViewState["Price"]));
                                mallitemcart.Qty        = Convert.ToInt32(ViewState["ShoppingCartNumber"]);
                                mallitemcart.Tot_amt    = Convert.ToDecimal((ViewState["Price"])) * (Convert.ToInt32(ViewState["ShoppingCartNumber"]));
                                int result = GoodsManager.InsertShoppingCart(mallitemcart);
                                if (result >= 1)
                                {
                                    Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('加入购物车成功!');</script>");
                                    BindUserMallCart();
                                }
                            }
                        }
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('请确定购买数量');</script>");
                    }
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('请先登录');</script>");
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('已经卖光了。。。');</script>");
            }
        }