/// <summary> /// 获取帖子列表 /// </summary> /// <param name="pageIndex">页面索引</param> /// <param name="fpids">帖子ID列表</param> /// <param name="ftids">主题ID列表</param> /// <param name="username">发帖用户名</param> /// <param name="title">帖子标题</param> /// <param name="content">帖子内容</param> /// <param name="isHide">是否隐藏</param> /// <param name="startDate">发帖开始时间</param> /// <param name="endDate">发帖结束时间</param> /// <param name="postip">发帖IP</param> /// <returns>帖子列表</returns> public static PagedList <ForumPostEntity> AdminGetForumPostList(Int32 pageIndex, String fpids, String ftids, String username, String title, String content, String isHide, String startDate, String endDate, String postip) { if (!AdminManager.HasPermission(PermissionType.ForumManage)) { throw new NoPermissionException(); } Int32 pageSize = AdminManager.ADMIN_LIST_PAGE_SIZE; Int32 recordCount = ForumPostManager.AdminCountForumPosts(fpids, ftids, username, title, content, isHide, startDate, endDate, postip); DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue; fpids = fpids.SearchOptimized(); ftids = ftids.SearchOptimized(); if (!String.IsNullOrEmpty(fpids) && !RegexVerify.IsNumericIDs(fpids)) { throw new InvalidRequstException(RequestType.ForumPost); } if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids)) { throw new InvalidRequstException(RequestType.ForumTopic); } return(ForumPostRepository.Instance .GetEntities(pageIndex, pageSize, recordCount, fpids, ftids, username, title, content, (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()), (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()), (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()), postip) .ToPagedList(pageSize, recordCount)); }
/// <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); } } }
/// <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> >()); } }
/// <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); } }