zoukankan      html  css  js  c++  java
  • 分页类

    /// <summary>
        ///     分页
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        public class PagedList<T> : List<T>
        {
            /// <summary>
            ///     缓存分页构造函数
            /// </summary>
            /// <param name="source">数据源</param>
            /// <param name="pageIndex">当前页页码</param>
            /// <param name="pageSize">每页显示记录数</param>
            public PagedList(IQueryable<T> source, int pageIndex, int pageSize)
            {
                if (source == null || !source.Any())
                    throw new ArgumentNullException("source");
    
                int total = source.Count();
                TotalCount = total;
                TotalPages = total/pageSize;
    
                if (total%pageSize > 0)
                    TotalPages++;
    
                PageSize = pageSize;
                PageIndex = pageIndex;
                AddRange(source.Skip(pageIndex*pageSize).Take(pageSize).ToList());
            }
    
            /// <summary>
            ///     缓存分页构造函数
            /// </summary>
            /// <param name="source">数据源</param>
            /// <param name="pageIndex">当前页页码</param>
            /// <param name="pageSize">每页显示记录数</param>
            public PagedList(IList<T> source, int pageIndex, int pageSize)
            {
                if (source == null || !source.Any())
                    throw new ArgumentNullException("source");
    
                TotalCount = source.Count();
                TotalPages = TotalCount/pageSize;
    
                if (TotalCount%pageSize > 0)
                    TotalPages++;
    
                PageSize = pageSize;
                PageIndex = pageIndex;
                AddRange(source.Skip(pageIndex*pageSize).Take(pageSize).ToList());
            }
    
            /// <summary>
            ///     非缓存分页构造函数
            /// </summary>
            /// <param name="source">数据源</param>
            /// <param name="pageIndex">当前页页码</param>
            /// <param name="pageSize">每页显示记录数</param>
            /// <param name="totalCount">总记录数</param>
            public PagedList(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount)
            {
                if (source == null || !source.Any())
                    throw new ArgumentNullException("source");
    
                TotalCount = totalCount;
                TotalPages = TotalCount/pageSize;
    
                if (TotalCount%pageSize > 0)
                    TotalPages++;
    
                PageSize = pageSize;
                PageIndex = pageIndex;
                AddRange(source);
            }
    
            /// <summary>
            ///     当前页页码
            /// </summary>
            public int PageIndex { get; private set; }
    
            /// <summary>
            ///     每页显示记录数
            /// </summary>
            public int PageSize { get; private set; }
    
            /// <summary>
            ///     总记录数
            /// </summary>
            public int TotalCount { get; private set; }
    
            /// <summary>
            ///     总页数
            /// </summary>
            public int TotalPages { get; private set; }
    
            /// <summary>
            ///     有上一页
            /// </summary>
            public bool HasPreviousPage
            {
                get { return (PageIndex > 0); }
            }
    
            /// <summary>
            ///     有下一页
            /// </summary>
            public bool HasNextPage
            {
                get { return (PageIndex + 1 < TotalPages); }
            }
        }
  • 相关阅读:
    poj2192
    poj2002
    poj2190
    poj2001
    poj2195
    自我成长:20岁到40岁的简单人生规划
    最容易让人失恋的十种职业
    职场发展的5W问题(对我影响很大)
    你个人知识管理了吗?
    安慰人的10大原则——当不知该说什么时
  • 原文地址:https://www.cnblogs.com/jes_shaw/p/4123740.html
Copyright © 2011-2022 走看看