Ejemplo n.º 1
0
        private void editContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = contactListDiplayListBox.SelectedIndex;

            if (index == -1)
            {
                MessageBox.Show("Please Select an Item First");
                return;
            }
            // Create the edit Dialog, have it prepopulate the contents of the field and
            // Show the Dialog

            ContactsMain CM = ContactsDataList[index];

            if (CM is Student)
            {
                editStudentContact(index);
            }
            else if (CM is Faculty)
            {
                editFacultyContact(index);
            }
            else
            {
                MessageBox.Show("Unknow Product");
            }
            alreadySaved = false;

            //If the user selects cancel, give up, if the user selects upates then change all the
            // fields in the object
        }
Ejemplo n.º 2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title       = "Open a Text File";
            ofd.Filter      = "Text File|*.txt|All Files|*.*";
            ofd.FilterIndex = 1;
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            contactListDiplayListBox.Items.Clear();
            ContactsDataList.Clear();
            Filepath = ofd.FileName;

            // Read customer data from file and loading the data

            ContactsMain CI = null;

            try
            {
                // file automatically will be saved to in the project Debug folder


                StreamReader input = new StreamReader(ofd.FileName);
                while (!input.EndOfStream)
                {
                    string Type = input.ReadLine();
                    switch (Type)
                    {
                    case "Faculty": CI = new Faculty(input.ReadLine()); break;

                    case "Student": CI = new Student(input.ReadLine()); break;


                    default:
                        MessageBox.Show("Unknow Value");
                        break;
                    }

                    if (CI != null)
                    {
                        ContactsDataList.Add(CI);
                        contactListDiplayListBox.Items.Add(CI.ToFormattedString());
                    }
                    CI = null;
                }
                input.Close();
            }

            catch (IOException excp)
            {
                MessageBox.Show($"File did not Load.{excp.Message}");
                return;
            }
            MessageBox.Show("File has been loaded");
            alreadySaved = true;
        }
Ejemplo n.º 3
0
        private void contactDetailToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = contactListDiplayListBox.SelectedIndex;

            if (index == -1)
            {
                MessageBox.Show("Please Select an Item First");
                return;
            }

            // Create the edit Dialog, have it prepopulate the contents of the field and
            // Show the Dialog

            ContactsMain CM = ContactsDataList[index];

            if (CM is Student)
            {
                // Create Dialog and Configure for edit
                contactsInformation ci = new contactsInformation();
                ci.ContactDetialMode = true;
                ci.EditMode          = true;
                ci.LoadStudentForm   = true;
                Student S = (Student)ContactsDataList[index];

                ci.FirstName                  = S.FirstName;
                ci.LastName                   = S.LastName;
                ci.AcademicDepartment         = S.AcademicDepartment;
                ci.EmailAddress               = S.EmailAddress;
                ci.SnailMailAndOfficeLocation = S.SnailMailAddress;
                ci.GraduationYear             = S.GraduationYear;
                ci.CourseList                 = S.CourseList;

                // Show the Dialog and Wait for OK
                DialogResult result = ci.ShowDialog();

                // If Answer was OK update the ContactList with the new values

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

                CM = new Student(ci.FirstName,
                                 ci.LastName,
                                 ci.AcademicDepartment,
                                 ci.EmailAddress,
                                 ci.SnailMailAndOfficeLocation,
                                 ci.GraduationYear,
                                 ci.CourseList);


                ContactsDataList[index] = CM;
            }
            else if (CM is Faculty)
            {
                // Create Dialog and Configure for eidit
                contactsInformation cif = new contactsInformation();
                cif.EditMode          = true;
                cif.LoadFacultyForm   = true;
                cif.ContactDetialMode = true;

                Faculty f = (Faculty)ContactsDataList[index];

                cif.FirstName                  = f.FirstName;
                cif.LastName                   = f.LastName;
                cif.AcademicDepartment         = f.AcademicDepartment;
                cif.EmailAddress               = f.EmailAddress;
                cif.SnailMailAndOfficeLocation = f.OfficeLocationBuilding;

                // Show the Dialog and Wait for OK
                DialogResult result = cif.ShowDialog();

                // If Answer was OK update the ContactList with the new values

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

                CM = new Faculty(cif.FirstName,
                                 cif.LastName,
                                 cif.AcademicDepartment,
                                 cif.EmailAddress,
                                 cif.SnailMailAndOfficeLocation);


                ContactsDataList[index] = CM;
            }
            else
            {
                MessageBox.Show("Unknow Product");
            }
        }