using System;
using System.IO;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Base.Data;
namespace Base.Web
...{
PagingMode enum#region PagingMode enum
public enum PagingMode
...{
Cached,
NonCached
}
#endregion

PagerStyle enum#region PagerStyle enum
public enum PagerStyle
...{
NextPrev,
NumericPages,
NumericList
}
#endregion

VirtualRecordCount class#region VirtualRecordCount class
public class VirtualRecordCount
...{
public int RecordCount;
public int PageCount;
public int RecordsInLastPage;
}
#endregion

PageChangedEventArgs class#region PageChangedEventArgs class
public class PageChangedEventArgs : EventArgs 
...{
public int OldPageIndex;
public int NewPageIndex;
}
#endregion 

ListChangedEventArgs class#region ListChangedEventArgs class
public class ListChangedEventArgs : EventArgs 
...{
public int OldListIndex;
public int NewListIndex;
}
#endregion 

Page Control#region Page Control
[DefaultProperty("SelectCommand")]
[DefaultEvent("PageIndexChanged")]
public class PageControl : WebControl, INamingContainer
...{
PRIVATE DATA MEMBERS#region PRIVATE DATA MEMBERS
// ***********************************************************************
// PRIVATE members
private PagedDataSource _dataSource;
private Control _controlToPaginate;
private string CacheKeyName 
...{
get ...{return Page.Request.FilePath + "_" + UniqueID + "_Data";}
}
private string CurrentPageText = "【当前{0}页】【总共{1}页】";
private string RecordCountText = "【总共{0}条记录】";
private string NoPageSelectedText = "无选中页";
private string QueryPageCommandText = "SELECT * FROM " +
"(SELECT TOP {0} * FROM " +
"(SELECT TOP {1} * FROM ({2}) AS t0 ORDER BY {3} {4}) AS t1 " +
"ORDER BY {3} {5}) AS t2 " +
"ORDER BY {3}";
private string QueryCountCommandText = "SELECT COUNT(*) FROM ({0}) AS t0";
// ***********************************************************************
#endregion

CTOR(s)#region CTOR(s)
// ***********************************************************************
// Ctor
public PageControl() : base()
...{
_dataSource = null;
_controlToPaginate = null;
Font.Name = "verdana";
Font.Size = FontUnit.Point(8);
BackColor = Color.Transparent;
ForeColor = Color.Black;
BorderStyle = BorderStyle.None;
BorderWidth = Unit.Parse("1px");
Width=Unit.Parse("100%");
PagingMode = PagingMode.NonCached;
PagerStyle = PagerStyle.NextPrev;
CurrentPageIndex = 0;
SelectCommand = "";
ItemsPerPage = 20;
TotalPages = -1;
CacheDuration = 60;
}
// ***********************************************************************
#endregion

PUBLIC PROGRAMMING INTERFACE#region PUBLIC PROGRAMMING INTERFACE
// ***********************************************************************
// METHOD ClearCache
// Removes any data cached for paging
public void ClearCache()
...{
if (PagingMode == PagingMode.Cached)
Page.Cache.Remove(CacheKeyName);
}
// ***********************************************************************
// ***********************************************************************
// EVENT PageIndexChanged
// Fires when the pager is about to switch to a new page
public delegate void PageChangedEventHandler(object sender, PageChangedEventArgs e);
public event PageChangedEventHandler PageIndexChanged;
protected virtual void OnPageIndexChanged(PageChangedEventArgs e)
...{
if (PageIndexChanged != null)
PageIndexChanged(this, e);
}
// ***********************************************************************
public delegate void ListChangedEventHandler(object sender, ListChangedEventArgs e);
public event ListChangedEventHandler ListIndexChanged;
protected virtual void OnListIndexChanged(ListChangedEventArgs e)
...{
if (ListIndexChanged != null)
ListIndexChanged(this, e);
}
// ***********************************************************************
// PROPERTY CacheDuration
[Description("Gets and sets for how many seconds the data should stay in the cache")]
public int CacheDuration
...{
get ...{return Convert.ToInt32(ViewState["CacheDuration"]);}
set ...{ViewState["CacheDuration"] = value;}
}
// ***********************************************************************
// ***********************************************************************
// PROPERTY PagingMode
[Description("Indicates whether the data are retrieved page by page or can be cached")]
public PagingMode PagingMode
...{
get ...{return (PagingMode) ViewState["PagingMode"];}
set ...{ViewState["PagingMode"] = value;}
}
// ***********************************************************************
// ***********************************************************************
// PROPERTY PagerStyle
[Description("Indicates the style of the pager's navigation bar")]
public PagerStyle PagerStyle
...{
get ...{return (PagerStyle) ViewState["PagerStyle"];}
set ...{ViewState["PagerStyle"] = value;}
}
// ***********************************************************************
// ***********************************************************************
// PROPERTY ControlToPaginate
[Description("Gets and sets the name of the control to paginate")]
public string ControlToPaginate
...{
get ...{return Convert.ToString(ViewState["ControlToPaginate"]);}
set ...{ViewState["ControlToPaginate"] = value;}
}
// ***********************************************************************
// ***********************************************************************
// PROPERTY ItemsPerPage
[Description("Gets and sets the number of items to display per page")]
public int ItemsPerPage
...{
get ...{return Convert.ToInt32(ViewState["ItemsPerPage"]);}
set ...{ViewState["ItemsPerPage"] = value;}
}
// ***********************************************************************
// ***********************************************************************
// PROPERTY CurrentPageIndex
[Description("Gets and sets the index of the currently displayed page")]
public int CurrentPageIndex
...{
get ...{return Convert.ToInt32(ViewState["CurrentPageIndex"]);}
set ...{ViewState["CurrentPageIndex"] = value;}
}
// ***********************************************************************
public int RecordCount
...{
get ...{return Convert.ToInt32(ViewState["RecordCount"]);}
set ...{ViewState["RecordCount"] = value;}
}
public int CurrentListIndex
...{
get ...{return Convert.ToInt32(ViewState["CurrentListIndex"]);}
set ...{ViewState["CurrentListIndex"] = value;}
}
public int ListCount
...{
get ...{return Convert.ToInt32(ViewState["ListCount"]);}
set ...{ViewState["ListCount"] = value;}
}
// ***********************************************************************
// PROPERTY SelectCommand
[Description("Gets and sets the SQL query to get data")]
public string SelectCommand
...{
get ...{return Convert.ToString(ViewState["SelectCommand"]);}
set ...{ViewState["SelectCommand"] = value;}
}
// ***********************************************************************
// ***********************************************************************
// PROPERTY SortField
[Description("Gets and sets the sort-by field. It is mandatory in NonCached mode.)")]
public string SortField
...{
get ...{return Convert.ToString(ViewState["SortKeyField"]);}