【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             else
112             {
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                 else
127                 {
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 }
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM