using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
namespace ComResProSystem
{
    public partial class Tree :BasePage
    {
        UserBll bll = new UserBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string ID = Session["UserID"].ToString();
                DataTable dt = bll.gettable("SELECT ID,NodeText,NodeURL,NodeImage,ParentID FROM Authority WHERE ID IN(SELECT AuthorityID FROM UserPermissions where UserID='"+ID+"')");
                DataView dv = dt.DefaultView;
                TreeNode node = new TreeNode();
                node.Text = "企业资源管理平台";
                node.Value = "0";
                Tv_Per.Nodes.Add(node);
                AddChirld(dv, node);
            }
        }
        protected void AddChirld(DataView dv, TreeNode node)
        {
            dv.RowFilter = "ParentID='" + node.Value + "'";
            foreach (DataRowView view in dv)
            {
                TreeNode chnode = new TreeNode();
                chnode.Text = view["NodeText"].ToString();
                chnode.Value = view["ID"].ToString();
                chnode.ImageUrl = view["NodeImage"].ToString();
                if (node.Value !="0")
                {
                    chnode.NavigateUrl = view["NodeURL"].ToString();
                    chnode.Target = "I2";
                }
                chnode.Expanded = false;
                node.ChildNodes.Add(chnode);
                AddChirld(dv, chnode);
            }
        }
    }
}
