using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkEntity.Common
{
///
/// 分页组件实体类
///
/// 泛型实体
[Serializable]
public class PageList : List, IPageList
{
///
/// 构造函数
///
/// 数据源
/// 分页索引
/// 分页大小
public PageList(IQueryable source, int pageIndex, int pageSize)
{
var total = source.Count();
TotalCount = total;
TotalPages = total / pageSize;
if (total % pageSize > 0)
TotalPages++;
PageSize = pageSize;
PageIndex = pageIndex;
AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList());
}
///
/// 构造函数
///
/// 数据源
/// 分页索引
/// 分页大小
public PageList(IList source, int pageIndex, int pageSize)
{
TotalCount = source.Count();
TotalPages = TotalCount / pageSize;
if (TotalCount % pageSize > 0)
TotalPages++;
PageSize = pageSize;
PageIndex = pageIndex;
AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList());
}
///
/// 构造函数
///
/// 数据源
/// 分页索引
/// 分页大小
/// 总记录数
public PageList(IEnumerable source, int pageIndex, int pageSize, int totalCount)
{
TotalCount = totalCount;
TotalPages = TotalCount / pageSize;
if (TotalCount % pageSize > 0)
TotalPages++;
PageSize = pageSize;
PageIndex = pageIndex;
AddRange(source);
}
///
/// 分页索引
///
public int PageIndex { get; }
///
/// 分页大小
///
public int PageSize { get; private set; }
///
/// 总记录数
///
public int TotalCount { get; }
///
/// 总页数
///
public int TotalPages { get; }
///
/// 是否有上一页
///
public bool HasPreviousPage => PageIndex > 0;
///
/// 是否有下一页
///
public bool HasNextPage => PageIndex + 1 < TotalPages;
}
}