1
Answer

code help

Ask a question
Kevin

Kevin

12y
1.1k
1
How would I call the Check ID in the add studentbutton every time I call the checkID inside the student button it displays both the student id is already taken and it says student is saved.

        private void addStudentButton_Click(object sender, EventArgs e)
        {
            if (firstNameAddTextBox.Text == string.Empty ||
                lastNameAddTextBox.Text == string.Empty ||
                idAddTextBox.Text == string.Empty)
            {
                System.Windows.Forms.MessageBox.Show("Please enter all required information");
            }
            else
            {
                Student temp = new Student(this.firstNameAddTextBox.Text,
                    this.lastNameAddTextBox.Text, this.dobAddTextBox.Value,
                    Convert.ToInt32(this.idAddTextBox.Text));
                data.AddStudent(temp);
checkId();
                System.Windows.Forms.MessageBox.Show("Your student has been stored");
            }
        }



        public void checkId()
        {

            foreach (Student stu in students)
            {
                if (stu.IdNumber.ToString().Equals(idAddTextBox.Text))
                {
                    MessageBox.Show("Sorry.Student id already in use");
                    return;
                }
            }
        } 

Answers (1)