輔助類using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Text;
/// <summary>
///MyPagination 的摘要說明
/// </summary>
public class MyPagination
{
public MyPagination()
{
//
//TODO: 在此處添加構(gòu)造函數(shù)邏輯
//
}
private int _count=0;
private string _tableName = "tableName";
private string _fldName = "Id";
private int _pageSize = 10;
private int _pageIndex = 1;
private int _orderType = 0;
private int _isCount = 0;
private string strWhere = "";
private string _curPage;
public string CurPage
{
get { return _curPage; }
set { _curPage = value; }
}
public int Count
{
get { return _count; }
set { _count = value; }
}
public string FldName
{
get { return _fldName; }
set { _fldName = value; }
}
public int PageSize
{
get { return _pageSize; }
set { _pageSize = value; }
}
public int PageIndex
{
get { return _pageIndex; }
set { _pageIndex = value; }
}
public int OrderType
{
get { return _orderType; }
set { _orderType = value; }
}
public int IsCount
{
get { return _isCount; }
set { _isCount = value; }
}
public string StrWhere
{
get { return strWhere; }
set { strWhere = value; }
}
public string TableName
{
get { return _tableName; }
set { _tableName = value; }
}
public SqlParameter[] GetParam()
{
SqlParameter[] sparam=new SqlParameter[]
{
new SqlParameter("@tblName",SqlDbType.VarChar),new SqlParameter("@fldName",SqlDbType.VarChar),new SqlParameter("@PageSize",SqlDbType.Int),
new SqlParameter("@PageIndex",SqlDbType.Int),new SqlParameter("@OrderType",SqlDbType.Int),new SqlParameter("@IsCount",SqlDbType.Int),
new SqlParameter("@strWhere",SqlDbType.VarChar)
};
sparam[0].Value = this.TableName;
sparam[1].Value = this.FldName;
sparam[2].Value = this.PageSize;
sparam[3].Value = this.PageIndex;
sparam[4].Value = this.OrderType;
sparam[5].Value = this.IsCount;
sparam[6].Value = this.strWhere;
return sparam;
}
public string ChinesePage()
{
int PageCount = Convert.ToInt32(Math.Ceiling((double)((double)this.Count / (double)this.PageSize)));
string str = DelUrlPara("page");
StringBuilder builder = new StringBuilder();
int num = 0;
int num2 = 0;
if ((PageCount <= 10) || (this.PageIndex <= 3))
{
num = 1;
num2 = (10 > PageCount) ? PageCount : 10;
}
else if ((PageCount - this.PageIndex) <= 7)
{
num = PageCount - 9;
num2 = PageCount;
}
else
{
num = this.PageIndex - 2;
num2 = this.PageIndex + 7;
}
builder.Append(string.Concat(new object[] { "<span class=\"pagenav\">共:", this.Count, "條 ", this.PageSize, "條/頁 ", PageCount, "頁/<font color=red>", this.PageIndex, "頁</font> </span>" }));
if (this.PageIndex > 1)
{
builder.Append(string.Concat(new object[] { "<a href=\"", str, "page=1\" title=\"首頁\"><<</a> <a href=\"", str, "page=", this.PageIndex - 1, "\" title=\"上一頁\"><</a> " }));
}
for (int i = num; i <= num2; i++)
{
builder.Append((this.PageIndex == i) ? ("<a class=\"curr\" href=\"javascript:void(0)\">" + i + "</a> ") : string.Concat(new object[] { "<a href=\"", str, "page=", i, "\" title=\"第", i, "頁\">", i, "</a> " }));
}
if (PageCount > this.PageIndex)
{
builder.Append(string.Concat(new object[] { "<a href=\"", str, "page=", this.PageIndex + 1, "\" title=\"下一頁\">></a> <a href=\"", str, "page=", PageCount, "\" title=\"末頁\">>></a> " }));
}
return builder.ToString();
}
private static string DelUrlPara(string urlPara)
{
string input = "";
input = Regex.Replace(input + HttpContext.Current.Request.RawUrl, @"(?<=.*?\?.+?)&" + urlPara + @"=\d+|(?<=.*?\?)" + urlPara + @"=\d+&|(?<=.*?)\?" + urlPara + @"=\d+$", "");
return (Regex.IsMatch(input, @"\?/g") ? (input + "?") : (Regex.IsMatch(input, @"(&|\?)") ? (input + "&") : (input + "?")));
}
}