Exemple #1
0
        private void saveGradeButton_Click(object sender, EventArgs e)
        {
            Enrollment selectedEnrollment = (Enrollment)this.enrollmentsListBox.SelectedValue;
            Assignment selectedAssignment = (Assignment)this.assignmentsListBox.SelectedValue;

            if (selectedEnrollment != null && selectedAssignment != null)
            {
                AssignmentGrade grade = selectedEnrollment.FindAssignmentGrade(selectedAssignment.Assign);
                if (grade == null)
                {
                    short points = 0;
                    Int16.TryParse(this.pointsTextBox.Text, out points);
                    grade = new AssignmentGrade(points, DateTime.Now,
                                                selectedEnrollment, selectedAssignment);
                }
                else
                {
                    short points = 0;
                    Int16.TryParse(this.pointsTextBox.Text, out points);
                    grade.Points        = points;
                    grade.DateCompleted = DateTime.Now;
                }
                this.dbContext.SaveChanges();
            }
        }
Exemple #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.DisableEventHandlers();
            this.dbContext = new StudentInfoModelContainer();
            this.school    = this.dbContext.Schools.First();

            this.school.Departments = this.dbContext.Departments.ToList();
            this.departmentsDropDownList.DisplayMember = "DeptName";
            this.departmentsDropDownList.DataSource    = this.school.Departments;
            Department comc = this.school.FindDepartment("COMC");

            this.departmentsDropDownList.SelectedItem = comc;

            comc.Courses = this.dbContext.Courses.Where(c =>
                                                        c.Department.Id == comc.Id).ToList();
            this.coursesDropDownList.DisplayMember = "CourseTitle";
            this.coursesDropDownList.DataSource    = comc.Courses;
            Course comc2750 = comc.FindCourse("2750");

            this.coursesDropDownList.SelectedItem = comc2750;

            this.school.Terms = this.dbContext.Terms.ToList();
            this.termsDropDownList.DisplayMember = "DisplayString";
            this.termsDropDownList.DataSource    = this.school.Terms;
            Term spr2020 = this.school.FindTerm(2020, TermsEnum.Spr);

            this.termsDropDownList.SelectedItem = spr2020;

            comc2750.Sections = this.dbContext.Sections.Where(s =>
                                                              s.Course.Id == comc2750.Id &&
                                                              s.Term.Id == spr2020.Id).ToList();
            this.sectionsDropDownList.DisplayMember = "Id";
            this.sectionsDropDownList.DataSource    = comc2750.Sections;
            Section section2750 = comc2750.Sections.Last();

            this.sectionsDropDownList.SelectedItem = section2750;

            section2750.Assignments = this.dbContext.Assignments.Where(a =>
                                                                       a.Section.Id == section2750.Id).ToList();
            this.assignmentsListBox.DisplayMember = "DisplayString";
            this.assignmentsListBox.DataSource    = section2750.Assignments;

            section2750.Enrollments = this.dbContext.Enrollments.Include("Student").Where(enr =>
                                                                                          enr.Section.Id == section2750.Id).ToList();
            this.enrollmentsListBox.DisplayMember = "DisplayString";
            this.enrollmentsListBox.DataSource    = section2750.Enrollments;

            Enrollment      selectedEnrollment = (Enrollment)this.enrollmentsListBox.SelectedValue;
            Assignment      selectedAssignment = (Assignment)this.assignmentsListBox.SelectedValue;
            AssignmentGrade grade = this.dbContext.AssignmentGrades.Where(g =>
                                                                          g.Enrollment.Id == selectedEnrollment.Id &&
                                                                          g.Assignment.Id == selectedAssignment.Id).SingleOrDefault();

            this.pointsTextBox.Text = grade.Points.ToString();
            this.dateTextBox.Text   = grade.DateCompleted.ToShortDateString();

            this.EnableEventHandlers();
        }
        public AssignmentGrade FindAssignmentGrade(string assign)
        {
            AssignmentGrade foundGrade = null;

            foreach (AssignmentGrade g in this.AssignmentGrades)
            {
                if (g.Assignment.Assign == assign)
                {
                    foundGrade = g;
                    break;
                }
            }
            return(foundGrade);
        }
        public AssignmentGrade FindAssignmentGrade(int studentId)
        {
            AssignmentGrade foundGrade = null;

            foreach (AssignmentGrade g in this.AssignmentGrades)
            {
                if (g.Enrollment.Student.Id == studentId)
                {
                    foundGrade = g;
                    break;
                }
            }
            return(foundGrade);
        }
        private void assignmentsListBox_SelectedValueChanged(object sender, EventArgs e)
        {
            this.pointsTextBox.Text = "";
            this.dateTextBox.Text   = "";
            Enrollment selectedEnrollment = (Enrollment)this.enrollmentsListBox.SelectedItem;
            Assignment selectedAssignment = (Assignment)this.assignmentsListBox.SelectedItem;

            if (selectedEnrollment != null && selectedAssignment != null)
            {
                AssignmentGrade grade = this.dbContext.AssignmentGrades.Where(g =>
                                                                              g.Enrollment.Id == selectedEnrollment.Id &&
                                                                              g.Assignment.Id == selectedAssignment.Id).SingleOrDefault();
                if (grade != null)
                {
                    this.pointsTextBox.Text = grade.Points.ToString();
                    this.dateTextBox.Text   = grade.DateCompleted.ToShortDateString();
                }
            }
        }