private void CustomerForm_Load_1(object sender, EventArgs e) { List <Customer> customerList; try { customerList = CustomerDBDAL.GetCustomers(); if (customerList.Count > 0) { Customer customer; for (int i = 0; i < customerList.Count; i++) { customer = customerList[i]; txtCustID.Text = customer.CustomID.ToString(); txtName.Text = customer.Name; txtAddress.Text = customer.Address; txtCity.Text = customer.City; txtState.Text = customer.State; txtZip.Text = customer.ZipCode.ToString(); txtPhone.Text = customer.Phone; txtEmail.Text = customer.Email; } } else { MessageBox.Show("No Customer fitting that ID can be found."); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
private void btnAccept_Click(object sender, EventArgs e) { if (IsValidData()) { if (addCustomer) { customer = new Customer(); this.PutCustomerData(customer); try { customer.CustomID = CustomerDBDAL.AddCustomer(customer); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else { Customer newCustomer = new Customer(); newCustomer.CustomID = customer.CustomID; this.PutCustomerData(newCustomer); try { if (!CustomerDBDAL.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()); } } } }
private void GetCustomer(int customID) { try { customer = CustomerDBDAL.GetCustomer(customID); if (customer == null) { MessageBox.Show("No customer found with this ID." + "Please try again.", "Customer Not Found"); } else { this.DisplayCustomer(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
/// <summary> /// Constructor for the CustomerController class /// </summary public CustomerController() { customerDBDAL = new CustomerDBDAL(); }