Esempio n. 1
0
        //节点太多,点击加载更多未显示的节点
        void moreNode_Load(object sender, RoutedEventArgs e)
        {
            TreeViewItem moreItem   = sender as TreeViewItem;
            MyTreeNode   node       = moreItem.Tag as MyTreeNode;
            TreeViewItem parentItem = moreItem.Parent as TreeViewItem;

            if (parentItem != null)
            {
                parentItem.Items.Remove(moreItem);

                MyTrees.OpenDB();
                List <MyTreeNode> childrenNodes = MyTrees.GetNodesByTopIdPage(node.TopId, node.ChildrenCount);
                MyTrees.CloseDB();
                foreach (MyTreeNode subNode in childrenNodes)
                {
                    TreeViewItem subItem = NewTreeViewItem(subNode);
                    parentItem.Items.Add(subItem);

                    //如果子节点还有孙子节点,则添加一个虚假的孙节点,使该子节点具有折叠的"+"
                    if (subNode.ChildrenCount > 0)
                    {
                        subItem.Items.Add(NewTreeViewItem(null));
                    }

                    WindowView.notify.SetStatusMessage("正在展开节点" + subItem.Header);
                }

                //表示分页加载更多的节点
                node.ChildrenCount = node.ChildrenCount + MyTrees.getNodePageSize;
                if (node.ChildrenCount < node.ChildrenCountAll)
                {
                    parentItem.Items.Add(NewTreeViewItem(node));
                }
            }
        }
Esempio n. 2
0
        void item_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;

            if (item.HasItems && (item.Items[0] as TreeViewItem).Header.ToString() == "none")
            {
                //先移除为使该节点具有折叠的"+"而添加的虚假的子节点
                item.Items.Clear();

                if ((e.Source as TreeViewItem).IsSelected)
                {
                    MyTrees.OpenDB();
                }

                MyTreeNode        node          = item.Tag as MyTreeNode;
                List <MyTreeNode> childrenNodes = MyTrees.GetNodesByTopIdPage(node.SysId, 0);

                foreach (MyTreeNode subNode in childrenNodes)
                {
                    TreeViewItem subItem = NewTreeViewItem(subNode);
                    item.Items.Add(subItem);

                    //如果子节点还有孙子节点,则添加一个虚假的孙节点,使该子节点具有折叠的"+"
                    if (subNode.ChildrenCount > 0)
                    {
                        subItem.Items.Add(NewTreeViewItem(null));
                    }

                    WindowView.notify.SetStatusMessage("正在展开节点" + subItem.Header);
                }

                //表示分页加载更多的节点
                if (node.ChildrenCount > MyTrees.getNodePageSize)
                {
                    MyTreeNode moreNode = new MyTreeNode();
                    moreNode.SysId            = "moreNode";
                    moreNode.Name             = node.Name;
                    moreNode.TopId            = node.SysId;
                    moreNode.ChildrenCount    = MyTrees.getNodePageSize;
                    moreNode.ChildrenCountAll = node.ChildrenCount;
                    item.Items.Add(NewTreeViewItem(moreNode));
                }

                if ((e.Source as TreeViewItem).IsSelected)
                {
                    MyTrees.CloseDB();
                }
            }
        }
Esempio n. 3
0
        //显示上一级节点
        private void btnUpLevelNode_Click(object sender, RoutedEventArgs e)
        {
            MyTrees.OpenDB();
            TreeViewItem oldRootItem = memberTreeView.Items[0] as TreeViewItem;
            MyTreeNode   oldRootNode = oldRootItem.Tag as MyTreeNode;
            MyTreeNode   newRootNode = MyTrees.GetNodeBySysId(oldRootNode.TopId);

            if (isRingClose(newRootNode.SysId))
            {
                return;
            }

            //先移除旧的根节点
            memberTreeView.Items.Remove(oldRootItem);

            //添加新的根节点
            TreeViewItem newRootItem = NewTreeViewItem(newRootNode);

            memberTreeView.Items.Add(newRootItem);
            newRootItem.IsExpanded = true;

            //新的根节点添加子节点
            List <MyTreeNode> childrenNodes = MyTrees.GetNodesByTopIdPage(newRootNode.SysId, 0);
            bool hasNotAdded = true;

            foreach (MyTreeNode subNode in childrenNodes)
            {
                if (hasNotAdded)
                {
                    if (oldRootNode.SysId == subNode.SysId)
                    {
                        newRootItem.Items.Add(oldRootItem);
                        hasNotAdded = false;
                        continue;
                    }
                }
                TreeViewItem subItem = NewTreeViewItem(subNode);
                newRootItem.Items.Add(subItem);

                //如果子节点还有孙子节点,则添加一个虚假的孙节点,使该子节点具有折叠的"+"
                if (subNode.ChildrenCount > 0)
                {
                    subItem.Items.Add(NewTreeViewItem(null));
                }
            }

            //表示分页加载更多的节点
            if (newRootNode.ChildrenCount > MyTrees.getNodePageSize)
            {
                MyTreeNode moreNode = new MyTreeNode();
                moreNode.SysId            = "moreNode";
                moreNode.Name             = newRootNode.Name;
                moreNode.TopId            = newRootNode.SysId;
                moreNode.ChildrenCount    = MyTrees.getNodePageSize;
                moreNode.ChildrenCountAll = newRootNode.ChildrenCount;
                newRootItem.Items.Add(NewTreeViewItem(moreNode));
            }

            //判断当前根节点是否存在父节点
            if (MyTrees.GetNodeBySysId(newRootNode.TopId) != null)
            {
                btnUpLevelNode.IsEnabled = true;
                btnUpRootNode.IsEnabled  = true;
            }
            else
            {
                btnUpLevelNode.IsEnabled = false;
                btnUpRootNode.IsEnabled  = false;
            }
            MyTrees.CloseDB();
        }