Exemplo n.º 1
0
        //添加图书到购物车
        public int addBookToCart(Book book, int customerID, int amount)
        {
            if (book.bookAmount >= amount && amount > 0 )
            {
                CartBookItem[] item;
                if (cartBook == null)
                {
                    cartBook = new CartBook(customerID);
                }

                item = cartBook.CartBookTableToCartBookItem();
                for (int i = 0; i < item.Length; i++)
                {
                    if (item[i].bookID == book.bookID)
                    {
                        return 0;
                    }
                }

                return cartBook.addBookToCart(customerID, book.bookID, amount);
            }
            else
            {
                return 0;
            }
        }
Exemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int ID = int.Parse(Request.QueryString["id"].ToString());
            bookShop.DAL.Book b = new bookShop.DAL.Book();
            b.bookID = ID;
            b.bookAmount = int.Parse(amountLabel.Text);
            cartBLL cb = new cartBLL();
            cb.addBookToCart(b, Convert.ToInt32(Session["userid"]), 1);

        }
Exemplo n.º 3
0
        //商家修改书本信息,已测
        //返回1修改成功,否则失败
        public int updateBook(int bookID, int typeID, string title, string author,
                                                    string publisher, string isbn, string info,
                                                    float price, int amount, string imgpath)
        {
            int result = 0;
            BookDAL bd = new BookDAL();
            Book b = new Book();
            b.bookID = bookID;
            b.typeListId = typeID;
            b.bookTitle = title;
            b.bookAuthor = author;
            b.bookPublisher = publisher;
            b.bookIsbn = isbn;
            b.bookInfo = info;
            b.bookPrice = price;
            b.bookAmount = amount;
            b.bookImage = imgpath;
            result = bd.modifyBook(b);

            return result;
        }
Exemplo n.º 4
0
        //商家插入一本书,已测
        //返回1插入成功,否则失败
        public int insertBook(int sellerID,int typeID,string title,string author,
                                                    string publisher,string isbn,string info,
                                                    float price,int amount,bool valid,string imgpath)
        {
            int result = 0;
            BookDAL bd = new BookDAL();
            Book b = new Book();
            b.sellerID = sellerID;
            b.typeListId = typeID;

            b.bookTitle = title;
            b.bookAuthor = author;
            b.bookAmount = amount;
            b.bookPublisher = publisher;
            b.bookIsbn = isbn;
            b.bookInfo = info;
            b.bookPrice = price;
            b.isvalid = valid;
            b.bookImage = imgpath;
            result = bd.insertBook(b);

            return result;
        }
Exemplo n.º 5
0
        //根据不同的卖家生成不同订单
        //customerID: 顾客的ID
        //cartBook: 顾客的购物车信息
        public int generateOrder(int customerID)
        {
            cartBook = new CartBook(customerID);
            DataView dataview = cartBook.getCartBookTable().DefaultView;

            try
            {
                if (dataview.Table.Rows.Count > 0)
                {
                    //根据买家ID对购物车信息排序
                    dataview.Sort = "seller_id DESC";
                    DataTable tableTemp = dataview.ToTable();

                    int i = 0;
                    int index = i;
                    int temp = Convert.ToInt32(tableTemp.Rows[i]["seller_id"]);

                    //遍历表,寻找相同seller_id的数据
                    for (i = 0; i < dataview.Table.Rows.Count - 1; i++)
                    {
                        int id = Convert.ToInt32(tableTemp.Rows[i + 1]["seller_id"]);
                        if (id != temp)
                        {
                            int n = i - index + 1;
                            Book[] book = new Book[n];

                            for (int j = 0; index <= i; index++, j++)
                            {
                                book[j] = new Book();
                                book[j].bookTitle = tableTemp.Rows[index]["book_title"].ToString();
                                book[j].bookID = Convert.ToInt32(tableTemp.Rows[index]["book_id"]);
                                book[j].sellerID = Convert.ToInt32(tableTemp.Rows[index]["seller_id"]);
                                book[j].bookPrice = (float)Convert.ToDouble(tableTemp.Rows[index]["book_price"]);
                                book[j].bookAmount = Convert.ToInt32(tableTemp.Rows[index]["cart_amount"]);
                            }
                           
                            //插入订单
                            order.generateOrder(customerID, book[0].sellerID, book);
                        }
                    }

                    Book[] b = new Book[i - index + 1];

                    for (int j = 0; index <= i; index++, j++)
                    {
                        b[j] = new Book();
                        b[j].bookID = Convert.ToInt32(tableTemp.Rows[index]["book_id"]);
                        b[j].bookTitle = tableTemp.Rows[index]["book_title"].ToString();
                        b[j].sellerID = Convert.ToInt32(tableTemp.Rows[index]["seller_id"]);
                        b[j].bookPrice = (float)Convert.ToDouble(tableTemp.Rows[index]["book_price"]);
                        b[j].bookAmount = Convert.ToInt32(tableTemp.Rows[index]["cart_amount"]);
                    }

                    //提交最后一份订单
                    order.generateOrder(customerID, b[0].sellerID, b);

                    
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return 0;
            }

        }