// 添加到购物车 protected void BtnAddToCart_Click(object sender, EventArgs e) { // 判断是否已经有用户登录 if (Session["account"] == null) { Response.Redirect("Login.aspx"); return; } int num = 0; try { num = Convert.ToInt32(BuyNumber.Text); } catch (Exception) { BuyNumber.Text = "0"; return; } // 根据Session获取用户ID,进行商品的添加 Account account = (Account)Session["account"]; OrderDao orderDao = new OrderDao(); // 添加到数据库 if (orderDao.AddNewOrder(account.Id, BookId, num)) { ErrorInfo.CssClass = "text-primary"; ErrorInfo.Text = "商品已经添加~"; } else { ErrorInfo.Text = "加入购物车失败 = ="; } }