private void buttonAdd_Click(object sender, EventArgs e) { if (this.isCustomerValid()) { List <Customer> Customers = DataProvider.GetCustomer( this.textBoxName.Text, this.textBoxEmail.Text, this.phoneControlPhone.PhoneNumber ); if (Customers.Count > 0) { SelectCustomer frm = new SelectCustomer(Customers); if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { this.ClearUI(); this.SelectedCustomer = frm.SelectedCustomer; } //MessageBox.Show(this, "The Customer exists.", "Exists"); } else { Customer customer = new Customer() { CustomerName = textBoxName.Text.Trim(), Email = textBoxEmail.Text.Trim(), PhoneNumber = phoneControlPhone.PhoneNumber.Trim(), Address = textBoxAddress.Text.Trim(), Country = phoneControlPhone.Country }; try { customer.Commit(); this.ClearUI(); } catch (Exception ex) { DetailedDialog x = new DetailedDialog(new PropertyGrid()); x.Message = "Error Occurred while Inserting Data."; x.Details = ex.Message; x.Text = "Cannot Add Data."; x.ShowDialog(this); } } } else { string ValidationMessages = ""; ValidationMessages += (this.textBoxName.Text.Length == 0) ? "Customer name cannot be blank." + Environment.NewLine : ""; ValidationMessages += (IsValidEmail == false) ? "Invalid Email." + Environment.NewLine : ""; ValidationMessages += this.phoneControlPhone.ValidationMessage; MessageBox.Show(this, ValidationMessages, "Invalid Details"); } }
private void buttonCustmerForm_Click(object sender, EventArgs e) { using (HQConnection hqConnection = new HQConnection()) { try { hqConnection.DedicatedConnection.Open(); hqConnection.DedicatedConnection.Close(); CustomerForm CustomerForm = new CustomerForm(); CustomerForm.ShowDialog(this); } catch (Exception ex) { DetailedDialog x = new DetailedDialog(new PropertyGrid()); x.Message = "Error Occurred while connecting to server."; x.Details = ex.Message; x.Text = "Connection Error."; x.ShowDialog(this); } } }