Пример #1
0
 private void btnAccept_Click(object sender, EventArgs e)
 {
     if (IsValidData())
     {
         if (addCustomer)
         {
             customer = new Customer();
             this.PutCustomerData(customer);
             try
             {
                 customer.CustomerID = CustomerDB.AddCustomer(customer);
                 this.DialogResult   = DialogResult.OK;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
         else
         {
             // this is for updating Customer
             Customer newCustomer = new Customer();
             // new customer object, old customer object
             newCustomer.CustomerID = customer.CustomerID;
             this.PutCustomerData(newCustomer);
             try
             {
                 if (!CustomerDB.UpdateCustomer(customer, newCustomer))
                 {
                     MessageBox.Show("Another user has updated or " +
                                     "deleted that customer.", "Database Error");
                     this.DialogResult = DialogResult.Retry;
                 }
                 else
                 {
                     customer          = newCustomer;
                     this.DialogResult = DialogResult.OK;
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
     }
 }