using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ant.Service.Common
{
///
/// 分页逻辑处理类
///
public class PageCollection
{
///
/// 总页数
///
public int TotalPages { get; set; }
///
/// 当前页面
///
public int CurrentPage { get; set; }
///
/// 每页的记录数
///
public int OnePageSize { get; set; }
///
/// 总记录数
///
public long TotalRows { get; set; }
///
/// 排序
///
public string OrderBy { get; set; }
///
/// 构造无参默认为最大数
///
public PageCollection()
{
this.CurrentPage = 0;
this.OnePageSize = 20;//默认最大行数20条
}
///
///
///
///
///
///
public static Tuple GetSkipLimit(int pageIndex, int pageSize)
{
if (pageIndex <= 0 || pageSize <= 0)
{
return new Tuple(0, 1);
}
return new Tuple((pageIndex - 1) * pageSize, pageSize);
}
}
///
/// 分页逻辑处理类 linq to entites
///
public class PageInfo where TEntity : class
{
public PageInfo(int index, int pageSize, int count, List list,string url="")
{
Index = index;
PageSize = pageSize;
Count = count;
List = list;
Url = url;
//计算数据条数从开始到结束的值
if (count == 0)
{
BeginPage = 0;
EndPage = 0;
}
else
{
int maxpage = count / pageSize;
if (count % pageSize > 0)
{
maxpage++;
}
if (index >= maxpage)
{
index = maxpage;
BeginPage = pageSize * index - pageSize + 1;
EndPage = count;
}
else
{
BeginPage = pageSize * index - pageSize + 1;
EndPage = pageSize * index;
}
}
}
public int Index { get; private set; }
public int PageSize { get; private set; }
public int Count { get; private set; }
public List List { get; set; }
public string Url { get; set; }
public int BeginPage { get; private set; }
public int EndPage { get; private set; }
}
///
/// 分页逻辑处理类 dynamic
///
public class PageInfo
{
public PageInfo(int index, int pageSize, int count, dynamic list, string url = "")
{
Index = index;
PageSize = pageSize;
Count = count;
List = list;
Url = url;
//计算数据条数从开始到结束的值
if (count == 0)
{
BeginPage = 0;
EndPage = 0;
}
else
{
int maxpage = count / pageSize;
if (count % pageSize > 0)
{
maxpage++;
}
if (index >= maxpage)
{
index = maxpage;
BeginPage = pageSize * index - pageSize + 1;
EndPage = count;
}
else
{
BeginPage = pageSize * index - pageSize + 1;
EndPage = pageSize * index;
}
}
}
///
/// 当前页
///
public int Index { get; private set; }
///
/// 每页显示的条数
///
public int PageSize { get; private set; }
///
/// 总记录数
///
public int Count { get; private set; }
///
/// 列表
///
public dynamic List { get; private set; }
public string Url { get; set; }
///
/// 起始页
///
public int BeginPage { get; private set; }
///
/// 结束页
///
public int EndPage { get; private set; }
}
///
/// Eazyui分页处理逻辑类
///
public class PageEazyUi
{
public PageEazyUi(int _page, int _pagesize, int _total, object _rows)
{
page = _page;
pagesize = _pagesize;
total = _total;
rows = _rows;
}
public int page { get; private set; }
public int pagesize { get; private set; }
public int total { get; private set; }
public object rows { get; private set; }
}
}