Sunday, 31 March 2013

dynamic

using table





<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Inventory_DynamicTab.aspx.cs" Inherits="Website.ERP.AMS.Inventory_DynamicTab" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>


<%--    <script language="javascript" type="text/javascript">
        debugger

         
//        function callFunction(val) {
//            $("#DropDownList" + val).val(val);
//        }
 

        $(document).ready(function () {
            $("#DropDownList").click(function (event) {
                alert(event.target.id);
                                    });


//            $("input").mouseenter(function (e) {
//                e.stopPropagation();
//                $id = $(this).attr("id");
//            });

//        });
     
    </script>--%>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
         <asp:TabContainer ID="TabContainer1" runat="server">
         <asp:TabPanel ID="TabGeneral" runat="server">
           <HeaderTemplate>General</HeaderTemplate>
           <ContentTemplate>
             
           </ContentTemplate>
         </asp:TabPanel>
        </asp:TabContainer></ContentTemplate>
        </asp:UpdatePanel>
      
    </div>
    </form>
</body>
</html>
c# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using Swash.BusinessLayer;
using Swash.Frameworks;
using Swash.Objects;
using System.Data;

namespace Website.ERP.AMS
{
    public partial class Inventory_DynamicTab : System.Web.UI.Page
    {
        TabPanel pnl;
        Table tbl;
        TableRow tbr;
        TableCell tcl;
        Button objButton;
        Button objButtonReset;
        Button objButtonSelect;
        DropDownList objDDL;
        ComboBox objCmb;
        Label objLavel;
        TextBox objTextBox;
        CalendarExtender objCalender;
        FilteredTextBoxExtender objFilter;
        CascadingDropDown objCDD;
        DataTable dt;
        RequiredFieldValidator rfv;
        ValidationSummary vs;
        static string Id1 = string.Empty;


        static string nm;

        void fillTabname()
        {
            try
            {

                var lnqParameter = (from Item in ERPManagement.GetInstance.GetTabSequence()
                                    orderby Item.Sequence
                                    select Item.TabName).Distinct();
                if (lnqParameter.ToArray().Length > 0)
                {
                    for (int i = 0; i < lnqParameter.ToList().Count; i++)
                    {

                        pnl = new TabPanel();
                        pnl.HeaderText = lnqParameter.ToList()[i].ToString();
                        pnl.ID = (i).ToString();
                        TabContainer1.Tabs.Add(pnl);


                        tbl = new Table();
                        tbl.BorderColor = System.Drawing.Color.Black;
                        tbl.ID = i.ToString();

                        TabContainer1.Tabs[i + 1].Controls.Add(tbl);

                        //// table
                        var lnqParameterCount = from Item in ERPManagement.GetInstance.GetSequence()
                                                orderby Item.Sequence
                                                where Item.TabName == pnl.HeaderText && Item.Multiple_Rows == false
                                                select new
                                                {
                                                    fieldId = Item.Field_ID,
                                                    fieldNm = Item.FieldName,
                                                    fieldNm_Id = Item.Field_Name_ID,
                                                    fieldType = Item.Control_type,
                                                    multipleRow = Item.Multiple_Rows,
                                                    sequence = Item.Sequence,
                                                    maxlength = Item.Max_Length,
                                                    compulsary = Item.Is_Compulsory,
                                                    datatype = Item.Datatype
                                                };
                        if (lnqParameterCount.ToList().Count > 0)
                        {

                            for (int j = 0; j < lnqParameterCount.ToList().Count; j++)
                            {

                                objLavel = new Label();
                                objTextBox = new TextBox();
                                objButton = new Button();


                                if (j <= 6)
                                {
                                    if (lnqParameterCount.ToList()[j].fieldType == "TextBox" && lnqParameterCount.ToList()[j].multipleRow == false)
                                    {

                                        //________________________
                                        objLavel.ID = lnqParameterCount.ToList()[j].fieldId.ToString() + "_" + "Lbl" + lnqParameterCount.ToList()[j].fieldNm_Id.ToString() + "_" + pnl.ID + "_" + lnqParameterCount.ToList()[j].compulsary.ToString() + "_" + lnqParameterCount.ToList()[j].datatype.ToString();
                                        objLavel.Text = lnqParameterCount.ToList()[j].fieldNm.ToString() + " :";
                                        objLavel.Width = 90;
                                        objLavel.Height = 15;
                                        objLavel.Font.Size = FontUnit.Smaller;
                                        //_____________________________
                                        Id1 = lnqParameterCount.ToList()[j].fieldId.ToString() + "_" + "Txt" + lnqParameterCount.ToList()[j].fieldNm_Id.ToString() + "_" + pnl.ID + "_" + lnqParameterCount.ToList()[j].compulsary.ToString() + "_" + lnqParameterCount.ToList()[j].datatype.ToString();
                                        objTextBox.ID = lnqParameterCount.ToList()[j].fieldId.ToString() + "_" + "Txt" + lnqParameterCount.ToList()[j].fieldNm_Id.ToString() + "_" + pnl.ID + "_" + lnqParameterCount.ToList()[j].compulsary.ToString() + "_" + lnqParameterCount.ToList()[j].datatype.ToString();
                                        objTextBox.Width = 120;
                                        objTextBox.Height = 15;
                                        objTextBox.MaxLength = int.Parse(lnqParameterCount.ToList()[j].maxlength.ToString());

                                        objTextBox.AutoPostBack = true;
                                        objTextBox.TextChanged += new EventHandler(objTextBox_TextChanged);


                                        tcl = new TableCell();
                                        tcl.ID = "TCL" + lnqParameterCount.ToList()[j].fieldId.ToString();
                                        tcl.Controls.Add(objLavel);
                                        tcl.Controls.Add(objTextBox);


                                        //string Id = objTextBox.ID;
                                        //string[] IDS = Id.Split('_');
                                        //if (IDS[4] == "Decimal")
                                        //{
                                        //    objFilter = new FilteredTextBoxExtender();
                                        //    if (objTextBox.ID != null)
                                        //        objFilter.ID = "Ftl" + lnqParameterCount.ToList()[j].fieldId.ToString();
                                        //    //objFilter.TargetControlID = Id1;
                                        //    //    objFilter.FilterType = FilterTypes.Numbers;
                                        //    objFilter.ValidChars = "1,2,3,4,5,6,7,8,9,0";
                                        //    //   objFilter.Enabled = true;
                                        //}


                                        //tcl.Controls.Add(objFilter);





                                        tbr = new TableRow();
                                        tbr.ID = "TBR" + lnqParameterCount.ToList()[j].fieldId.ToString();
                                        tbr.Cells.Add(tcl);
                                        tbr.BackColor = System.Drawing.Color.Cyan;
                                        tbr.Width = 100;
                                        tbr.BorderWidth = 5;
                                        tbl.Rows.Add(tbr);


                                    }
                                    else if (lnqParameterCount.ToList()[j].fieldType == "Dropdown" && lnqParameterCount.ToList()[j].multipleRow == false)
                                    {
                                        objLavel.ID = "Lbl" + lnqParameterCount.ToList()[j].fieldNm.ToString();
                                        objLavel.Text = lnqParameterCount.ToList()[j].fieldNm.ToString() + " :";
                                        objLavel.Width = 90;
                                        objLavel.Height = 15;
                                        objLavel.Font.Size = FontUnit.Smaller;
                                        //________________________                               
                                        //objComboBox = new ComboBox();
                                        objDDL = new DropDownList();
                                        objDDL.ID = lnqParameterCount.ToList()[j].fieldId.ToString() + "_" + "Cmb" + lnqParameterCount.ToList()[j].fieldNm_Id.ToString() + "_" + pnl.ID + "_" + lnqParameterCount.ToList()[j].compulsary.ToString() + "_" + lnqParameterCount.ToList()[j].datatype.ToString();
                                        objDDL.Width = 120;
                                        objDDL.Height = 20;
                                        objDDL.AutoPostBack = true;
                                        objDDL.SelectedIndexChanged += new EventHandler(objDDL_SelectedIndexChanged);
                                        //E-Mart Show Room & Ipsar-Cpe(First Floor) Ca Center , Accredited By Icai

                                        tcl = new TableCell();
                                        tcl.Controls.Add(objLavel);
                                        tcl.Controls.Add(objDDL);


                                        tbr = new TableRow();
                                        tbr.Cells.Add(tcl);
                                        tbr.BackColor = System.Drawing.Color.Cyan;
                                        tbr.Width = 100;
                                        tbr.BorderWidth = 5;
                                        tbl.Rows.Add(tbr);


                                        var getCmbData = from data in ERPManagement.GetInstance.GetSequenceDetails()
                                                         where data.ParameterID == int.Parse(lnqParameterCount.ToList()[j].fieldId.ToString()) && data.Reference_Parameter_ID == 0
                                                         select data;

                                        if (getCmbData.ToList().Count > 0)
                                        {

                                            List<TAGGING_Property> colors = new List<TAGGING_Property>();
                                            TAGGING_Property objcol = new TAGGING_Property();
                                            objcol.Data_Value = "Field_ID";
                                            objcol.Data_Display = "Select";
                                            colors.Add(objcol);
                                            foreach (TAGGING_Property country in getCmbData.ToList())
                                            {
                                                colors.Add(country);
                                            }
                                            string idd = objDDL.ID.ToString();
                                            objDDL.DataSource = colors;
                                            objDDL.DataTextField = "Data_Display";
                                            objDDL.DataValueField = "Field_ID";
                                            objDDL.DataBind();
                                            objDDL.SelectedIndex = 0;
                                        }
                                    }
                                    else if (lnqParameterCount.ToList()[j].fieldType == "Calender" && lnqParameterCount.ToList()[j].multipleRow == false)
                                    {
                                        objCalender = new CalendarExtender();
                                        //________________________
                                        objLavel.ID = "Lbl" + lnqParameterCount.ToList()[j].fieldNm.ToString();
                                        objLavel.Text = lnqParameterCount.ToList()[j].fieldNm.ToString() + " :";
                                        objLavel.Width = 90;
                                        objLavel.Height = 15;
                                        objLavel.Font.Size = FontUnit.Smaller;
                                        //_____________________________

                                        objTextBox.ID = lnqParameterCount.ToList()[j].fieldId.ToString() + "_" + "Txt" + lnqParameterCount.ToList()[j].fieldNm_Id.ToString() + "_" + pnl.ID + "_" + lnqParameterCount.ToList()[j].compulsary.ToString() + "_" + lnqParameterCount.ToList()[j].datatype.ToString();
                                        objTextBox.Width = 120;
                                        objTextBox.Height = 15;
                                        objTextBox.MaxLength = int.Parse(lnqParameterCount.ToList()[j].maxlength.ToString());
                                        objCalender.ID = "Cal" + lnqParameterCount.ToList()[j].fieldId.ToString();
                                        objCalender.TargetControlID = objTextBox.ID;
                                        objCalender.Format = "dd/MM/yyyy";

                                        tcl = new TableCell();
                                        tcl.Controls.Add(objLavel);
                                        tcl.Controls.Add(objTextBox);
                                        tcl.Controls.Add(objCalender);

                                        tbr = new TableRow();
                                        tbr.Cells.Add(tcl);
                                        tbr.BackColor = System.Drawing.Color.Cyan;
                                        tbr.Width = 100;
                                        tbr.BorderWidth = 5;
                                        tbl.Rows.Add(tbr);
                                    }
                                }

                            }
                        }

                        objButton = new Button();
                        objButton.Text = "Save";
                        objButton.ID = pnl.ID + objButton.Text;
                        objButton.Width = 80;
                        objButton.Height = 25;
                        objButton.Click += new EventHandler(objButton_Click);
                        pnl.Controls.Add(objButton);

                        objButtonReset = new Button();
                        objButtonReset.Text = "Reset";
                        objButtonReset.ID = pnl.ID + objButtonReset.Text;
                        objButtonReset.Width = 80;
                        objButtonReset.Height = 25;
                        objButtonReset.Click += new EventHandler(objButtonReset_Click);
                        pnl.Controls.Add(objButtonReset);

                        objButtonSelect = new Button();
                        objButtonSelect.Text = "Select";
                        objButtonSelect.ID = pnl.ID + objButtonSelect.Text;
                        objButtonSelect.Width = 80;
                        objButtonSelect.Height = 25;
                        objButtonSelect.Click += new EventHandler(objButtonSelect_Click);
                        pnl.Controls.Add(objButtonSelect);




                    }
                }
                //   SetAjax();
            }
            catch (Exception ex)
            {
                string x = ex.Message.ToString();
            }
        }


        void Save()
        {
            if (CheckValid() == true)
            {
                string x = "", y = "";
                dt.Clear();
                d_Tagging_ItemCustomizeData objIC = new d_Tagging_ItemCustomizeData();
                //if (GridViewItems.Visible == true)
                //{
                objIC.Item_ID = TAGGING_Item.Item_ID_Global;
                objIC.Variation_Or_Item = true;

                AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabContainer1;
                if (container.ActiveTabIndex > 0)
                {
                    foreach (object obj in container.ActiveTab.Controls)
                    {
                        if (obj is Control)
                        {
                            Control c = (Control)obj;
                            if (c is System.Web.UI.WebControls.Table)
                            {
                                Table tbl = c as Table;
                                foreach (object rw in tbl.Rows)
                                {
                                    TableRow tbr = rw as TableRow;
                                    foreach (object cl in tbr.Cells)
                                    {
                                        TableCell tcl = cl as TableCell;
                                        foreach (object ctl in tcl.Controls)
                                        {

                                            if (ctl is System.Web.UI.WebControls.TextBox)
                                            {
                                                TextBox txt = ctl as TextBox;
                                                x = txt.ID;
                                                string[] words = x.Split('_');
                                                dt.Rows.Add(new Object[] { TAGGING_Item.Item_ID_Global, true, words[0], txt.Text, 1, txt.ID, container.ActiveTab.HeaderText });
                                                dt.AcceptChanges();
                                            }
                                            else if (ctl is System.Web.UI.WebControls.DropDownList)
                                            {
                                                DropDownList ddl = ctl as DropDownList;
                                                x = ddl.ID;
                                                string[] words = x.Split('_');
                                                dt.Rows.Add(new Object[] { TAGGING_Item.Item_ID_Global, true, words[0], ddl.SelectedValue, 1, ddl.ID, container.ActiveTab.HeaderText });
                                                dt.AcceptChanges();
                                            }

                                        }

                                    }
                                }

                            }
                        }

                    }
                }









                // }
                //else if (DataGridItemVariation.Visible == true)
                //{
                //    objIC.Item_ID = TAGGING_Item.Variation_ID_Global;
                //    objIC.Variation_Or_Item = false;
                //    foreach (Control ctl in TabItem.SelectedTab.Controls)
                //    {
                //        if (ctl is TextBox)
                //        {
                //            x = ctl.Name;
                //            string[] words = x.Split('_');
                //            dt.Rows.Add(new Object[] { TAGGING_Item.Variation_ID_Global, false, words[0], ctl.Text, 1, ctl.Name });
                //            dt.AcceptChanges();

                //        }
                //        else if (ctl is ComboBox)
                //        {
                //            ComboBox cmb = ctl as ComboBox;
                //            x = ctl.Name;
                //            string[] words = x.Split('_');
                //            dt.Rows.Add(new Object[] { TAGGING_Item.Variation_ID_Global, false, words[0], cmb.SelectedValue, 1, ctl.Name });
                //            dt.AcceptChanges();

                //        }
                //        else if (ctl is DateTimePicker)
                //        {
                //            DateTimePicker dtp = ctl as DateTimePicker;
                //            x = ctl.Name;
                //            string[] words = x.Split('_');
                //            dt.Rows.Add(new Object[] { TAGGING_Item.Variation_ID_Global, false, words[0], dtp.Value, 1, ctl.Name });
                //            dt.AcceptChanges();

                //        }
                //    }
                //}


                objIC.DataTableItemCustomised = dt;
                ERPManagement.GetInstance.InsertItemCustomiseData(objIC);
                objLavel = new Label();
                objLavel.ID = "lblMessage";
                objLavel.Text = "Data Inserted Successfully.";
                container.ActiveTab.Controls.Add(objLavel);

                //if (InsertUpdateFlag == 0)
                //{

                //   // InsertUpdateFlag = 0;
                //}
                //else
                //{

                //   // InsertUpdateFlag = 0;
                //}
                RefreshDynamicTab();
            }
        }
        bool CheckValid()
        {
            string x = "";
            AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabContainer1;
            //if (TAGGING_Item.Item_ID_Global == 0)
            //{
            //    //MessageBox.Show("Please select an item to save data.");
            //    //return false;
            //}
            //else
            if (container.ActiveTabIndex > 0)
            {

                foreach (object obj in container.ActiveTab.Controls)
                {
                    if (obj is Control)
                    {
                        Control c = (Control)obj;
                        if (c is System.Web.UI.WebControls.Table)
                        {
                            Table tbl = c as Table;
                            foreach (object rw in tbl.Rows)
                            {
                                TableRow tbr = rw as TableRow;
                                foreach (object cl in tbr.Cells)
                                {
                                    TableCell tcl = cl as TableCell;
                                    foreach (object ctl in tcl.Controls)
                                    {

                                        if (ctl is System.Web.UI.WebControls.TextBox)
                                        {
                                            TextBox txt = ctl as TextBox;
                                            x = txt.ID;
                                            string[] words = x.Split('_');
                                            if (words[3] == "True")
                                            {
                                                if (txt.Text == "")
                                                {
                                                    objLavel = new Label();
                                                    objLavel.ID = "lblMessage";
                                                    objLavel.Text = words[1].Substring(3, words[1].Length - 3) + " can not be blank.";
                                                    container.ActiveTab.Controls.Add(objLavel);
                                                    // rfv = new RequiredFieldValidator();
                                                    // rfv.ID = "rfvMessage" + txt.ID;
                                                    // rfv.ControlToValidate = txt.ID;
                                                    // rfv.ValidationGroup = "satya";
                                                    //  rfv.ErrorMessage = words[1].Substring(3, words[1].Length - 3) + " can not be blank.";
                                                    //container.ActiveTab.Controls.Add(rfv);
                                                    // ScriptManager.RegisterStartupScript("<script>alert('" + words[1].Substring(3, words[1].Length - 3) + " can not be blank.')</script>");
                                                    //Response.Write("<script>alert(" + words[1].Substring(3, words[1].Length - 3) + " ' can not be blank.')</script>");
                                                    return false;
                                                }
                                            }
                                        }
                                        else if (ctl is System.Web.UI.WebControls.DropDownList)
                                        {
                                            DropDownList ddl = ctl as DropDownList;
                                            x = ddl.ID;
                                            string[] words = x.Split('_');
                                            if (words[3] == "True")
                                            {
                                                if (ddl.SelectedIndex == 0)
                                                {
                                                    objLavel = new Label();
                                                    objLavel.ID = "lblMessage";
                                                    objLavel.Text = "Please select " + words[1].Substring(3, words[1].Length - 3) + ".";
                                                    container.ActiveTab.Controls.Add(objLavel);
                                                    //rfv = new RequiredFieldValidator();
                                                    //rfv.ID = "rfvMessage" + ddl.ID;
                                                    //rfv.ControlToValidate = ddl.ID;
                                                    //rfv.ValidationGroup = "satya";
                                                    //rfv.ErrorMessage = "Please select " + words[1].Substring(3, words[1].Length - 3) + ".";
                                                    //container.ActiveTab.Controls.Add(rfv);
                                                    //  Response.Write("<script>alert('Please select  " + words[1].Substring(3, words[1].Length - 3) + ".')</script>");
                                                    return false;
                                                }
                                            }

                                        }

                                    }

                                }
                            }

                        }
                    }

                }
                //  vs= new ValidationSummary();
                //  vs.ID = "vss";
                //  vs.ShowMessageBox = true;
                //  vs.ShowSummary = false;
                //  vs.ValidationGroup = "satya";
                ////  vs.Controls.Add(rfv);
                //  container.ActiveTab.Controls.Add(vs);


            }

            return true;
        }
        private void CreateDataTable()
        {
            try
            {
                dt = new DataTable();
                dt.Columns.Add("Item_ID", typeof(int));
                dt.Columns.Add("Variation_Or_Item", typeof(Boolean));
                dt.Columns.Add("Field_ID", typeof(int));
                dt.Columns.Add("Data", typeof(string));
                dt.Columns.Add("Created_By", typeof(int));
                dt.Columns.Add("ControlName", typeof(string));
                dt.Columns.Add("Tab_Name", typeof(string));
                //Inventory.D_ItemCustomizeDataType
            }
            catch (Exception ex)
            {
            }

        }
        void RefreshDynamicTab()
        {
            AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabContainer1;
            if (container.ActiveTabIndex > 0)
            {
                foreach (object obj in container.ActiveTab.Controls)
                {
                    if (obj is Control)
                    {
                        Control c = (Control)obj;
                        if (c is System.Web.UI.WebControls.Table)
                        {
                            Table tbl = c as Table;
                            foreach (object rw in tbl.Rows)
                            {
                                TableRow tbr = rw as TableRow;
                                foreach (object cl in tbr.Cells)
                                {
                                    TableCell tcl = cl as TableCell;
                                    foreach (object ctl in tcl.Controls)
                                    {

                                        if (ctl is System.Web.UI.WebControls.TextBox)
                                        {
                                            TextBox txt = ctl as TextBox;
                                            txt.Text = "";
                                        }

                                        if (ctl is System.Web.UI.WebControls.DropDownList)
                                        {
                                            DropDownList ddl = ctl as DropDownList;
                                            if (ddl.Items.Count > 0)
                                            {
                                                ddl.SelectedIndex = 0;
                                            }
                                        }

                                    }

                                }
                            }

                        }
                    }

                }
            }
        }
        void SelectButtonHandler()
        {

        }
        private void SetAjax()
        {
            try
            {
                AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabContainer1;

                foreach (object obj in container.Controls)
                {
                    TabPanel pnl = obj as TabPanel;
                    if (pnl.ID != "TabGeneral")
                    {

                        foreach (object objctl in pnl.Controls)
                        {
                            if (objctl is Control)
                            {
                                Control c = (Control)objctl;
                                if (c is System.Web.UI.WebControls.Table)
                                {
                                    Table tbl = c as Table;
                                    foreach (object rw in tbl.Rows)
                                    {
                                        TableRow tbr = rw as TableRow;
                                        foreach (object cl in tbr.Cells)
                                        {
                                            TableCell tcl = cl as TableCell;
                                            foreach (object ctl in tcl.Controls)
                                            {

                                                if (ctl is System.Web.UI.WebControls.TextBox)
                                                {
                                                    TextBox txt = ctl as TextBox;
                                                    string Id = txt.ID;
                                                    string[] IDS = Id.Split('_');
                                                    if (IDS[4] == "Number")
                                                    {
                                                        objFilter = new FilteredTextBoxExtender();


                                                        objFilter.ID = "Ftl" + txt.ID;
                                                        objFilter.TargetControlID = txt.ID;
                                                        objFilter.FilterType = FilterTypes.Numbers;
                                                        objFilter.ValidChars = "1,2,3,4,5,6,7,8,9,0";
                                                        objFilter.Enabled = true;
                                                        pnl.Controls.Add(objFilter);
                                                    }
                                                    else if (IDS[4] == "Decimal")
                                                    {
                                                        objFilter = new FilteredTextBoxExtender();

                                                        objFilter.ID = "Ftl" + txt.ID;
                                                        objFilter.TargetControlID = txt.ID;
                                                        // objFilter.FilterType = FilterTypes.Numbers;
                                                        objFilter.ValidChars = "1,2,3,4,5,6,7,8,9,0,.";
                                                        objFilter.Enabled = true;
                                                        pnl.Controls.Add(objFilter);
                                                    }
                                                }


                                            }
                                        }

                                    }
                                }

                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                string ss = ex.Message.ToString();
            }
        }
        private void SetFocus()
        {
            try
            {
                AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabContainer1;

                foreach (object obj in container.ActiveTab.Controls)
                {
                    if (obj is Control)
                    {
                        Control c = (Control)obj;
                        if (c is System.Web.UI.WebControls.Table)
                        {
                            Table tbl = c as Table;
                            foreach (object rw in tbl.Rows)
                            {
                                TableRow tbr = rw as TableRow;
                                foreach (object cl in tbr.Cells)
                                {
                                    TableCell tcl = cl as TableCell;
                                    foreach (object ctl in tcl.Controls)
                                    {

                                        if (ctl is System.Web.UI.WebControls.TextBox)
                                        {
                                            TextBox txt = ctl as TextBox;
                                            txt.Focus();
                                            return;
                                        }

                                        if (ctl is System.Web.UI.WebControls.DropDownList)
                                        {
                                            DropDownList ddl = ctl as DropDownList;
                                            ddl.Focus();
                                            return;
                                        }

                                    }

                                }
                            }

                        }
                    }


                }
            }
            catch (Exception ex)
            {
                string ss = ex.Message.ToString();
            }
        }



        private void objTextBox_TextChanged(object sender, EventArgs e)
        {
            TextBox tb = (TextBox)sender;
            // string[] s = new string[] { "ABCDEFGHiJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~`!@#$%^&*()_+={}[]:;<>,.?/" };

            string Id = tb.ID;
            string[] IDS = Id.Split('_');
            if (IDS[4] == "Decimal")
            {
                string y = "ABCDEFGHiJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~`!@#$%^&*()_+={}[]:;<>,?/";
                for (int i = 0; i < tb.Text.Length; i++)
                {
                    if (y.IndexOf(tb.Text.ToString().Substring(i, 1)) != -1)
                    {

                        ScriptManager.RegisterStartupScript(this, this.GetType(), "KenCloud", "alert('Enter only decimal !')", true);
                        tb.Text = "";
                        tb.Focus();
                        return;
                    }

                }
            }
            else if (IDS[4] == "Number")
            {
                string y = "ABCDEFGHiJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~`!@#$%^&*()_+={}[]:;<>,.?/";
                for (int i = 0; i < tb.Text.Length; i++)
                {
                    if (y.IndexOf(tb.Text.ToString().Substring(i, 1)) != -1)
                    {

                        ScriptManager.RegisterStartupScript(this, this.GetType(), "KenCloud", "alert('Enter only numbers !')", true);
                        tb.Text = "";
                        tb.Focus();
                        return;
                    }

                }
            }

        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            try
            {

                fillTabname();
                CreateDataTable();
                SetFocus();
            }
            catch (Exception ex)
            {
                string st = ex.Message.ToString();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {


        }

        private void objButton_Click(object sender, EventArgs e)
        {
            Save();
        }

        private void objButtonReset_Click(object sender, EventArgs e)
        {
            RefreshDynamicTab();

        }
        private void objButtonSelect_Click(object sender, EventArgs e)
        {
            // RefreshDynamicTab();
            TabContainer container = (TabContainer)TabContainer1;
            if (container.ActiveTabIndex > 2)
            {
                // InsertUpdateFlag = 1;


                //if (GridViewItems.Visible == true)
                //{

                var getData = from item in ERPManagement.GetInstance.GetAllItemCustomisedData(TAGGING_Item.Item_ID_Global)
                              where item.Tab_Name == container.ActiveTab.HeaderText && item.Variation_Or_Item == true
                              select item;
                if (getData.ToList().Count > 0)
                {
                    for (int g = 0; g < getData.ToList().Count; g++)
                    {

                        foreach (object obj in container.ActiveTab.Controls)
                        {
                            if (obj is Control)
                            {
                                Control c = (Control)obj;
                                if (c is System.Web.UI.WebControls.Table)
                                {
                                    Table tbl = c as Table;
                                    foreach (object rw in tbl.Rows)
                                    {
                                        TableRow tbr = rw as TableRow;
                                        foreach (object cl in tbr.Cells)
                                        {
                                            TableCell tcl = cl as TableCell;
                                            foreach (object ctl in tcl.Controls)
                                            {

                                                if (ctl is System.Web.UI.WebControls.TextBox)
                                                {
                                                    TextBox txt = ctl as TextBox;
                                                    //for (int g = 0; g < getData.ToList().Count; g++)
                                                    //{
                                                    if (txt.ID == getData.ToList()[g].ControlName.ToString())
                                                    {
                                                        txt.Text = getData.ToList()[g].Data.ToString();
                                                    }
                                                    // }
                                                }
                                                if (ctl is System.Web.UI.WebControls.DropDownList)
                                                {
                                                    DropDownList ddl = ctl as DropDownList;
                                                    //for (int g = 0; g < getData.ToList().Count; g++)
                                                    //{
                                                    if (ddl.ID == getData.ToList()[g].ControlName.ToString())
                                                    {
                                                        ddl.SelectedValue = getData.ToList()[g].Data.ToString();
                                                        objDDL_SelectedIndexChanged(ctl, e);
                                                    }
                                                    // }
                                                }
                                            }

                                        }
                                    }
                                }


                            }

                        }


                        //    if (ctl.Name == getData.ToList()[g].ControlName.ToString())
                        //    {

                        //        if (ctl is TextBox)
                        //        {
                        //            ctl.Text = getData.ToList()[g].Data.ToString();
                        //        }
                        //        if (ctl is ComboBox)
                        //        {
                        //            ComboBox cmb = ctl as ComboBox;
                        //            cmb.SelectedValue = int.Parse(getData.ToList()[g].Data.ToString());
                        //        }
                        //        if (ctl is DateTimePicker)
                        //        {
                        //            DateTimePicker cmb = ctl as DateTimePicker;
                        //            cmb.Value = Convert.ToDateTime(getData.ToList()[g].Data.ToString());
                        //        }
                        //    }

                    }
                }
                else
                {
                    RefreshDynamicTab();
                }

                //    }
                //    else if (DataGridItemVariation.Visible == true)
                //    {
                //        var getDataVar = from item in ERPManagement.GetInstance.GetAllItemCustomisedData(TAGGING_Item.Variation_ID_Global)
                //                         where item.Tab_Name == TabItem.SelectedTab.Text && item.Variation_Or_Item == false
                //                         select item;
                //        if (getDataVar.ToList().Count > 0)
                //        {
                //            for (int g = 0; g < getDataVar.ToList().Count; g++)
                //            {
                //                foreach (Control ctl in TabItem.SelectedTab.Controls)
                //                {
                //                    if (ctl.Name == getDataVar.ToList()[g].ControlName.ToString())
                //                    {

                //                        if (ctl is TextBox)
                //                        {
                //                            ctl.Text = getDataVar.ToList()[g].Data.ToString();
                //                        }
                //                        if (ctl is ComboBox)
                //                        {
                //                            ComboBox cmb = ctl as ComboBox;
                //                            cmb.SelectedValue = int.Parse(getDataVar.ToList()[g].Data.ToString());
                //                        }
                //                        if (ctl is DateTimePicker)
                //                        {
                //                            DateTimePicker cmb = ctl as DateTimePicker;
                //                            cmb.Value = Convert.ToDateTime(getDataVar.ToList()[g].Data.ToString());
                //                        }
                //                    }


                //                }
                //            }
                //        }
                //        else
                //        {
                //            RefreshDynamicTab();
                //        }
                //    }

            }
            else
            {

                //  RefreshDynamicTab();

            }
        }
        private void objDDL_SelectedIndexChanged(object sender, EventArgs e)
        {

            Control ctrl = (Control)sender;
            DropDownList objDDLParent = ctrl as DropDownList;
            string x = objDDLParent.ID;

            //  object cc= objDDLParent.Attributes.Add("onclick","yourJavascriptFunction();");

            string[] words = x.Split('_');
            if (objDDLParent.SelectedIndex > 0)
            {

                //It checks the combobox has the child value or not
                var getCmbDataa = (from data in ERPManagement.GetInstance.GetSequenceDetails()
                                   where data.Reference_Parameter_ID == int.Parse(words[0])// && data.Reference_Parameter_ID != 0  //&& data.ParameterID == int.Parse(words[0])
                                   select new { data.ParameterID }).Distinct();
                if (getCmbDataa.ToList().Count > 0)
                {

                    // It gets data from database for child combobox
                    var getCmbData = from data in ERPManagement.GetInstance.GetSequenceDetails()
                                     where data.Reference_ID == int.Parse(objDDLParent.SelectedValue.ToString()) && data.ParameterID == int.Parse(getCmbDataa.ToList()[0].ParameterID.ToString()) //&& data.ParameterID == int.Parse(words[0])
                                     select data;

                    if (getCmbData.ToList().Count > 0)
                    {

                        ///////////////////////////

                        AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabContainer1;
                        if (container.ActiveTabIndex > 0)
                        {
                            foreach (object obj in container.ActiveTab.Controls)
                            {
                                if (obj is Control)
                                {
                                    Control c = (Control)obj;
                                    if (c is System.Web.UI.WebControls.Table)
                                    {
                                        Table tbl = c as Table;
                                        foreach (object rw in tbl.Rows)
                                        {
                                            TableRow tbr = rw as TableRow;
                                            foreach (object cl in tbr.Cells)
                                            {
                                                TableCell tcl = cl as TableCell;
                                                foreach (object ctl in tcl.Controls)
                                                {

                                                    if (ctl is System.Web.UI.WebControls.DropDownList)
                                                    {
                                                        DropDownList objDDL = ctl as DropDownList;
                                                        string[] ids = objDDL.ID.Split('_');
                                                        if (int.Parse(ids[0]) == int.Parse(getCmbDataa.ToList()[0].ParameterID.ToString()))
                                                        {

                                                            List<TAGGING_Property> colors = new List<TAGGING_Property>();
                                                            TAGGING_Property objcol = new TAGGING_Property();
                                                            objcol.Data_Value = (0).ToString();
                                                            objcol.Data_Display = "Select";
                                                            colors.Add(objcol);
                                                            foreach (TAGGING_Property country in getCmbData.ToList())
                                                            {
                                                                colors.Add(country);
                                                            }
                                                            objDDL.DataSource = colors;
                                                            objDDL.DataTextField = "Data_Display";
                                                            objDDL.DataValueField = "Field_ID";
                                                            objDDL.DataBind();
                                                            objDDL.SelectedIndex = 0;
                                                        }
                                                    }

                                                }

                                            }
                                        }

                                    }
                                }

                            }
                        }
                    }
                    else
                    {

                        AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabContainer1;
                        if (container.ActiveTabIndex > 0)
                        {
                            foreach (object obj in container.ActiveTab.Controls)
                            {
                                if (obj is Control)
                                {
                                    Control c = (Control)obj;
                                    if (c is System.Web.UI.WebControls.Table)
                                    {
                                        Table tbl = c as Table;
                                        foreach (object rw in tbl.Rows)
                                        {
                                            TableRow tbr = rw as TableRow;
                                            foreach (object cl in tbr.Cells)
                                            {
                                                TableCell tcl = cl as TableCell;
                                                foreach (object ctl in tcl.Controls)
                                                {

                                                    if (ctl is System.Web.UI.WebControls.DropDownList)
                                                    {
                                                        DropDownList objDDL = ctl as DropDownList;
                                                        string[] ids = objDDL.ID.Split('_');
                                                        if (int.Parse(ids[0]) == int.Parse(getCmbDataa.ToList()[0].ParameterID.ToString()))
                                                        {

                                                            List<TAGGING_Property> colors = new List<TAGGING_Property>();
                                                            TAGGING_Property objcol = new TAGGING_Property();
                                                            objDDL.Items.Clear();
                                                            //objDDL.DataSource = null;
                                                            //objDDL.DataBind();
                                                            //  objDDL.SelectedIndex = 0;
                                                        }
                                                    }

                                                }

                                            }
                                        }

                                    }
                                }

                            }
                        }

                    }
                }
            }

        }

    }
}