Ejemplo n.º 1
0
        /// <summary>
        /// show all related carts
        /// </summary>
        /// <param name="userName">cart owner name</param>
        /// <returns>list of all carts made by user</returns>
        internal List <Cart> ShowCarts(string userName)
        {
            CartDataAccess dataAccess = new CartDataAccess();
            UserDataAccess user       = new UserDataAccess();

            return(dataAccess.GetCartUId(userName, "", false));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// show detail information about the cart
        /// </summary>
        /// <param name="cartId">the cartId</param>
        /// <returns>the cart</returns>
        internal Cart ShowCart(string cartId)
        {
            Cart           cart       = new Cart();
            CartDataAccess dataAccess = new CartDataAccess();

            cart = dataAccess.GetCart(Convert.ToInt32(cartId), "", false).FirstOrDefault();
            return(cart);
        }
Ejemplo n.º 3
0
 private void dataGridViewMyCart_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridViewMyCart.Columns[e.ColumnIndex].Name == "Detail" && e.RowIndex >= 0)
     {
         string ISBN_Value = dataGridViewMyCart.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         if (!BookDataAccess.IsBookExisted(ISBN_Value))
         {
             MessageBox.Show("错误:图书不存在");
             return;
         }
         var            book           = BookDataAccess.GetFullBookByISBN(ISBN_Value);
         BookDetailForm bookDetailForm = new BookDetailForm();
         SendBookInfoEvent += bookDetailForm.ShowBookDetail;
         SendBookInfoEvent.Invoke(book);
         bookDetailForm.ShowDialog();
     }
     else if (dataGridViewMyCart.Columns[e.ColumnIndex].Name == "Edit" && e.RowIndex >= 0)
     {
         string ISBN_Value = dataGridViewMyCart.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         if (!BookDataAccess.IsBookExisted(ISBN_Value))
         {
             MessageBox.Show("错误:图书不存在");
             return;
         }
         var book = BookDataAccess.GetFullBookByISBN(ISBN_Value);
         CartItemAmountForm cartItemAmountForm = new CartItemAmountForm();
         SendCartInfoEvent += cartItemAmountForm.GetInfo;
         SendCartInfoEvent.Invoke(book, false);
         cartItemAmountForm.ShowDialog();
         ShowAllCartData();
     }
     else if (dataGridViewMyCart.Columns[e.ColumnIndex].Name == "CheckOut" && e.RowIndex >= 0)
     {
         string          ISBN_Value      = dataGridViewMyCart.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         var             book            = BookDataAccess.GetFullBookByISBN(ISBN_Value);
         int             amount          = CartDataAccess.SelectAmount(CustomerInfo.customer.Id, ISBN_Value);
         SubmitOrderForm submitOrderForm = new SubmitOrderForm();
         SendOrderInfoEvent += submitOrderForm.GetOrderInfo;
         SendOrderInfoEvent.Invoke(book, amount);
         submitOrderForm.ShowDialog();
         ShowAllCartData();
     }
     else if (dataGridViewMyCart.Columns[e.ColumnIndex].Name == "Delete" && e.RowIndex >= 0)
     {
         string ISBN_Value = dataGridViewMyCart.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         try
         {
             CartDataAccess.DeleteCartItem(CustomerInfo.customer.Id, ISBN_Value);
             MessageBox.Show("删除成功");
         }
         catch (Exception ex)
         {
             MessageBox.Show("删除失败\r\n" + ex.Message);
         }
         ShowAllCartData();
     }
 }
 private void UpdateCartItem()
 {
     try
     {
         CartDataAccess.UpdateCartItem(CustomerInfo.customer.Id, _book.ISBN, (int)numericUpDownAmount.Value);
         MessageBox.Show("修改成功");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 public void AddToCart()
 {
     try
     {
         CartDataAccess.InsertItem(CustomerInfo.customer, _book, (int)numericUpDownAmount.Value);
         MessageBox.Show("加入购物车成功");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void iconButtonSubmit_Click(object sender, EventArgs e)
 {
     if (_book == null)
     {
         MessageBox.Show("错误:找不到图书");
         return;
     }
     try
     {
         CustomerOrderDataAccess.SubmitOrder(CustomerInfo.customer.Id, _book.ISBN, _amount, _totalPrice, DateTime.Now);
         CartDataAccess.DeleteCartItem(CustomerInfo.customer.Id, _book.ISBN);
         MessageBox.Show("提交订单成功");
         Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("提交订单失败\r\n" + ex.Message);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Add item in cart
        /// </summary>
        /// <param name="amount">the amout of item</param>
        /// <param name="productId">item productId</param>
        /// <param name="userName">the one who ordered item</param>
        /// <param name="cartId">item cartId, null if no cart created in this session</param>
        public void AddToCart(string amount, string productId, string userName, string cartId)
        {
            Cart     cart     = new Cart();
            CartItem cartItem = new CartItem();

            cartItem.Amount    = Convert.ToInt32(amount);
            cartItem.ProductID = Convert.ToInt32(productId);
            CartDataAccess dataAccess = new CartDataAccess();

            if (cartId == "")
            {
                cart.CartID   = 0;
                cart.UserName = userName;
                cart.Items.Add(cartItem);
            }
            else
            {
                cart = dataAccess.GetCart(Convert.ToInt32(cartId), "", false).First();
                cart.Items.Add(cartItem);
            }
            dataAccess.CartUpdate(cart);
        }
Ejemplo n.º 8
0
 private void ShowAllCartData()
 {
     try
     {
         dataGridViewMyCart.Rows.Clear();
         var items = CartDataAccess.GetCartItems(CustomerInfo.customer.Id);
         foreach (var item in items)
         {
             int             rowId = dataGridViewMyCart.Rows.Add();
             DataGridViewRow row   = dataGridViewMyCart.Rows[rowId];
             row.Cells["ISBN"].Value       = item.Book.ISBN;
             row.Cells["Title"].Value      = item.Book.Title;
             row.Cells["Amount"].Value     = item.Amount;
             row.Cells["Price"].Value      = item.Book.Price;
             row.Cells["TotalPrice"].Value = item.Book.Price * item.Amount;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 9
0
 public Cart()
 {
     InitializeComponent();
     this.dataAccess = new CartDataAccess();
 }
Ejemplo n.º 10
0
 public CartService(CartDataAccess dao)
 {
     _dao = dao;
 }