private void FacultyToolStripMenuItem1_Click(object sender, EventArgs e) { // pop a AddComputerDialog. If return is cancel, give up // if return is dialog ok, try to create a computer object // return that reference FacultyForm facForm = new FacultyForm(); DialogResult result; result = facForm.ShowDialog(); if (result != DialogResult.OK) { return; } Faculty f = new Faculty(facForm.FirstName, facForm.LastName, facForm.MemberType, facForm.Department, facForm.Email, facForm.Building); if (f != null) { memberList.Add(f); contactsListBox.Items.Add(f.ToDisplayString()); } listIsSaved = false; }
private void EditFacultyMember(int index) { //create a dialog and configure for edit FacultyForm facForm = new FacultyForm(); facForm.EditMode = true; Faculty f = (Faculty)memberList[index]; //We cast the Faculty class to the memberList as Faculty is a subclass of the Member class facForm.FirstName = f.FirstName; facForm.LastName = f.LastName; facForm.MemberType = f.MemberType; facForm.Department = f.Department; facForm.Email = f.Email; facForm.Building = f.Building; DialogResult result = facForm.ShowDialog(); //show the dialog and wait for an OK //if answer was OK update the product inventory with the new values and update dispaly //create Computer product a new computer with updated properties if (result != DialogResult.OK) { return; } Member m = new Faculty(facForm.FirstName, facForm.LastName, facForm.MemberType, facForm.Department, facForm.Email, facForm.Building); string message = $"Are you sure that you would like to update the { m.MemberType} item?"; string caption = "Update Item"; var result2 = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result2 == DialogResult.No) { // cancel the closure of the form. return; } memberList[index] = m; //Update the inventory contactsListBox.Items[index] = m.ToDisplayString(); //update the listBox display listIsSaved = false; }