• 分页类


    /// <summary>
        /// 分页列表类
        /// </summary>
        public class PagedList<T>
        {
            /// <summary>
            /// 每页页面大小
            /// </summary>
            public int PageSize { get; private set; }
    
            /// <summary>
            /// 页面总数
            /// </summary>
            public int TotalCount { get; private set; }
    
            /// <summary>
            /// 首页页面Index
            /// </summary>
            public IEnumerable<T> Items { get; private set; }
    
            /// <summary>
            /// .ctor
            /// </summary>
            /// <param name="items">总列表</param>
            /// <param name="pageSize">每页大小</param>
            public PagedList(IEnumerable<T> items, int pageSize)
            {
                PageSize = pageSize;
                TotalCount = items.Count();
                Items = items;
            }
    
            /// <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);
            }
    
            /// <summary>
            /// 根据页面索引获得列表中对应的数据
            /// </summary>
            /// <param name="pageIdx"></param>
            /// <returns></returns>
            public IEnumerable<T> SubItems(int pageIdx)
            {
                return this.Items.Skip(GetStartIndex(pageIdx)-1).Take(PageSize);
            }
        }
  • 相关阅读:
    pat甲级1004 Counting Leaves
    pat甲级1003 Emergency
    pat甲级1002 A+B for Polynomials
    pat甲级1001 A+B Format
    【转载】sql注入之入门
    JavaScript基础学习笔记
    django 安装
    python web编程CGI
    python urllib库
    python数据库编程
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/8058917.html
Copyright © 2020-2023  润新知