protected void Page_Load(object sender, EventArgs e) { if (Session["User"] != null && Session["Account"].ToString() == "Student") { /* * check if the user session exist and Account session value is student */ /* * instantiate classes when the page loads */ sectionList = new SectionList(); sectionStudentList = new SectionStudentList(); studentList = new StudentList(); taughtCoursesList = new TaughtCourseList(); courseList = new CourseList(); instructorList = new InstructorList(); string studentID = Session["User"].ToString(); //declare , get the id of the student from the session and assign it to variable sectionStudentList.Filter("StudentID", studentID); // filter the section student list using the studentID GenerateGridData(); //call GenerateGridData method to add data to the gridView } else if (Session["User"] != null && Session["Account"].ToString() != "Student") { /* * 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"); Response.End(); } else { /* * else show error message */ Response.Write("Error please log in before trying to Access this page..!"); Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["User"] != null && Session["Account"].ToString() == "Student") { /* * check if the user session exist and Account session value is student */ /* * instantiate classes when the page loads */ scheduleList = new ScheduleList(); SectionList = new SectionList(); SectionStudentList = new SectionStudentList(); taughtCoursesList = new TaughtCourseList(); courseList = new CourseList(); id = Session["User"].ToString(); //get the id of the student from the session and assign it to variable SectionStudentList.Filter("StudentID", id); // filter the sectionstudentList usign the student id GenerateGridView(); // call the GenerateGridView method to fill the gridView element with data } else if (Session["User"] != null && Session["Account"].ToString() != "Student") { /* * 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"); Response.End(); } else { /* * else show error message */ Response.Write("Error please log in before trying to Access this page..!"); Response.End(); } }
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 } }
protected void EnrollMeBtn_Click(object sender, EventArgs e) { /* * This method is called when enroll me button is clicked */ /* * Declare variables and classes and instantiate them */ bool exist = false; bool alreadyExist = false; string scheduleID = ""; GridViewRow row = classListGrid.SelectedRow; // get the selected gidview row string sectionId = row.Cells[2].Text.ToString(); // get the section id string studentID = Session["User"].ToString(); // assign the student id from User session Section section = new Section(sectionId); sectionsList.Populate(section); // populate the section object Student student = new Student(studentID); studentList.Populate(student); // populate the student object // get the total hours of the student //int totalHours = scheduleList.TotalValue("Duration", "Section", "Schedule.SectionID", "Section.SectionID", "SectionStudent", "Section.SectionID", "SectionStudent.SectionID", "StudentID", student.getID()); //get the total hours of the student //This line calls the new total value with the less parameters int totalHours = scheduleList.TotalValue("Duration", "Section", "SectionID", "SectionID", "SectionStudent", "StudentID", student.getID()); int sectionTotalHours = scheduleList.TotalValue("Duration", "SectionID", sectionId); // get the total hours of the section per week if (totalHours < 20) // check if the student registerd hours are less than 20 hours { if (totalHours + sectionTotalHours > 20) { /* * if the section hours and student registerd hours are more than 20 hours then display error message in a popup * */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('You can't SignUP for more than 20 hours !')", true); } else { scheduleList.Filter("SectionID", section.getID()); // filter schedual list by the sectionId taken from the section object foreach (Schedule schedule in scheduleList.List) { /* forEach element in the scheduleList */ // exist = scheduleList.Exist("Section", "Schedule.SectionID", "Section.SectionID", "SectionStudent", "Section.SectionID", "SectionStudent.SectionID", "Day", schedule.Day, "Time", schedule.Time, "StudentID", student.getID()); //check if the student has a class in that day and time -- //this is the 12 parameter method exist = scheduleList.Exist("Section", "SectionID", "SectionID", "SectionStudent", "Day", schedule.Day, "Time", schedule.Time, "StudentID", student.getID()); //check if the student has a class in that day and time -- this is the less parameters method scheduleID = schedule.getID(); // get the schedule id while (Convert.ToInt32(schedule.Duration) > 1 && !exist) { /* * while schedual duration more than 1 and the exit var is false */ int newTime = Convert.ToInt32(schedule.Time) + 1; // get the new time by the adding 1 to the schedule time schedule.Time = newTime.ToString(); // assign the new time to the schedule object time // exist = scheduleList.Exist("Section", "Schedule.SectionID", "Section.SectionID", "SectionStudent", "Section.SectionID", "SectionStudent.SectionID", "Day", schedule.Day, "Time", schedule.Time, "StudentID", student.getID()); //check if the student has a class in that day and time -- //this is the 12 parameter method exist = scheduleList.Exist("Section", "SectionID", "SectionID", "SectionStudent", "Day", schedule.Day, "Time", schedule.Time, "StudentID", student.getID()); //check if the student has a class in that day and time -- this is the less parameters method int duration = Convert.ToInt32(schedule.Duration) - 1; // decrease the duration by 1 schedule.Duration = duration.ToString(); // assign the new duration to the schedule object } if (exist) { /* if the exist var true make the alreadyExist var true */ alreadyExist = true; } } if (alreadyExist) { /* if the alreadyExist var true display a message saying you already have class in that time in a popup */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('You already have a class in that time !')", true); } else { /* else */ sectionStudentList.Filter("SectionID", sectionId); // filter sectionstudentList by section id int total = sectionStudentList.List.Count; // get the count of the students that already registerd in the section total = total + 1; // add one to the count if (Convert.ToInt32(section.Capacity) >= total) { /* if the loccation capicty greater or equal to toatal var then add student to the section */ SectionStudent sectionStudent = new SectionStudent(sectionId, studentID); // create new sectionStudent object SectionStudentList sectionStudentList = new SectionStudentList(); // create new sectionStudentList sectionStudentList.Add(sectionStudent); // add the new object to the list ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Section Added", "alert('You have been Enrolled to this section !')", true); // show a message in a popup } else { /* else show a message that the section is already full */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('The Section is Already Full !')", true); } } } } else { /* else show a messagw that you can signup for more than 20h in a popup */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('You can't SignUP for more than 20 hours !')", true); } }