// SAVE CHANGES BUTTON click event - Save changes made to currently selected customer private void btn_SaveChanges_Click(object sender, EventArgs e) { // BEGIN USER INPUT DATA VALIDATION..... // Verify that PERSONAL information was not left blank if ((this.tbx_FirstName.Text == "") || (this.tbx_LastName.Text == "") || (this.tbx_PhoneNumber.Text == "") || (this.tbx_EMail.Text == "")) { // If any personal information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the personal fields and try again."); return; } // Verify that MAILING address information was not left blank if ((this.tbx_MailingStreetNumber.Text == "") || (this.tbx_MailingStreetName.Text == "") || (this.tbx_MailingCity.Text == "") || (this.tbx_MailingState.Text == "") || (this.tbx_MailingZipCode.Text == "")) { // If any mailing address information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the mailing address fields and try again."); return; } // Verify that BILLING address information was not left blank if ((this.tbx_BillingStreetNumber.Text == "") || (this.tbx_BillingStreetName.Text == "") || (this.tbx_BillingCity.Text == "") || (this.tbx_BillingState.Text == "") || (this.tbx_BillingZipCode.Text == "")) { // If any billing address information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the billing address fields and try again."); return; } // Validate numeric input for phone number if ((!long.TryParse((this.tbx_PhoneNumber.Text), out longValidation)) || (this.tbx_PhoneNumber.Text.Length != 10)) { // If phone number input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid phone number entered. Please enter 10 digits (no dashes) & try again."); return; } // validate email address format if (!ApplicationObjects.EmailIsValid(this.tbx_EMail.Text)) { // If email address was not in specified format, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid e-mail address entered. Please try again."); return; } // Validate numeric input for street numbers if ((!long.TryParse((this.tbx_MailingStreetNumber.Text), out longValidation)) || (!long.TryParse((this.tbx_BillingStreetNumber.Text), out longValidation))) { // If street number input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid street number entered. Please enter only numeric values & try again."); return; } // Verify that the state is only 2 characters if ((this.tbx_MailingState.Text.Length != 2) || (this.tbx_BillingState.Text.Length != 2)) { // If state input does not have only 2 characters, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid state entered. Please enter a 2-letter state abbreviation & try again."); return; } // Validate numeric input for zip codes if ((!long.TryParse((this.tbx_MailingZipCode.Text), out longValidation)) || (!long.TryParse((this.tbx_BillingZipCode.Text), out longValidation))) { // If zip code input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid zip code entered. Please enter only numeric values & try again."); return; } // If zip is numeric, validate only 5 digits else if ((this.tbx_MailingZipCode.Text.Length != 5) || (this.tbx_BillingZipCode.Text.Length != 5)) { // If zip code does not have only 5 characters, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid zip code entered. Please enter only 5 digits & try again."); return; } // .....END USER INPUT DATA VALIDATION // Take the user input from the text boxes and update the currently selected... // ...customer's information within the customer object PopulateCustomerObjectWithDetails(); // Send update request to business layer int returnValue = ApplicationObjects.UpdateCustomer(customers[cbx_CustomerResultsList.SelectedIndex]); // Re-run search if (returnValue == 0) { // If update successfull, re-run search based on the customerID of the customer that was just updated cbx_CustomerSearchType.SelectedIndex = 2; tbx_CustomerSearchInput.Text = customers[cbx_CustomerResultsList.SelectedIndex].CustomerId.ToString(); } // Perform search button click to re-populate search results gbx_SearchCriteria.Visible = true; btn_ViewOrders.Visible = true; btn_CreateCustomer.Visible = true; btn_CustomerSearch.Visible = true;; btn_MainPage.Visible = true; btn_EnableEditing.Visible = true; btn_NewOrder.Visible = true; btn_SaveChanges.Visible = false; lbl_CustomerResultSort.Visible = false; cbx_SameAsMailing.Visible = true; btn_CustomerSearch.PerformClick(); }