예제 #1
0
        private void createStudent_Click(object sender, EventArgs e)
        {
            try
            {
                // Create a student reference
                Student student;

                // Generate and undergraduate or graduate student depending on selection
                if (studentLevelComboBox.SelectedIndex == (int)StudentLevel.Undergraduate)
                {
                    student = new UnderGraduate(nameTextBox.Text, Convert.ToInt32(idTextBox.Text), dataComboBox1.SelectedItem.ToString(), dataTextBox2.Text, dataTextBox3.Text);
                }
                else if (studentLevelComboBox.SelectedIndex == (int)StudentLevel.Graduate)
                {
                    student = new GraduateStudent(nameTextBox.Text, Convert.ToInt32(idTextBox.Text), dataComboBox1.SelectedItem.ToString(), dataTextBox2.Text, dataTextBox3.Text);
                }
                else
                {
                    MessageBox.Show("Please select a Student Level", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Clear the current data entered and display the student info
                this.ClearForm();
                NewStudentInfo.Text = student.ToString();
            }
            catch (System.FormatException e1)
            {
                // User entered data that is not a number
                MessageBox.Show("Please enter a valid Student ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.NullReferenceException e1)
            {
                // Some of the fields were left blank
                MessageBox.Show("Please ensure the entire form has been filled before creating the student", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e1)
            {
                // Something unanticipated happened
                MessageBox.Show(e1.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        private void createStudent_Click(object sender, EventArgs e)
        {
            try
            {
                // Create a student reference
                Student student;

                // Generate and undergraduate or graduate student depending on selection
                if (studentLevelComboBox.SelectedIndex == (int)StudentLevel.Undergraduate)
                {
                    student = new UnderGraduate(nameTextBox.Text, Convert.ToInt32(idTextBox.Text), dataComboBox1.SelectedItem.ToString(), dataTextBox2.Text, dataTextBox3.Text);
                }
                else if (studentLevelComboBox.SelectedIndex == (int)StudentLevel.Graduate)
                {
                    student = new GraduateStudent(nameTextBox.Text, Convert.ToInt32(idTextBox.Text), dataComboBox1.SelectedItem.ToString(), dataTextBox2.Text, dataTextBox3.Text);
                }
                else
                {
                    MessageBox.Show("Please select a Student Level", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Clear the current data entered and display the student info
                this.ClearForm();
                NewStudentInfo.Text = student.ToString();
            }
            catch (System.FormatException e1)
            {
                // User entered data that is not a number
                MessageBox.Show("Please enter a valid Student ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.NullReferenceException e1)
            {
                // Some of the fields were left blank
                MessageBox.Show("Please ensure the entire form has been filled before creating the student", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e1)
            {
                // Something unanticipated happened
                MessageBox.Show(e1.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }