常见的人事树,按部门,岗位,人员显示,其中部门和岗位都是多个层次的现在要显示在线人员的人事树,就是不要显示那些没有在线人员的部门和岗位如果部门和岗位都只一个层次,我还会,可是多个层次的话,只有显示到人员那一级才知道该部门/岗位该部该显示,感觉是递归再逆向,请问该怎么做呢??

解决方案 »

  1.   

    1.把树存储在缓存中。
    2.用getparent()获取父节点层次
      

  2.   

    通过登录日志,查询在线人员,获取数据集。
    再递归绑定数据。
     if (!IsPostBack)
            {
                BindJG();
            }
        }
        private void BindJG()
        {
            DataSet ds = new DataSet();
            DB c = new DB();
           //获取数据
            DataTable dtb = ds.Tables[0];
            TreeNode root = new TreeNode();
            root.Value = "0";
            root.Text = "";
            root.ImageUrl = "../images/folder.gif";
            root.Expanded = true;
            this.TreeView1.Nodes.Add(root);
            initTree(dtb, "", root);
            this.TreeView1.ExpandAll();
        }
      protected void initTree(DataTable dt, string nFatherid, TreeNode fatherNode)
        {
            DataView dv = new DataView(dt);        if (nFatherid == "")
                dv.RowFilter = "depth='1'";
            else
                dv.RowFilter = "shangjjgbh='"+nFatherid+"'";
            foreach (DataRowView Row in dv)
            {
                TreeNode node = new TreeNode();
                if (fatherNode.Value == "0")
                {
                   node.Value = Row["BH"].ToString();
                   node.Text = Row["mc"].ToString();
                   node.NavigateUrl = "";
                   node.ImageUrl = "../images/folder.gif";
                   fatherNode.ChildNodes.Add(node);
                   initTree(dt, Row["BH"].ToString(), node);
                }
                else
                {
                    node.Text = Row["mc"].ToString();
                    node.Value = Row["BH"].ToString();
                    node.ImageUrl = "../images/jg.gif";
                    fatherNode.ChildNodes.Add(node);           }
            }    }
      

  3.   

    目前数据库的相关表有:
    部门表Department:DeptID,DeptNam,ParentID
    岗位表Station:StationID,StationNam,ParentID,DepartID
    员工表Employee:EmpID,StationID,IsOnline说明:
    1.部门和岗位都是多个层次的
    2.3个表的关系是:人员属于岗位,岗位属于部门
    3.是否在线对应员工表里的IsOnline字段
    4.暂时认为用户通过提供的"注销"按钮退出,不考虑直接关闭网页的情况给出大概的思路和算法就可以了,谢谢