Beispiel #1
0
        /// <summary>
        /// Add Student submenu option; adds student to contact list
        /// </summary>
        /// <param name="sender">Method parameter for the component that fires the event</param>
        /// <param name="e">Method parameter for the events tied to the component</param>
        private void StudentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddEditStudent addStudent = new AddEditStudent();  //create instance of addeditstudent window

            DialogResult result = addStudent.ShowDialog(this); //variable the stores result returned from modal dialog form; shows add student form

            if (result == DialogResult.OK)
            {
                //create instance of student class with the newly added student info
                Student addedStudent = new Student(addStudent.addedFirstName, addStudent.addedLastName, addStudent.addedAcademicDepartment, addStudent.addedEmailAddress, addStudent.addedAddress, int.Parse(addStudent.addedGraduationYear), "Student", addStudent.CoursesList);

                ContactListBox.Items.Add(addedStudent.ToFormattedString()); //display the info in our student list
                mainContactList.Add(addedStudent);                          //add student to our contact list
                saveChanges = true;                                         //update public boolean variable that indicates some changes have been made so prompt will be given on exit
            }
        }
Beispiel #2
0
        /// <summary>
        /// Method that is called to populate contact details for viewing
        /// </summary>
        /// <param name="index"></param>
        private void viewPersonBySelectedIndex(int index)
        {
            try
            {
                //Checks what the type of person being selected for viewing is then populates their respective modal dialog form for viewing
                if (mainContactList[index].PersonType == "Student")
                {
                    AddEditStudent viewStudent = new AddEditStudent(); //create instance of addeditstudent window
                    viewStudent.ViewMode = true;                       //enable view mode

                    //create instance of student class utlizing the selected index
                    Student personToView = (Student)mainContactList[index];

                    //update form fields with values from contact list for selected person
                    viewStudent.addedFirstName          = personToView.FirstName;
                    viewStudent.addedLastName           = personToView.LastName;
                    viewStudent.addedAcademicDepartment = personToView.AcademicDepartment;
                    viewStudent.addedEmailAddress       = personToView.EmailAddress;
                    viewStudent.addedAddress            = personToView.Address;
                    viewStudent.addedGraduationYear     = personToView.ExpectedGraduationYear.ToString();
                    viewStudent.CoursesList             = personToView.CourseList;

                    DialogResult result = viewStudent.ShowDialog();// show the dialog and wait for an OK.

                    // if answer was OK update the contact list with the new values and update display
                    if (result != DialogResult.OK)
                    {
                        return;
                    }
                }
                else if (mainContactList[index].PersonType == "Faculty")
                {
                    AddEditFaculty viewFaculty = new AddEditFaculty(); //create instance of addeditfaculty window
                    viewFaculty.ViewMode = true;                       //enable view mode

                    //create instance of student class utlizing the selected index
                    FacultyPerson personToView = (FacultyPerson)mainContactList[index];

                    //update form fields with values from contact list for selected person
                    viewFaculty.addedFirstName          = personToView.FirstName;
                    viewFaculty.addedLastName           = personToView.LastName;
                    viewFaculty.addedAcademicDepartment = personToView.AcademicDepartment;
                    viewFaculty.addedEmailAddress       = personToView.EmailAddress;
                    viewFaculty.addedAddress            = personToView.Address;

                    DialogResult result = viewFaculty.ShowDialog();// show the dialog and wait for an OK.

                    // if answer was OK update the contact list with the new values and update display
                    if (result != DialogResult.OK)
                    {
                        return;
                    }

                    viewFaculty.Dispose();//disposes of all resources used by the control
                }
            }
            catch (Exception)
            {
                string msg  = "You must select a person before viewing their details"; //string variable message; warning message
                string capt = "View Contact Information";                              //string variable caption; warning caption
                                                                                       //initiate an instance of DialogResult class with return value of CustomMsgBoxes method call
                MessageBox.Show(msg, capt, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Edit contact menu option; edits contact from contact list
        /// </summary>
        /// <param name="sender">Method parameter for the component that fires the event</param>
        /// <param name="e">Method parameter for the events tied to the component</param>
        private void editContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = ContactListBox.SelectedIndex;//variable that stores selected index of contact list box

            try
            {
                //Prompts user to select a contact if none is selected; edits contact from contact list box and list if one is selected, does not allow selecting more than one
                if (index == -1)
                {
                    MessageBox.Show("You must select person to edit");
                }
                else if (ContactListBox.SelectedItems.Count > 1)
                {
                    MessageBox.Show("You must select one contact at a time to edit");
                    return;
                }
                else
                {
                    //Checks what the type of person being selected for editing is then populates their respective modal dialog form for editing
                    if (mainContactList[index].PersonType == "Student")
                    {
                        AddEditStudent editStudent = new AddEditStudent(); //create instance of addeditstudent window
                        editStudent.EditMode = true;                       //enable edit mode

                        //create instance of student class utlizing the selected index
                        Student personToEdit = (Student)mainContactList[index];

                        //update form fields with values from contact list for selected person
                        editStudent.addedFirstName          = personToEdit.FirstName;
                        editStudent.addedLastName           = personToEdit.LastName;
                        editStudent.addedAcademicDepartment = personToEdit.AcademicDepartment;
                        editStudent.addedEmailAddress       = personToEdit.EmailAddress;
                        editStudent.addedAddress            = personToEdit.Address;
                        editStudent.addedGraduationYear     = personToEdit.ExpectedGraduationYear.ToString();
                        //editStudent.CoursesList = personToEdit.CourseList;
                        editStudent.CoursesList = new List <string>(personToEdit.CourseList);

                        DialogResult result = editStudent.ShowDialog();// show the dialog and wait for an OK.

                        // if answer was OK update the contact list with the new values and update display
                        if (result != DialogResult.OK)
                        {
                            return;
                        }

                        //create an instance of student class initialized with updated values
                        Student updatedStudent = new Student(editStudent.addedFirstName,
                                                             editStudent.addedLastName,
                                                             editStudent.addedAcademicDepartment,
                                                             editStudent.addedEmailAddress,
                                                             editStudent.addedAddress,
                                                             int.Parse(editStudent.addedGraduationYear),
                                                             "Student",
                                                             editStudent.CoursesList);

                        mainContactList[index]      = updatedStudent;                     //Populate contact list with updated values
                        ContactListBox.Items[index] = updatedStudent.ToFormattedString(); //populate contact listbox with updated values
                        saveChanges = true;                                               //update public boolean variable that indicates some changes have been made so prompt will be given on exit
                    }
                    else if (mainContactList[index].PersonType == "Faculty")
                    {
                        AddEditFaculty editFaculty = new AddEditFaculty(); //create instance of addeditfaculty window
                        editFaculty.EditMode = true;                       //enable edit mode

                        //create instance of student class utlizing the selected index
                        FacultyPerson personToEdit = (FacultyPerson)mainContactList[index];

                        //update form fields with values from contact list for selected person
                        editFaculty.addedFirstName          = personToEdit.FirstName;
                        editFaculty.addedLastName           = personToEdit.LastName;
                        editFaculty.addedAcademicDepartment = personToEdit.AcademicDepartment;
                        editFaculty.addedEmailAddress       = personToEdit.EmailAddress;
                        editFaculty.addedAddress            = personToEdit.Address;

                        DialogResult result = editFaculty.ShowDialog();// show the dialog and wait for an OK.

                        // if answer was OK update the contact list with the new values and update display
                        if (result != DialogResult.OK)
                        {
                            return;
                        }

                        //create an instance of faculty person class initialized with updated values
                        FacultyPerson updatedFaculty = new FacultyPerson(editFaculty.addedFirstName,
                                                                         editFaculty.addedLastName,
                                                                         editFaculty.addedAcademicDepartment,
                                                                         editFaculty.addedEmailAddress,
                                                                         editFaculty.addedAddress,
                                                                         "Faculty");

                        mainContactList[index]      = updatedFaculty;                     //Populate contact list with updated values
                        ContactListBox.Items[index] = updatedFaculty.ToFormattedString(); //populate contact listbox with updated values
                        saveChanges = true;                                               //update public boolean variable that indicates some changes have been made so prompt will be given on exit
                        editFaculty.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                //string msg = "You must select a person before editing their details"; //string variable message; warning message
                //string capt = "Edit Contact Information";//string variable caption; warning caption
                //initiate an instance of DialogResult class with return value of CustomMsgBoxes method call
                MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }