示例#1
0
        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定移除吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }

            ZDLTreeNode deleteN    = (ZDLTreeNode)this.treeView.SelectedNode;
            Node        deleteObjN = deleteN.ObjNode;

            if (deleteN != null && deleteObjN != null)
            {
                ZDLTreeNode parentN    = (ZDLTreeNode)deleteN.Parent;
                Node        parentObjN = parentN.ObjNode;
                if (parentN != null && parentObjN != null)
                {
                    //数据
                    parentObjN.child.Remove(deleteObjN);
                    this.AddMemento();

                    //显示
                    parentN.Nodes.Remove(deleteN);

                    //状态
                    this.state = PageState.Edit;
                }
            }
        }
示例#2
0
 /// <summary>
 /// 绑定树
 /// </summary>
 /// <param name="node"></param>
 /// <param name="childs"></param>
 private void BandIngTreeView(ZDLTreeNode node, List <Node> childs)
 {
     if (node != null && childs != null && childs.Count > 0)
     {
         foreach (var item in childs)
         {
             ZDLTreeNode child = new ZDLTreeNode(item.name + "(" + item.type + ")");
             child.ObjNode = item;
             if (item.precondition != null)
             {
                 child.ToolTipText = item.precondition.name;
                 child.ForeColor   = Color.Black;
             }
             else
             {
                 child.ToolTipText = "没有设置进入条件";
                 child.ForeColor   = Color.Red;
             }
             node.Nodes.Add(child);
             if (item.child != null && item.child.Count > 0)
             {
                 this.BandIngTreeView(child, item.child);
                 child.ExpandAll();
             }
         }
     }
     else
     {
         ZDLTreeNode root = new ZDLTreeNode(this.treeHandler.Tree.Root.name + "(" + this.treeHandler.Tree.Root.type + ")");
         root.ObjNode = this.treeHandler.Tree.Root;
         this.treeView.Nodes.Clear();
         this.treeView.Nodes.Add(root);
         if (this.treeHandler.Tree.Root.precondition != null)
         {
             root.ToolTipText = this.treeHandler.Tree.Root.precondition.name;
             root.ForeColor   = Color.Black;
         }
         else
         {
             root.ToolTipText = "没有设置进入条件";
             root.ForeColor   = Color.Red;
         }
         if (this.treeHandler.Tree.Root.child != null && this.treeHandler.Tree.Root.child.Count > 0)
         {
             this.BandIngTreeView(root, this.treeHandler.Tree.Root.child);
             root.ExpandAll();
         }
     }
 }
示例#3
0
        /// <summary>
        /// 检查树是否完整
        /// </summary>
        public bool CheckTree(ref string error, TreeNodeCollection childs)
        {
            if (childs != null && childs.Count > 0)
            {
                foreach (var item in childs)
                {
                    ZDLTreeNode child = item as ZDLTreeNode;
                    if (child.ForeColor == Color.Red)
                    {
                        error = string.Format("第{0}层,{1}的条件不可以为空。", child.Level + 1, child.Text);
                        return(false);
                    }
                    else
                    {
                        if (child.Nodes.Count > 0)
                        {
                            return(this.CheckTree(ref error, child.Nodes));
                        }
                    }
                }
            }
            else
            {
                ZDLTreeNode root = (ZDLTreeNode)this.treeView.Nodes[0];
                if (root.ForeColor == Color.Red)
                {
                    error = string.Format("第{0}层,{1}的条件不可以为空。", root.Level + 1, root.Text);
                    return(false);
                }
                else
                {
                    if (root.Nodes.Count > 0)
                    {
                        return(this.CheckTree(ref error, root.Nodes));
                    }
                }
            }

            return(true);
        }
示例#4
0
        private void treeView_DragDrop(object sender, DragEventArgs e)
        {
            Point p = this.treeView.PointToClient(new Point(e.X, e.Y));
            ZDLTreeNode node = (ZDLTreeNode)this.treeView.GetNodeAt(p.X, p.Y);//拖拽到的节点
            Node objNode = null;//拖拽到的节点对应的行为树节点
            if (node != null)
            {
                objNode = node.ObjNode;
            }

            object treeNodeData = e.Data.GetData(typeof(ZDLTreeNode));
            object stringData = e.Data.GetData(DataFormats.Text);

            #region 是从左边列表拖进来的
            if (stringData != null)
            {
                string stringDataValue = e.Data.GetData(DataFormats.Text).ToString();

                bool isRoot = false;
                if (this.treeHandler == null || this.treeHandler.Tree.Root == null)
                {
                    isRoot = true;
                }

                if (stringDataValue == "Node")
                {
                    #region 节点
                    if (this.dragNode != null)
                    {
                        if (isRoot)
                        {
                            //创建树
                            Node root = (Node)this.dragNode.Clone();

                            if (this.treeHandler == null)
                            {
                                this.treeHandler = new TreeHandler();
                            }

                            Tree tree = this.treeHandler.Tree;
                            if (tree == null)
                            {
                                tree = new Tree();
                                tree.Name = "untitled";
                                tree.IsTemplate = false;
                                tree.TemplateName = null;
                                this.treeHandler.Tree = tree;
                            }
                            tree.Root = root;
                            this.AddMemento();

                            //添加根节点视图
                            ZDLTreeNode rootNodeView = new ZDLTreeNode(this.dragNode.name + "(" + this.dragNode.type + ")");
                            rootNodeView.ObjNode = root;
                            rootNodeView.ToolTipText = "没有设置进入条件";
                            rootNodeView.ForeColor = Color.Red;
                            this.treeView.Nodes.Add(rootNodeView);
                            this.treeView.ExpandAll();

                            //为编辑状态
                            this.state = PageState.Edit;

                        }
                        else if (node != null && objNode != null)
                        {
                            if (objNode.isVirtual)
                            {
                                //添加对象
                                Node dragNodeClone = (Node)this.dragNode.Clone();
                                objNode.child.Add(dragNodeClone);
                                this.AddMemento();

                                //添加视图
                                ZDLTreeNode nodeView = new ZDLTreeNode(this.dragNode.name + "(" + this.dragNode.type + ")");
                                nodeView.ObjNode = dragNodeClone;
                                nodeView.ToolTipText = "没有设置进入条件";
                                nodeView.ForeColor = Color.Red;
                                node.Nodes.Add(nodeView);
                                node.ExpandAll();

                                //为编辑状态
                                this.state = PageState.Edit;
                            }
                        }
                    }
                    #endregion
                }
                else if (stringDataValue == "Tree")
                {
                    #region 树

                    //如果是拖拽模板创建模板是不允许的
                    if (this.isTemplate)
                    {
                        MessageBox.Show("暂不支持模板拖拽到模板", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    if (this.isTemplate == false && this.dragTree != null && this.dragTree.Root != null)
                    {
                        if (isRoot)
                        {
                            //创建树
                            if (this.treeHandler == null)
                            {
                                this.treeHandler = new TreeHandler();
                            }

                            if (this.treeHandler.Tree == null)
                            {
                                //这种是拖拽模板创建普通树的情况
                                this.treeHandler.Tree = new Tree();
                                this.treeHandler.Tree.TemplateName = this.dragTree.Name;
                                this.treeHandler.Tree.Name = "untitled";
                                this.treeHandler.Tree.IsTemplate = false;
                            }

                            this.treeHandler.Tree.Root = (Node)this.dragTree.Root.Clone();
                            this.AddMemento();

                            //添加根节点视图
                            this.BandIngTreeView(null, null);

                            //为编辑状态
                            this.state = PageState.Edit;
                        }
                        else if (node != null && objNode != null)
                        {
                            if (objNode.isVirtual)
                            {
                                //添加对象
                                Node dragNodeClone = (Node)this.dragTree.Root.Clone();
                                objNode.child.Add(dragNodeClone);
                                this.AddMemento();

                                //添加根节点视图
                                this.BandIngTreeView(null, null);

                                //为编辑状态
                                this.state = PageState.Edit;
                            }
                        }
                    }
                    #endregion
                }
                else if (stringDataValue == "Precondition")
                {
                    #region 条件
                    if (this.dragPrecondition != null)
                    {
                        if (node != null && objNode != null)
                        {
                            Precondition dragPreconditionClone = (Precondition)this.dragPrecondition.Clone();
                            objNode.precondition = dragPreconditionClone;
                            this.AddMemento();

                            node.ExpandAll();
                            node.ToolTipText = dragPreconditionClone.name;
                            node.ForeColor = Color.Black;

                            //为编辑状态
                            this.state = PageState.Edit;
                        }
                    }
                    #endregion
                }
            }
            #endregion

            #region 树本身节点拖拽
            if (treeNodeData != null)
            {
                ZDLTreeNode dNode = treeNodeData as ZDLTreeNode;
                if (dNode != null && node != null && objNode != null && dNode != node)
                {
                    Node dObjNode = dNode.ObjNode;
                    if (dObjNode != null && dObjNode != objNode)
                    {
                        //如果拖拽的节点不是目标节点父亲
                        if (!this.isHasTreeNode(dObjNode.child, objNode))
                        {
                            //如果目标节点不是虚节点,那么只有交换顺序的情况
                            if (!objNode.isVirtual)
                            {
                                #region 交换顺序
                                ZDLTreeNode dParentNode = (ZDLTreeNode)dNode.Parent;
                                if (dParentNode != null)
                                {
                                    Node dObjParentNode = dParentNode.ObjNode;
                                    if (dObjParentNode != null)
                                    {
                                        ZDLTreeNode parentNode = (ZDLTreeNode)node.Parent;
                                        if (parentNode != null)
                                        {
                                            Node objParentNode = parentNode.ObjNode;

                                            if (objParentNode != null)
                                            {
                                                if (dParentNode == parentNode)//调整顺序
                                                {
                                                    //数据
                                                    dObjParentNode.child.Remove(dObjNode);
                                                    int index = dObjParentNode.child.IndexOf(objNode);
                                                    dObjParentNode.child.Insert(index, dObjNode);
                                                    this.AddMemento();

                                                    //视图
                                                    dParentNode.Nodes.Remove(dNode);
                                                    index = dParentNode.Nodes.IndexOf(node);
                                                    dParentNode.Nodes.Insert(index, dNode);
                                                    dParentNode.ExpandAll();

                                                    //为编辑状态
                                                    this.state = PageState.Edit;

                                                }

                                            }
                                        }
                                    }
                                }
                                #endregion
                            }
                            else//移动到另一个父亲节点
                            {
                                if (node != dNode.Parent && MessageBox.Show("插入到该节点吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    #region 插入到该节点
                                    ZDLTreeNode dParentNode = (ZDLTreeNode)dNode.Parent;
                                    Node dObjParentNode = dParentNode.ObjNode;

                                    if (dParentNode != null && dObjParentNode != null)
                                    {
                                        //数据
                                        dObjParentNode.child.Remove(dObjNode);
                                        objNode.child.Add(dObjNode);
                                        this.AddMemento();

                                        //视图
                                        dParentNode.Nodes.Remove(dNode);
                                        node.Nodes.Add(dNode);
                                        node.ExpandAll();

                                        //为编辑状态
                                        this.state = PageState.Edit;
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region 交换顺序
                                    ZDLTreeNode dParentNode = (ZDLTreeNode)dNode.Parent;
                                    if (dParentNode != null)
                                    {
                                        Node dObjParentNode = dParentNode.ObjNode;
                                        if (dObjParentNode != null)
                                        {
                                            ZDLTreeNode parentNode = (ZDLTreeNode)node.Parent;
                                            if (parentNode != null)
                                            {
                                                Node objParentNode = parentNode.ObjNode;

                                                if (objParentNode != null)
                                                {
                                                    if (dParentNode == parentNode)//调整顺序
                                                    {
                                                        //数据
                                                        dObjParentNode.child.Remove(dObjNode);
                                                        int index = dObjParentNode.child.IndexOf(objNode);
                                                        dObjParentNode.child.Insert(index, dObjNode);
                                                        this.AddMemento();

                                                        //视图
                                                        dParentNode.Nodes.Remove(dNode);
                                                        index = dParentNode.Nodes.IndexOf(node);
                                                        dParentNode.Nodes.Insert(index, dNode);
                                                        dParentNode.ExpandAll();

                                                        //为编辑状态
                                                        this.state = PageState.Edit;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }
示例#5
0
 /// <summary>
 /// 绑定树
 /// </summary>
 /// <param name="node"></param>
 /// <param name="childs"></param>
 private void BandIngTreeView(ZDLTreeNode node, List<Node> childs)
 {
     if (node != null && childs != null && childs.Count > 0)
     {
         foreach (var item in childs)
         {
             ZDLTreeNode child = new ZDLTreeNode(item.name + "(" + item.type + ")");
             child.ObjNode = item;
             if (item.precondition != null)
             {
                 child.ToolTipText = item.precondition.name;
                 child.ForeColor = Color.Black;
             }
             else
             {
                 child.ToolTipText = "没有设置进入条件";
                 child.ForeColor = Color.Red;
             }
             node.Nodes.Add(child);
             if (item.child != null && item.child.Count > 0)
             {
                 this.BandIngTreeView(child, item.child);
                 child.ExpandAll();
             }
         }
     }
     else
     {
         ZDLTreeNode root = new ZDLTreeNode(this.treeHandler.Tree.Root.name + "(" + this.treeHandler.Tree.Root.type + ")");
         root.ObjNode = this.treeHandler.Tree.Root;
         this.treeView.Nodes.Clear();
         this.treeView.Nodes.Add(root);
         if (this.treeHandler.Tree.Root.precondition != null)
         {
             root.ToolTipText = this.treeHandler.Tree.Root.precondition.name;
             root.ForeColor = Color.Black;
         }
         else
         {
             root.ToolTipText = "没有设置进入条件";
             root.ForeColor = Color.Red;
         }
         if (this.treeHandler.Tree.Root.child != null && this.treeHandler.Tree.Root.child.Count > 0)
         {
             this.BandIngTreeView(root, this.treeHandler.Tree.Root.child);
             root.ExpandAll();
         }
     }
 }
示例#6
0
        private void treeView_DragDrop(object sender, DragEventArgs e)
        {
            Point       p       = this.treeView.PointToClient(new Point(e.X, e.Y));
            ZDLTreeNode node    = (ZDLTreeNode)this.treeView.GetNodeAt(p.X, p.Y); //拖拽到的节点
            Node        objNode = null;                                           //拖拽到的节点对应的行为树节点

            if (node != null)
            {
                objNode = node.ObjNode;
            }

            object treeNodeData = e.Data.GetData(typeof(ZDLTreeNode));
            object stringData   = e.Data.GetData(DataFormats.Text);

            #region 是从左边列表拖进来的
            if (stringData != null)
            {
                string stringDataValue = e.Data.GetData(DataFormats.Text).ToString();

                bool isRoot = false;
                if (this.treeHandler == null || this.treeHandler.Tree.Root == null)
                {
                    isRoot = true;
                }

                if (stringDataValue == "Node")
                {
                    #region 节点
                    if (this.dragNode != null)
                    {
                        if (isRoot)
                        {
                            //创建树
                            Node root = (Node)this.dragNode.Clone();

                            if (this.treeHandler == null)
                            {
                                this.treeHandler = new TreeHandler();
                            }

                            Tree tree = this.treeHandler.Tree;
                            if (tree == null)
                            {
                                tree                  = new Tree();
                                tree.Name             = "untitled";
                                tree.IsTemplate       = false;
                                tree.TemplateName     = null;
                                this.treeHandler.Tree = tree;
                            }
                            tree.Root = root;
                            this.AddMemento();

                            //添加根节点视图
                            ZDLTreeNode rootNodeView = new ZDLTreeNode(this.dragNode.name + "(" + this.dragNode.type + ")");
                            rootNodeView.ObjNode     = root;
                            rootNodeView.ToolTipText = "没有设置进入条件";
                            rootNodeView.ForeColor   = Color.Red;
                            this.treeView.Nodes.Add(rootNodeView);
                            this.treeView.ExpandAll();

                            //为编辑状态
                            this.state = PageState.Edit;
                        }
                        else if (node != null && objNode != null)
                        {
                            if (objNode.isVirtual)
                            {
                                //添加对象
                                Node dragNodeClone = (Node)this.dragNode.Clone();
                                objNode.child.Add(dragNodeClone);
                                this.AddMemento();

                                //添加视图
                                ZDLTreeNode nodeView = new ZDLTreeNode(this.dragNode.name + "(" + this.dragNode.type + ")");
                                nodeView.ObjNode     = dragNodeClone;
                                nodeView.ToolTipText = "没有设置进入条件";
                                nodeView.ForeColor   = Color.Red;
                                node.Nodes.Add(nodeView);
                                node.ExpandAll();

                                //为编辑状态
                                this.state = PageState.Edit;
                            }
                        }
                    }
                    #endregion
                }
                else if (stringDataValue == "Tree")
                {
                    #region 树

                    //如果是拖拽模板创建模板是不允许的
                    if (this.isTemplate)
                    {
                        MessageBox.Show("暂不支持模板拖拽到模板", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    if (this.isTemplate == false && this.dragTree != null && this.dragTree.Root != null)
                    {
                        if (isRoot)
                        {
                            //创建树
                            if (this.treeHandler == null)
                            {
                                this.treeHandler = new TreeHandler();
                            }

                            if (this.treeHandler.Tree == null)
                            {
                                //这种是拖拽模板创建普通树的情况
                                this.treeHandler.Tree = new Tree();
                                this.treeHandler.Tree.TemplateName = this.dragTree.Name;
                                this.treeHandler.Tree.Name         = "untitled";
                                this.treeHandler.Tree.IsTemplate   = false;
                            }

                            this.treeHandler.Tree.Root = (Node)this.dragTree.Root.Clone();
                            this.AddMemento();

                            //添加根节点视图
                            this.BandIngTreeView(null, null);

                            //为编辑状态
                            this.state = PageState.Edit;
                        }
                        else if (node != null && objNode != null)
                        {
                            if (objNode.isVirtual)
                            {
                                //添加对象
                                Node dragNodeClone = (Node)this.dragTree.Root.Clone();
                                objNode.child.Add(dragNodeClone);
                                this.AddMemento();

                                //添加根节点视图
                                this.BandIngTreeView(null, null);

                                //为编辑状态
                                this.state = PageState.Edit;
                            }
                        }
                    }
                    #endregion
                }
                else if (stringDataValue == "Precondition")
                {
                    #region 条件
                    if (this.dragPrecondition != null)
                    {
                        if (node != null && objNode != null)
                        {
                            Precondition dragPreconditionClone = (Precondition)this.dragPrecondition.Clone();
                            objNode.precondition = dragPreconditionClone;
                            this.AddMemento();

                            node.ExpandAll();
                            node.ToolTipText = dragPreconditionClone.name;
                            node.ForeColor   = Color.Black;

                            //为编辑状态
                            this.state = PageState.Edit;
                        }
                    }
                    #endregion
                }
            }
            #endregion

            #region 树本身节点拖拽
            if (treeNodeData != null)
            {
                ZDLTreeNode dNode = treeNodeData as ZDLTreeNode;
                if (dNode != null && node != null && objNode != null && dNode != node)
                {
                    Node dObjNode = dNode.ObjNode;
                    if (dObjNode != null && dObjNode != objNode)
                    {
                        //如果拖拽的节点不是目标节点父亲
                        if (!this.isHasTreeNode(dObjNode.child, objNode))
                        {
                            //如果目标节点不是虚节点,那么只有交换顺序的情况
                            if (!objNode.isVirtual)
                            {
                                #region 交换顺序
                                ZDLTreeNode dParentNode = (ZDLTreeNode)dNode.Parent;
                                if (dParentNode != null)
                                {
                                    Node dObjParentNode = dParentNode.ObjNode;
                                    if (dObjParentNode != null)
                                    {
                                        ZDLTreeNode parentNode = (ZDLTreeNode)node.Parent;
                                        if (parentNode != null)
                                        {
                                            Node objParentNode = parentNode.ObjNode;

                                            if (objParentNode != null)
                                            {
                                                if (dParentNode == parentNode)//调整顺序
                                                {
                                                    //数据
                                                    dObjParentNode.child.Remove(dObjNode);
                                                    int index = dObjParentNode.child.IndexOf(objNode);
                                                    dObjParentNode.child.Insert(index, dObjNode);
                                                    this.AddMemento();

                                                    //视图
                                                    dParentNode.Nodes.Remove(dNode);
                                                    index = dParentNode.Nodes.IndexOf(node);
                                                    dParentNode.Nodes.Insert(index, dNode);
                                                    dParentNode.ExpandAll();

                                                    //为编辑状态
                                                    this.state = PageState.Edit;
                                                }
                                            }
                                        }
                                    }
                                }
                                #endregion
                            }
                            else//移动到另一个父亲节点
                            {
                                if (node != dNode.Parent && MessageBox.Show("插入到该节点吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    #region 插入到该节点
                                    ZDLTreeNode dParentNode    = (ZDLTreeNode)dNode.Parent;
                                    Node        dObjParentNode = dParentNode.ObjNode;

                                    if (dParentNode != null && dObjParentNode != null)
                                    {
                                        //数据
                                        dObjParentNode.child.Remove(dObjNode);
                                        objNode.child.Add(dObjNode);
                                        this.AddMemento();

                                        //视图
                                        dParentNode.Nodes.Remove(dNode);
                                        node.Nodes.Add(dNode);
                                        node.ExpandAll();

                                        //为编辑状态
                                        this.state = PageState.Edit;
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region 交换顺序
                                    ZDLTreeNode dParentNode = (ZDLTreeNode)dNode.Parent;
                                    if (dParentNode != null)
                                    {
                                        Node dObjParentNode = dParentNode.ObjNode;
                                        if (dObjParentNode != null)
                                        {
                                            ZDLTreeNode parentNode = (ZDLTreeNode)node.Parent;
                                            if (parentNode != null)
                                            {
                                                Node objParentNode = parentNode.ObjNode;

                                                if (objParentNode != null)
                                                {
                                                    if (dParentNode == parentNode)//调整顺序
                                                    {
                                                        //数据
                                                        dObjParentNode.child.Remove(dObjNode);
                                                        int index = dObjParentNode.child.IndexOf(objNode);
                                                        dObjParentNode.child.Insert(index, dObjNode);
                                                        this.AddMemento();

                                                        //视图
                                                        dParentNode.Nodes.Remove(dNode);
                                                        index = dParentNode.Nodes.IndexOf(node);
                                                        dParentNode.Nodes.Insert(index, dNode);
                                                        dParentNode.ExpandAll();

                                                        //为编辑状态
                                                        this.state = PageState.Edit;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }