Example #1
0
        private void ContactDetailsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //check if an item is selected in the lsitbox
            int index = ContactDisplayListBoz.SelectedIndex;

            if (index == -1)
            {
                MessageBox.Show("You must select an item to view Contact Details");
                return;
            }
            //check if the user selected more than one item
            if (ContactDisplayListBoz.SelectedItems.Count > 1)
            {
                MessageBox.Show("You must select one item to view the contact details");
                return;
            }
            //instantiate the base class object
            EducationPerson person = educationPeople[index];

            //add the object to the dialogue by calling the method
            if (person is Faculty)
            {
                showFacultyContact(index);
            }
            else if (person is Student)
            {
                showStudentContact(index);
            }
            else
            {
                MessageBox.Show("Unknown Contact details cannot be displayed");
                return;
            }
        }
Example #2
0
        private void EditContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = ContactDisplayListBoz.SelectedIndex;

            if (index == -1)
            {
                MessageBox.Show("You must select an item to edit or update");
                return;
            }
            //check if the user selected more than one item
            if (ContactDisplayListBoz.SelectedItems.Count > 1)
            {
                MessageBox.Show("You must select one item to edit or update");
                return;
            }

            EducationPerson person = educationPeople[index];

            if (person is Faculty)
            {
                editFaculty(index);
                changesMade = true;
            }
            else if (person is Student)
            {
                editStudent(index);
                changesMade = true;
            }
            else
            {
                MessageBox.Show("Unknown Contact details to be edited");
            }
        }
Example #3
0
        private void DeleteContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //check to see if the user selcted an item
            //before performing the delete opertaion
            int index = ContactDisplayListBoz.SelectedIndex;

            if (index == -1)
            {
                MessageBox.Show("You must select an item to be deleted");
                return;
            }
            //check if the user selected more than one item
            if (ContactDisplayListBoz.SelectedItems.Count > 1)
            {
                MessageBox.Show("You must select one item to delete");
                return;
            }
            //pop confirmation dialogue that the item is about to be deleted
            EducationPerson person = educationPeople[index];

            if (DialogResult.Yes != MessageBox.Show($"Are you sure you wish to delete {person.FirstName}'s details?",
                                                    "Confirmation", MessageBoxButtons.YesNo))
            {
                return;
            }
            //delete the item and remote it from the education people list
            //remove it from the listbox display as well
            educationPeople.RemoveAt(index);
            ContactDisplayListBoz.Items.RemoveAt(index);
            changesMade = true;
        }
Example #4
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title       = "Open a File";
            ofd.Filter      = "Text Files|*.txt|All Files|*.*";
            ofd.FilterIndex = 1;

            DialogResult result = ofd.ShowDialog();

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

            EducationPerson person = null;

            Filepath = ofd.FileName.ToString();  //save the current file path into the filapath variable.
            try
            {
                StreamReader input = new StreamReader(ofd.FileName);

                while (!input.EndOfStream)
                {
                    string personType = input.ReadLine();
                    switch (personType)
                    {
                    case "FACULTY":
                        person = new Faculty(input.ReadLine());
                        break;

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

                    default:
                        MessageBox.Show("Unknown Person in the file");
                        person = null;
                        break;
                    }

                    if (person != null)
                    {
                        educationPeople.Add(person);
                        ContactDisplayListBoz.Items.Add(person.ToFormattedString());
                    }
                }
                input.Close();
            }
            catch (Exception excp)
            {
                MessageBox.Show($"File failed to load. {excp.Message}");
                return;
            }
        }
Example #5
0
 //this method differentiates btween faculty and student
 //by writing faculty above before the data is inserted
 private string personTypeString(EducationPerson p)
 {
     if (p is Faculty)
     {
         return("FACULTY");
     }
     else if (p is Student)
     {
         return("STUDENT");
     }
     else
     {
         return("UNKNOWN");
     }
 }