コード例 #1
0
        // Search Button Event.
        // Summary: Handles the Search Button Event.
        //          Displaying a filtered list of Students or Lecturers based on
        //          the key typed in the search text box by the user.
        private void btnIconSearch_Click(object sender, EventArgs e)
        {
            if (dgvStudent.Visible)
            {
                try
                {
                    dgvStudent.DataSource = FormsMethods.FilterList(AddStudent.EnrolledStudents, txtSearch.Text);
                }

                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message, "Information",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            else if (dgvLecturer.Visible)
            {
                try
                {
                    dgvLecturer.DataSource = FormsMethods.FilterList(AddLecturers.ListOfLecturers, txtSearch.Text);
                }

                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message, "Information",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
コード例 #2
0
        // Add Button Event
        // Try to initialize a new student acquiring all the properties from the user entries.
        // Then Add this new Student to the List<Student> of all Enrolled Students.
        // Catch four kind of main Exceptions that the user might enter while typing students properties.
        private void btnAddStud_Click(object sender, EventArgs e)
        {
            try
            {
                Student newStudent = new Student(txtFirst.Text,
                                                 txtSurname.Text,
                                                 txtAddress.Text,
                                                 txtCity.Text,
                                                 txtCountry.Text,
                                                 txtPPS.Text,
                                                 txtPhone.Text,
                                                 txtEmail.Text,
                                                 (Status)(cmbStatus.SelectedIndex),
                                                 int.Parse(txtId.Text),
                                                 txtDegree.Text);

                FormsMethods.AddRecordToList(EnrolledStudents, newStudent);


                this.Close();
            }

            catch (ArgumentNullException ex)
            {
                MessageBox.Show("All the fields need to be completed. " + ex.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            catch (ArgumentOutOfRangeException ex)
            {
                MessageBox.Show("Field values are not valid. " + ex.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "Information",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            catch (FormatException ex)
            {
                MessageBox.Show("Impossible store data. " + ex.Message, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        // Add Button Event
        // Try to initialize a new Lecturer object with all properties getting from user entries.
        // Catch some major Exceptions and then Add the new object to the List<Lecturer> if it
        // doesn't throw any exceptions.
        private void btnAddLect_Click(object sender, EventArgs e)
        {
            try
            {
                Lecturer newLecturer = new Lecturer(txtFirst.Text,
                                                    txtSurname.Text,
                                                    txtAddress.Text,
                                                    txtCity.Text,
                                                    txtCountry.Text,
                                                    txtPPS.Text,
                                                    txtPhone.Text,
                                                    txtEMail.Text,
                                                    int.Parse(txtId.Text),
                                                    decimal.Parse(txtSalary.Text),
                                                    txtSubjects.Text);


                FormsMethods.AddRecordToList(ListOfLecturers, newLecturer);

                this.Close();
            }

            catch (ArgumentNullException ex)
            {
                MessageBox.Show("All the fields need to be completed. " + ex.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            catch (ArgumentOutOfRangeException ex)
            {
                MessageBox.Show("Field values are not valid. " + ex.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "Information",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            catch (FormatException ex)
            {
                MessageBox.Show("Impossible store data. " + ex.Message, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }