You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace POSV.Utils
{
/// <summary>
/// List分页
/// </summary>
/// <typeparam name="T"></typeparam>
public class ListPager<T> : List<T>
{
/// <summary>
/// 总记录
/// </summary>
public int TotalCount { get; set; }
/// <summary>
/// 总页数
/// </summary>
public int PageCount { get; set; } //总页数
/// <summary>
/// 当前页码
/// </summary>
public int PageNumber { get; set; }
/// <summary>
/// 每页显示记录数
/// </summary>
public int PageSize { get; set; } //每页显示记录数
//是否有上一页
public bool HasPreviousPage
{
get { return PageNumber > 1; }
}
//是否有下一页
public bool HasNextPage
{
get { return PageNumber < this.PageCount; }
}
/// <summary>
/// 构造方法
/// </summary>
/// <param name="dataList"></param>
/// <param name="pageSize"></param>
/// <param name="pageNo"></param>
public ListPager(List<T> data , int pageSize , int pageNumber)
{
this.PageSize = pageSize;
this.PageNumber = pageNumber;
this.TotalCount = data.Count;
this.PageCount = (this.TotalCount + this.PageSize - 1) / this.PageSize;
this.AddRange(data.Skip((pageNumber - 1) * pageSize).Take(pageSize));
}
}
}