Пример #1
0
        /// <summary>
        /// 递归创建树
        /// </summary>
        /// <param name="parent">父节点</param>
        /// <param name="listPost">帖子数组</param>
        private static void CreateTree(TreeNode <ForumPostEntity> parent, List <ForumPostEntity> listPost)
        {
            for (Int32 i = 0; i < listPost.Count; i++)
            {
                if (String.Equals(listPost[i].ParentPostID.ToString(), parent.Value))
                {
                    TreeNode <ForumPostEntity> node = new TreeNode <ForumPostEntity>(listPost[i].PostID.ToString(), listPost[i]);
                    parent.AddNote(node);
                    listPost.RemoveAt(i--);

                    ForumPostManager.CreateTree(node, listPost);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 创建树形列表
        /// </summary>
        /// <param name="topic">主题帖</param>
        /// <param name="postID">帖子ID</param>
        /// <returns>树形列表</returns>
        public static List <TreeNode <ForumPostEntity> > GetPostTreeList(ForumTopicEntity topic, Int32 postID)
        {
            List <ForumPostEntity> listPost = ForumPostManager.GetForumPostList(topic, false);

            if (listPost == null || listPost.Count == 0)
            {
                return(new List <TreeNode <ForumPostEntity> >());
            }

            //将主题帖放入树节点数组
            List <TreeNode <ForumPostEntity> > listTreeNode = new List <TreeNode <ForumPostEntity> >();

            //将父节点是帖子ID的节点放入树节点数组
            for (Int32 i = 0; i < listPost.Count; i++)
            {
                if (listPost[i].ParentPostID == postID)
                {
                    TreeNode <ForumPostEntity> node = new TreeNode <ForumPostEntity>(listPost[i].PostID.ToString(), listPost[i]);
                    listTreeNode.Add(node);
                    listPost.RemoveAt(i--);
                }
            }

            //根据树节点数组创建树
            if (listTreeNode.Count > 0)
            {
                for (Int32 i = 0; i < listTreeNode.Count; i++)
                {
                    ForumPostManager.CreateTree(listTreeNode[i], listPost);
                }

                return(listTreeNode);
            }
            else
            {
                return(new List <TreeNode <ForumPostEntity> >());
            }
        }
Пример #3
0
        /// <summary>
        /// 创建树形列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="pid">题目ID</param>
        /// <returns>树形列表</returns>
        public static PagedList <TreeNode <ForumPostEntity> > GetPostTreeList(Int32 pageIndex, String pid)
        {
            PagedList <ForumTopicEntity> listTopic = ForumTopicManager.GetForumTopicList(pageIndex, String.Empty, pid);
            List <ForumPostEntity>       listPost  = ForumPostManager.GetForumPostList(listTopic, false);

            if (listPost == null || listPost.Count == 0)
            {
                return(PagedList <TreeNode <ForumPostEntity> > .Empty);
            }

            //将主题帖放入树节点数组
            List <TreeNode <ForumPostEntity> > listTreeNode = new List <TreeNode <ForumPostEntity> >();
            List <ForumPostEntity>             listRoot     = new List <ForumPostEntity>();

            //找出所有根节点
            for (Int32 i = 0; i < listPost.Count; i++)
            {
                if (listPost[i].Deepth == 0)
                {
                    listRoot.Add(listPost[i]);
                    listPost.RemoveAt(i--);
                }
            }

            //将Topic的Type和RelativeID写入Post中
            for (Int32 i = 0; i < listTopic.Count; i++)
            {
                for (Int32 j = 0; j < listRoot.Count; j++)
                {
                    if (listRoot[j].TopicID == listTopic[i].TopicID)
                    {
                        if (listTopic[i].Type != ForumTopicType.Default)
                        {
                            listRoot[j].RelativeType = listTopic[i].Type;
                            listRoot[j].RelativeID   = listTopic[i].RelativeID;
                        }

                        TreeNode <ForumPostEntity> node = new TreeNode <ForumPostEntity>(listRoot[j].PostID.ToString(), listRoot[j]);
                        listTreeNode.Add(node);
                        listRoot.RemoveAt(j);

                        break;
                    }
                }
            }

            //根据树节点数组创建树
            if (listTreeNode.Count > 0)
            {
                for (Int32 i = 0; i < listTreeNode.Count; i++)
                {
                    ForumPostManager.CreateTree(listTreeNode[i], listPost);
                }

                return(listTreeNode.ToPagedList(listTopic.PageSize, listTopic.RecordCount));
            }
            else
            {
                return(PagedList <TreeNode <ForumPostEntity> > .Empty);
            }
        }