using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Leave Policy                                Last Modified : 14-Aug-2007
* Programmer      : Arun Vinoth.T
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          : \\Windev\EIT\Projects\Inprogress\SCREEN1206\code\TimecheckAVBackup
****************************************************************************************************************************/
public partial class Master_TA_UI_MasterLeavePolicyModify : Base.BasePage
{
    #region "Variable  Declaration"
    //variable declaration
    string gstrUserGroupName = string.Empty, ddlEmpCategory, ddlEmpType, ddlReligion;
    int intPolicyID, EmployeeID;
    bool checkApplicableDaysExist, blApplicable, checkMaxDaysSpellExist, checkMinDaysSpellExist;
    bool checkSpellPerYearExist, checkCalcFactorExists, checkMinWorkedDaysExists;
    ResourceManager rm;
    cls_Common objCommon = new cls_Common();
    LeaveEventData objLeave = new LeaveEventData();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    CultureInfo ci;
    EmployeeEventData objEmployeeEventData = new EmployeeEventData();
    Table tbl_LeavePolicy = new Table();
    DataSet ds_LeaveType = new DataSet();
    DataSet ds_LeavePolicy = new DataSet();
    DataSet ds_leavePolicyDetails = new DataSet();
    #endregion
    #region PageLoadEvents
    protected void Page_Init(object sender, EventArgs e)
    {
        //useful for maintaining viewstate in dynamic controls
        if (IsPostBack)
        {
            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;

            if (Session["LeaveType"] != null)
            {
                ds_LeaveType = (DataSet)Session["LeaveType"];
            }
            if (Session["LeavePolicy"] != null)
            {
                ds_LeavePolicy = (DataSet)Session["LeavePolicy"];
            }
            if (Session["LeavePolicyDetails"] != null)
            {
                ds_leavePolicyDetails = (DataSet)Session["LeavePolicyDetails"];
            }
        }
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        if (!IsPostBack)
        {
            if (shouldCreateControl == true)
            {
                //table created and policy details loaded
                //BindingEmployeeCategoryandType();
                tbl_LeavePolicy.Rows.Clear();
                Table_Creation();
                BindPolicyDetails();
            }
            ViewState["NotModifyInCategory"] = true;
            objCommon.menu("LeaveMasters", "196");
        }
    }
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        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;
        // LoadStrings Function fills the Label from the Resource File
        LoadStrings(ci);
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        //Set UserRights
        UserRights();
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        txt_PolicyName.Focus();
        intPolicyID = Convert.ToInt32(Request.QueryString["Policy_Id"]);
        hdfFilter.Value = Convert.ToString(intPolicyID);
        int count = objLeave.CheckLeavePolicy(intPolicyID);
        if (count > 0)
        {
            btn_save.Enabled = false;
            btn_save.OnClientClick = null;
        }
        //btn_save.Attributes.Add("onclick", "return FieldValidation('" + rm.GetString("Alert_EnterPolicyName", ci) + "');");
        //getting leave policy
        ds_LeavePolicy = objLeave.SelectLeavePolicyByID(intPolicyID, gstrUserGroupName);
        //getting leave policy details
        ds_leavePolicyDetails = objLeave.SelectLeavePolicyDetails(intPolicyID);
        ds_LeaveType = objLeave.SelectLeaveTypeDetails("");
        if (Session["LeaveType"] != null)
        {
            ds_LeaveType = Session["LeaveType"] as DataSet;
        }
        else
        {
            Session["LeaveType"] = ds_LeaveType;
        }
        if (Session["LeavePolicy"] == null)
        {
            Session["LeavePolicy"] = ds_LeavePolicy;
        }
        if (Session["LeavePolicyDetails"] == null)
        {
            Session["LeavePolicyDetails"] = ds_leavePolicyDetails;
        }
        #region "Table creation"
        //tbl_LeavePolicy.Width = Unit.Pixel(800);
        tbl_LeavePolicy.CssClass = "td";
        TableHeaderRow hr = new TableHeaderRow();
        TableHeaderCell hc_Applicable = new TableHeaderCell();
        hc_Applicable.Width = Unit.Percentage(1);
        hc_Applicable.CssClass = "lvepo-tblhdr";
        hc_Applicable.VerticalAlign = VerticalAlign.Top;
        hc_Applicable.Text = rm.GetString("LeavePolicy_Applicable", ci);
        hr.Cells.Add(hc_Applicable);
        TableHeaderCell hc_type = new TableHeaderCell();
        hc_type.VerticalAlign = VerticalAlign.Top;
        hc_type.Width = Unit.Percentage(1);
        hc_type.CssClass = "lvepo-tblhdr";
        hc_type.Text = rm.GetString("lbl_leavetype", ci);
        hr.Cells.Add(hc_type);
        TableHeaderCell hc_days = new TableHeaderCell();
        hc_days.VerticalAlign = VerticalAlign.Top;
        hc_days.Width = Unit.Percentage(1);
        hc_days.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_days.Text = rm.GetString("LeavePolicy_AppDays", ci);
        hr.Cells.Add(hc_days);

        TableHeaderCell hc_DaysPerMonth = new TableHeaderCell();
        hc_DaysPerMonth.VerticalAlign = VerticalAlign.Top;
        hc_DaysPerMonth.Width = Unit.Percentage(1);
        hc_DaysPerMonth.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_DaysPerMonth.Text = rm.GetString("LeavePolicy_MaxDaysPerMon", ci);
        hr.Cells.Add(hc_DaysPerMonth);
        TableHeaderCell hc_max = new TableHeaderCell();
        hc_max.VerticalAlign = VerticalAlign.Top;
        hc_max.Width = Unit.Percentage(1);
        hc_max.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_max.Text = rm.GetString("LeavePolicy_MaxDaysPerSpell", ci);
        hr.Cells.Add(hc_max);
        TableHeaderCell hc_min = new TableHeaderCell();
        hc_min.VerticalAlign = VerticalAlign.Top;
        hc_min.Width = Unit.Percentage(1);
        hc_min.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_min.Text = rm.GetString("LeavePolicy_MinDaysPerSpell", ci);
        hr.Cells.Add(hc_min);
        TableHeaderCell hc_spell = new TableHeaderCell();
        hc_spell.VerticalAlign = VerticalAlign.Top;
        hc_spell.Width = Unit.Percentage(1);
        hc_spell.CssClass = "lvepo-tblhdr";
        hc_spell.Text = rm.GetString("LeavePlicy_SpellsPeryear", ci);
        hr.Cells.Add(hc_spell);
        TableHeaderCell hc_LOP = new TableHeaderCell();
        hc_LOP.VerticalAlign = VerticalAlign.Top;
        hc_LOP.Width = Unit.Percentage(1);
        hc_LOP.CssClass = "lvepo-tblhdr";
        hc_LOP.Text = rm.GetString("lbl_LOP", ci);
        hr.Cells.Add(hc_LOP);
        TableHeaderCell hc_LOPdays = new TableHeaderCell();
        hc_LOPdays.VerticalAlign = VerticalAlign.Top;
        hc_LOPdays.Width = Unit.Percentage(1);
        hc_LOPdays.CssClass = "lvepo-tblhdr";
        hc_LOPdays.Text = rm.GetString("LeavePolicy_MaxLOP", ci);
        hr.Cells.Add(hc_LOPdays);
        TableHeaderCell hc_Count = new TableHeaderCell();
        hc_Count.VerticalAlign = VerticalAlign.Top;
        hc_Count.HorizontalAlign = HorizontalAlign.Center;
        //hc_Count.Width = Unit.Pixel(15);
        hc_Count.CssClass = "lvepo-tblhdr lve-tblwid2";
        hc_Count.Text = rm.GetString("LeavePolicy_CountWeekoff", ci);
        hr.Cells.Add(hc_Count);
        TableHeaderCell hc_Borrow = new TableHeaderCell();
        hc_Borrow.VerticalAlign = VerticalAlign.Top;
        hc_Borrow.Width = Unit.Percentage(1);
        hc_Borrow.CssClass = "lvepo-tblhdr";
        hc_Borrow.Text = rm.GetString("LeavePlocy_Borrow", ci);
        hr.Cells.Add(hc_Borrow);
        TableHeaderCell hc_Carry = new TableHeaderCell();
        hc_Carry.VerticalAlign = VerticalAlign.Top;
        hc_Carry.Width = Unit.Percentage(1);
        hc_Carry.CssClass = "lvepo-tblhdr";
        hc_Carry.Text = rm.GetString("LeavePolicy_CarryOver", ci);
        hr.Cells.Add(hc_Carry);
        TableHeaderCell hc_MaxAcc = new TableHeaderCell();
        hc_MaxAcc.VerticalAlign = VerticalAlign.Top;
        hc_MaxAcc.Width = Unit.Percentage(1);
        hc_MaxAcc.CssClass = "lvepo-tblhdr";
        hc_MaxAcc.Text = rm.GetString("LeavePolicy_MaxAccDays", ci);
        hr.Cells.Add(hc_MaxAcc);
        TableHeaderCell hc_encash = new TableHeaderCell();
        hc_encash.VerticalAlign = VerticalAlign.Top;
        hc_encash.Width = Unit.Percentage(1);
        hc_encash.CssClass = "lvepo-tblhdr";
        hc_encash.Text = rm.GetString("LeavePolicy_Encash", ci);
        hr.Cells.Add(hc_encash);
        TableHeaderCell hc_AppAfter = new TableHeaderCell();
        hc_AppAfter.VerticalAlign = VerticalAlign.Top;
        hc_AppAfter.Width = Unit.Percentage(1);
        hc_AppAfter.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_AppAfter.Text = rm.GetString("LeavePolicy_ApplAfterDays", ci);
        hr.Cells.Add(hc_AppAfter);
        TableHeaderCell hc_CalcFactor = new TableHeaderCell();
        hc_CalcFactor.VerticalAlign = VerticalAlign.Top;
        hc_CalcFactor.Visible = true;
        hc_CalcFactor.CssClass = "lvepo-tblhdr";
        hc_CalcFactor.Width = Unit.Percentage(1);
        hc_CalcFactor.Text = rm.GetString("LeavePolicy_CalcFactor", ci);
        hr.Cells.Add(hc_CalcFactor);
        TableHeaderCell hc_Workdays = new TableHeaderCell();
        hc_Workdays.VerticalAlign = VerticalAlign.Top;
        hc_Workdays.Width = Unit.Percentage(1);
        hc_Workdays.CssClass = "lvepo-tblhdr";
        hc_Workdays.Text = rm.GetString("LeavePolicy_MinWorkDays", ci);
        hr.Cells.Add(hc_Workdays);
        TableHeaderCell hc_CountFactor = new TableHeaderCell();
        hc_CountFactor.VerticalAlign = VerticalAlign.Top;
        hc_CountFactor.Visible = true;
        hc_Workdays.Width = Unit.Percentage(1);
        hc_CountFactor.CssClass = "lvepo-tblhdr";
        hc_CountFactor.Text = rm.GetString("lblCountFactor", ci);
        hr.Cells.Add(hc_CountFactor);
        TableHeaderCell Thc_AvailNoTimes = new TableHeaderCell();
        Thc_AvailNoTimes.VerticalAlign = VerticalAlign.Top;
        Thc_AvailNoTimes.Width = Unit.Percentage(1);
        Thc_AvailNoTimes.Visible = true;
        //hc_CountFactor.Width = Unit.Pixel(100);
        Thc_AvailNoTimes.CssClass = "lvepo-tblhdr";
        Thc_AvailNoTimes.Text = "Service Period - Avail";
        hr.Cells.Add(Thc_AvailNoTimes);

        tbl_LeavePolicy.Rows.Add(hr);
        PH_DynmCtrl.Controls.Add(tbl_LeavePolicy);
        #endregion
        int i = 1;
        if (Convert.ToBoolean(ViewState["NotModifyInCategory"]) == true)
        {
            foreach (DataRow dr in ds_LeaveType.Tables[0].Rows)
            {
                #region "Controls creation"
                TableRow tr = new TableRow();
                TableCell tc_Applicable = new TableCell();
                tc_Applicable.HorizontalAlign = HorizontalAlign.Center;
                CheckBox chk_Applicable = new CheckBox();
                chk_Applicable.ID = "Applicable" + i;
                chk_Applicable.CssClass = "checkboxLeave checkboxLeave-primary";
                chk_Applicable.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-top:10px;min-height: 17px;");
                tc_Applicable.Controls.Add(chk_Applicable);
                tr.CssClass = "lve-text lve-potablebg";
                tr.Cells.Add(tc_Applicable);
                TableCell tc_Type = new TableCell();
                tc_Type.Text = Convert.ToString(dr["LeaveType"]);
                tc_Type.CssClass = "lve-clsl";
                tr.Cells.Add(tc_Type);
                TableCell tc_Total = new TableCell();
                tc_Total.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb = new TextBox();
                tb.ID = "total" + i;
                tb.Attributes.Add("onkeypress", "return number_only(event,this);");
                tb.Attributes.Add("onpaste", "return false;");
                tb.Attributes.Add("ondrop", "return false;");
                tb.MaxLength = 3;
                tb.CssClass = "form-control lve-form1";
                if (Convert.ToString(dr["CountFactor"]) == "True")
                {
                    tb.Enabled = false;
                }
                tc_Total.Controls.Add(tb);
                tr.Cells.Add(tc_Total);
                /*Below parameter is used for Angler*/
                TableCell tc_MaxDaysPerMonth = new TableCell();
                TextBox tb_MaxDaysPerMonth = new TextBox();

                tc_MaxDaysPerMonth.HorizontalAlign = HorizontalAlign.Center;
                tb_MaxDaysPerMonth.ID = "MaxDaysPerMonth" + i;
                tb_MaxDaysPerMonth.Attributes.Add("onkeypress", "return number_dot(event,this);");
                //tb_max.Attributes.Add("onblur", "return chkAppDayValue(this," + i + ");");
                tb_MaxDaysPerMonth.Attributes.Add("onpaste", "return false;");
                tb_MaxDaysPerMonth.Attributes.Add("ondrop", "return false;");
                tb_MaxDaysPerMonth.MaxLength = 5;
                tb_MaxDaysPerMonth.CssClass = "form-control lve-form1";
                tc_MaxDaysPerMonth.Controls.Add(tb_MaxDaysPerMonth);
                tr.Cells.Add(tc_MaxDaysPerMonth);
                TableCell tc_Max = new TableCell();
                tc_Max.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_max = new TextBox();
                tb_max.ID = "Max" + i;
                tb_max.Attributes.Add("onkeypress", "return number_dot(event,this);");
                tb_max.Attributes.Add("onpaste", "return false;");
                tb_max.Attributes.Add("ondrop", "return false;");
                tb_max.MaxLength = 5;
                tb_max.CssClass = "form-control lve-form1";
                tc_Max.Controls.Add(tb_max);
                tr.Cells.Add(tc_Max);
                TableCell tc_Min = new TableCell();
                tc_Min.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_min = new TextBox();
                tb_min.ID = "Min" + i;
                tb_min.Attributes.Add("onkeypress", "return number_dot(event,this);");
                tb_min.Attributes.Add("onblur", "return SpellsPerYear_fn(this," + i + ");");
                tb_min.Attributes.Add("onpaste", "return false;");
                tb_min.Attributes.Add("ondrop", "return false;");
                tb_min.MaxLength = 5;
                tb_min.CssClass = "form-control lve-form1";
                tc_Min.Controls.Add(tb_min);
                tr.Cells.Add(tc_Min);
                TableCell tc_Spell = new TableCell();
                tc_Spell.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_spell = new TextBox();
                tb_spell.ID = "Spell" + i;
                tb_spell.Attributes.Add("onkeypress", "return number_only(event,this);");
                tb_spell.Attributes.Add("onpaste", "return false;");
                tb_spell.Attributes.Add("ondrop", "return false;");
                tb_spell.MaxLength = 2;
                tb_spell.CssClass = "form-control lve-form1";
                tc_Spell.Controls.Add(tb_spell);
                tr.Cells.Add(tc_Spell);
                TableCell tc_Loss = new TableCell();
                RadioButtonList rbl_Loss = new RadioButtonList();
                rbl_Loss.ID = "Loss" + i;
                tc_Loss.Style.Add("padding-left", "20px");
                //rbl_Loss.Width = 50;
                ListItem lst_Yes = new ListItem();
                lst_Yes.Text = rm.GetString("ShiftSetting_Yes", ci);
                lst_Yes.Value = "1";
                lst_Yes.Attributes.Add("onclick", "return chkRadiobut(" + i + ",'1');");
                ListItem lst_No = new ListItem();
                lst_No.Selected = true;
                lst_No.Text = rm.GetString("ShiftSetting_No", ci);
                lst_No.Value = "0";
                rbl_Loss.Items.Add(lst_Yes);
                rbl_Loss.Items.Add(lst_No);
                rbl_Loss.CssClass = "radioPolicy radioPolicy-primary";
                rbl_Loss.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-right:0px");
                lst_No.Attributes.Add("onclick", "return chkRadiobut(" + i + ",'0');");
                tc_Loss.Controls.Add(rbl_Loss);
                tr.Cells.Add(tc_Loss);
                TableCell tc_MaxLOP = new TableCell();
                tc_MaxLOP.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_LOP = new TextBox();
                tb_LOP.ID = "MaxLOP" + i;
                tb_LOP.Attributes.Add("onkeypress", "return number_dot(event,this);");
                tb_LOP.Attributes.Add("onpaste", "return false;");
                tb_LOP.Attributes.Add("ondrop", "return false;");
                tb_LOP.MaxLength = 5;
                tb_LOP.CssClass = "form-control lve-form1";
                tb_LOP.Enabled = false;
                tc_MaxLOP.Controls.Add(tb_LOP);
                tr.Cells.Add(tc_MaxLOP);
                TableCell tc_Count = new TableCell();
                CheckBox chk_before = new CheckBox();
                chk_before.ID = "chkBefore" + i;
                chk_before.CssClass = "checkbox checkbox-primary holiday-chkbox";
                chk_before.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                chk_before.Text = rm.GetString("LeavePolicy_Before", ci);
                chk_before.Width = 100;
                CheckBox chk_after = new CheckBox();
                chk_after.ID = "chkAfter" + i;
                chk_after.CssClass = "checkbox checkbox-primary holiday-chkbox";
                chk_after.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                chk_after.Text = rm.GetString("LeavePolicy_After", ci);
                chk_after.Width = 100;
                CheckBox chk_inter = new CheckBox();
                chk_inter.ID = "chkInter" + i;
                chk_inter.CssClass = "checkbox checkbox-primary holiday-chkbox";
                chk_inter.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                chk_inter.Text = rm.GetString("LeavePolicy_Intervening", ci);
                chk_inter.Width = 100;
                tc_Count.Controls.Add(chk_before);
                tc_Count.Controls.Add(chk_after);
                tc_Count.Controls.Add(chk_inter);
                tr.Cells.Add(tc_Count);
                TableCell tc_Borrow = new TableCell();
                tc_Borrow.HorizontalAlign = HorizontalAlign.Center;
                CheckBox chk_Borrow = new CheckBox();
                chk_Borrow.ID = "Borrow" + i;
                chk_Borrow.Text = " ";
                chk_Borrow.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                //chk_Borrow.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                tc_Borrow.Controls.Add(chk_Borrow);
                tr.Cells.Add(tc_Borrow);
                TableCell tc_Carry = new TableCell();
                tc_Carry.HorizontalAlign = HorizontalAlign.Center;
                CheckBox chk_carry = new CheckBox();
                chk_carry.ID = "Carry" + i;
                chk_carry.Text = " ";
                chk_carry.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                //chk_carry.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                tc_Carry.Controls.Add(chk_carry);
                tr.Cells.Add(tc_Carry);
                TableCell tc_Acc = new TableCell();
                tc_Acc.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_Acc = new TextBox();
                tb_Acc.ID = "Acc" + i;
                tb_Acc.Attributes.Add("onkeypress", "return number_dot(event,this);");
                tb_Acc.Attributes.Add("onpaste", "return false;");
                tb_Acc.Attributes.Add("ondrop", "return false;");
                tb_Acc.MaxLength = 5;
                tb_Acc.CssClass = "form-control  lve-form1";
                tc_Acc.Controls.Add(tb_Acc);
                tr.Cells.Add(tc_Acc);
                TableCell tc_encash = new TableCell();
                tc_encash.HorizontalAlign = HorizontalAlign.Center;
                CheckBox chk_encash = new CheckBox();
                chk_encash.ID = "Encash" + i;
                chk_encash.Text = " ";
                chk_encash.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                //chk_encash.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                tc_encash.Controls.Add(chk_encash);
                tr.Cells.Add(tc_encash);
                TableCell tc_AppAfter = new TableCell();
                tc_AppAfter.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_AppAfter = new TextBox();
                tb_AppAfter.ID = "AppAfter" + i;
                tb_AppAfter.Attributes.Add("onkeypress", "return number_dot(event,this);");
                tb_AppAfter.Attributes.Add("onpaste", "return false;");
                tb_AppAfter.Attributes.Add("ondrop", "return false;");
                tb_AppAfter.MaxLength = 5;
                tb_AppAfter.CssClass = "form-control  lve-form1";
                tc_AppAfter.Controls.Add(tb_AppAfter);
                tr.Cells.Add(tc_AppAfter);
                TableCell tc_CalcFactor = new TableCell();
                tc_CalcFactor.Visible = true;
                tc_CalcFactor.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_CalcFactor = new TextBox();
                tb_CalcFactor.ID = "calcFactor" + i;
                tb_CalcFactor.Attributes.Add("onkeypress", "return number_dot(event,this);");
                tb_CalcFactor.Attributes.Add("onpaste", "return false;");
                tb_CalcFactor.Attributes.Add("ondrop", "return false;");
                tb_CalcFactor.MaxLength = 5;
                tb_CalcFactor.CssClass = "form-control  lve-form1";
                if (Convert.ToString(dr["CountFactor"]) == "False")
                {
                    tb_CalcFactor.Enabled = false;
                }
                tc_CalcFactor.Controls.Add(tb_CalcFactor);
                tr.Cells.Add(tc_CalcFactor);
                TableCell tc_WorkDays = new TableCell();
                tc_WorkDays.Visible = true;
                tc_WorkDays.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_WorkDays = new TextBox();
                tb_WorkDays.ID = "MinWorkedDays" + i;
                tb_WorkDays.Attributes.Add("onkeypress", "return number_dot(event,this);");
                tb_WorkDays.Attributes.Add("onpaste", "return false;");
                tb_WorkDays.Attributes.Add("ondrop", "return false;");
                tb_WorkDays.MaxLength = 5;
                tb_WorkDays.CssClass = "textbox_short";
                if (Convert.ToString(dr["CountFactor"]) == "False")
                {
                    tb_WorkDays.Enabled = false;
                }
                tc_WorkDays.Controls.Add(tb_WorkDays);
                tr.Cells.Add(tc_WorkDays);
                TableCell tc_CountFactor = new TableCell();
                //tc_CountFactor.HorizontalAlign = HorizontalAlign.Center;
                tc_CountFactor.Visible = true;
                CheckBox chk_WeekDays = new CheckBox();
                chk_WeekDays.ID = "chkWeekDays" + i;
                chk_WeekDays.CssClass = "checkbox checkbox-primary holiday-chkbox";
                chk_WeekDays.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                chk_WeekDays.Text = rm.GetString("LeavePolicy_WkDay", ci);
                chk_WeekDays.Width = 100;
                CheckBox chk_WeekOff = new CheckBox();
                chk_WeekOff.ID = "chkWeekOff" + i;
                chk_WeekOff.Text = rm.GetString("LeavePolicy_WkOff", ci);
                chk_WeekOff.CssClass = "checkbox checkbox-primary holiday-chkbox";
                chk_WeekOff.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                chk_WeekOff.Width = 100;
                CheckBox chk_Leave = new CheckBox();
                chk_Leave.ID = "chkLeave" + i;
                chk_Leave.CssClass = "checkbox checkbox-primary holiday-chkbox";
                chk_Leave.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                chk_Leave.Text = rm.GetString("LeaveApplication_Leave", ci);
                chk_Leave.Width = 100;
                CheckBox chk_Holidays = new CheckBox();
                chk_Holidays.ID = "chkHolidays" + i;
                chk_Holidays.Text = rm.GetString("Menu_Masters_Holidays", ci);
                chk_Holidays.CssClass = "checkbox checkbox-primary holiday-chkbox";
                chk_Holidays.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                chk_Holidays.Width = 100;
                if (Convert.ToString(dr["CountFactor"]) == "False")
                {
                    chk_WeekDays.Enabled = false;
                    chk_WeekOff.Enabled = false;
                    chk_Leave.Enabled = false;
                    chk_Holidays.Enabled = false;
                }

                else
                {
                    chk_WeekDays.Checked = true;
                    chk_WeekDays.Enabled = false;
                }
                tc_CountFactor.Controls.Add(chk_WeekDays);
                tc_CountFactor.Controls.Add(chk_WeekOff);
                tc_CountFactor.Controls.Add(chk_Leave);
                tc_CountFactor.Controls.Add(chk_Holidays);
                tr.Cells.Add(tc_CountFactor);
                TableCell tc_TypeID = new TableCell();
                Label lbl_TypeID = new Label();
                lbl_TypeID.ID = "Type_ID" + i;
                lbl_TypeID.Text = Convert.ToString(dr[0]);
                tc_TypeID.Controls.Add(lbl_TypeID);
                tr.Cells.Add(tc_TypeID);
                tc_TypeID.Visible = false;
                TableCell tc_LeaveTypeCountFactor = new TableCell();
                HiddenField hdnCountFactor = new HiddenField();
                hdnCountFactor.ID = "hdnCountFactor" + i;
                if (Convert.ToString(dr["CountFactor"]) == "True")
                {
                    hdnCountFactor.Value = "True";
                }
                else
                {
                    hdnCountFactor.Value = "False";
                }
                tc_LeaveTypeCountFactor.Controls.Add(hdnCountFactor);
                tr.Cells.Add(tc_LeaveTypeCountFactor);
                TableCell tc_AvailNoTimes_Service = new TableCell();
                tc_AvailNoTimes_Service.HorizontalAlign = HorizontalAlign.Center;
                TextBox txtAvailNoTime = new TextBox();
                txtAvailNoTime.ID = "txtAvailNoTimes" + i;
                txtAvailNoTime.Attributes.Add("onkeypress", "return number_dot(event,this);");
                txtAvailNoTime.MaxLength = 1;
                txtAvailNoTime.CssClass = "form-control  lve-form1";
                tc_AvailNoTimes_Service.Controls.Add(txtAvailNoTime);
                Label lblTimes = new Label();
                lblTimes.Text = "Time(s)";
                tc_AvailNoTimes_Service.Controls.Add(lblTimes);
                tr.Cells.Add(tc_AvailNoTimes_Service);
                tbl_LeavePolicy.Rows.Add(tr);
                if (Convert.ToInt32(dr["isWFH"]) == 1)
                {
                    tc_Count.Enabled = false;
                    tc_Loss.Enabled = false;
                    tc_Borrow.Enabled = false;
                    tc_Carry.Enabled = false;
                    tc_encash.Enabled = false;
                    tc_AppAfter.Enabled = false;
                    tb_CalcFactor.Enabled = false;
                    hdnCountFactor.Value = "false";
                    chk_WeekDays.Checked = true;
                    chk_WeekDays.Enabled = false;
                    tc_AvailNoTimes_Service.Enabled = false;
                    chk_WeekDays.Enabled = true;
                    chk_WeekOff.Enabled = true;
                    chk_Leave.Enabled = true;
                    chk_Holidays.Enabled = true;
                    tc_Acc.Enabled = false;
                }
                hdnLeaveCount.Value = Convert.ToString(i);
                i = i + 1;
                #endregion
            }
            tbl_LeavePolicy.EnableViewState = true;
            PH_DynmCtrl.Visible = true;
            ViewState["NotModifyInCategory"] = true;
        }
        else
        {
            PH_DynmCtrl.Visible = false;
            hdnLeaveCount.Value = "0";
        }
        if (!IsPostBack)
        {
            //table created and policy details loaded
            //getting leave types
            tbl_LeavePolicy.Rows.Clear();
            Table_Creation();
            //BindingEmployeeCategoryandType();
            BindPolicyDetails();
            Session["ddlEmployeeCategory"] = Convert.ToString(ddlEmpCategory);//Convert.ToInt16(ddlEmpCatagory.SelectedValue);
            Session["ddlEmployeeType"] = Convert.ToString(ddlEmpType);//Convert.ToInt16(ddlEmpType.SelectedValue);
            Session["ddlGender"] = lblSelectedGender.Text;//Convert.ToString(ddlGender.SelectedItem.Text);
            Session["ddlReligion"] = Convert.ToString(ddlReligion);//Convert.ToInt16(ddlReligion.SelectedValue);
            string strSetAlert = "";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "chkPermission('" + rm.GetString("Alert_Enterinhhmmformat", ci) + "');";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_SelectOvertimetype") + "','" + rm.GetString("Alert_EnterMinimumOTHours") + "','" + rm.GetString("Alert_EnterPolicyName") + "','" + rm.GetString("Alert_ConfirmSave") + "','" + rm.GetString("Alert_SpellYearNotEmpty") + "','" + rm.GetString("Alert_ApplyLeaveForLeavePolicy") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("Alert_AppDaysNotEmpty") + "','" + rm.GetString("Alert_MaxDaysPerSpellNotEmpty") + "','" + rm.GetString("Alert_EnterPermissionHours") + "','" + rm.GetString("Alert_CalcFactor") + "','" + rm.GetString("Alert_EnterPermissionHours") + "','" + rm.GetString("Alert_EnterMaximunPermissionHrs") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("Alert_EnterMaximunNoOfInstance") + "','" + rm.GetString("Alert_EnterMaximunPermissionHrsPerInstance") + "','" + rm.GetString("Alert_EntervalidTime") + "','" + rm.GetString("Alert_AppDaysNotZero") + "','" + rm.GetString("Alert_InvalidAppDays") + "','" + rm.GetString("Alert_MaxValue_AppDays_365") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("Alert_MaxDaysPerSpellNotZero") + "','" + rm.GetString("Alert_InvalidMaxDaysPerSpell") + "','" + rm.GetString("Alert_MaxValue_MaxDaysPerSpell_365") + "','" + rm.GetString("Alert_MinDaysPerSpellNotZero") + "','" + rm.GetString("Alert_InvalidMinDaysPerSpell") + "','" + rm.GetString("Alert_MaxValue_MinDaysPerSpell_365") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("Alert_MinDaysPerSpellNotEmpty") + "','" + rm.GetString("ALert_MaxDaysLesserThanAppDays") + "','" + rm.GetString("Alert_MinDaysLesserThanAppDays") + "','" + rm.GetString("Alert_SpellsPerYearLesserThanAppDays") + "','" + rm.GetString("Alert_MinDaysLesserThanMaxDays") + "','" + rm.GetString("Alert_MaxLOPNotZero") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("ALert_InvalidMaxLOP") + "','" + rm.GetString("ALert_MaxValue_MaxLOP_365") + "','" + rm.GetString("ALert_MaxLOPNotEmpty") + "','" + rm.GetString("Alert_MaxAccDaysNotZero") + "','" + rm.GetString("Alert_InvalidMaxAccDays") + "','" + rm.GetString("Alert_MaxValue_MaxAccDays_365") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("Alert_AppAfterDaysNotZero") + "','" + rm.GetString("Alert_InvalidAppAfterDays") + "','" + rm.GetString("Alert_MaxValue_AppAfterDays_365") + "','" + rm.GetString("Alert_CalcFactorNotZero") + "','" + rm.GetString("Alert_InvalidCalcFactor") + "','" + rm.GetString("Alert_MaxValue_CalcFactor_365") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("Alert_CalcFactorNotEmpty") + "','" + rm.GetString("Alert_MinWorkDaysNotZero") + "','" + rm.GetString("ALert_InvalidMinWorkDays") + "','" + rm.GetString("Alert_MaxValue_WorkDay_365") + "','" + rm.GetString("Alert_MinWorkDaysNotEmpty");
            strSetAlert = strSetAlert + "','" + rm.GetString("Alert_Enter_HalfDayComoff", ci) + "','" + rm.GetString("Alert_Enter_FullDayComoff", ci) + "', '" + rm.GetString("Alert_Enter_ValidsDays", ci) + "', '" + rm.GetString("Alert_Vaild_HalfDayComoff", ci) + "', '" + rm.GetString("Alert_ClickViewButton", ci) + "', '" + rm.GetString("Alert_SelectValidOptionThenClickSave", ci) + "', '" + rm.GetString("Alert_EnterValidPermissionHours", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_save_Click(object sender, EventArgs e)
    {
        //Boolean value used for the applicable days not equal to zero
        checkApplicableDaysExist = true;
        //checked for already existing policy name and update
        int ret_value = LeavePolicy();
        if (ret_value != 1)
        {
            //deleting & reinserting leave policy details
            objLeave.PermanentDeleteLeavePolicyDetails(intPolicyID);
            //Updating the Newly Entered Leave Policy;
            LeavePolicyDetails(intPolicyID);
            if (checkApplicableDaysExist == false)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ApplicableDaysShouldNotBeZero", ci) + "');", true);
                return;
            }
            Session["LeaveType"] = null;
            Session["LeavePolicy"] = null;
            Session["LeavePolicyDetails"] = null;
            shouldCreateControl = false;
            string strRedirectPage = "TA_UI_MasterLeavePolicyView.aspx?Policy_Id=" + Convert.ToString(intPolicyID);
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_LeavePolicymodifiedsuccessfully", ci) + "');";
            strScript = strScript + "location.replace('TA_UI_MasterLeavePolicyList.aspx');";
            strScript = strScript + "</script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
        }
    }
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        //To Remove all values in all the Sessions
        Session["LeaveType"] = null;
        Session["LeavePolicy"] = null;
        Session["LeavePolicyDetails"] = null;
        Response.Redirect("TA_UI_MasterLeavePolicyList.aspx");
    }
    protected void btn_View_Click(object sender, EventArgs e)
    {
        //Creating an new tables based on the Filter conditions
        DataSet ds_LeaveType = new DataSet();
        ds_LeaveType = objLeave.SelectLeavePolicyDetails("", Convert.ToString(lblSelectedCategory.Text), Convert.ToString(lblSelectedType.Text), Convert.ToString(lblSelectedGender.Text), Convert.ToString(lblSelectedReligion.Text));
        Session["LeaveType"] = ds_LeaveType;
        Session["ddlEmployeeCategory"] = Convert.ToInt16(lblSelectedCategory.Text);
        Session["ddlEmployeeType"] = Convert.ToInt16(lblSelectedType.Text);
        Session["ddlGender"] = Convert.ToString(lblSelectedGender.Text);
        Session["ddlReligion"] = Convert.ToInt16(lblSelectedReligion.Text);
        tbl_LeavePolicy.Rows.Clear();
        #region "Table creation"
        tbl_LeavePolicy.Rows.Clear();
        //tbl_LeavePolicy.Width = Unit.Pixel(800);
        tbl_LeavePolicy.CssClass = "table table-bordered";
        TableHeaderRow hr = new TableHeaderRow();
        TableHeaderCell hc_Applicable = new TableHeaderCell();
        hc_Applicable.Width = Unit.Percentage(1);
        hc_Applicable.CssClass = "lvepo-tblhdr";
        hc_Applicable.Text = rm.GetString("LeavePolicy_Applicable", ci);
        hr.Cells.Add(hc_Applicable);
        TableHeaderCell hc_type = new TableHeaderCell();
        hc_type.Width = Unit.Percentage(1);
        hc_type.CssClass = "lvepo-tblhdr";
        hc_type.Text = rm.GetString("lbl_leavetype", ci);
        hr.Cells.Add(hc_type);
        TableHeaderCell hc_days = new TableHeaderCell();
        hc_days.Width = Unit.Percentage(1);
        hc_days.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_days.Text = rm.GetString("LeavePolicy_AppDays", ci);
        hr.Cells.Add(hc_days);
        TableHeaderCell hc_DaysPerMonth = new TableHeaderCell();
        hc_DaysPerMonth.VerticalAlign = VerticalAlign.Top;
        hc_DaysPerMonth.Width = Unit.Percentage(1);
        hc_DaysPerMonth.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_DaysPerMonth.Text = rm.GetString("LeavePolicy_MaxDaysPerMon", ci);
        hr.Cells.Add(hc_DaysPerMonth);
        TableHeaderCell hc_max = new TableHeaderCell();
        hc_max.Width = Unit.Percentage(1);
        hc_max.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_max.Text = rm.GetString("LeavePolicy_MaxDaysPerSpell", ci);
        hr.Cells.Add(hc_max);
        TableHeaderCell hc_min = new TableHeaderCell();
        hc_min.Width = Unit.Percentage(1);
        hc_min.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_min.Text = rm.GetString("LeavePolicy_MinDaysPerSpell", ci);
        hr.Cells.Add(hc_min);
        TableHeaderCell hc_spell = new TableHeaderCell();
        hc_spell.Width = Unit.Percentage(1);
        hc_spell.CssClass = "lvepo-tblhdr";
        hc_spell.Text = rm.GetString("LeavePlicy_SpellsPeryear", ci);
        hr.Cells.Add(hc_spell);
        TableHeaderCell hc_LOP = new TableHeaderCell();
        hc_LOP.Width = Unit.Percentage(1);
        hc_LOP.CssClass = "lvepo-tblhdr";
        hc_LOP.Text = rm.GetString("lbl_LOP", ci);
        hr.Cells.Add(hc_LOP);
        TableHeaderCell hc_LOPdays = new TableHeaderCell();
        hc_LOPdays.Width = Unit.Percentage(1);
        hc_LOPdays.CssClass = "lvepo-tblhdr";
        hc_LOPdays.Text = rm.GetString("LeavePolicy_MaxLOP", ci);
        hr.Cells.Add(hc_LOPdays);
        TableHeaderCell hc_Count = new TableHeaderCell();
        hc_Count.HorizontalAlign = HorizontalAlign.Center;
        //hc_Count.Width = Unit.Pixel(15);
        hc_Count.CssClass = "lvepo-tblhdr lve-tblwid2";
        hc_Count.Text = rm.GetString("LeavePolicy_CountWeekoff", ci);
        hr.Cells.Add(hc_Count);
        TableHeaderCell hc_Borrow = new TableHeaderCell();
        hc_Borrow.Width = Unit.Percentage(1);
        hc_Borrow.CssClass = "lvepo-tblhdr";
        hc_Borrow.Text = rm.GetString("LeavePlocy_Borrow", ci);
        hr.Cells.Add(hc_Borrow);
        TableHeaderCell hc_Carry = new TableHeaderCell();
        hc_Carry.Width = Unit.Percentage(1);
        hc_Carry.CssClass = "lvepo-tblhdr";
        hc_Carry.Text = rm.GetString("LeavePolicy_CarryOver", ci);
        hr.Cells.Add(hc_Carry);
        TableHeaderCell hc_MaxAcc = new TableHeaderCell();
        hc_MaxAcc.Width = Unit.Percentage(1);
        hc_MaxAcc.CssClass = "lvepo-tblhdr";
        hc_MaxAcc.Text = rm.GetString("LeavePolicy_MaxAccDays", ci);
        hr.Cells.Add(hc_MaxAcc);
        TableHeaderCell hc_encash = new TableHeaderCell();
        hc_encash.Width = Unit.Percentage(1);
        hc_encash.CssClass = "lvepo-tblhdr";
        hc_encash.Text = rm.GetString("LeavePolicy_Encash", ci);
        hr.Cells.Add(hc_encash);
        TableHeaderCell hc_AppAfter = new TableHeaderCell();
        hc_AppAfter.Width = Unit.Percentage(1);
        hc_AppAfter.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_AppAfter.Text = rm.GetString("LeavePolicy_ApplAfterDays", ci);
        hr.Cells.Add(hc_AppAfter);
        TableHeaderCell hc_CalcFactor = new TableHeaderCell();
        hc_CalcFactor.Visible = true;
        hc_CalcFactor.CssClass = "lvepo-tblhdr";
        hc_CalcFactor.Width = Unit.Percentage(1);
        hc_CalcFactor.Text = rm.GetString("LeavePolicy_CalcFactor", ci);
        hr.Cells.Add(hc_CalcFactor);
        TableHeaderCell hc_Workdays = new TableHeaderCell();
        hc_Workdays.Width = Unit.Percentage(1);
        hc_Workdays.CssClass = "lvepo-tblhdr";
        hc_Workdays.Text = rm.GetString("LeavePolicy_MinWorkDays", ci);
        hr.Cells.Add(hc_Workdays);
        TableHeaderCell hc_CountFactor = new TableHeaderCell();
        hc_CountFactor.Visible = true;
        //hc_CountFactor.Width = Unit.Pixel(100);
        hc_CountFactor.CssClass = "lvepo-tblhdr";
        hc_CountFactor.Text = rm.GetString("lblCountFactor", ci);
        hr.Cells.Add(hc_CountFactor);
        TableHeaderCell Thc_AvailNoTimes = new TableHeaderCell();
        Thc_AvailNoTimes.VerticalAlign = VerticalAlign.Top;
        Thc_AvailNoTimes.Width = Unit.Percentage(1);
        Thc_AvailNoTimes.Visible = true;
        //hc_CountFactor.Width = Unit.Pixel(100);
        Thc_AvailNoTimes.CssClass = "lvepo-tblhdr";
        Thc_AvailNoTimes.Text = "Service Period - Avail";
        hr.Cells.Add(Thc_AvailNoTimes);
        tbl_LeavePolicy.Rows.Add(hr);
        PH_DynmCtrl.Controls.Add(tbl_LeavePolicy);
        #endregion
        int i = 1;
        if (ds_LeaveType.Tables.Count > 0)
        {
            if (ds_LeaveType != null && ds_LeaveType.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds_LeaveType.Tables[0].Rows)
                {
                    ViewState["RowCount"] = ds_LeaveType.Tables[0].Rows.Count;
                    #region "Controls creation"
                    TableRow tr = new TableRow();
                    TableCell tc_Applicable = new TableCell();
                    tc_Applicable.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox chk_Applicable = new CheckBox();
                    chk_Applicable.ID = "Applicable" + i;
                    chk_Applicable.CssClass = "checkboxLeave checkboxLeave-primary";
                    chk_Applicable.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-top:10px;min-height: 17px;");
                    tc_Applicable.Controls.Add(chk_Applicable);
                    tr.Cells.Add(tc_Applicable);
                    TableCell tc_Type = new TableCell();
                    tc_Type.Text = Convert.ToString(dr["LeaveType"]);
                    tr.Cells.Add(tc_Type);
                    TableCell tc_Total = new TableCell();
                    tc_Total.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb = new TextBox();
                    tb.ID = "total" + i;
                    tb.Attributes.Add("onkeypress", "return number_only(event,this);");
                    tb.Attributes.Add("onpaste", "return false;");
                    tb.Attributes.Add("ondrop", "return false;");
                    tb.MaxLength = 3;
                    tb.CssClass = "form-control";
                    if (Convert.ToString(dr["CountFactor"]) == "True")
                    {
                        tb.Enabled = false;
                    }
                    tc_Total.Controls.Add(tb);
                    tr.Cells.Add(tc_Total);
                    /*Below parameter is used for Angler*/
                    TableCell tc_MaxDaysPerMonth = new TableCell();
                    TextBox tb_MaxDaysPerMonth = new TextBox();
                    tc_MaxDaysPerMonth.HorizontalAlign = HorizontalAlign.Center;
                    tb_MaxDaysPerMonth.ID = "MaxDaysPerMonth" + i;
                    tb_MaxDaysPerMonth.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    //tb_max.Attributes.Add("onblur", "return chkAppDayValue(this," + i + ");");
                    tb_MaxDaysPerMonth.Attributes.Add("onpaste", "return false;");
                    tb_MaxDaysPerMonth.Attributes.Add("ondrop", "return false;");
                    tb_MaxDaysPerMonth.MaxLength = 5;
                    tb_MaxDaysPerMonth.CssClass = "form-control lve-form1";
                    tc_MaxDaysPerMonth.Controls.Add(tb_MaxDaysPerMonth);
                    tr.Cells.Add(tc_MaxDaysPerMonth);
                    TableCell tc_Max = new TableCell();
                    tc_Max.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_max = new TextBox();
                    tb_max.ID = "Max" + i;
                    tb_max.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_max.Attributes.Add("onpaste", "return false;");
                    tb_max.Attributes.Add("ondrop", "return false;");
                    tb_max.MaxLength = 5;
                    tb_max.CssClass = "form-control lve-form1";
                    tc_Max.Controls.Add(tb_max);
                    tr.Cells.Add(tc_Max);
                    TableCell tc_Min = new TableCell();
                    tc_Min.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_min = new TextBox();
                    tb_min.ID = "Min" + i;
                    tb_min.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_min.Attributes.Add("onblur", "return SpellsPerYear_fn(this," + i + ");");
                    tb_min.Attributes.Add("onpaste", "return false;");
                    tb_min.Attributes.Add("ondrop", "return false;");
                    tb_min.MaxLength = 5;
                    tb_min.CssClass = "form-control lve-form1";
                    tc_Min.Controls.Add(tb_min);
                    tr.Cells.Add(tc_Min);
                    TableCell tc_Spell = new TableCell();
                    tc_Spell.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_spell = new TextBox();
                    tb_spell.ID = "Spell" + i;
                    tb_spell.Attributes.Add("onkeypress", "return number_only(event,this);");
                    tb_spell.Attributes.Add("onpaste", "return false;");
                    tb_spell.Attributes.Add("ondrop", "return false;");
                    tb_spell.MaxLength = 2;
                    tb_spell.CssClass = "form-control lve-form1";
                    tc_Spell.Controls.Add(tb_spell);
                    tr.Cells.Add(tc_Spell);
                    TableCell tc_Loss = new TableCell();
                    RadioButtonList rbl_Loss = new RadioButtonList();
                    rbl_Loss.ID = "Loss" + i;
                    tc_Loss.Style.Add("padding-left", "20px");
                    rbl_Loss.Width = 50;
                    ListItem lst_Yes = new ListItem();
                    lst_Yes.Text = rm.GetString("ShiftSetting_Yes", ci);
                    lst_Yes.Value = "1";
                    lst_Yes.Attributes.Add("onclick", "return chkRadiobut(" + i + ",'1');");
                    ListItem lst_No = new ListItem();
                    lst_No.Selected = true;
                    lst_No.Text = rm.GetString("ShiftSetting_No", ci);
                    lst_No.Value = "0";
                    rbl_Loss.Items.Add(lst_Yes);
                    rbl_Loss.Items.Add(lst_No);
                    rbl_Loss.CssClass = "radioPolicy radioPolicy-primary";
                    rbl_Loss.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-right:0px");
                    lst_No.Attributes.Add("onclick", "return chkRadiobut(" + i + ",'0');");
                    tc_Loss.Controls.Add(rbl_Loss);
                    tr.Cells.Add(tc_Loss);
                    TableCell tc_MaxLOP = new TableCell();
                    tc_MaxLOP.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_LOP = new TextBox();
                    tb_LOP.ID = "MaxLOP" + i;
                    tb_LOP.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_LOP.Attributes.Add("onpaste", "return false;");
                    tb_LOP.Attributes.Add("ondrop", "return false;");
                    tb_LOP.MaxLength = 5;
                    tb_LOP.CssClass = "form-control lve-form1";
                    tb_LOP.Enabled = false;
                    tc_MaxLOP.Controls.Add(tb_LOP);
                    tr.Cells.Add(tc_MaxLOP);
                    TableCell tc_Count = new TableCell();
                    CheckBox chk_before = new CheckBox();
                    chk_before.ID = "chkBefore" + i;
                    chk_before.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_before.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    chk_before.Text = rm.GetString("LeavePolicy_Before", ci);
                    chk_before.Width = 100;
                    CheckBox chk_after = new CheckBox();
                    chk_after.ID = "chkAfter" + i;
                    chk_after.Text = rm.GetString("LeavePolicy_After", ci);
                    chk_after.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_after.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    chk_after.Width = 100;
                    CheckBox chk_inter = new CheckBox();
                    chk_inter.ID = "chkInter" + i;
                    chk_inter.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_inter.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    chk_inter.Text = rm.GetString("LeavePolicy_Intervening", ci);
                    chk_inter.Width = 100;
                    tc_Count.Controls.Add(chk_before);
                    tc_Count.Controls.Add(chk_after);
                    tc_Count.Controls.Add(chk_inter);
                    tr.Cells.Add(tc_Count);
                    TableCell tc_Borrow = new TableCell();
                    tc_Borrow.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox chk_Borrow = new CheckBox();
                    chk_Borrow.ID = "Borrow" + i;
                    chk_Borrow.Text = " ";
                    chk_Borrow.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                    //chk_Borrow.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                    tc_Borrow.Controls.Add(chk_Borrow);
                    tr.Cells.Add(tc_Borrow);
                    TableCell tc_Carry = new TableCell();
                    tc_Carry.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox chk_carry = new CheckBox();
                    chk_carry.ID = "Carry" + i;
                    chk_carry.Text = " ";
                    chk_carry.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                    //chk_carry.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                    tc_Carry.Controls.Add(chk_carry);
                    tr.Cells.Add(tc_Carry);
                    TableCell tc_Acc = new TableCell();
                    tc_Acc.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_Acc = new TextBox();
                    tb_Acc.ID = "Acc" + i;
                    tb_Acc.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_Acc.Attributes.Add("onpaste", "return false;");
                    tb_Acc.Attributes.Add("ondrop", "return false;");
                    tb_Acc.MaxLength = 5;
                    tb_Acc.CssClass = "form-control";
                    tc_Acc.Controls.Add(tb_Acc);
                    tr.Cells.Add(tc_Acc);
                    TableCell tc_encash = new TableCell();
                    tc_encash.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox chk_encash = new CheckBox();
                    chk_encash.ID = "Encash" + i;
                    chk_encash.Text = " ";
                    chk_encash.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                    //chk_encash.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                    tc_encash.Controls.Add(chk_encash);
                    tr.Cells.Add(tc_encash);
                    TableCell tc_AppAfter = new TableCell();
                    tc_AppAfter.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_AppAfter = new TextBox();
                    tb_AppAfter.ID = "AppAfter" + i;
                    tb_AppAfter.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_AppAfter.Attributes.Add("onpaste", "return false;");
                    tb_AppAfter.Attributes.Add("ondrop", "return false;");
                    tb_AppAfter.MaxLength = 5;
                    tb_AppAfter.CssClass = "form-control  lve-form1";
                    tc_AppAfter.Controls.Add(tb_AppAfter);
                    tr.Cells.Add(tc_AppAfter);
                    TableCell tc_CalcFactor = new TableCell();
                    tc_CalcFactor.Visible = true;
                    tc_CalcFactor.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_CalcFactor = new TextBox();
                    tb_CalcFactor.ID = "calcFactor" + i;
                    tb_CalcFactor.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_CalcFactor.Attributes.Add("onpaste", "return false;");
                    tb_CalcFactor.Attributes.Add("ondrop", "return false;");
                    tb_CalcFactor.MaxLength = 5;
                    tb_CalcFactor.CssClass = "form-control  lve-form1";
                    if (Convert.ToString(dr["CountFactor"]) == "False")
                    {
                        tb_CalcFactor.Enabled = false;
                    }
                    tc_CalcFactor.Controls.Add(tb_CalcFactor);
                    tr.Cells.Add(tc_CalcFactor);
                    TableCell tc_WorkDays = new TableCell();
                    tc_WorkDays.Visible = true;
                    tc_WorkDays.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_WorkDays = new TextBox();
                    tb_WorkDays.ID = "MinWorkedDays" + i;
                    tb_WorkDays.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_WorkDays.Attributes.Add("onpaste", "return false;");
                    tb_WorkDays.Attributes.Add("ondrop", "return false;");
                    tb_WorkDays.MaxLength = 5;
                    tb_WorkDays.CssClass = "form-control  lve-form1";
                    if (Convert.ToString(dr["CountFactor"]) == "False")
                    {
                        tb_WorkDays.Enabled = false;
                    }
                    tc_WorkDays.Controls.Add(tb_WorkDays);
                    tr.Cells.Add(tc_WorkDays);
                    TableCell tc_CountFactor = new TableCell();
                    //tc_CountFactor.HorizontalAlign = HorizontalAlign.Center;
                    tc_CountFactor.Visible = true;
                    CheckBox chk_WeekDays = new CheckBox();
                    chk_WeekDays.ID = "chkWeekDays" + i;
                    chk_WeekDays.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_WeekDays.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    chk_WeekDays.Text = rm.GetString("LeavePolicy_WkDay", ci);
                    chk_WeekDays.Width = 100;
                    CheckBox chk_WeekOff = new CheckBox();
                    chk_WeekOff.ID = "chkWeekOff" + i;
                    chk_WeekOff.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_WeekOff.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    chk_WeekOff.Text = rm.GetString("LeavePolicy_WkOff", ci);
                    chk_WeekOff.Width = 100;
                    CheckBox chk_Leave = new CheckBox();
                    chk_Leave.ID = "chkLeave" + i;
                    chk_Leave.Text = rm.GetString("LeaveApplication_Leave", ci);
                    chk_Leave.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_Leave.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    chk_Leave.Width = 100;
                    CheckBox chk_Holidays = new CheckBox();
                    chk_Holidays.ID = "chkHolidays" + i;
                    chk_Holidays.Text = rm.GetString("Menu_Masters_Holidays", ci);
                    chk_Holidays.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_Holidays.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    if (Convert.ToString(dr["CountFactor"]) == "False")
                    {
                        chk_WeekDays.Enabled = false;
                        chk_WeekOff.Enabled = false;
                        chk_Leave.Enabled = false;
                        chk_Holidays.Enabled = false;
                    }
                    else
                    {
                        chk_WeekDays.Checked = true;
                        chk_WeekDays.Enabled = false;
                    }
                    tc_CountFactor.Controls.Add(chk_WeekDays);
                    tc_CountFactor.Controls.Add(chk_WeekOff);
                    tc_CountFactor.Controls.Add(chk_Leave);
                    tc_CountFactor.Controls.Add(chk_Holidays);
                    tr.Cells.Add(tc_CountFactor);
                    TableCell tc_TypeID = new TableCell();
                    Label lbl_TypeID = new Label();
                    lbl_TypeID.ID = "Type_ID" + i;
                    lbl_TypeID.Text = Convert.ToString(dr[0]);
                    tc_TypeID.Controls.Add(lbl_TypeID);
                    tr.Cells.Add(tc_TypeID);
                    tc_TypeID.Visible = false;
                    TableCell tc_LeaveTypeCountFactor = new TableCell();
                    HiddenField hdnCountFactor = new HiddenField();
                    hdnCountFactor.ID = "hdnCountFactor" + i;
                    if (Convert.ToString(dr["CountFactor"]) == "True")
                    {
                        hdnCountFactor.Value = "True";
                    }
                    else
                    {
                        hdnCountFactor.Value = "False";
                    }
                    tc_LeaveTypeCountFactor.Controls.Add(hdnCountFactor);
                    tr.Cells.Add(tc_LeaveTypeCountFactor);
                    TableCell tc_AvailNoTimes_Service = new TableCell();
                    tc_AvailNoTimes_Service.HorizontalAlign = HorizontalAlign.Center;
                    TextBox txtAvailNoTime = new TextBox();
                    txtAvailNoTime.ID = "txtAvailNoTimes" + i;
                    txtAvailNoTime.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    txtAvailNoTime.MaxLength = 1;
                    txtAvailNoTime.CssClass = "form-control  lve-form1";
                    tc_AvailNoTimes_Service.Controls.Add(txtAvailNoTime);
                    Label lblTimes = new Label();
                    lblTimes.Text = "Time(s)";
                    tc_AvailNoTimes_Service.Controls.Add(lblTimes);
                    tr.Cells.Add(tc_AvailNoTimes_Service);
                    tbl_LeavePolicy.Rows.Add(tr);
                    hdnLeaveCount.Value = Convert.ToString(i);
                    if (Convert.ToInt32(dr["isWFH"]) == 1)
                    {
                        tc_Count.Enabled = false;
                        tc_Loss.Enabled = false;
                        tc_Borrow.Enabled = false;
                        tc_Carry.Enabled = false;
                        tc_encash.Enabled = false;
                        tc_AppAfter.Enabled = false;
                        tb_CalcFactor.Enabled = false;
                        hdnCountFactor.Value = "false";
                        chk_WeekDays.Checked = true;
                        chk_WeekDays.Enabled = false;
                        tc_AvailNoTimes_Service.Enabled = false;
                        chk_WeekDays.Enabled = true;
                        chk_WeekOff.Enabled = true;
                        chk_Leave.Enabled = true;
                        chk_Holidays.Enabled = true;
                        tc_Acc.Enabled = false;
                    }
                    i = i + 1;
                    #endregion
                }
                tbl_LeavePolicy.EnableViewState = true;
                PH_DynmCtrl.Visible = true;
                ViewState["NotModifyInCategory"] = true;
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ThereIsNoRecordInThisCategory", ci) + "');", true);
                PH_DynmCtrl.Visible = false;
                hdnLeaveCount.Value = "0";
                ViewState["NotModifyInCategory"] = false;
                hdfFilter.Value = "-1";
            }
        }
        tbl_LeavePolicy.EnableViewState = true;
    }
    #endregion

    #region UserDefinedFunctions
    //useful for maintaining viewstate in dynamic controls
    private static bool shouldCreateControl = false;
    protected override void LoadViewState(object savedState)
    {
        //useful for maintaining viewstate in dynamic controls
        if (savedState != null)
        {
            object[] state = (object[])savedState;
            base.LoadViewState(state[0]);
            shouldCreateControl = (bool)state[1];
        }
    }
    protected override object SaveViewState()
    {
        //useful for maintaining viewstate in dynamic controls
        object[] state = new object[2];
        state[0] = base.SaveViewState();
        state[1] = shouldCreateControl;
        return state;
    }

    #region BindingEmployeeCategoryandType.
    /// <summary>
    /// Bindings the employee category,type and Religion
    /// </summary>
    private void BindingEmployeeCategoryandType()
    {
        // employee category binding
        DataSet dsCategory = new DataSet();
        //dsCategory = objEmployeeEventData.SelectCategoryDetailsEmployee("");
        if (dsCategory != null)
        {
            if (dsCategory.Tables[0].Rows.Count > 0)
            {
                //ddlEmpCatagory.DataSource = dsCategory;
                //ddlEmpCatagory.DataTextField = "CategoryName";
                //ddlEmpCatagory.DataValueField = "CategoryId";
                //ddlEmpCatagory.DataBind();
            }
            dsCategory.Dispose();
        }
        // employee type binding
        DataSet dsType = new DataSet();
        dsType = objEmployeeEventData.SelectTypeDetailsEmployee("");
        if (dsType != null)
        {
            if (dsType.Tables[0].Rows.Count > 0)
            {
                //ddlEmpType.DataSource = dsType;
                //ddlEmpType.DataTextField = "TypeName";
                //ddlEmpType.DataValueField = "TypeId";
                //ddlEmpType.DataBind();
            }
            dsType.Dispose();
        }
        DataSet dsReligion = new DataSet();
        dsReligion = objEmployeeEventData.SelectReligion();
        if (dsReligion != null)
        {
            if (dsReligion.Tables[0].Rows.Count > 0)
            {
                //ddlReligion.DataSource = dsReligion;
                //ddlReligion.DataTextField = "Name";
                //ddlReligion.DataValueField = "Id";
                //ddlReligion.DataBind();
            }
            dsReligion.Dispose();
        }
    }
    #endregion

    #region "Table creation"

    private void Table_Creation()
    {
        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;
        // LoadStrings Function fills the Label from the Resource File
        LoadStrings(ci);
        //tbl_LeavePolicy.Width = Unit.Pixel(800);
        tbl_LeavePolicy.CssClass = "table table-bordered";
        TableHeaderRow hr = new TableHeaderRow();
        TableHeaderCell hc_Appplicable = new TableHeaderCell();
        hc_Appplicable.VerticalAlign = VerticalAlign.Top;
        hc_Appplicable.Width = Unit.Percentage(1);
        hc_Appplicable.CssClass = "lvepo-tblhdr";
        hc_Appplicable.VerticalAlign = VerticalAlign.Top;
        hc_Appplicable.Text = rm.GetString("LeavePolicy_Applicable", ci);
        hr.Cells.Add(hc_Appplicable);
        TableHeaderCell hc_type = new TableHeaderCell();
        hc_type.VerticalAlign = VerticalAlign.Top;
        hc_type.Width = Unit.Percentage(1);
        hc_type.CssClass = "lvepo-tblhdr";
        hc_type.Text = rm.GetString("lbl_leavetype", ci);
        hr.Cells.Add(hc_type);
        TableHeaderCell hc_days = new TableHeaderCell();
        hc_days.VerticalAlign = VerticalAlign.Top;
        hc_days.Width = Unit.Percentage(1);
        hc_days.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_days.Text = rm.GetString("LeavePolicy_AppDays", ci);
        hr.Cells.Add(hc_days);
        TableHeaderCell hc_DaysPerMonth = new TableHeaderCell();
        hc_DaysPerMonth.VerticalAlign = VerticalAlign.Top;
        hc_DaysPerMonth.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_DaysPerMonth.Width = Unit.Percentage(1);
        hc_DaysPerMonth.Text = rm.GetString("LeavePolicy_MaxDaysPerMon", ci);
        hr.Cells.Add(hc_DaysPerMonth);
        TableHeaderCell hc_max = new TableHeaderCell();
        hc_max.VerticalAlign = VerticalAlign.Top;
        hc_max.Width = Unit.Percentage(1);
        hc_max.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_max.Text = rm.GetString("LeavePolicy_MaxDaysPerSpell", ci);
        hr.Cells.Add(hc_max);
        TableHeaderCell hc_min = new TableHeaderCell();
        hc_min.VerticalAlign = VerticalAlign.Top;
        hc_min.Width = Unit.Percentage(1);
        hc_min.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_min.Text = rm.GetString("LeavePolicy_MinDaysPerSpell", ci);
        hc_min.Width = Unit.Percentage(1);
        hr.Cells.Add(hc_min);
        TableHeaderCell hc_spell = new TableHeaderCell();
        hc_spell.VerticalAlign = VerticalAlign.Top;
        hc_spell.Width = Unit.Percentage(1);
        hc_spell.CssClass = "lvepo-tblhdr";
        hc_spell.Text = rm.GetString("LeavePlicy_SpellsPeryear", ci);
        hr.Cells.Add(hc_spell);
        TableHeaderCell hc_LOP = new TableHeaderCell();
        hc_LOP.VerticalAlign = VerticalAlign.Top;
        hc_LOP.Width = Unit.Percentage(1);
        hc_LOP.CssClass = "lvepo-tblhdr";
        hc_LOP.Text = rm.GetString("lbl_LOP", ci);
        hr.Cells.Add(hc_LOP);
        TableHeaderCell hc_LOPdays = new TableHeaderCell();
        hc_LOPdays.VerticalAlign = VerticalAlign.Top;
        hc_LOPdays.Width = Unit.Percentage(1);
        hc_LOPdays.CssClass = "lvepo-tblhdr";
        hc_LOPdays.Text = rm.GetString("LeavePolicy_MaxLOP", ci);
        hr.Cells.Add(hc_LOPdays);
        TableHeaderCell hc_Count = new TableHeaderCell();
        hc_Count.VerticalAlign = VerticalAlign.Top;
        hc_Count.CssClass = "lvepo-tblhdr lve-tblwid2";
        hc_Count.HorizontalAlign = HorizontalAlign.Center;
        hc_Count.Width = Unit.Percentage(1);
        hc_Count.Text = rm.GetString("LeavePolicy_CountWeekoff", ci);
        hr.Cells.Add(hc_Count);
        TableHeaderCell hc_Borrow = new TableHeaderCell();
        hc_Borrow.VerticalAlign = VerticalAlign.Top;
        hc_Borrow.Width = Unit.Percentage(1);
        hc_Borrow.CssClass = "lvepo-tblhdr";
        hc_Borrow.Text = rm.GetString("LeavePlocy_Borrow", ci);
        hr.Cells.Add(hc_Borrow);
        TableHeaderCell hc_Carry = new TableHeaderCell();
        hc_Carry.VerticalAlign = VerticalAlign.Top;
        hc_Carry.Width = Unit.Percentage(1);
        hc_Carry.CssClass = "lvepo-tblhdr";
        hc_Carry.Text = rm.GetString("LeavePolicy_CarryOver", ci);
        hr.Cells.Add(hc_Carry);
        TableHeaderCell hc_MaxAcc = new TableHeaderCell();
        hc_MaxAcc.VerticalAlign = VerticalAlign.Top;
        hc_MaxAcc.Width = Unit.Percentage(1);
        hc_MaxAcc.CssClass = "lvepo-tblhdr";
        hc_MaxAcc.Text = rm.GetString("LeavePolicy_MaxAccDays", ci);
        hr.Cells.Add(hc_MaxAcc);
        TableHeaderCell hc_encash = new TableHeaderCell();
        hc_encash.VerticalAlign = VerticalAlign.Top;
        hc_encash.Width = Unit.Percentage(1);
        hc_encash.CssClass = "lvepo-tblhdr";
        hc_encash.Text = rm.GetString("LeavePolicy_Encash", ci);
        hr.Cells.Add(hc_encash);
        TableHeaderCell hc_AppAfter = new TableHeaderCell();
        hc_AppAfter.VerticalAlign = VerticalAlign.Top;
        hc_AppAfter.Width = Unit.Percentage(1);
        hc_AppAfter.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_AppAfter.Text = rm.GetString("LeavePolicy_ApplAfterDays", ci);
        hr.Cells.Add(hc_AppAfter);
        TableHeaderCell hc_CalcFactor = new TableHeaderCell();
        hc_CalcFactor.VerticalAlign = VerticalAlign.Top;
        hc_CalcFactor.Visible = true;
        hc_CalcFactor.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_CalcFactor.Width = Unit.Percentage(1);
        hc_CalcFactor.Text = rm.GetString("LeavePolicy_CalcFactor", ci);
        hr.Cells.Add(hc_CalcFactor);
        TableHeaderCell hc_Workdays = new TableHeaderCell();
        hc_Workdays.VerticalAlign = VerticalAlign.Top;
        hc_Workdays.Width = Unit.Percentage(1);
        hc_Workdays.CssClass = "lvepo-tblhdr lve-tblwid1";
        hc_Workdays.Text = rm.GetString("LeavePolicy_MinWorkDays", ci);
        hr.Cells.Add(hc_Workdays);
        TableHeaderCell hc_CountFactor = new TableHeaderCell();
        hc_CountFactor.VerticalAlign = VerticalAlign.Top;
        hc_Workdays.Width = Unit.Percentage(1);
        hc_CountFactor.CssClass = "lvepo-tblhdr";
        hc_CountFactor.Visible = true;
        hc_CountFactor.Width = Unit.Percentage(1);
        hc_CountFactor.Text = rm.GetString("lblCountFactor", ci);
        hr.Cells.Add(hc_CountFactor);

        TableHeaderCell Thc_AvailNoTimes = new TableHeaderCell();
        Thc_AvailNoTimes.VerticalAlign = VerticalAlign.Top;
        Thc_AvailNoTimes.Width = Unit.Percentage(1);
        Thc_AvailNoTimes.Visible = true;
        //hc_CountFactor.Width = Unit.Pixel(100);
        Thc_AvailNoTimes.CssClass = "lvepo-tblhdr";
        Thc_AvailNoTimes.Text = "Service Period - Avail";
        hr.Cells.Add(Thc_AvailNoTimes);

        tbl_LeavePolicy.Rows.Add(hr);
    }
    #endregion
    #region "Insert Leave Policy"
    // function for insert Leave Policy
    private int LeavePolicy()
    {
        int PermissionBeforeLeave, PermissionAfterLeave, OtHourWise, OtDayWise;
        string OtMinHrs, HalfDayCompOff;
        int retvalue = 0, ValidsDays = 0;
        string strPolicyName = txt_PolicyName.Text;
        //string strMaxHrs_Year = txt_MaxHrsYear.Text.Trim();
        CheckBox chkApplicable = new CheckBox();
        string strMaxHrs_Month = txt_MaxHrsMonth.Text.Trim();
        int intMaxInstances_Month;
        if (txt_MaxInstances.Text.Trim() == "")
        {
            intMaxInstances_Month = 0;
        }
        else
        {
            intMaxInstances_Month = Convert.ToInt32(txt_MaxInstances.Text.Trim());
        }
        string strMaxHrs_Ins = txt_MaxHrsInstanceHdn.Value.Trim();
        string strMinHrs_Ins = "00:30";
        if (Convert.ToString(txtMinHrs_Instance.Text) != "")
        {
            strMinHrs_Ins = Convert.ToString(txtMinHrs_Instance.Text);
        }
        if (chkBeforeLeave.Checked == true)
        {
            PermissionBeforeLeave = 1;
        }
        else
        {
            PermissionBeforeLeave = 0;
        }
        if (chkAfterLeave.Checked == true)
        {
            PermissionAfterLeave = 1;
        }
        else
        {
            PermissionAfterLeave = 0;
        }
        if (chkPermission.Checked == false)
        {
            strMaxHrs_Month = string.Empty;
            strMaxHrs_Ins = string.Empty;
            intMaxInstances_Month = 0;
            PermissionBeforeLeave = 0;
            PermissionAfterLeave = 0;
        }
        if (chkOverTimeType.Checked == false)
        {
            OtHourWise = 0;
            OtDayWise = 0;
            ValidsDays = 0;
            OtMinHrs = string.Empty;
            HalfDayCompOff = string.Empty;
        }
        else
        {
            if (hdfOTHourType.Value == "1")
            {
                OtHourWise = 1;
            }
            else
            {
                OtHourWise = 0;
            }
            if (hdfOTDayType.Value == "1")
            {
                OtDayWise = 1;
            }
            else
            {
                OtDayWise = 0;
            }
            //OtMinHrs = txtMinOtHrs.Text.Trim();
            ValidsDays = Convert.ToInt32(txtValidsDays.Text);
            OtMinHrs = Convert.ToString(txtFullDayComoff.Text).Trim();
            HalfDayCompOff = Convert.ToString(txtHalfDayComoff.Text).Trim();
        }
        //checked for already existing policy name and update
        if (objLeave.CheckPolicyName(intPolicyID, strPolicyName) == 0)
        {
            HiddenField hdnCountFactor = new HiddenField();
            int isLeaveTypeSelectedCount = 0;
            for (int j = 1; j < tbl_LeavePolicy.Rows.Count; j++)
            {
                chkApplicable = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("Applicable" + j);
                if (chkApplicable.Checked == true)
                {
                    isLeaveTypeSelectedCount = isLeaveTypeSelectedCount + 1;
                }
            }
            if (isLeaveTypeSelectedCount > 0)
            {
                TextBox tbDays = new TextBox();
                ///
                TextBox tbMaxDaysSpell = new TextBox();
                TextBox tbMinDaysSpell = new TextBox();
                TextBox tbSpellPerYear = new TextBox();
                TextBox tbLOP = new TextBox();
                TextBox tbCalcFactor = new TextBox();
                TextBox tbMinWorkedDays = new TextBox();

                // for sum of applicable days
                float sumOfAppDays = 0;
                float sumOfLOP = 0;
                float totalYrDays = 0;
                float fltCalcFactor = 0;
                float fltMinWorkedDays = 0;
                #region LeavePolicyLoad
                for (int j = 1; j < tbl_LeavePolicy.Rows.Count; j++)
                {
                    chkApplicable = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("Applicable" + j);
                    hdnCountFactor = (HiddenField)tbl_LeavePolicy.Rows[j].FindControl("hdnCountFactor" + j);
                    if (chkApplicable.Checked == true)
                    {
                        blApplicable = true;
                    }
                    else
                    {
                        blApplicable = false;
                    }
                    tbDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("total" + j);
                    float fltTotalDays;
                    if (tbDays.Text.Trim() == "")
                    {
                        fltTotalDays = 0;
                    }
                    else
                    {
                        fltTotalDays = Convert.ToSingle(tbDays.Text.Trim());
                    }
                    ///
                    tbMaxDaysSpell = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("Max" + j);
                    float fltMaxDaysSpell;
                    if (tbMaxDaysSpell.Text.Trim() == "")
                    {
                        fltMaxDaysSpell = 0;
                    }
                    else
                    {
                        fltMaxDaysSpell = Convert.ToSingle(tbMaxDaysSpell.Text.Trim());
                    }
                    ///
                    ///
                    tbMinDaysSpell = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("Min" + j);
                    float fltMinDaysSpell;
                    if (tbMinDaysSpell.Text.Trim() == "")
                    {
                        fltMinDaysSpell = 0;
                    }
                    else
                    {
                        fltMinDaysSpell = Convert.ToSingle(tbMinDaysSpell.Text.Trim());
                    }
                    ///
                    ///
                    tbSpellPerYear = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("Spell" + j);
                    float fltSpellPerYear;
                    if (tbSpellPerYear.Text.Trim() == "")
                    {
                        fltSpellPerYear = 0;
                    }
                    else
                    {
                        fltSpellPerYear = Convert.ToSingle(tbSpellPerYear.Text.Trim());
                    }
                    ///
                    tbLOP = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("MaxLOP" + j);
                    float fltLop;
                    if (tbLOP.Text.Trim() == "")
                    {
                        fltLop = 0;
                    }
                    else
                    {
                        fltLop = Convert.ToSingle(tbLOP.Text.Trim());
                    }
                    ///
                    tbCalcFactor = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("calcFactor" + j);
                    if (tbCalcFactor.Text.Trim() == "")
                    {
                        fltCalcFactor = 0;
                    }
                    else
                    {
                        fltCalcFactor = Convert.ToSingle(tbCalcFactor.Text.Trim());
                    }
                    tbMinWorkedDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("MinWorkedDays" + j);
                    if (tbMinWorkedDays.Text.Trim() == "")
                    {
                        fltMinWorkedDays = 0;
                    }
                    else
                    {
                        fltMinWorkedDays = Convert.ToSingle(tbMinWorkedDays.Text.Trim());
                    }
                    if (chkApplicable.Checked == true)
                    {
                        if (fltTotalDays == 0 || fltTotalDays == 0.0)
                        {
                            if (hdnCountFactor.Value == "False")
                            {
                                checkApplicableDaysExist = false;
                            }
                        }
                        else
                        {
                            checkApplicableDaysExist = true;
                            sumOfAppDays = sumOfAppDays + fltTotalDays;
                        }
                        if (fltLop == 0 || fltLop == 0.0)
                        {
                        }
                        else
                        {
                            sumOfLOP = sumOfLOP + fltLop;
                        }
                        ///
                        if (fltMaxDaysSpell == 0 || fltMaxDaysSpell == 0.0)
                        {
                            checkMaxDaysSpellExist = false;
                        }
                        else
                        {
                            checkMaxDaysSpellExist = true;
                        }
                        ///
                        ///
                        if (fltMinDaysSpell == 0 || fltMinDaysSpell == 0.0)
                        {
                            checkMinDaysSpellExist = false;
                        }
                        else
                        {
                            checkMinDaysSpellExist = true;
                        }
                        ///
                        ///
                        if (fltSpellPerYear == 0 || fltSpellPerYear == 0.0)
                        {
                            checkSpellPerYearExist = false;
                        }
                        else
                        {
                            checkSpellPerYearExist = true;
                        }
                        ///
                        if (fltCalcFactor == 0 || fltCalcFactor == 0.0)
                        {
                            checkCalcFactorExists = false;
                        }
                        else
                        {
                            checkCalcFactorExists = true;
                        }
                        ///
                        ///
                        if (fltMinWorkedDays == 0 || fltMinWorkedDays == 0.0)
                        {
                            checkMinWorkedDaysExists = false;
                        }
                        else
                        {
                            checkMinWorkedDaysExists = true;
                        }
                        ///
                        ///
                        if (hdnCountFactor.Value == "False")
                        {
                            if (checkApplicableDaysExist == false)
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ApplicableDaysShouldNotBeEmptyorZero", ci) + "');", true);
                                retvalue = 1;
                                return 1;
                            }
                        }
                        else if (checkMaxDaysSpellExist == false)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_MaxDaysPerSpellShouldNotBeEmptyorZero", ci) + "');", true);
                            retvalue = 1;
                            return 1;
                        }
                        else if (checkMinDaysSpellExist == false)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_MinDaysPerSpellShouldNotBeEmptyorZero", ci) + "');", true);
                            retvalue = 1;
                            return 1;
                        }
                        else if (checkSpellPerYearExist == false)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpellPerYearShouldNotBeEmptyorZero", ci) + "');", true);
                            retvalue = 1;
                            return 1;
                        }
                        if (hdnCountFactor.Value == "True")
                        {
                            if (checkCalcFactorExists == false)
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_CalculationFactorShouldNotBeEmptyorZero", ci) + "');", true);
                                retvalue = 1;
                                return 1;
                            }
                            else if (checkMinWorkedDaysExists == false)
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_MinimumWorkedDaysShouldNotBeEmptyorZero", ci) + "');", true);
                                retvalue = 1;
                                return 1;
                            }
                            if (fltMinWorkedDays > 0 && fltCalcFactor > 0)
                            {
                                if (fltCalcFactor > fltMinWorkedDays)
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_CalcfactorshouldbelesserthanMinimumworkeddays", ci) + "');", true);
                                    retvalue = 1;
                                    return 1;
                                }
                            }
                        }
                    }
                }
                #endregion
                totalYrDays = sumOfAppDays + sumOfLOP;
                if (totalYrDays > 365 && Convert.ToString(hdfValidation.Value) == "1")
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Totalleavedaysshouldnotbegreaterthan365", ci) + "');", true);
                    retvalue = 1;
                    return 1;
                }

                objLeave.UpdateLeavePolicy('U', intPolicyID, strPolicyName, strMaxHrs_Month, intMaxInstances_Month, strMaxHrs_Ins, EmployeeID, PermissionBeforeLeave, PermissionAfterLeave, OtHourWise, OtDayWise, OtMinHrs, Convert.ToInt32(Session["ddlEmployeeCategory"]), Convert.ToInt16(Session["ddlEmployeeType"]), Convert.ToString(Session["ddlGender"]), Convert.ToInt16(Session["ddlReligion"]), HalfDayCompOff, ValidsDays, Convert.ToInt32(ViewState["vs_CompanyID"]), strMinHrs_Ins);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ApplyLeaveForLeavePolicy", ci) + "');", true);
                retvalue = 1;
            }
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_PolicyNameAlreadyExists", ci) + "');", true);
            retvalue = 1;
        }
        return retvalue;
    }
    #endregion
    #region "Insert Leave policy Details"
    // function for Leave policy details
    private void LeavePolicyDetails(int LPID)
    {
        for (int j = 1; j <= tbl_LeavePolicy.Rows.Count - 1; j++)
        {
            CheckBox chkApplicable = new CheckBox();
            HiddenField hdnCountFactor = new HiddenField();
            chkApplicable = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("Applicable" + j);
            hdnCountFactor = (HiddenField)tbl_LeavePolicy.Rows[j].FindControl("hdnCountFactor" + j);
            if (chkApplicable.Checked == true)
            {
                blApplicable = true;
            }
            else
            {
                blApplicable = false;
            }
            TextBox tbDays = new TextBox();
            tbDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("total" + j);
            float fltTotalDays;
            if (tbDays.Text.Trim() == "")
            {
                fltTotalDays = 0;
            }
            else
            {
                fltTotalDays = Convert.ToSingle(tbDays.Text.Trim());
            }
            float fltMaxDaysPerMonth = 0;
            TextBox tbMaxDaysPerMonth = new TextBox();
            tbMaxDaysPerMonth = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("MaxDaysPerMonth" + j);
            if (tbMaxDaysPerMonth.Text.Trim() == "")
            {
                fltMaxDaysPerMonth = 0;
            }
            else
            {
                fltMaxDaysPerMonth = Convert.ToSingle(tbMaxDaysPerMonth.Text.Trim());
            }
            TextBox tbMaxDays = new TextBox();
            tbMaxDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("Max" + j);
            float fltMaxDays;
            if (tbMaxDays.Text.Trim() == "")
            {
                fltMaxDays = 0;
            }
            else
            {
                fltMaxDays = Convert.ToSingle(tbMaxDays.Text.Trim());
            }
            TextBox tbMinDays = new TextBox();
            tbMinDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("Min" + j);
            float fltMinDays;
            if (tbMinDays.Text.Trim() == "")
            {
                fltMinDays = 0;
            }
            else
            {
                fltMinDays = Convert.ToSingle(tbMinDays.Text.Trim());
            }
            TextBox tbSpell = new TextBox();
            tbSpell = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("Spell" + j);
            int intSpell;
            if (tbSpell.Text.Trim() == "")
            {
                intSpell = 0;
            }
            else
            {
                intSpell = Convert.ToInt32(tbSpell.Text.Trim());
            }
            TextBox tbMaxAccDays = new TextBox();
            tbMaxAccDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("Acc" + j);
            float fltMaxAccDays;
            if (tbMaxAccDays.Text.Trim() == "")
            {
                fltMaxAccDays = 0;
            }
            else
            {
                fltMaxAccDays = Convert.ToSingle(tbMaxAccDays.Text.Trim());
            }
            RadioButtonList rbtnLOP = new RadioButtonList();
            rbtnLOP = (RadioButtonList)tbl_LeavePolicy.Rows[j].FindControl("Loss" + j);
            string strLOPay = (rbtnLOP.Text);
            bool blLOP;
            if (strLOPay == "1")
                blLOP = true;
            else
                blLOP = false;
            TextBox tbLOPDays = new TextBox();
            tbLOPDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("MaxLOP" + j);
            float fltLOPDays;
            if (tbLOPDays.Text.Trim() == "")
            {
                fltLOPDays = 0;
            }
            else if (blLOP == false)
            {
                fltLOPDays = 0;
            }
            else
            {
                fltLOPDays = Convert.ToSingle(tbLOPDays.Text.Trim());
            }
            CheckBox chkBefore = new CheckBox();
            chkBefore = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("chkBefore" + j);
            bool blCountBefore;
            if (chkBefore.Checked == true)
            {
                blCountBefore = true;
            }
            else
            {
                blCountBefore = false;
            }
            CheckBox chkAfter = new CheckBox();
            chkAfter = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("chkAfter" + j);
            bool blCountAfter;
            if (chkAfter.Checked == true)
            {
                blCountAfter = true;
            }
            else
            {
                blCountAfter = false;
            }
            CheckBox chkInter = new CheckBox();
            chkInter = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("chkInter" + j);
            bool blCountInter;
            if (chkInter.Checked == true)
            {
                blCountInter = true;
            }
            else
            {
                blCountInter = false;
            }
            CheckBox chkBorrow = new CheckBox();
            chkBorrow = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("Borrow" + j);
            bool blBorrow;
            if (chkBorrow.Checked == true)
            {
                blBorrow = true;
            }
            else
            {
                blBorrow = false;
            }
            CheckBox chkCarry = new CheckBox();
            chkCarry = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("Carry" + j);
            bool blCarry;
            if (chkCarry.Checked == true)
            {
                blCarry = true;
            }
            else
            {
                blCarry = false;
            }
            CheckBox chkEncash = new CheckBox();
            chkEncash = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("Encash" + j);
            bool blEncash;
            if (chkEncash.Checked == true)
            {
                blEncash = true;
            }
            else
            {
                blEncash = false;
            }
            TextBox tbAppAfter = new TextBox();
            tbAppAfter = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("AppAfter" + j);
            float fltAppAfter;
            if (tbAppAfter.Text.Trim() == "")
            {
                fltAppAfter = 0;
            }
            else
            {
                fltAppAfter = Convert.ToSingle(tbAppAfter.Text.Trim());
            }
            TextBox tbCalcFactor = new TextBox();
            tbCalcFactor = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("calcFactor" + j);
            float fltCalcFactor;
            if (tbCalcFactor.Text.Trim() == "")
            {
                fltCalcFactor = 0;
            }
            else
            {
                fltCalcFactor = Convert.ToSingle(tbCalcFactor.Text.Trim());
            }
            TextBox tbMinWorkedDays = new TextBox();
            tbMinWorkedDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("MinWorkedDays" + j);
            float fltMinWorkDays;
            if (tbMinWorkedDays.Text.Trim() == "")
            {
                fltMinWorkDays = 0;
            }
            else
            {
                fltMinWorkDays = Convert.ToSingle(tbMinWorkedDays.Text.Trim());
            }
            CheckBox chkWeekDays = new CheckBox();
            chkWeekDays = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("chkWeekDays" + j);
            bool blWeekdays;
            if (chkWeekDays.Checked == true)
            {
                blWeekdays = true;
            }
            else
            {
                blWeekdays = false;
            }
            CheckBox chkWeekOff = new CheckBox();
            chkWeekOff = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("chkWeekOff" + j);
            bool blWeekoff;
            if (chkWeekOff.Checked == true)
            {
                blWeekoff = true;
            }
            else
            {
                blWeekoff = false;
            }
            CheckBox chkLeave = new CheckBox();
            chkLeave = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("chkLeave" + j);
            bool blLeave;
            if (chkLeave.Checked == true)
            {
                blLeave = true;
            }
            else
            {
                blLeave = false;
            }
            CheckBox chkHolidays = new CheckBox();
            chkHolidays = (CheckBox)tbl_LeavePolicy.Rows[j].FindControl("chkHolidays" + j);
            bool blHolidays;
            if (chkHolidays.Checked == true)
            {
                blHolidays = true;
            }
            else
            {
                blHolidays = false;
            }
            Label lblTypeID = new Label();
            lblTypeID = (Label)tbl_LeavePolicy.Rows[j].FindControl("Type_ID" + j);
            int intLeaveTypeID = Convert.ToInt32(lblTypeID.Text);
            int intAvailServicePeriod = 0;
            TextBox tbAvailServicePeriod = new TextBox();
            tbAvailServicePeriod = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("txtAvailNoTimes" + j);
            if (tbAvailServicePeriod.Text.Trim() == "")
                intAvailServicePeriod = 0;
            else
                intAvailServicePeriod = Convert.ToInt16(tbAvailServicePeriod.Text.Trim());
            //check for applicable checkbox checked and insert leave policy details
            if (blApplicable == true)
            {
                objLeave.InsertLeavePolicyDetails(LPID, intLeaveTypeID, fltTotalDays, fltMaxDaysPerMonth, fltMaxDays, fltMinDays, intSpell, fltMaxAccDays, blLOP, fltLOPDays, blCountBefore, blCountAfter, blCountInter, blBorrow, blCarry, blEncash, fltCalcFactor, fltMinWorkDays, blWeekdays, blWeekoff, blLeave, blHolidays, fltAppAfter, EmployeeID, intAvailServicePeriod);
            }
        }
    }
    #endregion
    /// <summary>
    /// Loading LeavePolicy Details
    /// </summary>
    private void BindPolicyDetails()
    {
        if (ds_LeavePolicy.Tables.Count > 0)
        {
            if (ds_LeavePolicy != null && ds_LeavePolicy.Tables[0].Rows.Count > 0)
            {
                #region "Policy"
                // filling policy
                if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["CompanyName"]) != null)
                {
                    lblSelectedCompany.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["CompanyName"]);
                }
                int CompanyID = 0;
                if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["CompanyID"]) != "")
                {
                    CompanyID = Convert.ToInt32(ds_LeavePolicy.Tables[0].Rows[0]["CompanyID"]);
                    ViewState["vs_CompanyID"] = CompanyID;
                }
                txt_PolicyName.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["PolicyName"]);
                ddlEmpCategory = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["EmployeeCategory"]);
                if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["EmployeeCategorys"]) != string.Empty && ds_LeavePolicy.Tables[0].Rows[0]["EmployeeCategorys"] != null)
                {
                    lblSelectedCategory.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["EmployeeCategorys"]);
                }
                else
                {
                    lblSelectedCategory.Text = "All";
                }
                ddlEmpType = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["EmployeeType"]);
                if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["EmployeeTypes"]) != string.Empty && ds_LeavePolicy.Tables[0].Rows[0]["EmployeeTypes"] != null)
                {
                    lblSelectedType.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["EmployeeTypes"]);
                }
                else
                {
                    lblSelectedType.Text = "All";
                }
                lblSelectedGender.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Gender"]);
                ddlReligion = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Religion"]);
                if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Religions"]) != string.Empty && ds_LeavePolicy.Tables[0].Rows[0]["Religions"] != null)
                {
                    lblSelectedReligion.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Religions"]);
                }
                else
                {
                    lblSelectedReligion.Text = "All";
                }
                txt_MaxHrsMonth.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Permission_MaxHrs_Month"]);
                if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Permission_MaxInstances_Month"]) == "0")
                {
                    txt_MaxInstances.Text = "";
                }
                else
                {
                    txt_MaxInstances.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Permission_MaxInstances_Month"]);
                }
                txt_MaxHrsInstance.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Permission_MaxHrs_Instance"]);
                txtMinHrs_Instance.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Permission_MinHrs_Instance"]);
                txt_MaxHrsInstanceHdn.Value = txt_MaxHrsInstance.Text;
                // Ot Details and Permission After and Before Leave            
                if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["Permission_MaxHrs_Month"]) != string.Empty)
                {
                    chkPermission.Checked = true;
                    chkBeforeLeave.Enabled = false;
                    chkAfterLeave.Enabled = false;
                    txt_MaxHrsMonth.Enabled = true;
                    txt_MaxInstances.Enabled = true;
                    if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["PermissionAfterLeave"]) == "True")
                    {
                        chkAfterLeave.Checked = true;
                    }
                    else
                    {
                        chkAfterLeave.Checked = false;
                    }
                    if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["PermissionBeforeLeave"]) == "True")
                    {
                        chkBeforeLeave.Checked = true;
                    }
                    else
                    {
                        chkBeforeLeave.Checked = false;
                    }
                }
                else
                {
                    chkPermission.Checked = false;
                    chkBeforeLeave.Enabled = true;
                    chkAfterLeave.Enabled = true;
                    txt_MaxHrsMonth.Enabled = false;
                    txt_MaxInstances.Enabled = false;
                }
                if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["OtMinHrs"]) != string.Empty)
                {
                    chkOverTimeType.Checked = true;
                    rbt_HourWise.Enabled = false;
                    rbt_DayWise.Enabled = false;
                    txtHalfDayComoff.Enabled = true;
                    txtFullDayComoff.Enabled = true;
                    txtValidsDays.Enabled = true;
                    txtHalfDayComoff.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["OtMinHrs"]);
                    txtFullDayComoff.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["FullDayOTMinHrs"]);
                    txtValidsDays.Text = Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["CompOffValidDays"]);
                    if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["OtHourWise"]) == "True")
                    {
                        rbt_HourWise.Checked = true;
                    }
                    else
                    {
                        rbt_HourWise.Checked = false;
                    }
                    if (Convert.ToString(ds_LeavePolicy.Tables[0].Rows[0]["OtDayWise"]) == "True")
                    {
                        rbt_DayWise.Checked = true;
                    }
                    else
                    {
                        rbt_DayWise.Checked = false;
                    }
                }
                else
                {
                    chkOverTimeType.Checked = false;
                    rbt_HourWise.Enabled = true;
                    rbt_DayWise.Enabled = true;
                }
                #endregion
                #region "Policy Details"
                int i = 1;
                #region "Existing Leave types"
                ds_LeaveType = objLeave.SelectLeavePolicyDetails("", Convert.ToString(ddlEmpCategory), Convert.ToString(ddlEmpType), Convert.ToString(lblSelectedGender.Text), Convert.ToString(ddlReligion));
                Session["LeaveType"] = ds_LeaveType;
                foreach (DataRow dr1 in ds_LeaveType.Tables[0].Rows)
                {
                    TableRow tr = new TableRow();
                    TableCell tc_Applicable = new TableCell();
                    tc_Applicable.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox chk_Applicable = new CheckBox();
                    chk_Applicable.ID = "Applicable" + i;
                    chk_Applicable.Text = " ";
                    chk_Applicable.CssClass = "checkboxLeave checkboxLeave-primary";
                    chk_Applicable.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-top:10px;min-height: 17px;");
                    tr.CssClass = "lve-text lve-potablebg";
                    chk_Applicable.EnableViewState = true;
                    tc_Applicable.Controls.Add(chk_Applicable);
                    tr.Cells.Add(tc_Applicable);
                    TableCell tc_Type = new TableCell();
                    tc_Type.Text = Convert.ToString(dr1["LeaveType"]);
                    tr.Cells.Add(tc_Type);
                    TableCell tc_Total = new TableCell();
                    tc_Total.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb = new TextBox();
                    tb.ID = "total" + i;
                    tb.Attributes.Add("onkeypress", "return number_only(event,this);");
                    tb.Attributes.Add("onpaste", "return false;");
                    tb.Attributes.Add("ondrop", "return false;");
                    tb.MaxLength = 3;
                    tb.CssClass = "form-control lve-form1";
                    if (Convert.ToString(dr1["CountFactor"]) == "True")
                    {
                        tb.Enabled = false;
                    }
                    tb.EnableViewState = true;
                    tc_Total.Controls.Add(tb);
                    tr.Cells.Add(tc_Total);
                    TableCell tc_MaxDaysPerMonth = new TableCell();
                    TextBox tb_MaxDaysPerMonth = new TextBox();
                    tc_MaxDaysPerMonth.HorizontalAlign = HorizontalAlign.Center;
                    tb_MaxDaysPerMonth.ID = "MaxDaysPerMonth" + i;
                    tb_MaxDaysPerMonth.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    //tb_max.Attributes.Add("onblur", "return chkAppDayValue(this," + i + ");");
                    tb_MaxDaysPerMonth.Attributes.Add("onpaste", "return false;");
                    tb_MaxDaysPerMonth.Attributes.Add("ondrop", "return false;");
                    tb_MaxDaysPerMonth.MaxLength = 5;
                    tb_MaxDaysPerMonth.CssClass = "form-control lve-form1";
                    tc_MaxDaysPerMonth.Controls.Add(tb_MaxDaysPerMonth);
                    tr.Cells.Add(tc_MaxDaysPerMonth);
                    TableCell tc_Max = new TableCell();
                    tc_Max.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_max = new TextBox();
                    tb_max.ID = "Max" + i;
                    tb_max.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_max.Attributes.Add("onpaste", "return false;");
                    tb_max.Attributes.Add("ondrop", "return false;");
                    tb_max.MaxLength = 5;
                    tb_max.CssClass = "form-control lve-form1";
                    tc_Max.Controls.Add(tb_max);
                    tr.Cells.Add(tc_Max);
                    TableCell tc_Min = new TableCell();
                    tc_Min.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_min = new TextBox();
                    tb_min.ID = "Min" + i;
                    tb_min.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_min.Attributes.Add("onblur", "return SpellsPerYear_fn(this," + i + ");");
                    tb_min.Attributes.Add("onpaste", "return false;");
                    tb_min.Attributes.Add("ondrop", "return false;");
                    tb_min.MaxLength = 5;
                    tb_min.CssClass = "form-control lve-form1";
                    tc_Min.Controls.Add(tb_min);
                    tr.Cells.Add(tc_Min);
                    TableCell tc_Spell = new TableCell();
                    tc_Spell.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_spell = new TextBox();
                    tb_spell.ID = "Spell" + i;
                    tb_spell.Attributes.Add("onkeypress", "return number_only(event,this);");
                    tb_spell.Attributes.Add("onpaste", "return false;");
                    tb_spell.Attributes.Add("ondrop", "return false;");
                    tb_spell.MaxLength = 2;
                    tb_spell.CssClass = "form-control lve-form1";
                    tc_Spell.Controls.Add(tb_spell);
                    tr.Cells.Add(tc_Spell);
                    TableCell tc_Loss = new TableCell();
                    tc_Loss.HorizontalAlign = HorizontalAlign.Center;
                    RadioButtonList rbl_Loss = new RadioButtonList();
                    rbl_Loss.ID = "Loss" + i;
                    tc_Loss.Style.Add("padding-left", "20px");
                    //rbl_Loss.Width = 62;
                    ListItem lst_Yes = new ListItem();
                    lst_Yes.Text = rm.GetString("ShiftSetting_Yes", ci);
                    lst_Yes.Value = "1";
                    lst_Yes.Attributes.Add("onclick", "return chkRadiobut(" + i + ",'1');");
                    ListItem lst_No = new ListItem();
                    lst_No.Text = rm.GetString("ShiftSetting_No", ci);
                    lst_No.Value = "0";
                    lst_No.Attributes.Add("onclick", "return chkRadiobut(" + i + ",'0');");
                    rbl_Loss.Items.Add(lst_Yes);
                    rbl_Loss.Items.Add(lst_No);
                    rbl_Loss.CssClass = "radioPolicy radioPolicy-primary";
                    rbl_Loss.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-right:0px");
                    rbl_Loss.EnableViewState = true;
                    lst_No.Selected = true;
                    tc_Loss.Controls.Add(rbl_Loss);
                    tr.Cells.Add(tc_Loss);
                    TableCell tc_MaxLOP = new TableCell();
                    tc_MaxLOP.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_LOP = new TextBox();
                    tb_LOP.ID = "MaxLOP" + i;
                    tb_LOP.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_LOP.Attributes.Add("onpaste", "return false;");
                    tb_LOP.Attributes.Add("ondrop", "return false;");
                    tb_LOP.MaxLength = 5;
                    tb_LOP.CssClass = "form-control lve-form1";
                    tb_LOP.EnableViewState = true;
                    tb_LOP.Enabled = false;
                    tc_MaxLOP.Controls.Add(tb_LOP);
                    tr.Cells.Add(tc_MaxLOP);
                    TableCell tc_Count = new TableCell();
                    CheckBox chk_before = new CheckBox();
                    chk_before.ID = "chkBefore" + i;
                    chk_before.Text = rm.GetString("LeavePolicy_Before", ci);
                    chk_before.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_before.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    //chk_before.Width = 100;
                    chk_before.EnableViewState = true;
                    CheckBox chk_after = new CheckBox();
                    chk_after.ID = "chkAfter" + i;
                    chk_after.Text = rm.GetString("LeavePolicy_After", ci);
                    chk_after.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_after.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    //chk_after.Width = 100;
                    chk_after.EnableViewState = true;
                    CheckBox chk_inter = new CheckBox();
                    chk_inter.ID = "chkInter" + i;
                    chk_inter.Text = rm.GetString("LeavePolicy_Intervening", ci);
                    //chk_inter.Width = 100;
                    chk_inter.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_inter.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    chk_inter.EnableViewState = true;
                    tc_Count.Controls.Add(chk_before);
                    tc_Count.Controls.Add(chk_after);
                    tc_Count.Controls.Add(chk_inter);
                    tr.Cells.Add(tc_Count);
                    TableCell tc_Borrow = new TableCell();
                    tc_Borrow.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox chk_Borrow = new CheckBox();
                    chk_Borrow.ID = "Borrow" + i;
                    chk_Borrow.Text = " ";
                    chk_Borrow.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                    //chk_Borrow.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                    chk_Borrow.EnableViewState = true;
                    tc_Borrow.Controls.Add(chk_Borrow);
                    tr.Cells.Add(tc_Borrow);
                    TableCell tc_Carry = new TableCell();
                    tc_Carry.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox chk_carry = new CheckBox();
                    chk_carry.ID = "Carry" + i;
                    chk_carry.Text = " ";
                    chk_carry.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                    //chk_carry.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                    chk_carry.EnableViewState = true;
                    tc_Carry.Controls.Add(chk_carry);
                    tr.Cells.Add(tc_Carry);
                    TableCell tc_Acc = new TableCell();
                    tc_Acc.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_Acc = new TextBox();
                    tb_Acc.ID = "Acc" + i;
                    tb_Acc.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_Acc.Attributes.Add("onpaste", "return false;");
                    tb_Acc.Attributes.Add("ondrop", "return false;");
                    tb_Acc.MaxLength = 5;
                    tb_Acc.CssClass = "form-control  lve-form1";
                    tc_Acc.Controls.Add(tb_Acc);
                    tr.Cells.Add(tc_Acc);
                    TableCell tc_Encash = new TableCell();
                    tc_Encash.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox chk_Encash = new CheckBox();
                    chk_Encash.ID = "Encash" + i;
                    chk_Encash.Text = " ";
                    chk_Encash.CssClass = "checkboxLeave checkboxLeave-primary LeavePolicyCheckbox";
                    //chk_Encash.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-left:10px;min-height: 17px;");
                    chk_Encash.EnableViewState = true;
                    tc_Encash.Controls.Add(chk_Encash);
                    tr.Cells.Add(tc_Encash);
                    TableCell tc_ApplAfter = new TableCell();
                    tc_ApplAfter.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_ApplAfter = new TextBox();
                    tb_ApplAfter.ID = "AppAfter" + i;
                    tb_ApplAfter.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_ApplAfter.Attributes.Add("onpaste", "return false;");
                    tb_ApplAfter.Attributes.Add("ondrop", "return false;");
                    tb_ApplAfter.MaxLength = 5;
                    tb_ApplAfter.CssClass = "form-control lve-form1";
                    tb_ApplAfter.EnableViewState = true;
                    tc_ApplAfter.Controls.Add(tb_ApplAfter);
                    tr.Cells.Add(tc_ApplAfter);
                    TableCell tc_CalcFactor = new TableCell();
                    tc_CalcFactor.Visible = true;
                    tc_CalcFactor.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_CalcFactor = new TextBox();
                    tb_CalcFactor.ID = "calcFactor" + i;
                    tb_CalcFactor.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_CalcFactor.Attributes.Add("onpaste", "return false;");
                    tb_CalcFactor.Attributes.Add("ondrop", "return false;");
                    tb_CalcFactor.MaxLength = 5;
                    tb_CalcFactor.CssClass = "form-control  lve-form1";
                    if (Convert.ToString(dr1["CountFactor"]) == "False")
                    {
                        tb_CalcFactor.Enabled = false;
                    }
                    tb_CalcFactor.EnableViewState = true;
                    tc_CalcFactor.Controls.Add(tb_CalcFactor);
                    tr.Cells.Add(tc_CalcFactor);
                    TableCell tc_WorkDays = new TableCell();
                    tc_WorkDays.Visible = true;
                    tc_WorkDays.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_WorkDays = new TextBox();
                    tb_WorkDays.ID = "MinWorkedDays" + i;
                    tb_WorkDays.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    tb_WorkDays.Attributes.Add("onpaste", "return false;");
                    tb_WorkDays.Attributes.Add("ondrop", "return false;");
                    tb_WorkDays.MaxLength = 5;
                    tb_WorkDays.CssClass = "form-control  lve-form1";
                    if (Convert.ToString(dr1["CountFactor"]) == "False")
                    {
                        tb_WorkDays.Enabled = false;
                    }
                    tc_WorkDays.Controls.Add(tb_WorkDays);
                    tr.Cells.Add(tc_WorkDays);
                    TableCell tc_CountFactor = new TableCell();
                    //tc_CountFactor.HorizontalAlign = HorizontalAlign.Center;
                    tc_CountFactor.Visible = true;
                    tc_CountFactor.Width = Unit.Pixel(1);
                    CheckBox chk_WeekDays = new CheckBox();
                    chk_WeekDays.ID = "chkWeekDays" + i;
                    chk_WeekDays.Text = rm.GetString("LeavePolicy_WkDay", ci);
                    chk_WeekDays.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_WeekDays.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    CheckBox chk_WeekOff = new CheckBox();
                    chk_WeekOff.ID = "chkWeekOff" + i;
                    chk_WeekOff.Text = rm.GetString("LeavePolicy_WkOff", ci);
                    chk_WeekOff.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_WeekOff.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    CheckBox chk_Leave = new CheckBox();
                    chk_Leave.ID = "chkLeave" + i;
                    chk_Leave.Text = rm.GetString("LeaveApplication_Leave", ci);
                    chk_Leave.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_Leave.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    CheckBox chk_Holidays = new CheckBox();
                    chk_Holidays.ID = "chkHolidays" + i;
                    chk_Holidays.Text = rm.GetString("Menu_Masters_Holidays", ci);
                    chk_Holidays.CssClass = "checkbox checkbox-primary holiday-chkbox";
                    chk_Holidays.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;min-height:17px");
                    if (Convert.ToString(dr1["CountFactor"]) == "False")
                    {
                        chk_WeekDays.Enabled = false;
                        chk_WeekOff.Enabled = false;
                        chk_Leave.Enabled = false;
                        chk_Holidays.Enabled = false;
                    }
                    else
                    {
                        chk_WeekDays.Checked = true;
                        chk_WeekDays.Enabled = false;
                    }
                    tc_CountFactor.Controls.Add(chk_WeekDays);
                    tc_CountFactor.Controls.Add(chk_WeekOff);
                    tc_CountFactor.Controls.Add(chk_Leave);
                    tc_CountFactor.Controls.Add(chk_Holidays);
                    tr.Cells.Add(tc_CountFactor);
                    TableCell tc_TypeID = new TableCell();
                    Label lbl_TypeID = new Label();
                    lbl_TypeID.ID = "Type_ID" + i;
                    lbl_TypeID.Text = Convert.ToString(dr1["LeaveType_Id"]);
                    tc_TypeID.Controls.Add(lbl_TypeID);
                    tr.Cells.Add(tc_TypeID);
                    tc_TypeID.Visible = false;
                    TableCell tc_LeaveTypeCountFactor = new TableCell();
                    HiddenField hdnCountFactor = new HiddenField();
                    hdnCountFactor.ID = "hdnCountFactor" + i;
                    if (Convert.ToString(dr1["CountFactor"]) == "True")
                    {
                        hdnCountFactor.Value = "True";
                    }
                    else
                    {
                        hdnCountFactor.Value = "False";
                    }
                    tc_LeaveTypeCountFactor.Controls.Add(hdnCountFactor);
                    tc_LeaveTypeCountFactor.Style.Add("display", "none");
                    tr.Cells.Add(tc_LeaveTypeCountFactor);

                    TableCell tc_AvailNoTimes_Service = new TableCell();
                    tc_AvailNoTimes_Service.HorizontalAlign = HorizontalAlign.Center;
                    TextBox txtAvailNoTime = new TextBox();
                    txtAvailNoTime.ID = "txtAvailNoTimes" + i;
                    txtAvailNoTime.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    txtAvailNoTime.MaxLength = 1;
                    txtAvailNoTime.CssClass = "form-control  lve-form1";
                    tc_AvailNoTimes_Service.Controls.Add(txtAvailNoTime);
                    Label lblTimes = new Label();
                    lblTimes.Text = "Time(s)";
                    tc_AvailNoTimes_Service.Controls.Add(lblTimes);
                    tr.Cells.Add(tc_AvailNoTimes_Service);

                    if (Convert.ToInt32(dr1["isWFH"]) == 1)
                    {
                        tc_Count.Enabled = false;
                        tc_Loss.Enabled = false;
                        tc_Borrow.Enabled = false;
                        tc_Carry.Enabled = false;
                        tc_Encash.Enabled = false;
                        tc_ApplAfter.Enabled = false;
                        tb_CalcFactor.Enabled = false;
                        hdnCountFactor.Value = "false";
                        chk_WeekDays.Checked = true;
                        chk_WeekDays.Enabled = false;
                        tc_AvailNoTimes_Service.Enabled = false;
                        chk_WeekDays.Enabled = true;
                        chk_WeekOff.Enabled = true;
                        chk_Leave.Enabled = true;
                        chk_Holidays.Enabled = true;
                        tc_Acc.Enabled = false;
                    }

                    tbl_LeavePolicy.Rows.Add(tr);
                    hdnLeaveCount.Value = Convert.ToString(i);
                    i = i + 1;
                    //setting the values for controls
                    Session["LeavePolicyDetails"] = ds_leavePolicyDetails;
                    foreach (DataRow dr in ds_leavePolicyDetails.Tables[0].Rows)
                    {
                        if (lbl_TypeID.Text == Convert.ToString(dr["LeaveType_Id"]))
                        {
                            chk_Applicable.Checked = true;
                            tb.Text = Convert.ToString(dr["MaxDays_applicable"]);
                            tb_MaxDaysPerMonth.Text = Convert.ToString(dr["MaxDays_Month"]);
                            tb_max.Text = Convert.ToString(dr["MaxDays_avail"]);
                            tb_min.Text = Convert.ToString(dr["MinDays_avail"]);
                            tb_spell.Text = Convert.ToString(dr["Spells"]);
                            if (Convert.ToString(dr["AvailServicePeriod"]) != "")
                            {
                                txtAvailNoTime.Text = Convert.ToString(dr["AvailServicePeriod"]);
                            }
                            else
                            {
                                txtAvailNoTime.Text = "0";
                            }
                            if (Convert.ToString(dr["MaxDays_Acc"]) == "0.0" || Convert.ToString(dr["MaxDays_Acc"]) == "")
                            {
                                // nothing
                            }
                            else
                            {
                                tb_Acc.Text = Convert.ToString(dr["MaxDays_Acc"]);
                            }
                            if (Convert.ToString(dr["LossOfPay"]) == "True")
                            {
                                lst_Yes.Selected = true;
                                lst_No.Selected = false;
                                tb_LOP.Enabled = true;
                            }
                            else
                            {
                            }
                            tb_LOP.Text = Convert.ToString(dr["Max_LOP_Days"]);
                            if (Convert.ToString(dr["Count_BeforeWeeklyOff"]) == "True")
                            {
                                chk_before.Checked = true;
                            }
                            else
                            {
                                chk_before.Checked = false;
                            }
                            if (Convert.ToString(dr["Count_AfterWeeklyOff"]) == "True")
                            {
                                chk_after.Checked = true;
                            }
                            else
                            {
                                chk_after.Checked = false;
                            }
                            if (Convert.ToString(dr["Count_Intervening"]) == "True")
                            {
                                chk_inter.Checked = true;
                            }
                            else
                            {
                                chk_inter.Checked = false;
                            }
                            if (Convert.ToString(dr["Borrow_FromNextYear"]) == "True")
                            {
                                chk_Borrow.Checked = true;
                            }
                            else
                            {
                                chk_Borrow.Checked = false;
                            }
                            if (Convert.ToString(dr["Carry_ToNextYear"]) == "True")
                            {
                                chk_carry.Checked = true;
                            }
                            else
                            {
                                chk_carry.Checked = false;
                            }
                            if (Convert.ToString(dr["Encashment"]) == "True")
                            {
                                chk_Encash.Checked = true;
                            }
                            else
                            {
                                chk_Encash.Checked = false;
                            }
                            if (Convert.ToString(dr["ApplicableAfterDays"]) == "0.0" || Convert.ToString(dr["ApplicableAfterDays"]) == "")
                            {
                                // nothing
                            }
                            else
                            {
                                tb_ApplAfter.Text = Convert.ToString(dr["ApplicableAfterDays"]);
                            }
                            tb_CalcFactor.Text = Convert.ToString(dr["Calc_Factor"]);
                            tb_WorkDays.Text = Convert.ToString(dr["MinWorkDays"]);
                            if (Convert.ToString(dr["WeekDays"]) == "True")
                            {
                                chk_WeekDays.Checked = true;
                            }
                            else
                            {
                                chk_WeekDays.Checked = false;
                            }
                            if (Convert.ToString(dr["WeekOff"]) == "True")
                            {
                                chk_WeekOff.Checked = true;
                            }
                            else
                            {
                                chk_WeekOff.Checked = false;
                            }
                            if (Convert.ToString(dr["Leave"]) == "True")
                            {
                                chk_Leave.Checked = true;
                            }
                            else
                            {
                                chk_Leave.Checked = false;
                            }
                            if (Convert.ToString(dr["Holidays"]) == "True")
                            {
                                chk_Holidays.Checked = true;
                            }
                            else
                            {
                                chk_Holidays.Checked = false;
                            }
                        }
                    }
                }
                #endregion
                #region "New Leave types"
                //extra Leave type
                if (ds_LeaveType.Tables[0].Rows.Count > i - 1)
                {
                    for (int k = i - 1; k < ds_LeaveType.Tables[0].Rows.Count; k++)
                    {
                        TableRow tr = new TableRow();
                        TableCell tc_Applicable = new TableCell();
                        tc_Applicable.HorizontalAlign = HorizontalAlign.Center;
                        CheckBox chk_Applicable = new CheckBox();
                        chk_Applicable.ID = "Applicable" + (k + 1);
                        chk_Applicable.EnableViewState = true;
                        tc_Applicable.Controls.Add(chk_Applicable);
                        tr.Cells.Add(tc_Applicable);
                        TableCell tc_Type = new TableCell();
                        tc_Type.Text = Convert.ToString(ds_LeaveType.Tables[0].Rows[k]["LeaveType"]);
                        tr.Cells.Add(tc_Type);
                        TableCell tc_Total = new TableCell();
                        tc_Total.HorizontalAlign = HorizontalAlign.Center;
                        TextBox tb = new TextBox();
                        tb.ID = "total" + (k + 1);
                        tb.Attributes.Add("onkeypress", "return number_dot(event,this);");
                        tb.Attributes.Add("onpaste", "return false;");
                        tb.Attributes.Add("ondrop", "return false;");
                        tb.MaxLength = 3;
                        tb.CssClass = "form-control";
                        if (Convert.ToString(ds_LeaveType.Tables[0].Rows[k]["CountFactor"]) == "True")
                        {
                            tb.Enabled = false;
                        }
                        tc_Total.Controls.Add(tb);
                        tr.Cells.Add(tc_Total);
                        TableCell tc_Max = new TableCell();
                        tc_Max.HorizontalAlign = HorizontalAlign.Center;
                        TextBox tb_max = new TextBox();
                        tb_max.ID = "Max" + (k + 1);
                        tb_max.Attributes.Add("onkeypress", "return number_dot(event,this);");
                        tb_max.Attributes.Add("onpaste", "return false;");
                        tb_max.Attributes.Add("ondrop", "return false;");
                        tb_max.MaxLength = 5;
                        tb_max.CssClass = "form-control";
                        tc_Max.Controls.Add(tb_max);
                        tr.Cells.Add(tc_Max);
                        TableCell tc_Min = new TableCell();
                        tc_Min.HorizontalAlign = HorizontalAlign.Center;
                        TextBox tb_min = new TextBox();
                        tb_min.ID = "Min" + (k + 1);
                        tb_min.Attributes.Add("onkeypress", "return number_dot(event,this);");
                        tb_min.Attributes.Add("onblur", "return SpellsPerYear_fn(this," + i + ");");
                        tb_min.Attributes.Add("onpaste", "return false;");
                        tb_min.Attributes.Add("ondrop", "return false;");
                        tb_min.MaxLength = 5;
                        tb_min.CssClass = "form-control";
                        tc_Min.Controls.Add(tb_min);
                        tr.Cells.Add(tc_Min);
                        TableCell tc_Spell = new TableCell();
                        tc_Spell.HorizontalAlign = HorizontalAlign.Center;
                        TextBox tb_spell = new TextBox();
                        tb_spell.ID = "Spell" + (k + 1);
                        tb_spell.Attributes.Add("onkeypress", "return number_only(event,this);");
                        tb_spell.Attributes.Add("onpaste", "return false;");
                        tb_spell.Attributes.Add("ondrop", "return false;");
                        tb_spell.MaxLength = 2;
                        tb_spell.CssClass = "form-control";
                        tc_Spell.Controls.Add(tb_spell);
                        tr.Cells.Add(tc_Spell);
                        TableCell tc_Loss = new TableCell();
                        tc_Loss.HorizontalAlign = HorizontalAlign.Center;
                        RadioButtonList rbl_Loss = new RadioButtonList();
                        rbl_Loss.ID = "Loss" + (k + 1);
                        ListItem lst_Yes = new ListItem();
                        lst_Yes.Text = rm.GetString("ShiftSetting_Yes", ci);
                        lst_Yes.Value = "1";
                        lst_Yes.Attributes.Add("onclick", "return chkRadiobut(" + (k + 1) + ",'1');");
                        ListItem lst_No = new ListItem();
                        lst_No.Selected = true;
                        lst_Yes.Selected = false;
                        lst_No.Text = rm.GetString("ShiftSetting_No", ci);
                        lst_No.Value = "0";
                        lst_No.Attributes.Add("onclick", "return chkRadiobut(" + (k + 1) + ",'0');");
                        rbl_Loss.Items.Add(lst_Yes);
                        rbl_Loss.Items.Add(lst_No);
                        rbl_Loss.CssClass = "td";
                        tc_Loss.Controls.Add(rbl_Loss);
                        tr.Cells.Add(tc_Loss);
                        TableCell tc_MaxLOP = new TableCell();
                        tc_MaxLOP.HorizontalAlign = HorizontalAlign.Center;
                        TextBox tb_LOP = new TextBox();
                        tb_LOP.ID = "MaxLOP" + (k + 1);
                        tb_LOP.Attributes.Add("onkeypress", "return number_dot(event,this);");
                        tb_LOP.Attributes.Add("onpaste", "return false;");
                        tb_LOP.Attributes.Add("ondrop", "return false;");
                        tb_LOP.MaxLength = 5;
                        tb_LOP.CssClass = "form-control";
                        tb_LOP.Enabled = false;
                        tc_MaxLOP.Controls.Add(tb_LOP);
                        tr.Cells.Add(tc_MaxLOP);
                        TableCell tc_Count = new TableCell();
                        tc_Count.Width = Unit.Pixel(15);
                        tc_Count.HorizontalAlign = HorizontalAlign.Center;
                        CheckBox chk_before = new CheckBox();
                        chk_before.ID = "chkBefore" + (k + 1);
                        chk_before.Text = "Before";
                        CheckBox chk_after = new CheckBox();
                        chk_after.ID = "chkAfter" + (k + 1);
                        chk_after.Text = "After";
                        CheckBox chk_inter = new CheckBox();
                        chk_inter.ID = "chkInter" + (k + 1);
                        chk_inter.Text = "Intervening";
                        tc_Count.Controls.Add(chk_before);
                        tc_Count.Controls.Add(chk_after);
                        tc_Count.Controls.Add(chk_inter);
                        tr.Cells.Add(tc_Count);
                        TableCell tc_Borrow = new TableCell();
                        tc_Borrow.HorizontalAlign = HorizontalAlign.Center;
                        CheckBox chk_Borrow = new CheckBox();
                        chk_Borrow.ID = "Borrow" + (k + 1);
                        tc_Borrow.Controls.Add(chk_Borrow);
                        tr.Cells.Add(tc_Borrow);
                        TableCell tc_Carry = new TableCell();
                        tc_Carry.HorizontalAlign = HorizontalAlign.Center;
                        CheckBox chk_carry = new CheckBox();
                        chk_carry.ID = "Carry" + (k + 1);
                        tc_Carry.Controls.Add(chk_carry);
                        tr.Cells.Add(tc_Carry);
                        TableCell tc_Acc = new TableCell();
                        tc_Acc.HorizontalAlign = HorizontalAlign.Center;
                        TextBox tb_Acc = new TextBox();
                        tb_Acc.ID = "Acc" + (k + 1);
                        tb_Acc.Attributes.Add("onkeypress", "return number_dot(event,this);");
                        tb_Acc.Attributes.Add("onpaste", "return false;");
                        tb_Acc.Attributes.Add("ondrop", "return false;");
                        tb_Acc.MaxLength = 5;
                        tb_Acc.CssClass = "form-control";
                        tc_Acc.Controls.Add(tb_Acc);
                        tr.Cells.Add(tc_Acc);
                        TableCell tc_Encash = new TableCell();
                        tc_Encash.HorizontalAlign = HorizontalAlign.Center;
                        CheckBox chk_Encash = new CheckBox();
                        chk_Encash.ID = "Encash" + (k + 1);
                        chk_Encash.EnableViewState = true;
                        tc_Encash.Controls.Add(chk_Encash);
                        tr.Cells.Add(tc_Encash);
                        TableCell tc_AppAfter = new TableCell();
                        tc_AppAfter.HorizontalAlign = HorizontalAlign.Center;
                        TextBox tb_AppAfter = new TextBox();
                        tb_AppAfter.ID = "calcFactor" + (k + 1);
                        tb_AppAfter.Attributes.Add("onkeypress", "return number_dot(event,this);");
                        tb_AppAfter.Attributes.Add("onpaste", "return false;");
                        tb_AppAfter.Attributes.Add("ondrop", "return false;");
                        tb_AppAfter.MaxLength = 5;
                        tb_AppAfter.CssClass = "form-control";
                        tb_AppAfter.EnableViewState = true;
                        tc_AppAfter.Controls.Add(tb_AppAfter);
                        tr.Cells.Add(tc_AppAfter);
                        TableCell tc_CalcFactor = new TableCell();
                        tc_CalcFactor.Visible = true;
                        tc_CalcFactor.HorizontalAlign = HorizontalAlign.Center;
                        TextBox tb_CalcFactor = new TextBox();
                        tb_CalcFactor.ID = "calcFactor" + (k + 1);
                        tb_CalcFactor.Attributes.Add("onkeypress", "return number_dot(event,this);");
                        tb_CalcFactor.Attributes.Add("onpaste", "return false;");
                        tb_CalcFactor.Attributes.Add("ondrop", "return false;");
                        tb_CalcFactor.MaxLength = 5;
                        tb_CalcFactor.CssClass = "form-control";
                        if (Convert.ToString(ds_LeaveType.Tables[0].Rows[k]["CountFactor"]) == "False")
                        {
                            tb_CalcFactor.Enabled = false;
                        }
                        tb_CalcFactor.EnableViewState = true;
                        tc_CalcFactor.Controls.Add(tb_CalcFactor);
                        tr.Cells.Add(tc_CalcFactor);
                        TableCell tc_CountFactor = new TableCell();
                        tc_CountFactor.Visible = false;
                        //tc_CountFactor.HorizontalAlign = HorizontalAlign.Center;
                        CheckBox chk_WeekDays = new CheckBox();
                        chk_WeekDays.ID = "chkWeekDays" + (k + 1);
                        chk_WeekDays.Text = "Week Days ";
                        CheckBox chk_WeekOff = new CheckBox();
                        chk_WeekOff.ID = "chkWeekOff" + (k + 1);
                        chk_WeekOff.Text = "Week Off ";
                        CheckBox chk_Leave = new CheckBox();
                        chk_Leave.ID = "chkLeave" + (k + 1);
                        chk_Leave.Text = "Leave ";
                        CheckBox chk_Holidays = new CheckBox();
                        chk_Holidays.ID = "chkHolidays" + (k + 1);
                        chk_Holidays.Text = "Holidays";
                        if (Convert.ToString(ds_LeaveType.Tables[0].Rows[k]["CountFactor"]) == "False")
                        {
                            chk_WeekDays.Enabled = false;
                            chk_WeekOff.Enabled = false;
                            chk_Leave.Enabled = false;
                            chk_Holidays.Enabled = false;
                        }
                        else
                        {
                            chk_WeekDays.Checked = true;
                            chk_WeekDays.Enabled = false;
                        }
                        tc_CountFactor.Controls.Add(chk_WeekDays);
                        tc_CountFactor.Controls.Add(chk_WeekOff);
                        tc_CountFactor.Controls.Add(chk_Leave);
                        tc_CountFactor.Controls.Add(chk_Holidays);
                        tr.Cells.Add(tc_CountFactor);
                        TableCell tc_TypeID = new TableCell();
                        Label lbl_TypeID = new Label();
                        lbl_TypeID.ID = "Type_ID" + (k + 1);
                        lbl_TypeID.Text = Convert.ToString(ds_LeaveType.Tables[0].Rows[k]["LeaveType_Id"]);
                        tc_TypeID.Controls.Add(lbl_TypeID);
                        tr.Cells.Add(tc_TypeID);
                        tc_TypeID.Visible = false;
                        TableCell tc_AvailNoTimes_Service = new TableCell();
                        TextBox txtAvailNoTime = new TextBox();
                        txtAvailNoTime.ID = "txtAvailNoTime" + (k + 1);
                        txtAvailNoTime.Attributes.Add("onkeypress", "return number_dot(event,this);");
                        txtAvailNoTime.Attributes.Add("onpaste", "return false;");
                        txtAvailNoTime.Attributes.Add("ondrop", "return false;");
                        txtAvailNoTime.MaxLength = 5;
                        txtAvailNoTime.CssClass = "form-control";
                        tc_AvailNoTimes_Service.Controls.Add(txtAvailNoTime);
                        Label lblTimes = new Label();
                        lblTimes.Text = "Time(s)";
                        tc_AvailNoTimes_Service.Controls.Add(lblTimes);
                        tr.Cells.Add(tc_AvailNoTimes_Service);

                        if (Convert.ToInt32(ds_LeaveType.Tables[0].Rows[k]["isWFH"]) == 1)
                        {
                            tc_Count.Enabled = false;
                            tc_Loss.Enabled = false;
                            tc_Borrow.Enabled = false;
                            tc_Carry.Enabled = false;
                            tc_Encash.Enabled = false;
                            tc_AppAfter.Enabled = false;
                            tb_CalcFactor.Enabled = false;
                            //hdnCountFactor.Value = "false";
                            chk_WeekDays.Checked = true;
                            chk_WeekDays.Enabled = false;
                            tc_AvailNoTimes_Service.Enabled = false;
                            chk_WeekDays.Enabled = true;
                            chk_WeekOff.Enabled = true;
                            chk_Leave.Enabled = true;
                            chk_Holidays.Enabled = true;
                            tc_Acc.Enabled = false;
                        }

                        tbl_LeavePolicy.Rows.Add(tr);
                    }
                }
                #endregion
                //}
                #endregion
            }
        }
        PH_DynmCtrl.Controls.Add(tbl_LeavePolicy);
        shouldCreateControl = true;
    }
    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        lblminHrs_Instance.Text = rm.GetString("LeavePermissionPolicy_MinPermission_Hr_Per_Instance", ci);
        lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_MaxNoOfInstancesPerMonth.Text = rm.GetString("LeavePermissionPolicy_MaxNo_Of_Instances_Per_Month", ci);
        lbl_MaxPermissionHoursPerInstance.Text = rm.GetString("LeavePermissionPolicy_MaxPermission_Hr_Per_Instance", ci);
        lbl_MaxPermissionHoursPerMonth.Text = rm.GetString("LeavePermissionPolicy_MaxPermission_Hr_Per_Month", ci);
        lbl_PolicyName.Text = rm.GetString("LeavePermissionPolicy_PolicyName", ci);
        lbl_HeaderLeavePolicy.Text = rm.GetString("Masters_Leave_LeavePermissionPolicy", ci);
        chkAfterLeave.Text = rm.GetString("Permission_After_Leave", ci);
        chkBeforeLeave.Text = rm.GetString("Permission_Before_Leave", ci);
        chkOverTimeType.Text = rm.GetString("CompOff_Type", ci);
        lblGender.Text = rm.GetString("EmployeeMaster_Gender", ci);
        lblReligion.Text = rm.GetString("EmployeeMaster_Religion", ci);
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmpType.Text = rm.GetString("Master_Type", ci);
        rbt_HourWise.Text = rm.GetString("rbtn_HourWise", ci);
        rbt_DayWise.Text = rm.GetString("rbtn_DayWise", ci);
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        chkPermission.Text = rm.GetString("UserGroups_Permission", ci);
        lblHalfDayComoff.Text = rm.GetString("Min_Hrs_HalfDay_Comoff", ci);
        lblFullDayComoff.Text = rm.GetString("Min_Hrs_FullDay_Comoff", ci);
        lblValidsDays.Text = rm.GetString("CompOff_Validity_Days", ci);
        lbl_LeaveConfi.Text = rm.GetString("Leave_LeaveConfiguration", ci);
    }
    /// <summary>
    /// Checking the UserRights
    /// </summary>
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(196, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
}