using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Employee Master                             Last Modified : 27-Aug-2007
* Programmer      : Arun Vinoth.T
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          : \\Windev\EIT\Projects\Inprogress\SCREEN1206\code\TimecheckAVBackup
Modified By        :    Manjula.P
Modified Date      :    18-Jul-2013
Descriptions       :    Adding Leave type in Others tab.
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_EmployeeModify : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    LeaveEventData objLeaveEventData = new LeaveEventData();
    EmployeeEventData objEmployee = new EmployeeEventData();
    cls_Common objCommon = new cls_Common();
    LeaveEventData objLeave = new LeaveEventData();
    cls_Master_Transportation objRoute = new cls_Master_Transportation();
    YearSettingsEventData objYearsetting = new YearSettingsEventData();
    PayrollConfigurationEventData objPayrollData = new PayrollConfigurationEventData();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    YearClosureEventdata objYearClosureEventdata = new YearClosureEventdata();
    int payrollConfig = 0;
    Table tbLeaveType = new Table();
    DataSet dsLoadLeavetypes = new DataSet();
    string strGender;
    AttandanceCodeEventData objAttCode = new AttandanceCodeEventData();
    #region "Variable Declaration"
    int levelID = 0;
    int intLevelID = 0;
    int intCountry = 0;
    int intState = 0;
    int intNativeplace = 0;
    int intDesignation = 0;
    int intReporting = 0;
    int intLeaveSancAuthority = 0;
    int EmployeeID;
    int intEmpid;
    int intYearSettingsId;
    DataSet ds_Empdetails;
    string strEPassword = "", gstrDateFormat = "";
    byte[] image;
    DataTable dt_EmpPolicy;
    Boolean checkLeavePolicy = true;
    bool blnNoError = true;

    string finalCustomefile1 = string.Empty;
    string finalCustomefile2 = string.Empty;
    string finalCustomefile3 = string.Empty;
    string finalCustomefile4 = string.Empty;
    string finalCustomefile5 = string.Empty;
    #endregion
    protected override void Page_Load(object sender, EventArgs e)
    {
        UserRights();
        Session["ModeToDisplay"] = "1";
        base.Page_Load(sender, e);
        GC.Collect();
        string source_Language;
        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"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "ChMaxLengthh('" + rm.GetString("Alert_Maximumlengthis250", ci) + "');";
        strSetAlert = strSetAlert + "ChMaxLength500Fun('" + rm.GetString("Alert_Maximumlengthis500", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_Entervalid") + "','" + rm.GetString("Alert_number") + "','" + rm.GetString("Alert_Enterchildrendetails") + "','" + rm.GetString("Alert_Enterspousedetails") + "','" + rm.GetString("Alert_SelectorganizationlevelsEmployeeMaster") + "','" + rm.GetString("Alert_EnterEmployeeFirstName") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_EnterEmployeeLastName") + "','" + rm.GetString("Alert_SelectDOB") + "','" + rm.GetString("Alert_InvalidDOB") + "','" + rm.GetString("Alert_InvalidDOBRecord") + "','" + rm.GetString("Alert_EnterContactAddress") + "','" + rm.GetString("Alert_EnterValidEmailId") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_EnterEmployeeID") + "','" + rm.GetString("Alert_EmployeeIdshouldnotexceed15digits") + "','" + rm.GetString("Alert_SelectDOJ") + "','" + rm.GetString("Alert_InvalidDOJ") + "','" + rm.GetString("Alert_SelectDesignation") + "','" + rm.GetString("Alert_EnterPassword") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_Passwordshouldbeatleast5character") + "','" + rm.GetString("Req_confirmpassword") + "','" + rm.GetString("ALert_PasswordAndConfirmNotMatch") + "','" + rm.GetString("Alert_EnterCardNo") + "','" + rm.GetString("Alert_SelectEffectiveDateforLevel") + "','" + rm.GetString("Alert_EnterEmployeeBasicSalary") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_BasicSalaryshouldbegreaterthan0") + "','" + rm.GetString("Alert_SelectDesignationEffectiveDate") + "','" + rm.GetString("Alert_SelectBasicSalaryEffectiveDate") + "','" + rm.GetString("Alert_SelectEmployeeCategory") + "','" + rm.GetString("Alert_SelectEmployeeType") + "','" + rm.GetString("Alert_SelectEffectiveDateforCategory") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_SelectEffectiveDateforEmployeeType") + "','" + rm.GetString("Alert_OrgLeveleffdateshouldbeequaltoDOJ") + "','" + rm.GetString("Alert_DesigeffdateshouldbeequaltoDOJ") + "','" + rm.GetString("Alert_BasicsaleffdateshouldbeequaltoDOJ") + "','" + rm.GetString("Alert_EmpCateffdateshouldbeequaltoDOJ") + "','" + rm.GetString("Alert_EmpTypeeffdateshouldbeequaltoDOJ") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_DOJshouldbegreaterthanDOB") + "','" + rm.GetString("Alert_ClickCalculateButtontocalProrata") + "','" + rm.GetString("Alert_InvalidPassportExpiryDate") + "','" + rm.GetString("Alert_InvalidVisaExpiryDate") + "','" + rm.GetString("Alert_InvalidAnniversaryDate") + "','" + rm.GetString("Alert_SelectLeavePolicy") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_SaveEmployeeInformation") + "','" + rm.GetString("Alert_ErrorretrievingdatafromAuthority") + "','" + rm.GetString("Alert_EmployeeIDalreadyexists") + "','" + rm.GetString("Alert_SwipeCardNumberAlreadyExists") + "','" + rm.GetString("Alert_ErrorinretrivingdetailsfromLeavepolicymodify")
                            + "','" + rm.GetString("InactiveDateshouldbegreaterthanDOJ") + "','" + rm.GetString("Alert_SelectInActiveDateinOfficalTab") + "');";
        strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry") + "','" + rm.GetString("Alert_Invalidmonthentry") + "','" + rm.GetString("Alert_Invaliddateentry") + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY") + "','" + rm.GetString("Alert_Entertime") + "','" + rm.GetString("Alert_Invalidvalueforhours") + "','" + rm.GetString("Alert_Invalidvalueforminites") + "','" + rm.GetString("Alert_Invalidtimeformat1") + "','" + rm.GetString("Alert_PleaseentervalidDateandTime") + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM") + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT") + "','" + rm.GetString("Alert_PleaseentervalidDateandTime") + "','" + rm.GetString("Alert_Invalidvalueforhours") + "','" + rm.GetString("Alert_Invalidvalueforminites") + "');";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "SetAlert_AjaxChild('" + rm.GetString("Alert_EntertheChildrenintherangeof1to10", ci) + "','" + rm.GetString("Alert_NoDetailsfoundinChild", ci) + "','" + rm.GetString("Alert_Errorinretrivingdetails", ci) + "','" + rm.GetString("Alert_InvalidChildDOB", ci) + "');";
        strSetAlert = strSetAlert + "SetAlert_AjaxSpouse('" + rm.GetString("Alert_EntertheSpouseintherangeof1to4", ci) + "','" + rm.GetString("Alert_NoDetailsfoundinspouse", ci) + "','" + rm.GetString("Alert_Errorinretrivingdetailsfromspouse", ci) + "','" + rm.GetString("Alert_InvalidSpouseDOB", ci) + "','" + rm.GetString("Alert_EntertheSpouseintherangeof1to10", ci) + "');";
        strSetAlert = strSetAlert + "SetAlert_LeavePolicy('" + rm.GetString("Alert_FillLeavePolicy") + "','" + rm.GetString("Alert_Leavepolicydurationshouldnotbeempty") + "','" + rm.GetString("ALert_SelectDate") + "','" + rm.GetString("Alert_InValidDate") + "','" + rm.GetString("Alert_PolicyStartDateshouldbegreaterthantheDOJ") + "','" + rm.GetString("Alert_PolicyDatealreadyExists") + "','" + rm.GetString("Alert_FillStartDateandEndDate") + "','" + rm.GetString("Alert_NoDetailsfoundinEmpLeave") + "','" + rm.GetString("Alert_Errorinretrivingdetails") + "','" + rm.GetString("Alert_LeavePolicyNoDetailsfoundinEmpLeave") + "','" + rm.GetString("Alert_LeavePolicyErrorinretrivingdetails") + "','" + rm.GetString("Alert_PolicyDateContinutyMissing") + "','" + rm.GetString("AlertCompOffDayWise") + "');";
        strSetAlert = strSetAlert + "Alert_LookUp('" + rm.GetString("Alert_Errorretrievingdatafromlookup", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        if (Session.IsNewSession)
        {
            string strScriptSession = "";
            strScriptSession = strScriptSession + "<script language='javascript'>";
            strScriptSession = strScriptSession + "alert('" + rm.GetString("Alert_NewSessionCreated", ci) + "');";
            strScriptSession = strScriptSession + "</script>";
            Page.RegisterStartupScript("AlertShiftAllocationEmployeeModify", strScriptSession);
        }
        DivOfficial.Style.Add("display", "block");
        DivLeavePolicy.Style.Add("display", "block");
        DivOthers.Style.Add("display", "block");

        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        intEmpid = Convert.ToInt32(Request.QueryString["Emp_Id"]);
        Session["ModifiyEmployeeID"] = Convert.ToString(intEmpid);
        hdf_EmpID.Value = Convert.ToString(intEmpid);
        //To Handle AD integration Commented below line on 03-Aug-2020 04:29 PM.
        //txt_Username.Text = txt_EmpID.Text;
        blnNoError = true;
        DataSet ds_Year = objYearsetting.GetActiveYearSettings();
        string strScript = string.Empty;
        if (ds_Year.Tables.Count > 0)
        {
            if (ds_Year.Tables[0].Rows.Count > 0)
            {
                string strfrom = Convert.ToString(ds_Year.Tables[0].Rows[0]["FromDate"]);
                string strto = Convert.ToString(ds_Year.Tables[0].Rows[0]["ToDate"]);
                DateTime dtFrom = Convert.ToDateTime(strfrom);
                DateTime dtTo = Convert.ToDateTime(strto);
                hdf_PolVal.Value = dtFrom.ToShortDateString() + "*" + dtTo.ToShortDateString();
                intYearSettingsId = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
            }
            else
            {
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Alert_DefineYearSettinginOrganizationSettings", ci) + "');location.replace('../Organization Settings/Organization_YearSetting.aspx')";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("AlertYearSetting", strScript);
            }
        }
        else
        {
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_DefineYearSettinginOrganizationSettings", ci) + "');location.replace('../Organization Settings/Organization_YearSetting.aspx')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("AlertYearSetting", strScript);
        }
        txt_EmpFirstName.Focus();
        this.Page.RegisterStartupScript("pageldMod", "<script>var EmpID=" + intEmpid + "</script>");
        if (!Page.IsPostBack)
        {
            BindCustomizableFieldName();
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            this.Page.RegisterStartupScript("pageld", "<script>var checkPageLoad=0</script>");
            string strPage = "";
            if (Request.QueryString["curPage"] != null && Convert.ToString(Request.QueryString["curPage"]) != "")
            {
                strPage = Convert.ToString(Request.QueryString["curPage"]);
            }
            Page.RegisterStartupScript("divshow", "<script>div_show" + strPage + "();</script>");
            txt_ChildrenNo.Attributes.Add("onchange", "ajaxfunctionModify(" + intEmpid + ");");
            txt_SpouseNo.Attributes.Add("onchange", "ajaxfunctionModify_spouse(" + intEmpid + ");");
            BindingReligion();
            fillCategoryddl();
            fillTypeddl();
            GetBlocking420EmpDetail();
            GetEmpDetailsbyID(intEmpid);
            fillLeavePolicyDetials(intEmpid);
            Page.RegisterStartupScript("upload", "<script>ajaxfunctionModify(" + intEmpid + ")</script>");
            Page.RegisterStartupScript("spouse", "<script>ajaxfunctionModify_spouse(" + intEmpid + ")</script>");
            Page.RegisterStartupScript("Employee_LeavePolicy", "<script>ajaxLeavePolicyMod(" + intEmpid + ",'1','" + rm.GetString("Alert_ErrorinretrivingdetailsfromLeavepolicymodify", ci) + "')</script>");
            hdf_controlID.Value = "0";
            hdf_RowsMod.Value = "0";
            txt_ChildrenNo.Attributes.Add("onkeypress", "javascript:return number_only(event,this);");
            txt_SpouseNo.Attributes.Add("onkeypress", "javascript:return number_only(event,this);");
            objCommon.menu("EmployeeMaster", "18");
        }
        else
        {
            this.Page.RegisterStartupScript("pageload", "<script>var checkPageLoad=1</script>");
        }
        if (IsPostBack)
        {
            this.Page.RegisterStartupScript("pagepost", "<script>div_show_Post()</script>");
            try
            {
                if (Session["country"] != null)
                    intCountry = Convert.ToInt32(Session["country"]);
                if (Session["state"] != null)
                    intState = Convert.ToInt32(Session["state"]);
                if (Session["city"] != null)
                    intNativeplace = Convert.ToInt32(Session["city"]);
                if (Session["Designation"] != null)
                    intDesignation = Convert.ToInt32(Session["Designation"]);
                if (Session["Reporting"] != null && Convert.ToString(Session["Reporting"]) != "-Select-")
                    intReporting = Convert.ToInt32(Session["Reporting"]);
                if (Session["LeaveSanc"] != null && Convert.ToString(Session["LeaveSanc"]) != "-Select-")
                    intLeaveSancAuthority = Convert.ToInt32(Session["LeaveSanc"]);
                if (Session["Emp_Policy"] != null)
                    dt_EmpPolicy = (DataTable)Session["Emp_Policy"];
            }
            catch (Exception ex)
            {
                Message(ex.ToString());
            }
        }
        int count = 0;
        count = objYearClosureEventdata.CheckYearClosed(intEmpid);
        if (count > 0)
        {
            divLeavePolicyDuration.Visible = false;
            div_Leavepolicy.Visible = false;
            btn_AddPolicy.Visible = false;
            btn_View.Visible = false;
            Button1.Visible = false;
        }
        int otApprovalExists = 0;
        int leaveSanctionExists = 0;
        int manualEntryExists = 0;
        int PayrollconfigExists = 0;
        otApprovalExists = objCommon.CheckPageExistsInLicense(97);
        leaveSanctionExists = objCommon.CheckPageExistsInLicense(248);
        manualEntryExists = objCommon.CheckPageExistsInLicense(98);
        PayrollconfigExists= objCommon.CheckPageExistsInLicense(314);
        if (otApprovalExists == 0 && leaveSanctionExists == 0 && manualEntryExists == 0)
        {
            trStatus.Style.Add("display", "none");
        }
        if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) == "Express")
        {
            chk_CompOffAndOT.Enabled = false;
            chk_CompOffAndOT.Checked = false;
            chk_OTEligible.Enabled = false;
            chk_OTEligible.Checked = false;
            chk_CompOffEligible.Enabled = false;
            chk_CompOffEligible.Checked = false;
        }
        if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) != "Express" && Convert.ToString(Session["Demo"]) != "Standard")
        {
            LoadLeaveTypes();
        }
        /*Added New parameter(Max Days/Month)for Angler. For this we are checking whether the payroll configuration page is exists or not*/
        payrollConfig = objCommon.CheckPageExistsInLicense(185);
        /*Below parameter is used for Angler*/
        if (payrollConfig == 0)
        {
            divlblEntrance.Style.Add("display", "none");
            divddlEntrance.Style.Add("display", "none");
        }
        if (Convert.ToString(Session["packageID"]) != "")
        {
            if (Convert.ToString(Session["packageID"]) == "157") // Sohit admin
                divPenalty.Style.Add("display", "");
            //MTTS and Samsung Client
            else if (Convert.ToInt32(Session["packageID"]) == 169 || Convert.ToInt32(Session["packageID"]) == 168)  //vaigai and future clients
                DivMobileSMS.Style.Add("display", "none");
            else if (Convert.ToInt32(Session["packageID"]) < 159 && Convert.ToInt32(Session["packageID"]) != 169 && Convert.ToInt32(Session["packageID"]) == 168)  //vaigai and future clients
                DivMobileSMS.Style.Add("display", "none");
        }
        if(PayrollconfigExists==0)
        {
            DivPayrollPolicy.Style.Add("display","none");
            PH_Payroll.Style.Add("display", "None");
        }
        HdnEmployeeMaster.Value = "EmployeeMaster";
    }

    private void fillTaxPolicy()
    {
        DataSet ds_taxPolicy = new DataSet();
        Hashtable htaxpolicy = new Hashtable();
        htaxpolicy.Add("@tag", "SL");
        ds_taxPolicy = objPayrollData.InsertTaxPolicy(htaxpolicy);
        if (ds_taxPolicy != null)
        {
            if (ds_taxPolicy.Tables[0].Rows.Count > 0)
            {
                ddl_TaxPolicy.DataSource = ds_taxPolicy;
                ddl_TaxPolicy.DataValueField = "TaxPolicy_Id";
                ddl_TaxPolicy.DataTextField = "TaxPolicyName";
                ddl_TaxPolicy.DataBind();
            }
            ds_taxPolicy.Dispose();
        }
        BindTooltip(ddl_TaxPolicy);
    }
    private void BindTooltip(DropDownList ddl)
    {
        foreach (ListItem item in ddl_BusRouteNo.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void fillConveyanceAllowvance()
    {
        DataSet ds_CA = new DataSet();
        if (ViewState["CA_Policy"] != null)
        {
            ds_CA = (DataSet)ViewState["CA_Policy"];
        }
        else
        {
            Hashtable h_CA = new Hashtable();
            h_CA.Add("@tag", "S");
            h_CA.Add("@LevelID", Convert.ToInt32(Session["parentLevelId"]));
            ds_CA = objPayrollData.InsertandupdateConveyancePolicyDetails(h_CA);
            ViewState["CA_Policy"] = ds_CA;
        }

        if (ds_CA != null)
        {
            if (ds_CA.Tables[0].Rows.Count > 0)
            {
                ddl_CA.DataSource = ds_CA;
                ddl_CA.DataTextField = "ConPolicyName";
                ddl_CA.DataValueField = "C_Id";
                ddl_CA.DataBind();
            }
            ds_CA.Dispose();
        }
        foreach (ListItem item in ddl_PFESI.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }

   
    #region "Fills Category dropdowns"
    private void fillCategoryddl()
    {
        DataSet ds_Category = new DataSet();
        string UserGroupName = "";
        ds_Category = objEmployee.SelectCategoryDetailsEmployee(UserGroupName);
        if (ds_Category != null)
        {
            if (ds_Category.Tables[0].Rows.Count > 0)
            {
                ddlEmpCatagory.DataSource = ds_Category;
                ddlEmpCatagory.DataTextField = "CategoryName";
                ddlEmpCatagory.DataValueField = "CategoryId";
                ddlEmpCatagory.DataBind();
            }
            ds_Category.Dispose();
        }
        ListItem lstItem = new ListItem();
        lstItem.Value = "0";
        lstItem.Text = "Select";
        ddlEmpCatagory.Items.Insert(0, lstItem);
        foreach (ListItem item in ddlEmpCatagory.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region fillLeavepolicydetails
    private void fillLeavePolicyDetials(int employeeid)
    {
        DataSet ds_LPL = new DataSet();
        ds_LPL = objEmployee.select_EmpLeavepolicyLeaveDetails(employeeid);
        if (ds_LPL != null)
        {
            DataTable dt_LPL = new DataTable();
            dt_LPL = ds_LPL.Tables[0];
            if (dt_LPL != null)
            {
                if (dt_LPL.Rows.Count > 0)
                {
                    if (dt_LPL.Rows[0]["policy_Id"] != DBNull.Value)
                    {
                        ddl_LeavePolicy.SelectedValue = Convert.ToString(dt_LPL.Rows[0]["policy_Id"]);
                        hdf_PolicyID.Value = Convert.ToString(dt_LPL.Rows[0]["policy_Id"]);
                        hdf_PolicyName.Value = Convert.ToString(dt_LPL.Rows[0]["PolicyName"]);
                    }
                }
                dt_LPL.Dispose();
            }
            ds_LPL.Dispose();
        }
    }
    #endregion
    # region "Fills Type dropdowns"
    private void fillTypeddl()
    {
        DataSet ds_Type = new DataSet();
        string UserGroupName = "";
        ds_Type = objEmployee.SelectTypeDetailsEmployee(UserGroupName);
        if (ds_Type != null)
        {
            if (ds_Type.Tables[0].Rows.Count > 0)
            {
                ddlEmpType.DataSource = ds_Type;
                ddlEmpType.DataTextField = "TypeName";
                ddlEmpType.DataValueField = "TypeId";
                ddlEmpType.DataBind();
            }
            ds_Type.Dispose();
        }
        ListItem lstItem = new ListItem();
        lstItem.Value = "0";
        lstItem.Text = "Select";
        ddlEmpType.Items.Insert(0, lstItem);
        foreach (ListItem item in ddlEmpType.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region BindingEmployeeCategoryandType.
    private void BindingReligion()
    {
        DataSet dsReligion = new DataSet();
        dsReligion = objEmployee.SelectReligion();
        if (dsReligion != null)
        {
            if (dsReligion.Tables[0].Rows.Count > 0)
            {
                ddlReligion.DataSource = dsReligion;
                ddlReligion.DataTextField = "Name";
                ddlReligion.DataValueField = "Id";
                ddlReligion.DataBind();
            }
            dsReligion.Dispose();
        }
        foreach (ListItem item in ddlReligion.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region"Update EmployeeDetails
    protected void btn_Modify_Click(object sender, EventArgs e)
    {
        string strDob = string.Empty;
        string st = Convert.ToString(hdf_orgLevel.Value);
        if (Convert.ToInt32(Session["parentLevelId"]) == 0)
        {
            Session["parentLevelId"] = Convert.ToString(hdf_orgLevel.Value);
        }
        if (Convert.ToInt32(Session["parentLevelId"]) != 0)
        {
            int LeavePolicyId;
            strGender = CheckGender(rbtn_Male, rbtn_Female);
            int Religion = Convert.ToInt32(ddlReligion.SelectedValue);
            int EmpCategory = Convert.ToInt32(ddlEmpCatagory.SelectedValue);
            int EmpType = Convert.ToInt32(ddlEmpType.SelectedValue);
            if (Convert.ToString(ddl_LeavePolicy.SelectedItem.Value) != "-Select-")
            {
                LeavePolicyId = objEmployee.ValidateLeavePolicyByFilters(EmpCategory, EmpType, strGender, Religion, Convert.ToInt32(ddl_LeavePolicy.SelectedItem.Value));
                if (LeavePolicyId == 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_SelectVaildLeavePolicy", ci) + "');", true);
                    return;
                }
            }
            string strFirstname = txt_EmpFirstName.Text.Trim().Replace("'", "''");
            string strMiddlename = txt_MiddleName.Text.Trim().Replace("'", "''");
            string strLastname = txt_LastName.Text.Trim().Replace("'", "''");
            string strFathername = txt_FatherName.Text.Trim().Replace("'", "''");
            string strMothername = txt_MotherName.Text.Trim().Replace("'", "''");
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            if (txt_dob.Text != "")
            {
                strDob = objCommon.DateConvertion(gstrDateFormat, txt_dob.Text.Trim());
            }
            string strDobrecord = objCommon.DateConvertion(gstrDateFormat, txt_dobrecord.Text.Trim());
            string strBloodgroup = txt_BloodGroup.Text.Trim();
            string strEmailID = txt_EmailID.Text.Trim();
            string strContactaddress = txt_ContactAddress.Text.Trim();
            string strPermanentAddress = txt_PermanentAddress.Text.Trim();
            string strPhoneno = txt_PhoneNo.Text.Trim();
            string strMobileno = txt_MobileNo.Text.Trim();
            string strMstatus = CheckMstatus(rbtn_Single, rbtn_Married);
            string strNationality = txt_Nationality.Text.Trim();
            string strPersonalmailID = txt_PerEmailId.Text.Trim();
            string strPassportno = txt_PassportNo.Text.Trim();
            string strPexpiry = objCommon.DateConvertion(gstrDateFormat, txt_PExpiry.Text.Trim());
            string strVisano = txt_VisaNo.Text.Trim();
            string strVexpiry = objCommon.DateConvertion(gstrDateFormat, txt_VExpiry.Text.Trim());
            string strVehicletype = ddl_VehicleType.SelectedItem.Text;
            string strVehicleno = txt_VehicleNo.Text.Trim();
            string strAnniversarydate = objCommon.DateConvertion(gstrDateFormat, txt_AnniversaryDate.Text.Trim());
            string strDistrict = txt_District.Text.Trim();
            int intFlexibleTimings = 0;
            if (rbtnFlexibleTimingsYes.Checked == true)
            {
                intFlexibleTimings = 1;
            }
            if (rbtnFlexibleTimingsNo.Checked == true)
            {
                intFlexibleTimings = 0;
            }
            int intSpouseno = 0;
            if (txt_SpouseNo.Value.Trim() != "")
            {
                intSpouseno = Convert.ToInt32(txt_SpouseNo.Value.Trim());
            }
            else
            {
                intSpouseno = 0;
            }
            int intChildrenno = 0;
            if (txt_ChildrenNo.Value.Trim() != "")
            {
                intChildrenno = Convert.ToInt32(txt_ChildrenNo.Value.Trim());
            }
            else
            {
                intChildrenno = 0;
            }
            string strEmpcodeID = txt_EmpID.Text.Trim();
            if (Session["parentLevelId"] != null)
            {
                intLevelID = Convert.ToInt32(Session["parentLevelId"]);
            }
            else
            {
                intLevelID = levelID;
            }
            int intBusrouteno;
            if (ddl_BusRouteNo.Text == "-Select-")
            {
                intBusrouteno = 0;
            }
            else
            {
                intBusrouteno = Convert.ToInt32(ddl_BusRouteNo.SelectedValue);
            }
            string strUsergroup = "";
            for (int i = 1; i < ddl_UserGroup.Items.Count; i++)
            {
                if (ddl_UserGroup.Items[i].Selected == true)
                {
                    strUsergroup = ddl_UserGroup.Items[i].Value;
                    break;
                }
            }
            if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) != "Express")
            {
                if (ValidLeaveTypes() == false)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_EnterValidLeaveTaken", ci) + "');", true);
                    tbLeaveType.Focus();
                    return;
                }
            }
            string strDoj = objCommon.DateConvertion(gstrDateFormat, txt_doj.Text.Trim());
            if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) != "Express")
            {
                if (Convert.ToString(Session["PreviousYearCount"]) == "1")
                {
                    string strMsg = ValidateDOJPreviousYearBalance(strDoj);
                    if (strMsg != string.Empty)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + strMsg + "');", true);
                        phLeaveTypes.Focus();
                        return;
                    }
                }
            }
            TimeSpan tsYearDifference;
            if (strDob != "")
            {
                tsYearDifference = DateTime.Parse(strDoj).Subtract(DateTime.Parse(strDob));
                if (tsYearDifference.Ticks <= 0)
                {
                    blnNoError = false;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_DOJshouldbegreaterthanDOB", ci) + "');", true);
                    return;
                }
            }
            if (strPexpiry != "")
            {
                if (strDob != "")
                {
                    tsYearDifference = DateTime.Parse(strPexpiry).Subtract(DateTime.Parse(strDob));
                    if (tsYearDifference.Ticks <= 0)
                    {
                        blnNoError = false;
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_PassExpiryDateGreaterThanDOB", ci) + "');", true);
                        return;
                    }
                }
            }
            if (strVexpiry != "")
            {
                if (strDob != "")
                {
                    tsYearDifference = DateTime.Parse(strVexpiry).Subtract(DateTime.Parse(strDob));
                    if (tsYearDifference.Ticks <= 0)
                    {
                        blnNoError = false;
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_VisaExpiryDategreaterthanDOB", ci) + "');", true);
                        return;
                    }
                }
            }
            if (strAnniversarydate != "")
            {
                if (strDob != "")
                {
                    tsYearDifference = DateTime.Parse(strAnniversarydate).Subtract(DateTime.Parse(strDob));
                    if (tsYearDifference.Ticks <= 0)
                    {
                        blnNoError = false;
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_AnniversaryDategreaterThanDOB", ci) + "');", true);
                        return;
                    }
                }
            }
            float fltPrevexperience = 0;
            if (txt_PrevExperience.Text.Length > 0)
            {
                fltPrevexperience = Convert.ToSingle(txt_PrevExperience.Text);
            }
            float fltBasicsalary = 0;
            if (txt_BasicSalary.Text.Trim() != "")
            {
                fltBasicsalary = Convert.ToSingle(txt_BasicSalary.Text.Trim());
            }
            string strBasicSalEffDate = objCommon.DateConvertion(gstrDateFormat, txtBasicSalEffDate.Text.Trim());
            string strDesigEffDate = objCommon.DateConvertion(gstrDateFormat, txt_DesigEffDate.Text.Trim());
            string strLevelEffDate = objCommon.DateConvertion(gstrDateFormat, txteffDateLevel.Text.Trim());
            string strEmpCatEffDate = objCommon.DateConvertion(gstrDateFormat, txtEmpCatEffDate.Text.Trim());
            string strEmpTypeEffDate = objCommon.DateConvertion(gstrDateFormat, txtEmpTypEffDate.Text.Trim());
            string strEmpContractEffDate = objCommon.DateConvertion(gstrDateFormat, txtConEffectiveDate.Text.Trim());
            string strUsername = txt_Username.Text.Trim();
            string strPassWord = hdfPass.Value;
            string strQualJoining = txt_QualAtJoiningTime.Text.Trim();
            string strQualEmployment = txt_QualDurEmployment.Text.Trim();
            int blOutdoorEmployee = CheckOutDoor(chk_OutdoorEmployee);
            int blOTeligible = WhetherOTEligible(chk_OTEligible);
            int blCOffeligible = WhetherCOffEligible(chk_CompOffEligible);
            int blESIeligible = WhetherESIEligible(chk_EligibleESI);
            int blPFeligible = WhetherPFEligible(chk_EligiblePF);
            int blExclReport = WhetherReportExclude(chk_ReportsExcl);
            int blActiveness = CheckActiveness(rbtn_Active, rbtn_Inactive);
            bool blHostelWorker = CheckHostelWorker(rbtn_HostelYes, rbtn_HostelNo);
            string strSwipecardNo = txt_SwipeCardNo.Text.Trim();
            string inActiveDate;
            if (rbtn_Inactive.Checked == true)
            {
                if (txtInActive.Text == string.Empty)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_PleaseSelectInActiveDate", ci) + "');", true);
                    return;
                }
                else
                {
                    inActiveDate = objCommon.DateConvertion(gstrDateFormat, txtInActive.Text.Trim());
                }
            }
            else
            {
                inActiveDate = "";
            }
            if (fup_Photo.HasFile)
            {
                string strphotofile = fup_Photo.PostedFile.FileName;
                int index = strphotofile.LastIndexOf(".");
                string strFileFormat = strphotofile.Substring(index + 1).ToLower();
                if (strFileFormat == "png" || strFileFormat == "jpg" || strFileFormat == "bmp" || strFileFormat == "gif")
                {
                    image = fup_Photo.FileBytes;
                }
                else
                {
                    blnNoError = false;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_PleaseSelectJPGorGIForBMPFileforPhoto", ci) + "');", true);
                    return;
                }
            }
            else if (fup_Photo.PostedFile.FileName == "")
            {
                ds_Empdetails = objEmployee.Select_EmployeeDetailsbyId(intEmpid);
                if (ds_Empdetails.Tables[0].Rows.Count > 0)
                {
                    if (Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Photo"]) != "")
                    {
                        image = (byte[])ds_Empdetails.Tables[0].Rows[0]["Photo"];
                    }
                }
            }
            int intEmpCategory = 0, intEmpType = 0, intReligion = 0;
            if (ddlEmpCatagory.SelectedIndex == 0)
            {
                blnNoError = false;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_SelectEmployeeCategory", ci) + "');", true);
                return;
            }
            else
            {
                intEmpCategory = Convert.ToInt32(ddlEmpCatagory.SelectedValue);
            }
            intReligion = Convert.ToInt32(ddlReligion.SelectedValue);
            if (ddlEmpType.SelectedIndex == 0)
            {
                blnNoError = false;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_SelectEmployeeType", ci) + "');", true);
                return;
            }
            else
            {
                intEmpType = Convert.ToInt32(ddlEmpType.SelectedValue);
            }
            if (intDesignation == 0)
            {
                intDesignation = Convert.ToInt32(ddl_Designation.SelectedValue);
            }
            if (intDesignation == 0)
            {
                blnNoError = false;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_SelectDesignation", ci) + "');", true);
                return;
            }
            if (Convert.ToString(ddl_EntranceName.SelectedItem.Value) != "-Select-")
            {
                objEmployee.Insert_EmployeeEntranceDetails(strEmpcodeID, Convert.ToInt32(ddl_EntranceName.SelectedItem.Value));
            }
            int penaltyCat = 0;
            int MobileClockInOut = 0;
            int SMS = 0;
            if (Convert.ToString(Session["packageID"]) != "")
            {
                if (Convert.ToString(Session["packageID"]) == "157")
                    penaltyCat = (rbtnDisruptive.Checked) ? 1 : 0;
            }
            MobileClockInOut = (rbtnMobileClockYes.Checked) ? 1 : 0;
            SMS = (rbtnSMSEnable.Checked) ? 1 : 0;
           
            // Maria Prasanth developed by payroll config

            string strPFESI = "";

            int ddlcount = ddl_PFESI.SelectedIndex;


            if (ddl_PFESI.SelectedIndex!=0)
            {
                for (int i = 1; i < ddl_PFESI.Items.Count; i++)
                {
                    if (ddl_PFESI.Items[i].Selected == true)
                    {
                        if (strPFESI == "")
                        {
                            strPFESI = ddl_PFESI.Items[i].Value;
                        }
                        else
                        {
                            strPFESI = strPFESI + "," + ddl_PFESI.Items[i].Value;
                        }
                    }
                    else
                    {
                        strPFESI = "0";
                    }
                }
            }
            else
            {
                strPFESI = "0";
            }
            
           


            string strConveyance = "";
            if(ddl_CA.SelectedIndex!=0)
            {
                for (int i = 1; i < ddl_CA.Items.Count; i++)
                {
                    if (ddl_CA.Items[i].Selected == true)
                    {
                        if (strConveyance == "")
                        {
                            strConveyance = ddl_CA.Items[i].Value;

                        }
                        else
                        {
                            strConveyance = strConveyance + "," + ddl_CA.Items[i].Value;
                        }
                    }
                    else
                    {
                        strConveyance = "0";
                    }
                }
            }
            else
            {
                strConveyance = "0";
            }
            
            // Maria Prasanth Payroll Config
            int hra = 0;
            int Da = 0;
            int PFESI = 0;
            int CA = 0;
            int Medical = 0;
            int ChildAllowance = 0;
            int Tax_policy = 0;
            Int64 CTC = 0;

            if (Convert.ToInt32(dd_HRA.SelectedValue) == 1)
            {
                hra = 1;
            }
            else
            {
                hra = 0;
            }
            Da = 1;

            if (rbtn_CEAYes.Checked)
            {
                ChildAllowance = 1;
            }
            else
            {
                ChildAllowance = 0;
            }

            if (rbtn_MediaclYes.Checked)
            {
                Medical = 1;
            }
            else
            {
                Medical = 0;
            }

            if(Convert.ToString(ddl_TaxPolicy.SelectedValue) == "-Select-" || Convert.ToString(ddl_TaxPolicy.SelectedValue)==string.Empty)
            {
               Tax_policy = ddl_TaxPolicy.SelectedIndex;
            }
            else
            {
                Tax_policy = Convert.ToInt32(ddl_TaxPolicy.SelectedValue);
            }

            PFESI = Convert.ToInt32(strPFESI);

            CA = Convert.ToInt32(strConveyance);

            CTC = Convert.ToInt64(Convert.ToString(txtCurrentCTC.Text)==""?"0": txtCurrentCTC.Text);

            //Added by Velumani on Feb 28 for Product
            bool IsPassportReminderRequired = false;
            int PassportRemindDays = 0;
            bool IsVisaReminderRequired = false;
            int VisaRemindDays = 0;
            IsPassportReminderRequired = (chk_IspassportRemindReq.Checked) ? true : false;
            IsVisaReminderRequired = (chk_IsVisaRemindReq.Checked) ? true : false;
            if (txtPassportRemindDayscount.Text.Trim() != "")
            {
                PassportRemindDays = Convert.ToInt32(txtPassportRemindDayscount.Text.Trim());
            }
            if (txtVisaRemindDayscount.Text.Trim() != "")
            {
                VisaRemindDays = Convert.ToInt32(txtVisaRemindDayscount.Text.Trim());
            }
            if (blnNoError == true)
            {
                int count = objEmployee.CheckDuplicateEmployeeCodeupdate(strEmpcodeID, intEmpid, Convert.ToBoolean(Session["ApplnMode"]));
                if (count == 0)
                {
                    bool isAllowAdd = false;
                    isAllowAdd = CheckNoOfEmployeeForLicense(Convert.ToBoolean(ViewState["vsBlActiveness"]), blActiveness);
                    if (isAllowAdd)
                    {
                        objEmployee.InsertUpdateEmployeeDetails("U", intEmpid, intLevelID, strUsergroup, intDesignation,
                                  intBusrouteno, strFirstname, strMiddlename, strLastname, strFathername,
                                  strMothername, strDob, strDobrecord, strBloodgroup, strEmailID, strContactaddress, strPermanentAddress,
                                  strPhoneno, strMobileno, strGender, strMstatus, strNationality, intReligion, image,
                                  strPersonalmailID, strPassportno, strPexpiry, strVisano, strVexpiry, strVehicletype,
                                  strVehicleno, strAnniversarydate, intNativeplace, strDistrict, intState, intCountry,
                                  intSpouseno, intChildrenno, strEmpcodeID, strDoj, intReporting,
                                  intLeaveSancAuthority, fltPrevexperience, fltBasicsalary, blHostelWorker, strUsername, strPassWord,
                                  strQualJoining, strQualEmployment, blOutdoorEmployee, blCOffeligible, blOTeligible,
                                  blESIeligible, blPFeligible, blExclReport, blActiveness, strSwipecardNo, intEmpCategory, intEmpType,
                                  EmployeeID, strBasicSalEffDate, strDesigEffDate, intYearSettingsId, strLevelEffDate, strEmpCatEffDate,
                                  strEmpTypeEffDate, intFlexibleTimings, inActiveDate, Convert.ToString(txtCustomField1.Text), Convert.ToString(txtCustomField2.Text), Convert.ToString(txtCustomField3.Text),
                                  Convert.ToString(txtCustomField4.Text), Convert.ToString(txtCustomField5.Text), Convert.ToBoolean(Session["ApplnMode"]), penaltyCat, MobileClockInOut, SMS,
                                  IsPassportReminderRequired, PassportRemindDays, IsVisaReminderRequired, VisaRemindDays, hra, Da, Medical, CA, PFESI, Tax_policy, ChildAllowance, CTC,
                                  Convert.ToInt32(ddlContractor.SelectedValue), strEmpContractEffDate, Convert.ToString(txtCustomField6.Text));
                        if (hid_Children.Value != "")
                        {
                            objEmployee.delete_EmployeeChildren(intEmpid);
                            ChildrenData(intEmpid);
                        }
                        else
                        {
                            objEmployee.delete_EmployeeChildren(intEmpid);
                        }
                        UpdateLeaveTypeDetails(intEmpid);
                        if (hid_Spouse.Value != "")
                        {
                            objEmployee.delete_EmployeeSpouse(intEmpid);
                            SpouseData(intEmpid);
                        }
                        else
                        {
                            objEmployee.delete_EmployeeSpouse(intEmpid);
                        }
                        if (hdf_Policy.Value != "")
                        {
                            if (hdf_Policy.Value == "MappedPolicy@~%")
                            {
                            }
                            else
                            {
                                LeavePolicyData(intEmpid);
                            }
                        }
                        else
                        {
                            objEmployee.delete_EmployeeLeavePolicy(intEmpid);
                        }
                        if (checkLeavePolicy == true)
                        {
                            Session["country"] = null;
                            Session["state"] = null;
                            Session["city"] = null;
                            Session["Designation"] = null;
                            Session["Reporting"] = null;
                            Session["LeaveSanc"] = null;
                            Session["Rowcount"] = null;
                            Random rnd = new Random();
                            string str = "alert('" + rm.GetString("Alert_EmployeeModifiedSucessfully", ci) + "');location.replace('TA_UI_Master_Employee.aspx');";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                        }
                        int intRawDataCount = 0;
                        intRawDataCount = objEmployee.RawDataCountEmployee(strSwipecardNo);
                        if (intRawDataCount == 0)
                        {
                            updateBioAdmin(strSwipecardNo);
                        }
                    }
                }
                else
                {
                    blnNoError = false;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_EmployeeIDalreadyexists", ci) + "');", true);
                }
            }
        }
        else
        {
            blnNoError = false;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + rm.GetString("Alert_Selectallorganizationlevels", ci) + "');", true);
        }
    }
    private bool CheckNoOfEmployeeForLicense(bool vsActive, int blActiveness)
    {
        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.DVCheckEmployeeCreation("License", noOfEmployeeLicFile, vsActive, blActiveness);
            if (allowEmployeeAdd)
            {
                return true;
            }
            else
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Alert_LicensenotallowtomodifyEmployee", ci) + "');";
                strScript += " </script>";
                this.RegisterStartupScript("setScript", strScript);
                return false;
            }
        }
        return true;
    }
    #endregion
    private void updateBioAdmin(string strSwipecardNo)
    {
        DataTable dtTerminalDataType = new DataTable();
        DataSet dsTerminalDataType = new DataSet();
        string strBioAdminConnection = string.Empty;
        string strTableName = string.Empty;
        string strSwipeCardFieldName = string.Empty;
        string strRDBMS_MDBFlag = string.Empty;
        TerminalDatatypeEventData objTerminalDatatypeEventData = new TerminalDatatypeEventData();
        dsTerminalDataType = objTerminalDatatypeEventData.Select_TerminalDatatype("AllActive");
        if (dsTerminalDataType.Tables.Count > 0)
        {
            dtTerminalDataType = dsTerminalDataType.Tables[0].Copy();
        }
        if (dtTerminalDataType.Rows.Count > 0)
        {
            foreach (DataRow drTerminalDataType in dtTerminalDataType.Rows)
            {
                if (drTerminalDataType["FileType"] != DBNull.Value)
                {
                    strBioAdminConnection = Encryption.Decrypt(Convert.ToString(drTerminalDataType["ConnectionString"]), "");
                    strTableName = Convert.ToString(drTerminalDataType["TableName"]);
                    strRDBMS_MDBFlag = Convert.ToString(drTerminalDataType["RDBMS_MDB_Flag"]);
                    if (Convert.ToString(drTerminalDataType["FileType"]) == "RDBMS")
                    {
                        strSwipeCardFieldName = Convert.ToString(drTerminalDataType["RDBMS_CardNo"]);
                        objEmployee.BioAdminUpdate(strBioAdminConnection, strTableName, strRDBMS_MDBFlag, strSwipeCardFieldName, strSwipecardNo);
                    }
                    else if (Convert.ToString(drTerminalDataType["FileType"]) == "MDB")
                    {
                        string[] connectionStringArr = strBioAdminConnection.Split(';');
                        string checkStringSource = "Data Source";
                        checkStringSource = checkStringSource.ToUpper();
                        string connection = string.Empty, strFileName = string.Empty;
                        for (int i = 0; i < connectionStringArr.Length - 1; i++)
                        {
                            string[] initialCatalogPart = connectionStringArr[i].Split('=');
                            string checkStringInput = Convert.ToString(initialCatalogPart[0]);
                            checkStringInput = checkStringInput.ToUpper();
                            if (checkStringSource == checkStringInput)
                            {
                                strFileName = Convert.ToString(initialCatalogPart[1]);
                            }
                        }
                        if (File.Exists(strFileName) == true)
                        {
                            strSwipeCardFieldName = Convert.ToString(drTerminalDataType["MDB_CardNo"]);
                            objEmployee.BioAdminUpdate(strBioAdminConnection, strTableName, strRDBMS_MDBFlag, strSwipeCardFieldName, strSwipecardNo);
                        }
                        strFileName = string.Empty;
                    }
                }
            }
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Session["country"] = null;
        Session["state"] = null;
        Session["city"] = null;
        Session["Designation"] = null;
        Session["Reporting"] = null;
        Session["LeaveSanc"] = null;
        Session["Rowcount"] = null;
        Session["parentLevelId"] = "0";
        Response.Redirect("TA_UI_Master_Employee.aspx");
    }
    #region"Function Which fills Employee details"
    /// <summary>
    /// Get Employee Details using Employee auto id.
    /// </summary>
    /// <param name="Empid"></param>
    private void GetEmpDetailsbyID(int Empid)
    {
        string detenew = DateTime.Today.ToShortDateString();
        ds_Empdetails = new DataSet();
        ds_Empdetails = objEmployee.Select_EmployeeDetailsbyId(Empid);
        bool blOutdoorEmployee = false, blOTeligible = false, blCOffeligible = false, blESI = false, blPF = false, blExRep = false, blActiveness = false, blHostelWorker = false
            , blIsVisaRemindReq = false, blIspassportRemindReq = false;
        if (ds_Empdetails != null)
        {
            if (ds_Empdetails.Tables[0].Rows.Count > 0)
            {
                divPenalty.Style.Add("display", "none");
                if (Convert.ToString(Session["packageID"]) != "")
                {
                    if (Convert.ToString(Session["packageID"]) == "157")
                    {
                        //PACKAGEID 156 - Sohit Admin
                        divPenalty.Style.Add("display", "");
                        if (ds_Empdetails.Tables[0].Rows[0]["penalty"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["penalty"]) != "")
                        {
                            if (Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["penalty"]) == true)
                            {
                                rbtnDisruptive.Checked = true;
                                rbtnNonDisruptive.Checked = false;
                            }
                            else if (Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["penalty"]) == false)
                            {
                                rbtnDisruptive.Checked = false;
                                rbtnNonDisruptive.Checked = true;
                            }
                        }
                    }
                }
                if (ds_Empdetails.Tables[0].Rows[0]["MobileClockInOUt"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["MobileClockInOUt"]) != "")
                {
                    if (Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["MobileClockInOUt"]) == 1)
                    {
                        rbtnMobileClockYes.Checked = true;
                        rbtnMobileClockNo.Checked = false;
                    }
                    else if (Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["MobileClockInOUt"]) == 0)
                    {
                        rbtnMobileClockNo.Checked = true;
                        rbtnMobileClockYes.Checked = false;
                    }
                }
                if (ds_Empdetails.Tables[0].Rows[0]["SMSEnabled"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["SMSEnabled"]) != "")
                {
                    if (Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["SMSEnabled"]) == 1)
                    {
                        rbtnSMSEnable.Checked = true;
                        rbtnSMSDisable.Checked = false;
                    }
                    else if (Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["SMSEnabled"]) == 0)
                    {
                        rbtnSMSDisable.Checked = true;
                        rbtnSMSEnable.Checked = false;
                    }
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Employee_FirstName"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_FirstName"]) != "")
                    txt_EmpFirstName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_FirstName"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Employee_MiddleName"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_MiddleName"]) != "")
                    txt_MiddleName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_MiddleName"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Employee_LastName"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_LastName"]) != "")
                    txt_LastName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_LastName"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Father_name"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Father_name"]) != "")
                    txt_FatherName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Father_name"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Mother_name"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Mother_name"]) != "")
                    txt_MotherName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Mother_name"]);
                DateTime date1 = new DateTime();
                DateTime date2 = new DateTime();
                DateTime date3 = new DateTime();
                DateTime date4 = new DateTime();
                DateTime date5 = new DateTime();
                DateTime date6 = new DateTime();
                if (ds_Empdetails.Tables[0].Rows[0]["DateofBirth"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["DateofBirth"]) != "")
                {
                    date1 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["DateofBirth"]);
                    txt_dob.Text = date1.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["DateofBirth_Record"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["DateofBirth_Record"]) != "")
                {
                    date2 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["DateofBirth_Record"]);
                    txt_dobrecord.Text = date2.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["LevelEffDate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["LevelEffDate"]) != string.Empty)
                {
                    DateTime dateLevel = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["LevelEffDate"]);
                    txteffDateLevel.Text = dateLevel.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Blood_Group"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Blood_Group"]) != "")
                    txt_BloodGroup.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Blood_Group"]);
                if (ds_Empdetails.Tables[0].Rows[0]["EmailId"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["EmailId"]) != "")
                    txt_EmailID.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["EmailId"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Contact_Address"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Contact_Address"]) != "")
                    txt_ContactAddress.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Contact_Address"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Permanent_Address"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Permanent_Address"]) != "")
                    txt_PermanentAddress.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Permanent_Address"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Phone_Number"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Phone_Number"]) != "")
                    txt_PhoneNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Phone_Number"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Mobile_Number"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Mobile_Number"]) != "")
                    txt_MobileNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Mobile_Number"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Photo"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Photo"]) != "")
                {
                    try
                    {
                        DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "Masters");
                        FileInfo[] files = dir.GetFiles("*.bmp");
                        foreach (FileInfo file in files)
                        {
                            string str = AppDomain.CurrentDomain.BaseDirectory + "Masters\\";
                            File.Delete(str + Convert.ToString(file));
                        }
                        Random rnd = new Random();
                        string strPath = "Employee_Photo_" + intEmpid + ".bmp";
                        byte[] storedImage = (byte[])(ds_Empdetails.Tables[0].Rows[0]["Photo"]);
                        MemoryStream stream = new MemoryStream(storedImage);
                        System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
                        img.Save(Server.MapPath(strPath));
                        img.Dispose();
                        img_Photo.ImageUrl = strPath + "?rnd=" + rnd.NextDouble();
                    }
                    catch (Exception ex)
                    {
                        Message(ex.ToString());
                    }
                }
                else
                {
                    img_Photo.ImageUrl = "../dist/img/emp-photo.png";
                }
                string strGender = "", strMstatus = "";
                if (ds_Empdetails.Tables[0].Rows[0]["Gender"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Gender"]) != "")
                {
                    strGender = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Gender"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Marital_status"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Marital_status"]) != "")
                {
                    strMstatus = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Marital_status"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Nationality"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Nationality"]) != "")
                {
                    txt_Nationality.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Nationality"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["ReligionId"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["ReligionId"]) != "")
                {
                    if (ddlReligion.Items.FindByValue(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["ReligionId"])).Enabled)
                    {
                        ddlReligion.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["ReligionId"]);
                    }
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Personal_mailid"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Personal_mailid"]) != "")
                {
                    txt_PerEmailId.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Personal_mailid"]);
                }
                fillLookupddl();
                string strcountry = string.Empty;
                string strState = string.Empty;
                string strCity = string.Empty;
                if (ds_Empdetails.Tables[0].Rows[0]["country"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["country"]) != "")
                {
                    ddl_Country.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["country"]);
                    strcountry = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["country"]);
                    if (strcountry != "0")
                    {
                        intCountry = Convert.ToInt32(ddl_Country.SelectedValue);
                        Session["country"] = ddl_Country.SelectedValue;
                        fillStateddl(intCountry);
                        if (ds_Empdetails.Tables[0].Rows[0]["state"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["state"]) != "")
                        {
                            ddl_State.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["state"]);
                            strState = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["state"]);
                            if (strState != "0")
                            {
                                intState = Convert.ToInt32(ddl_State.SelectedValue);
                                Session["state"] = ddl_State.SelectedValue;
                                fillCityddl(intState);
                                if (ds_Empdetails.Tables[0].Rows[0]["Native_Place"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Native_Place"]) != "")
                                {
                                    ddl_City.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Native_Place"]);
                                    strCity = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Native_Place"]);
                                    if (strCity != "0")
                                    {
                                        intNativeplace = Convert.ToInt32(ddl_City.SelectedValue);
                                        Session["city"] = ddl_City.SelectedValue;
                                    }
                                }
                            }
                        }
                    }
                }
                if (ds_Empdetails.Tables[0].Rows[0]["LevelID"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["LevelID"]) != "")
                {
                    Session["parentLevelId_modify"] = Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["LevelID"]);
                    levelID = Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["LevelID"]);
                    String Check = Convert.ToString(hdf_Levelalert1.Value);
                    if (hdf_Levelalert1.Value=="select" || hdf_Levelalert1.Value.ToString() ==String.Empty)
                    {
                        if(levelID.ToString() != "" && levelID.ToString() != null)
                        {
                            hdf_Levelalert1.Value = levelID.ToString();
                            
                        }
                    }
                    
                }
                if (ds_Empdetails.Tables[0].Rows[0]["IsFlexible"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["IsFlexible"]) != "")
                {
                    if (Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["IsFlexible"]) == 0)
                    {
                        rbtnFlexibleTimingsNo.Checked = true;
                        rbtnFlexibleTimingsYes.Checked = false;
                    }
                    else if (Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["IsFlexible"]) == 1)
                    {
                        rbtnFlexibleTimingsYes.Checked = true;
                        rbtnFlexibleTimingsNo.Checked = false;
                    }
                }
                int companyId = 0;
                org_levelsEventData getOrg = new org_levelsEventData();
                getOrg.GetOrgParentLevels_FromID(levelID);
                DataSet ds_getOrg = new DataSet();
                ds_getOrg = getOrg.GetOrgParentLevels();
                if (ds_getOrg != null)
                {
                    if (ds_getOrg.Tables[0].Rows.Count > 0)
                    {
                        companyId = Convert.ToInt32(ds_getOrg.Tables[0].Rows[0]["LevelID"]);
                    }
                }
                int intFlexibleCount = 0;
                intFlexibleCount = objEmployee.SelectFlexibleEmployeeDetails(companyId);
                if (intFlexibleCount > 0)
                {
                    divLabelFlexible.Visible = true;
                    divRadioFlexibleTimings.Visible = true;
                }
                else
                {
                    divLabelFlexible.Visible = false;
                    divRadioFlexibleTimings.Visible = false;
                }
                GetUserGroupDetails();
                if (ds_Empdetails.Tables[0].Rows[0]["UserGroup_Id"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["UserGroup_Id"]) != "")
                {
                    string usergroupID = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["UserGroup_Id"]);
                    string[] UID = usergroupID.Split(",".ToCharArray());
                    foreach (string item in UID)
                    {
                        for (int i = 0; i < ddl_UserGroup.Items.Count; i++)
                        {
                            if (ddl_UserGroup.Items[i].Value == item)
                            {
                                ddl_UserGroup.Items[i].Selected = true;
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }
                fillDesignationddl(companyId);
                if (ds_Empdetails.Tables[0].Rows[0]["Designation_Id"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Designation_Id"]) != "")
                {
                    ddl_Designation.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Designation_Id"]);
                    Session["DesignationId_modify"] = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Designation_Id"]);
                }
                int designationID = 0;
                if (ddl_Designation.SelectedValue != "-Select-")
                {
                    designationID = Convert.ToInt32(ddl_Designation.SelectedValue);
                    Session["Designation"] = ddl_Designation.SelectedValue;
                    hidEmpDesg.Value = Convert.ToString(Session["Designation"]);
                    fillReportingddl(designationID);
                    if (ds_Empdetails.Tables[0].Rows[0]["Reporting_To"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Reporting_To"]) != "")
                    {
                        ddl_ReportingTo.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Reporting_To"]);
                        Session["Reporting_To_modify"] = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Reporting_To"]);
                    }
                    Session["Reporting"] = ddl_ReportingTo.SelectedValue;
                    if (ds_Empdetails.Tables[0].Rows[0]["Leave_Sanc_Authority"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Leave_Sanc_Authority"]) != "")
                    {
                        ddl_LeaveSancAuthority.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Leave_Sanc_Authority"]);
                        Session["Leave_Sanc_Authority_modify"] = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Leave_Sanc_Authority"]);
                    }
                    Session["LeaveSanc"] = ddl_LeaveSancAuthority.SelectedValue;
                }
                if (ds_Empdetails.Tables[0].Rows[0]["EDesigEffectDate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["EDesigEffectDate"]) != "")
                {
                    DateTime dateDesig = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["EDesigEffectDate"]);
                    txt_DesigEffDate.Text = dateDesig.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Passport_No"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Passport_No"]) != "")
                {
                    txt_PassportNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Passport_No"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Passport_expirydate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Passport_expirydate"]) != "")
                {
                    date3 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["Passport_expirydate"]);
                    txt_PExpiry.Text = date3.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                txt_VisaNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Visa_No"]);
                if (ds_Empdetails.Tables[0].Rows[0]["Visa_expirydate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Visa_expirydate"]) != "")
                {
                    date4 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["Visa_expirydate"]);
                    txt_VExpiry.Text = date4.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Vehicle_Type"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Vehicle_Type"]) != "")
                {
                    ddl_VehicleType.SelectedIndex = ddl_VehicleType.Items.IndexOf(ddl_VehicleType.Items.FindByText(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Vehicle_Type"])));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Vehicle_No"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Vehicle_No"]) != "")
                {
                    txt_VehicleNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Vehicle_No"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Anniversary_Date"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Anniversary_Date"]) != "")
                {
                    date5 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["Anniversary_Date"]);
                    txt_AnniversaryDate.Text = date5.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                fillEntrance();
                if (ds_Empdetails.Tables[0].Rows[0]["Entrance_Name"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Entrance_Name"]) != "")
                {
                    ddl_EntranceName.SelectedIndex = ddl_EntranceName.Items.IndexOf(ddl_EntranceName.Items.FindByText(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Entrance_Name"])));
                }
                fillContractor();
                if (ds_Empdetails.Tables[0].Rows[0]["Contractor_Id"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Contractor_Id"]) != "")
                {
                    ddlContractor.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Contractor_Id"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["ContractorEffDate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["ContractorEffDate"]) != string.Empty)
                {
                    DateTime dateLevel = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["ContractorEffDate"]);
                    txtConEffectiveDate.Text = dateLevel.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["District"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["District"]) != string.Empty)
                {
                    txt_District.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["District"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Spouse_No"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Spouse_No"]) != string.Empty)
                {
                    txt_SpouseNo.Value = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Spouse_No"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Children_No"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Children_No"]) != string.Empty)
                {
                    txt_ChildrenNo.Value = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Children_No"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Employee_Code_Id"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_Code_Id"]) != string.Empty)
                {
                    txt_EmpID.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_Code_Id"]);
                }
                GetRouteDetails();
                if (ds_Empdetails.Tables[0].Rows[0]["Bus_Id"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Bus_Id"]) != string.Empty)
                {
                    ddl_BusRouteNo.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Bus_Id"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["DateOfJoining"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["DateOfJoining"]) != string.Empty)
                {
                    date6 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["DateOfJoining"]);
                    txt_doj.Text = date6.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                string prev = "0.00";
                if (ds_Empdetails.Tables[0].Rows[0]["Prev_Experience"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Prev_Experience"]) != string.Empty)
                {
                    prev = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Prev_Experience"]);
                }
                if (prev == "0.00")
                {
                    txt_PrevExperience.Text = "";
                }
                else
                {
                    txt_PrevExperience.Text = prev;
                }
                string sal = "0";
                if (ds_Empdetails.Tables[0].Rows[0]["Basic_Salary"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Basic_Salary"]) != string.Empty)
                {
                    sal = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Basic_Salary"]);
                }
                if (sal == "0")
                {
                    txt_BasicSalary.Text = "";
                }
                else
                {
                    txt_BasicSalary.Text = sal;
                }
                if (ds_Empdetails.Tables[0].Rows[0]["EPayEffectDate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["EPayEffectDate"]) != string.Empty)
                {
                    DateTime dateBPay = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["EPayEffectDate"]);
                    txtBasicSalEffDate.Text = dateBPay.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["CategoryId"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CategoryId"]) != string.Empty)
                {
                    ddlEmpCatagory.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CategoryId"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["CategoryEffDate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CategoryEffDate"]) != string.Empty)
                {
                    DateTime dateCategory = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["CategoryEffDate"]);
                    txtEmpCatEffDate.Text = dateCategory.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                if (ds_Empdetails.Tables[0].Rows[0]["TypeId"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["TypeId"]) != string.Empty)
                {
                    ddlEmpType.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["TypeId"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["TypeEffDate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["TypeEffDate"]) != string.Empty)
                {
                    DateTime dateType = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["TypeEffDate"]);
                    txtEmpTypEffDate.Text = dateType.ToString(Convert.ToString(Session["MDateFormat"]));
                }
                fillLeavePolicyddl();
                if (ds_Empdetails.Tables[0].Rows[0]["UserName"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["UserName"]) != string.Empty)
                {
                    txt_Username.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["UserName"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Emp_password"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Emp_password"]) != string.Empty)
                {
                    hdfPass.Value = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Emp_password"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Qual_JoiningTime"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Qual_JoiningTime"]) != string.Empty)
                {
                    txt_QualAtJoiningTime.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Qual_JoiningTime"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Qual_Employment"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Qual_Employment"]) != string.Empty)
                {
                    txt_QualDurEmployment.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Qual_Employment"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["OutDoorJob"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["OutDoorJob"]) != string.Empty)
                {
                    blOutdoorEmployee = Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["OutDoorJob"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["OT_Eligible"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["OT_Eligible"]) != string.Empty)
                {
                    blOTeligible = Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["OT_Eligible"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["CompOff_Eligible"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CompOff_Eligible"]) != string.Empty)
                {
                    blCOffeligible = Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["CompOff_Eligible"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["ESI_Eligible"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["ESI_Eligible"]) != string.Empty)
                {
                    blESI = Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["ESI_Eligible"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["PF_Eligible"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["PF_Eligible"]) != string.Empty)
                {
                    blPF = Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["PF_Eligible"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Report_Exclude"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Report_Exclude"]) != string.Empty)
                {
                    blExRep = Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["Report_Exclude"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Employee_Status"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_Status"]) != string.Empty)
                {
                    blActiveness = Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["Employee_Status"]);
                    if (blActiveness == false)
                    {
                        txtInActive.Enabled = true;
                    }
                    ViewState["vsBlActiveness"] = blActiveness;
                }
                if (Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["Employee_Status"]) == false)
                {
                    if (ds_Empdetails.Tables[0].Rows[0]["InActiveDate"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["InActiveDate"]) != string.Empty)
                    {
                        DateTime dtInactiveDate1 = new DateTime();
                        txtInActive.Enabled = true;
                        dtInactiveDate1 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["InActiveDate"]);
                        txtInActive.Text = dtInactiveDate1.ToString(Convert.ToString(Session["MDateFormat"]));
                        ViewState["InActiveDate"] = txtInActive.Text;
                    }
                }
                if (ds_Empdetails.Tables[0].Rows[0]["Hostel"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Hostel"]) != string.Empty)
                {
                    blHostelWorker = Convert.ToBoolean(ds_Empdetails.Tables[0].Rows[0]["Hostel"]);
                }

                if (ds_Empdetails.Tables[0].Rows[0]["SwipeCardNo"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["SwipeCardNo"]) != string.Empty)
                {
                    txt_SwipeCardNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["SwipeCardNo"]);
                }
                string strpath = "";
                if (ds_Empdetails.Tables[0].Rows[0]["Photo"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Photo"]) != string.Empty)
                {
                    strpath = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Photo"]);
                }
                if (ds_Empdetails.Tables[0].Rows[0]["CustomField1"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField1"]) != string.Empty)
                {
                    txtCustomField1.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField1"]);
                    //if (File.Exists(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField1"])))
                    //{
                    //    finalCustomefile1 = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField1"]);
                    //    hdnpdfViewer1.Value = finalCustomefile1;
                    //    btnCustomAdd1.Visible = false;
                    //    btnCustomView1.Visible = true;
                    //}
                    //else
                    //{
                    //    btnCustomAdd1.Visible = true;
                    //    btnCustomView1.Visible = false;
                    //}

                }
                if (ds_Empdetails.Tables[0].Rows[0]["CustomField2"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField2"]) != string.Empty)
                {
                    txtCustomField2.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField2"]);
                    //if (File.Exists(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField2"])))
                    //{
                    //    finalCustomefile2 = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField2"]);
                    //    hdnpdfViewer2.Value = finalCustomefile2;
                    //    btnCustomAdd2.Visible = false;
                    //    btnCustomView2.Visible = true;
                    //}
                    //else
                    //{
                    //    btnCustomAdd2.Visible = true;
                    //    btnCustomView2.Visible = false;
                    //}
                }
                if (ds_Empdetails.Tables[0].Rows[0]["CustomField3"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField3"]) != string.Empty)
                {
                    txtCustomField3.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField3"]);
                    //if (File.Exists(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField3"])))
                    //{
                    //    finalCustomefile3 = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField3"]);
                    //    hdnpdfViewer3.Value = finalCustomefile3;
                    //    btnCustomAdd3.Visible = false;
                    //    btnCustomView3.Visible = true;
                    //}
                    //else
                    //{
                    //    btnCustomAdd3.Visible = true;
                    //    btnCustomView3.Visible = false;
                    //}
                }
                if (ds_Empdetails.Tables[0].Rows[0]["CustomField4"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField4"]) != string.Empty)
                {
                    txtCustomField4.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField4"]);
                    //if (File.Exists(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField4"])))
                    //{
                    //    finalCustomefile4 = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField4"]);
                    //    hdnpdfViewer4.Value = finalCustomefile4;
                    //    btnCustomAdd4.Visible = false;
                    //    btnCustomView4.Visible = true;
                    //}
                    //else
                    //{
                    //    btnCustomAdd4.Visible = true;
                    //    btnCustomView4.Visible = false;
                    //}
                }
                if (ds_Empdetails.Tables[0].Rows[0]["CustomField5"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField5"]) != string.Empty)
                {
                    txtCustomField4.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField5"]);
                    //if (File.Exists(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField5"])))
                    //{
                    //    finalCustomefile5 = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField5"]);
                    //    hdnpdfViewer5.Value = finalCustomefile5;
                    //    btnCustomAdd5.Visible = false;
                    //    btnCustomView5.Visible = true;
                    //}
                    //else
                    //{
                    //    btnCustomAdd5.Visible = true;
                    //    btnCustomView5.Visible = false;
                    //}
                }
                if (ds_Empdetails.Tables[0].Rows[0]["CustomField6"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField6"]) != string.Empty)
                {
                    txtCustomField6.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField6"]);
                    //if (File.Exists(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField5"])))
                    //{
                    //    finalCustomefile5 = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField5"]);
                    //    hdnpdfViewer5.Value = finalCustomefile5;
                    //    btnCustomAdd5.Visible = false;
                    //    btnCustomView5.Visible = true;
                    //}
                    //else
                    //{
                    //    btnCustomAdd5.Visible = true;
                    //    btnCustomView5.Visible = false;
                    //}
                }
                fillTaxPolicy();

                String taxpolicyId = string.Empty;
                if (ds_Empdetails.Tables[0].Rows[0]["Tax_Policy"]!=DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Tax_Policy"])!=string.Empty)
                {
                    taxpolicyId = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Tax_Policy"]);
                    ddl_TaxPolicy.SelectedValue = taxpolicyId;
                }
                else
                {
                    ddl_TaxPolicy.SelectedIndex = 0;
                }
                GetPFESIPolicy();
                if (ds_Empdetails.Tables[0].Rows[0]["PF_Policy"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["PF_Policy"]) != string.Empty)
                {
                    string PFpolicyId = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["PF_Policy"]);
                    Session["PFESI_modify"] = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["PF_Policy"]);
                    if (PFpolicyId== "0")
                    {
                        ddl_PFESI.SelectedIndex = 0;
                    }
                    else
                    {
                        string[] PID = PFpolicyId.Split(",".ToCharArray());

                        foreach (string item in PID)
                        {
                            for (int i = 0; i < ddl_PFESI.Items.Count; i++)
                            {
                                if (ddl_PFESI.Items[i].Value == item)
                                {
                                    ddl_PFESI.Items[i].Selected = true;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    
                }
                else
                {
                    ddl_PFESI.SelectedIndex=0;
                }
               
                fillConveyanceAllowvance();
                if (ds_Empdetails.Tables[0].Rows[0]["CA"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CA"]) != string.Empty)
                {
                    String CAId = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CA"]);
                    if(CAId=="0")
                    {
                        ddl_CA.SelectedIndex = 0;
                    }
                    else
                    {
                        string[] C_AllowanceID = CAId.Split(",".ToCharArray());
                        foreach (string item in C_AllowanceID)
                        {
                            for (int i = 0; i < ddl_CA.Items.Count; i++)
                            {
                                if (ddl_CA.Items[i].Value == item)
                                {
                                    ddl_CA.Items[i].Selected = true;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                    }
                   
                }
                else
                {
                    ddl_CA.SelectedIndex = 0;

                }
                int HraID = 0;
                if (ds_Empdetails.Tables[0].Rows[0]["HRA"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["HRA"]) != string.Empty)
                {
                    HraID = Convert.ToInt32(ds_Empdetails.Tables[0].Rows[0]["HRA"]);
                    
                    if(HraID==0)
                    {
                        rbtn_HraNo.Checked = true;
                        rbtn_Hrayes.Checked = false;

                    }
                    else
                    {
                        rbtn_Hrayes.Checked = true;
                        rbtn_HraNo.Checked = false;
                    }

                    if(rbtn_Hrayes.Checked)
                    {
                        dd_HRA.SelectedIndex = HraID;
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "EnableDisableDropdwon()", true);

                    }
                }

                int Medical_Allowance = 0;

                if(ds_Empdetails.Tables[0].Rows[0]["MedicalAlllowance"]!=DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["MedicalAlllowance"]) != string.Empty)
                {
                    Medical_Allowance = Convert.ToInt16(ds_Empdetails.Tables[0].Rows[0]["MedicalAlllowance"]);
                    if(Medical_Allowance==0)
                    {
                        rbtn_MediaclNo.Checked = true;
                        rbtn_MediaclYes.Checked = false;
                    }
                    else
                    {
                        rbtn_MediaclYes.Checked = true;
                        rbtn_MediaclNo.Checked = false;
                    }
                }

                int CEAId = 0;
                if (ds_Empdetails.Tables[0].Rows[0]["CEDAllowance"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CEDAllowance"]) != string.Empty)
                {
                    CEAId = Convert.ToInt16(ds_Empdetails.Tables[0].Rows[0]["CEDAllowance"]);
                    if (CEAId == 0)
                    {
                        rbtn_CEANo.Checked = true;
                        rbtn_CEAYes.Checked = false;
                    }
                    else
                    {
                        rbtn_CEAYes.Checked = true;
                        rbtn_CEANo.Checked = false;
                    }
                }

                if(ds_Empdetails.Tables[0].Rows[0]["Emp_Ctc"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Emp_Ctc"]) != string.Empty)
                {
                    txtCurrentCTC.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Emp_Ctc"]);
                }
                //end

                checkGender(strGender);
                checkMstatus(strMstatus);
                checkoutdoor(blOutdoorEmployee);
                checkCoffeligible(blCOffeligible);
                checkOTeligible(blOTeligible);
                checkstatus(blActiveness);
                checkHostelWorker(blHostelWorker);
                checkESIelig(blESI);
                checkPFelig(blPF);
                checkExclReport(blExRep);

              
            }
            ds_Empdetails.Dispose();
        }
    }

    private void fillReportingddl(int designationID)
    {
        DataSet ds_Reporting = new DataSet();
        ds_Reporting = objEmployee.SelectReportingPerson(designationID);
        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();
            }
            ds_Reporting.Dispose();
        }
        foreach (ListItem item in ddl_ReportingTo.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
        foreach (ListItem item in ddl_LeaveSancAuthority.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void fillDesignationddl(int levelID)
    {
        DataSet ds_designation = new DataSet();
        ds_designation = objEmployee.select_Designationdetails(levelID);
        if (ds_designation != null)
        {
            if (ds_designation.Tables[0].Rows.Count > 0)
            {
                ddl_Designation.DataSource = ds_designation;
                ddl_Designation.DataTextField = "TitleName";
                ddl_Designation.DataValueField = "TitleId";
                ddl_Designation.DataBind();
            }
            ds_designation.Dispose();
        }
        foreach (ListItem item in ddl_Designation.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void fillDesignation()
    {
        DataSet ds_designation = new DataSet();
        ds_designation = objEmployee.select_CommonDesignation();
        if (ds_designation != null)
        {
            if (ds_designation.Tables[0].Rows.Count > 0)
            {
                ddl_Designation.DataSource = ds_designation;
                ddl_Designation.DataTextField = "TitleName";
                ddl_Designation.DataValueField = "TitleId";
                ddl_Designation.DataBind();
            }
            ds_designation.Dispose();
        }
        foreach (ListItem item in ddl_Designation.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void fillStateddl(int country)
    {
        DataSet ds_state = new DataSet();
        ds_state = objEmployee.SelectStates(country);
        if (ds_state != null)
        {
            if (ds_state.Tables[0].Rows.Count > 0)
            {
                ddl_State.DataSource = ds_state;
                ddl_State.DataTextField = "Title";
                ddl_State.DataValueField = "ID";
                ddl_State.DataBind();
            }
            ds_state.Dispose();
        }
        foreach (ListItem item in ddl_State.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void fillCityddl(int state)
    {
        DataSet ds_city = new DataSet();
        ds_city = objEmployee.SelectCities(state);
        if (ds_city != null)
        {
            if (ds_city.Tables[0].Rows.Count > 0)
            {
                ddl_City.DataSource = ds_city;
                ddl_City.DataTextField = "Title";
                ddl_City.DataValueField = "ID";
                ddl_City.DataBind();
            }
            ds_city.Dispose();
        }
        foreach (ListItem item in ddl_City.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void checkESIelig(bool blESIelig)
    {
        if (blESIelig == true)
            chk_EligibleESI.Checked = true;
        else
            chk_EligibleESI.Checked = false;
    }
    private void checkPFelig(bool blPFelig)
    {
        if (blPFelig == true)
            chk_EligiblePF.Checked = true;
        else
            chk_EligiblePF.Checked = false;
    }
    private void checkExclReport(bool blExReport)
    {
        if (blExReport == true)
            chk_ReportsExcl.Checked = true;
        else
            chk_ReportsExcl.Checked = false;
    }
    private void checkGender(string strGender)
    {
        if (strGender == "Male")
            rbtn_Male.Checked = true;
        if (strGender == "Female")
            rbtn_Female.Checked = true;
    }
    private void checkMstatus(string mstatus)
    {
        if (mstatus == "Single")
            rbtn_Single.Checked = true;
        if (mstatus == "Married")
            rbtn_Married.Checked = true;
    }
    private void checkoutdoor(bool outdoor)
    {
        if (outdoor == true)
            chk_OutdoorEmployee.Checked = true;
        else
            chk_OutdoorEmployee.Checked = false;
    }
    private void checkOTeligible(bool OTeligibility)
    {
        if (OTeligibility == true)
            chk_OTEligible.Checked = true;
        else
            chk_OTEligible.Checked = false;
        chk_CompOffAndOT.Checked = (chk_CompOffEligible.Checked && chk_OTEligible.Checked);
    }
    private void checkCoffeligible(bool Coffeligibility)
    {
        if (Coffeligibility == true)
            chk_CompOffEligible.Checked = true;
        else
            chk_CompOffEligible.Checked = false;
    }
    private void checkstatus(bool status)
    {
        if (status == true)
            rbtn_Active.Checked = true;
        else
            rbtn_Inactive.Checked = true;
    }
    private void checkHostelWorker(bool HostelWorker)
    {
        if (HostelWorker == true)
            rbtn_HostelYes.Checked = true;
        else
            rbtn_HostelNo.Checked = true;

        lblhostel.Text = HostelWorker.ToString();
    }
    private void checkVisaReminder(bool visaReminder)
    {
        if (visaReminder == true)
            chk_IsVisaRemindReq.Checked = true;
        else
            chk_IsVisaRemindReq.Checked = false;
    }

    private void checkPassportReminder(bool passportReminder)
    {
        if (passportReminder == true)
            chk_IspassportRemindReq.Checked = true;
        else
            chk_IspassportRemindReq.Checked = false;
    }
    #endregion
    #region"Function returns Employee Marital status"
    private string CheckMstatus(RadioButton r1, RadioButton r2)
    {
        string mstatus = "";
        if (r1.Checked == true)
            mstatus = "Single";
        if (r2.Checked == true)
            mstatus = "Married";
        return mstatus;
    }
    #endregion
    #region"Function returns EmployeeGender"
    private string CheckGender(RadioButton r1, RadioButton r2)
    {
        string Gender = "";
        if (r1.Checked == true)
            Gender = "Male";
        if (r2.Checked)
            Gender = "Female";
        return Gender;
    }
    #endregion
    #region"Function returns Employee Activeness"
    private int CheckActiveness(RadioButton r1, RadioButton r2)
    {
        int Activeness = 1;
        if (r1.Checked == true)
            Activeness = 1;
        if (r2.Checked == true)
            Activeness = 0;
        return Activeness;
    }
    #endregion
    #region"Function returns Employee HostelWorker"
    private bool CheckHostelWorker(RadioButton r1, RadioButton r2)
    {
        bool HostelWorker = true;
        if (r1.Checked == true)
            HostelWorker = true;
        if (r2.Checked == true)
            HostelWorker = false;
        return HostelWorker;
    }
    #endregion
    #region"Function Checks whether Employee is OutdoorEmployee"
    private int CheckOutDoor(CheckBox chkout)
    {
        int Outdoor = 1;
        if (chkout.Checked == true)
            Outdoor = 1;
        if (chkout.Checked == false)
            Outdoor = 0;
        return Outdoor;
    }
    #endregion
    #region "function return OT eligible"
    private int WhetherOTEligible(CheckBox OTEligible)
    {
        int oteligible = 0;
        if (OTEligible.Checked == true)
        {
            oteligible = 1;
        }
        return oteligible;
    }
    #endregion
    #region "function return Coff eligible"
    private int WhetherCOffEligible(CheckBox CoffEligible)
    {
        int coffeligible = 0;
        if (CoffEligible.Checked == true)
        {
            coffeligible = 1;
        }
        return coffeligible;
    }
    #endregion
    #region "function return ESI eligible"
    private int WhetherESIEligible(CheckBox ESIEligible)
    {
        int esieligible = 0;
        if (ESIEligible.Checked == true)
        {
            esieligible = 1;
        }
        return esieligible;
    }
    #endregion
    #region "function return PF eligible"
    private int WhetherPFEligible(CheckBox PFEligible)
    {
        int pfeligible = 0;
        if (PFEligible.Checked == true)
        {
            pfeligible = 1;
        }
        return pfeligible;
    }
    #endregion
    #region "function return Exclusion from Reports"
    private int WhetherReportExclude(CheckBox ReportExcl)
    {
        int exclreports = 0;
        if (ReportExcl.Checked == true)
        {
            exclreports = 1;
        }
        return exclreports;
    }
    #endregion
    #region"Function Converts Image into byte Array"
    private byte[] GetbinaryData(string file)
    {
        byte[] photo;
        int filelength = file.Length;
        FileStream fs_Photo = new FileStream(file, FileMode.Open);
        BinaryReader br_Photo = new BinaryReader(fs_Photo);
        photo = br_Photo.ReadBytes(filelength);
        fs_Photo.Close();
        return photo;
    }
    #endregion
    #region "Function 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();
        }
        foreach (ListItem item in ddl_UserGroup.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion

    private void GetPFESIPolicy()
    {
        DataSet ds_PFESI = new DataSet();
        if (ViewState["PF_ESI_Policy"] != null)
        {
            ds_PFESI = (DataSet)ViewState["PF_ESI_Policy"];
        }
        else
        {
            
            Hashtable h_PFESI = new Hashtable();
            h_PFESI.Add("@tag", "S");
            h_PFESI.Add("@levelID", Convert.ToInt32(Session["parentLevelId"]));
            ds_PFESI = objPayrollData.InsertPFESIPolicyDetails(h_PFESI);
            ViewState["PF_ESI_Policy"] = ds_PFESI;
        }

        if (ds_PFESI != null)
        {
            if (ds_PFESI.Tables[0].Rows.Count > 0)
            {
                ddl_PFESI.DataSource = ds_PFESI;
                ddl_PFESI.DataTextField = "PFESI_PolicyName";
                ddl_PFESI.DataValueField = "PFESI_Id";
                ddl_PFESI.DataBind();
            }
            ds_PFESI.Dispose();
        }
        foreach (ListItem item in ddl_PFESI.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }


    #region "Fills Route dropdown"
    private void GetRouteDetails()
    {
        DataSet ds_Route = new DataSet();
        string usergroupname = string.Empty;
        ds_Route = objRoute.SelectTransportationRouteDetails(usergroupname);
        if (ds_Route != null)
        {
            if (ds_Route.Tables[0].Rows.Count > 0)
            {
                ddl_BusRouteNo.DataSource = ds_Route;
                ddl_BusRouteNo.DataTextField = "Route_Name";
                ddl_BusRouteNo.DataValueField = "Id";
                ddl_BusRouteNo.DataBind();
            }
            ds_Route.Dispose();
        }
        foreach (ListItem item in ddl_BusRouteNo.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    # region "Fills Country dropdowns"
    private void fillLookupddl()
    {
        DataSet ds_country = new DataSet();
        ds_country = objEmployee.SelectCountries();
        if (ds_country != null)
        {
            if (ds_country.Tables[0].Rows.Count > 0)
            {
                ddl_Country.DataSource = ds_country;
                ddl_Country.DataTextField = "Title";
                ddl_Country.DataValueField = "ID";
                ddl_Country.DataBind();
            }
            ds_country.Dispose();
        }
        foreach (ListItem item in ddl_Country.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region "function fills Leave policy ddl"
    private void fillLeavePolicyddl()
    {
        DataSet ds_leavepolicy = new DataSet();
        ds_leavepolicy = objLeaveEventData.SelectLeavePolicyDetailsBasedOnFilter(Convert.ToInt32(ddlEmpCatagory.SelectedItem.Value), Convert.ToInt32(ddlEmpType.SelectedItem.Value), strGender, Convert.ToInt32(ddlReligion.SelectedItem.Value));
        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();
        }
        foreach (ListItem item in ddl_LeavePolicy.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region  "Function insert spouse data"
    private void SpouseData(int MaxID)
    {
        string spouse_data = hid_Spouse.Value;
        if (spouse_data != "")
        {
            char[] comma = { ',' };
            char[] star = { '*' };
            string[] spousename = { };
            string[] spouse = spouse_data.Split(star);
            for (int i = 0; i < spouse.Length; i++)
            {
                string data = spouse[i];
                spousename = data.Split(comma);
                objEmployee.InsertSpouseDetails(MaxID, spousename[0], objCommon.DateConvertion(gstrDateFormat, spousename[1]), EmployeeID);
            }
        }
    }
    #endregion
    #region  "Function insert Children data"
    private void ChildrenData(int MaxID)
    {
        string children_data = hid_Children.Value;
        if (children_data != "")
        {
            char[] comma = { ',' };
            char[] star = { '*' };
            string[] childrenname = { };
            string[] children = children_data.Split(star);
            for (int i = 0; i < children.Length; i++)
            {
                string data = children[i];
                childrenname = data.Split(comma);
                objEmployee.InsertChildrenDetails(MaxID, childrenname[0], objCommon.DateConvertion(gstrDateFormat, childrenname[1]), EmployeeID);
            }
        }
    }
    #endregion
    #region  "Function insert Leave policy data"
    private void LeavePolicyData(int MaxID)
    {
        bool notYearClosure = false;
        string LeavePolicy_data = hdf_Policy.Value;
        if (LeavePolicy_data != "" & LeavePolicy_data != "undefined")
        {
            char[] comma = { ',' };
            char[] star = { '*' };
            string[] policy = { };
            string[] policydetails = LeavePolicy_data.Split(star);
            string[] StartDateArr = new string[10];
            string[] EndDateArr = new string[10];
            for (int i = 0; i < policydetails.Length; i++)
            {
                string[] details = policydetails[i].Split(comma);
                if ((details[0] != "") && (details[1] != ""))
                {
                    StartDateArr[i] = details[0];
                    EndDateArr[i] = details[1];
                }
            }
            for (int i = 0; i < policydetails.Length; i++)
            {
                string datas = policydetails[i];
                policy = datas.Split(comma);
                if (i > 0)
                {
                    DateTime dtmPrevStartDate = Convert.ToDateTime(objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), StartDateArr[i - 1]));
                    DateTime dtmPrevEndDate = Convert.ToDateTime(objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), EndDateArr[i - 1]));
                    DateTime dtmStartDate = Convert.ToDateTime(objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), StartDateArr[i]));
                    DateTime dtmEndDate = Convert.ToDateTime(objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), EndDateArr[i]));
                    if (dtmStartDate > dtmPrevStartDate && dtmStartDate > dtmPrevEndDate && dtmEndDate > dtmPrevStartDate && dtmEndDate > dtmPrevEndDate)
                    {
                    }
                    else
                    {
                        checkLeavePolicy = false;
                        return;
                    }
                }
            }
            DataSet ds_ELP = objEmployee.select_EmpLP(intEmpid);
            foreach (DataRow dr in ds_ELP.Tables[0].Rows)
            {
                for (int i = 0; i < policydetails.Length; i++)
                {
                    string data = policydetails[i];
                    policy = data.Split(comma);
                    objEmployee.delete_EmployeeLeavePolicy(intEmpid);
                }
            }
            int checkLeavePolicyValue = 1;
            for (int i = 0; i < policydetails.Length; i++)
            {
                string data = policydetails[i];
                policy = data.Split(comma);
                string fromdt = objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), policy[0]);
                string todt = objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), policy[1]);
                objEmployee.InsertLeavePolicy(MaxID, Convert.ToInt32(policy[2]), fromdt, todt, EmployeeID);
                int MaxLPID = objEmployee.select_MaxEmpLeavepolicyIDUpdated(fromdt, todt, MaxID);
                if (dt_EmpPolicy != null)
                {
                    DataRow[] dr = dt_EmpPolicy.Select("LeavePolicyValue=" + Convert.ToInt32(checkLeavePolicyValue));
                    if (policydetails.Length == 1)
                    {
                        if (dt_EmpPolicy.Rows.Count > 0)
                        {
                            if (MaxLPID > 0)
                            {
                                for (int j = 0; j < dr.Length; j++)
                                {
                                    int PolicyID = Convert.ToInt32(dr[j]["PolicyId"]);
                                    int LeavetypeID = Convert.ToInt32(dr[j]["LeaveTypeId"]);
                                    decimal Maxdays = Convert.ToDecimal(dr[j]["MaxDays"]);
                                    decimal Maxdays_month = Convert.ToDecimal(dr[j]["MaxDays_month"]);
                                    objEmployee.InsertEmpLeavePolicyDetails(MaxID, MaxLPID, PolicyID, LeavetypeID, Maxdays, EmployeeID, Maxdays_month);
                                    if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) != "Express")
                                    {
                                        if (Convert.ToDecimal(GetMaxDays(LeavetypeID)) > -1)
                                            objEmployee.InsertYearclosure(intLevelID, MaxID, LeavetypeID, Convert.ToDecimal(GetMaxDays(LeavetypeID)), EmployeeID);
                                        else
                                            objEmployee.InsertYearclosure(intLevelID, MaxID, LeavetypeID, Maxdays, EmployeeID);
                                    }
                                    if (Convert.ToDecimal(GetMaxDays(LeavetypeID)) <= -1)
                                    {
                                        objEmployee.InsertYearclosure_Modify(intLevelID, MaxID, LeavetypeID, Maxdays, EmployeeID);
                                        notYearClosure = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            DataTable dtTemp = GetMaxDaysWithoutLeavePolicy();
                            if (dtTemp.Rows.Count > 0)
                            {
                                for (int j = 0; j < dtTemp.Rows.Count; j++)
                                {
                                    int LeavetypeID = Convert.ToInt32(dtTemp.Rows[j]["LeaveTypeId"]);
                                    decimal Maxdays = Convert.ToDecimal(dtTemp.Rows[j]["MaxVal"]);
                                    objEmployee.InsertYearclosure(intLevelID, MaxID, LeavetypeID, Maxdays, EmployeeID);
                                    notYearClosure = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (dt_EmpPolicy.Rows.Count > 0)
                        {
                            if (MaxLPID > 0)
                            {
                                for (int k = 0; k < dr.Length; k++)
                                {
                                    int PolicyID = Convert.ToInt32(dr[k]["PolicyId"]);
                                    int LeavetypeID = Convert.ToInt32(dr[k]["LeaveTypeId"]);
                                    decimal Maxdays = Convert.ToDecimal(dr[k]["MaxDays"]);
                                    decimal Maxdays_month = Convert.ToDecimal(dr[k]["MaxDays_month"]);
                                    objEmployee.InsertEmpLeavePolicyDetails(MaxID, MaxLPID, PolicyID, LeavetypeID, Maxdays, EmployeeID, Maxdays_month);
                                }
                            }
                        }
                    }
                    checkLeavePolicyValue = checkLeavePolicyValue + 1;
                }
            }
            DataSet ds_emp = new DataSet();
            DataTable dt_emp = new DataTable();
            ds_emp = objEmployee.select_EmpLeavepolicyDetailsForUpdateYearClosure(MaxID);
            dt_emp = ds_emp.Tables[0];
            if (policydetails.Length != 1)
            {
                if (dt_emp != null && dt_emp.Rows.Count != 0)
                {
                    foreach (DataRow dRow in dt_emp.Rows)
                    {
                        if (Convert.ToDecimal(GetMaxDays(Convert.ToInt32(dRow["LeaveType_Id"]))) > -1)
                        {
                            objEmployee.InsertYearclosure_Modify(intLevelID, MaxID, Convert.ToInt32(dRow["LeaveType_Id"]), Convert.ToDecimal(GetMaxDays(Convert.ToInt32(dRow["LeaveType_Id"]))), EmployeeID);
                            notYearClosure = true;
                        }
                        else
                        {
                            objEmployee.InsertYearclosure_Modify(intLevelID, MaxID, Convert.ToInt32(dRow["LeaveType_Id"]), Convert.ToDecimal(dRow["No_Of_Days"]), EmployeeID);
                            notYearClosure = false;
                        }
                    }
                }
            }
            if (notYearClosure == false)
            {
                string strMappedLeaveTypes = string.Empty;
                foreach (DataRow dRowEmp in dt_emp.Rows)
                {
                    if (strMappedLeaveTypes == string.Empty)
                    {
                        strMappedLeaveTypes = Convert.ToString(dRowEmp["LeaveType_Id"]);
                    }
                    else
                    {
                        strMappedLeaveTypes = strMappedLeaveTypes + "," + Convert.ToString(dRowEmp["LeaveType_Id"]);
                    }
                }
                objEmployee.DeleteYearClosureLeaveTypedetails(MaxID, strMappedLeaveTypes, intYearSettingsId, EmployeeID);
            }
        }
        else
        {
            objEmployee.delete_EmployeeLeavePolicy(intEmpid);
        }
    }
    #endregion
    private void LoadStrings(CultureInfo ci)
    {
        lbl_EntranceName.Text = rm.GetString("lbl_Entrance", ci);
        lblContractor.Text = rm.GetString("lbl_Contractor", ci);
        if (Convert.ToString(Session["packageID"]) != "")
        {
            if (Convert.ToInt32(Session["packageID"]) == 168)  //Samsung
                lbl_HostelWorker.Text = "Blocking is required";
            else
                lbl_HostelWorker.Text = rm.GetString("lbl_EmployeeMaster_HostelWorker", ci);
        }
        else
        {
            lbl_HostelWorker.Text = rm.GetString("lbl_EmployeeMaster_HostelWorker", ci);
        }
        lbl_AnniversaryDate.Text = rm.GetString("EmployeeMaster_AnniversaryDate", ci);
        lbl_BasicSalary.Text = rm.GetString("EmployeeMaster_BasicSalary", ci);
        lbl_BloodGroup.Text = rm.GetString("EmployeeMaster_BloodGroup", ci);
        lbl_CardNo.Text = rm.GetString("TerminalDataType_Card_No", ci);
        lbl_City.Text = rm.GetString("Masters_Generic_City", ci);
        lbl_ContactAddress.Text = rm.GetString("EmployeeMaster_ContactAddress", ci);
        lbl_Country.Text = rm.GetString("Masters_Generic_Country", ci);
        lbl_DateofBirth.Text = rm.GetString("EmployeeMaster_DateOfBirth", ci);
        lbl_DateofBirthAsPerRec.Text = rm.GetString("EmployeeMaster_DateOfBirthAsPerRecord", ci);
        lbl_DateofJoining.Text = rm.GetString("EmployeeMaster_DateOfJoining", ci);
        lbl_Designation.Text = rm.GetString("EmployeeMaster_Designation", ci);
        lblDesigEffectiveDate.Text = rm.GetString("EmployeeMaster_BasicSal_EffectiveDate", ci);
        lblBasicSalEffectiveDate.Text = rm.GetString("EmployeeMaster_BasicSal_EffectiveDate", ci);
        lbl_District.Text = rm.GetString("EmployeeMaster_District", ci);
        lbl_EmailID.Text = rm.GetString("EmployeeMaster_EmailId", ci);
        lbl_EmployeeFirstName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EmployeeID.Text = rm.GetString("email_EmployeeId", ci);
        lbl_EmployeeStatus.Text = rm.GetString("EmployeeMaster_EmployeeStatus", ci);
        lbl_FathersName.Text = rm.GetString("EmployeeMaster_FathersName", ci);
        lbl_Gender.Text = rm.GetString("EmployeeMaster_Gender", ci);
        lbl_LastName.Text = rm.GetString("EmployeeMaster_LastName", ci);
        lbl_LeaveSanctioninguthority.Text = rm.GetString("EmployeeMaster_LeaveSanctioningAuthority", ci);
        lbl_Maritalstatus.Text = rm.GetString("EmployeeMaster_MaritalStatus", ci);
        lbl_MiddleName.Text = rm.GetString("EmployeeMaster_MiddleName", ci);
        lbl_MobileNumber.Text = rm.GetString("EmployeeMaster_MobileNumber", ci);
        lbl_MothersName.Text = rm.GetString("EmployeeMaster_MothersName", ci);
        lbl_Nationality.Text = rm.GetString("EmployeeMaster_Nationality", ci);
        lbl_NoofChildren.Text = rm.GetString("EmployeeMaster_NoOfChildren", ci);
        lbl_NoofSpouse.Text = rm.GetString("EmployeeMaster_NoOfSpouse", ci);
        lbl_PassportexpiryDate.Text = rm.GetString("EmployeeMaster_PassportExpiryDate", ci);
        lbl_PassportNo.Text = rm.GetString("EmployeeMaster_PassportNo", ci);
        lbl_PermanentAddress.Text = rm.GetString("EmployeeMaster_PermanentAddress", ci);
        lbl_PersonalMailID.Text = rm.GetString("EmployeeMaster_PersionalMailId", ci);
        lbl_PhoneNumber.Text = rm.GetString("EmployeeMaster_PhoneNumber", ci);
        lbl_Photo.Text = rm.GetString("EmployeeMaster_Photo", ci);
        lbl_PolicyName1.Text = rm.GetString("EmployeeMaster_PolicyName1", ci);
        lbl_PreviousExperience.Text = rm.GetString("EmployeeMaster_PreviousExperience", ci);
        lbl_QualifactionattheTimeofJoining.Text = rm.GetString("EmployeeMaster_QualifactionAtTheTimeOfJoining", ci);
        lbl_QualificationduringEmployment.Text = rm.GetString("EmployeeMaster_QualificationDuringEmployment", ci);
        lbl_Religion.Text = rm.GetString("EmployeeMaster_Religion", ci);
        lbl_ReportingTo.Text = rm.GetString("EmployeeMaster_ReportingTo", ci);
        lbl_State.Text = rm.GetString("Masters_Generic_State", ci);
        lbl_Transportation.Text = rm.GetString("EmployeeMaster_Transportation", ci);
        lbl_UserGroup.Text = rm.GetString("EmployeeMaster_UserGroup", ci);
        lbl_UserName.Text = rm.GetString("EmployeeMaster_UserName_AD", ci);
        lbl_VehicleNumber.Text = rm.GetString("EmployeeMaster_VehicleNumber", ci);
        lbl_VehicleType.Text = rm.GetString("EmployeeMaster_VehicleType", ci);
        lbl_VisaExpiryDate.Text = rm.GetString("EmployeeMaster_VisaExpiryDate", ci);
        lbl_VisaNo.Text = rm.GetString("EmployeeMaster_VisaNo", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_HeaderEmployeeMaster.Text = rm.GetString("Masters_Employee_EmployeeMaster", ci);
        lblEmployeeMaster.Text = rm.GetString("Masters_Employee_EmployeeMaster", ci);
        lblEmployeeMaster1.Text = rm.GetString("Masters_Employee_EmployeeMaster", ci);
        lblEmployeeMaster2.Text = rm.GetString("Masters_Employee_EmployeeMaster", ci);
        lblIndicateMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lblIsFlexibleTimings.Text = rm.GetString("FlexibleTimings", ci);
        rbtnFlexibleTimingsYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnFlexibleTimingsNo.Text = rm.GetString("ShiftSetting_No", ci);
        rbtn_Active.Text = rm.GetString("rbtn_EmployeeMaster_Active", ci);
        rbtn_Female.Text = rm.GetString("rbtn_EmployeeMaster_Female", ci);
        rbtn_Inactive.Text = rm.GetString("rbtn_EmployeeMaster_InActive", ci);
        rbtn_Male.Text = rm.GetString("rbtn_EmployeeMaster_Male", ci);
        rbtn_Married.Text = rm.GetString("rbtn_EmployeeMaster_Married", ci);
        rbtn_Single.Text = rm.GetString("rbtn_EmployeeMaster_Single", ci);
        chk_CompOffEligible.Text = rm.GetString("chk_EmployeeMaster_CompensationOffEligible", ci);
        chk_EligibleESI.Text = rm.GetString("chk_EmployeeMaster_EligibleForESI", ci);
        chk_EligiblePF.Text = rm.GetString("chk_EmployeeMaster_EligibleForPF", ci);
        chk_OTEligible.Text = rm.GetString("EmployeeMaster_OTEligible", ci);
        chk_CompOffAndOT.Text = rm.GetString("lblOTCompOffApproval", ci);
        chk_OutdoorEmployee.Text = rm.GetString("EmployeeMaster_OutDoorEmployee", ci);
        chk_ReportsExcl.Text = rm.GetString("chk_EmployeeMaster_ExcludeFromReports", ci);
        rbtn_HostelYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtn_HostelNo.Text = rm.GetString("ShiftSetting_No", ci);
        btn_Next1.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Next", ci);
        btn_Modify.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Next2.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Next", ci);
        btn_Back1.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_Back2.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_Next3.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Next", ci);
        btn_Back3.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_Back5.Text = "&nbsp; &nbsp; " + rm.GetString("btn_Back", ci);
        btn_Next5.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Next", ci);
        btn_Cancel5.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        btn_Save.Text = rm.GetString("btn_Save", ci);
        btn_Cancel3.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        btn_AddPolicy.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Calculate", ci);
        ImageButton3.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        ImageButton4.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        ButSave.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        ImageButton1.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        btn_Personal_main.Text = rm.GetString("Employee_personal", ci);
        btn_Official_blur.Text = rm.GetString("Employee_official", ci);
        btn_LeavePolicy_blur.Text = rm.GetString("Employee_LeavePolicy", ci);
        btn_Others_blur.Text = rm.GetString("Employee_Others", ci);
        btn_Personal_blur.Text = rm.GetString("Employee_personal", ci);
        btn_Official_main.Text = rm.GetString("Employee_official", ci);
        btn_LeavePolicy_blur1.Text = rm.GetString("Employee_LeavePolicy", ci);
        btn_Others_blur1.Text = rm.GetString("Employee_Others", ci);
        btn_Personal_blur1.Text = rm.GetString("Employee_personal", ci);
        btn_Official_blur1.Text = rm.GetString("Employee_official", ci);
        btn_LeavePolicy_main.Text = rm.GetString("Employee_LeavePolicy", ci);
        btn_Others_blur2.Text = rm.GetString("Employee_Others", ci);
        btn_Personal_blur2.Text = rm.GetString("Employee_personal", ci);
        btn_Official_blur2.Text = rm.GetString("Employee_official", ci);
        btn_LeavePolicy_blur2.Text = rm.GetString("Employee_LeavePolicy", ci);
        btn_Others_main.Text = rm.GetString("Employee_Others", ci);
        ddl_VehicleType.Items[0].Text = rm.GetString("Select", ci);
        ddl_VehicleType.Items[1].Text = rm.GetString("VehicleType_TwoWheeler", ci);
        ddl_VehicleType.Items[2].Text = rm.GetString("VehicleType_FourWheeler", ci);
        ddl_Country.Items[0].Text = rm.GetString("Select", ci);
        ddl_State.Items[0].Text = rm.GetString("Select", ci);
        ddl_City.Items[0].Text = rm.GetString("Select", ci);
        ddl_LeavePolicy.Items[0].Text = rm.GetString("Select", ci);
        ddl_Designation.Items[0].Text = rm.GetString("Select", ci);
        ddl_ReportingTo.Items[0].Text = rm.GetString("Select", ci);
        ddl_LeaveSancAuthority.Items[0].Text = rm.GetString("Select", ci);
        ddl_BusRouteNo.Items[0].Text = rm.GetString("Select", ci);
        ddlEmpCatagory.Items[0].Text = rm.GetString("Select", ci);
        ddlEmpType.Items[0].Text = rm.GetString("Select", ci);
        lblEmpCategory.Text = rm.GetString("lblEmpCategory", ci);
        lblEmpType.Text = rm.GetString("lblEmpType", ci);
        lblEmpTypEffDate.Text = rm.GetString("EmployeeMaster_BasicSal_EffectiveDate", ci);
        lblEmpCatEffDate.Text = rm.GetString("EmployeeMaster_BasicSal_EffectiveDate", ci);
        Button1.Text = "&nbsp;&nbsp;" + rm.GetString("Caption_ViewQuota", ci);
        lblEffectiveDateLeve.Text = rm.GetString("Caption_EffectiveDateForLevel", ci);
        //lblCustomField1.Text = rm.GetString("Employee_CustomField1", ci);
        //lblCustomField2.Text = rm.GetString("Employee_CustomField2", ci);
        //lblCustomField3.Text = rm.GetString("Employee_CustomField3", ci);
        //lblCustomField4.Text = rm.GetString("Employee_CustomField4", ci);
        //lblCustomField5.Text = rm.GetString("Employee_CustomField5", ci);
        lbl_Personal.Text = rm.GetString("Employee_personal", ci);
        lbl_Others.Text = rm.GetString("Employee_Others", ci);
        lbl_Official.Text = rm.GetString("Employee_official", ci);
        lbl_LeavePolicy.Text = rm.GetString("Employee_LeavePolicy", ci);
        lbl_Mandatory.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lblIsActiveDate.Text = rm.GetString("lbl_InActiveDate", ci);

        lblMobileClock.Text = rm.GetString("lblMobileClock", ci);
        rbtnSMSEnable.Text = rbtnMobileClockYes.Text = rm.GetString("rbtnMobileClockYes", ci);
        rbtnSMSDisable.Text = rbtnMobileClockNo.Text = rm.GetString("rbtnMobileClockNo", ci);
        lblSMSEnableDisable.Text = rm.GetString("lblSMSEnableDisable", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(18, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    public void LoadLeaveTypes()
    {
        try
        {
            string LeaveTypeHeader = rm.GetString("lbl_leavetype", ci);
            string PreviouYearHeader = rm.GetString("Master_Employee_PreviousYearBalance", ci);
            string LeaveTakenHeader = rm.GetString("Master_Employee_NoOffLeaveTaken", ci);
            string LeaveTakenToolTip = rm.GetString("Master_Employee_NoOffLeaveTaken_ToolTip", ci);
            if (!IsPostBack)
            {
                dsLoadLeavetypes = objEmployee.FillLeaveTypesforEmployee(intEmpid, intYearSettingsId);
                ViewState["LeaveTypes"] = dsLoadLeavetypes.Tables[0];
                string strLeaveType = string.Empty;
                if (dsLoadLeavetypes.Tables[0].Rows.Count > 0)
                {
                    if (Convert.ToInt32(dsLoadLeavetypes.Tables[0].Rows[0]["Emp_LeaveType_Id"]) > 0)
                    {
                        tbLeaveType.CssClass = "table das-table1 TableWidth";
                        TableHeaderRow trleaveType = new TableHeaderRow();
                        trleaveType.Attributes.Add("class", "row");
                        TableHeaderCell tcLeaveTypeName = new TableHeaderCell();
                        tcLeaveTypeName.Attributes.Add("class", "col-md-4 empheader");
                        tcLeaveTypeName.Text = LeaveTypeHeader;
                        tcLeaveTypeName.Wrap = true;
                        trleaveType.Cells.Add(tcLeaveTypeName);
                        TableHeaderCell tcPreviousYearBalance = new TableHeaderCell();
                        tcPreviousYearBalance.Attributes.Add("class", "col-md-4 empheader");
                        tcPreviousYearBalance.Wrap = true;
                        tcPreviousYearBalance.Text = PreviouYearHeader;
                        trleaveType.Cells.Add(tcPreviousYearBalance);
                        TableHeaderCell tcNoOfLeaveAvailed = new TableHeaderCell();
                        tcNoOfLeaveAvailed.Attributes.Add("class", "col-md-4 empheader");
                        tcNoOfLeaveAvailed.Wrap = true;
                        tcNoOfLeaveAvailed.Text = LeaveTakenHeader;
                        trleaveType.Cells.Add(tcNoOfLeaveAvailed);
                        tbLeaveType.Rows.Add(trleaveType);
                        if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) != "Express")
                        {
                            phLeaveTypes.Controls.Add(tbLeaveType);
                        }
                        int i = 1;
                        foreach (DataRow dr in dsLoadLeavetypes.Tables[0].Rows)
                        {
                            TableRow tr = new TableRow();
                            tr.Attributes.Add("class", "row form-group");
                            TableCell tc_LeaveType = new TableCell();
                            tc_LeaveType.Attributes.Add("class", "col-md-4");
                            Label lblLeaveType = new Label();
                            lblLeaveType.ID = Convert.ToString(dr["Emp_LeaveType_Id"]);
                            lblLeaveType.Text = Convert.ToString(dr["LeaveType"]);
                            tc_LeaveType.Controls.Add(lblLeaveType);
                            tr.Cells.Add(tc_LeaveType);
                            TableCell tc_PreviousYearBalance = new TableCell();
                            tc_PreviousYearBalance.Attributes.Add("class", "col-md-4");
                            TextBox txtPreviousYearBalance = new TextBox();
                            txtPreviousYearBalance.ID = "txtPreviousYearBalance" + Convert.ToInt32(dr["Emp_LeaveType_Id"]);
                            txtPreviousYearBalance.Text = Convert.ToString(dr["PreviousYearBalance"]);
                            txtPreviousYearBalance.Attributes.Add("onkeypress", "return number_dot_Without_Dollar(event,this);");
                            txtPreviousYearBalance.Attributes.Add("onchange", "return onChangeHalfDay(this);");
                            txtPreviousYearBalance.Attributes.Add("onpaste", "return false;");
                            txtPreviousYearBalance.Attributes.Add("oncopy", "return false;");
                            txtPreviousYearBalance.Attributes.Add("ondrop", "return false;");
                            txtPreviousYearBalance.Attributes.Add("class", "form-control");
                            txtPreviousYearBalance.MaxLength = 4;
                            tc_PreviousYearBalance.Controls.Add(txtPreviousYearBalance);
                            tr.Cells.Add(tc_PreviousYearBalance);
                            TableCell tc_NoOffLeaveAvailed = new TableCell();
                            tc_NoOffLeaveAvailed.Attributes.Add("class", "col-md-4");
                            TextBox txtNoOffLeaveAvailed = new TextBox();
                            txtNoOffLeaveAvailed.ID = "txtNoOffLeaveAvailed" + Convert.ToInt32(dr["Emp_LeaveType_Id"]);
                            txtNoOffLeaveAvailed.Text = Convert.ToString(dr["NoOffLeaveAvailed"]);
                            txtNoOffLeaveAvailed.Attributes.Add("onkeypress", "return number_dot_Without_Dollar(event,this);");
                            txtNoOffLeaveAvailed.Attributes.Add("onchange", "return onChangeHalfDay(this);");
                            txtNoOffLeaveAvailed.Attributes.Add("onpaste", "return false;");
                            txtNoOffLeaveAvailed.Attributes.Add("oncopy", "return false;");
                            txtNoOffLeaveAvailed.Attributes.Add("ondrop", "return false;");
                            txtNoOffLeaveAvailed.Attributes.Add("class", "form-control");
                            txtNoOffLeaveAvailed.MaxLength = 4;
                            txtNoOffLeaveAvailed.ToolTip = LeaveTakenToolTip;
                            tc_NoOffLeaveAvailed.Controls.Add(txtNoOffLeaveAvailed);
                            tr.Cells.Add(tc_NoOffLeaveAvailed);
                            tbLeaveType.Rows.Add(tr);
                            i = i + 1;
                        }
                    }
                }
            }
            else if (IsPostBack)
            {
                dsLoadLeavetypes = objEmployee.LoadLeaveType(intYearSettingsId);
                if (dsLoadLeavetypes.Tables.Count > 0)
                {
                    if (dsLoadLeavetypes.Tables[0].Rows.Count > 0)
                    {
                        if (Convert.ToInt32(dsLoadLeavetypes.Tables[0].Rows[0]["Emp_LeaveType_Id"]) > 0)
                        {
                            tbLeaveType.CssClass = "table das-table1 TableWidth";
                            TableHeaderRow trleaveType = new TableHeaderRow();
                            trleaveType.Attributes.Add("class", "row");
                            TableHeaderCell tcLeaveTypeName = new TableHeaderCell();
                            tcLeaveTypeName.Attributes.Add("class", "col-md-4 empheader");
                            tcLeaveTypeName.Wrap = true;
                            tcLeaveTypeName.Text = LeaveTypeHeader;
                            tcLeaveTypeName.Wrap = true;
                            trleaveType.Cells.Add(tcLeaveTypeName);
                            TableHeaderCell tcPreviousYearBalance = new TableHeaderCell();
                            tcPreviousYearBalance.Wrap = true;
                            tcPreviousYearBalance.Attributes.Add("class", "col-md-4 empheader");
                            tcPreviousYearBalance.Text = PreviouYearHeader;
                            trleaveType.Cells.Add(tcPreviousYearBalance);
                            TableHeaderCell tcNoOfLeaveAvailed = new TableHeaderCell();
                            tcNoOfLeaveAvailed.Attributes.Add("class", "col-md-4 empheader");
                            tcNoOfLeaveAvailed.Text = LeaveTakenHeader;
                            tcNoOfLeaveAvailed.Wrap = true;
                            trleaveType.Cells.Add(tcNoOfLeaveAvailed);
                            tbLeaveType.Rows.Add(trleaveType);
                            phLeaveTypes.Controls.Add(tbLeaveType);
                            int i = 1;
                            foreach (DataRow dr in dsLoadLeavetypes.Tables[0].Rows)
                            {
                                TableRow tr = new TableRow();
                                tr.Attributes.Add("class", "row form-group");
                                TableCell tc_LeaveType = new TableCell();
                                tc_LeaveType.Attributes.Add("class", "col-md-4");
                                Label lblLeaveType = new Label();
                                lblLeaveType.ID = Convert.ToString(dr["Emp_LeaveType_Id"]);
                                lblLeaveType.Text = Convert.ToString(dr["LeaveType"]);
                                tc_LeaveType.Controls.Add(lblLeaveType);
                                tr.Cells.Add(tc_LeaveType);
                                TableCell tc_PreviousYearBalance = new TableCell();
                                tc_PreviousYearBalance.Attributes.Add("class", "col-md-4");
                                TextBox txtPreviousYearBalance = new TextBox();
                                txtPreviousYearBalance.ID = "txtPreviousYearBalance" + Convert.ToInt32(dr["Emp_LeaveType_Id"]);
                                txtPreviousYearBalance.Attributes.Add("onkeypress", "return number_dot_Without_Dollar(event,this);");
                                txtPreviousYearBalance.Attributes.Add("onchange", "return onChangeHalfDay(this);");
                                txtPreviousYearBalance.Attributes.Add("onpaste", "return false;");
                                txtPreviousYearBalance.Attributes.Add("oncopy", "return false;");
                                txtPreviousYearBalance.Attributes.Add("ondrop", "return false;");
                                txtPreviousYearBalance.Attributes.Add("class", "form-control");
                                txtPreviousYearBalance.MaxLength = 4;
                                tc_PreviousYearBalance.Controls.Add(txtPreviousYearBalance);
                                tr.Cells.Add(tc_PreviousYearBalance);
                                TableCell tc_NoOffLeaveAvailed = new TableCell();
                                tc_NoOffLeaveAvailed.Attributes.Add("class", "col-md-4");
                                TextBox txtNoOffLeaveAvailed = new TextBox();
                                txtNoOffLeaveAvailed.ID = "txtNoOffLeaveAvailed" + Convert.ToInt32(dr["Emp_LeaveType_Id"]);
                                txtNoOffLeaveAvailed.Attributes.Add("onkeypress", "return number_dot_Without_Dollar(event,this);");
                                txtNoOffLeaveAvailed.Attributes.Add("onchange", "return onChangeHalfDay(this);");
                                txtNoOffLeaveAvailed.Attributes.Add("onpaste", "return false;");
                                txtNoOffLeaveAvailed.Attributes.Add("oncopy", "return false;");
                                txtNoOffLeaveAvailed.Attributes.Add("ondrop", "return false;");
                                txtNoOffLeaveAvailed.Attributes.Add("class", "form-control");
                                txtNoOffLeaveAvailed.MaxLength = 4;
                                txtNoOffLeaveAvailed.ToolTip = LeaveTakenToolTip;
                                tc_NoOffLeaveAvailed.Controls.Add(txtNoOffLeaveAvailed);
                                tr.Cells.Add(tc_NoOffLeaveAvailed);
                                tbLeaveType.Rows.Add(tr);
                                i = i + 1;
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Message(ex.Message);
        }
        finally
        {
        }
    }
    public DataTable GetMaxDaysWithoutLeavePolicy()
    {
        decimal MaxValue = 0;
        DataTable dtWithouLeavePolicy = new DataTable();
        dtWithouLeavePolicy.Columns.Add("LeaveTypeId");
        dtWithouLeavePolicy.Columns.Add("MaxVal");
        if (ViewState["LeaveTypes"] != null)
        {
            if (tbLeaveType.Rows.Count > 0)
            {
                DataTable dt = new DataTable();
                dt = (DataTable)ViewState["LeaveTypes"];
                TextBox txtPreviousYearBalance = new TextBox();
                TextBox txtNoOffLeaveAvailed = new TextBox();
                if (dt.Rows.Count > 0)
                {
                    int RowCount = dt.Rows.Count;
                    decimal intPrevious = 0;
                    decimal intNoOfLeave = 0;
                    int i = 1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        intPrevious = 0;
                        intNoOfLeave = 0;
                        txtPreviousYearBalance = (TextBox)tbLeaveType.Rows[i].FindControl("txtPreviousYearBalance" + Convert.ToInt32(dr["Emp_LeaveType_Id"]));
                        txtNoOffLeaveAvailed = (TextBox)tbLeaveType.Rows[i].FindControl("txtNoOffLeaveAvailed" + Convert.ToInt32(dr["Emp_LeaveType_Id"]));
                        if (txtPreviousYearBalance != null)
                            if (txtPreviousYearBalance.Text.Trim() != string.Empty)
                                intPrevious = Convert.ToDecimal(txtPreviousYearBalance.Text.Trim());
                        if (txtNoOffLeaveAvailed != null)
                            if (txtNoOffLeaveAvailed.Text.Trim() != string.Empty)
                                intNoOfLeave = Convert.ToDecimal(txtNoOffLeaveAvailed.Text.Trim());
                        MaxValue = Convert.ToDecimal(intPrevious - intNoOfLeave);
                        DataRow drWOPolicy = dtWithouLeavePolicy.NewRow();
                        drWOPolicy["LeaveTypeId"] = Convert.ToInt32(dr["Emp_LeaveType_Id"]);
                        drWOPolicy["MaxVal"] = MaxValue;
                        dtWithouLeavePolicy.Rows.Add(drWOPolicy);
                    }
                }
            }
        }
        return dtWithouLeavePolicy;
    }
    public decimal GetMaxDays(int LeaveTypeId)
    {
        decimal CurrentQuota = -1;
        decimal MaxValue = -1;
        if (ViewState["LeaveTypes"] != null)
        {
            if (tbLeaveType.Rows.Count > 0)
            {
                DataTable dt = new DataTable();
                dt = (DataTable)ViewState["LeaveTypes"];
                TextBox txtPreviousYearBalance = new TextBox();
                TextBox txtNoOffLeaveAvailed = new TextBox();
                if (dt.Rows.Count > 0)
                {
                    int RowCount = dt.Rows.Count;
                    decimal intPrevious = 0;
                    decimal intNoOfLeave = 0;
                    int i = 1;
                    foreach (DataRow dr in dt.Select("Emp_LeaveType_Id='" + LeaveTypeId + "'"))
                    {
                        intPrevious = 0;
                        intNoOfLeave = 0;
                        txtPreviousYearBalance = (TextBox)tbLeaveType.Rows[i].FindControl("txtPreviousYearBalance" + Convert.ToInt32(dr["Emp_LeaveType_Id"]));
                        txtNoOffLeaveAvailed = (TextBox)tbLeaveType.Rows[i].FindControl("txtNoOffLeaveAvailed" + Convert.ToInt32(dr["Emp_LeaveType_Id"]));
                        if (txtPreviousYearBalance != null)
                            if (txtPreviousYearBalance.Text.Trim() != string.Empty)
                                intPrevious = Convert.ToDecimal(txtPreviousYearBalance.Text.Trim());
                        if (txtNoOffLeaveAvailed != null)
                            if (txtNoOffLeaveAvailed.Text.Trim() != string.Empty)
                                intNoOfLeave = Convert.ToDecimal(txtNoOffLeaveAvailed.Text.Trim());
                        MaxValue = Convert.ToDecimal(intPrevious - intNoOfLeave);
                        if (Session["Emp_Policy"] != null)
                        {
                            DataTable dtTemp = (DataTable)Session["Emp_Policy"];
                            foreach (DataRow dtRow in dtTemp.Select("LeaveTypeId=" + Convert.ToInt32(dr["Emp_LeaveType_Id"])))
                            {
                                if (Convert.ToString(dtRow["MaxDays"]) != string.Empty)
                                {
                                    MaxValue = MaxValue + Convert.ToDecimal(dtRow["MaxDays"]);
                                }
                            }
                        }
                    }
                }
            }
        }
        CurrentQuota = MaxValue;
        return CurrentQuota;
    }
    public bool ValidLeaveTypes()
    {
        Session["PreviousYearCount"] = "0";
        bool returnValue = true;
        if (ViewState["LeaveTypes"] != null)
        {
            if (tbLeaveType.Rows.Count > 0)
            {
                DataTable dt = new DataTable();
                dt = (DataTable)ViewState["LeaveTypes"];
                TextBox txtPreviousYearBalance = new TextBox();
                TextBox txtNoOffLeaveAvailed = new TextBox();
                if (dt.Rows.Count > 0)
                {
                    int RowCount = dt.Rows.Count;
                    decimal intPrevious = 0;
                    decimal intNoOfLeave = 0;
                    int i = 1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        intPrevious = 0;
                        intNoOfLeave = 0;
                        txtPreviousYearBalance = (TextBox)tbLeaveType.Rows[i].FindControl("txtPreviousYearBalance" + Convert.ToInt32(dr["Emp_LeaveType_Id"]));
                        txtNoOffLeaveAvailed = (TextBox)tbLeaveType.Rows[i].FindControl("txtNoOffLeaveAvailed" + Convert.ToInt32(dr["Emp_LeaveType_Id"]));
                        if (txtPreviousYearBalance != null)
                            if (txtPreviousYearBalance.Text.Trim() != string.Empty)
                            {
                                if (Convert.ToDecimal(txtPreviousYearBalance.Text) > 0)
                                {
                                    intPrevious = Convert.ToDecimal(txtPreviousYearBalance.Text.Trim());
                                    Session["PreviousYearCount"] = "1";
                                }
                            }
                        if (txtNoOffLeaveAvailed != null)
                            if (txtNoOffLeaveAvailed.Text.Trim() != string.Empty)
                                intNoOfLeave = Convert.ToDecimal(txtNoOffLeaveAvailed.Text.Trim());
                        decimal MaxValue = Convert.ToDecimal(intPrevious);
                        string LeavePolicy_data = hdf_Policy.Value;
                        if (Session["Emp_Policy"] != null && LeavePolicy_data != "" && LeavePolicy_data != "undefined")
                        {
                            DataTable dtTemp = (DataTable)Session["Emp_Policy"];
                            foreach (DataRow dtRow in dtTemp.Select("LeaveTypeId=" + Convert.ToInt32(dr["Emp_LeaveType_Id"])))
                            {
                                if (Convert.ToString(dtRow["MaxDays"]) != string.Empty)
                                    MaxValue = MaxValue + Convert.ToDecimal(dtRow["MaxDays"]);
                            }
                        }
                        Session["MaxVal"] = MaxValue;
                        if (intNoOfLeave > MaxValue)
                            return false;
                        else
                            returnValue = true;
                    }
                }
            }
        }
        return returnValue;
    }
    public string ValidateDOJPreviousYearBalance(string strDoj)
    {
        string Message = "";
        if (strDoj != "")
        {
            DateTime dateDOJ = Convert.ToDateTime(strDoj);
            if (Session["YearSettingFromDate"] != null && Session["YearSettingToDate"] != null)
            {
                string Alert = rm.GetString("Employee_Master_Alert_DOJGreaterPrevious", ci);
                DateTime dateFromDate = DateTime.Parse(Convert.ToString(Session["YearSettingFromDate"]));
                DateTime dateToDate = DateTime.Parse(Convert.ToString(Session["YearSettingToDate"]));
                DateTime dateApproximatePreviouYear = dateToDate.AddYears(-1);
                if (dateDOJ > dateApproximatePreviouYear)
                {
                    Message = Alert;
                }
                else
                {
                    Message = "";
                }
            }
        }
        return Message;
    }
    public void UpdateLeaveTypeDetails(int EmployeeId)
    {
        try
        {
            if (ViewState["LeaveTypes"] != null)
            {
                DataTable dt = new DataTable();
                dt = (DataTable)ViewState["LeaveTypes"];
                TextBox txtPreviousYearBalance = new TextBox();
                TextBox txtNoOffLeaveAvailed = new TextBox();
                if (dt.Rows.Count > 0)
                {
                    int RowCount = dt.Rows.Count;
                    int i = 1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (tbLeaveType.Rows.Count > 0)
                        {
                            txtPreviousYearBalance = (TextBox)tbLeaveType.Rows[i].FindControl("txtPreviousYearBalance" + Convert.ToInt32(dr["Emp_LeaveType_Id"]));
                            txtNoOffLeaveAvailed = (TextBox)tbLeaveType.Rows[i].FindControl("txtNoOffLeaveAvailed" + Convert.ToInt32(dr["Emp_LeaveType_Id"]));
                            if (txtPreviousYearBalance != null)
                                if (txtPreviousYearBalance.Text == string.Empty)
                                {
                                    txtPreviousYearBalance.Text = "0";
                                }
                            if (txtNoOffLeaveAvailed != null)
                                if (txtNoOffLeaveAvailed.Text == string.Empty)
                                {
                                    txtNoOffLeaveAvailed.Text = "0";
                                }
                            objEmployee.InsertLeavetypeDetails(EmployeeId, Convert.ToInt32(dr["Emp_LeaveType_Id"]), Convert.ToDecimal(txtPreviousYearBalance.Text), Convert.ToDecimal(txtNoOffLeaveAvailed.Text), intYearSettingsId);
                            i = i + 1;
                        }
                    }
                }
            }
            else
            {
                objEmployee.DeleteLeaveType(EmployeeId, intYearSettingsId);
            }
        }
        catch (Exception ex)
        {
            Message(ex.Message);
        }
    }
    private void fillEntrance()
    {
        DataSet dsEntrance = new DataSet();
        dsEntrance = objEmployee.LoadInEntrance();
        if (dsEntrance != null && dsEntrance.Tables.Count > 0 && dsEntrance.Tables[0].Rows.Count > 0)
        {
            ddl_EntranceName.DataSource = dsEntrance;
            ddl_EntranceName.DataTextField = "Entrance_Name";
            ddl_EntranceName.DataValueField = "Terminal_ReaderID";
            ddl_EntranceName.DataBind();
        }
        ddl_EntranceName.Items.Insert(0, new ListItem("-Select-", "0"));
        dsEntrance.Dispose();
    }

    #region load Contractor Details
    private void fillContractor()
    {
        DataSet dsContractor = new DataSet();
        dsContractor = objEmployee.LoadInContractor();
        if (dsContractor != null && dsContractor.Tables.Count > 0 && dsContractor.Tables[0].Rows.Count > 0)
        {
            ddlContractor.DataSource = dsContractor;
            ddlContractor.DataTextField = "ContractorName";
            ddlContractor.DataValueField = "ID";
            ddlContractor.DataBind();
        }
        ddlContractor.Items.Insert(0, new ListItem("-Select-", "0"));
        dsContractor.Dispose();
    }
    #endregion

    /// <summary>
    /// Get Customizable field name form attendance code screen
    /// Based on the creation there, the label name will be displayed here for display.
    /// </summary>
    private void BindCustomizableFieldName()
    {
        DataSet ds = new DataSet();
        ds = objAttCode.SelectAllAttandance(0, "All", Convert.ToString(Session["UserGroupName"]), "", 0);
        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                ds.Tables[0].DefaultView.RowFilter = "AttandanceValue in('Customizable Field1','Customizable Field2','Customizable Field3','Customizable Field4','Customizable Field5','Customizable Field6')";
                DataTable dt = ds.Tables[0].DefaultView.ToTable();
                if (dt.Rows.Count > 0)
                {
                    string customFields = "";
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        customFields = Convert.ToString(dt.Rows[i]["AttandanceValue"]);
                        switch (customFields)
                        {
                            case "Customizable Field1":
                                lblCustomField1.Text = Convert.ToString(dt.Rows[i]["AttandanceCode"]);
                                break;
                            case "Customizable Field2":
                                lblCustomField2.Text = Convert.ToString(dt.Rows[i]["AttandanceCode"]);
                                break;
                            case "Customizable Field3":
                                lblCustomField3.Text = Convert.ToString(dt.Rows[i]["AttandanceCode"]);
                                break;
                            case "Customizable Field4":
                                lblCustomField4.Text = Convert.ToString(dt.Rows[i]["AttandanceCode"]);
                                break;
                            case "Customizable Field5":
                                lblCustomField5.Text = Convert.ToString(dt.Rows[i]["AttandanceCode"]);
                                break;
                            case "Customizable Field6":
                                lblCustomField6.Text = Convert.ToString(dt.Rows[i]["AttandanceCode"]);
                                break;
                        }
                    }
                }
            }
        }
        else
        {
            //lblCustomField1.Text = rm.GetString("Employee_CustomField1", ci);
            //lblCustomField2.Text = rm.GetString("Employee_CustomField2", ci);
            //lblCustomField3.Text = rm.GetString("Employee_CustomField3", ci);
            //lblCustomField4.Text = rm.GetString("Employee_CustomField4", ci);
            //lblCustomField5.Text = rm.GetString("Employee_CustomField5", ci);
        }
    }



    protected void btn_Add_Click(object sender, EventArgs e)
    {

    }
    //protected void btnCustomAdd1_Click(object sender, EventArgs e)
    //{
    //    int MaxFileSize = Convert.ToInt32(ConfigurationManager.AppSettings["MaxFileSize"]);
    //    string Ex_JPEG = ConfigurationManager.AppSettings["Ex_JPEG"];
    //    string Ex_JPG = ConfigurationManager.AppSettings["Ex_JPG"];
    //    string Ex_BMP = ConfigurationManager.AppSettings["Ex_BMP"];
    //    string Ex_PNG = ConfigurationManager.AppSettings["Ex_PNG"];
    //    string Ex_PDF = ConfigurationManager.AppSettings["Ex_PDF"];
    //    string Ex_DOC = ConfigurationManager.AppSettings["Ex_DOC"];
    //    string Ex_DOCX = ConfigurationManager.AppSettings["Ex_DOCX"];
    //    string GetCurrentDate = DateTime.Today.ToString("yyyyMMdd");
    //    string GetEmployeeId = Convert.ToString(txt_SwipeCardNo.Text);
    //    string GetLeaveApplicationId = string.Empty;
    //    bool result = false;
    //    string GetDash = "_";
    //    string GetSessionEmployeeID = Convert.ToString(Session["EmployeeCodeId"]);

    //    if (GetCurrentDate != string.Empty && GetEmployeeId != string.Empty && lblCustomField1.Text != string.Empty)
    //    {
    //        string DocumentName = string.Concat(GetEmployeeId, GetDash, GetCurrentDate, GetDash, "CusFd1");
    //        if (txtCustomField1.HasFile)
    //        {
    //            string fileExtension = System.IO.Path.GetExtension(txtCustomField1.FileName);
    //            if (fileExtension != Ex_PDF)
    //            {
    //                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Please Upload only PDF extension file format');", true);
    //            }
    //            else
    //            {
    //                int fileSize = txtCustomField1.PostedFile.ContentLength;
    //                if (fileSize == 0 || fileSize > MaxFileSize)
    //                {
    //                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Maximum upload file size is 5MB.');", true);
    //                }
    //                else
    //                {
    //                    try
    //                    {
    //                        string extension = Path.GetExtension(txtCustomField1.PostedFile.FileName);
    //                        DirectoryInfo isDirectExists = new DirectoryInfo(Server.MapPath("~/Masters/EmployeeDocumentUpload"));
    //                        if (!isDirectExists.Exists)
    //                        {
    //                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('The Application doest not contain Leave Application Upload Files folder, please create it');", true);
    //                            result = false;
    //                        }
    //                        else
    //                        {
    //                            string serverpath = Server.MapPath("~/Masters/EmployeeDocumentUpload/") + DocumentName + extension;
    //                            finalCustomefile1 = AppendFileNumberIfExists(serverpath, extension);
    //                            txtCustomField1.SaveAs(finalCustomefile1);
    //                            Session["EmployeeCusDoc1"] = finalCustomefile1;
    //                            //ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File uploaded Sucessfully');", true);
    //                            btnCustomAdd1.Visible = false;
    //                            btnCustomView1.Visible = true;
    //                            hdnpdfViewer1.Value = finalCustomefile1;
    //                            //txtCustomField1.FileName = DocumentName;
    //                        }
    //                    }
    //                    catch (Exception ex)
    //                    {
    //                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //                    }
    //                }
    //            }
    //        }
    //        else
    //        {
    //            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Upload the necessary document to avail this leave.');", true);

    //        }
    //    }
    //    else
    //    {
    //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //    }
    //}

    //protected void btnCustomAdd2_Click(object sender, EventArgs e)
    //{
    //    int MaxFileSize = Convert.ToInt32(ConfigurationManager.AppSettings["MaxFileSize"]);
    //    string Ex_JPEG = ConfigurationManager.AppSettings["Ex_JPEG"];
    //    string Ex_JPG = ConfigurationManager.AppSettings["Ex_JPG"];
    //    string Ex_BMP = ConfigurationManager.AppSettings["Ex_BMP"];
    //    string Ex_PNG = ConfigurationManager.AppSettings["Ex_PNG"];
    //    string Ex_PDF = ConfigurationManager.AppSettings["Ex_PDF"];
    //    string Ex_DOC = ConfigurationManager.AppSettings["Ex_DOC"];
    //    string Ex_DOCX = ConfigurationManager.AppSettings["Ex_DOCX"];
    //    string GetCurrentDate = DateTime.Today.ToString("yyyyMMdd");
    //    string GetEmployeeId = Convert.ToString(txt_SwipeCardNo.Text);
    //    string GetLeaveApplicationId = string.Empty;
    //    bool result = false;
    //    string GetDash = "_";
    //    string GetSessionEmployeeID = Convert.ToString(Session["EmployeeCodeId"]);


    //    if (GetCurrentDate != string.Empty && GetEmployeeId != string.Empty && lblCustomField2.Text != string.Empty)
    //    {
    //        string DocumentName = string.Concat(GetEmployeeId, GetDash, GetCurrentDate, GetDash, "CusFd2");
    //        if (txtCustomField2.HasFile)
    //        {
    //            string fileExtension = System.IO.Path.GetExtension(txtCustomField2.FileName);
    //            if (fileExtension != Ex_PDF)
    //            {
    //                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Please Upload only PDF extension file format');", true);
    //            }
    //            else
    //            {
    //                int fileSize = txtCustomField2.PostedFile.ContentLength;
    //                if (fileSize == 0 || fileSize > MaxFileSize)
    //                {
    //                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Maximum upload file size is 5MB.');", true);
    //                }
    //                else
    //                {
    //                    try
    //                    {
    //                        string extension = Path.GetExtension(txtCustomField2.PostedFile.FileName);
    //                        DirectoryInfo isDirectExists = new DirectoryInfo(Server.MapPath("~/Masters/EmployeeDocumentUpload"));
    //                        if (!isDirectExists.Exists)
    //                        {
    //                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('The Application doest not contain Leave Application Upload Files folder, please create it');", true);
    //                            result = false;
    //                        }
    //                        else
    //                        {
    //                            string serverpath = Server.MapPath("~/Masters/EmployeeDocumentUpload/") + DocumentName + extension;
    //                            finalCustomefile2 = AppendFileNumberIfExists(serverpath, extension);
    //                            txtCustomField2.SaveAs(finalCustomefile2);
    //                            Session["EmployeeCusDoc2"] = finalCustomefile2;
    //                            //ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File uploaded Sucessfully');", true);
    //                            btnCustomAdd2.Visible = false;
    //                            btnCustomView2.Visible = true;
    //                            hdnpdfViewer2.Value = finalCustomefile2;
    //                            //txtCustomField1.FileName = DocumentName;
    //                        }
    //                    }
    //                    catch (Exception ex)
    //                    {
    //                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //                    }
    //                }
    //            }
    //        }
    //        else
    //        {
    //            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Upload the necessary document to avail this leave.');", true);

    //        }
    //    }
    //    else
    //    {
    //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //    }
    //}

    //protected void btnCustomAdd3_Click(object sender, EventArgs e)
    //{
    //    int MaxFileSize = Convert.ToInt32(ConfigurationManager.AppSettings["MaxFileSize"]);
    //    string Ex_JPEG = ConfigurationManager.AppSettings["Ex_JPEG"];
    //    string Ex_JPG = ConfigurationManager.AppSettings["Ex_JPG"];
    //    string Ex_BMP = ConfigurationManager.AppSettings["Ex_BMP"];
    //    string Ex_PNG = ConfigurationManager.AppSettings["Ex_PNG"];
    //    string Ex_PDF = ConfigurationManager.AppSettings["Ex_PDF"];
    //    string Ex_DOC = ConfigurationManager.AppSettings["Ex_DOC"];
    //    string Ex_DOCX = ConfigurationManager.AppSettings["Ex_DOCX"];
    //    string GetCurrentDate = DateTime.Today.ToString("yyyyMMdd");
    //    string GetEmployeeId = Convert.ToString(txt_SwipeCardNo.Text);
    //    string GetLeaveApplicationId = string.Empty;
    //    bool result = false;
    //    string GetDash = "_";
    //    string GetSessionEmployeeID = Convert.ToString(Session["EmployeeCodeId"]);


    //    if (GetCurrentDate != string.Empty && GetEmployeeId != string.Empty && lblCustomField3.Text != string.Empty)
    //    {
    //        string DocumentName = string.Concat(GetEmployeeId, GetDash, GetCurrentDate, GetDash, "CusFd3");
    //        if (txtCustomField3.HasFile)
    //        {
    //            string fileExtension = System.IO.Path.GetExtension(txtCustomField3.FileName);
    //            if (fileExtension != Ex_PDF)
    //            {
    //                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Please Upload only PDF extension file format');", true);
    //            }
    //            else
    //            {
    //                int fileSize = txtCustomField3.PostedFile.ContentLength;
    //                if (fileSize == 0 || fileSize > MaxFileSize)
    //                {
    //                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Maximum upload file size is 5MB.');", true);
    //                }
    //                else
    //                {
    //                    try
    //                    {
    //                        string extension = Path.GetExtension(txtCustomField3.PostedFile.FileName);
    //                        DirectoryInfo isDirectExists = new DirectoryInfo(Server.MapPath("~/Masters/EmployeeDocumentUpload"));
    //                        if (!isDirectExists.Exists)
    //                        {
    //                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('The Application doest not contain Leave Application Upload Files folder, please create it');", true);
    //                            result = false;
    //                        }
    //                        else
    //                        {
    //                            string serverpath = Server.MapPath("~/Masters/EmployeeDocumentUpload/") + DocumentName + extension;
    //                            finalCustomefile3 = AppendFileNumberIfExists(serverpath, extension);
    //                            txtCustomField3.SaveAs(finalCustomefile3);
    //                            Session["EmployeeCusDoc3"] = finalCustomefile3;
    //                            //ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File uploaded Sucessfully');", true);
    //                            btnCustomAdd3.Visible = false;
    //                            btnCustomView3.Visible = true;
    //                            hdnpdfViewer3.Value = finalCustomefile3;
    //                            //txtCustomField1.FileName = DocumentName;
    //                        }
    //                    }
    //                    catch (Exception ex)
    //                    {
    //                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //                    }
    //                }
    //            }
    //        }
    //        else
    //        {
    //            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Upload the necessary document to avail this leave.');", true);

    //        }
    //    }
    //    else
    //    {
    //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //    }
    //}

    //protected void btnCustomAdd4_Click(object sender, EventArgs e)
    //{
    //    int MaxFileSize = Convert.ToInt32(ConfigurationManager.AppSettings["MaxFileSize"]);
    //    string Ex_JPEG = ConfigurationManager.AppSettings["Ex_JPEG"];
    //    string Ex_JPG = ConfigurationManager.AppSettings["Ex_JPG"];
    //    string Ex_BMP = ConfigurationManager.AppSettings["Ex_BMP"];
    //    string Ex_PNG = ConfigurationManager.AppSettings["Ex_PNG"];
    //    string Ex_PDF = ConfigurationManager.AppSettings["Ex_PDF"];
    //    string Ex_DOC = ConfigurationManager.AppSettings["Ex_DOC"];
    //    string Ex_DOCX = ConfigurationManager.AppSettings["Ex_DOCX"];
    //    string GetCurrentDate = DateTime.Today.ToString("yyyyMMdd");
    //    string GetEmployeeId = Convert.ToString(txt_SwipeCardNo.Text);
    //    string GetLeaveApplicationId = string.Empty;
    //    bool result = false;
    //    string GetDash = "_";
    //    string GetSessionEmployeeID = Convert.ToString(Session["EmployeeCodeId"]);


    //    if (GetCurrentDate != string.Empty && GetEmployeeId != string.Empty && lblCustomField4.Text != string.Empty)
    //    {
    //        string DocumentName = string.Concat(GetEmployeeId, GetDash, GetCurrentDate, GetDash, "CusFd4");
    //        if (txtCustomField4.HasFile)
    //        {
    //            string fileExtension = System.IO.Path.GetExtension(txtCustomField4.FileName);
    //            if (fileExtension != Ex_PDF)
    //            {
    //                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Please Upload only PDF extension file format');", true);
    //            }
    //            else
    //            {
    //                int fileSize = txtCustomField4.PostedFile.ContentLength;
    //                if (fileSize == 0 || fileSize > MaxFileSize)
    //                {
    //                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Maximum upload file size is 5MB.');", true);
    //                }
    //                else
    //                {
    //                    try
    //                    {
    //                        string extension = Path.GetExtension(txtCustomField4.PostedFile.FileName);
    //                        DirectoryInfo isDirectExists = new DirectoryInfo(Server.MapPath("~/Masters/EmployeeDocumentUpload"));
    //                        if (!isDirectExists.Exists)
    //                        {
    //                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('The Application doest not contain Leave Application Upload Files folder, please create it');", true);
    //                            result = false;
    //                        }
    //                        else
    //                        {
    //                            string serverpath = Server.MapPath("~/Masters/EmployeeDocumentUpload/") + DocumentName + extension;
    //                            finalCustomefile4 = AppendFileNumberIfExists(serverpath, extension);
    //                            txtCustomField4.SaveAs(finalCustomefile4);
    //                            Session["EmployeeCusDoc4"] = finalCustomefile4;
    //                            //ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File uploaded Sucessfully');", true);
    //                            btnCustomAdd4.Visible = false;
    //                            btnCustomView4.Visible = true;
    //                            hdnpdfViewer4.Value = finalCustomefile4;
    //                            //txtCustomField1.FileName = DocumentName;
    //                        }
    //                    }
    //                    catch (Exception ex)
    //                    {
    //                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //                    }
    //                }
    //            }
    //        }
    //        else
    //        {
    //            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Upload the necessary document to avail this leave.');", true);

    //        }
    //    }
    //    else
    //    {
    //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //    }
    //}

    //protected void btnCustomAdd5_Click(object sender, EventArgs e)
    //{
    //    int MaxFileSize = Convert.ToInt32(ConfigurationManager.AppSettings["MaxFileSize"]);
    //    string Ex_JPEG = ConfigurationManager.AppSettings["Ex_JPEG"];
    //    string Ex_JPG = ConfigurationManager.AppSettings["Ex_JPG"];
    //    string Ex_BMP = ConfigurationManager.AppSettings["Ex_BMP"];
    //    string Ex_PNG = ConfigurationManager.AppSettings["Ex_PNG"];
    //    string Ex_PDF = ConfigurationManager.AppSettings["Ex_PDF"];
    //    string Ex_DOC = ConfigurationManager.AppSettings["Ex_DOC"];
    //    string Ex_DOCX = ConfigurationManager.AppSettings["Ex_DOCX"];
    //    string GetCurrentDate = DateTime.Today.ToString("yyyyMMdd");
    //    string GetEmployeeId = Convert.ToString(txt_SwipeCardNo.Text);
    //    string GetLeaveApplicationId = string.Empty;
    //    bool result = false;
    //    string GetDash = "_";
    //    string GetSessionEmployeeID = Convert.ToString(Session["EmployeeCodeId"]);


    //    if (GetCurrentDate != string.Empty && GetEmployeeId != string.Empty && lblCustomField5.Text != string.Empty)
    //    {
    //        string DocumentName = string.Concat(GetEmployeeId, GetDash, GetCurrentDate, GetDash, "CusFd5");
    //        if (txtCustomField5.HasFile)
    //        {
    //            string fileExtension = System.IO.Path.GetExtension(txtCustomField5.FileName);
    //            if (fileExtension != Ex_DOC && fileExtension != Ex_DOCX && fileExtension != Ex_PDF && fileExtension != Ex_JPG && fileExtension != Ex_JPEG)
    //            {
    //                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Please Upload only PDF,DOC,JPEG.JPG extension file format');", true);
    //            }
    //            else
    //            {
    //                int fileSize = txtCustomField5.PostedFile.ContentLength;
    //                if (fileSize == 0 || fileSize > MaxFileSize)
    //                {
    //                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Maximum upload file size is 5MB.');", true);
    //                }
    //                else
    //                {
    //                    try
    //                    {
    //                        string extension = Path.GetExtension(txtCustomField5.PostedFile.FileName);
    //                        DirectoryInfo isDirectExists = new DirectoryInfo(Server.MapPath("~/Masters/EmployeeDocumentUpload"));
    //                        if (!isDirectExists.Exists)
    //                        {
    //                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('The Application doest not contain Leave Application Upload Files folder, please create it');", true);
    //                            result = false;
    //                        }
    //                        else
    //                        {
    //                            string serverpath = Server.MapPath("~/Masters/EmployeeDocumentUpload/") + DocumentName + extension;
    //                            finalCustomefile5 = AppendFileNumberIfExists(serverpath, extension);
    //                            txtCustomField5.SaveAs(finalCustomefile5);
    //                            Session["EmployeeCusDoc5"] = finalCustomefile5;
    //                            //ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File uploaded Sucessfully');", true);
    //                            btnCustomAdd5.Visible = false;
    //                            btnCustomView5.Visible = true;
    //                            hdnpdfViewer5.Value = finalCustomefile5;
    //                            //txtCustomField1.FileName = DocumentName;
    //                        }
    //                    }
    //                    catch (Exception ex)
    //                    {
    //                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //                    }
    //                }
    //            }
    //        }
    //        else
    //        {
    //            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Upload the necessary document to avail this leave.');", true);

    //        }
    //    }
    //    else
    //    {
    //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
    //    }
    //}

    private string AppendFileNumberIfExists(string file, string ext)
    {
        // If the file exists, then do stuff. Otherwise, we just return the original file name.
        if (File.Exists(file))
        {
            string folderPath = Path.GetDirectoryName(file); // The path to the file. No sense in dealing with this unecessarily. 
            string fileName = Path.GetFileNameWithoutExtension(file); // The file name with no extension. 
            string extension = string.Empty; // The file extension. 
                                             // This lets us pass in an empty string for the file extension if required. i.e. It just makes this function a bit more versatile. 
            if (ext == string.Empty)
            {
                extension = Path.GetExtension(file);
            }
            else
            {
                extension = ext;
            }
            // at this point, find out if the fileName ends in a number, then get that number.
            int fileNumber = 0; // This stores the number as a number for us. 
                                // need a regex here - \(([0-9]+)\)$
            Regex r = new Regex(@"\(([0-9]+)\)$"); // This matches the pattern we are using, i.e. ~(#).ext
            Match m = r.Match(fileName); // We pass in the file name with no extension.
            string addSpace = " "; // We'll add a space when we don't have our pattern in order to pad the pattern.
            if (m.Success)
            {
                addSpace = string.Empty; // We have the pattern, so we don't add a space - it has already been added. 
                string s = m.Groups[1].Captures[0].Value; // This is the single capture that we are looking for. Stored as a string.
                                                          // set fileNumber to the new number.
                fileNumber = int.Parse(s); // Convert the number to an int.
                                           // remove the numbering from the string as we're constructing it again below.
                fileName = fileName.Replace("(" + s + ")", "");
            }
            if (File.Exists(file))
            {
                File.Delete(file);
            }

            // Start looping. 
            //do
            //{
            //    fileNumber += 1; // Increment the file number that we have above. 
            //    file = Path.Combine(folderPath, // Combine it all.
            //                            String.Format("{0}{3}({1}){2}", // The pattern to combine.
            //                                                      fileName,         // The file name with no extension. 
            //                                                      fileNumber,       // The file number.
            //                                                      extension,        // The file extension.
            //                                                      addSpace));       // A space if needed to pad the initial ~(#).ext pattern.
            //}
            //while (File.Exists(file)); // As long as the file name exists, keep looping. 
        }
        return file;
    }


    //protected void btnCustomView1_Click(object sender, EventArgs e)
    //{
    //    btnDeleteDoc1.Visible = true;

    //}
    //protected void btnCustomView2_Click(object sender, EventArgs e)
    //{
    //    btnDeleteDoc1.Visible = true;

    //}

    //protected void btnCustomView3_Click(object sender, EventArgs e)
    //{
    //    btnDeleteDoc1.Visible = true;

    //}
    //protected void btnCustomView4_Click(object sender, EventArgs e)
    //{
    //    btnDeleteDoc1.Visible = true;

    //}

    //protected void btnCustomView5_Click(object sender, EventArgs e)
    //{
    //    btnDeleteDoc1.Visible = true;
    //}


    //protected void btnDeleteDoc_Click(object sender, EventArgs e)
    //{
    //    if (File.Exists(Convert.ToString(hdnDeleteDocURL.Value)))
    //    {
    //        File.Delete(Convert.ToString(hdnDeleteDocURL.Value));
    //        //Response.Redirect("../Masters/TA_UI_Master_EmployeeModify.aspx?isFileDeleted=Y");
    //        //Proc_TA_EmployeeMasterDocumentUpload

    //        if (hdnpdfViewer1.Value == hdnDeleteDocURL.Value)
    //        {
    //            hdnpdfViewer1.Value = string.Empty;
    //            objEmployee.updateEmployeeDocument(txt_SwipeCardNo.Text, hdnpdfViewer1.Value, "cusField1");
    //            btnCustomView1.Visible = false;
    //            btnCustomAdd1.Visible = true;
    //        }
    //        if (hdnpdfViewer2.Value == hdnDeleteDocURL.Value)
    //        {
    //            hdnpdfViewer2.Value = string.Empty;
    //            objEmployee.updateEmployeeDocument(txt_SwipeCardNo.Text, hdnpdfViewer2.Value, "cusField2");
    //            btnCustomView2.Visible = false;
    //            btnCustomAdd2.Visible = true;
    //        }
    //        if (hdnpdfViewer3.Value == hdnDeleteDocURL.Value)
    //        {
    //            hdnpdfViewer3.Value = string.Empty;
    //            objEmployee.updateEmployeeDocument(txt_SwipeCardNo.Text, hdnpdfViewer3.Value, "cusField3");
    //            btnCustomView3.Visible = false;
    //            btnCustomAdd3.Visible = true;
    //        }
    //        if (hdnpdfViewer4.Value == hdnDeleteDocURL.Value)
    //        {
    //            hdnpdfViewer4.Value = string.Empty;
    //            objEmployee.updateEmployeeDocument(txt_SwipeCardNo.Text, hdnpdfViewer4.Value, "cusField4");
    //            btnCustomView4.Visible = false;
    //            btnCustomAdd4.Visible = true;
    //        }
    //        if (hdnpdfViewer5.Value == hdnDeleteDocURL.Value)
    //        {
    //            hdnpdfViewer5.Value = string.Empty;
    //            objEmployee.updateEmployeeDocument(txt_SwipeCardNo.Text, hdnpdfViewer5.Value, "cusField5");
    //            btnCustomView5.Visible = false;
    //            btnCustomAdd5.Visible = true;
    //        }

    //    }

    //}

    private void GetBlocking420EmpDetail()
    {

        DataSet dsBlocking420employess = objEmployee.SelectBlocking420employess();

        // Check if the dataset contains any rows
        if (dsBlocking420employess != null && dsBlocking420employess.Tables.Count > 0)
        {
            // Iterate over each row in the DataSet
            foreach (DataRow row in dsBlocking420employess.Tables[0].Rows)
            {
                int autoIdFromQuery = Convert.ToInt32(row["ID"]);
                int sessionEmpAutoId = Convert.ToInt32(Request.QueryString["Emp_Id"]); // Or use Session["EmpAutoID"] if required

                if (autoIdFromQuery == sessionEmpAutoId)
                {

                    Hidden2.Value = "1";


                }
            }
        }
        else
        {

        }
    }

}
