private void Acceptchangebtn_Click(object sender, RoutedEventArgs e) { //sends data in textboxes to SQL database choice.setCourseId(courseidtxtbox.Text); choice.setName(coursenametxtbox.Text); choice.setCourseDesc(descriptiontxtbox.Text); choice.setCreditHours(Convert.ToInt32(credithourstxtbox.Text)); choice.setClassSize(Convert.ToInt32(classsizetxtbox.Text)); choice.setStudentsRegistered(Convert.ToInt32(registeredtxtbox.Text)); SqlCommand courseUpdateQuery = new SqlCommand("UPDATE classes SET courseId = '" + choice.getCourseId() + "', name = '" + choice.getName() + "', credithours = " + choice.getCreditHours() + ", classSize = " + choice.getClassSize() + ", studentsRegistered = " + choice.getStudentsRegistered() + ", courseDescription = '" + choice.getCourseDesc() + "' WHERE courseId = '" + choice.getCourseId() + "'", clsDB.Get_DB_Connection()); courseUpdateQuery.ExecuteNonQuery(); clsDB.Close_DB_Connection(); MessageBox.Show(choice.getCourseId() + " was successfully updated."); }
private void DropBtn_Click(object sender, RoutedEventArgs e) { //---------------------------------------- //logic for dropping a class from a student's schedule //SQL logic removes the courseID and adds a position back to the class if (dropChoice == null) { label3.Content = "Please select a valid course"; } else if (studentChoice == null) { label3.Content = "Please select a student"; } else if (studentChoice.getCurrentClass1() != "" && studentChoice.getCurrentClass2() != "" && studentChoice.getCurrentClass3() != "") { label3.Content = string.Format("Students can not register for more than 9 credit hours."); } else if (studentChoice.getCurrentClass1() == dropChoice.getCourseId()) { dropclasslistbox.Items.Remove(dropChoice.getCourseId()); SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass1 = '', creditcount = " + (studentChoice.getCreditHours() - 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("{0} successfully dropped", dropChoice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (dropChoice.getStudentsRegistered() + 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); studentChoice.setCurrentClass1(""); } else if (studentChoice.getCurrentClass2() == dropChoice.getCourseId()) { dropclasslistbox.Items.Remove(dropChoice.getCourseId()); SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass2 = '', creditcount = " + (studentChoice.getCreditHours() - 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("{0} successfully dropped", dropChoice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (dropChoice.getStudentsRegistered() + 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); studentChoice.setCurrentClass2(""); } else if (studentChoice.getCurrentClass3() == dropChoice.getCourseId()) { dropclasslistbox.Items.Remove(dropChoice.getCourseId()); SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass3 = '', creditcount = " + (studentChoice.getCreditHours() - 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("{0} successfully dropped", dropChoice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (dropChoice.getStudentsRegistered() + 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); studentChoice.setCurrentClass3(""); } //resets the courses listed in the drop listbox dropclasslistbox.Items.Clear(); dropclasslistbox.Items.Add(studentChoice.getCurrentClass1()); dropclasslistbox.Items.Add(studentChoice.getCurrentClass2()); dropclasslistbox.Items.Add(studentChoice.getCurrentClass3()); }
//---------------------------------- //logic for registering a student for a class //SQL logic for adding courseID to selected student //SQL logic for updating the number of students registered in a course private void AddBtn_Click(object sender, RoutedEventArgs e) { if (addChoice == null) { label3.Content = "Please select a valid course"; } else if (studentChoice == null) { label3.Content = "Please select a student"; } else if (studentChoice.getCurrentClass1() == addChoice.getCourseId() || studentChoice.getCurrentClass2() == addChoice.getCourseId() || studentChoice.getCurrentClass3() == addChoice.getCourseId()) { label3.Content = string.Format("This student is already registered for {0}.", addChoice.getCourseId()); } else if (studentChoice.getCurrentClass1() != "" && studentChoice.getCurrentClass2() != "" && studentChoice.getCurrentClass3() != "") { label3.Content = string.Format("Students can not register for more than 9 credit hours."); } else if (studentChoice.getCurrentClass1() == "") { dropclasslistbox.Items.Add(addChoice.getCourseId()); SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass1 = '" + addChoice.getCourseId() + "', creditcount = " + (studentChoice.getCreditHours() + 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("Registration confirmed for course {0}", addChoice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (addChoice.getStudentsRegistered() - 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); studentChoice.setCurrentClass1(addChoice.getCourseId()); } else if (studentChoice.getCurrentClass1() != "" && studentChoice.getCurrentClass2() == "") { dropclasslistbox.Items.Add(addChoice.getCourseId()); SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass2 = '" + addChoice.getCourseId() + "', creditcount = " + (studentChoice.getCreditHours() + 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("Registration confirmed for course {0}", addChoice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (addChoice.getStudentsRegistered() - 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); studentChoice.setCurrentClass2(addChoice.getCourseId()); } else if (studentChoice.getCurrentClass2() != "" && studentChoice.getCurrentClass3() == "") { dropclasslistbox.Items.Add(addChoice.getCourseId()); SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass3 = '" + addChoice.getCourseId() + "', creditcount = " + (studentChoice.getCreditHours() + 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("Registration confirmed for course {0}", addChoice.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (addChoice.getStudentsRegistered() - 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); studentChoice.setCurrentClass3(addChoice.getCourseId()); } //resets listbox items dropclasslistbox.Items.Clear(); dropclasslistbox.Items.Add(studentChoice.getCurrentClass1()); dropclasslistbox.Items.Add(studentChoice.getCurrentClass2()); dropclasslistbox.Items.Add(studentChoice.getCurrentClass3()); }
private void dropbutton_Click(object sender, RoutedEventArgs e) { //----------------------------------------- //logic for dropping a class and SQL logic //for removing the courseID from the student's schedule listChoice = (string)listBox.SelectedItem; if (listChoice == null || listChoice == "") { label3.Content = "Please select a class to drop."; } else if (student.getCurrentClass1() == selectedCourse.getCourseId()) { SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass1 = '', creditcount = " + (student.getCreditHours() - 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("{0} successfully dropped", selectedCourse.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (selectedCourse.getStudentsRegistered() + 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); student.setCurrentClass1(""); student.setCreditHours(student.getCreditHours() - 3); } else if (student.getCurrentClass2() == selectedCourse.getCourseId()) { SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass2 = '', creditcount = " + (student.getCreditHours() - 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("{0} successfully dropped", selectedCourse.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (selectedCourse.getStudentsRegistered() + 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); student.setCurrentClass2(""); student.setCreditHours(student.getCreditHours() - 3); } else if (student.getCurrentClass3() == selectedCourse.getCourseId()) { SqlCommand updateStudentInfo = new SqlCommand("UPDATE student SET currentclass3 = '', creditcount = " + (student.getCreditHours() - 3), clsDB.Get_DB_Connection()); updateStudentInfo.ExecuteNonQuery(); label3.Content = string.Format("{0} successfully dropped", selectedCourse.getCourseId()); SqlCommand updateClassNumber = new SqlCommand("UPDATE classes SET studentsRegistered = " + (selectedCourse.getStudentsRegistered() + 1), clsDB.Get_DB_Connection()); updateClassNumber.ExecuteNonQuery(); student.setCurrentClass3(""); student.setCreditHours(student.getCreditHours() - 3); } listBox.Items.Clear(); listBox.Items.Add(student.getCurrentClass1()); listBox.Items.Add(student.getCurrentClass2()); listBox.Items.Add(student.getCurrentClass3()); textBox.Text = student.getCreditHours().ToString(); }
//------------------------------ //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(); }
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { //changes the information displayed based on which course is selected for (int i = 0; i < comboBox.Items.Count; i++) { if (courses[i].getCourseId() == (string)comboBox.Items.CurrentItem) { course = courses[i]; string courseIdSelected = courses[i].getCourseId(); Course currentSelection = courses[i]; string courseDesc = currentSelection.getCourseDesc(); this.courseIdtxtblk.Text = currentSelection.getCourseId(); this.coursedesctxtblk.Text = courseDesc; this.seatsremainingtxtblk.Text = (currentSelection.getClassSize() - currentSelection.getStudentsRegistered()).ToString(); this.credithourstxtblk.Text = currentSelection.getCreditHours().ToString(); } } }