private void dataGridViewReviews_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridViewReviews.Columns[e.ColumnIndex].Name == "Detail" && e.RowIndex >= 0)
     {
         string             Username_Value     = dataGridViewReviews.Rows[e.RowIndex].Cells["Username"].Value.ToString();
         var                customer           = CustomerDataAccess.GetCustomerByUsername(Username_Value);
         CustomerDetailForm customerDetailForm = new CustomerDetailForm();
         SendCustomerInfoEvent += customerDetailForm.ShowDetail;
         SendCustomerInfoEvent.Invoke(customer);
         customerDetailForm.ShowDialog();
     }
 }
Ejemplo n.º 2
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();
     }
 }