예제 #1
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 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);
     }
 }