[Assembly: TagPrefix ("WebPages", "WebPages")] // XXX is the namespace of the custom control, and YYY is the name you want.
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Text;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Text. RegularExpressions;
Namespace WebPages
{
[DefaultProperty ("Text")]
[ToolboxData ("<{0}: Pages runat = \" server \ "> </{0}: Pages>")]
Public class Pages: WebControl
{
Private int _ CuttentPage;
Private int _ NumCount;
Private int _ PageSize = 1;
Private string _ Url = "";
Private string _ RewriteFormat = "";
Private string _ RewriteRegex = "";
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;
}
}
// Address
Public string Url
{
Set
{
_ Url = value;
}
Get
{
If (string. IsNullOrEmpty (_ Url ))
{
Try
{
_ Url = this. Parent. Page. Request. RawUrl. ToString ();
}
Catch
{
_ Url = "";
}
}
Return this. _ Url;
}
}
Public string RewriteFormat
{
Set {this. _ RewriteFormat = value ;}
Get {return this. _ RewriteFormat ;}
}
Public string RewriteRegex
{
Set {_ RewriteRegex = value ;}
Get {return this. _ RewriteRegex ;}
}
[Bindable (true)]
[Category ("Appearance")]
[DefaultValue ("")]
[Localizable (true)]
Public string Text
{
Get
{
String s = (String) ViewState ["Text"];
Return (s = null )? String. Empty: s );
}
Set
{
ViewState ["Text"] = value;
}
}
Protected string GetRightRegexUrl (string url)
{
String [,] tempStrArr = new string [12, 2];
TempStrArr [0, 0] = "\\";
TempStrArr [0, 1] = "\\\\ u005C ";
TempStrArr [1, 0] = "$ ";
TempStrArr [1, 1] = "\\\\ u0024 ";
TempStrArr [2, 0] = "^ ";
TempStrArr [2, 1] = "\\\\ u005E ";
TempStrArr [3, 0] = "{";
TempStrArr [3, 1] = "\\\\ u007B ";
TempStrArr [4, 0] = "[";
TempStrArr [4, 1] = "\\\\ u005B ";
TempStrArr [5, 0] = "(";
TempStrArr [5, 1] = "\\\\ u0028 ";
TempStrArr [6, 0] = "| ";
TempStrArr [6, 1] = "\\\\ u007C ";
TempStrArr [7, 0] = ")";
TempStrArr [7, 1] = "\\\ u0029 ";
TempStrArr [8, 0] = "*";
TempStrArr [8, 1] = "\\\\ u002A ";
TempStrArr [9, 0] = "+ ";
TempStrArr [9, 1] = "\\\\ u002B ";
TempStrArr [10, 0] = "? ";
TempStrArr [10, 1] = "\\\\\\ u003F ";
TempStrArr [11, 0] = ".";
TempStrArr [11, 1] = "\\\\\\ u002E ";
For (int I = 0; I <12; I ++)
{
Url = url. Replace (tempStrArr [I, 0], tempStrArr [I, 1]);
}
Return url;
}
Protected string getUrl (string url)
{
MatchCollection mats = Regex. Matches (url ,"(? <First> [\ w] *) = (? <Two> [\ S \ s] * [\ u4e00-\ u9fa5] + [\ S \ s] *) ", RegexOptions. ignoreCase | RegexOptions. multiline );
Foreach (Match mat in mats)
{
Url = url. replace (mat. groups ["first"]. value + "=" + mat. groups ["two"]. value, mat. groups ["first"]. value + "=" + HttpUtility. urlEncodeUnicode (mat. groups ["two"]. value. trim ()));
}
Return url;
}
/// <Summary>
/// The Bottom page of the current page displayed based on the current page number
/// </Summary>
/// <Param name = "current"> </param>
/// <Param name = "size"> </param>
/// <Param name = "zong"> </param>
/// <Returns> </returns>
Protected string GetPage (int current, int size, int zong)
{
String url = this. Url;
Url = getUrl (url );
String urltemp = "";
Urltemp = url. IndexOf ("page =")> = 0? (Regex. Replace (url, "page = ([^ &] *)", "page = {0}"): (url. IndexOf ("? ")> = 0? (Url + "& page = {0}"): (url + "? Page = {0 }"));
If (this. RewriteFormat. Length> 0)
{
Regex reg = new Regex (RewriteRegex, RegexOptions. IgnoreCase );
If (reg. IsMatch (urltemp ))
{
Urltemp = reg. Replace (urltemp, RewriteFormat );
}
}
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 ("& nbsp; <a href = '" + string. Format (urltemp, current-1 <1? ("1"): (current-1). ToString () + "'> previous page </a> & nbsp ;");
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 ("& nbsp; <a href = '" + string. format (urltemp, (I + 1 ). toString () + "'> {0} </a>", (I + 1 ). toString ());
Sball. Append ("& nbsp ;");
}
For (int I = (xian-1) * 10> pagecount? (Pagecount): (xian-1) * 10); 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 ("& nbsp; <a href = '" + string. format (urltemp, (I + 1 ). toString () + "'> "). append (I + 1 )). append ("</a> ");
}
Sball. Append ("& nbsp; <a href = '" + string. Format (urltemp, (current + 1> pagecount? (Pagecount. ToString (): (current + 1). ToString () + "'> next page </a> ");
Sball. append ("& nbsp; Total "). append (zong. toString ()). append ("Entry & nbsp; current entry "). append (current ). toString ()). append ("page "). append ("Total "). append (pagecount ). append ("page ");
Return sball. ToString ();
}
Protected override void RenderContents (HtmlTextWriter output)
{
String tempData = "<table border = \" 1 \ "width = \" 100% \ "height = \" 30px \ "style = \" margin: 0px \ "> <tr> <td style = \" width: 89% \ ">{0} </td> <td style = \" width: 30% \ "> <input type = \" text \ "id = \" Pages1_TbPageGo \ "onKeyUp = \" this. value = this. value. replace (/[^ \ d] +/, '') \" style = \ "width: 33px \ "/> <input id = \" BtGo \ "style = \" width: 34px \ "type = \" button \ "value = \" GO \ "onClick = \" document. location. href = document. location. href . IndexOf ('page = ')> = 0? (Document. location. href. replace (/page = ([^ &] *)/, 'page = '+ document. getElementById ('pages1 _ TbPageGo '). value) :( document. location. href. indexOf ('? ')> = 0? (Document. location. href + '& page =' + document. getElementById ('pages1 _ TbPageGo '). value) :( document. location. href + '? Page = '+ document. getElementById ('pages1 _ TbPageGo'). value) \ "/> </td> </tr> </table> ";
// Output. Write (Text );
// <% = GetPage (this. CurrentPage, this. PageSize, this. NumCount, this. Request. Url. ToString () %>
Output. Write (string. Format (tempData, GetPage (CurrentPage, PageSize, NumCount )));
}
}
}