/* * Method: GenerateAllClassessGridData * Areguments: none * Return: none * Des: this method is to fill the all classes GridView with data */ protected void GenerateAllClassessGridData() { DataTable table = new DataTable(); // create data table object // add the table columns table.Columns.Add("Course Id"); table.Columns.Add("Section Id"); table.Columns.Add("Course Title"); table.Columns.Add("Location"); table.Columns.Add("Time"); table.Columns.Add("Date"); table.Columns.Add("Instructor Name"); foreach (Schedule schedule in scheduleList.List) { /* foreach element in the scheduleList */ sectionsList.Filter("SectionID", schedule.SectionID); // filter the sectionList with sectionID Section section = (Section)sectionsList.List.ElementAt(0); // get the first element in the list and cast it to ( section ) taughtList.Filter("TaughtCourseID", section.TaughtCourseID); // filter the taughtCourseList with taughtcourseID from the section object TaughtCourse taughtcourse = (TaughtCourse)taughtList.List.ElementAt(0); // get the first element in the list and cast it to ( TaughtCourse ) courseList.Filter("CourseID", taughtcourse.CourseID); //filter the CoursList with courseID from taughCourse object Course course = (Course)courseList.List.ElementAt(0); // get the first element in the list and cast it to ( Course ) locationList.Filter("LocationID", schedule.LocationID); // filter the locationList with locationID from the section object Location location = (Location)locationList.List.ElementAt(0); // get the first element in the list and cast it to ( Location ) instructorList.Filter("InstructorID", section.InstructorID); // filter the instructorList with the instructorID from section object Instructor instructor = (Instructor)instructorList.List.ElementAt(0); // get the first element in the list and cast it to ( Instructor ) table.Rows.Add(taughtcourse.CourseID, section.getID(), course.Title, location.Name, schedule.Time, schedule.Day, instructor.FirstName + " " + instructor.LastName); // add information as row to the table object } allclassListGrid.DataSource = table; // set table as the dataSource of the grid view allclassListGrid.DataBind(); // bind the data }
/* * Method: GenerateGridData * Areguments: none * Return: none * Des: this method is to fill the GridView with data */ protected void GenerateGridData() { DataTable table = new DataTable(); // declare and instantiate DataTable object /* * Add Columns to the data table */ table.Columns.Add("Course Id"); table.Columns.Add("Section Id"); table.Columns.Add("Course Title"); table.Columns.Add("Location"); table.Columns.Add("Time"); table.Columns.Add("Date"); table.Columns.Add("Instructor Name"); foreach (Schedule schedule in scheduleList.List) { /* * Foreach Element in the scheduleList */ sectionsList.Filter("SectionID", schedule.SectionID); // filter the sectionList using the section id from the element of scheduleList Section section = (Section)sectionsList.List.ElementAt(0); // get the section object from the sectionList taughtList.Filter("TaughtCourseID", section.TaughtCourseID); // filter the taughtCourseList usign the taughtCourse id from the section object TaughtCourse taughtcourse = (TaughtCourse)taughtList.List.ElementAt(0); // get the taughtCourse object from the list courseList.Filter("CourseID", taughtcourse.CourseID); //filter the courseList using the CourseId from the taughtCourse object Course course = (Course)courseList.List.ElementAt(0); // get the course object fom the couseList locationList.Filter("LocationID", schedule.LocationID); //filter the locationList using the location id from the element Location location = (Location)locationList.List.ElementAt(0); // get location object instructorList.Filter("InstructorID", section.InstructorID); // filter the instructor id form the Instructor instructor = (Instructor)instructorList.List.ElementAt(0); // get the instructor object form the instructorList table.Rows.Add(taughtcourse.CourseID, section.getID(), course.Title, location.Name, schedule.Time, schedule.Day, instructor.FirstName + " " + instructor.LastName); // add a row to the dataTable object with the information from the above objects } classListGrid.DataSource = table; // set the dataTable object as the dataSource of the GidView element classListGrid.DataBind(); // bind the data }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["cls"] == null) { /* check if there is no query string then */ Response.Write("Error No class requested"); // show error message Response.End(); // stop page excution } else { sectionList = new SectionList(); // this is needed to check if the section id is valid so we instantiate it before the rest sectionList.Filter("SectionID", Request.QueryString["cls"]); // filter the section with the section id to check if the section id exist } /* * check if the user session exist and Account session value is Instructor and the sectionID is valid */ if (Session["User"] != null && Session["Account"].ToString() == "Instructor" && sectionList.List.Count != 0) { /* * instantiate classes when the page loads */ sectionStudentList = new SectionStudentList(); studentList = new StudentList(); taughtCoursesList = new TaughtCourseList(); courseList = new CourseList(); sectionId = Request.QueryString["cls"]; // get the section id passed in the page url and assign it to secionId var sectionList.Filter("SectionID", sectionId); // filter the sectionList with the sectionID section = (Section)sectionList.List.ElementAt(0); // get the first element in the list and cast it to (Section) taughtCoursesList.Filter("TaughtCourseID", section.TaughtCourseID); // filter the taughtCoursesList with the TaughtCourseID taughtCourses = (TaughtCourse)taughtCoursesList.List.ElementAt(0); // get the first element in the list and cast it to (TaughtCourse) course = new Course(); // create new Course object course.setID(taughtCourses.CourseID.ToString()); // set the id of the course object to the value from the taughtCourse object courseList.Populate(course); //populate object sectionStudentList.Filter("SectionID", sectionId); //filter the sectionstudentList with sectionId SectionIdLbl.Text = section.getID(); // set the sectionLable text to the section id CourseID.Text = taughtCourses.CourseID; // set the courseid lable text to the course id CourseName.Text = course.Title; // set courseName lable text to the course title GenerateTable(); // call GenerateTable method to fill the grid view with data } else if (Session["User"] != null && Session["Account"].ToString() != "Instructor") { /* * else if the user session exist but the account session value is not student show error message */ Response.Write("Error You are not allowed to be here"); // show error message Response.End(); // stop page excution } else if (Session["User"] != null && Session["Account"].ToString() == "Instructor" && sectionList.List.Count == 0) { /* else if the user session exist and Account session value is Instructor and the sectionID is not valid */ Response.Write("Error Class not found"); // show error message Response.End(); // stop page excution } else { /* * else show error message */ Response.Write("Error please log in before trying to Access this page..!"); // show error message Response.End(); // stop page excution } }