using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Text;
namespace manage.Controls
{
public partial class Pages : System.Web.UI.UserControl
{
private int _CuttentPage;
private int _NumCount;
private int _PageSize=1;
public int CurrentPage
{
set
{
if (Regex.IsMatch(Convert.ToString(value), "^\\d+$"))
{
this._CuttentPage = Convert.ToInt32(value);
}
else
{
this._CuttentPage = 0;
}
}
get
{
return this._CuttentPage;
}
}
public int NumCount
{
set
{
if (Regex.IsMatch(Convert.ToString(value), "^\\d+$"))
{
this._NumCount = Convert.ToInt32(value);
}
else
{
this._NumCount = 0;
}
}
get
{
return this._NumCount;
}
}
public int PageSize
{
set
{
if (Regex.IsMatch(Convert.ToString(value), "^\\d+$"))
{
this._PageSize = Convert.ToInt32(value);
}
else
{
this._PageSize = 1;
}
}
get
{
return this._PageSize;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 根据当前的页数显示的当前页的底部分页
/// </summary>
/// <param name="current"></param>
/// <param name="size"></param>
/// <param name="zong"></param>
/// <returns></returns>
public string GetPage(int current, int size, int zong,string url)
{
string urltemp = url.IndexOf("page=")>=0?(Regex.Replace(url,"page=([^&]*)","page={0}")):(url.IndexOf("?")>=0?(url+"&page={0}"):(url+"?page={0}"));
int pagecount = zong % size == 0 ? (zong / size) : (zong / size + 1);
int num = current / 10;
System.Text.StringBuilder sball = new System.Text.StringBuilder("");
int xian = current / 10 + 1;
int before = current % 10 == 0 ? (current / 10) : (current / 10);
sball.AppendFormat(" <a href='" + string.Format(urltemp, current-1<1?("1"):((current-1).ToString())) + "'>上一页</a> ");
for (int i = ((before * 10 - 5) > 0 ? (before * 10 - 5) : (1)); i <= (before * 10 == 0 ? (1) : (before * 10)); i++)
{
if ((before * 10 - 5) < 0)
continue;
sball.AppendFormat(" <a href='" + string.Format(urltemp, (i+1).ToString()) + "'>{0}</a>",(i+1).ToString());
sball.Append(" ");
}
for (int i = ((xian - 1) * 10 > pagecount ? (pagecount) : ((xian - 1) * 10)+1); i < (xian * 10 < pagecount ? (xian * 10) : (pagecount)); i++)
{
if (i == 0)
sball.AppendFormat("<a href='"+string.Format(urltemp,(i+1).ToString())+"'>").Append((i + 1)).Append("</a>");
else
sball.Append(" <a href='"+string.Format(urltemp,(i+1).ToString())+"'>").Append((i + 1)).Append("</a>");
}
sball.Append(" <a href='" + string.Format(urltemp, (current + 1 > pagecount ? (pagecount.ToString()) : ((current + 1).ToString()))) + "'>下一页</a>");
sball.Append(" 共").Append(zong.ToString()).Append("条 当前第").Append((current).ToString()).Append("页").Append("共").Append(pagecount).Append("页");
return sball.ToString();
}
}
}