/// <summary> /// Populate course type display table /// </summary> private void populateCourseTypeTable() { //Get current code types from database CourseTypeDataAccess courseTypeDAL = new CourseTypeDataAccess(); IList <CourseCodeType> courseTypeList = courseTypeDAL.GetAllCourseCodeTypes(); // Get All Course Code //Clear table rows tblParent.Rows.Clear(); string innerHTML = ""; //If no code type found in database if (courseTypeList.Count == 0) { //Create table row createHTMLRow(tblParent); //Create table column createHTMLColumn(htRow); //Add column attributes htCell.Attributes.Add("align", "center"); htCell.Attributes.Add("valign", "middle"); htCell.Attributes.Add("class", "LoginLabel"); //Display not found message innerHTML = "<b>No Code Type found.</b>"; //Add inner HTML to cell addInnerHTML(htCell, innerHTML.ToString()); } else//If code types found in database { //for all code types in list foreach (CourseCodeType courseCodeType in courseTypeList) { //create new row createHTMLRow(tblParent); //create new column createHTMLColumn(htRow); //add course code in cell innerHTML = courseCodeType.CodeType; //add column addtibutes htCell.Attributes.Add("align", "left"); htCell.Attributes.Add("valign", "middle"); htCell.Attributes.Add("width", "50%"); //add inner HTML to cell addInnerHTML(htCell, innerHTML.ToString()); //create new column createHTMLColumn(htRow); //display remove link with confirm delete function innerHTML = "<a href=\"?CodeTypeID=" + courseCodeType.ID + "\" onClick='javascript:return confirmCodeTypeDelete()'>remove</a>"; //add attributes to column htCell.Attributes.Add("align", "left"); htCell.Attributes.Add("valign", "middle"); htCell.Attributes.Add("class", "participantList"); //add inner HTML to column addInnerHTML(htCell, innerHTML.ToString()); } } }
/// <summary> /// Admin manage course code type page load function /// Loads existing course code types for display /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //generate code type table display populateCourseTypeTable(); } //If code type id found perform delete action if (Request.QueryString["CodeTypeID"] != null) { CourseTypeDataAccess courseTypeDAL = new CourseTypeDataAccess(); CourseCodeType code = new CourseCodeType(); //check if code type already exists with given id code = courseTypeDAL.GetCodeTypeByID(Convert.ToInt32(Request.QueryString["CodeTypeID"])); if (code == null) { //If not found alert user that code type is already deleted lblMessage.Text = "Code type that you want to delete is already deleted by another admin.<BR> "; lblMessage.ForeColor = System.Drawing.Color.Red; } else { //else perform delete action int delCode = 0; delCode = courseTypeDAL.DeleteCodeTypeByCodeTypeID(Convert.ToInt32(Request.QueryString["CodeTypeID"])); //if delcode is 0 alert user that error in delete operation if (delCode == 0) { lblMessage.Text = "Could not delete code type. This code type may be in use. Please try again.<BR> "; lblMessage.ForeColor = System.Drawing.Color.Red; } else { //notify user about delete success lblMessage.Text = "Code type deleted successfully.<BR> "; lblMessage.ForeColor = System.Drawing.Color.Green; //generate code type table display populateCourseTypeTable(); } } } txtCodeType.Focus(); }
protected long GetCodeIDfromName(string strCourseCode) { long ID = 0; try { CourseTypeDataAccess courseTypeDAL = new CourseTypeDataAccess(); CourseCodeType code = new CourseCodeType(); code = courseTypeDAL.GetCodeTypeByName(Server.HtmlEncode(strCourseCode.Trim()).ToString()); if (code != null) { ID = code.ID; } return(ID); } catch (Exception ex) { return(ID); } }
/// <summary> /// Perform add new code type button action /// Adds new code type /// Notify user about success or error /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddNewCodeType_Click(object sender, EventArgs e) { //if code name is not null if (txtCodeType.Text.Trim() != "") { CourseTypeDataAccess courseTypeDAL = new CourseTypeDataAccess(); CourseCodeType code = new CourseCodeType(); //check if code type already exists with given name code = courseTypeDAL.GetCodeTypeByName(Server.HtmlEncode(txtCodeType.Text.Trim()).ToString()); if (code == null) { //if not found name in database add new code type int newCodeTypeId = courseTypeDAL.AddCodeType(Server.HtmlEncode(txtCodeType.Text.Trim()).ToString()); //alert user about status if (newCodeTypeId > 0) { lblMessage.Text = "Code type added successfully.<BR> "; lblMessage.ForeColor = System.Drawing.Color.Green; txtCodeType.Text = ""; } else { lblMessage.Text = "Could not add code type. Please try again.<BR> "; lblMessage.ForeColor = System.Drawing.Color.Red; } } else { //if given name found in database notify user. lblMessage.Text = "Code type with this name already exists.<BR> "; lblMessage.ForeColor = System.Drawing.Color.Red; } } //populate code type table populateCourseTypeTable(); }