コード例 #1
0
 protected void SubmitGrades_Click(object sender, EventArgs e)
 {
     // Take the form's data and send it to the BLL for processing
     // The .TryRun will process the anonymous method inside a try block & report any errors.
     MessageUserControl.TryRun(() =>
     {
         // 1) Gather form data
         var course        = CourseDropDown.SelectedValue;
         var assignment    = AssignmentDropDown.SelectedValue;
         var studentGrades = new List <AssignedGrade>();
         // 1.a) Get the data from the ListView
         int possible;
         if (!int.TryParse(PossibleMarks.Text, out possible))
         {
             throw new Exception("You must enter a number for possible marks.");
         }
         foreach (ListViewDataItem item in StudentMarkListView.Items)
         {
             // Get a reference to the controls in the <ItemTemplate> that hold the data
             var markTextBox = item.FindControl("EarnedMarksTextBox") as TextBox;
             var idLabel     = item.FindControl("StudentIDLabel") as Label;
             // Don't assume! Check that the controls were actually found before using them
             if (markTextBox != null && idLabel != null)
             {
                 double mark;
                 int id;
                 if (!double.TryParse(markTextBox.Text, out mark))
                 {
                     throw new Exception("You can only enter numbers for the student grade");
                 }
                 if (!int.TryParse(idLabel.Text, out id))
                 {
                     throw new Exception("Stop hacking the code-behind on the form");
                 }
                 var grade = new AssignedGrade
                 {
                     EarnedMarks   = mark,
                     StudentID     = id,
                     PossibleMarks = possible
                 };
                 studentGrades.Add(grade);
             }
             else
             {
                 throw new Exception("Programmer, check your code!");
             }
         }
         // 2) Send to BLL
         var controller = new StudentGradesController();
         controller.ProcessMarks(course, assignment, studentGrades);
     }, "Grades Processed", "Grades were sent. Beyond that, I don't know what they did with them");
 }
コード例 #2
0
        // Final processing for this page to add courses to our system.
        protected void AddCourse_Click(object sender, EventArgs e)
        {
            MessageUserControl.TryRun(() =>
            {
                // 1) Extract the data from the form
                DateTime start;
                DateTime.TryParse(StartsOn.Text, out start);
                var courseInfo = new CourseOffering(CourseName.Text, start);

                RetrieveAssignments();

                // 2) Send the data to the BLL for processing
                var controller = new StudentGradesController();
                controller.CreateCourse(courseInfo, 7, Assignments);
                Courses.DataBind();
            }, "Course Added", $"Successfully added the {CourseName.Text} course");
        }
コード例 #3
0
 protected void CourseDropDownList_SelectedIndexChanged(object sender, EventArgs e)
 {
     // Take the info from this drop-down and use it to get data for the next drop-down
     if (CourseDropDownList.SelectedIndex > 0)
     {
         var controller = new StudentGradesController();
         AssignmentDropDownList.DataSource     = controller.ListAssignments(CourseDropDownList.SelectedValue);
         AssignmentDropDownList.DataTextField  = nameof(AssignmentInfo.Description);
         AssignmentDropDownList.DataValueField = nameof(AssignmentInfo.Name);
         AssignmentDropDownList.DataBind();
         AssignmentDropDownList.Items.Insert(0, "[Select an assignment]");
     }
     else
     {
         // Clear out my second drop-down
         AssignmentDropDownList.Items.Clear();
     }
 }
コード例 #4
0
        protected void Courses_SelectedIndexChanged(object sender, EventArgs e)
        {
            // our chance to do something AFTER the change takes place
            GridViewEventInfo.Text += $"Changed Event - {Courses.SelectedDataKey.Value}<br />";
            GridViewEventInfo.Text += "<ul>";
            foreach (var item in Courses.SelectedDataKey.Values.Values)
            {
                GridViewEventInfo.Text += $"<li>{item}</li>";
            }
            GridViewEventInfo.Text += "</ul>";

            // Our actual processing of getting the students based on our "data key" values
            string courseName   = Courses.SelectedDataKey[nameof(CourseSummary.CourseName)].ToString();
            string startingDate = Courses.SelectedDataKey[nameof(CourseSummary.StartDate)].ToString();

            // $"" is called String Interpolation
            GridViewEventInfo.Text += $"-{courseName}-{startingDate}-";

            var controller    = new StudentGradesController();
            var classListData = controller.ListStudentsInClass(courseName, DateTime.Parse(startingDate));

            ClassListRepeater.DataSource = classListData;
            ClassListRepeater.DataBind();
        }