Ejemplo n.º 1
0
 // Exercise 4: Task 5a: Enable a teacher to add a grade to a student
 private void AddGrade_Click(object sender, RoutedEventArgs e)
 {
     if (SessionContext.UserRole != Role.Teacher)
     {
         return;
     }
     try
     {
         GradeDialog gradeDialog = new GradeDialog();
         if (gradeDialog.ShowDialog().Value)
         {
             Grade grade = new Grade();
             grade.AssessmentDate = gradeDialog.assessmentDate.SelectedDate.ToString();
             grade.SubjectName    = gradeDialog.subject.Text;
             grade.Assessment     = gradeDialog.assessmentGrade.Text;
             grade.Comments       = gradeDialog.comments.Text;
             DataSource.Grades.Add(grade);
             SessionContext.CurrentTeacher.AddGrade(grade, SessionContext.CurrentStudent);
             this.Refresh();
         }
     }
     catch (ArgumentException exception)
     {
         MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        // TODO: Exercise 4: Task 5a: Enable a teacher to add a grade to a student
        private void AddGrade_Click(object sender, RoutedEventArgs e)
        {
            if (SessionContext.UserRole == Role.Teacher)
            {
                try
                {
                    GradeDialog gd = new GradeDialog();
                    if (gd.ShowDialog().Value)
                    {
                        Grade newGrade = new Grade(
                            SessionContext.CurrentStudent.StudentID
                            , gd.assessmentDate.SelectedDate.Value.ToString("d")
                            , gd.subject.SelectedValue.ToString()
                            , gd.assessmentGrade.Text
                            , gd.comments.Text);

                        DataSource.Grades.Add(newGrade);
                    }
                }
                catch (Exception ex)
                {
                    string message = $"Unable to save grade.\nError: {ex.InnerException}";
                    MessageBox.Show(message, "Exception caught");
                }

                Refresh();
            }
        }
        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
            {
                GradeDialog newGrade = new GradeDialog(); //New instance of GradeDialog.

                if (newGrade.ShowDialog().Value)          //Runs when the OK button is pressed.
                {
                    Grade studentGrade = new Grade        //Creates a new grade, with all the inserted values and the Student ID from SessionContext.
                    {
                        AssessmentDate = newGrade.assessmentDate.SelectedDate.Value,
                        SubjectId      = newGrade.subject.SelectedIndex,
                        Assessment     = newGrade.assessmentGrade.Text,
                        Comments       = newGrade.comments.Text,
                        StudentUserId  = SessionContext.CurrentStudent.UserId
                    };

                    SessionContext.DBContext.Grades.Add(studentGrade); //Adds the grade to the database.
                    SessionContext.DBContext.SaveChanges();            //Saves the changes to the database.

                    Refresh();                                         //Refreshes the display to showcase the new grade.
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error adding assessment grade", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 4
0
        // TODO: Exercise 4: Task 5a: Enable a teacher to add a grade to a student
        private void AddGrade_Click(object sender, RoutedEventArgs e)
        {
            if (SessionContext.UserRole != Role.Teacher)
            {
                return;
            }

            try
            {
                var dialog = new GradeDialog();
                if (dialog.ShowDialog() == true)
                {
                    var grade = new Grade()
                    {
                        Assessment     = dialog.assessmentGrade.Text,
                        AssessmentDate = dialog.assessmentDate.Text,
                        Comments       = dialog.comments.Text,
                        StudentID      = SessionContext.CurrentStudent.StudentID,
                        SubjectName    = dialog.subject.Text
                    };
                    DataSource.Grades.Add(grade);
                    SessionContext.CurrentStudent.AddGrade(grade);
                    Refresh();
                }
            }
            catch (Exception)
            {
                throw new ArgumentException("Could not add grade to student.");
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        //添加学生成绩
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                return;
            }
            var r = dataGridView1.CurrentRow.Cells;

            using (GradeDialog addgrade = new GradeDialog(teacher,
                                                          Convert.ToInt32(r[3].Value),
                                                          Convert.ToInt32(r[0].Value),
                                                          r[1].Value as string,
                                                          Convert.ToSingle(r[4].Value as string),
                                                          Convert.ToSingle(r[5].Value as string),
                                                          Convert.ToSingle(r[6].Value as string)
                                                          ))
                addgrade.ShowDialog();
            if (toolStripComboBox3.Text.Trim() != "")
            {
                string    option = " AND " + Convert.ToString(dataGridView1.CurrentRow.Cells[3].Value) + " = classId ";
                DataTable t      = GradeManager.SelectDifferentGrade(teacher.Id, option);
                t.Columns[0].ColumnName  = "学号";
                t.Columns[1].ColumnName  = "姓名";
                t.Columns[2].ColumnName  = "学院";
                t.Columns[3].ColumnName  = "课程编号";
                t.Columns[4].ColumnName  = "平时成绩";
                t.Columns[5].ColumnName  = "期末成绩";
                t.Columns[6].ColumnName  = "总成绩";
                dataGridView1.DataSource = t;
            }
            else
            {
                RefreshClassTable();
            }
        }
        private void AddGrade_Click(object sender, RoutedEventArgs e)
        {
            if (SessionContext.UserRole != Role.Teacher)        //Makes the button do nothing if a Student clicks on it, since it returns immediately when the role is not a Teacher.
            {
                return;
            }

            try
            {
                GradeDialog gd = new GradeDialog();

                if (gd.ShowDialog().Value)
                {
                    Grade newGrade = new Grade();       //Creates a new Grade object and stores (and converts if necessary) the new grades in it.
                    newGrade.AssessmentDate = gd.assessmentDate.SelectedDate.Value.ToString("d");
                    newGrade.SubjectName    = gd.subject.SelectedValue.ToString();
                    newGrade.Assessment     = gd.assessmentGrade.Text;
                    newGrade.Comments       = gd.comments.Text;

                    DataSource.Grades.Add(newGrade);                  //Adds the grade to the DataSource list.

                    SessionContext.CurrentStudent.AddGrade(newGrade); //Saves the newly added grade to the current student.

                    Refresh();                                        //Execute the Refresh method so the added grade appears.
                }
            }
            catch (Exception ex)        //Whenever an unexpected error occurs when adding a grade.
            {
                MessageBox.Show(ex.Message, "There was an error adding the grade to this student.", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void AddGrade_Click(object sender, RoutedEventArgs e)
        {
            if (SessionContext.UserRole != Role.Teacher)
            {
                return;
            }

            try
            {
                var gd = new GradeDialog();

                if (gd.ShowDialog().Value)
                {
                    var newGrade = new Grade
                    {
                        AssessmentDate = gd.assessmentDate.SelectedDate.Value.ToString("d"),
                        SubjectName    = gd.subject.SelectedValue.ToString(),
                        Assessment     = gd.assessmentGrade.Text,
                        Comments       = gd.comments.Text
                    };

                    DataSource.Grades.Add(newGrade);

                    SessionContext.CurrentStudent.AddGrade(newGrade);

                    Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error adding assessment grade", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 9
0
        // TODO: Exercise 4: Task 5a: Enable a teacher to add a grade to a student
        private void AddGrade_Click(object sender, RoutedEventArgs e)
        {
            if (SessionContext.UserRole == Role.Teacher)
            {
                try
                {
                    GradeDialog gd          = new GradeDialog();
                    Grade       addingGrade = new Grade();

                    addingGrade.AssessmentDate = gd.assessmentDate.ToString();
                    addingGrade.SubjectName    = gd.subject.Text;
                    addingGrade.Assessment     = gd.assessmentGrade.ToString();
                    addingGrade.Comments       = gd.comments.ToString();

                    DataSource.Grades.Add(addingGrade);

                    SessionContext.CurrentStudent.AddGrade(addingGrade);
                    Refresh();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                return;
            }
        }
        private async void handleClickAddGrade(object sender, RoutedEventArgs e)
        {
            Module module        = (Module)((Button)sender).DataContext;
            var    gradeDialog   = new GradeDialog(new Grade(), module.id, GradeDialog.GradeDialogMode.CREATE);
            var    buttonClicked = await gradeDialog.ShowAsync();

            module.grades.Add(gradeDialog.result);

            if (buttonClicked == ContentDialogResult.Primary)
            {
                this.learningUnit = await PsApi.getInstance().getLearningUnitAsync(this.learningUnit.id);

                this.modules.Clear();
                this.learningUnit.modules.ForEach(modules.Add);
            }
        }
Ejemplo n.º 11
0
        //If the grading button is clicked on a student's assignment
        private void gradingButton_Clicked(object sender, RoutedEventArgs e)
        {
            //Get the assignment
            var    item       = (sender as FrameworkElement).Tag as Assignment;
            string gradeInput = "";

            //Show the grade dialog and fetch the result
            GradeDialog gradeDialog = new GradeDialog("Please assign new grade (leave blank to unassign)");

            if (gradeDialog.ShowDialog() == true)
            {
                gradeInput = gradeDialog.Answer;
            }

            //Submit the new result
            viewModel.NewResult(item, gradeInput);

            RefreshBindings();
        }
        private async void handleClickUpdateGrade(object sender, RoutedEventArgs e)
        {
            Grade grade         = (Grade)((Button)sender).DataContext;
            var   gradeDialog   = new GradeDialog(grade, grade.id, GradeDialog.GradeDialogMode.EDIT);
            var   buttonClicked = await gradeDialog.ShowAsync();

            if (buttonClicked == ContentDialogResult.Primary)
            {
                Module module = modules.FirstOrDefault(m => m.grades.Select(g => grade.id).Contains(grade.id));
                grade.name        = gradeDialog.result.name;
                grade.coefficient = gradeDialog.result.coefficient;
                grade.score       = gradeDialog.result.score;
                module.grades.Remove(grade);
                module.grades.Add(grade);

                var index = this.modules.IndexOf(module);
                modules.RemoveAt(index);
                modules.Insert(index, module);
            }
        }
Ejemplo n.º 13
0
        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
            {
                // Use the GradeDialog to get the details of the assessment grade
                GradeDialog gd = new GradeDialog();

                // Display the form and get the details of the new grade
                if (gd.ShowDialog().Value)
                {
                    // 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
                    Grade newGrade = new Grade();
                    newGrade.AssessmentDate = gd.assessmentDate.SelectedDate.Value.ToString("d");
                    newGrade.SubjectName    = gd.subject.SelectedValue.ToString();
                    newGrade.Assessment     = gd.assessmentGrade.Text;
                    newGrade.Comments       = gd.comments.Text;

                    // Save the grade to the list of grades
                    DataSource.Grades.Add(newGrade);

                    // Add the grade to the current student
                    SessionContext.CurrentStudent.AddGrade(newGrade);

                    // Refresh the display so that the new grade appears
                    Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error adding assessment grade", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 14
0
        //增加修改成绩
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                return;
            }
            var r = dataGridView1.CurrentRow.Cells;

            using (GradeDialog addgrade = new GradeDialog(GetSelectedTeacher(),
                                                          Convert.ToInt32(r[3].Value),
                                                          Convert.ToInt32(r[0].Value),
                                                          r[1].Value as string,
                                                          Convert.ToSingle(r[4].Value as string),
                                                          Convert.ToSingle(r[5].Value as string),
                                                          Convert.ToSingle(r[6].Value as string)
                                                          ))
                addgrade.ShowDialog();
            string option = "";

            if (toolStripComboBox3.Text.Trim() != "")
            {
                option = " AND " + Convert.ToInt32(toolStripComboBox3.Text.Trim()) + " = teacherId ";
                DataTable dt = AdminManager.DisplayAllStuGra(option);
                dt.Columns[0].ColumnName = "课程编号";
                dt.Columns[1].ColumnName = "学生ID";
                dt.Columns[2].ColumnName = "学生姓名";
                dt.Columns[3].ColumnName = "学院";
                dt.Columns[4].ColumnName = "平时成绩";
                dt.Columns[5].ColumnName = "期末成绩";
                dt.Columns[6].ColumnName = "总成绩";
                dataGridView1.DataSource = dt;
            }
            else
            {
                RefreshClassTable();
            }
        }