Exemplo n.º 1
0
 /// <summary>
 /// 将商品添加到购物车中
 /// </summary>
 private void AddBookToCart()
 {
     int bookId;
     if (int.TryParse(Request.QueryString["id"], out bookId))
     {
         BooksBLL bb = new BooksBLL();
         Books book = bb.GetModel(bookId);
         if (book != null)
         {
             CartBLL cb = new CartBLL();
             Model.Cart cart = cb.GetModel(LoginUser.Id, bookId);
             if (cart != null)
             {
                 cart.Count = cart.Count + 1;
                 cb.Update(cart);
             }
             else
             {
                 Model.Cart newCart = new Model.Cart();
                 newCart.Book.Id = bookId;
                 newCart.Count = 1;
                 newCart.UserId = LoginUser.Id;
                 cb.Add(newCart);
             }
         }
         else
         {
             Response.Redirect("/ShowMsg.aspx?m=" + HttpUtility.UrlEncode("此商品不存在!"));
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 绑定图书列表
        /// </summary>
        /// <param name="pageIndex"></param>
        protected void BindBookList()
        {
            //图书类别编号
            int categoryId;
            if (!int.TryParse(Request.QueryString["categoryId"], out categoryId))
            {
                categoryId = 0;
            }
            //当前页码
            int pageIndex;
            if (!int.TryParse(Request.QueryString["page"], out pageIndex))
            {
                pageIndex = 1;
            }
            //图书总页数
            int pageCount = 0;
            BooksBLL bb = new BooksBLL();
            pageCount = bb.GetPageCount(categoryId, pageSize);
            if (pageIndex < 1)
            {
                pageIndex = 1;
            }
            if (pageCount < pageIndex)
            {
                pageIndex = pageCount;
            }
            //排序字符串
            string orderBy = "";
            if (!string.IsNullOrEmpty(Request.QueryString["orderBy"]))
            {
                orderBy = Request.QueryString["orderBy"];
                SetOrderByValue(orderBy);
            }
            BookListRepeater.DataSource = bb.GetPagedBooks(pageIndex, pageSize, categoryId, orderBy);
            BookListRepeater.DataBind();

            CreatePagedBar(pageIndex, pageCount, categoryId, orderBy);
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         BooksBLL bb = new BooksBLL();
         List<Books> list = bb.GetModelList("");
         foreach (Books b in list)
         {
             bb.CreateSaticHtml(b.Id);
         }
     }
 }