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_MasterLeavePolicyAdd : Base.BasePage
{
    #region "Variable  Declaration"
    ResourceManager rm;
    LeaveEventData objLeave = new LeaveEventData();
    cls_Common objCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    CultureInfo ci;
    EmployeeEventData objEmployeeEventData = new EmployeeEventData();
    ShiftEvenData objShift = new ShiftEvenData();
    string gstrUserGroupName = string.Empty;
    int EmployeeID = 0;
    bool checkApplicableDaysExist;
    bool blApplicable;
    bool checkMaxDaysSpellExist;
    bool checkMinDaysSpellExist;
    bool checkSpellPerYearExist;
    bool checkCalcFactorExists;
    bool checkMinWorkedDaysExists;
    Table tbl_LeavePolicy = new Table();
    #endregion
    #region PageLoad
    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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        // LoadStrings Function fills the Label from the Resource File
        LoadStrings(ci);
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        //Set UserRights
        UserRights();
        txt_PolicyName.Focus();
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        // getting year setting details
        DataSet ds_Year = new DataSet();
        ds_Year = objCommon.GetYearsetting();
        if (ds_Year.Tables[0].Rows.Count <= 0)
        {
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        }
        btn_save.Attributes.Add("onclick", "return FieldValidation('" + rm.GetString("Alert_EnterPolicyName", ci) + "');");
        DataSet ds_LeaveType = new DataSet();
        if (Session["LeaveTypes"] == null)
        {
            ds_LeaveType = objLeave.SelectLeavePolicyDetails("", null, null, null, null);
        }
        else
        {
            ds_LeaveType = Session["LeaveTypes"] as DataSet;
        }
        #region "Table creation"
        //tbl_LeavePolicy.Width = Unit.Pixel(3000);
        //tbl_LeavePolicy.CssClass = "td";
        TableHeaderRow hr = new TableHeaderRow();
        TableHeaderCell hc_Applicable = new TableHeaderCell();
        hc_Applicable.VerticalAlign = VerticalAlign.Top;
        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.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);
        /*Below parameter is used for Angler*/
        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.Width = Unit.Percentage(1);
        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(0.5);
        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.Width = Unit.Percentage(1);
        hc_CalcFactor.Visible = true;
        hc_CalcFactor.CssClass = "lvepo-tblhdr lve-tblwid1";
        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_CountFactor.Width = Unit.Percentage(1);
        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 (Convert.ToBoolean(ViewState["NotInCategory"]) == true)
        {
            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.Text = " ";
                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"]);
                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();
                tc_MaxDaysPerMonth.HorizontalAlign = HorizontalAlign.Center;
                TextBox tb_MaxDaysPerMonth = new TextBox();
                tb_MaxDaysPerMonth.ID = "MaxDaysPerMonth" + i;
                tb_MaxDaysPerMonth.Attributes.Add("onkeypress", "return number_dot(event,this);");
                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("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");
                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";
                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);
                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);
                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);
                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";
                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.Left;
                CheckBox chk_carry = new CheckBox();
                //chk_carry.Style.Add("padding-left", "10px");
                chk_carry.ID = "Carry" + i;
                chk_carry.Text = " ";
                chk_carry.CssClass = "checkboxLeave checkboxLeave-primary";
                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.MaxLength = 5;
                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";
                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.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);
                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(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);
                tc_LeaveTypeCountFactor.Attributes.Add("style", "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);
                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
            }
        }
        else
        {
            PH_DynmCtrlDiv.Visible = false;
            hdnLeaveCount.Value = "0";
        }
        if (!IsPostBack)
        {
            Session["ddlEmployeeCategory"] = Convert.ToInt16(ddlEmpCatagory.SelectedValue);
            Session["ddlEmployeeType"] = Convert.ToInt16(ddlEmpType.SelectedValue);
            Session["ddlGender"] = Convert.ToInt16(ddlGender.SelectedValue);
            Session["ddlReligion"] = Convert.ToInt16(ddlReligion.SelectedValue);
            BindingEmployeeCategoryandType();
            PH_DynmCtrlDiv.Visible = false;
            objCommon.menu("LeaveMasters", "196");
            CompanyBinding();
        }
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "chkPermission('" + rm.GetString("Alert_Enterinhhmmformat", 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") + "','" + rm.GetString("Alert_ClickViewButton") + "','" + rm.GetString("Alert_Mentioned_Spells");
        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_SelectValidOptioninabove", 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;
        checkCalcFactorExists = true;
        checkMinWorkedDaysExists = true;
        //checking for already existing policy name and insert leave policy
        int ret_value = LeavePolicy();
        if (ret_value != 1)
        {
            //getting latest entry policy Id
            int MaxLeavePolicyID = objLeave.selectMAXLeavePolicyID();
            //insert leave policy details
            LeavePolicyDetails(MaxLeavePolicyID);
            Session["LeaveTypes"] = null;
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_LeavePolicysavedsuccessfully", ci) + "');";
            strScript = strScript + "location.replace('TA_UI_MasterLeavePolicyList.aspx');";
            strScript = strScript + "</script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, true);
        }
    }
    protected void btn_View_Click(object sender, EventArgs e)
    {
        hdfFilter.Value = "1";
        DataSet ds_LeaveType = new DataSet();
        ds_LeaveType = objLeave.SelectLeavePolicyDetails("", Convert.ToString(ddlEmpCatagory.SelectedItem.Value), Convert.ToString(ddlEmpType.SelectedItem.Value), Convert.ToString(ddlGender.SelectedItem.Text), Convert.ToString(ddlReligion.SelectedItem.Value));
        Session["LeaveTypes"] = ds_LeaveType;
        Session["ddlEmployeeCategory"] = Convert.ToInt16(ddlEmpCatagory.SelectedValue);
        Session["ddlEmployeeType"] = Convert.ToInt16(ddlEmpType.SelectedValue);
        Session["ddlGender"] = Convert.ToString(ddlGender.SelectedItem.Text);
        Session["ddlReligion"] = Convert.ToInt16(ddlReligion.SelectedValue);
        #region "Table creation"
        tbl_LeavePolicy.Rows.Clear();
        //tbl_LeavePolicy.Width = Unit.Percentage(100);
        tbl_LeavePolicy.CssClass = "table table-bordered";
        //tbl_LeavePolicy.Attributes.Add("style", "border-color:#86BFF0");
        TableHeaderRow hr = new TableHeaderRow();
        TableHeaderCell hc_Applicable = new TableHeaderCell();
        //hr.Attributes.Add("style", "border-color:#86BFF0");
        hc_Applicable.VerticalAlign = VerticalAlign.Top;
        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.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);
        /*Below parameter is used for Angler*/
        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);
        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.Width = Unit.Percentage(1);
        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.Width = Unit.Percentage(1);
        hc_CalcFactor.Visible = true;
        hc_CalcFactor.CssClass = "lvepo-tblhdr lve-tblwid1";
        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_CountFactor.Width = Unit.Percentage(1);
        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
        if (ds_LeaveType.Tables.Count > 0)
        {
            if (ds_LeaveType != null && ds_LeaveType.Tables[0].Rows.Count > 0)
            {
                int i = 1;
                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.Text = " ";
                    chk_Applicable.CssClass = "checkboxLeave checkboxLeave-primary";
                    chk_Applicable.Attributes.Add("style", "margin-top:0px;margin-bottom:0px;padding-top:10px;min-height: 17px;");
                    //chk_Applicable.CssClass = "checkbox checkbox-primary checkbox-circle";
                    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_dot(event,this);");
                    tb.Attributes.Add("onpaste", "return false;");
                    tb.Attributes.Add("ondrop", "return false;");
                    tb.MaxLength = 5;
                    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();
                    tc_MaxDaysPerMonth.HorizontalAlign = HorizontalAlign.Center;
                    TextBox tb_MaxDaysPerMonth = new TextBox();
                    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("onkeypress", "return chkDecNums(event, this);");
                    //tb_max.Attributes.Add("onblur", "return chkAppDayValue(this," + i + ");");
                    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("onblur", "return chkMinMaxValue(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("onblur", "return chkSpells(this," + i + ");");
                    tb_spell.Attributes.Add("onpaste", "return false;");
                    tb_spell.Attributes.Add("ondrop", "return false;");
                    tb_spell.MaxLength = 3;
                    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();
                    if (Convert.ToInt32(dr["isWFH"]) == 1)
                    {

                    }
                    rbl_Loss.ID = "Loss" + i;
                    tc_Loss.Style.Add("padding-left", "20px");
                    // rbl_Loss.CssClass = "radioLeave radioLeave-primary";
                    //rbl_Loss.CssClass = "radio radio-primary";
                    //rbl_Loss.Width = 62;
                    //rbl_Loss.Attributes.Add("onclick", "return chkRadiobut(this);");
                    ListItem lst_Yes = new ListItem();
                    //lst_Yes.Text = "Yes";
                    lst_Yes.Text = rm.GetString("ShiftSetting_Yes", ci);
                    lst_Yes.Value = "1";
                    //lst_Yes.Attributes.Add("Width", "100");
                    lst_Yes.Attributes.Add("onclick", "return chkRadiobut(" + i + ",'1');");
                    ListItem lst_No = new ListItem();
                    lst_No.Selected = true;
                    //lst_No.Text = "No";
                    //lst_No.CssClass = "radio radio-primary";
                    lst_No.Text = rm.GetString("ShiftSetting_No", ci);
                    lst_No.Value = "0";
                    //lst_No.Attributes.Add("Width", "100");
                    rbl_Loss.Items.Add(lst_Yes);
                    rbl_Loss.Items.Add(lst_No);
                    rbl_Loss.CssClass = "radioPolicy radioPolicy-primary";
                    //rbl_Loss.Style.Add("padding-right", "1px");
                    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("onkeypress", "return chkDecNums(event, this);");
                    //tb_LOP.Attributes.Add("onblur", "return chkMaxLOP(this," + i + ");");
                    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();

                    //tc_Count.Width = Unit.Pixel(15);
                    //tc_Count.HorizontalAlign = HorizontalAlign.Center;
                    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 = "Before";
                    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 = "After";
                    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 = "Intervening";
                    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.MaxLength = 5;
                    tb_Acc.Attributes.Add("onkeypress", "return number_dot(event,this);");
                    //tb_Acc.Attributes.Add("onkeypress", "return chkDecNums(event, this);");
                    // tb_Acc.Attributes.Add("onblur", "return chkMAccDays(this," + i + ");");
                    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("onkeypress", "return chkDecNums(event, this);");
                    //tb_AppAfter.Attributes.Add("onblur", "return chkAppAfterDays(this," + i + ");");
                    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("onkeypress", "return chkDecNums(event, this);");
                    //tb_CalcFactor.Attributes.Add("onblur", "return chkCalcFactor(this," + i + ");");
                    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("onkeypress", "return chkDecNums(event, this);");
                    //tb_WorkDays.Attributes.Add("onblur", "return chkWorkDays(this," + i + ");");
                    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.Visible = true;
                    //tc_CountFactor.Width = Unit.Pixel(250);
                    //tc_CountFactor.HorizontalAlign = HorizontalAlign.Left;
                    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 = "Wk Day";
                    chk_WeekDays.Text = rm.GetString("LeavePolicy_WkDay", ci);
                    CheckBox chk_WeekOff = new CheckBox();
                    chk_WeekOff.ID = "chkWeekOff" + i;
                    //chk_WeekOff.Text = "Wk Off";
                    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.Text = "Leave ";
                    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 = "Holidays";
                    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);
                    tc_LeaveTypeCountFactor.Attributes.Add("style", "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);
                    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_DynmCtrlDiv.Visible = true;
                ViewState["NotInCategory"] = true;
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ThereIsNoRecordInThisCategory", ci) + "');", true);
                PH_DynmCtrlDiv.Visible = false;
                hdnLeaveCount.Value = "0";
                ViewState["NotInCategory"] = false;
                hdfFilter.Value = "-1";
            }
        }
    }
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        Session["LeaveTypes"] = null;
        Response.Redirect("TA_UI_MasterLeavePolicyList.aspx");
    }
    #endregion
    #region UserDefined Functions
    #region BindingEmployeeCategoryandType.
    /// <summary>
    /// Bindings the employee category and type.
    /// </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();
            foreach (ListItem item in ddlEmpCatagory.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
        // 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();
            foreach (ListItem item in ddlEmpType.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
        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();
            foreach (ListItem item in ddlReligion.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }
    #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_Month = txt_MaxHrsMonth.Text.Trim();
        int intMaxInstances_Month;
        intMaxInstances_Month = (txt_MaxInstances.Text.Trim() == "") ? 0 : 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);
        }
        PermissionBeforeLeave = (chkBeforeLeave.Checked == true) ? 1 : 0;
        PermissionAfterLeave = (chkAfterLeave.Checked == true) ? 1 : 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;
            }
            ValidsDays = Convert.ToInt32(txtValidsDays.Text);
            OtMinHrs = Convert.ToString(txtFullDayComoff.Text).Trim();
            HalfDayCompOff = Convert.ToString(txtHalfDayComoff.Text).Trim();
        }
        //checking already existing policy name and insert new policy
        if (objLeave.LeavePolicyName(strPolicyName) == 0)
        {
            int isLeaveTypeSelectedCount = 0;
            CheckBox chkApplicable = new CheckBox();
            HiddenField hdnCountFactor = new HiddenField();
            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;
                    break;
                }
            }
            #region InsertleavepolicyDetails
            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;

                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)
                        {
                            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 (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;
                            }
                            else 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;
                                }
                            }
                        }
                    }
                }
                totalYrDays = sumOfAppDays + sumOfLOP;
                //As per partner requisition displayed this validation on 12-02-2019 02.07 PM by manikandan.rr
                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;
                }
                //Policy Year Removed                
                objLeave.UpdateLeavePolicy('I', 0, strPolicyName, strMaxHrs_Month, intMaxInstances_Month, strMaxHrs_Ins, EmployeeID, PermissionBeforeLeave, PermissionAfterLeave, OtHourWise, OtDayWise, OtMinHrs, Convert.ToInt16(Session["ddlEmployeeCategory"]), Convert.ToInt16(Session["ddlEmployeeType"]), Convert.ToString(Session["ddlGender"]), Convert.ToInt16(Session["ddlReligion"]), HalfDayCompOff, ValidsDays, Convert.ToInt32(ddlCompany.SelectedItem.Value), strMinHrs_Ins);
            }
            #endregion
            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 Max_LPID)
    {
        CheckBox chkApplicable = new CheckBox();
        HiddenField hdnCountFactor = new HiddenField();
        TextBox tbDays = new TextBox();
        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 != null)
            {
                if (chkApplicable.Checked == true)
                    blApplicable = true;
                else
                    blApplicable = false;
            }
            tbDays = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("total" + j);
            float fltTotalDays = 0;
            if (tbDays != null)
            {
                if (tbDays.Text.Trim() == "")
                    fltTotalDays = 0;
                else
                    fltTotalDays = Convert.ToSingle(tbDays.Text.Trim());
            }
            if (chkApplicable != null)
            {
                if (chkApplicable.Checked == true)
                    if (fltTotalDays == 0 || fltTotalDays == 0.0)
                        if (hdnCountFactor.Value == "False")
                        {
                            checkApplicableDaysExist = false;
                            return;
                        }
            }
            /*Below parameter is used for Angler*/
            float fltMaxDaysPerMonth = 0;
            TextBox tbMaxDaysPerMonth = new TextBox();
            tbMaxDaysPerMonth = (TextBox)tbl_LeavePolicy.Rows[j].FindControl("MaxDaysPerMonth" + j);
            if (tbMaxDaysPerMonth != null)
            {
                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 = 0;
            if (tbMaxDays != null)
            {
                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 = 0;
            if (tbMinDays != null)
            {
                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 = 0;
            if (tbSpell != null)
            {
                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 = 0;
            if (tbMaxAccDays != null)
            {
                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);
            TextBox tbAvailServicePeriod = new TextBox();
            int intAvailServicePeriod = 0;
            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(Max_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);
                string strScript = "";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Alert_LeavePolicysavedsuccessfully", ci) + "');";
                strScript = strScript + "location.replace('TA_UI_MasterLeavePolicyList.aspx');";
                strScript = strScript + "</script>";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            }
        }
    }
    #endregion
    #region Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo 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);
        //lblPermissionAfterLeave.Text = rm.GetString("Permission_After_Leave", ci);
        //lblPermissionBeforeLeave.Text = rm.GetString("Permission_Before_Leave", ci);
        chkBeforeLeave.Text = rm.GetString("Permission_Before_Leave", ci);
        chkAfterLeave.Text = rm.GetString("Permission_After_Leave", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", 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);
        //l1.Text = rm.GetString("rbtn_HourWise", ci);
        rbt_HourWise.Text = rm.GetString("rbtn_HourWise", ci);
        //Label1.Text = rm.GetString("rbtn_DayWise", ci);
        rbt_DayWise.Text = rm.GetString("rbtn_DayWise", ci);
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        //lblPermissionStatus.Text = rm.GetString("UserGroups_Permission", ci);
        //lbl_OtType.Text = rm.GetString("CompOff_Type", ci);
        chkOverTimeType.Text = rm.GetString("CompOff_Type", 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);
        lblminHrs_Instance.Text = rm.GetString("LeavePermissionPolicy_MinPermission_Hr_Per_Instance", ci);
    }
    #endregion
    #region CheckingUserRights
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(196, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
    protected void ddlEmpCatagory_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl = sender as DropDownList;
        DropdownTooltip(ddl);
    }
    protected void ddlEmpType_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl = sender as DropDownList;
        DropdownTooltip(ddl);
    }
    protected void ddlReligion_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl = sender as DropDownList;
        DropdownTooltip(ddl);
    }
    private void DropdownTooltip(DropDownList ddl)
    {
        if (ddl != null)
        {
            foreach (ListItem li in ddl.Items)
            {
                li.Attributes["title"] = li.Text;
            }
        }
    }
    private void CompanyBinding()
    {
        DataSet dsCompany = new DataSet();
        dsCompany = objShift.SelectCompany(gstrUserGroupName, Convert.ToString(Session["LevelRights"]), 0);
        if (dsCompany != null)
        {
            if (dsCompany.Tables[0].Rows.Count > 0)
            {
                ddlCompany.DataSource = dsCompany;
                ddlCompany.DataTextField = "CompanyName";
                ddlCompany.DataValueField = "CompanyId";
                ddlCompany.DataBind();
            }
        }
        foreach (ListItem item in ddlCompany.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
}