简单分页计算类

/// <summary>
    /// 简单分页列表类
    /// </summary>
    public class SimplePagedList
    {
        /// <summary>
        /// 每页页面大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 页面总数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 首页页面Index
        /// </summary>
        public int FirstPageIndex { get; set; }

        /// <summary>
        /// .ctor
        /// </summary>
        /// <param name="totalCount">列表总数</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="firstPageIndex">首页页面Index</param>
        public SimplePagedList(int totalCount, int pageSize, int firstPageIndex = 1)
        {
            TotalCount = totalCount;
            PageSize = pageSize;
            FirstPageIndex = firstPageIndex;
        }

        /// <summary>
        /// 总页面数
        /// </summary>
        public int PageCount
        {
            get { return TotalCount % PageSize == 0 ? TotalCount / PageSize : TotalCount / PageSize + 1; }
        }

        /// <summary>
        /// 根据页面索引计算当前页在列表中的区间上限
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public int GetStartIndex(int pageIndex)
        {
            return (pageIndex - 1) * PageSize + 1;
        }

        /// <summary>
        /// 根据页面索引计算当前页在列表中的区间下限
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public int GetEndIndex(int pageIndex)
        {
            return (pageIndex * PageSize);
        }
    }

 

posted @ 2017-12-18 18:03  zslm___  阅读(366)  评论(0编辑  收藏  举报