using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using CRM.BLL;
using CRM.Model;
using CRM.Common;


public partial class Left : System.Web.UI.Page
{
    protected void Init_TreeView(string IsInit,string fid) {
        IList<CRM.Model.MenuInfo> menus;
        CRM.BLL.Menu menu = new CRM.BLL.Menu();
        menus = menu.GetMenuByFid(fid);

        for (int i = 0; i < menus.Count; i++) {
            TreeNode node = new TreeNode();
            node.Text = menus[i].菜单名称;
            node.SelectAction = TreeNodeSelectAction.Expand;
            node.NavigateUrl = menus[i].文件路径;
            node.Target = "Right";
            //node.ImageUrl = menus[i].菜单图片;
            DataTable dt = CRM.Common.InitData.GetEmployeesRight(Session["LoginID"].ToString());
            if (dt.Rows[0]["权限"].ToString().IndexOf("|"+menus[i].ID.ToString()+",")>-1)
            {
                TreeView1.Nodes.Add(node);
            }

            CreateNode(node,menus[i].ID.ToString());
        }

        TreeNode LoginOut = new TreeNode();
        LoginOut.Text = "退出";
        LoginOut.NavigateUrl = "LoginOut.aspx";
        TreeView1.Nodes.Add(LoginOut);
    }

    protected void CreateNode(TreeNode node,string fid) {
        IList<CRM.Model.MenuInfo> childs;
        CRM.BLL.Menu child = new CRM.BLL.Menu();
        childs = child.GetMenuByFid(fid);

        for (int i = 0; i < childs.Count; i++) {
            TreeNode childNode = new TreeNode();
            childNode.Text = childs[i].菜单名称;
            childNode.NavigateUrl = childs[i].文件路径;
            childNode.Target = "Right";
            childNode.SelectAction = TreeNodeSelectAction.Expand;

            DataTable dt = CRM.Common.InitData.GetEmployeesRight(Session["LoginID"].ToString());
            if (dt.Rows[0]["权限"].ToString().IndexOf("|" + childs[i].ID.ToString() + ",") > -1)
            {
                node.ChildNodes.Add(childNode);
            }
            CreateNode(childNode,childs[i].ID.ToString());
        
        }

        
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        CRM.Common.Login.IsLogin();
        if (!IsPostBack)
        {
            Init_TreeView("1", "0");
        }
    }
}
