using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Reports_Report_OrgSettings : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //getLevels();
            getNodes();
        }
    }
    public void getNodes()
    {
        try
        {
            GetReports levl = new GetReports();
            DataSet dsLev = new DataSet();
            dsLev = levl.SelectLevelDetails();
            int count;
            for (count = 0; count <= dsLev.Tables[0].Rows.Count - 1; count++)
            {
                TreeNode root = new TreeNode();
                if (Convert.ToInt16(dsLev.Tables[0].Rows[count]["parentid"]) == 0)
                {
                    DropDownList dd = new DropDownList();
                    dd.DataTextField = Convert.ToString(dsLev.Tables[0].Rows[count]["Name"]);
                    dd.DataBind();
                    root.Text = Convert.ToString(dsLev.Tables[0].Rows[count]["Name"]);
                    root.Value = Convert.ToString(dsLev.Tables[0].Rows[count]["id"]);
                    //root.NavigateUrl = "TA_UI_Master_LevelDetails.aspx?tid=" + Convert.ToString(dsLev.Tables[0].Rows[count]["levelid"]) + "&sid=" + Session.SessionID;
                    getChildNodes(root, Convert.ToInt16(dsLev.Tables[0].Rows[count]["id"]));
                    this.tvLevel.Nodes.Add(root);
                }
            }
            dsLev.Dispose();
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
    }
    public void getChildNodes(TreeNode parent, Int16 menuNo)
    {
        GetReports levl = new GetReports();
        DataSet dsLev1 = new DataSet();
        dsLev1 = levl.SelectLevelDetails();
        TreeNode childNode;
        int rowCount = 0, kloop = 0;
        for (kloop = 0; kloop <= dsLev1.Tables[0].Rows.Count - 1; kloop++)
        {
            if (Convert.ToInt16(dsLev1.Tables[0].Rows[kloop]["parentId"]) == menuNo)
            {
                rowCount += 1;
            }
        }
        if (rowCount != 0)
        {
            for (kloop = 0; kloop <= dsLev1.Tables[0].Rows.Count - 1; kloop++)
            {
                if (Convert.ToInt16(dsLev1.Tables[0].Rows[kloop]["parentId"]) == menuNo)
                {
                    childNode = new TreeNode();
                    childNode.Text = Convert.ToString(dsLev1.Tables[0].Rows[kloop]["Name"]);
                    childNode.Value = Convert.ToString(dsLev1.Tables[0].Rows[kloop]["Id"]);
                    //childNode.NavigateUrl = "TA_UI_Master_LevelDetails.aspx?tid=" + Convert.ToString(dsLev1.Tables[0].Rows[kloop]["levelid"]) + "&sid=" + Session.SessionID;
                    parent.ChildNodes.Add(childNode);
                    getChildNodes(childNode, Convert.ToInt16(dsLev1.Tables[0].Rows[kloop]["id"]));
                }
            }
        }
        dsLev1.Dispose();
    }
}
