예제 #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());
             }
         }
     }
 }
 /// <summary>
 /// Validates the inputted information and sends it to MySql.
 /// </summary>
 /// <param></param>
 /// <returns>Conslidated customer data</returns>
 private void btnAccept_Click(object sender, EventArgs e)
 {
     //Validates the data with the IsValidData method.
     if (blnIsValidData())
     {
         if (blnAddCustomer)
         {
             customer = new Customer();
             this.PutCustomerData(customer);
             try
             {
                 customer.CUSTOMER_ID = CustomerDB.AddCustomer(customer);
                 this.DialogResult    = DialogResult.OK;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
         else
         {
             //Creates an instance of a new customer.
             Customer newCustomer = new Customer();
             newCustomer.CUSTOMER_ID = customer.CUSTOMER_ID;
             this.PutCustomerData(newCustomer);
             try
             {
                 if (!CustomerDB.blnUpdateCustomer(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());
             }
         }
     }
 }