コード例 #1
0
        // Loads all the data into the page
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "Course Management";

            if (!IsPostBack)
            {
                try
                {
                    // Shows all the courses as none was selected
                    if (!string.IsNullOrEmpty(Request.QueryString["course"]))
                    {
                        selectedCourse              = courseController.FindCourseById(int.Parse(Request.QueryString["course"]));
                        enrollmentCount             = courseController.GetAllEnrollmentsForCourseAndBindToRepeater(selectedCourse, ref StudentsEnrolledRepeater);
                        unenrollmentCount           = courseController.GetAllNotEnrolledStudentsForCourseAndBindToRepeater(selectedCourse, ref StudentsUnenrolledRepeater);
                        ViewState["SelectedCourse"] = selectedCourse;

                        if (!string.IsNullOrEmpty(Request.QueryString["unenrolledFirstName"]) && !string.IsNullOrEmpty(Request.QueryString["unenrolledLastName"]))
                        {
                            ShowSuccessMessage(string.Format("Student {0}, {1} successfully unenrolled from the {2} course.", Request.QueryString["unenrolledLastName"], Request.QueryString["unenrolledFirstName"], selectedCourse.Title));
                        }
                        else if (!string.IsNullOrEmpty(Request.QueryString["enrolledFirstName"]) && !string.IsNullOrEmpty(Request.QueryString["enrolledLastName"]))
                        {
                            ShowSuccessMessage(string.Format("Student {0}, {1} successfully enrolled int the {2} course.", Request.QueryString["enrolledLastName"], Request.QueryString["enrolledFirstName"], selectedCourse.Title));
                        }
                    }
                    // Shows the selected course
                    else
                    {
                        departmentController.GetAllDepartmentsAndBindToDropDownList(ref CourseDepartmentDropDown);
                        courseController.GetAllCoursesAndBindToRepeater(ref CoursesRepeater);
                    }
                }
                catch (DatabaseException ex)
                {
                    ShowErrorMessage(ex.Message);
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("The system failed with the following message: " + ex.Message);
                }
            }
        }