public Course_elearn get_course_by_name(Course_elearn getThis) { SqlConnection conn = new SqlConnection(); Course_elearn toReturn = null; try { conn = new SqlConnection(); string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString(); conn.ConnectionString = connstr; conn.Open(); SqlCommand comm = new SqlCommand(); comm.Connection = conn; comm.CommandText = "select * from Elearn_course where elearn_courseName =@name"; comm.Parameters.AddWithValue("@name", getThis.getCourseName()); SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { toReturn = new Course_elearn(); int cid = (int)dr["elearn_courseID"]; //1 toReturn.setCourseID(cid); toReturn.setCourseName((string)dr["elearn_courseName"]); //2 if (!dr.IsDBNull(4)) { toReturn.setCourseProvider((string)dr["elearn_courseProvider"]); } ; toReturn.setStartDate((DateTime)dr["start_date"]);//3 if (!dr.IsDBNull(4)) { toReturn.setExpiryDate((DateTime)dr["expiry_date"]); } toReturn.setStatus((string)dr["status"]); //4 //get the prereq toReturn.setDescription((string)dr["description"]); //6 ArrayList list = getPrereqOfCourse(cid); //5 if (list != null) { toReturn.setPrerequisite(list); //retrieve arraylist of all prereq course_elearn objects } toReturn.setCategoryID((int)dr["categoryID"]); //7 toReturn.setHoursAwarded((double)dr["hoursAwarded"]); if (!dr.IsDBNull(11)) { toReturn.setTargetAudience((string)dr["targetAudience"]); } toReturn.setCourseType((string)dr["courseType"]); } dr.Close(); } catch (SqlException ex) { throw ex; } finally { conn.Close(); } return(toReturn); }
protected void Page_Load(object sender, EventArgs e) { //Response.Write(DateTime.Now.ToShortDateString()); Course_elearnDAO cdao = new Course_elearnDAO(); string id_str = null; if (Request.QueryString["id"] != null) { id_str = Request.QueryString["id"]; int id_num = int.Parse(id_str); current = cdao.get_course_by_id(id_num); TestimonialDAO t = new TestimonialDAO(); testimonials = t.get_testimonials_by_course(current); } else { return; } if (!IsPostBack) { int id_num = int.Parse(id_str); current = cdao.get_course_by_id(id_num); lblCourseNameHeader.Text = current.getCourseName(); lblBreadcrumbCourseName.Text = current.getCourseName(); lblCourseName.Text = current.getCourseName(); lblCourseDescription.Text = current.getDescription(); hoursOutput.Text = current.getHoursAwarded().ToString(); if (!current.getTargetAudience().Equals("")) { lblTargetAudience.Text = current.getTargetAudience(); } else { lblTargetAudience.Text = "-"; } lblCoursePeriodStart.Text = "Start: " + current.getStartDate().ToLongDateString(); lblCoursePeriodEnd.Text = "End: " + current.getExpiryDate().ToLongDateString(); DateTime currentDateTime = DateTime.Now; if (current.getStatus().Equals("Inactive") || !(DateTime.Compare(current.getStartDate(), currentDateTime) < 0 && DateTime.Compare(current.getExpiryDate(), currentDateTime) > 0)) { panelInactive.Visible = true; } Page.Form.Attributes.Add("enctype", "multipart/form-data"); } }
protected void Page_Load(object sender, EventArgs e) { //Response.Write(DateTime.Now.ToShortDateString()); Course_elearnDAO cdao = new Course_elearnDAO(); string id_str = null; if (Request.QueryString["id"] != null) { id_str = Request.QueryString["id"]; int id_num = int.Parse(id_str); current = cdao.get_course_by_id(id_num); TestimonialDAO t = new TestimonialDAO(); testimonials = t.get_testimonials_by_course(current); } else { return; } if (!IsPostBack) { int id_num = int.Parse(id_str); current = cdao.get_course_by_id(id_num); lblCourseNameHeader.Text = current.getCourseName(); lblBreadcrumbCourseName.Text = current.getCourseName(); lblCourseName.Text = current.getCourseName(); lblCourseDescription.Text = current.getDescription(); hoursOutput.Text = current.getHoursAwarded().ToString(); if (!current.getTargetAudience().Equals("")) { lblTargetAudience.Text = current.getTargetAudience(); } else { lblTargetAudience.Text = "-"; } lblCoursePeriodStart.Text = "Start: " + current.getStartDate().ToLongDateString(); lblCoursePeriodEnd.Text = "End: " + current.getExpiryDate().ToLongDateString(); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "filename=" + e.CommandArgument); string coursedir = "~/Data/" + current.getCourseName(); Response.TransmitFile(Server.MapPath(coursedir) + e.CommandArgument); Response.End(); }
public Course_elearn create_elearnCourse(Course_elearn course) { SqlConnection conn = new SqlConnection(); Course_elearn toReturn = null; try { conn = new SqlConnection(); string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString(); conn.ConnectionString = connstr; conn.Open(); SqlCommand comm = new SqlCommand(); comm.Connection = conn; comm.CommandText = "insert into [Elearn_course] " + "(elearn_courseName, elearn_courseProvider, entry_date, start_date, expiry_date, status, description, categoryID, courseCreator, hoursAwarded, targetAudience, courseType) OUTPUT INSERTED.elearn_courseID " + "values (@cName, @provider, Convert(datetime, @entry, 103), convert(datetime,@time,103), Convert(datetime,@expiry,103), @status, @desc, @category, @courseCreator, @hoursAwarded, @targetAudience, @courseType)"; comm.Parameters.AddWithValue("@cName", course.getCourseName()); if (course.getCourseProvider() != null) { comm.Parameters.AddWithValue("@provider", course.getCourseProvider()); } else { comm.Parameters.AddWithValue("@provider", DBNull.Value); } comm.Parameters.AddWithValue("@entry", course.getEntryDate()); if (course.getStartDate() == null) { comm.Parameters.AddWithValue("@time", DBNull.Value); } else { comm.Parameters.AddWithValue("@time", course.getStartDate()); } if (course.getExpiryDate() == null) { comm.Parameters.AddWithValue("@expiry", DBNull.Value); } else { comm.Parameters.AddWithValue("@expiry", course.getExpiryDate()); } comm.Parameters.AddWithValue("@status", course.getStatus()); comm.Parameters.AddWithValue("@desc", course.getDescription()); comm.Parameters.AddWithValue("@category", course.getCategoryID()); comm.Parameters.AddWithValue("@courseCreator", course.getCourseCreator().getUserID()); comm.Parameters.AddWithValue("@hoursAwarded", course.getHoursAwarded()); comm.Parameters.AddWithValue("@targetAudience", course.getTargetAudience()); comm.Parameters.AddWithValue("@courseType", course.getCourseType()); int a = (Int32)comm.ExecuteScalar(); //need new method to create pre-requisities here to store in seperate table (pre-req table) course.setCourseID(a); toReturn = course; } catch (SqlException ex) { throw ex; } finally { conn.Close(); } return(toReturn); }
protected void cfmSubmit_Click(object sender, EventArgs e) { //to do validations Course_elearnDAO ceDAO = new Course_elearnDAO(); int courseID = Convert.ToInt32(Request.QueryString["id"]); Course_elearn currentCourse = ceDAO.get_course_by_id(courseID); //change to MM-dd-yyyy string fromDate = fromDateInput.Text.Substring(3, 2) + "/" + fromDateInput.Text.Substring(0, 2) + "/" + fromDateInput.Text.Substring(6, 4); string toDate = toDateInput.Text.Substring(3, 2) + "/" + toDateInput.Text.Substring(0, 2) + "/" + toDateInput.Text.Substring(6, 4); ceDAO.updateCourse(courseID, Convert.ToInt32(moduleType.SelectedValue), nameOfModuleInput.Text, descriptionModuleInput.Text, Convert.ToDouble(hoursInput.Text), DateTime.ParseExact(fromDate, "MM/dd/yyyy", CultureInfo.InvariantCulture), DateTime.ParseExact(toDate, "MM/dd/yyyy", CultureInfo.InvariantCulture)); //update prerequisites //delete all prereq first ceDAO.deletePrerequisitesByCourseID(courseID); //insert all new prereq List <int> prereqIDlist = (List <int>)Session["selectedPrereq"]; foreach (int prereqID in prereqIDlist) { ceDAO.insertPrerequisite(courseID, prereqID); } //set audit User currentUser = (User)Session["currentUser"]; setAudit(currentUser, "course", "update", courseID.ToString(), "course name: " + currentCourse.getCourseName()); Response.Redirect($"viewModuleInfo.aspx?id={courseID}"); }
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; } } } }
protected void cfmActivate_Click(object sender, EventArgs e) { Course_elearnDAO ceDAO = new Course_elearnDAO(); Course_elearn currentCourse = ceDAO.get_course_by_id(Convert.ToInt32(Request.QueryString["id"])); ceDAO.activateCourse(Convert.ToInt32(Request.QueryString["id"])); int cat = currentCourse.getCategoryID(); //set audit User currentUser = (User)Session["currentUser"]; setAudit(currentUser, "course", "activate", currentCourse.getCourseID().ToString(), "course name: " + currentCourse.getCourseName()); Response.Redirect($"viewAllModule.aspx"); }
protected void submitBtn_Click(object sender, EventArgs e) { Page.Validate("ValidateForm"); if (!Page.IsValid) { } else { Course_elearnDAO cdao = new Course_elearnDAO(); //int id_int = Convert.ToInt32(id.Text); Boolean check = true; User user = (User)Session["currentUser"]; Course_elearn c = null; string type = Request.QueryString["type"]; string name = nameOfModuleInput.Text; string fromDate = fromDateInput.Text.Substring(3, 2) + "/" + fromDateInput.Text.Substring(0, 2) + "/" + fromDateInput.Text.Substring(6, 4); string toDate = toDateInput.Text.Substring(3, 2) + "/" + toDateInput.Text.Substring(0, 2) + "/" + toDateInput.Text.Substring(6, 4); if (check && moduleType.Text != "") // if no expiry date { c = new Course_elearn(name, user.getDepartment(), DateTime.Now, DateTime.ParseExact(fromDate, "MM/dd/yyyy", CultureInfo.InvariantCulture), DateTime.ParseExact(toDate, "MM/dd/yyyy", CultureInfo.InvariantCulture), "active", descriptionModuleInput.Text, Convert.ToInt32(moduleType.SelectedValue), user, Convert.ToDouble(hoursInput.Text), txtTargetAudience.Text, ddlCourseType.SelectedValue); } //check pre req here //pull pre req from model, check the course object here before creating the entry in the database /*List<int> allSelectedID = new List<int>(); * int counter = 0; * foreach (GridViewRow row in gvPrereq.Rows) * { * CheckBox chkRow = (row.Cells[0].FindControl("chkboxPrereq") as CheckBox); * if (chkRow.Checked) * { * int prereqID = Convert.ToInt32(gvPrereq.DataKeys[counter].Value.ToString()); * allSelectedID.Add(prereqID); * } * counter++; * }*/ //create the course object //now insert into database by calling DAO Course_elearnDAO cDao = new Course_elearnDAO(); Course_elearn res = cDao.create_elearnCourse(c); Course_elearn course_with_id = cDao.get_course_by_name(res); List <int> prereqIDlist = (List <int>)Session["selectedPrereq"]; int id = course_with_id.getCourseID(); if (ddlCourseType.SelectedValue.Equals("Online Learning")) { foreach (int prereqID in prereqIDlist) { cDao.insertPrerequisite(id, prereqID); } //create dir string file = "~/Data/"; string add = Server.MapPath(file) + id; Directory.CreateDirectory(add); } //set audit User currentUser = (User)Session["currentUser"]; setAudit(currentUser, "course", "create", res.getCourseID().ToString(), "course name: " + res.getCourseName()); Response.Redirect("viewModuleInfo.aspx?id=" + id); } }