//添加图书到购物车
        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;
            }
        }
        //清空购物车
        public int clearCart(int customerID)
        {      
            if (cartBook == null)
            {
                cartBook = new CartBook(customerID);
            }

             return cartBook.getCart().clearCart(customerID);           
        }
        //根据不同的卖家生成不同订单
        //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;
            }

        }
        //更改购物车数量
        public int changeAmount(int customerID,int bookID, int newAmount)
        {
            CartBookItem[] item;
            if (cartBook == null)
            {
                cartBook = new CartBook(customerID);
            }

            //提取购物车信息
            item = cartBook.CartBookTableToCartBookItem();

            int i = 0;
            for (; i < item.Length; i++)
            {
                if (item[i].bookID == bookID)
                {
                    break;
                }
            }

            if (newAmount <= item[i].bookAmount && newAmount > 0)
            {
                return cartBook.changeAmount(customerID, bookID, newAmount);      
            }
            else
            {
                return 0;
            }

        }
 //删除购物车某一项
 public int removeBook(int customerID,int bookID)
 {
     if (cartBook == null)
     {
         cartBook = new CartBook();
     }
     return cartBook.removeBook(customerID, bookID);
 }
 public void setCartBook(int customer_id)
 {
     cartBook = new CartBook(customer_id);
 }
 public cartBLL(int customer_id)
 {
     cartBook = new CartBook(customer_id);
 }