110,534
社区成员
发帖
与我相关
我的任务
分享
public class PagedList<T> : List<T>
{
/// <summary>
/// 分页编号
/// </summary>
public int intPageIndex { get; set; }
/// <summary>
/// 分页大小
/// </summary>
public int intPageSize { get; set; }
/// <summary>
/// 分页数
/// </summary>
public int intPages { get; set; }
/// <summary>
/// 总元素的个数
/// </summary>
public int intTotalCount { get; set; }
/// <summary>
/// 是否有下一页
/// </summary>
public bool HasNextPage { get; set; }
/// <summary>
/// 是否有上一页
/// </summary>
public bool HasPrPage { get; set; }
public PagedList(IQueryable<T> list, int intPageIndex, int intPageSize, int intPageCount)
{
intTotalCount = intPageCount;
if (intTotalCount % intPageSize == 0 && intTotalCount != 0) intPages = intTotalCount / intPageSize;
else intPages = intTotalCount / intPageSize + 1;
if (intPageIndex >= intPages) intPageIndex = intPages;
this.intPageIndex = intPageIndex;
this.intPageSize = intPageSize;
//var pageResult = list.Skip((intPageIndex - 1) * intPageSize).Take(intPageSize).ToList<T>();
//intCount = list.Count();
HasNextPage = this.intPageIndex < this.intPages ? true : false;
HasPrPage = this.intPageIndex > 1 ? true : false;
if (list!=null)
{
foreach (var t in list.ToList<T>())
{
this.Add(t);
}
}
}
public PagedList(List<T> list, int intPageIndex, int intPageSize, int intPageCount)
{
intTotalCount = intPageCount;
if (intTotalCount % intPageSize == 0 && intTotalCount != 0) intPages = intTotalCount / intPageSize;
else intPages = intTotalCount / intPageSize + 1;
if (intPageIndex >= intPages) intPageIndex = intPages;
this.intPageIndex = intPageIndex;
this.intPageSize = intPageSize;
//var pageResult = list.Skip((intPageIndex - 1) * intPageSize).Take(intPageSize).ToList<T>();
//intCount = list.Count();
HasNextPage = this.intPageIndex < this.intPages ? true : false;
HasPrPage = this.intPageIndex > 1 ? true : false;
if (list != null)
{
foreach (var t in list.ToList<T>())
{
this.Add(t);
}
}
}
public PagedList(IEnumerable<T> list, int intPageIndex, int intPageSize, int intPageCount)
: this(list as IQueryable<T>, intPageIndex, intPageSize, intPageCount)
{
}
/// <summary>
/// 下一页URL 自带搜索参数
/// </summary>
public string NextPageURL
{
get
{
string nextPageURL = RequestHelper.RawUrl;
int nextPage = this.intPageIndex + 1;
if (nextPage > this.intPages) return "javascript:;";
if (nextPageURL.ToLower().IndexOf("&page=") > -1)
{
nextPageURL = nextPageURL.Substring(0, nextPageURL.ToLower().IndexOf("&page=")) + "&page=";
}
else if (nextPageURL.ToLower().IndexOf("?page=") > -1)
{
nextPageURL = nextPageURL.Substring(0, nextPageURL.ToLower().IndexOf("?page=")) + "?page=";
}
else if (nextPageURL.ToLower().IndexOf("?") > -1)
{
if (nextPageURL.EndsWith("?"))
nextPageURL += "Page=";
else
nextPageURL += "&Page=";
}
else
{
nextPageURL += "?page=";
}
return nextPageURL + nextPage.ToString();
}
}
/// <summary>
/// 上一页URL 自带搜索参数
/// </summary>
public string PrevPageURL
{
get
{
string prevPageURL = RequestHelper.RawUrl;
int prevPage = this.intPageIndex - 1;
if (prevPage <= 0) return "javascript:;";
if (prevPageURL.ToLower().IndexOf("&page=") > -1)
{
prevPageURL = prevPageURL.Substring(0, prevPageURL.ToLower().IndexOf("&page=")) + "&page=";
}
else if (prevPageURL.ToLower().IndexOf("?page=") > -1)
{
prevPageURL = prevPageURL.Substring(0, prevPageURL.ToLower().IndexOf("?page=")) + "?page=";
}
else if (prevPageURL.ToLower().IndexOf("?") > -1)
{
if (prevPageURL.EndsWith("?"))
prevPageURL += "Page=";
else
prevPageURL += "&Page=";
}
else
{
prevPageURL += "?page=";
}
return prevPageURL + prevPage.ToString();
}
}
}