Example #1
0
 /// <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>&nbsp;";
             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>&nbsp;";
                 lblMessage.ForeColor = System.Drawing.Color.Red;
             }
             else
             {
                 //notify user about delete success
                 lblMessage.Text      = "Code type deleted successfully.<BR>&nbsp;";
                 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);
        }
    }
Example #3
0
 /// <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>&nbsp;";
                 lblMessage.ForeColor = System.Drawing.Color.Green;
                 txtCodeType.Text     = "";
             }
             else
             {
                 lblMessage.Text      = "Could not add code type. Please try again.<BR>&nbsp;";
                 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>&nbsp;";
             lblMessage.ForeColor = System.Drawing.Color.Red;
         }
     }
     //populate code type table
     populateCourseTypeTable();
 }