/// <summary> /// Handles click event for add student to course button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { while (lvwStudentsNotInCourse.SelectedItems.Count > 0) { ListViewItem item = lvwStudentsNotInCourse.SelectedItems[0]; lvwStudentsNotInCourse.Items.Remove(item); //remove from list lvwStudentsInCourse.Items.Add(item); //add to list //make changes in database UserData studentToAdd = (UserData)item.Tag; CourseController.AddUser(GlobalData.currentCourse, studentToAdd); } }
/// <summary> /// handles add course button click. allows user to add a new course. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addToolStripMenuItem_Click(object sender, EventArgs e) { //prompt user for name of new course string courseName = ""; var result = HelperUI.InputBox("New Course", "Enter name of course", ref courseName); //if user selected okay if (result == DialogResult.OK) { //add to database CourseData courseToAdd = new CourseData(); courseToAdd.Name = courseName; CourseController.SaveCourse(courseToAdd); CourseController.AddUser(courseToAdd, GlobalData.currentUser); //add to list ListViewItem item = lvwCourses.Items.Add(courseToAdd.Name, 0); item.Tag = courseToAdd; } }