Example #1
0
        /// <summary>
        /// 获取所有页码
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        private static string GetPageAll(PaginationEntity pagination)
        {
            if (!pagination.IsShowAll)
            {
                return(string.Empty);
            }

            return(PageAll.Replace("@url", "href='" + GetUrl(pagination, pagination.CurrentPage, true) + "'"));
        }
Example #2
0
        /// <summary>
        /// 获取分页信息
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageSimplifyInfo(PaginationEntity pagination, int totalPage)
        {
            if (!pagination.IsShowSimplifyInfo)
            {
                return(string.Empty);
            }

            string pageSimplifyInfo = PageSimplifyInfo;

            pageSimplifyInfo = pageSimplifyInfo.Replace("@CurrentPage", pagination.CurrentPage.ToString());
            pageSimplifyInfo = pageSimplifyInfo.Replace("@TotalPage", totalPage.ToString());
            return(pageSimplifyInfo);
        }
Example #3
0
        /// <summary>
        /// 获取分页信息
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageInfo(PaginationEntity pagination, int totalPage)
        {
            if (!pagination.IsShowInfo)
            {
                return(string.Empty);
            }

            string pageInfo = PageInfo;

            pageInfo = pageInfo.Replace("@RecordCount", pagination.RecordCount.ToString());
            pageInfo = pageInfo.Replace("@PageSize", pagination.PageSize.ToString());
            pageInfo = pageInfo.Replace("@CurrentPage", pagination.CurrentPage.ToString());
            pageInfo = pageInfo.Replace("@TotalPage", totalPage.ToString());

            return(pageInfo);
        }
Example #4
0
        /// <summary>
        /// 获得分页内容
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public static string GetPage(PaginationEntity pagination)
        {
            if (pagination == null)
            {
                return(string.Empty);
            }

            int pageCount = 1;

            if (pagination.RecordCount != 0)
            {
                if (pagination.RecordCount % pagination.PageSize == 0)
                {
                    pageCount = pagination.RecordCount / pagination.PageSize; // 获得总页数
                }
                else
                {
                    pageCount = (pagination.RecordCount / pagination.PageSize) + 1; // 获得总页数
                }
            }

            if (pageCount <= 1 && !pagination.OnlyOneIsShow)
            {
                return(string.Empty);
            }

            if (pageCount < pagination.CurrentPage)
            {
                pagination.CurrentPage = pageCount;
            }

            string pageMaster = PageMaster;

            pageMaster = pageMaster.Replace("@pageInfo", GetPageInfo(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageFirst", GetPageFirst(pagination));
            pageMaster = pageMaster.Replace("@pagePrevious", GetPagePrevious(pagination));
            pageMaster = pageMaster.Replace("@pageNumber", GetPageNumber(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageSimplifyInfo", GetPageSimplifyInfo(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageAll", GetPageAll(pagination));
            pageMaster = pageMaster.Replace("@pageNext", GetPageNext(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageLast", GetPageLast(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageGo", GetPageGo(pagination, pageCount));

            return(pageMaster);
        }
Example #5
0
        /// <summary>
        /// 获取url
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="pageIndex"></param>
        /// <param name="isAll">是否为全部url</param>
        /// <returns></returns>
        private static string GetUrl(PaginationEntity pagination, int pageIndex, bool isAll = false)
        {
            if (pagination == null)
            {
                return(string.Empty);
            }

            switch (pagination.UrlFormat)
            {
            case UrlFormat.Dynamic1:
                // 如果有参数则直接加page参数
                string url;
                if (pagination.Url.Contains("?"))
                {
                    url = pagination.Url + "&page=" + pageIndex;
                }
                else
                {
                    url = pagination.Url + "?page=" + pageIndex;
                }
                return(url);

            case UrlFormat.Static1:
                return(pagination.Url + "-" + pageIndex + "." + pagination.StaticExtension.Replace(".", string.Empty));

            case UrlFormat.Static2:
                if (isAll)
                {
                    return(pagination.Url + "-0-0-1." + pagination.StaticExtension.Replace(".", string.Empty));
                }
                return(pagination.Url + "-" + pageIndex + "-" + pagination.PageSize + "-0." + pagination.StaticExtension.Replace(".", string.Empty));

            case UrlFormat.Placeholder:
                return(pagination.Url.Replace("{page}", pageIndex.ToString()).Replace("{pagesize}", pagination.PageSize.ToString()).Replace("{sort}", pagination.Sort.ToString()));
            }

            return(string.Empty);
        }
Example #6
0
        /// <summary>
        /// 获得分页内容
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public static string GetPage(PaginationEntity pagination)
        {
            if (pagination == null)
                return string.Empty;

            int pageCount = 1;
            if (pagination.RecordCount != 0)
            {
                if (pagination.RecordCount % pagination.PageSize == 0)
                {
                    pageCount = pagination.RecordCount / pagination.PageSize; // 获得总页数
                }
                else
                {
                    pageCount = (pagination.RecordCount / pagination.PageSize) + 1; // 获得总页数
                }
            }

            if (pageCount <= 1 && !pagination.OnlyOneIsShow)
                return string.Empty;

            if (pageCount < pagination.CurrentPage)
                pagination.CurrentPage = pageCount;

            string pageMaster = PageMaster;

            pageMaster = pageMaster.Replace("@pageInfo", GetPageInfo(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageFirst", GetPageFirst(pagination));
            pageMaster = pageMaster.Replace("@pagePrevious", GetPagePrevious(pagination));
            pageMaster = pageMaster.Replace("@pageNumber", GetPageNumber(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageSimplifyInfo", GetPageSimplifyInfo(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageAll", GetPageAll(pagination));
            pageMaster = pageMaster.Replace("@pageNext", GetPageNext(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageLast", GetPageLast(pagination, pageCount));
            pageMaster = pageMaster.Replace("@pageGo", GetPageGo(pagination, pageCount));

            return pageMaster;
        }
Example #7
0
        /// <summary>
        /// 获取跳转页
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageGo(PaginationEntity pagination, int totalPage)
        {
            if (!pagination.IsShowGo)
            {
                return(string.Empty);
            }

            var subHtml = new StringBuilder();

            for (int i = 1; i <= totalPage; i++)
            {
                string pageGoSub = PageGoSub;
                pageGoSub = pageGoSub.Replace("@selected", i == pagination.CurrentPage ? "selected" : string.Empty);
                pageGoSub = pageGoSub.Replace("@value", GetUrl(pagination, i));
                pageGoSub = pageGoSub.Replace("@index", i.ToString());
                subHtml.Append(pageGoSub);
            }

            string pageGo = PageGo;

            pageGo = pageGo.Replace("@Subset", subHtml.ToString());
            return(pageGo);
        }
Example #8
0
        /// <summary>
        /// 获取跳到第一页
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        private static string GetPageFirst(PaginationEntity pagination)
        {
            if (!pagination.IsShowFirstPageAndLastPage)
            {
                return(string.Empty);
            }

            string pageFirst = PageFirst;
            string url;

            // 如果为第一页,就不跳转
            if (pagination.CurrentPage <= 1)
            {
                if (pagination.IsDisabledFirstPageAndLastPage)
                {
                    pageFirst = pageFirst.Replace("@disabled", "disabled=disabled");
                    url       = string.Empty;
                }
                else
                {
                    return(string.Empty);
                }
            }
            else
            {
                pageFirst = pageFirst.Replace("@disabled", string.Empty);
                url       = GetUrl(pagination, 1);
                if (!string.IsNullOrEmpty(url))
                {
                    url = "href='" + url + "'";
                }
            }

            pageFirst = pageFirst.Replace("@url", url);
            pageFirst = pageFirst.Replace("@FirstInnerText", pagination.FirstInnerText);
            return(pageFirst);
        }
Example #9
0
        /// <summary>
        /// 获取最后一页
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageLast(PaginationEntity pagination, int totalPage)
        {
            if (pagination.IsShowFirstPageAndLastPage == false)
            {
                return(string.Empty);
            }

            string pageLast = PageLast;
            string url;

            if (pagination.CurrentPage >= totalPage)
            {
                if (pagination.IsDisabledFirstPageAndLastPage)
                {
                    pageLast = pageLast.Replace("@disabled", "disabled=disabled");
                    url      = string.Empty;
                }
                else
                {
                    return(string.Empty);
                }
            }
            else
            {
                pageLast = pageLast.Replace("@disabled", string.Empty);
                url      = GetUrl(pagination, totalPage);
                if (!string.IsNullOrEmpty(url))
                {
                    url = "href='" + url + "'";
                }
            }

            pageLast = pageLast.Replace("@url", url);
            pageLast = pageLast.Replace("@LastInnerText", pagination.LastInnerText);
            return(pageLast);
        }
Example #10
0
        /// <summary>
        /// 获取下一页
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageNext(PaginationEntity pagination, int totalPage)
        {
            if (!pagination.IsShowPreviousAndNext)
            {
                return(string.Empty);
            }

            string pageNext = PageNext;
            string url;

            if (pagination.CurrentPage >= totalPage)
            {
                if (pagination.IsDisabledPreviousAndNext)
                {
                    pageNext = pageNext.Replace("@disabled", "disabled=disabled");
                    url      = string.Empty;
                }
                else
                {
                    return(string.Empty);
                }
            }
            else
            {
                pageNext = pageNext.Replace("@disabled", string.Empty);
                url      = GetUrl(pagination, pagination.CurrentPage + 1);
                if (!string.IsNullOrEmpty(url))
                {
                    url = "href='" + url + "'";
                }
            }

            pageNext = pageNext.Replace("@url", url);
            pageNext = pageNext.Replace("@NextInnerText", pagination.NextInnerText);
            return(pageNext);
        }
Example #11
0
        /// <summary>
        /// 获取跳到上一页
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        private static string GetPagePrevious(PaginationEntity pagination)
        {
            if (!pagination.IsShowPreviousAndNext)
            {
                return(string.Empty);
            }

            string pagePrevious = PagePrevious;
            string url;

            if (pagination.CurrentPage <= 1)
            {
                if (pagination.IsDisabledPreviousAndNext)
                {
                    pagePrevious = pagePrevious.Replace("@disabled", "disabled=disabled");
                    url          = string.Empty;
                }
                else
                {
                    return(string.Empty);
                }
            }
            else
            {
                pagePrevious = pagePrevious.Replace("@disabled", string.Empty);
                url          = GetUrl(pagination, pagination.CurrentPage - 1);
                if (!string.IsNullOrEmpty(url))
                {
                    url = "href='" + url + "'";
                }
            }

            pagePrevious = pagePrevious.Replace("@url", url);
            pagePrevious = pagePrevious.Replace("@PreviousInnerText", pagination.PreviousInnerText);
            return(pagePrevious);
        }
Example #12
0
        /// <summary>
        /// 获取所有页码
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        private static string GetPageAll(PaginationEntity pagination)
        {
            if (!pagination.IsShowAll) return string.Empty;

            return PageAll.Replace("@url", "href='" + GetUrl(pagination, pagination.CurrentPage, true) + "'");
        }
Example #13
0
        /// <summary>
        /// 获取跳转页
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageGo(PaginationEntity pagination, int totalPage)
        {
            if (!pagination.IsShowGo) return string.Empty;

            var subHtml = new StringBuilder();
            for (int i = 1; i <= totalPage; i++)
            {
                string pageGoSub = PageGoSub;
                pageGoSub = pageGoSub.Replace("@selected", i == pagination.CurrentPage ? "selected" : string.Empty);
                pageGoSub = pageGoSub.Replace("@value", GetUrl(pagination, i));
                pageGoSub = pageGoSub.Replace("@index", i.ToString());
                subHtml.Append(pageGoSub);
            }

            string pageGo = PageGo;
            pageGo = pageGo.Replace("@Subset", subHtml.ToString());
            return pageGo;
        }
Example #14
0
        /// <summary>
        /// 获取分页数字
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageNumber(PaginationEntity pagination, int totalPage)
        {
            if (pagination.IsShowPageNumber == false)
            {
                return(string.Empty);
            }

            int number = pagination.ShowPageNumber == -1
                             ? totalPage
                             : pagination.ShowPageNumber > 0 ? pagination.ShowPageNumber : 10;
            var numberHtml = new StringBuilder();

            if (number > totalPage || pagination.ShowPageNumber == -1)
            {
                for (int i = 1; i <= totalPage; i++)
                {
                    string pageIndex        = PageIndex;
                    string pageCurrentIndex = PageCurrentIndex;
                    string url = GetUrl(pagination, i);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    if (i == pagination.CurrentPage)
                    {
                        pageCurrentIndex = pageCurrentIndex.Replace("@url", string.Empty);
                        pageCurrentIndex = pageCurrentIndex.Replace("@index", i.ToString());
                        numberHtml.Append(pageCurrentIndex);
                    }
                    else
                    {
                        pageIndex = pageIndex.Replace("@url", url);
                        pageIndex = pageIndex.Replace("@index", i.ToString());
                        numberHtml.Append(pageIndex);
                    }
                }
            }
            else
            {
                // 如果设置显示部分页码就将当前页显示在页码中间
                var avgNumber = pagination.ShowPageNumber == -1 ? number : number / 2;

                int before = avgNumber;
                int after  = number - avgNumber - 1;

                if (pagination.CurrentPage - before < 1)
                {
                    while (pagination.CurrentPage - before < 1)
                    {
                        before -= 1;
                        after  += 1;
                    }
                }
                else
                {
                    while (pagination.CurrentPage + after > totalPage)
                    {
                        before += 1;
                        after  -= 1;
                    }
                }

                // 如果前半部分还有页码未显示就显示省略号
                if (pagination.CurrentPage - before > 1 && pagination.IsShowMore)
                {
                    string pageMore = PageMore;
                    string url      = GetUrl(pagination, pagination.CurrentPage - before - 1);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    pageMore = pageMore.Replace("@url", url);
                    numberHtml.Append(pageMore);
                }

                // 显示前半部分页码
                for (int i = before; i > 0; i--)
                {
                    string pageIndex = PageIndex;
                    string url       = GetUrl(pagination, pagination.CurrentPage - i);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    pageIndex = pageIndex.Replace("@url", url);
                    pageIndex = pageIndex.Replace("@index", (pagination.CurrentPage - i).ToString());
                    numberHtml.Append(pageIndex);
                }

                string pageCurrentIndex = PageCurrentIndex;
                pageCurrentIndex = pageCurrentIndex.Replace("@url", string.Empty);
                pageCurrentIndex = pageCurrentIndex.Replace("@index", pagination.CurrentPage.ToString());
                numberHtml.Append(pageCurrentIndex);

                // 显示后半部分页码
                for (int i = 1; i <= after; i++)
                {
                    string pageIndex = PageIndex;

                    string url = GetUrl(pagination, pagination.CurrentPage + i);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    pageIndex = pageIndex.Replace("@url", url);
                    pageIndex = pageIndex.Replace("@index", (pagination.CurrentPage + i).ToString());
                    numberHtml.Append(pageIndex);
                }
                // 如何后半部分还有页码未显示则显示省略号
                if (pagination.CurrentPage + after < totalPage && pagination.IsShowMore)
                {
                    string pageIndex = PageIndex;
                    string url       = GetUrl(pagination, pagination.CurrentPage + after + 1);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    pageIndex = pageIndex.Replace("@url", url);
                    pageIndex = pageIndex.Replace("@index", "...");
                    numberHtml.Append(pageIndex);
                }
            }

            return(numberHtml.ToString());
        }
Example #15
0
        /// <summary>
        /// 获取分页信息
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageInfo(PaginationEntity pagination, int totalPage)
        {
            if (!pagination.IsShowInfo)
                return string.Empty;

            string pageInfo = PageInfo;

            pageInfo = pageInfo.Replace("@RecordCount", pagination.RecordCount.ToString());
            pageInfo = pageInfo.Replace("@PageSize", pagination.PageSize.ToString());
            pageInfo = pageInfo.Replace("@CurrentPage", pagination.CurrentPage.ToString());
            pageInfo = pageInfo.Replace("@TotalPage", totalPage.ToString());

            return pageInfo;
        }
Example #16
0
        /// <summary>
        /// 获取下一页
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageNext(PaginationEntity pagination, int totalPage)
        {
            if (!pagination.IsShowPreviousAndNext) return string.Empty;

            string pageNext = PageNext;
            string url;
            if (pagination.CurrentPage >= totalPage)
            {
                if (pagination.IsDisabledPreviousAndNext)
                {
                    pageNext = pageNext.Replace("@disabled", "disabled=disabled");
                    url = string.Empty;
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                pageNext = pageNext.Replace("@disabled", string.Empty);
                url = GetUrl(pagination, pagination.CurrentPage + 1);
                if (!string.IsNullOrEmpty(url))
                {
                    url = "href='" + url + "'";
                }
            }

            pageNext = pageNext.Replace("@url", url);
            pageNext = pageNext.Replace("@NextInnerText", pagination.NextInnerText);
            return pageNext;
        }
Example #17
0
        /// <summary>
        /// 获取最后一页
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageLast(PaginationEntity pagination, int totalPage)
        {
            if (pagination.IsShowFirstPageAndLastPage == false) return string.Empty;

            string pageLast = PageLast;
            string url;
            if (pagination.CurrentPage >= totalPage)
            {
                if (pagination.IsDisabledFirstPageAndLastPage)
                {
                    pageLast = pageLast.Replace("@disabled", "disabled=disabled");
                    url = string.Empty;
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                pageLast = pageLast.Replace("@disabled", string.Empty);
                url = GetUrl(pagination, totalPage);
                if (!string.IsNullOrEmpty(url))
                {
                    url = "href='" + url + "'";
                }
            }

            pageLast = pageLast.Replace("@url", url);
            pageLast = pageLast.Replace("@LastInnerText", pagination.LastInnerText);
            return pageLast;
        }
Example #18
0
        /// <summary>
        /// 获取跳到第一页
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        private static string GetPageFirst(PaginationEntity pagination)
        {
            if (!pagination.IsShowFirstPageAndLastPage)
                return string.Empty;

            string pageFirst = PageFirst;
            string url;
            // 如果为第一页,就不跳转
            if (pagination.CurrentPage <= 1)
            {
                if (pagination.IsDisabledFirstPageAndLastPage)
                {
                    pageFirst = pageFirst.Replace("@disabled", "disabled=disabled");
                    url = string.Empty;
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                pageFirst = pageFirst.Replace("@disabled", string.Empty);
                url = GetUrl(pagination, 1);
                if (!string.IsNullOrEmpty(url))
                {
                    url = "href='" + url + "'";
                }
            }

            pageFirst = pageFirst.Replace("@url", url);
            pageFirst = pageFirst.Replace("@FirstInnerText", pagination.FirstInnerText);
            return pageFirst;
        }
Example #19
0
        /// <summary>
        /// 获取分页数字
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageNumber(PaginationEntity pagination, int totalPage)
        {
            if (pagination.IsShowPageNumber == false) return string.Empty;

            int number = pagination.ShowPageNumber == -1
                             ? totalPage
                             : pagination.ShowPageNumber > 0 ? pagination.ShowPageNumber : 10;
            var numberHtml = new StringBuilder();
            if (number > totalPage || pagination.ShowPageNumber == -1)
            {
                for (int i = 1; i <= totalPage; i++)
                {
                    string pageIndex = PageIndex;
                    string pageCurrentIndex = PageCurrentIndex;
                    string url = GetUrl(pagination, i);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    if (i == pagination.CurrentPage)
                    {
                        pageCurrentIndex = pageCurrentIndex.Replace("@url", string.Empty);
                        pageCurrentIndex = pageCurrentIndex.Replace("@index", i.ToString());
                        numberHtml.Append(pageCurrentIndex);
                    }
                    else
                    {
                        pageIndex = pageIndex.Replace("@url", url);
                        pageIndex = pageIndex.Replace("@index", i.ToString());
                        numberHtml.Append(pageIndex);
                    }
                }
            }
            else
            {
                // 如果设置显示部分页码就将当前页显示在页码中间
                var avgNumber = pagination.ShowPageNumber == -1 ? number : number / 2;

                int before = avgNumber;
                int after = number - avgNumber - 1;

                if (pagination.CurrentPage - before < 1)
                {
                    while (pagination.CurrentPage - before < 1)
                    {
                        before -= 1;
                        after += 1;
                    }
                }
                else
                {
                    while (pagination.CurrentPage + after > totalPage)
                    {
                        before += 1;
                        after -= 1;
                    }
                }

                // 如果前半部分还有页码未显示就显示省略号
                if (pagination.CurrentPage - before > 1 && pagination.IsShowMore)
                {
                    string pageMore = PageMore;
                    string url = GetUrl(pagination, pagination.CurrentPage - before - 1);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    pageMore = pageMore.Replace("@url", url);
                    numberHtml.Append(pageMore);
                }

                // 显示前半部分页码
                for (int i = before; i > 0; i--)
                {
                    string pageIndex = PageIndex;
                    string url = GetUrl(pagination, pagination.CurrentPage - i);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    pageIndex = pageIndex.Replace("@url", url);
                    pageIndex = pageIndex.Replace("@index", (pagination.CurrentPage - i).ToString());
                    numberHtml.Append(pageIndex);
                }

                string pageCurrentIndex = PageCurrentIndex;
                pageCurrentIndex = pageCurrentIndex.Replace("@url", string.Empty);
                pageCurrentIndex = pageCurrentIndex.Replace("@index", pagination.CurrentPage.ToString());
                numberHtml.Append(pageCurrentIndex);

                // 显示后半部分页码
                for (int i = 1; i <= after; i++)
                {
                    string pageIndex = PageIndex;

                    string url = GetUrl(pagination, pagination.CurrentPage + i);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    pageIndex = pageIndex.Replace("@url", url);
                    pageIndex = pageIndex.Replace("@index", (pagination.CurrentPage + i).ToString());
                    numberHtml.Append(pageIndex);
                }
                // 如何后半部分还有页码未显示则显示省略号
                if (pagination.CurrentPage + after < totalPage && pagination.IsShowMore)
                {
                    string pageIndex = PageIndex;
                    string url = GetUrl(pagination, pagination.CurrentPage + after + 1);
                    if (!string.IsNullOrEmpty(url))
                    {
                        url = "href='" + url + "'";
                    }

                    pageIndex = pageIndex.Replace("@url", url);
                    pageIndex = pageIndex.Replace("@index", "...");
                    numberHtml.Append(pageIndex);
                }
            }

            return numberHtml.ToString();
        }
Example #20
0
        /// <summary>
        /// 获取url
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="pageIndex"></param>
        /// <param name="isAll">是否为全部url</param>
        /// <returns></returns>
        private static string GetUrl(PaginationEntity pagination, int pageIndex, bool isAll = false)
        {
            if (pagination == null)
                return string.Empty;

            switch (pagination.UrlFormat)
            {
                case UrlFormat.Dynamic1:
                    // 如果有参数则直接加page参数
                    string url;
                    if (pagination.Url.Contains("?"))
                    {
                        url = pagination.Url + "&page=" + pageIndex;
                    }
                    else
                    {
                        url = pagination.Url + "?page=" + pageIndex;
                    }
                    return url;
                case UrlFormat.Static1:
                    return pagination.Url + "-" + pageIndex + "." + pagination.StaticExtension.Replace(".", string.Empty);
                case UrlFormat.Static2:
                    if (isAll) return pagination.Url + "-0-0-1." + pagination.StaticExtension.Replace(".", string.Empty);
                    return pagination.Url + "-" + pageIndex + "-" + pagination.PageSize + "-0." + pagination.StaticExtension.Replace(".", string.Empty);
                case UrlFormat.Placeholder:
                    return pagination.Url.Replace("{page}", pageIndex.ToString()).Replace("{pagesize}", pagination.PageSize.ToString()).Replace("{sort}", pagination.Sort.ToString());
            }

            return string.Empty;
        }
Example #21
0
        /// <summary>
        /// 获取分页信息
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        private static string GetPageSimplifyInfo(PaginationEntity pagination, int totalPage)
        {
            if (!pagination.IsShowSimplifyInfo)
                return string.Empty;

            string pageSimplifyInfo = PageSimplifyInfo;
            pageSimplifyInfo = pageSimplifyInfo.Replace("@CurrentPage", pagination.CurrentPage.ToString());
            pageSimplifyInfo = pageSimplifyInfo.Replace("@TotalPage", totalPage.ToString());
            return pageSimplifyInfo;
        }
Example #22
0
        /// <summary>
        /// 获取跳到上一页
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        private static string GetPagePrevious(PaginationEntity pagination)
        {
            if (!pagination.IsShowPreviousAndNext)
                return string.Empty;

            string pagePrevious = PagePrevious;
            string url;
            if (pagination.CurrentPage <= 1)
            {
                if (pagination.IsDisabledPreviousAndNext)
                {
                    pagePrevious = pagePrevious.Replace("@disabled", "disabled=disabled");
                    url = string.Empty;
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                pagePrevious = pagePrevious.Replace("@disabled", string.Empty);
                url = GetUrl(pagination, pagination.CurrentPage - 1);
                if (!string.IsNullOrEmpty(url))
                {
                    url = "href='" + url + "'";
                }
            }

            pagePrevious = pagePrevious.Replace("@url", url);
            pagePrevious = pagePrevious.Replace("@PreviousInnerText", pagination.PreviousInnerText);
            return pagePrevious;
        }