private void dataGridViewBooks_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridViewBooks.Columns[e.ColumnIndex].Name == "AddToCart" && e.RowIndex >= 0)
     {
         string             ISBN_Value    = dataGridViewBooks.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         var                book          = BookDataAccess.GetFullBookByISBN(ISBN_Value);
         CartItemAmountForm addToCartForm = new CartItemAmountForm();
         SendCartInfoEvent += addToCartForm.GetInfo;
         SendCartInfoEvent.Invoke(book, true);
         addToCartForm.ShowDialog();
     }
     else if (dataGridViewBooks.Columns[e.ColumnIndex].Name == "Review" && e.RowIndex >= 0)
     {
         string            ISBN_Value        = dataGridViewBooks.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         var               reviews           = ReviewOfBookDataAccess.GetReviews(ISBN_Value);
         ReviewsOfBookForm reviewsOfBookForm = new ReviewsOfBookForm();
         SendReviewsInfoEvent += reviewsOfBookForm.ShowReviews;
         SendReviewsInfoEvent.Invoke(reviews);
         reviewsOfBookForm.ShowDialog();
     }
     else if (dataGridViewBooks.Columns[e.ColumnIndex].Name == "More" && e.RowIndex >= 0)
     {
         string         ISBN_Value     = dataGridViewBooks.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         var            book           = BookDataAccess.GetFullBookByISBN(ISBN_Value);
         BookDetailForm bookDetailForm = new BookDetailForm();
         SendBookInfoEvent += bookDetailForm.ShowBookDetail;
         SendBookInfoEvent.Invoke(book);
         bookDetailForm.ShowDialog();
     }
 }
Ejemplo n.º 2
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();
     }
 }