protected void Page_Load(object sender, EventArgs e) { if (Session["currentUser"] == null) { Response.Redirect("Login.aspx"); } else { User currentUser = (User)Session["currentUser"]; Course_elearnDAO ceDAO = new Course_elearnDAO(); Course_elearn currentCourse = ceDAO.get_course_by_id(Convert.ToInt32(Request.QueryString["id"])); Boolean superuser = false; Boolean course_creator = false; foreach (string s in currentUser.getRoles()) { if (s.Equals("superuser")) { superuser = true; } else if (s.Equals("course creator")) { course_creator = true; } } if (currentUser.getUserID() != currentCourse.getCourseCreator().getUserID() && !(superuser || course_creator)) { Response.Redirect("errorPage.aspx"); } else { if (!IsPostBack) { moduleType.SelectedValue = currentCourse.getCategoryID().ToString(); ddlCourseType.SelectedValue = currentCourse.getCourseType(); nameOfModuleInput.Text = currentCourse.getCourseName(); lblBreadcrumbCourseName.Text = currentCourse.getCourseName(); descriptionModuleInput.Text = currentCourse.getDescription(); hoursInput.Text = currentCourse.getHoursAwarded().ToString(); if (currentCourse.getTargetAudience() != null) { txtTargetAudience.Text = currentCourse.getTargetAudience().ToString(); } fromDateInput.Text = currentCourse.getStartDate().ToString("dd/MM/yyyy"); toDateInput.Text = currentCourse.getExpiryDate().ToString("dd/MM/yyyy"); //prerequisites ArrayList allPrerequisites = currentCourse.getPrerequisite(); List <int> prereqIDlist = new List <int>(); foreach (Course_elearn prereq in allPrerequisites) { prereqIDlist.Add(prereq.getCourseID()); } Session["selectedPrereq"] = prereqIDlist; var itemIDs = string.Join(",", ((IList <int>)Session["selectedPrereq"]).ToArray()); //postrequisites List <int> postReqIDList = getAllPostRequisiteCourses(currentCourse.getCourseID()); List <int> postReqIDListNoDup = new List <int>(); foreach (int postreqID in postReqIDList) { if (!postReqIDListNoDup.Contains(postreqID) && postReqIDList.Contains(postreqID)) { postReqIDListNoDup.Add(postreqID); } } Session["selectedPostreq"] = postReqIDListNoDup; var itemIDs2 = string.Join(",", ((IList <int>)Session["selectedPostreq"]).ToArray()); //to load course list var sqlQueryCourseList = ""; if (itemIDs.Length > 0 && itemIDs2.Length > 0) { sqlQueryCourseList = String.Format("SELECT * FROM [Elearn_course] ec INNER JOIN [Elearn_courseCategory] ecc ON ec.categoryID = ecc.categoryID WHERE ec.status='active' and ec.start_date<=getDate() and ec.expiry_date>=getDate() and ec.elearn_courseID NOT IN ({0}) and ec.elearn_courseID NOT IN ({1}) and ec.courseType='Online Learning' and ec.elearn_courseID != " + currentCourse.getCourseID(), itemIDs, itemIDs2); } else if (itemIDs.Length > 0 && itemIDs2.Length < 1) { sqlQueryCourseList = String.Format("SELECT * FROM [Elearn_course] ec INNER JOIN [Elearn_courseCategory] ecc ON ec.categoryID = ecc.categoryID WHERE ec.status='active' and ec.start_date<=getDate() and ec.expiry_date>=getDate() and ec.elearn_courseID NOT IN ({0}) and ec.courseType='Online Learning' and ec.elearn_courseID != " + currentCourse.getCourseID(), itemIDs); } else if (itemIDs.Length < 1 && itemIDs2.Length > 0) { sqlQueryCourseList = String.Format("SELECT * FROM [Elearn_course] ec INNER JOIN [Elearn_courseCategory] ecc ON ec.categoryID = ecc.categoryID WHERE ec.status='active' and ec.start_date<=getDate() and ec.expiry_date>=getDate() and ec.elearn_courseID NOT IN ({0}) and ec.courseType='Online Learning' and ec.elearn_courseID != " + currentCourse.getCourseID(), itemIDs2); } else { sqlQueryCourseList = String.Format("SELECT * FROM [Elearn_course] ec INNER JOIN [Elearn_courseCategory] ecc ON ec.categoryID = ecc.categoryID WHERE ec.status='active' and ec.start_date<=getDate() and ec.expiry_date>=getDate() and ec.courseType='Online Learning' and ec.elearn_courseID != " + currentCourse.getCourseID()); } SqlDataSource1.SelectCommand = sqlQueryCourseList; gvPrereq.DataSource = SqlDataSource1; gvPrereq.DataBind(); gvPrereq.UseAccessibleHeader = true; if (gvPrereq.Rows.Count > 0) { gvPrereq.HeaderRow.TableSection = TableRowSection.TableHeader; } //to load prereq cart var sqlQuery = ""; if (itemIDs.Length > 0) { sqlQuery = String.Format("SELECT * FROM [Elearn_course] WHERE [elearn_courseID] IN ({0}) and elearn_courseID != " + currentCourse.getCourseID(), itemIDs); } else { sqlQuery = "SELECT * FROM [Elearn_course] WHERE [elearn_courseID] = -1"; } SqlDataSourcePrereqCart.SelectCommand = sqlQuery; gvPrereqCart.DataSource = SqlDataSourcePrereqCart; gvPrereqCart.DataBind(); Session["currentMod"] = nameOfModuleInput.Text; } } } }