using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.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();
    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;
    #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;
    #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);
        }
        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)
        {
            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();
            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;
        otApprovalExists = objCommon.CheckPageExistsInLicense(97);
        leaveSanctionExists = objCommon.CheckPageExistsInLicense(248);
        manualEntryExists = objCommon.CheckPageExistsInLicense(98);
        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.ToInt32(Session["packageID"]) < 159)  //vaigai and future clients
            {
                DivMobileSMS.Style.Add("display", "block");
            }
        }
    }
    # 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 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;
            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, txtCustomField1.Text, txtCustomField2.Text, txtCustomField3.Text,
                                   txtCustomField4.Text, txtCustomField5.Text, Convert.ToBoolean(Session["ApplnMode"]), penaltyCat, MobileClockInOut, SMS);
                        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"
    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;
        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/defaultPhoto.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"]);
                }
                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"])));
                }
                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 (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 (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 (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 (ds_Empdetails.Tables[0].Rows[0]["CustomField5"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField5"]) != string.Empty)
                {
                    txtCustomField5.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["CustomField5"]);
                }
                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;
    }
    #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
    #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);
                                    DataTable dtTemp = GetMaxDaysWithoutLeavePolicy();
                                    if (dtTemp.Rows.Count > 0)
                                    {
                                        for (int k = 0; k < dtTemp.Rows.Count; k++)
                                        {
                                            if (Convert.ToDecimal(GetMaxDays(Convert.ToInt32(dtTemp.Rows[k]["LeaveTypeId"]))) > -1)
                                            {
                                                objEmployee.InsertYearclosure_Modify(intLevelID, MaxID, Convert.ToInt32(dtTemp.Rows[k]["LeaveTypeId"]), Convert.ToDecimal(GetMaxDays(Convert.ToInt32(dtTemp.Rows[k]["LeaveTypeId"]))), EmployeeID);
                                                notYearClosure = true;
                                            }
                                        }
                                    }
                                    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);
            }
            #region Yearclosure table Insert/Update old
            #endregion
        }
        else
        {
            objEmployee.delete_EmployeeLeavePolicy(intEmpid);
        }
    }
    #endregion
    private void LoadStrings(CultureInfo ci)
    {
        lbl_EntranceName.Text = rm.GetString("lbl_Entrance", ci);
        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_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();
    }
}
