Esempio n. 1
0
        private void AddContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FacultyForm facForm = new FacultyForm();

            DialogResult result;

            result = facForm.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            Member m = new Faculty(facForm.FirstName,
                                   facForm.LastName,
                                   facForm.MemberType,
                                   facForm.Department,
                                   facForm.Email,
                                   facForm.Building);

            if (m != null)
            {
                memberList.Add(m);
                contactsListBox.Items.Add(m.ToFormattedString());
            }
            listIsSaved = false;
        }
        /**** File Menu Code **********/
        //method to navigate ,read  and load the content of a new file
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //open a dialog a new save dialog box
            OpenFileDialog ofd = new OpenFileDialog();

            // configure dialog and show
            ofd.Title       = "Save Contact List";
            ofd.DefaultExt  = "txt";
            ofd.Filter      = "Contact Inventory File|*.cil|Text Files|*.txt|All Files|*.*";
            ofd.FilterIndex = 2;
            DialogResult result = ofd.ShowDialog();

            //pass the file name from
            if (result != DialogResult.OK)
            {
                return;
            }
            myfilePath = ofd.FileName;
            //Savefile(ofd.FileName);
            StreamReader input = new StreamReader(ofd.FileName);
            // All inside a try catch
            Person p = null;

            try
            {
                // open a stream reader on productList on the desktop
                // foreach contact call the constractor that takes a single string
                //and get a contact information back . Add that object to my list and to the display close
                while (!input.EndOfStream)
                {
                    string contactType = input.ReadLine();
                    switch (contactType)
                    {
                    case "Student": p = new Student(input.ReadLine()); break;

                    case "Faculty": p = new Faculty(input.ReadLine()); break;

                    default:
                        MessageBox.Show("Unkown Contact Information");
                        p = null;
                        break;
                    }
                    if (p != null)
                    {
                        PeopleInventory.Add(p);
                        displayContactListbox.Items.Add(p.ToFormattedString());
                    }
                }
                input.Close();
            }
            catch (Exception excp)
            {
                MessageBox.Show($"Error:File did not Load.{excp.Message}");
                return;
            }
            haveFileBeenSaved = false;
        }
        private void EditContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // make sure that someon is selected before displaying the information

            int    index = displayContactListbox.SelectedIndex;
            Person p;

            p = SelectContactFirst();

            if (p != null)
            {
                DialogResult result1 = MessageBox.Show($"Do you wish to edit " +
                                                       $"{p.FirstName} {p.LastName} contact information?", "Confirmation Message", MessageBoxButtons.YesNo);
                if (result1 == DialogResult.Yes)
                {
                    if (p is Faculty)
                    {
                        afd             = new AddStudentDialog();
                        afd.FacultyMode = true;
                        afd.EditMode    = true;
                        addFacultyDialog();

                        // if user confirm create a update the current contact information and student from the info from the dialog box
                        ContactInformation c = new ContactInformation();
                        c.EmailAddress   = afd.EmailAddress;
                        c.OfficeLocation = afd.SnailMailAddress;
                        Person p1 = new Faculty(afd.FirstName, afd.LastName, afd.AcademicDepartment, c);
                        PeopleInventory[index]             = p1;
                        displayContactListbox.Items[index] = p1.ToFormattedString();
                    }
                    else if (p is Student)
                    {
                        asd = new AddStudentDialog();
                        // ceate a new dialog for displaying and configure it
                        asd.EditMode    = true;
                        asd.StudentMode = true;
                        addStudentDialog();
                        // show the dialog and and wait for the Ok

                        // if user confirm create a update the current contact information and student from the info from the dialog box
                        ContactInformation c = new ContactInformation();
                        c.EmailAddress     = asd.EmailAddress;
                        c.SnailMailAddress = asd.SnailMailAddress;
                        Person p1 = new Student(asd.FirstName, asd.LastName, asd.AcademicDepartment, c, asd.GraduationYear, asd.CourseList);
                        PeopleInventory[index]             = p1;
                        displayContactListbox.Items[index] = p1.ToFormattedString();
                    }

                    haveFileBeenSaved = false;
                }
            }
        }
Esempio n. 4
0
        // Function - Edit faculty staff contact information
        private void EditFacultyPerson(int index, int mode)
        {
            // create a dialog and configure for edit or only display

            AddEditFacultyDialog adfd = new AddEditFacultyDialog();

            switch (mode)
            {
            case 0:         // 0 - show mode
            case 2:         // 2 - edit mode

                Faculty f = (Faculty)personList[index];

                // assign values in personList to public properties in AddEditFacultyDialog
                adfd.FacultyEditMode     = mode;
                adfd.FacultyFirstName    = f.FirstName;
                adfd.FacultyLastName     = f.LastName;
                adfd.FacultyAcademicDept = f.Department;
                adfd.FacultyEmail        = f.ContactFaculty.Email;
                adfd.FacultyBuilding     = f.ContactFaculty.Building;

                break;

            case 1:         // 1 - add mode
                adfd.FacultyEditMode = mode;
                break;
            }


            // show the dialog and wait for a ok

            DialogResult result = adfd.ShowDialog();

            // if answer was ok update the contact information with the new values and update display

            // update faculty contact information



            if (result == DialogResult.OK)
            {
                ContactFaculty facultyInfo;
                try
                {
                    facultyInfo = new ContactFaculty(adfd.FacultyEmail, adfd.FacultyBuilding);
                }
                catch (Exception excp)
                {
                    MessageBox.Show($"email address error. {excp.Message}");
                    return;
                }

                Person p = new Faculty(adfd.FacultyFirstName,
                                       adfd.FacultyLastName,
                                       adfd.FacultyAcademicDept,
                                       facultyInfo);

                // set mode to public property
                p.Type = "Faculty";

                switch (mode)
                {
                case 0:     // show mode
                    break;

                case 2:     // edit mode

                    // update new values for dispaly and list

                    personList[index] = p;
                    personListListBox.Items[index] = p.ToFormattedString();
                    EditCount++;                        // EditCount add 1 after sucessful edit
                    break;

                case 1:     //add mode

                    // add to list
                    personList.Add(p);

                    // add to list box for display
                    personListListBox.Items.Add(p.ToFormattedString());
                    EditCount++;                        // EditCount add 1 after sucessful add
                    break;

                default:
                    break;
                }
            }
            else if (result == DialogResult.Cancel)
            {
                return;
            }
            else
            {
                MessageBox.Show("AddEditFacultyDialog not return OK ....debug");
                return;
            }
        }