/// <summary> /// Opens form to add a new faculty member to the contact list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FacultyToolStripMenuItem_Click(object sender, EventArgs e) { // Opens faculty form AddEditFacultyForm facultyForm = new AddEditFacultyForm(); DialogResult result = facultyForm.ShowDialog(); // If user successfully entered required info, add faculty and flip file save flag if (result == DialogResult.OK) { AddContactToList(facultyForm.NewFaculty); fileSavedSinceLastChange = false; } }
/// <summary> /// Opens appropriate form to edit contact /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditContactToolStripMenuItem_Click(object sender, EventArgs e) { // Gets list of selected contacts. Only 1 allowed List <int> selectedIndices = contactsListBox.SelectedIndices.Cast <int>().ToList(); // Ensures only 1 is selected. Otherwise, displays error message if (selectedIndices.Count == 1) { Person person = contactsList[selectedIndices[0]]; // Student edit form if (person is Student) { // Opens student form for editing AddEditStudentForm addEditStudentForm = new AddEditStudentForm((Student)person); DialogResult result = addEditStudentForm.ShowDialog(); // If result is OK, update the contact List with the new string. Flip file flag. if (result == DialogResult.OK) { MessageBox.Show($"Saved changes to student {person.FirstName} {person.LastName}"); contactsListBox.Items[selectedIndices[0]] = contactsList[selectedIndices[0]].ToListBoxString(); fileSavedSinceLastChange = false; } } // Faculty edit form else if (person is Faculty) { // Open faculty form for editing AddEditFacultyForm addEditFacultyForm = new AddEditFacultyForm((Faculty)person); DialogResult result = addEditFacultyForm.ShowDialog(); // If result is OK, update the contact List with the new string. Flip file flag. if (result == DialogResult.OK) { MessageBox.Show($"Saved changes to faculty {person.FirstName} {person.LastName}"); contactsListBox.Items[selectedIndices[0]] = contactsList[selectedIndices[0]].ToListBoxString(); fileSavedSinceLastChange = false; } } else { // Show error for unsupported type MessageBox.Show("Error. Selected member is not a faculty or student.", "Error", MessageBoxButtons.OK); } } else if (selectedIndices.Count == 0) { MessageBox.Show("Must select a contact to edit.", "No contact selected.", MessageBoxButtons.OK); } else { MessageBox.Show("Must select only one contact to edit.", "Too many contacts selected.", MessageBoxButtons.OK); } }