//添加商品到购物车 protected void BtnAddToCard_Click(object sender, EventArgs e) { if (Session["UserId"] != null) { int bid = int.Parse(Request.QueryString["Book_Id"].ToString()); int uid = int.Parse(Session["UserId"].ToString()); int qty = int.Parse(txtPurchaseQty.Text); //先判断购物车是否存在该商品,若不存在,则添加;存在,则提示已添加 if (qty > 0 && qty <= 10) { if (!cartService.IsCartItemExist(bid, uid)) { var book = ProService.GetBookInfoByBookId(bid); cartService.InsertIntoCartItem(uid, bid, book.BookName, decimal.Parse(book.ListPrice.ToString()), qty); Response.Write("<script> alert('添加成功!')</script>"); Response.Write("<script>window.location.href='ProDetails.aspx?Book_Id=" + bid + "'</script>"); } else { lblAddCartMsg.Text = "你已经添加过该商品了!"; } } else { lblAddCartMsg.Text = "购买数量必须大于0并且不能大于10!"; } } else { Response.Redirect("Login.aspx"); } }