/// <summary>
    /// Gets the qualification details.
    /// </summary>
    /// <returns></returns>
    private BusinessEntities.RaveHRCollection GetQualificationDetails(int employeeID)
    {
        Rave.HR.BusinessLayer.Employee.QualificationDetails objQualificationDetailsBAL;
        BusinessEntities.QualificationDetails objQualificationDetails;

        // Initialise Collection class object
        BusinessEntities.RaveHRCollection raveHRCollection = new BusinessEntities.RaveHRCollection();

        try
        {
            objQualificationDetailsBAL = new Rave.HR.BusinessLayer.Employee.QualificationDetails();
            objQualificationDetails    = new BusinessEntities.QualificationDetails();

            //objQualificationDetails.EMPId = 14;
            objQualificationDetails.EMPId = employeeID;

            raveHRCollection = objQualificationDetailsBAL.GetQualificationDetails(objQualificationDetails);
        }
        catch (RaveHRException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            RaveHRException objEx = new RaveHRException(ex.Message, ex, Sources.PresentationLayer, CLASS_NAME, "GetQualificationDetails", EventIDConstants.RAVE_HR_PROJECTS_PRESENTATION_LAYER);
            LogErrorMessage(objEx);
        }

        return(raveHRCollection);
    }
    /// <summary>
    /// Handles the RowDeleting event of the gvQualification 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 gvQualification_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int deleteRowIndex = 0;
        int rowIndex       = -1;

        BusinessEntities.QualificationDetails objQualificationDetails = new BusinessEntities.QualificationDetails();

        deleteRowIndex = e.RowIndex;

        objQualificationDetails      = (BusinessEntities.QualificationDetails)QualificationDetailsCollection.Item(deleteRowIndex);
        objQualificationDetails.Mode = 3;

        if (ViewState[QUALIFICATIONDETAILSDELETE] != null)
        {
            BusinessEntities.RaveHRCollection objDeleteQualificationDetailsCollection = (BusinessEntities.RaveHRCollection)ViewState[QUALIFICATIONDETAILSDELETE];
            objDeleteQualificationDetailsCollection.Add(objQualificationDetails);

            ViewState[QUALIFICATIONDETAILSDELETE] = objDeleteQualificationDetailsCollection;
        }
        else
        {
            BusinessEntities.RaveHRCollection objDeleteQualificationDetailsCollection1 = new BusinessEntities.RaveHRCollection();

            objDeleteQualificationDetailsCollection1.Add(objQualificationDetails);

            ViewState[QUALIFICATIONDETAILSDELETE] = objDeleteQualificationDetailsCollection1;
        }

        QualificationDetailsCollection.RemoveAt(deleteRowIndex);

        ViewState[DELETEROWINDEX] = deleteRowIndex;

        DoDataBind();

        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)gvQualification.Rows[rowIndex].FindControl(IMGBTNDELETE);
            btnImg.Enabled = false;

            //Disabling all the edit buttons.
            for (int i = 0; i < gvQualification.Rows.Count; i++)
            {
                if (rowIndex != i)
                {
                    ImageButton btnImgEdit = (ImageButton)gvQualification.Rows[i].FindControl(IMGBTNEDIT);
                    btnImgEdit.Enabled = false;
                }
            }
        }
    }
    /// <summary>
    /// Handles the Click event of the btnAddRow 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)
    {
        if (ValidateControls())
        {
            BusinessEntities.QualificationDetails objQualificationDetails = new BusinessEntities.QualificationDetails();

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

            objQualificationDetails.QualificationName = ddlQualification.SelectedItem.Text;
            objQualificationDetails.UniversityName    = txtUniversityName.Text;
            objQualificationDetails.InstituteName     = txtInstituteName.Text;
            objQualificationDetails.PassingYear       = txtYearOfPassing.Text;
            if (!string.IsNullOrEmpty(txtGPA.Text))
            {
                objQualificationDetails.GPA = float.Parse(txtGPA.Text);
            }
            objQualificationDetails.Outof           = float.Parse(txtOutOf.Text);
            objQualificationDetails.Percentage      = float.Parse(txtPercentage.Text);
            objQualificationDetails.Qualification   = int.Parse(ddlQualification.SelectedItem.Value);
            objQualificationDetails.Mode            = 1;
            objQualificationDetails.QualificationId = 0;

            QualificationDetailsCollection.Add(objQualificationDetails);

            this.DoDataBind();

            this.ClearControls();

            if (gvQualification.Rows.Count != 0)
            {
                btnSave.Visible = true;
            }
        }
    }
    /// <summary>
    /// Handles the Click event of the btnUpdateRow 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 btnUpdateRow_Click(object sender, EventArgs e)
    {
        if (ValidateControls())
        {
            int rowIndex       = 0;
            int deleteRowIndex = -1;
            value = 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 QualificationValue = (Label)gvQualification.Rows[rowIndex].FindControl(QUALIFICATION);
                Label QualificationId    = (Label)gvQualification.Rows[rowIndex].FindControl(QUALIFICATIONID);
                Label Mode = (Label)gvQualification.Rows[rowIndex].FindControl(MODE);

                QualificationValue.Text = ddlQualification.SelectedValue;

                gvQualification.Rows[rowIndex].Cells[0].Text = ddlQualification.SelectedItem.Text;
                gvQualification.Rows[rowIndex].Cells[1].Text = txtUniversityName.Text;
                gvQualification.Rows[rowIndex].Cells[2].Text = txtInstituteName.Text;
                gvQualification.Rows[rowIndex].Cells[3].Text = txtYearOfPassing.Text;
                gvQualification.Rows[rowIndex].Cells[4].Text = txtGPA.Text;

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

            for (int i = 0; i < QualificationDetailsCollection.Count; i++)
            {
                BusinessEntities.QualificationDetails objQualificationDetails = new BusinessEntities.QualificationDetails();
                objQualificationDetails = (BusinessEntities.QualificationDetails)QualificationDetailsCollection.Item(i);

                Label QualificationId = (Label)gvQualification.Rows[i].FindControl(QUALIFICATIONID);
                Label Mode            = (Label)gvQualification.Rows[rowIndex].FindControl(MODE);

                objQualificationDetails.QualificationId   = int.Parse(QualificationId.Text);
                objQualificationDetails.EMPId             = int.Parse(EMPId.Value);
                objQualificationDetails.QualificationName = gvQualification.Rows[i].Cells[0].Text;
                objQualificationDetails.UniversityName    = gvQualification.Rows[i].Cells[1].Text;
                objQualificationDetails.InstituteName     = gvQualification.Rows[i].Cells[2].Text;
                objQualificationDetails.PassingYear       = gvQualification.Rows[i].Cells[3].Text;
                if (!string.IsNullOrEmpty(gvQualification.Rows[i].Cells[4].Text))
                {
                    objQualificationDetails.GPA = float.Parse(gvQualification.Rows[i].Cells[4].Text);
                }
                else
                {
                    objQualificationDetails.GPA = CommonConstants.ZERO;
                }
                objQualificationDetails.Outof      = float.Parse(gvQualification.Rows[i].Cells[5].Text);
                objQualificationDetails.Percentage = float.Parse(gvQualification.Rows[i].Cells[6].Text);
                objQualificationDetails.Mode       = int.Parse(Mode.Text);
            }

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

            btnAddRow.Visible    = true;
            btnUpdateRow.Visible = false;
            btnCancelRow.Visible = false;

            //Enabling all the edit buttons.
            for (int i = 0; i < gvQualification.Rows.Count; i++)
            {
                ImageButton btnImgEdit = (ImageButton)gvQualification.Rows[i].FindControl(IMGBTNEDIT);
                btnImgEdit.Enabled = true;
            }
        }
    }
    /// <summary>
    /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
    {
        Rave.HR.BusinessLayer.Employee.QualificationDetails objQualificationDetailsBAL;

        BusinessEntities.QualificationDetails objQualificationDetails;
        BusinessEntities.RaveHRCollection     objSaveQualificationDetailsCollection = new BusinessEntities.RaveHRCollection();

        try
        {
            objQualificationDetailsBAL = new Rave.HR.BusinessLayer.Employee.QualificationDetails();

            if (gvQualification.Rows[0].Cells[0].Text != NO_RECORDS_FOUND_MESSAGE)
            {
                for (int i = 0; i < gvQualification.Rows.Count; i++)
                {
                    objQualificationDetails = new BusinessEntities.QualificationDetails();

                    Label QualificationValue = (Label)gvQualification.Rows[i].FindControl(QUALIFICATION);
                    Label QualificationId    = (Label)gvQualification.Rows[i].FindControl(QUALIFICATIONID);
                    Label Mode = (Label)gvQualification.Rows[i].FindControl(MODE);

                    objQualificationDetails.QualificationId   = int.Parse(QualificationId.Text);
                    objQualificationDetails.EMPId             = int.Parse(EMPId.Value);
                    objQualificationDetails.QualificationName = gvQualification.Rows[i].Cells[0].Text;
                    objQualificationDetails.UniversityName    = gvQualification.Rows[i].Cells[1].Text;
                    objQualificationDetails.InstituteName     = gvQualification.Rows[i].Cells[2].Text;
                    objQualificationDetails.PassingYear       = gvQualification.Rows[i].Cells[3].Text;
                    objQualificationDetails.GPA           = float.Parse(gvQualification.Rows[i].Cells[4].Text);
                    objQualificationDetails.Outof         = float.Parse(gvQualification.Rows[i].Cells[5].Text);
                    objQualificationDetails.Percentage    = float.Parse(gvQualification.Rows[i].Cells[6].Text);
                    objQualificationDetails.Mode          = int.Parse(Mode.Text);
                    objQualificationDetails.Qualification = int.Parse(QualificationValue.Text);

                    objSaveQualificationDetailsCollection.Add(objQualificationDetails);
                }
            }
            BusinessEntities.RaveHRCollection objDeleteQualificationDetailsCollection = (BusinessEntities.RaveHRCollection)ViewState[QUALIFICATIONDETAILSDELETE];

            if (objDeleteQualificationDetailsCollection != null)
            {
                BusinessEntities.QualificationDetails obj = null;

                for (int i = 0; i < objDeleteQualificationDetailsCollection.Count; i++)
                {
                    objQualificationDetails = new BusinessEntities.QualificationDetails();
                    obj = (BusinessEntities.QualificationDetails)objDeleteQualificationDetailsCollection.Item(i);

                    objQualificationDetails.QualificationId   = obj.QualificationId;
                    objQualificationDetails.EMPId             = obj.EMPId;
                    objQualificationDetails.QualificationName = obj.QualificationName;
                    objQualificationDetails.UniversityName    = obj.UniversityName;
                    objQualificationDetails.InstituteName     = obj.InstituteName;
                    objQualificationDetails.PassingYear       = obj.PassingYear;
                    objQualificationDetails.GPA           = obj.GPA;
                    objQualificationDetails.Outof         = obj.Outof;
                    objQualificationDetails.Percentage    = obj.Percentage;
                    objQualificationDetails.Mode          = obj.Mode;
                    objQualificationDetails.Qualification = obj.Qualification;

                    objSaveQualificationDetailsCollection.Add(objQualificationDetails);
                }
            }
            objQualificationDetailsBAL.Manipulation(objSaveQualificationDetailsCollection);

            if (ViewState.Count > 0)
            {
                ViewState.Clear();
            }

            if (EMPId.Value != string.Empty)
            {
                int empID = Convert.ToInt32(EMPId.Value);
                //Refresh the grip after saving
                this.PopulateGrid(empID);
            }

            if (gvQualification.Rows[0].Cells[0].Text == NO_RECORDS_FOUND_MESSAGE)
            {
                btnSave.Visible = false;
            }


            lblMessage.Text = "Qualification details saved successfully.";
        }
        catch (RaveHRException ex)
        {
            LogErrorMessage(ex);
        }
        catch (Exception ex)
        {
            RaveHRException objEx = new RaveHRException(ex.Message, ex, Sources.PresentationLayer, CLASS_NAME, "btnSave_Click", EventIDConstants.RAVE_HR_PROJECTS_PRESENTATION_LAYER);
            LogErrorMessage(objEx);
        }
    }