Ejemplo n.º 1
0
        /// <summary>
        /// 移除当前选中的节点,同时需要更新处理当前节点的同级上节点,下节点
        /// </summary>
        /// <param name="entityTree">选择的节点</param>
        /// <returns>string</returns>
        public string RemoveChildrenEntityTree(BaseEntityTree entityTree)
        {
            string message = "";

            try
            {
                if (entityTree == null)
                {
                    return(NULLMESSAGE);
                }
                if (this.ChildrenEntityTree == null || this.ChildrenEntityTree.Count > 0)
                {
                    // 如果传入节点的同级上节点不为null
                    if (entityTree.PrevBaseEntityTree != null)
                    {
                        // 删除的最后一个
                        if (ChildrenEntityTree.IndexOf(entityTree) == ChildrenCount - 1)
                        {
                            entityTree.PrevBaseEntityTree.NextBaseEntityTree = null; // 同级上节点的下节点为null
                        }
                        else
                        {
                            entityTree.PrevBaseEntityTree.NextBaseEntityTree = entityTree.NextBaseEntityTree;
                            entityTree.NextBaseEntityTree.PrevBaseEntityTree = entityTree.PrevBaseEntityTree;
                        }
                    }
                    this.ChildrenEntityTree.Remove(entityTree);
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(message);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加孩子节点
        /// </summary>
        /// <param name="entityTree"></param>
        /// <returns>string</returns>
        public string AddChildrenEntityTree(BaseEntityTree entityTree)
        {
            string message = "";

            try
            {
                // 判断是否为空
                if (entityTree == null)
                {
                    return(NULLMESSAGE);
                }
                // 设置新添加孩子节点的深度
                entityTree.Depti = this.Depti + entityTree.Depti;
                // 设置新添加孩子节点的父节点为当前BaseEntityTree
                entityTree.ParentBaseEntityTree = this;

                // 添加到集合
                if (this.ChildrenEntityTree != null && this.ChildrenEntityTree.Count > 0)
                {
                    // 获取孩子节点集合中的最后一个
                    BaseEntityTree lastBaseEntityTree = this.ChildrenEntityTree.Last();
                    // 设置lastBaseEntityTree的同级下节点为当前 新添加孩子节点
                    if (lastBaseEntityTree != null)
                    {
                        lastBaseEntityTree.NextBaseEntityTree = entityTree;
                        // 设置当前新添节点的同级上节点为lastBaseEntityTree
                        entityTree.PrevBaseEntityTree = lastBaseEntityTree;
                    }
                }
                // 添加到当前集合
                this.ChildrenEntityTree.Add(entityTree);
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(message);
        }