using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;


public partial class Masters_TA_UI_Master_TaxPolicyAdd : Base.BasePage
{
    cls_Common objCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    ResourceManager rm;
    CultureInfo ci;
    PayrollConfigurationEventData objPayrollEventData = new PayrollConfigurationEventData();
    ShiftEvenData objShift = new ShiftEvenData();
    EmployeeEventData objEmployeeEventData = new EmployeeEventData();
    string gstrUserGroupName = string.Empty;
    Table tbl_TdsSlab = new Table();
    Table tbl_ProfessSlab = new Table();
    //Tbl_Class tblClass;
    List<string> controlList = new List<string>();
    Dictionary<string, string> txtDiscValue;
    int counter = 0;
    string source_Language;
    string strScript = string.Empty;

    protected override void Page_Load(object sender, EventArgs e)
    {
        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);
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        btn_save.Attributes.Add("onclick", "return FieldValidation('" + rm.GetString("Alert_EnterPolicyName", ci) + "');");

        if (!IsPostBack)
        {
            Session["ddlCompanyName"] = Convert.ToInt16(ddlCompany.SelectedValue);
            Session["ddlEmployeeCategory"] = Convert.ToInt16(ddlEmpCatagory.SelectedValue);
            Session["ddlEmployeeType"] = Convert.ToInt16(ddlEmpType.SelectedValue);
            Session["ddlGender"] = Convert.ToInt16(ddlGender.SelectedValue);
            BindingEmployeeCategoryandType();
            objCommon.menu("PayrollMaster", "317");
            CompanyBinding();
            Session["SlabCount"] = 3;

            TaxSlabAutoGenerate(Session["SlabCount"]);
            PH_DynmCtrl.Controls.Add(tbl_TdsSlab);
            Session["ProfSlabCount"] = 3;
            DynamicProfessionalSlabCreate(Session["ProfSlabCount"]);
            PHProfess_DynCtrl.Controls.Add(tbl_ProfessSlab);


        }
        else
        {

            TaxSlabAutoGenerate(Session["SlabCount"]);
            PH_DynmCtrl.Controls.Add(tbl_TdsSlab);
            DynamicProfessionalSlabCreate(Session["ProfSlabCount"]);
            PHProfess_DynCtrl.Controls.Add(tbl_ProfessSlab);

        }

    }

    #region Auto generate Table 
    private void TaxSlabAutoGenerate(object v)
    {
        tbl_TdsSlab.ID = "tbl_Slab";
        tbl_TdsSlab.CssClass = "Col-md-12 ";

        //tbl_TdsSlab.Attributes["Class"] = "tb_Slab";

        TableHeaderRow hr = new TableHeaderRow();
        hr.CssClass = "row form-group col-md-12";

        TableHeaderCell hc_slabName = new TableHeaderCell();
        hc_slabName.CssClass = "col-md-2 lvepo-tblHeader";
        hc_slabName.VerticalAlign = VerticalAlign.Top;
        hc_slabName.HorizontalAlign = HorizontalAlign.Left;
        hc_slabName.Text = "Tax slab No";
        hc_slabName.Style.Add("opacity", "0");
        hc_slabName.Width = Unit.Percentage(1);
        Label lbl_hcSlab = new Label();

        hr.Cells.Add(hc_slabName);

        TableHeaderCell hc_RangeFrom = new TableHeaderCell();
        hc_RangeFrom.CssClass = "col-md-2 lvepo-tblHeader";
        hc_RangeFrom.HorizontalAlign = HorizontalAlign.Center;
        hc_RangeFrom.Width = Unit.Percentage(1);
        hc_RangeFrom.Style.Add("Position", "relative");
        hc_RangeFrom.Style.Add("left", "30px");
        hc_RangeFrom.Text = "Range From";
        hr.Cells.Add(hc_RangeFrom);

        TableHeaderCell hc_RangeTo = new TableHeaderCell();
        hc_RangeTo.CssClass = "col-md-2 lvepo-tblHeader";
        hc_RangeTo.VerticalAlign = VerticalAlign.Middle;
        hc_RangeTo.HorizontalAlign = HorizontalAlign.Center;
        hc_RangeTo.Style.Add("Position", "relative");
        hc_RangeTo.Style.Add("left", "40px");
        hc_RangeTo.Width = Unit.Percentage(1);
        hc_RangeTo.Text = "Range To";
        hr.Cells.Add(hc_RangeTo);

        TableHeaderCell hc_TdsPercent = new TableHeaderCell();
        hc_TdsPercent.CssClass = "col-md-2 lvepo-tblHeader";
        hc_TdsPercent.VerticalAlign = VerticalAlign.Middle;
        hc_TdsPercent.HorizontalAlign = HorizontalAlign.Center;
        hc_TdsPercent.Style.Add("Position", "relative");
        hc_TdsPercent.Style.Add("left", "50px");
        hc_TdsPercent.Width = Unit.Percentage(1);
        hc_TdsPercent.Text = "TDS %";
        hr.Cells.Add(hc_TdsPercent);

        TableHeaderCell hc_Plus = new TableHeaderCell();
        hc_Plus.CssClass = "col-md-1 lvepo-tblHeader";
        hc_Plus.VerticalAlign = VerticalAlign.Middle;
        hc_Plus.HorizontalAlign = HorizontalAlign.Center;
        hc_Plus.Width = Unit.Percentage(0);
        hc_Plus.Text = "Symbol";
        hc_Plus.Style.Add("opacity", "0");
        hr.Cells.Add(hc_Plus);

        TableHeaderCell hc_Cess = new TableHeaderCell();
        hc_Cess.CssClass = "col-md-2 lvepo-tblHeader";
        hc_Cess.VerticalAlign = VerticalAlign.Middle;
        hc_Cess.HorizontalAlign = HorizontalAlign.Center;
        hc_Cess.Width = Unit.Percentage(1);
        hc_Cess.Style.Add("Position", "relative");
        hc_Cess.Style.Add("left", "30px");
        hc_Cess.Text = "Additional Cess";
        hr.Cells.Add(hc_Cess);

        TableHeaderCell hc_Delete = new TableHeaderCell();
        hc_Delete.CssClass = "col-md-1 lvepo-tblHeader";
        hc_Delete.VerticalAlign = VerticalAlign.Middle;
        hc_Delete.Width = Unit.Percentage(0.9);
        hc_Delete.HorizontalAlign = HorizontalAlign.Center;
        hc_Delete.Text = "Delete";
        hc_Delete.Style.Add("opacity", "0");
        hr.Cells.Add(hc_Delete);
        tbl_TdsSlab.Rows.Add(hr);


        int id = Convert.ToInt32(v);

        for (int i = 1; i <= id; i++)
        {
            TableRow tr = new TableRow();
            tr.ID = "tr_" + i;
            tr.CssClass = "row form-group col-md-12";

            TableCell tc_Slab = new TableCell();
            tc_Slab.CssClass = "col-md-2";


            tc_Slab.HorizontalAlign = HorizontalAlign.Left;
            tc_Slab.Width = Unit.Percentage(1);
            Label lbl_Slab = new Label();
            lbl_Slab.ID = "lbl_TdsSlab" + i;
            lbl_Slab.Text = "TDS Slab" + i;

            tc_Slab.Controls.Add(lbl_Slab);
            tr.Cells.Add(tc_Slab);


            TableCell tc_RangeFrom = new TableCell();
            tc_RangeFrom.CssClass = "col-md-2";
            tc_RangeFrom.HorizontalAlign = HorizontalAlign.Center;
            tc_RangeFrom.Width = Unit.Percentage(1);
            TextBox tb_SlabFrom = new TextBox();
            tb_SlabFrom.ID = "txt_TdsRangeFrom_" + i;
            tb_SlabFrom.Attributes.Add("onkeypress", "return OnlyNumberValuewithzero(event,this);");
            tb_SlabFrom.Attributes.Add("onpaste", "return false;");
            tb_SlabFrom.Attributes.Add("ondrop", "return false;");
            tb_SlabFrom.Attributes.Add("runnat", "Server");
            tb_SlabFrom.Attributes.Add("Placeholder", " ₹ INR");
            tb_SlabFrom.MaxLength = 12;
            tb_SlabFrom.CssClass = "form-control ";
            tc_RangeFrom.Controls.Add(tb_SlabFrom);
            tr.Cells.Add(tc_RangeFrom);


            TableCell tc_RangeTO = new TableCell();
            tc_RangeTO.CssClass = "col-md-2";
            tc_RangeTO.HorizontalAlign = HorizontalAlign.Center;
            tc_RangeTO.Width = Unit.Percentage(1);
            TextBox tb_SlabTO = new TextBox();
            tb_SlabTO.ID = "txt_TdsRangeTo_" + i;
            tb_SlabTO.Attributes.Add("onkeypress", "return onlyNumbersValue(event,this);");
            tb_SlabTO.Attributes.Add("onpaste", "return false;");
            tb_SlabTO.Attributes.Add("ondrop", "return false;");
            tb_SlabTO.Attributes.Add("runnat", "Server");
            tb_SlabTO.Attributes.Add("Placeholder", " ₹ INR");
            tb_SlabTO.MaxLength = 12;
            tb_SlabTO.CssClass = "form-control";

            tc_RangeTO.Controls.Add(tb_SlabTO);
            tr.Cells.Add(tc_RangeTO);

            TableCell tc_TdsPercent = new TableCell();
            tc_TdsPercent.CssClass = "col-md-2";
            tc_TdsPercent.HorizontalAlign = HorizontalAlign.Center;
            tc_TdsPercent.Width = Unit.Percentage(1);
            TextBox tb_SlabPercent = new TextBox();
            tb_SlabPercent.ID = "txt_TdsRangePercent_" + i;
            tb_SlabPercent.Attributes.Add("onkeypress", "return number_dot(event,this);");
            tb_SlabPercent.Attributes.Add("onpaste", "return false;");
            tb_SlabPercent.Attributes.Add("ondrop", "return false;");
            tb_SlabPercent.Attributes.Add("Placeholder", " %");
            tb_SlabPercent.MaxLength = 5;
            tb_SlabPercent.CssClass = "form-control ";
            tc_TdsPercent.Controls.Add(tb_SlabPercent);
            tr.Cells.Add(tc_TdsPercent);

            TableCell tc_Plus = new TableCell();
            tc_Plus.CssClass = "Col-md-1";
            tc_Plus.HorizontalAlign = HorizontalAlign.Center;
            tc_Plus.Width = Unit.Percentage(0);
            Label lbl_plus = new Label();
            lbl_plus.ID = "lbl_plus" + i;
            lbl_plus.CssClass = "col-md-12 control-label con-top";
            lbl_plus.Text = "+";

            tc_Plus.Controls.Add(lbl_plus);

            tr.Cells.Add(tc_Plus);

            TableCell tc_CessPercent = new TableCell();
            tc_CessPercent.HorizontalAlign = HorizontalAlign.Center;
            tc_CessPercent.Width = Unit.Percentage(1);
            tc_CessPercent.CssClass = "col-md-2";
            TextBox tb_SlabAdditional = new TextBox();
            tb_SlabAdditional.ID = "txt_TdsCess_" + i;
            tb_SlabAdditional.Attributes.Add("onkeypress", "return number_dot(event,this);");
            tb_SlabAdditional.Attributes.Add("onpaste", "return false;");
            tb_SlabAdditional.Attributes.Add("ondrop", "return false;");
            tb_SlabAdditional.Attributes.Add("Placeholder", " %");
            tb_SlabAdditional.MaxLength = 5;
            tb_SlabAdditional.CssClass = "form-control";
            tc_CessPercent.Controls.Add(tb_SlabAdditional);
            tr.Cells.Add(tc_CessPercent);

            TableCell tc_deletebtn = new TableCell();
            tc_deletebtn.ID = "tc_delete_btn_" + i;
            tc_deletebtn.HorizontalAlign = HorizontalAlign.Center;
            tc_deletebtn.Width = Unit.Percentage(1);
            Button btnDelete = new Button();
            btnDelete.ID = "tds_SlabDelete_" + i;
            btnDelete.Text = "-";
            btnDelete.CommandName = "Delete";
            btnDelete.CommandArgument = i.ToString();
            btnDelete.Click += new EventHandler(btnDelete_Click);
            btnDelete.Visible = false;
            tc_deletebtn.Controls.Add(btnDelete);
            tr.Cells.Add(tc_deletebtn);

            int count = Convert.ToInt32(Session["SlabCount"]);

            if (i == (count + 1) && i != 3)
            {
                tc_deletebtn.Width = Unit.Percentage(0.9);
                btnDelete.Visible = true;
            }
            else
            {
                btnDelete.Visible = false;
            }

            tbl_TdsSlab.Rows.Add(tr);
            hdnTaxPolicyCount.Value = Convert.ToString(i);

        }


    }
    #endregion

    private void LoadStrings(CultureInfo ci)
    {
        lbl_HeaderTaxPolicy.Text = rm.GetString("Masters_TaxPolicy", ci);
        lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        lbl_PolicyName.Text = rm.GetString("TaxPolicy_Name", ci);
        lblGender.Text = rm.GetString("EmployeeMaster_Gender", ci);
        lbl_IndicatesMandatoryFields.Text= rm.GetString("IndicatesMandatoryFields", ci);
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmpType.Text = rm.GetString("Master_Type", ci);
        chkTDS.Text = rm.GetString("UserGroups_TDS", ci);
        btn_AddSlab.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        chkProfessionalTax.Text = rm.GetString("UserGroup_Professional", ci);
        btn_ProfessAddSlab.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);


    }


    protected void btn_save_Click(object sender, EventArgs e)
    {

        InsertTaxPolicy();

    }


    private void InsertTaxPolicy()
    {

        DataSet dsPolicy = new DataSet();
        Hashtable Chkpolicy = new Hashtable();
        Chkpolicy.Add("@tag", "CP");
        Chkpolicy.Add("@TaxPolicyName", Convert.ToString(txt_PolicyName.Text));
        dsPolicy = objPayrollEventData.InsertTaxPolicy(Chkpolicy);
        if (dsPolicy.Tables[0].Rows.Count == 0)
        {

            int taxSlabcout = tbl_TdsSlab.Rows.Count;

            DataSet InsertTaxPolicy = new DataSet();
            Hashtable htable = new Hashtable();
            htable.Add("@tag", "I");
            htable.Add("@TaxPolicyName", Convert.ToString(txt_PolicyName.Text));
            htable.Add("@companyID", Convert.ToInt16(ddlCompany.SelectedValue));
            htable.Add("@EmployeeCategory", Convert.ToInt16(ddlEmpCatagory.SelectedValue));
            htable.Add("@EmployeeType", Convert.ToInt16(ddlEmpType.SelectedValue));
            htable.Add("@Gender", Convert.ToString(ddlGender.SelectedItem));
            htable.Add("@Employee_Id", Convert.ToInt32(Session["EmpAutoID"]));
            htable.Add("@TdsSlabCount", taxSlabcout);


            InsertTaxPolicy = objPayrollEventData.InsertTaxPolicy(htable);

            for (int j = 1; j < tbl_TdsSlab.Rows.Count; j++)
            {
                Label lblSlabName = new Label();
                lblSlabName = (Label)tbl_TdsSlab.Rows[j].FindControl("lbl_TdsSlab" + j);

                TextBox txt_FromRange = new TextBox();
                txt_FromRange = (TextBox)tbl_TdsSlab.Rows[j].FindControl("txt_TdsRangeFrom_" + j);

                TextBox txt_ToRange = new TextBox();
                txt_ToRange = (TextBox)tbl_TdsSlab.Rows[j].FindControl("txt_TdsRangeTo_" + j);

                TextBox txt_TdsPercentage = new TextBox();
                txt_TdsPercentage = (TextBox)tbl_TdsSlab.Rows[j].FindControl("txt_TdsRangePercent_" + j);

                TextBox txt_AddCess = new TextBox();
                txt_AddCess = (TextBox)tbl_TdsSlab.Rows[j].FindControl("txt_TdsCess_" + j);

                Hashtable tdsHash = new Hashtable();
                tdsHash.Add("@tag", "TDS");
                tdsHash.Add("@TaxPolicyId", Convert.ToInt32(InsertTaxPolicy.Tables[0].Rows[0]["PolicyID"].ToString()));
                tdsHash.Add("@TDSSlabName", lblSlabName.Text);
                tdsHash.Add("@TDSSalaryFrom", Convert.ToInt64(txt_FromRange.Text));
                tdsHash.Add("@TDSSalaryTO", Convert.ToInt64(txt_ToRange.Text));
                tdsHash.Add("@TDSPercentage", Convert.ToDouble(txt_TdsPercentage.Text));
                tdsHash.Add("@TDSCessPercentage", (txt_AddCess.Text == "" ? 0.0 : Convert.ToDouble(txt_AddCess.Text)));

                objPayrollEventData.InsertTaxSlabValues(tdsHash);

            }

            string txtID = string.Empty;
            int isflag = 0;
            if(rbtn_Percentage.Checked)
            {
                txtID = "txt_ProfTaxPercentage_";
                isflag = 1;
            }
            else
            {
                txtID = "txt_ProfTaxAmount_";
                isflag = 0;
            }
            for (int j = 1; j < tbl_ProfessSlab.Rows.Count; j++)
            {
                Label lblSlabName = new Label();
                lblSlabName = (Label)tbl_ProfessSlab.Rows[j].FindControl("lbl_ProfSlab" + j);

                TextBox txt_FromRange = new TextBox();
                txt_FromRange = (TextBox)tbl_ProfessSlab.Rows[j].FindControl("txt_ProfRangeFrom_" + j);

                TextBox txt_ToRange = new TextBox();
                txt_ToRange = (TextBox)tbl_ProfessSlab.Rows[j].FindControl("txt_ProfRangeTo_" + j);

                TextBox txt_TdsPercentage = new TextBox();
                txt_TdsPercentage = (TextBox)tbl_ProfessSlab.Rows[j].FindControl(txtID + j);

                Hashtable ProfHash = new Hashtable();
                ProfHash.Add("@tag", "PROF");
                ProfHash.Add("@TaxPolicyId", Convert.ToInt32(InsertTaxPolicy.Tables[0].Rows[0]["PolicyID"].ToString()));
                ProfHash.Add("@ProfSlabName", lblSlabName.Text);
                ProfHash.Add("@ProfSalaryFrom", Convert.ToInt64(txt_FromRange.Text));
                ProfHash.Add("@ProfSalaryTo", Convert.ToInt64(txt_ToRange.Text));
                ProfHash.Add("@ProfTaxAmount", Convert.ToString(txt_TdsPercentage.Text));
                ProfHash.Add("@ProfISFlag", isflag);


                objPayrollEventData.InsertTaxSlabValues(ProfHash);

            }


            base.MessageWithRedirect(rm.GetString("Alert_TaxPolicysavedsuccessfully", ci), "TA_UI_Master_TaxPolicy.aspx");

        }
        else
        {
            strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('Policy name already exist')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;

        }


    }

    protected void btn_cancel_Click(object sender, EventArgs e)
    {

        base.Response.Redirect("TA_UI_Master_TaxPolicy.aspx");
    }
    //TDS Slab Add Button
    protected void btn_AddSlab_Click(object sender, EventArgs e)
    {

        int rowId;
        rowId = Convert.ToInt32(Session["SlabCount"]);
        rowId = rowId + 1;


        TableRow tr = new TableRow();
        tr.ID = "tr_" + rowId;
        tr.CssClass = "row form-group col-sm-12";

        TableCell tc_Slab = new TableCell();
        tc_Slab.CssClass = "col-md-2";



        tc_Slab.HorizontalAlign = HorizontalAlign.Left;
        tc_Slab.Width = Unit.Percentage(1);
        Label lbl_Slab = new Label();
        lbl_Slab.ID = "lbl_TdsSlab" + rowId;
        lbl_Slab.Text = "TDS Slab" + rowId;

        tc_Slab.Controls.Add(lbl_Slab);
        tr.Cells.Add(tc_Slab);


        TableCell tc_RangeFrom = new TableCell();
        tc_RangeFrom.CssClass = "col-md-2";
        tc_RangeFrom.HorizontalAlign = HorizontalAlign.Center;
        tc_RangeFrom.Width = Unit.Percentage(1);
        TextBox tb_SlabFrom = new TextBox();
        tb_SlabFrom.ID = "txt_TdsRangeFrom_" + rowId;
        tb_SlabFrom.Attributes.Add("onkeypress", "return onlyNumbersValue(event,this);");
        tb_SlabFrom.Attributes.Add("onkeyup", "PreventFirstZero(event)");
        tb_SlabFrom.Attributes.Add("onpaste", "return false;");
        tb_SlabFrom.Attributes.Add("ondrop", "return false;");
        tb_SlabFrom.Attributes.Add("runnat", "Server");
        tb_SlabFrom.Attributes.Add("Placeholder", " ₹ INR");
        tb_SlabFrom.MaxLength = 12;
        tb_SlabFrom.CssClass = "form-control ";
        tc_RangeFrom.Controls.Add(tb_SlabFrom);
        tr.Cells.Add(tc_RangeFrom);


        TableCell tc_RangeTO = new TableCell();
        tc_RangeTO.CssClass = "col-md-2";
        tc_RangeTO.HorizontalAlign = HorizontalAlign.Center;
        tc_RangeTO.Width = Unit.Percentage(1);
        TextBox tb_SlabTO = new TextBox();
        tb_SlabTO.ID = "txt_TdsRangeTo_" + rowId;
        tb_SlabTO.Attributes.Add("onkeypress", "return onlyNumbersValue(event,this);");
        tb_SlabTO.Attributes.Add("onpaste", "return false;");
        tb_SlabTO.Attributes.Add("ondrop", "return false;");
        tb_SlabTO.Attributes.Add("runnat", "Server");
        tb_SlabTO.Attributes.Add("Placeholder", " ₹ INR");
        tb_SlabTO.MaxLength = 12;
        tb_SlabTO.CssClass = "form-control";
        tc_RangeTO.Controls.Add(tb_SlabTO);
        tr.Cells.Add(tc_RangeTO);

        TableCell tc_TdsPercent = new TableCell();
        tc_TdsPercent.CssClass = "col-md-2";
        tc_TdsPercent.HorizontalAlign = HorizontalAlign.Center;
        tc_TdsPercent.Width = Unit.Percentage(1);
        TextBox tb_SlabPercent = new TextBox();
        tb_SlabPercent.ID = "txt_TdsRangePercent_" + rowId;
        tb_SlabPercent.Attributes.Add("onkeypress", "return number_dot(event,this);");
        tb_SlabPercent.Attributes.Add("onpaste", "return false;");
        tb_SlabPercent.Attributes.Add("ondrop", "return false;");
        tb_SlabPercent.Attributes.Add("Placeholder", "%");
        tb_SlabPercent.MaxLength = 5;
        tb_SlabPercent.CssClass = "form-control ";
        tc_TdsPercent.Controls.Add(tb_SlabPercent);
        tr.Cells.Add(tc_TdsPercent);

        TableCell tc_Plus = new TableCell();
        tc_Plus.CssClass = "Col-md-1";
        tc_Plus.HorizontalAlign = HorizontalAlign.Center;
        tc_Plus.Width = Unit.Percentage(0);
        Label lbl_plus = new Label();
        lbl_plus.ID = "lbl_plus" + rowId;
        lbl_plus.CssClass = "col-md-12 control-label con-top";
        lbl_plus.Text = "+";

        tc_Plus.Controls.Add(lbl_plus);

        tr.Cells.Add(tc_Plus);

        TableCell tc_CessPercent = new TableCell();
        tc_CessPercent.HorizontalAlign = HorizontalAlign.Center;
        tc_CessPercent.Width = Unit.Percentage(1);
        tc_CessPercent.CssClass = "col-md-2";
        TextBox tb_SlabAdditional = new TextBox();
        tb_SlabAdditional.ID = "txt_TdsCess_" + rowId;
        tb_SlabAdditional.Attributes.Add("onkeypress", "return number_dot(event,this);");
        tb_SlabAdditional.Attributes.Add("onpaste", "return false;");
        tb_SlabAdditional.Attributes.Add("ondrop", "return false;");
        //tb_SlabAdditional.Attributes.Add("onblur", "validatepercent(this)");
        tb_SlabAdditional.Attributes.Add("Placeholder", " %");
        tb_SlabAdditional.MaxLength = 5;
        tb_SlabAdditional.CssClass = "form-control";
        tc_CessPercent.Controls.Add(tb_SlabAdditional);
        tr.Cells.Add(tc_CessPercent);

        TableCell tc_deletebtn = new TableCell();
        tc_deletebtn.ID = "tc_delete_btn_" + rowId;
        tc_deletebtn.HorizontalAlign = HorizontalAlign.Center;
        tc_deletebtn.Width = Unit.Percentage(0.9);
        Button btnDelete = new Button();
        btnDelete.ID = "tds_SlabDelete_" + rowId;
        btnDelete.Text = "-";
        btnDelete.CommandName = "Delete";
        btnDelete.CommandArgument = rowId.ToString();
        btnDelete.Click += new EventHandler(btnDelete_Click);
        tc_deletebtn.Controls.Add(btnDelete);
        tr.Cells.Add(tc_deletebtn);



        tbl_TdsSlab.Rows.Add(tr);

        hdnTaxPolicyCount.Value = Convert.ToString(rowId);

        Session["SlabCount"] = rowId;


        Button btnPrviousdelete = (Button)tbl_TdsSlab.Rows[rowId - 1].FindControl("tds_SlabDelete_" + (rowId - 1));
        btnPrviousdelete.Visible = false;

    }

    //Tds Slab Delete Button
    private void btnDelete_Click(object sender, EventArgs e)
    {
        Button delbtn = (Button)sender;
        int thisRow = Convert.ToInt32(delbtn.CommandArgument);
        TableRow tr = new TableRow();

        tr.ID = "tr_" + thisRow;

        tbl_TdsSlab.Rows.Remove(tbl_TdsSlab.Rows[thisRow]);

        hdnTaxPolicyCount.Value = Convert.ToString(tbl_TdsSlab.Rows.Count - 1);

        Session["SlabCount"] = tbl_TdsSlab.Rows.Count - 1;

        if (thisRow - 1 != 3)
        {
            TableCell tc_cell = (TableCell)tbl_TdsSlab.Rows[thisRow - 1].FindControl("tc_delete_btn_" + (thisRow - 1));
            tc_cell.Width = Unit.Percentage(0.9);
            Button btndelete = (Button)tbl_TdsSlab.Rows[thisRow - 1].FindControl("tds_SlabDelete_" + (thisRow - 1));
            btndelete.Visible = true;
            tc_cell.Controls.Add(btndelete);
        }
        

 

    }
    private void DynamicProfessionalSlabCreate(object v)
    {

        tbl_ProfessSlab.ID = "tbl_ProfSlab";
        tbl_ProfessSlab.CssClass = "Col-md-12";

        TableHeaderRow hr = new TableHeaderRow();
        hr.CssClass = "row form-group col-md-12";

        TableHeaderCell hc_slabName = new TableHeaderCell();
        hc_slabName.CssClass = "col-md-2 lvepo-tblHeader";
        hc_slabName.VerticalAlign = VerticalAlign.Top;
        hc_slabName.HorizontalAlign = HorizontalAlign.Center;
        hc_slabName.Width = Unit.Percentage(0.3);
        hc_slabName.Text = "Tax Slab No";
        hc_slabName.Visible = false;
        hr.Cells.Add(hc_slabName);

        TableHeaderCell hc_RangeFrom = new TableHeaderCell();
        hc_RangeFrom.CssClass = "col-md-2 lvepo-tblHeader";
        hc_RangeFrom.VerticalAlign = VerticalAlign.Top;
        hc_RangeFrom.HorizontalAlign = HorizontalAlign.Center;
        hc_RangeFrom.Style.Add("Position", "relative");
        hc_RangeFrom.Style.Add("left", "120px");
        hc_RangeFrom.Width = Unit.Percentage(1);
        hc_RangeFrom.Text = "Range From";
        hr.Cells.Add(hc_RangeFrom);

        TableHeaderCell hc_RangeTo = new TableHeaderCell();
        hc_RangeTo.CssClass = "col-md-2 lvepo-tblHeader";
        hc_RangeTo.VerticalAlign = VerticalAlign.Top;
        hc_RangeTo.HorizontalAlign = HorizontalAlign.Center;
        hc_RangeTo.Style.Add("Position", "relative");
        hc_RangeTo.Style.Add("left", "65px");
        hc_RangeTo.Width = Unit.Percentage(1);
        hc_RangeTo.Text = "Range To";
        hr.Cells.Add(hc_RangeTo);

        TableHeaderCell hc_TdsPercent = new TableHeaderCell();
        hc_TdsPercent.CssClass = "col-md-2 lvepo-tblHeader";
        hc_TdsPercent.VerticalAlign = VerticalAlign.Top;
        hc_TdsPercent.HorizontalAlign = HorizontalAlign.Center;
        hc_TdsPercent.Style.Add("Position", "relative");
        hc_TdsPercent.Style.Add("left", "55px");
        hc_TdsPercent.Width = Unit.Percentage(1);
        hc_TdsPercent.Text = "Professional Tax";
        hr.Cells.Add(hc_TdsPercent);

        TableHeaderCell hc_ProfPercent = new TableHeaderCell();
        hc_ProfPercent.CssClass = "col-md-2 lvepo-tblHeader";
        hc_ProfPercent.VerticalAlign = VerticalAlign.Top;
        hc_ProfPercent.HorizontalAlign = HorizontalAlign.Left;
        hc_ProfPercent.Style.Add("Position", "relative");
        hc_ProfPercent.Style.Add("left", "55px");
        hc_ProfPercent.Width = Unit.Percentage(0.5);

        hr.Cells.Add(hc_ProfPercent);

        tbl_ProfessSlab.Rows.Add(hr);

        int id = Convert.ToInt32(v);

        for (int i = 1; i <= id; i++)
        {
            TableRow tr = new TableRow();
            tr.ID = "tr_Prof_" + i;
            tr.CssClass = "row form-group col-md-12";

            TableCell tc_Slab = new TableCell();
            tc_Slab.CssClass = "col-md-2";

            tc_Slab.HorizontalAlign = HorizontalAlign.Left;
            tc_Slab.Width = Unit.Percentage(0.4);
            Label lbl_Slab = new Label();
            lbl_Slab.ID = "lbl_ProfSlab" + i;
            lbl_Slab.Text = "Professional Slab" + i;

            tc_Slab.Controls.Add(lbl_Slab);
            tr.Cells.Add(tc_Slab);


            TableCell tc_RangeFrom = new TableCell();
            tc_RangeFrom.CssClass = "col-md-2 ";
            tc_RangeFrom.HorizontalAlign = HorizontalAlign.Center;
            tc_RangeFrom.Width = Unit.Percentage(1);
            TextBox tb_SlabFrom = new TextBox();
            tb_SlabFrom.ID = "txt_ProfRangeFrom_" + i;
            tb_SlabFrom.Attributes.Add("onkeypress", "return OnlyNumberValuewithzero(event,this);");
            tb_SlabFrom.Attributes.Add("onpaste", "return false;");
            tb_SlabFrom.Attributes.Add("ondrop", "return false;");
            tb_SlabFrom.Attributes.Add("runnat", "Server");
            tb_SlabFrom.Attributes.Add("Placeholder", " ₹ INR");
            tb_SlabFrom.MaxLength = 12;
            tb_SlabFrom.CssClass = "form-control ";
            tc_RangeFrom.Controls.Add(tb_SlabFrom);
            tr.Cells.Add(tc_RangeFrom);


            TableCell tc_RangeTO = new TableCell();
            tc_RangeTO.CssClass = "col-md-2";
            tc_RangeTO.HorizontalAlign = HorizontalAlign.Center;
            tc_RangeTO.Width = Unit.Percentage(1);
            TextBox tb_SlabTO = new TextBox();
            tb_SlabTO.ID = "txt_ProfRangeTo_" + i;
            tb_SlabTO.Attributes.Add("onkeypress", "return onlyNumbersValue(event,this);");
            tb_SlabTO.Attributes.Add("onpaste", "return false;");
            tb_SlabTO.Attributes.Add("ondrop", "return false;");
            tb_SlabTO.Attributes.Add("runnat", "Server");
            tb_SlabTO.Attributes.Add("Placeholder", " ₹ INR");
            tb_SlabTO.MaxLength = 12;
            tb_SlabTO.CssClass = "form-control";

            tc_RangeTO.Controls.Add(tb_SlabTO);

            tr.Cells.Add(tc_RangeTO);

            TableCell tc_ProfTax = new TableCell();
            tc_ProfTax.ID = "tc_ProfAmount_" + i;
            tc_ProfTax.CssClass = "col-md-2";
            tc_ProfTax.HorizontalAlign = HorizontalAlign.Center;
            tc_ProfTax.Width = Unit.Percentage(1);

            TextBox tb_ProfAmount = new TextBox();
            tb_ProfAmount.ID = "txt_ProfTaxAmount_" + i;
            tb_ProfAmount.Attributes.Add("onkeypress", "return OnlyNumberValuewithzero(event,this);");
            tb_ProfAmount.Attributes.Add("onpaste", "return false;");
            tb_ProfAmount.Attributes.Add("ondrop", "return false;");
            tb_ProfAmount.Attributes.Add("Placeholder", " ₹ INR");
            tb_ProfAmount.MaxLength = 5;
            tb_ProfAmount.CssClass = "form-control ";
            tb_ProfAmount.Visible = true;
            tc_ProfTax.Controls.Add(tb_ProfAmount);
            tc_ProfTax.Visible = true;
            tr.Cells.Add(tc_ProfTax);

            TableCell tc_ProfTaxPercentage = new TableCell();
            tc_ProfTaxPercentage.ID = "tc_ProfTaxPercentage_" + i;
            tc_ProfTaxPercentage.CssClass = "col-md-2";
            tc_ProfTaxPercentage.HorizontalAlign = HorizontalAlign.Center;
            tc_ProfTaxPercentage.Width = Unit.Percentage(1);

            TextBox tb_ProfPercent = new TextBox();
            tb_ProfPercent.ID = "txt_ProfTaxPercentage_" + i;
            tb_ProfPercent.Attributes.Add("onkeypress", "return number_dot(event,this);");
            tb_ProfPercent.Attributes.Add("onpaste", "return false;");
            tb_ProfPercent.Attributes.Add("ondrop", "return false;");
            tb_ProfPercent.Attributes.Add("Placeholder", " % ");
            tb_ProfPercent.MaxLength = 5;
            tb_ProfPercent.CssClass = "form-control ";
            tb_ProfPercent.Visible = true;
            tc_ProfTaxPercentage.Controls.Add(tb_ProfPercent);
            tr.Controls.Add(tc_ProfTaxPercentage);
            tc_ProfTaxPercentage.Visible = false;


            TableCell tc_deletebtn = new TableCell();
            tc_deletebtn.ID = "tc_Prodelete_btn_" + i;
            tc_deletebtn.HorizontalAlign = HorizontalAlign.Center;
            tc_deletebtn.Width = Unit.Percentage(0.5);
            Button btnDelete = new Button();
            btnDelete.ID = "Prof_SlabDelete_" + i;
            btnDelete.Text = "-";
            btnDelete.CommandName = "Delete";
            btnDelete.CommandArgument = i.ToString();
            btnDelete.Click += new EventHandler(btnDeleteProf_Click);
            tc_deletebtn.Controls.Add(btnDelete);
            tr.Cells.Add(tc_deletebtn);


            int count = Convert.ToInt32(Session["ProfSlabCount"]);

            if (i == count && i != 3)
            {
                tc_deletebtn.Width = Unit.Percentage(0.7);
                btnDelete.Visible = true;
            }
            else
            {
                btnDelete.Visible = false;
            }

            tbl_ProfessSlab.Rows.Add(tr);

            hdnProfPolicyCount.Value = Convert.ToString(i);


        }
    }

    protected void btn_ProfessAddSlab_Click(object sender, EventArgs e)
    {

        int rowId;
        rowId = Convert.ToInt32(Session["ProfSlabCount"]);
        rowId = rowId + 1;


        TableRow tr = new TableRow();
        tr.ID = "tr_Prof_" + rowId;
        tr.CssClass = "row form-group col-sm-12";

        TableCell tc_Slab = new TableCell();
        tc_Slab.CssClass = "col-md-2";

        tc_Slab.HorizontalAlign = HorizontalAlign.Left;
        tc_Slab.Width = Unit.Percentage(0.3);
        Label lbl_Slab = new Label();
        lbl_Slab.ID = "lbl_ProfSlab" + rowId;
        lbl_Slab.Text = "Professional Slab" + rowId;

        tc_Slab.Controls.Add(lbl_Slab);
        tr.Cells.Add(tc_Slab);


        TableCell tc_RangeFrom = new TableCell();
        tc_RangeFrom.CssClass = "col-md-2";
        tc_RangeFrom.HorizontalAlign = HorizontalAlign.Center;
        tc_RangeFrom.Width = Unit.Percentage(1);
        TextBox tb_SlabFrom = new TextBox();
        tb_SlabFrom.ID = "txt_ProfRangeFrom_" + rowId;
        tb_SlabFrom.Attributes.Add("onkeypress", "return onlyNumbersValue(event,this);");
        tb_SlabFrom.Attributes.Add("onkeyup", "PreventFirstZero(event)");
        tb_SlabFrom.Attributes.Add("onpaste", "return false;");
        tb_SlabFrom.Attributes.Add("ondrop", "return false;");
        tb_SlabFrom.Attributes.Add("runnat", "Server");
        tb_SlabFrom.Attributes.Add("Placeholder", " ₹ INR");
        tb_SlabFrom.MaxLength = 12;
        tb_SlabFrom.CssClass = "form-control ";
        tc_RangeFrom.Controls.Add(tb_SlabFrom);
        tr.Cells.Add(tc_RangeFrom);


        TableCell tc_RangeTO = new TableCell();
        tc_RangeTO.CssClass = "col-md-2";
        tc_RangeTO.HorizontalAlign = HorizontalAlign.Center;
        tc_RangeTO.Width = Unit.Percentage(1);
        TextBox tb_SlabTO = new TextBox();
        tb_SlabTO.ID = "txt_ProfRangeTo_" + rowId;
        tb_SlabTO.Attributes.Add("onkeypress", "return onlyNumbersValue(event,this);");
        tb_SlabTO.Attributes.Add("onpaste", "return false;");
        tb_SlabTO.Attributes.Add("ondrop", "return false;");
        tb_SlabTO.Attributes.Add("runnat", "Server");
        tb_SlabTO.Attributes.Add("Placeholder", " ₹ INR");
        tb_SlabTO.MaxLength = 12;
        tb_SlabTO.CssClass = "form-control";
        tc_RangeTO.Controls.Add(tb_SlabTO);
        tr.Cells.Add(tc_RangeTO);

        TableCell tc_ProfTax = new TableCell();
        tc_ProfTax.ID = "tc_ProfAmount_" + rowId;
        tc_ProfTax.CssClass = "col-md-2";
        tc_ProfTax.HorizontalAlign = HorizontalAlign.Center;
        tc_ProfTax.Width = Unit.Percentage(1);

        TextBox tb_ProfAmount = new TextBox();
        tb_ProfAmount.ID = "txt_ProfTaxAmount_" + rowId;
        tb_ProfAmount.Attributes.Add("onkeypress", "return onlyNumbersValue(event,this);");
        tb_ProfAmount.Attributes.Add("onpaste", "return false;");
        tb_ProfAmount.Attributes.Add("ondrop", "return false;");
        tb_ProfAmount.Attributes.Add("Placeholder", " ₹ INR");
        tb_ProfAmount.MaxLength = 5;
        tb_ProfAmount.CssClass = "form-control ";
        tb_ProfAmount.Visible = true;
        tc_ProfTax.Controls.Add(tb_ProfAmount);
        tc_ProfTax.Visible = true;
        tr.Cells.Add(tc_ProfTax);

        TableCell tc_ProfTaxPercentage = new TableCell();
        tc_ProfTaxPercentage.ID = "tc_ProfTaxPercentage_" + rowId;
        tc_ProfTaxPercentage.CssClass = "col-md-2";
        tc_ProfTaxPercentage.HorizontalAlign = HorizontalAlign.Center;
        tc_ProfTaxPercentage.Width = Unit.Percentage(1);
        TextBox tb_ProfPercent = new TextBox();
        tb_ProfPercent.ID = "txt_ProfTaxPercentage_" + rowId;
        tb_ProfPercent.Attributes.Add("onkeypress", "return number_dot(event,this);");
        tb_ProfPercent.Attributes.Add("onpaste", "return false;");
        tb_ProfPercent.Attributes.Add("ondrop", "return false;");
        tb_ProfPercent.Attributes.Add("Placeholder", " % ");
        tb_ProfPercent.MaxLength = 5;
        tb_ProfPercent.CssClass = "form-control ";
        tb_ProfPercent.Visible = true;
        tc_ProfTaxPercentage.Controls.Add(tb_ProfPercent);
        tr.Controls.Add(tc_ProfTaxPercentage);
        tc_ProfTaxPercentage.Visible = false;

        if(rbtn_Amount.Checked)
        {
            tc_ProfTax.Visible = true;
            tc_ProfTaxPercentage.Visible = false;
        }
        else
        {
            tc_ProfTax.Visible = false;
            tc_ProfTaxPercentage.Visible = true;
        }
        TableCell tc_deletebtn = new TableCell();
        tc_deletebtn.ID = "tc_Prodelete_btn_" + rowId;
        tc_deletebtn.HorizontalAlign = HorizontalAlign.Center;
        tc_deletebtn.Width = Unit.Percentage(0.4);
        Button btnDelete = new Button();
        btnDelete.ID = "Prof_SlabDelete_" + rowId;
        btnDelete.Text = "-";
        btnDelete.CommandName = "Delete";
        btnDelete.CommandArgument = rowId.ToString();
        btnDelete.Click += new EventHandler(btnDeleteProf_Click);
        tc_deletebtn.Controls.Add(btnDelete);
        tr.Cells.Add(tc_deletebtn);

        tbl_ProfessSlab.Rows.Add(tr);

        hdnProfPolicyCount.Value = Convert.ToString(rowId);

        Session["ProfSlabCount"] = rowId;

        Button btnPrviousdelete = (Button)tbl_ProfessSlab.Rows[rowId - 1].FindControl("Prof_SlabDelete_" + (rowId - 1));
        btnPrviousdelete.Visible = false;
    }



    private void btnDeleteProf_Click(object sender, EventArgs e)
    {
        Button delbtn = (Button)sender;
        int thisRow = Convert.ToInt32(delbtn.CommandArgument);
        TableRow tr = new TableRow();

        tr.ID = "tr_Prof_" + thisRow;

        tbl_ProfessSlab.Rows.Remove(tbl_ProfessSlab.Rows[thisRow]);

        // hdnTaxPolicyCount.Value = Convert.ToString(tbl_ProfessSlab.Rows.Count - 1);

      
            Session["ProfSlabCount"] = tbl_ProfessSlab.Rows.Count - 1;

            if (thisRow - 1 != 3)
            {
                TableCell tc_cell = (TableCell)tbl_ProfessSlab.Rows[thisRow - 1].FindControl("tc_Prodelete_btn_" + (thisRow - 1));
                tc_cell.Width = Unit.Percentage(0.4);
                Button btndelete = (Button)tbl_ProfessSlab.Rows[thisRow - 1].FindControl("Prof_SlabDelete_" + (thisRow - 1));
                btndelete.Visible = true;
                tc_cell.Controls.Add(btndelete);
            }
       
    }

    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(317, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");

        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }

    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);
    }

    private void DropdownTooltip(DropDownList ddl)
    {
        if (ddl != null)
        {
            foreach (ListItem li in ddl.Items)
            {
                li.Attributes["title"] = li.Text;
            }
        }
    }
    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);
            }
        }

    }
    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);
        }
    }

    protected void rbtn_Amount_CheckedChanged(object sender, EventArgs e)
    {
        int rowCount = Convert.ToInt32(Session["ProfSlabCount"]);

        for (int i = 1; i <= rowCount; i++)
        {
            TableCell tc_cell_Prof = (TableCell)tbl_ProfessSlab.Rows[i].FindControl("tc_ProfTaxPercentage_" + i);
            tc_cell_Prof.Width = Unit.Percentage(1);
            tc_cell_Prof.Visible = false;
            TableCell tc_cell_Amount = (TableCell)tbl_ProfessSlab.Rows[i - 1].FindControl("tc_ProfAmount_" + i);
            tc_cell_Amount.Width = Unit.Percentage(1);
            tc_cell_Amount.Visible = true;


        }
        Session["ProfSlabCount"] = tbl_ProfessSlab.Rows.Count - 1;

        int thisRow = Convert.ToInt32(Session["ProfSlabCount"]);


        if (thisRow - 1 >= 3)
        {
            TableCell tc_cell = (TableCell)tbl_ProfessSlab.Rows[thisRow - 1].FindControl("tc_Prodelete_btn_" + (thisRow - 1));
            tc_cell.Width = Unit.Percentage(0.4);
            Button btndelete = (Button)tbl_ProfessSlab.Rows[thisRow - 1].FindControl("Prof_SlabDelete_" + (thisRow - 1));
            btndelete.Visible = true;
            tc_cell.Controls.Add(btndelete);
        }

    }

    protected void rbtn_Percentage_CheckedChanged(object sender, EventArgs e)
    {

        int rowCount = Convert.ToInt32(Session["ProfSlabCount"]);

        for (int i = 1; i <= rowCount; i++)
        {
            TableCell tc_cellAmount = (TableCell)tbl_ProfessSlab.Rows[i].FindControl("tc_ProfAmount_" + i);
            tc_cellAmount.Visible = false;

            TableCell tc_cell_Prof = (TableCell)tbl_ProfessSlab.Rows[i].FindControl("tc_ProfTaxPercentage_" + i);
            tc_cell_Prof.Width = Unit.Percentage(1);
            tc_cell_Prof.Visible = true;

        }

        Session["ProfSlabCount"] = tbl_ProfessSlab.Rows.Count - 1;

        int thisRow = Convert.ToInt32(Session["ProfSlabCount"]);


        if (thisRow != 3)
        {
            TableCell tc_cell = (TableCell)tbl_ProfessSlab.Rows[thisRow].FindControl("tc_Prodelete_btn_" + (thisRow));
            tc_cell.Width = Unit.Percentage(0.4);
            Button btndelete = (Button)tbl_ProfessSlab.Rows[thisRow].FindControl("Prof_SlabDelete_" + (thisRow));
            btndelete.Visible = true;
            tc_cell.Controls.Add(btndelete);
        }
    }
}