首页 > 代码库 > 【C#公共帮助类】分页逻辑处理类

【C#公共帮助类】分页逻辑处理类

分页逻辑处理类 PageCollection.cs
技术分享
  1 using System;  2 using System.Collections.Generic;  3 using System.Linq;  4 using System.Text;  5   6 namespace Common  7 {  8     /// <summary>  9     /// 分页逻辑处理类 10     /// </summary> 11     public class PageCollection 12     { 13         /// <summary> 14         /// 总页数 15         /// </summary> 16         public int TotalPages { get; set; } 17         /// <summary> 18         /// 当前页面 19         /// </summary> 20         public int CurrentPage { get; set; } 21         /// <summary> 22         /// 每页的记录数 23         /// </summary> 24         public int OnePageSize { get; set; } 25         /// <summary> 26         /// 总记录数 27         /// </summary> 28         public long TotalRows { get; set; } 29         /// <summary> 30         /// 排序 31         /// </summary> 32         public string OrderBy { get; set; } 33  34         /// <summary> 35         /// 构造无参默认为最大数 36         /// </summary> 37         public PageCollection() 38         { 39             this.CurrentPage = 0; 40             this.OnePageSize = 20;//默认最大行数20条 41         } 42     } 43     /// <summary> 44     /// 分页逻辑处理类 linq to entites 45     /// </summary> 46     public class PageInfo<TEntity> where TEntity : class 47     { 48         public PageInfo(int index, int pageSize, int count, List<TEntity> list,string url="") 49         { 50             Index = index; 51             PageSize = pageSize; 52             Count = count; 53             List = list; 54             Url = url; 55             //计算数据条数从开始到结束的值 56             if (count == 0) 57             { 58                 BeginPage = 0; 59                 EndPage = 0; 60             } 61             else 62             { 63                 int maxpage = count / pageSize; 64  65                 if (count % pageSize > 0) 66                 { 67                     maxpage++; 68                 } 69                 if (index >= maxpage) 70                 { 71                     index = maxpage; 72  73                     BeginPage = pageSize * index - pageSize + 1; 74                     EndPage = count; 75                 } 76                 else 77                 { 78                     BeginPage = pageSize * index - pageSize + 1; 79                     EndPage = pageSize * index; 80                 } 81             } 82         } 83  84         public int Index { get; private set; } 85         public int PageSize { get; private set; } 86         public int Count { get; private set; } 87         public List<TEntity> List { get; set; } 88         public string Url { get; set; } 89         public int BeginPage { get; private set; } 90         public int EndPage { get; private set; } 91     } 92  93     /// <summary> 94     /// 分页逻辑处理类 dynamic 95     /// </summary> 96     public class PageInfo  97     { 98         public PageInfo(int index, int pageSize, int count, dynamic list, string url = "") 99         {100             Index = index;101             PageSize = pageSize;102             Count = count;103             List = list;104             Url = url;105             //计算数据条数从开始到结束的值106             if (count == 0)107             {108                 BeginPage = 0;109                 EndPage = 0;110             }111             else112             {113                 int maxpage = count / pageSize;114 115                 if (count % pageSize > 0)116                 {117                     maxpage++;118                 }119                 if (index >= maxpage)120                 {121                     index = maxpage;122 123                     BeginPage = pageSize * index - pageSize + 1;124                     EndPage = count;125                 }126                 else127                 {128                     BeginPage = pageSize * index - pageSize + 1;129                     EndPage = pageSize * index;130                 }131             }132         }133 134         public int Index { get; private set; }135         public int PageSize { get; private set; }136         public int Count { get; private set; }137         public dynamic List { get; private set; }138         public string Url { get; set; }139         public int BeginPage { get; private set; }140         public int EndPage { get; private set; }141     }142 143     /// <summary>144     /// Eazyui分页处理逻辑类145     /// </summary>146     public class PageEazyUi 147     {148         public PageEazyUi(int _page, int _pagesize, int _total, object _rows)149         {150             page = _page;151             pagesize = _pagesize;152             total = _total;153             rows = _rows;154         }155 156         public int page { get; private set; }157         public int pagesize { get; private set; }158         public int total { get; private set; }159         public object rows { get; private set; }160     }161 }

【C#公共帮助类】分页逻辑处理类