//------------------------------ //Logic in the event of registration button clicked private void button_Click(object sender, RoutedEventArgs e) { listBox.Items.Clear(); courseIdChosen = (string)this.comboBox.SelectedItem; for (int i = 0; i < courses.Count(); i++) { if (courses[i].getCourseId() == courseIdChosen) { choice = courses[i]; } } int totalCredits = Convert.ToInt32(textBox.Text); //Display error message if no choice is selected if (choice == null) { label3.Content = string.Format("Please choose a course to register for"); } //Verification that student is able to register for selected class else if (student.getCurrentClass1() == choice.getCourseId() || student.getCurrentClass2() == choice.getCourseId() || student.getCurrentClass3() == choice.getCourseId()) { label3.Content = string.Format("You have alread registered for {0}.", choice.getCourseId()); } else if (student.getCurrentClass1() != "" && student.getCurrentClass2() != "" && student.getCurrentClass3() != "") { label3.Content = string.Format("You can not register for more than 9 credit hours."); } else if (student.getCurrentClass1() == "") { SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass1 = '" + choice.getCourseId() + "', creditcount = '" + (student.getCreditHours() + 3) + "' WHERE email = '" + studentEmail + "'", cn_connection); updateStudentInfo.ExecuteNonQuery(); textBox.Text = Convert.ToString(student.getCreditHours()); label3.Content = string.Format("Registration confirmed for course {0}", choice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (course.getStudentsRegistered() + 1) + " WHERE courseId = '" + choice.getCourseId() + "'", cn_connection); updateClassNumber.ExecuteNonQuery(); student.setCurrentClass1(choice.getCourseId()); student.setCreditHours(student.getCreditHours() + 3); } else if (student.getCurrentClass1() != "" && student.getCurrentClass2() == "") { SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass2 = '" + choice.getCourseId() + "', creditcount = '" + (student.getCreditHours() + 3) + "' WHERE email = '" + studentEmail + "'", cn_connection); updateStudentInfo.ExecuteNonQuery(); textBox.Text = Convert.ToString(student.getCreditHours()); label3.Content = string.Format("Registration confirmed for course {0}", choice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (course.getStudentsRegistered() + 1) + " WHERE courseId = '" + choice.getCourseId() + "'", cn_connection); updateClassNumber.ExecuteNonQuery(); student.setCurrentClass2(choice.getCourseId()); student.setCreditHours(student.getCreditHours() + 3); } else if (student.getCurrentClass2() != "" && student.getCurrentClass3() == "") { SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass3 = '" + choice.getCourseId() + "', creditcount = '" + (student.getCreditHours() + 3) + "' WHERE email = '" + studentEmail + "'", cn_connection); updateStudentInfo.ExecuteNonQuery(); textBox.Text = Convert.ToString(student.getCreditHours()); label3.Content = string.Format("Registration confirmed for course {0}", choice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (course.getStudentsRegistered() + 1) + " WHERE courseId = '" + choice.getCourseId() + "'", cn_connection); updateClassNumber.ExecuteNonQuery(); student.setCurrentClass3(choice.getCourseId()); student.setCreditHours(student.getCreditHours() + 3); } listBox.Items.Add(student.getCurrentClass1()); listBox.Items.Add(student.getCurrentClass2()); listBox.Items.Add(student.getCurrentClass3()); textBox.Text = student.getCreditHours().ToString(); }