|
|
@ -10,13 +10,13 @@ namespace Tool
|
|
|
|
public class PagedList<T>
|
|
|
|
public class PagedList<T>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public List<T> Items { get; private set; } // 存储当前页的元素
|
|
|
|
public List<T> Items { get; private set; } // 存储当前页的元素
|
|
|
|
public int PageIndex { get; private set; } // 当前页码(从0开始)
|
|
|
|
public int PageIndex { get; private set; } // 当前页码(从1开始)
|
|
|
|
public int PageSize { get; private set; } // 每页的元素数
|
|
|
|
public int PageSize { get; private set; } // 每页的元素数
|
|
|
|
public int TotalCount { get; private set; } // 总记录数
|
|
|
|
public int TotalCount { get; private set; } // 总记录数
|
|
|
|
public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize); // 总页数
|
|
|
|
public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize); // 总页数
|
|
|
|
|
|
|
|
|
|
|
|
public bool HasPreviousPage => PageIndex > 0;
|
|
|
|
|
|
|
|
public bool HasNextPage => PageIndex + 1 < TotalPages;
|
|
|
|
public bool HasNextPage => PageIndex < TotalPages;
|
|
|
|
|
|
|
|
|
|
|
|
public PagedList(List<T> items, int count, int pageIndex, int pageSize)
|
|
|
|
public PagedList(List<T> items, int count, int pageIndex, int pageSize)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -25,13 +25,5 @@ namespace Tool
|
|
|
|
PageIndex = pageIndex;
|
|
|
|
PageIndex = pageIndex;
|
|
|
|
PageSize = pageSize;
|
|
|
|
PageSize = pageSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 工厂方法,用于创建分页列表
|
|
|
|
|
|
|
|
public static PagedList<T> Create(IList<T> source, int pageIndex, int pageSize)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var count = source.Count; // 总记录数
|
|
|
|
|
|
|
|
var items = source.Skip(pageIndex * pageSize).Take(pageSize).ToList(); // 获取当前页的元素
|
|
|
|
|
|
|
|
return new PagedList<T>(items, count, pageIndex, pageSize);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|