using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using DevExpress.Web;
using System.Configuration;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                              Started Date  : 12-Aug-2007
* Module          : Employee Master                                        Last Modified : 21-Aug-2007
* Programmer      : Arun Vinoth.T
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          : \\Windev\EIT\Projects\Inprogress\SCREEN1206\code\TimecheckAVBackup
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_Employee : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    EmployeeEventData objEmployee = new EmployeeEventData();
    cls_Common objcommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DemoVersion objDemoVersion = new DemoVersion();
    DataSet ds_Checkuser = new DataSet();
    int EmployeeID = 0;
    string source_Language;
    LeaveEventData objLeave = new LeaveEventData();
    Licensing objLicense = new Licensing();
    string strScript = string.Empty;
    ResetPwd obj_ResetPwd = new ResetPwd();
    int isTriggered = 0;
    Email_Triggering objEmail = new Email_Triggering();
    int intIndividualUser = 0;
    #endregion    
    #region Page Load events
    /// <summary>
    /// On page loading
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected override void Page_Load(object sender, EventArgs e)
    {
        Session["country"] = null;
        Session["state"] = null;
        Session["city"] = null;
        Session["Designation"] = null;
        Session["Reporting"] = null;
        Session["LeaveSanc"] = null;
        // session checking
        base.Page_Load(sender, e);
        grv_EmpDetails.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        //this.ucOrganizationLevel.ehClick += new EventHandler(this.btnPageButton_Click);
        //get the culture info to set the language
        if (Convert.ToString(Session["localMACAdderssForlic"]) != "1A153492A74B" &&
            Convert.ToString(Session["localMACAdderssForlic"]) != "00224DB1924C" &&
            Convert.ToString(Session["localMACAdderssForlic"]) != "ECA86BFF8FBB")
        {
            objLicense.ActivateEmployeeBasedOnLicence(Convert.ToString(Session["ActiveEmployee"]));
        }
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        if (hdnAdvancedplus.Value == "1")
            trFiller.Style.Add("display", "");
        else
            trFiller.Style.Add("display", "none");
        if (!Page.IsPostBack)
        {
            //Set UserRights
            base.CheckPages(18);
            UserRights();
            LoadStrings(ci);
            Session["Level"] = string.Empty;            
            Session["EmployeeData"] = null;
            BindingEmployeeCategoryandType();
            GetUserGroupDetails();
            fillLeavePolicyddl();
            fillReportingddl();
            objcommon.menu("EmployeeMaster", "18");
            string strSetAlert = "";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "RestoreAlert('" + rm.GetString("Alert_Norecordsfound", ci) + "','" + rm.GetString("Alert_Areyousuretorestore", ci) + "','" + rm.GetString("Alert_Selecteddataisnotindeletedstatus", ci) + "','" + rm.GetString("Alert_Selectdatatorestore", ci) + "','" + rm.GetString("Alert_Nodeletedrecordsavailable", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
        }
        DataSet dsEmployee = new DataSet();
        if (Session["EmployeeData"] == null)
        {
            dsEmployee = objEmployee.Search_EmployeeDetailsbyName(txt_EmpName.Text.Replace("'", "''").Replace(' ', ' '), txtEmployeeId.Text.Trim(), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["LevelRights"]), Convert.ToString(Session["GradeLevel"]), ddlSwipeOpt.SelectedValue, Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''"), 0, EmployeeID, Convert.ToBoolean(Session["ApplnMode"]), 0, 0, 0, "Both", Convert.ToInt32(Session["EmpAutoID"]), 0, 0, 0, 0, 0, 0);
            Session["EmployeeData"] = dsEmployee;
            grv_EmpDetails.DataSource = dsEmployee;
            grv_EmpDetails.DataBind();
        }
        else
        {
            grv_EmpDetails.DataSource = (DataSet)Session["EmployeeData"];
            grv_EmpDetails.DataBind();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptsKey", "<script language='javascript'>AdjustSize();</script>");
            Session["ModeToDisplay"] = null;
        }
        if (ViewState["vs_intIndividualUser"] == null)
        {
            intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
            ViewState["vs_intIndividualUser"] = intIndividualUser;
        }
        else
            intIndividualUser = (int)ViewState["vs_intIndividualUser"];
        if (intIndividualUser >= 1)
        {
            trSwipeCardNo.Visible = false;
            trOrgLevel.Visible = false;
            trSearchButton.Visible = false;
            trSaveButton.Visible = false;
        }
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
        {
            btn_Restore.Visible = true;
            btn_PermanentDelete.Visible = true;
        }
        else
        {
            Search1.Visible = false;
            Search2.Visible = false;
            Search3.Visible = false;
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
    }
    #endregion
    #region Button events
    /// <summary>
    /// To search employee details and bind grid according to the filter options
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        DataSet dsEmployee = new DataSet();
        int intEmailAvail = 0;
        if (ckb_EmailAvail.Checked == true && ckb_EmailNotAvail.Checked == false)
            intEmailAvail = 1;
        else if (ckb_EmailAvail.Checked == false && ckb_EmailNotAvail.Checked == true)
            intEmailAvail = 2;
        dsEmployee = objEmployee.Search_EmployeeDetailsbyName(txt_EmpName.Text.Replace("'", "''").Replace(' ', ' '), txtEmployeeId.Text.Trim(), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["LevelRights"]), Convert.ToString(Session["GradeLevel"]), ddlSwipeOpt.SelectedValue, Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''"), Convert.ToInt16(Session["parentLevelId"]), EmployeeID, Convert.ToBoolean(Session["ApplnMode"]), Convert.ToInt32(ddlAdvanced.SelectedValue), Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(ddlGender.SelectedValue), Convert.ToInt32(Session["EmpAutoID"]), 0, Convert.ToInt32(ddl_UserGroup.SelectedValue), Convert.ToInt32(ddl_LeavePolicy.SelectedValue), Convert.ToInt32(ddl_ReportingTo.SelectedValue), Convert.ToInt32(ddl_LeaveSancAuthority.SelectedValue), intEmailAvail);
        Session["EmployeeData"] = dsEmployee;
        grv_EmpDetails.DataSource = dsEmployee;
        grv_EmpDetails.DataBind();
    }
    private void BindingEmployeeCategoryandType()
    {
        // employee category binding
        DataSet dsCategory = new DataSet();
        dsCategory = objEmployee.SelectCategoryDetailsEmployee("");
        if (dsCategory != null)
        {
            if (dsCategory.Tables[0].Rows.Count > 0)
            {
                ddlEmpCatagory.DataSource = dsCategory;
                ddlEmpCatagory.DataTextField = "CategoryName";
                ddlEmpCatagory.DataValueField = "CategoryId";
                ddlEmpCatagory.DataBind();
            }
            dsCategory.Dispose();
            foreach (ListItem item in ddlEmpCatagory.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
        // employee type binding
        DataSet dsType = new DataSet();
        dsType = objEmployee.SelectTypeDetailsEmployee("");
        if (dsType != null)
        {
            if (dsType.Tables[0].Rows.Count > 0)
            {
                ddlEmpType.DataSource = dsType;
                ddlEmpType.DataTextField = "TypeName";
                ddlEmpType.DataValueField = "TypeId";
                ddlEmpType.DataBind();
            }
            dsType.Dispose();
            foreach (ListItem item in ddlEmpType.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }
    /// <summary>
    /// To clear the filter options and bind the grid.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        Session["EmployeeData"] = null;
        Session["parentLevelId"] = null;
        Response.Redirect("TA_UI_Master_Employee.aspx");
    }
    /// <summary>
    /// To check for license and redirects to the add page
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        DemoVersion objDemoVersion = new DemoVersion();
        bool allowEmployeeAdd = true;
        // check for demo version or not
        string[] fileArr = Directory.GetFiles(Server.MapPath("../LicenseFile"), "*.lic");
        int arrCount = fileArr.Length;
        if (arrCount > 0)
        {
            string licenseFileName = Convert.ToString(fileArr[arrCount - 1]);
            FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
            StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
            string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
            licenseFileStreamReader.Close();
            licenseFileStream.Close();
            string decryptedLicFileInfo = string.Empty;
            try
            {
                decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
            }
            catch
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                strScript += "location.href='../Index.aspx';";
                strScript += " </script>";
                this.RegisterStartupScript("AlertLicInfoNotCorrect", strScript);
                return;
            }
            string[] decryptedLicFileInfoArr = decryptedLicFileInfo.Split('#');
            string basicLicInfo = Convert.ToString(decryptedLicFileInfoArr[0]);
            string[] basicLicInfoArr = basicLicInfo.Split(',');
            int noOfEmployeeLicFile = Convert.ToInt32(basicLicInfoArr[4]);
            allowEmployeeAdd = objDemoVersion.DVCheckEmployeeCreation("License", noOfEmployeeLicFile);
            if (!allowEmployeeAdd)
            {
                Message(rm.GetString("Alert_LicensenotallowtoAddmoreEmployee", ci));
                return;
            }
        }
        Random rnd = new Random();
        Response.Redirect("TA_UI_Master_EmployeeAdd.aspx?Rd=" + rnd);
    }
    /// <summary>
    /// To temporarily delete the selected records
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        string[] ChkBoxIDs;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                int Count = objEmployee.CountEmployee(Convert.ToInt32(ChkBoxIDs[i]));
                if (Count > 0)
                {
                    base.Message(rm.GetString("Master_Employee_Cannot_Delete", ci));
                    hdnSelectRow.Value = "";
                    return;
                }
            }
            objEmployee.delete_Employees(hdnSelectRow.Value, "PermanentDelete", EmployeeID, Convert.ToBoolean(Session["ApplnMode"]));
            base.MessageWithRedirect(rm.GetString("Alert_Employeedeletedsuccessfully", ci), "TA_UI_Master_Employee.aspx");
        }
        else
        {
            Message(rm.GetString("DeletionRecordAlert", ci));
            return;
        }
    }
    /// <summary>
    /// To permanently delete the selected records.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        string[] ChkBoxIDs;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                int Count = objEmployee.CountEmployee(Convert.ToInt32(ChkBoxIDs[i]));
                if (Count > 0)
                {
                    base.Message(rm.GetString("Master_Employee_Cannot_Delete", ci));
                    hdnSelectRow.Value = "";
                    return;
                }
            }
            objEmployee.delete_Employees(hdnSelectRow.Value, "PermanentDelete", EmployeeID, Convert.ToBoolean(Session["ApplnMode"]));
            base.MessageWithRedirect(rm.GetString("Alert_Employeedeletedsuccessfully", ci), "TA_UI_Master_Employee.aspx");
        }
        else
        {
            Message(rm.GetString("DeletionRecordAlert", ci));
            return;
        }
    }
    /// <summary>
    /// To restore the temporarily deleted records.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        string[] ChkBoxIDs;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                int intEmpid = Convert.ToInt32(ChkBoxIDs[i]);
                DataSet dsEmployee = objEmployee.GetEmployeesDetailsForDuplicationChecking(Convert.ToString(intEmpid));
                string strEmpcodeID = Convert.ToString(dsEmployee.Tables[0].Rows[0]["Employee_Code_Id"]);
                int Count = objEmployee.CheckDuplicateEmployeeCodeupdate(strEmpcodeID, intEmpid, Convert.ToBoolean(Session["ApplnMode"]));
                if (Count > 0)
                {
                    base.Message(rm.GetString("Message_Cannot_Restore", ci));
                    hdnSelectRow.Value = "";
                    return;
                }
                bool isAllowAdd = false;
                bool blActiveness = Convert.ToBoolean(dsEmployee.Tables[0].Rows[0]["Employee_Status"]);
                if (blActiveness)
                    isAllowAdd = CheckNoOfEmployeeForLicense();
                else
                    isAllowAdd = true;
                if (isAllowAdd)
                {
                    objEmployee.delete_Employees(ChkBoxIDs[i], "Restore", EmployeeID, Convert.ToBoolean(Session["ApplnMode"]));
                }
                else
                {
                    return;
                }
            }
            base.MessageWithRedirect(rm.GetString("Alert_Employeerestoredsuccessfully", ci), "TA_UI_Master_Employee.aspx");
        }
        else
        {
            Message(rm.GetString("DeletionRecordAlert", ci));
            return;
        }
    }
    protected void EditLinkButton_Click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int intEmpid = Convert.ToInt32(btn.CommandName);
        Random rnd = new Random();
        Response.Redirect("TA_UI_Master_EmployeeModify.aspx?Rn=" + rnd.NextDouble() + "&Emp_Id=" + intEmpid + "&curPage=");
    }
    protected void btn_delete_Click_1(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int intEmpid = Convert.ToInt32(btn.CommandName);
        int Count = objEmployee.CountEmployee(intEmpid);
        if (Count > 0)
        {
            base.Message(rm.GetString("Master_Employee_Cannot_Delete", ci));
        }
        else
        {
            objEmployee.delete_Employees(Convert.ToString(intEmpid), "PermanentDelete", EmployeeID, Convert.ToBoolean(Session["ApplnMode"]));
            Session["ModeToDisplay"] = null;
            base.MessageWithRedirect(rm.GetString("Alert_Employeedeletedsuccessfully", ci), "TA_UI_Master_Employee.aspx");
        }
    }
    protected void btnPageButton_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "Loaddropdown();", true);
    }
    protected void btnExport_Click(object sender, EventArgs e)
    {
        //LinkButton btn = (LinkButton)sender;
        HtmlAnchor anch = (HtmlAnchor)sender;
        grv_EmpDetails.Columns[0].Visible = false;
        grv_EmpDetails.Columns["Isdeleted"].Visible = false;
        grv_EmpDetails.Columns[5].Visible = false;
        grv_EmpDetails.Columns[10].Visible = false;
        grv_EmpDetails.Columns[11].Visible = false;
        grv_EmpDetails.Columns[12].Visible = false;
        grv_EmpDetails.Columns[13].Visible = false;
        ASPxGridViewExporter1.GridViewID = "grv_EmpDetails";
        ASPxGridViewExporter1.FileName = "List of Employees";
        ASPxGridViewExporter1.Landscape = true;
        ASPxGridViewExporter1.LeftMargin = 30;
        ASPxGridViewExporter1.RightMargin = 30;
        ASPxGridViewExporter1.MaxColumnWidth = 200;
        switch (anch.InnerText.Trim())
        {
            case "Excel":
                ASPxGridViewExporter1.WriteXlsxToResponse();
                break;
            case "PDF":
                ASPxGridViewExporter1.WritePdfToResponse();
                break;
            case "CSV":
                ASPxGridViewExporter1.WriteCsvToResponse();
                break;
            default:
                break;
        }
    }
    #endregion
    #region User Defined Functions
    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lbl_HeaderEmployeeMaster.Text = rm.GetString("Masters_Employee_EmployeeMaster", ci);
        btn_Search.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Search", ci);
        btn_Clear.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Clear", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);
        btn_Add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Restore.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Restore", ci);
        hlbulk.Text = "&nbsp;&nbsp;" + rm.GetString("btn_BulkConfiguration", ci);
        grv_EmpDetails.Columns[2].Caption = rm.GetString("email_EmployeeName", ci);
        grv_EmpDetails.Columns[3].Caption = rm.GetString("email_EmployeeId", ci);
        grv_EmpDetails.Columns[4].Caption = rm.GetString("EmployeeMaster_Designation", ci);
        grv_EmpDetails.Columns[6].Caption = rm.GetString("EmployeeMaster_EmployeeStatus", ci);

        grv_EmpDetails.Columns[7].Caption = rm.GetString("EmployeeMaster_EmailId", ci);
        grv_EmpDetails.Columns[8].Caption = rm.GetString("EmployeeMaster_MobileNumber", ci);
        grv_EmpDetails.Columns[9].Caption = rm.GetString("EmployeeMaster_ContactAddress", ci);

        grv_EmpDetails.Columns[14].Caption = rm.GetString("EmployeeMaster_FathersName", ci);
        grv_EmpDetails.Columns[15].Caption = rm.GetString("EmployeeMaster_MothersName", ci);
        grv_EmpDetails.Columns[16].Caption = rm.GetString("EmployeeMaster_DateOfBirth", ci);
        grv_EmpDetails.Columns[17].Caption = rm.GetString("EmployeeMaster_DateOfBirthAsPerRecord", ci);
        grv_EmpDetails.Columns[18].Caption = rm.GetString("EmployeeMaster_BloodGroup", ci);
        grv_EmpDetails.Columns[19].Caption = rm.GetString("EmployeeMaster_PermanentAddress", ci);
        grv_EmpDetails.Columns[20].Caption = rm.GetString("EmployeeMaster_PhoneNumber", ci);
        grv_EmpDetails.Columns[21].Caption = rm.GetString("EmployeeMaster_MobileNumber", ci);
        grv_EmpDetails.Columns[22].Caption = rm.GetString("EmployeeMaster_Gender", ci);
        grv_EmpDetails.Columns[23].Caption = rm.GetString("EmployeeMaster_MaritalStatus", ci);
        grv_EmpDetails.Columns[24].Caption = rm.GetString("EmployeeMaster_PersionalMailId", ci);
        grv_EmpDetails.Columns[25].Caption = rm.GetString("EmployeeMaster_PassportNo", ci);
        grv_EmpDetails.Columns[26].Caption = rm.GetString("EmployeeMaster_PassportExpiryDate", ci);
        grv_EmpDetails.Columns[27].Caption = rm.GetString("EmployeeMaster_VisaNo", ci);
        grv_EmpDetails.Columns[28].Caption = rm.GetString("EmployeeMaster_VisaExpiryDate", ci);
        grv_EmpDetails.Columns[29].Caption = rm.GetString("EmployeeMaster_VehicleNumber", ci);
        grv_EmpDetails.Columns[30].Caption = rm.GetString("EmployeeMaster_AnniversaryDate", ci);
        grv_EmpDetails.Columns[31].Caption = rm.GetString("EmployeeMaster_DateOfJoining", ci);
        grv_EmpDetails.Columns[32].Caption = rm.GetString("EmployeeMaster_ReportingTo", ci);
        grv_EmpDetails.Columns[33].Caption = rm.GetString("EmployeeMaster_LeaveSanctioningAuthority", ci);
        grv_EmpDetails.Columns[34].Caption = rm.GetString("EmployeeMaster_OTEligible", ci);
        grv_EmpDetails.Columns[35].Caption = rm.GetString("EmployeeMaster_OTEligible", ci);
        grv_EmpDetails.Columns[36].Caption = rm.GetString("chk_EmployeeMaster_ExcludeFromReports", ci);
        grv_EmpDetails.Columns[37].Caption = rm.GetString("lbl_InActiveDate", ci);
        grv_EmpDetails.Columns[38].Caption = rm.GetString("Employee_CustomField1", ci);
        grv_EmpDetails.Columns[39].Caption = rm.GetString("Employee_CustomField2", ci);
        grv_EmpDetails.Columns[40].Caption = rm.GetString("Employee_CustomField3", ci);
        grv_EmpDetails.Columns[41].Caption = rm.GetString("Employee_CustomField4", ci);
        grv_EmpDetails.Columns[42].Caption = rm.GetString("Employee_CustomField5", ci);
        grv_EmpDetails.Columns[43].Caption = "Imported";
        grv_EmpDetails.Columns[44].Caption = rm.GetString("lblMobileClock", ci);
        grv_EmpDetails.Columns[45].Caption = "Department Name";
        //grv_EmpDetails.Columns[10].Caption = rm.GetString("EmployeeMaster_UserGroup", ci);

        lblEmpSwipe.Text = rm.GetString("Employee_Card_No_Status", ci);
        lblEmpSwipeCard.Text = rm.GetString("TerminalDataType_Card_No", ci);
        ddlSwipeOpt.Items[0].Text = rm.GetString("Select", ci);
        ddlSwipeOpt.Items[1].Text = rm.GetString("ExportData_All", ci);
        ddlSwipeOpt.Items[2].Text = rm.GetString("Report_Exists", ci);
        ddlSwipeOpt.Items[3].Text = rm.GetString("Report_NotExists", ci);
        lblDataView.Text = rm.GetString("lblDataView", ci);
        lblEmpCategory.Text = rm.GetString("lblEmpCategory", ci);
        lblEmpType.Text = rm.GetString("lblEmpType", ci);
        lblGender.Text = rm.GetString("EmployeeMaster_Gender", ci);
        lblAdvanced.Text = rm.GetString("lblFilter", ci);
        ddlEmpCatagory.Items[0].Text = rm.GetString("Select", ci);
        ddlEmpType.Items[0].Text = rm.GetString("Select", ci);
        ddlGender.Items[0].Text = rm.GetString("Caption_Both", ci);
        ddlGender.Items[1].Text = rm.GetString("rbtn_EmployeeMaster_Male", ci);
        ddlGender.Items[2].Text = rm.GetString("rbtn_EmployeeMaster_Female", ci);
        ddlAdvanced.Items[0].Text = rm.GetString("ExportData_All", ci);
        lblUserGroup.Text = rm.GetString("EmployeeMaster_UserGroup", ci);
        lblLeavepolicy.Text = rm.GetString("Employee_LeavePolicy", ci);
        lbl_ReportingTo.Text = rm.GetString("EmployeeMaster_ReportingTo", ci);
        lbl_LeaveSanctioninguthority.Text = rm.GetString("EmployeeMaster_LeaveSanctioningAuthority", ci);
        lbl_EmailID.Text = rm.GetString("EmployeeMaster_EmailId", ci);
        ckb_EmailAvail.Text = rm.GetString("EmpMaster_Available", ci);
        ckb_EmailNotAvail.Text = rm.GetString("EmpMaster_NotAvailable", ci);
        btn_Show.Text = "&nbsp;" + "&nbsp;" + "Advanced Filters";
        hlLeavebalance.Text = "&nbsp;" + rm.GetString("hl_ImportLeaveBalance", ci);
        lblImportNote.Text = rm.GetString("Field_ImportantNote", ci);



    }
    /// <summary>
    /// To check rights for the logged in user
    /// </summary>
    private void UserRights()
    {
        if (ViewState["vs_ds_Checkuser"] == null)
        {
            ds_Checkuser = objCheckUser.checkRights(18, Convert.ToInt32(Session["userGroup_Id"]), "");
            ViewState["vs_ds_Checkuser"] = ds_Checkuser;
        }
        else
            ds_Checkuser = (DataSet)ViewState["vs_ds_Checkuser"];
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 1)
            {
                this.btn_Add.Visible = true;
            }
            else
            {
                this.btn_Add.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.btn_Delete.Visible = true;
                this.grv_EmpDetails.Columns[9].Visible = true;
                this.grv_EmpDetails.Columns[0].Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
                this.grv_EmpDetails.Columns[9].Visible = false;
                this.grv_EmpDetails.Columns[0].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.grv_EmpDetails.Columns[8].Visible = true;
            }
            else
            {
                this.grv_EmpDetails.Columns[8].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
            {
                this.grv_EmpDetails.Columns[7].Visible = true;
            }
            else
            {
                this.grv_EmpDetails.Columns[7].Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    /// <summary>
    /// To check license to create a employee
    /// </summary>
    /// <returns></returns>
    private bool CheckNoOfEmployeeForLicense()
    {
        DemoVersion objDemoVersion = new DemoVersion();
        bool allowEmployeeAdd = true;
        string[] fileArr = Directory.GetFiles(Server.MapPath("../LicenseFile"), "*.lic");
        int arrCount = fileArr.Length;
        if (arrCount > 0)
        {
            string licenseFileName = Convert.ToString(fileArr[arrCount - 1]);
            FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
            StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
            string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
            licenseFileStreamReader.Close();
            licenseFileStream.Close();
            string decryptedLicFileInfo = string.Empty;
            try
            {
                decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
            }
            catch
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                strScript += "location.href='../Index.aspx';";
                strScript += " </script>";
                this.RegisterStartupScript("AlertLicInfoNotCorrect", strScript);
                return false;
            }
            string[] decryptedLicFileInfoArr = decryptedLicFileInfo.Split('#');
            string basicLicInfo = Convert.ToString(decryptedLicFileInfoArr[0]);
            string[] basicLicInfoArr = basicLicInfo.Split(',');
            int noOfEmployeeLicFile = Convert.ToInt32(basicLicInfoArr[4]);
            allowEmployeeAdd = objDemoVersion.RestoreCheckEmployeeCreation("License", noOfEmployeeLicFile);
            if (allowEmployeeAdd)
            {
                return true;
            }
            else
            {
                Message(rm.GetString("Alert_LicensenotallowtoRestoreEmployee", ci));
                return false;
            }
        }
        return true;
    }
    /// <summary>
    /// To load the employee data based on the sorting.
    /// </summary>
    protected void LoadEmployeeDetailsInGrid()
    {
        DataTable dtEmployee = new DataTable();
        dtEmployee = (DataTable)Session["EmployeeData"];
        DataView dvEmployee = new DataView(dtEmployee);
        if (ViewState["Sort_Field"] != null)
        {
            dvEmployee.Sort = Convert.ToString(ViewState["Sort_Field"]) + " " + Convert.ToString(ViewState["Sort_Order"]);
        }
        grv_EmpDetails.DataSource = dvEmployee;
        grv_EmpDetails.DataBind();
        Session["EmployeeData"] = dvEmployee.ToTable();
    }
    #endregion
    #region Grid events
    protected void grv_EmpDetails_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType == GridViewRowType.Data)
        {
            source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
            rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            Label DeletedRecord = (Label)grv_EmpDetails.FindRowCellTemplateControl(e.VisibleIndex, null, "lblIsDeleted");
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True" || DeletedRecord.Text == rm.GetString("Grid_True", ci))
                {
                    DeletedRecord.ForeColor = System.Drawing.Color.Red;
                }
            }
            HtmlInputCheckBox deleteChkBxItem = (HtmlInputCheckBox)grv_EmpDetails.FindRowCellTemplateControl(e.VisibleIndex, null, "chkSelect");
            LinkButton LnkbtnDelete = (LinkButton)grv_EmpDetails.FindRowCellTemplateControl(e.VisibleIndex, null, "btnDelete");
            if (deleteChkBxItem != null)
            {
                int Employee = Convert.ToInt32(e.GetValue("Employee_Id"));
                int Count = objEmployee.CountEmployee(Employee);
                if (Count > 0)
                {
                    deleteChkBxItem.Disabled = true;
                    LnkbtnDelete.Enabled = false;
                }
                else
                {
                    deleteChkBxItem.Disabled = false;
                    LnkbtnDelete.Enabled = true;
                }
            }
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True")
                {
                    DeletedRecord.Text = rm.GetString("Grid_True", ci);
                    if (hdnDeletedData.Value == string.Empty)
                    {
                        hdnDeletedData.Value = Convert.ToString(e.GetValue("Employee_Id"));
                    }
                    else
                    {
                        if (hdnDeletedData.Value.Contains(Convert.ToString(e.GetValue("Employee_Id"))) == false)
                        {
                            hdnDeletedData.Value = hdnDeletedData.Value + "," + Convert.ToString(e.GetValue("Employee_Id"));
                        }
                    }
                }
                else if (DeletedRecord.Text == "False")
                {
                    DeletedRecord.Text = rm.GetString("Grid_False", ci);
                }
            }
        }
    }
    protected void btnreset_Click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        string intEmpid = Convert.ToString(btn.CommandName);
        int Count = 0;
        Count = obj_ResetPwd.ResetPassword(intEmpid, "QL5OWbmiorXf+5GMDoaz1w==");
        string strScript = string.Empty;
        if (Count == 0)
            strScript = rm.GetString("Alert_EmployeeIdnotfound", ci);
        else
        {
            if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
            {
                isTriggered = objEmail.PassingEmpDetailsAndModuleForEmailTriggering("ResetPassword", intEmpid);
                if (isTriggered == 0 || isTriggered == -1)
                    strScript = rm.GetString("ReqField_PwdChanged", ci) + " for employee id: " + intEmpid;
                else if (isTriggered == 1)
                    strScript = rm.GetString("ReqField_PwdChanged_Employee", ci);
                else if (isTriggered == 2)
                    strScript = rm.GetString("ReqField_PwdChanged_MailServer", ci);
            }
            else
            {
                strScript = rm.GetString("ReqField_PwdChanged", ci) + " for employee id: " + intEmpid;
            }
        }
        Message(strScript);
        return;
    }
    #region "Fills UserGroup dropdown"
    private void GetUserGroupDetails()
    {
        DataSet ds_Usergroup = new DataSet();
        ds_Usergroup = objEmployee.select_Usergroupdetails();
        if (ds_Usergroup != null)
        {
            if (ds_Usergroup.Tables[0].Rows.Count > 0)
            {
                ddl_UserGroup.DataSource = ds_Usergroup;
                ddl_UserGroup.DataTextField = "groupName";
                ddl_UserGroup.DataValueField = "groupId";
                ddl_UserGroup.DataBind();
            }
            ds_Usergroup.Dispose();
        }
        BindTooltip(ddl_UserGroup);
    }
    #endregion
    #region "function fills Leave policy ddl"
    private void fillLeavePolicyddl()
    {
        DataSet ds_leavepolicy = new DataSet();
        ds_leavepolicy = objLeave.SelectAllLeavePolicy(string.Empty);
        if (ds_leavepolicy != null)
        {
            if (ds_leavepolicy.Tables[0].Rows.Count > 0)
            {
                ddl_LeavePolicy.DataSource = ds_leavepolicy;
                ddl_LeavePolicy.DataTextField = "PolicyName";
                ddl_LeavePolicy.DataValueField = "Policy_Id";
                ddl_LeavePolicy.DataBind();
            }
            ds_leavepolicy.Dispose();
        }
        BindTooltip(ddl_LeavePolicy);
    }
    #endregion
    #region fillReportingddl
    private void fillReportingddl()
    {
        DataSet ds_Reporting = new DataSet();
        ds_Reporting = objEmployee.SelectReportingPersonReport();
        if (ds_Reporting != null)
        {
            if (ds_Reporting.Tables[0].Rows.Count > 0)
            {
                ddl_ReportingTo.DataSource = ds_Reporting;
                ddl_ReportingTo.DataTextField = "Employee_FirstName";
                ddl_ReportingTo.DataValueField = "Employee_Id";
                ddl_ReportingTo.DataBind();
                ddl_LeaveSancAuthority.DataSource = ds_Reporting;
                ddl_LeaveSancAuthority.DataTextField = "Employee_FirstName";
                ddl_LeaveSancAuthority.DataValueField = "Employee_Id";
                ddl_LeaveSancAuthority.DataBind();
            }
        }
        BindTooltip(ddl_LeaveSancAuthority);
        BindTooltip(ddl_ReportingTo);
    }
    #endregion
    private void BindTooltip(DropDownList ddl)
    {
        foreach (ListItem item in ddl.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion    
}