private void newCustomerFormSaveButton_Click(object sender, EventArgs e) { try { var customer = new Models.Customer(); customer.BirthDate = Convert.ToDateTime(newCustomerEntryFormBirthdayPicker.Text); customer.EmailAddress = newCustomerEntryFormEmailTextBox.Text; customer.FirstName = newCustomerEntryFormFirstNameTextBox.Text; customer.IsEmailAuthorized = newCustomerEntryFormEmailAuthorisationCheckBox.Checked; customer.LastName = newCustomerEntryFormLastNameTextBox.Text; customer.PhoneNumber = newCustomerEntryFormPhoneNumberTextBox.Text; var customerData = new DAL.CustomerData(); customerData.AddCustomer(customer); MessageBox.Show("The Customer was successfully saved to the database."); this.Close(); } //catch (SqlException f) when (f.Number == 2627) //{ // MessageBox.Show("That Phone Number Already Exists in the Database. Please Enter another number or use existing customer entry form."); //} //catch (SqlException f) when (f.Number == 8152) //{ // MessageBox.Show("One of your fields is too long, fix it."); //} //finally //{ //} catch (Exception ex) { MessageBox.Show($"An error occurred with message: {ex.Message}"); } }
private void customerInformationSearchButton_Click(object sender, EventArgs e) { { var customerData = new DAL.CustomerData(); var customer = customerData.GetCustomer(customerInformationFormPhoneNumberTextBox.Text); if (customer == null) { return; } customerInformationFormFirstNameTextBox.Text = customer.FirstName; customerInformationFormLastNameTextBox.Text = customer.LastName; customerInformationFormEmailTextBox.Text = customer.EmailAddress; customerInformationFormBirthdayPicker.Text = customer.BirthDate?.ToShortDateString(); customerInformationCurrentPointsBalanceTextBox.Text = customer.PointsBalance.ToString(); customerInformationFormLifetimePointsBalanceTextBox.Text = customer.PointsTotal.ToString(); var visits = customerData.GetCustomerVisits(customer.PhoneNumber); customerInformationVisitsDataGridView.DataSource = visits; customerInformationVisitsDataGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True; } }