玄龙戏珠无级树

作者在 2012-07-20 14:38:46 发布以下内容
        private void 开花树()
        {   /*下面自定义树顺序*/
            树.Nodes.Clear(); DataTable 表 = 加载数据(), 树表 = null; string[] 重组表列 = null;
            if (表.TableName == "人员") 重组表列 = new string[] { "归属", "姓名", "生日" };
            if (表.TableName == "提示") 重组表列 = new string[] { "提示内容", "心情日记" };
            if (表.TableName == "文摘") 重组表列 = new string[] { "总类", "别类", "子类", "标题", "内容" };
            /*玄龙戏珠无级树*/
            树表 = 表.DefaultView.ToTable(true, 重组表列);
            DataTable 根表 = 树表.DefaultView.ToTable(true, 重组表列[0]);
            foreach (DataRow 数据列 in 根表.Rows)/*父龙*/
            {
                ArrayList 子节 = new ArrayList(), 节存 = new ArrayList();
                DateTime 日期; DataRow[] 子节数据 = null;
                TreeNode 节点 = new TreeNode();
                节点.Text = 数据列[0].ToString();
                节点.Tag = 数据列;
                树.Nodes.Add(节点); 子节.Add(节点);
                if (!DateTime.TryParse(节点.Text, out 日期)) 子节数据 = 树表.Select(重组表列[0] + "='" + 节点.Text + "'");
                foreach (DataRow 元素 in 子节数据)/*母龙=父龙同步*/
                {
                    for (int 级 = 1, 列数 = 重组表列.Length; 级 < 列数; 级++)/*子龙*/
                    {
                        if (子节.Count < 列数)
                        { 节点 = 玄龙戏珠无级树(节点, 元素, 级); 子节.Add(节点); }
                        else
                        {
                            foreach (TreeNode 节数据 in 节存)/*龙珠*/
                            { if (元素[级].ToString() == ((TreeNode)节数据).Text) 子节[级] = (TreeNode)节数据; }
                            if (元素[级].ToString() != ((TreeNode)子节[级]).Text)
                            {
                                节点 = 玄龙戏珠无级树((TreeNode)子节[级 - 1], 元素, 级);
                                if (级 < 列数 - 2) 节存.Add(子节[级]); else 节存.Add(子节[级 - 1]);
                                子节[级] = 节点;
                            }
                        }
                    }
                }
            }
        }

        private TreeNode 玄龙戏珠无级树(TreeNode 节点, DataRow 元素, int 级)
        {
            TreeNode 加子节 = new TreeNode();
            加子节.Tag = 元素;
            加子节.Text = 元素[级].ToString();
            节点.Nodes.Add(加子节);
            return 加子节;
        }
        欢迎测试指正,不吝赐教,不拒砸蛋丢菜。
我的程序 | 阅读 1515 次
文章评论,共0条
游客请输入验证码