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;
}
}
}
FroglegPosted Feb 3, 2012, 11:19 PM
private void addStudentButton_Click(object sender, EventArgs e)
{
if (firstNameAddTextBox.Text == string.Empty || lastNameAddTextBox.Text == string.Empty || idAddTextBox.Text == string.Empty)
{
MessageBox.Show("Please enter all required information");
}
else
{
bool id = checkId();
if (id)
{
MessageBox.Show("Sorry." +Environment.NewLine + "Student id already in use","Warning");
return;
}
int _age = getAge();
students.Add(new Student(index,firstNameAddTextBox.Text, lastNameAddTextBox.Text, dobAddTextBox.Text, _age, Convert.ToInt32(idAddTextBox.Text)));
index++;
data.WriteData();
MessageBox.Show("Your student has been stored");
if (addStudentButton.Text.Equals("Add Student"))
{
firstNameAddTextBox.Text = "";
lastNameAddTextBox.Text = "";
idAddTextBox.Text = "";
}
}
}
public bool checkId()
{
bool used = false;
foreach (Student stu in students)
{
if (stu._idNumber.ToString() == idAddTextBox.Text)
{
used = true;
break;
}
}
return used;
}