private void AddGrade_Click(object sender, RoutedEventArgs e)
        {
            // If the user is not a teacher, do nothing (the button should not appear anyway)
            if (SessionContext.UserRole != Role.Teacher)
            {
                return;
            }

            try
            {
                // TODO: Exercise 2: Task 3a: Use the GradeDialog to get the details of the new grade.
                // TODO: Exercise 2: Task 3b: Display the form and get the details of the new grade.
                // TODO: Exercise 2: Task 3c: When the user closes the form, retrieve the details of the assessment grade from the form
                // and use them to create a new Grade object.
                // TODO: Exercise 2: Task 3d: Save the grade.
                // TODO: Exercise 2: Task 3e: Refresh the display so that the new grade appears
                GradeDialog gd = new GradeDialog();
                if (gd.ShowDialog().Value)
                {
                    Grades.DataModel.Grade newGrade = new Grades.DataModel.Grade();
                    newGrade.AssessmentDate = gd.assessmentDate.SelectedDate.Value;
                    newGrade.SubjectId      = gd.subject.SelectedIndex;
                    newGrade.Assessment     = gd.assessmentGrade.Text;
                    newGrade.Comments       = gd.comments.Text;
                    newGrade.StudentUserId  = SessionContext.CurrentStudent.UserId;
                    SessionContext.DBContext.Grades.Add(newGrade);
                    SessionContext.Save();
                    Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error adding assessment grade", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        // If the user clicks OK to save the Grade details, validate the information that the user has provided
        private void ok_Click(object sender, RoutedEventArgs e)
        {
            // Data validation functionality to be added in Exercise 3
            try
            {
                Grades.DataModel.Grade newGrade = new Grades.DataModel.Grade();
                testGrade.ValidateAssessmentDate(assessmentDate.SelectedDate.Value);
                testGrade.ValidateAssessmentGrade(assessmentGrade.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error creating assessment", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Indicate that the data is valid
            this.DialogResult = true;
        }
示例#3
0
        // If the user clicks OK to save the Grade details, validate the information that the user has provided
        private void ok_Click(object sender, RoutedEventArgs e)
        {
            // Create a Grade object and use it to trap and report any data validation exceptions that are thrown
            try
            {
                Grades.DataModel.Grade testGrade = new Grades.DataModel.Grade();

                object p = testGrade.ValidateAssessmentDate(assessmentDate.SelectedDate.Value);
                testGrade.ValidateAssessmentGrade(assessmentGrade.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error creating assessment", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Indicate that the data is valid
            this.DialogResult = true;
        }