public void ViewStudents_Apply(object sender, EventArgs args) { //If row not selected, return if (!dgvStudentView.SelectedRow()) { MessageBox.Show("Please select a row."); return; } //Get the student course of selected student Course_Schedule schedule = lcSchedules[cbCourses.SelectedIndex]; User student = lcStudents[dgvStudentView.SelectedRowIndex()]; Student_Course sCourse = student.GetStudentCourse(schedule); //Update sCourse.Grade = cbGrade.Text; sCourse.ModifiedDateTime = DateTime.Now; SharedManager.Update(sCourse, s => s.Grade, s => s.ModifiedDateTime); //Show message MessageBox.Show("Grade updated successfully", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); //Refresh grid view ViewStudents_Refresh(); }
public static List <Student_Course> GetStudentCourses(this Course_Schedule context) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Student_Course.Where(sc => sc.IsActive && sc.CourseSchedule_ID.Equals(context.CourseSchedule_ID)).ToList()); } }
public static bool Create(Course_Schedule source) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { try { Course_Schedule schedule = new Course_Schedule(); schedule.Course_ID = source.Course_ID; schedule.CreatedBy = source.CreatedBy; schedule.CreatedDateTime = DateTime.Now; schedule.DT_From = source.DT_From; schedule.DT_To = source.DT_To; schedule.IsActive = true; schedule.ModifiedBy = source.ModifiedBy; schedule.ModifiedDateTime = DateTime.Now; schedule.Teacher_ID = source.Teacher_ID; dbContext.Course_Schedule.Add(schedule); dbContext.SaveChanges(); } catch (Exception) { return(false); } } return(true); }
public static User GetTutor(this Course_Schedule context) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Users.FirstOrDefault(t => t.User_ID.Equals(context.Teacher_ID) && t.IsActive)); } }
public static List <Course_Schedule> GetSchedulesOf(User user, RoleTypes roleType) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { //Check role type if (roleType == RoleTypes.Student) { //Find all student course object with the user's id var selections = dbContext.Student_Course.Where(sc => sc.User_ID.Equals(user.User_ID) && sc.IsActive); //Convert student_course to course_schedule List <Course_Schedule> courseSchedules = new List <Course_Schedule>(); foreach (Student_Course sc in selections) { Course_Schedule cs = sc.GetSchedule(); if (cs != null) { courseSchedules.Add(cs); } } //Return the list return(courseSchedules); } else { //Return all course_schedules where its teacher_id equals the given user's id. var selections = dbContext.Course_Schedule.Where(s => s.Teacher_ID.Equals(user.User_ID) && s.IsActive); return(selections.ToList()); } } }
public static Course GetCourse(this Course_Schedule context) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Courses.FirstOrDefault(c => c.Course_ID.Equals(context.Course_ID) && c.IsActive)); } }
public static Student_Course GetStudentCourse(this User context, Course_Schedule schedule) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Student_Course.FirstOrDefault(sc => sc.IsActive && sc.User_ID.Equals(context.User_ID) && sc.CourseSchedule_ID.Equals(schedule.CourseSchedule_ID))); } }
public void Add(object sender, EventArgs args) { #region Validate inputs if (cbCourse.SelectedItem == null) { MessageBox.Show("Selected course is empty."); return; } if (cbTutor.SelectedItem == null) { MessageBox.Show("Selected tutor is empty."); return; } #endregion //Create new schedule object Course_Schedule schedule = new Course_Schedule(); schedule.Course_ID = lcCourses[cbCourse.SelectedIndex].Course_ID; schedule.DT_From = dtpStart.Value; schedule.DT_To = dtpEnd.Value; schedule.CreatedBy = GlobalApplication.cMyUser.User_ID; schedule.ModifiedBy = GlobalApplication.cMyUser.User_ID; schedule.Teacher_ID = lcTutors[cbTutor.SelectedIndex].User_ID; ScheduleManager.Create(schedule); MessageBox.Show("Schedule has been successfully added."); //Close this.Close(); }
public static bool IsEnrolled(this User context, Course_Schedule schedule) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Student_Course.FirstOrDefault(c => c.IsActive && c.CourseSchedule_ID.Equals(schedule.CourseSchedule_ID) && c.User_ID.Equals(context.User_ID)) != null); } }
public void ManageSchedule_Delete(object sender, EventArgs args) { //Return if no cell is selected if (!SelectedRow()) { MessageBox.Show("Select a schedule first."); return; } //Confirm if user wants to delete this record if (MessageBox.Show("Are you sure you want to delete this schedule?", "Deleting Schedule", MessageBoxButtons.YesNo) == DialogResult.Yes) { //Get the selected schedule info Course_Schedule selection = lcSchedules[SelectedRowIndex()]; //Delete this selection selection.IsActive = false; SharedManager.Update(selection, s => s.IsActive); //Refresh RefreshGridView(); MessageBox.Show("Deleted schedule."); } }
public void FillGridView() { //Get all schedules lcSchedules = ScheduleManager.GetAllSchedules(); //For each entry, add to data grid view for (int i = 0; i < lcSchedules.Count; i++) { Course_Schedule curSchedule = lcSchedules[i]; Course curCourse = curSchedule.GetCourse(); User curTutor = curSchedule.GetTutor(); dgvSchedules.Rows.Add(curSchedule.CourseSchedule_ID, curCourse.Course_Name, curTutor.FullName, curSchedule.DT_From, curSchedule.DT_To); } dgvSchedules.Refresh(); }
public void FillLabels(int index) { //Selection Course curCourse = lcCourses[index]; Course_Schedule curSchedule = lcSchedules[index]; Student_Course curStudentCourse = GlobalApplication.cMyUser.GetStudentCourse(curSchedule); //Set label text lbCourseName.Text = curCourse.Course_Name; lbCourseCode.Text = curCourse.Course_Code; lbGrade.Text = curStudentCourse.Grade; lbTutorName.Text = curSchedule.GetTutor().FullName; lbTutorEmail.Text = curSchedule.GetTutor().Email; lbStartDate.Text = curSchedule.DT_From.ToString(); lbFinishDate.Text = curSchedule.DT_To.ToString(); lbDescription.Text = curCourse.Course_Description; }
public static List <User> GetStudents(this Course_Schedule context) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { //This holds student_courses of all students booked on this course_schedule. var firstSelection = dbContext.Student_Course.Where(s => s.CourseSchedule_ID.Equals(context.CourseSchedule_ID) && s.IsActive); List <User> students = new List <User>(); foreach (Student_Course sc in firstSelection) { User user = sc.GetStudent(); if (user != null) { students.Add(user); } } return(students); } }
public void ManageCourse_Delete(object sender, EventArgs args) { //Return if no selection if (!dgvCourses.SelectedRow()) { MessageBox.Show("Please select a course."); return; } //Confirm first if (MessageBox.Show("Are you sure you want to delete this course?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //Select the target course Course course = lcCourses[dgvCourses.SelectedRowIndex()]; //Disable it course.IsActive = false; SharedManager.Update(course, c => c.IsActive); //Disable all schedules associated with this course List <Course_Schedule> schedules = course.GetSchedules(); for (int i = 0; i < schedules.Count; i++) { Course_Schedule cs = schedules[i]; cs.IsActive = false; SharedManager.Update(cs, x => x.IsActive); //Disable all student courses associated with this schedule List <Student_Course> studentCourses = cs.GetStudentCourses(); for (int j = 0; j < studentCourses.Count; j++) { Student_Course sc = studentCourses[j]; sc.IsActive = false; SharedManager.Update(sc, x => x.IsActive); } } MessageBox.Show("Course deleted successfully."); RefreshCourse(); } }