예제 #1
0
        protected string GetThreadPager(BasicThread thread, string style, string urlStyle, string type, bool typeIsExtParms, string codeName, int listPage)
        {
            if (thread == null || thread.RedirectThreadID < 1)
            {
                return(string.Empty);
            }

            if (thread.ThreadType == ThreadType.Polemize)
            {
                return(string.Empty);
            }

            int totalPosts;

            if (type != null && SystemForum.UnapprovePosts.ToString().ToLower() == type.ToLower())
            {
                totalPosts = thread.UnApprovedPostsCount;
            }
            else
            {
                if (thread.ThreadType == ThreadType.Question && thread.IsClosed)////减掉最佳答案那个回复,最佳答案单独显示[这里有个问题,如果最佳答案被删除了,统计又与其他主题一样(未解决)]
                {
                    totalPosts = thread.TotalReplies;
                }
                else
                {
                    totalPosts = thread.TotalReplies + 1;
                }
            }

            int postsPageSize = AllSettings.Current.BbsSettings.PostsPageSize;
            int totalPage     = totalPosts % postsPageSize == 0 ? totalPosts / postsPageSize : (totalPosts / postsPageSize + 1);

            if (totalPage < 1)
            {
                return(string.Empty);
            }

            Forum         forum = ForumBO.Instance.GetForum(thread.ForumID);
            StringBuilder sb    = new StringBuilder();

            string url;

            if (string.IsNullOrEmpty(codeName))
            {
                if (typeIsExtParms)
                {
                    url = BbsUrlHelper.GetThreadUrlForPagerExtParms(forum.CodeName, thread.RedirectThreadID, thread.ThreadTypeString, type);
                }
                else
                {
                    if (string.IsNullOrEmpty(type))
                    {
                        url = BbsUrlHelper.GetThreadUrlForPager(forum.CodeName, thread.RedirectThreadID, listPage, thread.ThreadTypeString);
                    }
                    else
                    {
                        url = BbsUrlHelper.GetThreadUrlForPager(forum.CodeName, thread.RedirectThreadID, thread.ThreadTypeString, type);
                    }
                }
            }
            else
            {
                if (typeIsExtParms)
                {
                    url = BbsUrlHelper.GetThreadUrlForPagerExtParms(forum.CodeName, thread.RedirectThreadID, thread.ThreadTypeString, type);
                }
                else
                {
                    if (string.IsNullOrEmpty(type))
                    {
                        url = BbsUrlHelper.GetThreadUrlForPager(codeName, thread.RedirectThreadID, listPage, thread.ThreadTypeString);
                    }
                    else
                    {
                        url = BbsUrlHelper.GetThreadUrlForPager(codeName, thread.RedirectThreadID, thread.ThreadTypeString, type);
                    }
                }
            }

            if (totalPage > 1 && totalPage <= 5)
            {
                for (int i = 1; i < totalPage + 1; i++)
                {
                    //string url=UrlHelper.GetThreadUrl(forum.CodeName, thread.RedirectThreadID, i);
                    //if (!string.IsNullOrEmpty(urlParams))
                    //    url = url + (url.IndexOf('?') > 0 ? "&" : "?") + urlParams;

                    sb.Append(string.Format(urlStyle, string.Format(url, i), i));
                    if (i < totalPage)
                    {
                        sb.Append(" ");
                    }
                }
            }
            else if (totalPage > 5)
            {
                for (int i = 1; i < totalPage + 1; i++)
                {
                    if (i < 3 || i > totalPage - 3)
                    {
                        sb.Append(string.Format(urlStyle, string.Format(url, i), i) + " ");
                    }
                    else if (i == 3)
                    {
                        sb.Append("... ");
                    }
                }
            }
            if (string.IsNullOrEmpty(style))
            {
                return(sb.ToString());
            }
            else
            {
                if (sb.Length > 0)
                {
                    return(string.Format(style, sb.ToString()));
                }
                else
                {
                    return("");
                }
            }
        }