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(); }