/// 页面分页数据显示
/// </summary>
public interface IDataResponse
{
/// <summary>
/// 总记录数
/// </summary>
int TotalCount { get; }
/// <summary>
/// 每页记录数
/// </summary>
int PageSize { get; }
/// <summary>
/// 总页数
/// </summary>
int TotalPage { get; }
/// <summary>
/// 当前页
/// </summary>
int PageIndex { get; }
/// <summary>
/// 是否有上一页
/// </summary>
bool HasPrevious { get; }
/// <summary>
/// 是否有下一页
/// </summary>
bool HasNext { get; }
/// <summary>
/// 是否分页
/// </summary>
bool IsPage { get; }
}
public class DataResponse<T>:IDataResponse
{
/// <summary>
/// 总记录数
/// </summary>
private int totalCount;
public int TotalCount
{
get { return totalCount; }
set
{
if (value < 0)
totalCount = 0;
else
totalCount = value;
}
}
/// <summary>
/// 是否分页
/// </summary>
private bool isPage = false;
public bool IsPage
{
get { return isPage; }
set { isPage = value; }
}
/// <summary>
/// 每页记录数
/// </summary>
private int pageSize;
public int PageSize
{
get { return pageSize; }
set
{
if (value <= 0)
pageSize = 10;
else
pageSize = value;
}
}
/// <summary>
/// 总页数
/// </summary>
public int TotalPage
{
get
{
if (TotalCount == 0)
return 1;
if (TotalCount % PageSize == 0)
return TotalCount / PageSize;
else
return TotalCount / PageSize + 1;
}
}
/// <summary>
/// 当前页码
/// </summary>
private int pageIndex;
public int PageIndex
{
get { return pageIndex; }
set
{
if (value <= 0)
pageIndex = 1;
else if (value > TotalPage)
pageIndex = TotalPage;
else
pageIndex = value;
}
}
/// <summary>
/// 是否有上一页
/// </summary>
public bool HasPrevious
{
get
{
if (PageIndex == 1)
return false;
return true;
}
}
/// <summary>
/// 是否有下一页
/// </summary>
public bool HasNext
{
get
{
if (PageIndex != TotalPage)
return true;
return false;
}
}
/// <summary>
/// 用于返回实际保存的结果
/// </summary>
private List<T> dataList;
public List<T> DataList
{
get { return dataList; }
set { dataList = value; }
}
public DataResponse()
{
TotalCount = 0;
PageSize = 10;
PageIndex = 1;
DataList = new List<T>(0);
}
}