コード例 #1
0
 private void dataGridViewBooks_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridViewBooks.Columns[e.ColumnIndex].Name == "Detail" && e.RowIndex >= 0)
     {
         string         ISBN_Value = dataGridViewBooks.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         var            book       = BookDataAccess.GetFullBookByISBN(ISBN_Value);
         BookDetailForm detailForm = new BookDetailForm();
         SendBookInfoEvent += detailForm.ShowDetail;
         SendBookInfoEvent.Invoke(book);
         detailForm.ShowDialog();
     }
     else if (dataGridViewBooks.Columns[e.ColumnIndex].Name == "Edit" && e.RowIndex >= 0)
     {
         string         ISBN_Value   = dataGridViewBooks.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         var            book         = BookDataAccess.GetFullBookByISBN(ISBN_Value);
         BookEditorForm editBookForm = new BookEditorForm();
         SendBookInfoEvent += editBookForm.GetValues;
         SendBookInfoEvent.Invoke(book);
         editBookForm.ShowDialog();
         ShowAllBasicBookData();
     }
     else if (dataGridViewBooks.Columns[e.ColumnIndex].Name == "Delete" && e.RowIndex >= 0)
     {
         if (MessageBox.Show("删除图书后可能会导致部分订单、购物车和评论数据失效\n确定删除图书?", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
         {
             string ISBN_Value = dataGridViewBooks.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
             try
             {
                 BookDataAccess.DeleteBook(ISBN_Value);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
             ShowAllBasicBookData();
         }
     }
     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 == "Order" && e.RowIndex >= 0)
     {
         string           ISBN_Value        = dataGridViewBooks.Rows[e.RowIndex].Cells["ISBN"].Value.ToString();
         var              orders            = OrderOfBookDataAccess.GetOrders(ISBN_Value);
         OrdersOfBookForm reviewsOfBookForm = new OrdersOfBookForm();
         SendOrdersInfoEvent += reviewsOfBookForm.ShowOrders;
         SendOrdersInfoEvent.Invoke(orders);
         reviewsOfBookForm.ShowDialog();
     }
 }
コード例 #2
0
 private void dataGridViewReviews_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridViewReviews.Columns[e.ColumnIndex].Name == "Detail" && e.RowIndex >= 0)
     {
         string         ISBN_Value = dataGridViewReviews.Rows[e.RowIndex].Cells["BookISBN"].Value.ToString();
         var            book       = BookDataAccess.GetFullBookByISBN(ISBN_Value);
         BookDetailForm detailForm = new BookDetailForm();
         SendBookInfoEvent += detailForm.ShowDetail;
         SendBookInfoEvent.Invoke(book);
         detailForm.ShowDialog();
     }
 }
コード例 #3
0
 private void dataGridViewOrders_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "CustomerDetail" && e.RowIndex >= 0)
     {
         string             Username_Value     = dataGridViewOrders.Rows[e.RowIndex].Cells["CustomerId"].Value.ToString();
         var                customer           = CustomerDataAccess.GetCustomerById(Username_Value);
         CustomerDetailForm customerDetailForm = new CustomerDetailForm();
         SendCustomerInfoEvent += customerDetailForm.ShowDetail;
         SendCustomerInfoEvent.Invoke(customer);
         customerDetailForm.ShowDialog();
     }
     else if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "BookDetail" && e.RowIndex >= 0)
     {
         string OrderId_Value  = dataGridViewOrders.Rows[e.RowIndex].Cells["OrderId"].Value.ToString();
         string BookISBN_Value = CustomerOrderDataAccess.GetBookISBNById(OrderId_Value);
         //string BookISBN_Value = dataGridViewOrders.Rows[e.RowIndex].Cells["BookISBN"].Value?.ToString();
         if (BookISBN_Value == null)
         {
             MessageBox.Show("图书不存在");
             return;
         }
         var            book           = BookDataAccess.GetFullBookByISBN(BookISBN_Value);
         BookDetailForm bookDetailForm = new BookDetailForm();
         SendBookInfoEvent += bookDetailForm.ShowDetail;
         SendBookInfoEvent.Invoke(book);
         bookDetailForm.ShowDialog();
     }
     else if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "Ship" && e.RowIndex >= 0)
     {
         string OrderId_Value  = dataGridViewOrders.Rows[e.RowIndex].Cells["OrderId"].Value.ToString();
         string BookISBN_Value = CustomerOrderDataAccess.GetBookISBNById(OrderId_Value);
         if (BookISBN_Value == null)
         {
             MessageBox.Show("图书不存在");
             return;
         }
         CustomerOrderStatusModel Status_Value = (CustomerOrderStatusModel)dataGridViewOrders.Rows[e.RowIndex].Cells["Status"].Value;
         if (Status_Value.Id == 2)
         {
             int quantity = BookDataAccess.GetBookQuantityByISBN(BookISBN_Value);
             int amount   = CustomerOrderDataAccess.GetAmountById(OrderId_Value);
             if (quantity >= amount)
             {
                 CustomerOrderDataAccess.ShipOrder(OrderId_Value);
                 BookDataAccess.UpdateBookQuantity(BookISBN_Value, quantity - amount);
             }
             else
             {
                 MessageBox.Show("库存不足");
                 return;
             }
         }
         ShowAllCustomerOrderData();
     }
     else if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "Cancel" && e.RowIndex >= 0)
     {
         string OrderId_Value = dataGridViewOrders.Rows[e.RowIndex].Cells["OrderId"].Value.ToString();
         CustomerOrderDataAccess.CancelOrder(OrderId_Value);
         ShowAllCustomerOrderData();
     }
     else if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "Delete" && e.RowIndex >= 0)
     {
         string OrderId_Value = dataGridViewOrders.Rows[e.RowIndex].Cells["OrderId"].Value.ToString();
         CustomerOrderDataAccess.DeleteOrder(OrderId_Value);
         ShowAllCustomerOrderData();
     }
 }
コード例 #4
0
 private void dataGridViewOrders_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "SupplierDetail" && e.RowIndex >= 0)
     {
         string             Username_Value     = dataGridViewOrders.Rows[e.RowIndex].Cells["SupplierId"].Value.ToString();
         var                supplier           = SupplierDataAccess.GetSupplierById(Username_Value);
         SupplierDetailForm supplierDetailForm = new SupplierDetailForm();
         SendSupplierInfoEvent += supplierDetailForm.ShowDetail;
         SendSupplierInfoEvent.Invoke(supplier);
         supplierDetailForm.ShowDialog();
     }
     else if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "BookDetail" && e.RowIndex >= 0)
     {
         string OrderId_Value = dataGridViewOrders.Rows[e.RowIndex].Cells["OrderId"].Value?.ToString();
         bool   IsNewBook;
         try
         {
             IsNewBook = SupplierOrderDataAccess.GetIsNewBook(OrderId_Value);
         }
         catch (MyException ex)
         {
             MessageBox.Show(ex.Message);
             return;
         }
         if (!IsNewBook)
         {
             var book = BookDataAccess.GetFullBookBySupplierExistentBookOrderId(OrderId_Value);
             if (book == null)
             {
                 MessageBox.Show("图书不存在");
                 return;
             }
             BookDetailForm detailForm = new BookDetailForm();
             SendBookInfoEvent += detailForm.ShowDetail;
             SendBookInfoEvent.Invoke(book);
             detailForm.ShowDialog();
         }
         else
         {
             var new_book  = NewBookInfoOfSupplierOrderDataAccess.GetNewBookInfoBySupplierOrderId(OrderId_Value);
             int status_id = new_book.Supplier_Order.Status.Id;
             if (status_id == 1) // 未入库
             {
                 BookUnstockedDetailForm detailForm = new BookUnstockedDetailForm();
                 SendNewBookInfoEvent += detailForm.ShowNewBookDetail;
                 SendNewBookInfoEvent.Invoke(new_book);
                 detailForm.ShowDialog();
             }
             else // 已入库
             {
                 var book = BookDataAccess.GetFullBookByISBN(new_book.Book_ISBN);
                 if (book == null)
                 {
                     MessageBox.Show("图书不存在");
                     return;
                 }
                 BookDetailForm detailForm = new BookDetailForm();
                 SendBookInfoEvent += detailForm.ShowDetail;
                 SendBookInfoEvent.Invoke(book);
                 detailForm.ShowDialog();
             }
         }
     }
     else if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "Warehouse" && e.RowIndex >= 0)
     {
         string OrderId_Value  = dataGridViewOrders.Rows[e.RowIndex].Cells["OrderId"].Value.ToString();
         int    StatusId_Value = SupplierOrderDataAccess.GetStatusIdValue(OrderId_Value);
         if (StatusId_Value == 1)
         {
             bool IsNewBook;
             try
             {
                 IsNewBook = SupplierOrderDataAccess.GetIsNewBook(OrderId_Value);
             }
             catch (MyException ex)
             {
                 MessageBox.Show(ex.Message);
                 return;
             }
             if (IsNewBook)
             {
                 bool is_on_sale = MessageBox.Show("是否立即上架该图书?", "上架", MessageBoxButtons.OKCancel) == DialogResult.OK;
                 try
                 {
                     SupplierOrderDataAccess.WarehouseNewBook(OrderId_Value, is_on_sale);
                 }
                 catch (MyException ex)
                 {
                     MessageBox.Show(ex.Message);
                 }
             }
             else
             {
                 try
                 {
                     SupplierOrderDataAccess.WarehouseExistentBook(OrderId_Value);
                 }
                 catch (MyException ex)
                 {
                     MessageBox.Show(ex.Message);
                 }
             }
         }
         ShowAllSupplierOrderData();
     }
     else if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "Cancel" && e.RowIndex >= 0)
     {
         string OrderId_Value = dataGridViewOrders.Rows[e.RowIndex].Cells["OrderId"].Value.ToString();
         try
         {
             SupplierOrderDataAccess.CancelOrder(OrderId_Value);
         }
         catch (Exception ex)
         {
             MessageBox.Show("取消订单失败\n" + ex.Message);
         }
         ShowAllSupplierOrderData();
     }
     else if (dataGridViewOrders.Columns[e.ColumnIndex].Name == "Delete" && e.RowIndex >= 0)
     {
         string OrderId_Value = dataGridViewOrders.Rows[e.RowIndex].Cells["OrderId"].Value.ToString();
         try
         {
             SupplierOrderDataAccess.DeleteOrder(OrderId_Value);
         }
         catch (Exception ex)
         {
             MessageBox.Show("删除订单失败\n" + ex.Message);
         }
         ShowAllSupplierOrderData();
     }
 }