/// <summary>
    /// Display Header When GridView Empty with proper message
    /// </summary>
    /// <param name="objListSort">EmptyList</param>
    private void ShowHeaderWhenEmptyGrid()
    {
        try
        {
            //set header visible
            gvCertification.ShowHeader = true;

            //Create empty datasource for Grid view and bind
            CertificationDetailsCollection.Add(new BusinessEntities.CertificationDetails());
            gvCertification.DataSource = CertificationDetailsCollection;
            gvCertification.DataBind();

            //Calculate number of columns in Grid view used for column Span
            int columnsCount = gvCertification.Columns.Count;

            //clear all the cells in the row
            gvCertification.Rows[0].Cells.Clear();

            //add a new blank cell
            gvCertification.Rows[0].Cells.Add(new TableCell());
            gvCertification.Rows[0].Cells[0].Text  = NO_RECORDS_FOUND_MESSAGE;
            gvCertification.Rows[0].Cells[0].Wrap  = false;
            gvCertification.Rows[0].Cells[0].Width = Unit.Percentage(10);
        }
        catch (RaveHRException ex)
        {
            LogErrorMessage(ex);
        }
        catch (Exception ex)
        {
            RaveHRException objEx = new RaveHRException(ex.Message, ex, Sources.PresentationLayer, CLASS_NAME, "ShowHeaderWhenEmptyGrid", EventIDConstants.RAVE_HR_PROJECTS_PRESENTATION_LAYER);
            LogErrorMessage(objEx);
        }
    }
    /// <summary>
    /// Handles the Click event of the btnAdd control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Rave.HR.BusinessLayer.Employee.CertificationDetails objCertificationDetailsBAL;

        if (ValidateControls())
        {
            BusinessEntities.CertificationDetails objCertificationDetails = new BusinessEntities.CertificationDetails();
            objCertificationDetailsBAL = new Rave.HR.BusinessLayer.Employee.CertificationDetails();

            if (gvCertification.Rows[0].Cells[0].Text == NO_RECORDS_FOUND_MESSAGE)
            {
                CertificationDetailsCollection.Clear();
            }

            objCertificationDetails.CertificationName = txtName.Text;
            objCertificationDetails.CertificateDate   = Convert.ToDateTime(ucDatePickerCertificationDate.Text);
            if (ucDatePickerCertficationValidDate.Text != "")
            {
                objCertificationDetails.CertificateValidDate = Convert.ToDateTime(ucDatePickerCertficationValidDate.Text);
            }
            // Mohamed :Issue 50440 : 10/04/2014 : Starts
            // Desc : Remove Mandatory validation from "TotalScore" and "OutOf" Fields
            objCertificationDetails.Score = float.Parse(txtTotalScore.Text == "" ? "0" : txtTotalScore.Text);
            objCertificationDetails.OutOf = float.Parse(txtOutOf.Text == "" ? "0" : txtOutOf.Text);
            // Mohamed :Issue 50440 : 10/04/2014 : Ends
            objCertificationDetails.Mode  = 1;
            objCertificationDetails.EMPId = int.Parse(EMPId.Value);

            CertificationDetailsCollection.Add(objCertificationDetails);

            objCertificationDetailsBAL.AddCertificationDetails(objCertificationDetails);

            this.PopulateGrid(objCertificationDetails.EMPId);

            this.ClearControls();
            //To solved the issue no 19221
            //Comment by Rahul P
            //Start
            //btnAddRow.Text = CommonConstants.BTN_AddRow;
            btnAddRow.Text = "Save";
            //End
            lblMessage.Text = "Certification details saved successfully.";
        }
    }
    /// <summary>
    /// Handles the Click event of the btnUpdate control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Rave.HR.BusinessLayer.Employee.CertificationDetails objCertificationDetailsBAL;
        BusinessEntities.CertificationDetails objCertificationDetails = new BusinessEntities.CertificationDetails();

        if (ValidateControls())
        {
            objCertificationDetailsBAL = new Rave.HR.BusinessLayer.Employee.CertificationDetails();
            int rowIndex       = 0;
            int deleteRowIndex = -1;
            int temp           = 0;

            if (ViewState[DELETEROWINDEX] != null)
            {
                deleteRowIndex = Convert.ToInt32(ViewState[DELETEROWINDEX].ToString());
            }

            //Update the grid view according the row, which is selected for editing.
            if (ViewState[ROWINDEX] != null)
            {
                rowIndex = Convert.ToInt32(ViewState[ROWINDEX].ToString());
                if (deleteRowIndex != -1 && deleteRowIndex < rowIndex)
                {
                    rowIndex--;
                }
                Label CertificationId = (Label)gvCertification.Rows[rowIndex].FindControl(CERTIFICATIONID);
                Label Mode            = (Label)gvCertification.Rows[rowIndex].FindControl(MODE);

                gvCertification.Rows[rowIndex].Cells[0].Text = txtName.Text;
                gvCertification.Rows[rowIndex].Cells[1].Text = ucDatePickerCertificationDate.Text;
                gvCertification.Rows[rowIndex].Cells[2].Text = ucDatePickerCertficationValidDate.Text;
                gvCertification.Rows[rowIndex].Cells[3].Text = txtTotalScore.Text;
                gvCertification.Rows[rowIndex].Cells[4].Text = txtOutOf.Text;

                if (int.Parse(CertificationId.Text) == 0)
                {
                    Mode.Text = "1";
                }
                else
                {
                    Mode.Text = "2";
                }
                ImageButton btnImg = (ImageButton)gvCertification.Rows[rowIndex].FindControl(IMGBTNDELETE);
                btnImg.Enabled            = true;
                ViewState[ROWINDEX]       = null;
                ViewState[DELETEROWINDEX] = null;
            }

            //Mohamed : Issue 50200 : 28/03/2014 : Starts
            //Desc :  Aryabhatta has raised 2 issues in RMS
            //for (int i = 0; i < CertificationDetailsCollection.Count; i++)
            //{

            objCertificationDetails = (BusinessEntities.CertificationDetails)CertificationDetailsCollection.Item(rowIndex);

            Label Grid_CertificationId = (Label)gvCertification.Rows[rowIndex].FindControl(CERTIFICATIONID);
            Label Grid_Mode            = (Label)gvCertification.Rows[rowIndex].FindControl(MODE);

            objCertificationDetails.CertificationId   = int.Parse(Grid_CertificationId.Text);
            objCertificationDetails.EMPId             = int.Parse(EMPId.Value);
            objCertificationDetails.CertificationName = gvCertification.Rows[rowIndex].Cells[0].Text;
            objCertificationDetails.CertificateDate   = Convert.ToDateTime(gvCertification.Rows[rowIndex].Cells[1].Text);
            if (gvCertification.Rows[rowIndex].Cells[2].Text != "")
            {
                objCertificationDetails.CertificateValidDate = Convert.ToDateTime(gvCertification.Rows[rowIndex].Cells[2].Text);
            }
            objCertificationDetails.Score = float.Parse(gvCertification.Rows[rowIndex].Cells[3].Text);
            objCertificationDetails.OutOf = float.Parse(gvCertification.Rows[rowIndex].Cells[4].Text);
            objCertificationDetails.Mode  = int.Parse(Grid_Mode.Text);
            //}

            this.DoDataBind();

            objCertificationDetailsBAL.UpdateCertificationDetails(objCertificationDetails);

            //Mohamed : Issue 50200 : 28/03/2014 : Ends

            //Clear all the fields after inserting row into gridview
            this.ClearControls();

            btnAddRow.Visible    = true;
            btnUpdate.Visible    = false;
            btnCancelRow.Visible = false;
            //To solved the issue no 19221
            //Comment by Rahul P
            //Start
            btnCancel.Visible = true;
            //End
            //Enabling all the edit buttons.
            for (int i = 0; i < gvCertification.Rows.Count; i++)
            {
                ImageButton btnImgEdit = (ImageButton)gvCertification.Rows[i].FindControl(IMGBTNEDIT);
                btnImgEdit.Enabled = true;
            }
            HfIsDataModified.Value = string.Empty;

            lblMessage.Text = "Certification details updated successfully.";
        }
    }
    /// <summary>
    /// Handles the RowDeleting event of the gvCertification control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewDeleteEventArgs"/> instance containing the event data.</param>
    protected void gvCertification_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int     deleteRowIndex = 0;
        int     rowIndex       = -1;
        Boolean Flag           = false;

        Rave.HR.BusinessLayer.Employee.CertificationDetails objCertificationDetailsBAL;
        BusinessEntities.CertificationDetails objCertificationDetails = new BusinessEntities.CertificationDetails();
        objCertificationDetailsBAL = new Rave.HR.BusinessLayer.Employee.CertificationDetails();

        deleteRowIndex = e.RowIndex;

        objCertificationDetails = (BusinessEntities.CertificationDetails)CertificationDetailsCollection.Item(deleteRowIndex);
        if (objCertificationDetails.Mode == 1)
        {
            Flag = true;
        }
        objCertificationDetails.Mode = 3;

        if (ViewState[CERTIFICATIONDETAILSDELETE] != null)
        {
            BusinessEntities.RaveHRCollection objDeleteCertificationDetailsCollection = (BusinessEntities.RaveHRCollection)ViewState[CERTIFICATIONDETAILSDELETE];
            objDeleteCertificationDetailsCollection.Add(objCertificationDetails);

            ViewState[CERTIFICATIONDETAILSDELETE] = objDeleteCertificationDetailsCollection;
        }
        else
        {
            BusinessEntities.RaveHRCollection objDeleteCertificationDetailsCollection1 = new BusinessEntities.RaveHRCollection();

            objDeleteCertificationDetailsCollection1.Add(objCertificationDetails);

            ViewState[CERTIFICATIONDETAILSDELETE] = objDeleteCertificationDetailsCollection1;
        }

        CertificationDetailsCollection.RemoveAt(deleteRowIndex);

        ViewState[DELETEROWINDEX] = deleteRowIndex;

        DoDataBind();

        objCertificationDetailsBAL.DeleteCertificationDetails(objCertificationDetails);

        if (ViewState[ROWINDEX] != null)
        {
            rowIndex = Convert.ToInt32(ViewState[ROWINDEX].ToString());
            //check edit index with deleted index if edit index is greater than or equal to delete index then rowindex decremented.
            if (rowIndex != -1 && deleteRowIndex <= rowIndex)
            {
                rowIndex--;
                //store the rowindex in viewstate.
                ViewState[ROWINDEX] = rowIndex;
            }

            ImageButton btnImg = (ImageButton)gvCertification.Rows[rowIndex].FindControl(IMGBTNDELETE);
            btnImg.Enabled = false;

            //Disabling all the edit buttons.
            for (int i = 0; i < gvCertification.Rows.Count; i++)
            {
                if (rowIndex != i)
                {
                    ImageButton btnImgEdit = (ImageButton)gvCertification.Rows[i].FindControl(IMGBTNEDIT);
                    btnImgEdit.Enabled = false;
                }
            }
        }

        lblMessage.Text = "Certification details deleted successfully.";
    }
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        //Clearing the error label
        lblError.Text   = string.Empty;
        lblMessage.Text = string.Empty;

        btnAddRow.Attributes.Add(Common.CommonConstants.EVENT_ONCLICK, "return ButtonClickValidate();");
        btnUpdate.Attributes.Add(Common.CommonConstants.EVENT_ONCLICK, "return ButtonClickValidate();");

        txtName.Attributes.Add(Common.CommonConstants.EVENT_ONBLUR, "return ValidateControl('" + txtName.ClientID + "','" + imgName.ClientID + "','" + Common.CommonConstants.VALIDATE_ALPHABET_WITHSPACE + "');");
        imgName.Attributes.Add(Common.CommonConstants.EVENT_ONMOUSEOVER, "ShowTooltip('" + spanName.ClientID + "','" + Common.CommonConstants.MSG_ONLY_ALPHABET + "');");
        imgName.Attributes.Add(Common.CommonConstants.EVENT_ONMOUSEOUT, "HideTooltip('" + spanName.ClientID + "');");

        txtTotalScore.Attributes.Add(Common.CommonConstants.EVENT_ONBLUR, "return ValidateControl('" + txtTotalScore.ClientID + "','" + imgTotalScore.ClientID + "','" + Common.CommonConstants.VALIDATE_NUMERIC_FUNCTION + "');");
        imgTotalScore.Attributes.Add(Common.CommonConstants.EVENT_ONMOUSEOVER, "ShowTooltip('" + spanTotalScore.ClientID + "','" + Common.CommonConstants.MSG_NUMERIC + "');");
        imgTotalScore.Attributes.Add(Common.CommonConstants.EVENT_ONMOUSEOUT, "HideTooltip('" + spanTotalScore.ClientID + "');");

        txtOutOf.Attributes.Add(Common.CommonConstants.EVENT_ONBLUR, "return ValidateControl('" + txtOutOf.ClientID + "','" + imgOutOf.ClientID + "','" + Common.CommonConstants.VALIDATE_NUMERIC_FUNCTION + "');");
        imgOutOf.Attributes.Add(Common.CommonConstants.EVENT_ONMOUSEOVER, "ShowTooltip('" + spanOutOf.ClientID + "','" + Common.CommonConstants.MSG_NUMERIC + "');");
        imgOutOf.Attributes.Add(Common.CommonConstants.EVENT_ONMOUSEOUT, "HideTooltip('" + spanOutOf.ClientID + "');");

        ucDatePickerCertificationDate.Attributes.Add(CommonConstants.EVENT_ONBLUR, "javascript:ValidateControl('" + ucDatePickerCertificationDate.ClientID + "','','');");
        ucDatePickerCertificationDate.Attributes.Add(ReadOnly, ReadOnly);
        ucDatePickerCertficationValidDate.Attributes.Add(CommonConstants.EVENT_ONBLUR, "javascript:ValidateControl('" + ucDatePickerCertficationValidDate.ClientID + "','','');");
        ucDatePickerCertficationValidDate.Attributes.Add(ReadOnly, ReadOnly);

        if (!ValidateURL())
        {
            Response.Redirect(CommonConstants.INVALIDURL, false);
        }

        if (Session[Common.SessionNames.EMPLOYEEDETAILS] != null)
        {
            employee = (BusinessEntities.Employee)Session[Common.SessionNames.EMPLOYEEDETAILS];
        }

        if (employee != null)
        {
            employeeID      = employee.EMPId;
            lblempName.Text = employee.FirstName.ToUpper() + " " + employee.LastName.ToUpper();
        }

        if (!IsPostBack)
        {
            Session["isSaved"]             = null;
            Session[SessionNames.PAGEMODE] = Common.MasterEnum.PageModeEnum.View;
            this.PopulateGrid(employeeID);
        }

        if (gvCertification.Rows[0].Cells[0].Text == NO_RECORDS_FOUND_MESSAGE)
        {
            CertificationDetailsCollection.Clear();
            ShowHeaderWhenEmptyGrid();
        }

        // Get logged-in user's email id
        AuthorizationManager objRaveHRAuthorizationManager = new AuthorizationManager();

        UserRaveDomainId = objRaveHRAuthorizationManager.getLoggedInUser();
        UserMailId       = UserRaveDomainId.Replace("co.in", "com");

        arrRolesForUser = RaveHRAuthorizationManager.getRolesForUser(objRaveHRAuthorizationManager.getLoggedInUser());

        if (UserMailId.ToLower() == employee.EmailId.ToLower() || arrRolesForUser.Contains(AuthorizationManagerConstants.ROLEHR))
        {
            if (Session[SessionNames.PAGEMODE] != null)
            {
                PageMode = Session[SessionNames.PAGEMODE].ToString();

                if (PageMode == Common.MasterEnum.PageModeEnum.View.ToString() && IsPostBack == false && gvCertification.Rows[0].Cells[0].Text != NO_RECORDS_FOUND_MESSAGE)
                {
                    Certificationdetails.Enabled = false;
                    btnEdit.Visible       = true;
                    btnEditCancel.Visible = true;
                    btnCancel.Visible     = false;
                    btnAddRow.Visible     = false;
                }
            }
        }
        else
        {
            Certificationdetails.Enabled = false;
        }


        SavedControlVirtualPath = "~/EmployeeMenuUC.ascx";
        ReloadControl();
    }