/// <summary> /// Method for editing selected contact /// Opens a new ContactForm if a current customer is selected /// If a customer is selected, it retrieves ContactData for that Customer and /// calls ChangeCustomer from CustomerManager. Finally updates the list. /// Hides submenus upon click. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bttnEdit_Click_1(object sender, EventArgs e) { ContactForm frmContact = new ContactForm("Edit Customer"); int index = listBoxCustomers.SelectedIndex; if (listBoxCustomers.SelectedItems.Count != 1) { MessageBox.Show("Please select a current customer to edit"); return; } if (index >= 0) { frmContact.ContactData = customerMngr.GetCustomer(index).ContactData; frmContact.ShowDialog(); customerMngr.ChangeCustomer(frmContact.ContactData, index); UpdateList(); } HideMenus(); }
/// <summary> /// Search button. /// /// Checks if input is emptry or if listbox is empty /// If not; calls SearchCustomer method in CustomerManager with text in txtBoxSearch /// and retrieves Contact data. Creates ContactForm window with ContactData. /// Also empties the textbox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bttnSearch_Click_1(object sender, EventArgs e) { string name = txtBoxSearch.Text; ContactForm frmContact = new ContactForm("Edit Searched Customer"); Customer customer = new Customer(); int index = listBoxCustomers.SelectedIndex; if (string.IsNullOrEmpty(name)) { MessageBox.Show("Enter the full name of a current customer", "Error", MessageBoxButtons.OK); } else { if (listBoxCustomers.Items.Count > 0) { if (customerMngr.SearchCustomer(name) != null && name.Equals(customerMngr.SearchCustomer(name).ContactData.CompleteName)) { frmContact.ContactData = customerMngr.SearchCustomer(name).ContactData; frmContact.ShowDialog(); txtBoxSearch.Text = string.Empty; } else { MessageBox.Show("Customer not found", "Error", MessageBoxButtons.OK); } } else if (listBoxCustomers.Items.Count == 0) { MessageBox.Show("Your customer registry is empty!"); } } HideMenus(); }