namespace JYK.Controls
{
/**//// <summary>
/// 分页控件
/// PageGetData.cs 负责提取数据
/// PageSQL.cs 负责生成SQl语句
/// PageUI.cs 负责分页控件的页面内容
/// </summary>
[DefaultProperty("Text")]
[ToolboxData("<{0}:JYKPage runat=server></{0}:JYKPage>")]
public class JYKPage : WebControl, INamingContainer, IPostBackEventHandler
{
/**//// <summary>
/// 访问数据库用的实例
/// </summary>
private DataAccessHelp dal = null;
/**//// <summary>
/// 生成SQL语句的部分
/// </summary>
private PageManage.PageSQL MgrPageSQL = null;
/**//// <summary>
/// 提取数据的部分
/// </summary>
private PageManage.PageGetData MgrGetData = null;
/**//// <summary>
/// 提取数据的部分
/// </summary>
private PageManage.PageUI MgrPageUI = null;
/**//// <summary>
/// 设置显示数据的控件
/// </summary>
public System.Web.UI.WebControls.WebControl ControlGrid;
成员#region 成员
页面显示#region 页面显示
/**//// <summary>
/// 上一页 的文字
/// </summary>
private string pPrevText = "上一页"; //上一页
/**//// <summary>
/// 下一页 的文字
/// </summary>
private string pNextText = "下一页"; //下一页
/**//// <summary>
/// 首页 的文字
/// </summary>
private string pFirstText = "首页"; //首页
/**//// <summary>
/// 末页 的文字
/// </summary>
private string pLastText = "末页"; //末页
/**//// <summary>
/// 去指定页号 的文字
/// </summary>
private string pGOText = "GO"; //GO
#endregion
#endregion
属性#region 属性
存放分页算法模版的属性#region 存放分页算法模版的属性
//记录数
记录相关#region 记录相关
一页的记录数#region 一页的记录数
/**//// <summary>
/// 一页的记录数
/// </summary>
[Bindable(true)]
[Category("记录集")]
[DefaultValue("")]
[Localizable(true)]
public Int32 PageSize
{
set { ViewState["PageSize"] = value; }
get
{
//没有设置的话,使用默认值:一页20条记录
if (ViewState["PageSize"] == null) { return 20; }
else { return (Int32)ViewState["PageSize"]; }
}
}
#endregion
符合条件的记录数#region 符合条件的记录数
/**//// <summary>
/// 符合条件的记录数
/// </summary>
[Bindable(true)]
[Category("记录集")]
[DefaultValue("")]
[Localizable(true)]
public Int32 PageRecordCount
{
set { ViewState["PageRecordCount"] = value; }
get
{
//没有设置的话,返回 0
if (ViewState["PageRecordCount"] == null) { return 0; }
else { return (Int32)ViewState["PageRecordCount"]; }
}
}
#endregion
页数#region 页数
/**//// <summary>
/// 页数
/// </summary>
[Bindable(true)]
[Category("记录集")]
[DefaultValue("")]
[Localizable(true)]
public Int32 PageCount
{
set { ViewState["PageCount"] = value; }
get
{
//没有设置的话,返回 0
if (ViewState["PageCount"] == null) { return 0; }
else { return (Int32)ViewState["PageCount"]; }
}
}
#endregion
想要查看哪一页的数据#region 想要查看哪一页的数据
/**//// <summary>
/// 想要查看那一页的数据
/// </summary>
[Bindable(true)]
[Category("记录集")]
[DefaultValue("")]
[Localizable(true)]
public Int32 PageIndex
{
set { ViewState["PageIndex"] = value; }
get
{
if (ViewState["PageIndex"] == null) { return 1; }
else { return (Int32)ViewState["PageIndex"]; }
}
}
#endregion
#endregion
//SQL语句的基础
分页算法需要的属性#region 分页算法需要的属性
表名、视图名#region 表名、视图名
/**//// <summary>
/// 表名、视图名
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableName
{
set { ViewState["TableName"] = value; }
get
{
if (ViewState["TableName"] == null)
{
if ((base.Site != null) && base.Site.DesignMode)
{
return "TableName";
}
else
{
CommandClass.MsgBox("没有设置TableName属性!", true);
return null;
}
}
else { return ViewState["TableName"].ToString(); }
}
}
#endregion
表的主键#region 表的主键
/**//// <summary>
/// 表的主键
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableIDColumns
{
set { ViewState["TableIDColumns"] = value; }
get
{
if (ViewState["TableIDColumns"] == null)
{
if ((base.Site != null) && base.Site.DesignMode)
{
return "TableIDColumns";
}
else
{
CommandClass.MsgBox("没有设置TableIDColumns属性!", true);
return null;
}
}
else { return ViewState["TableIDColumns"].ToString(); }
}
}
#endregion
显示的字段#region 显示的字段
/**//// <summary>
/// 显示的字段
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableShowColumns
{
set { ViewState["TableShowColumns"] = value; }
get
{
if (ViewState["TableShowColumns"] == null) { return "*"; }
else { return ViewState["TableShowColumns"].ToString(); }
}
}
#endregion
排序字段#region 排序字段
/**//// <summary>
/// 排序字段
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableOrderColumns
{
set { ViewState["TableOrderColumns"] = value; }
get
{
if (ViewState["TableOrderColumns"] == null)
{
if ((base.Site != null) && base.Site.DesignMode)
{
return "TableOrderColumns";
}
else
{
CommandClass.MsgBox("没有设置TableOrderColumns属性!", true);
return null;
}
}
else { return ViewState["TableOrderColumns"].ToString(); }
}
}
#endregion
查询条件#region 查询条件
/**//// <summary>
/// 查询条件
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableQuery
{
set { ViewState["TableQuery"] = value; }
get
{
if (ViewState["TableQuery"] == null)
return "";
else
return ViewState["TableQuery"].ToString();
}
}
#endregion
#endregion
//SQL模版
分页算法模版#region 分页算法模版
/**//// <summary>
/// 第一页的分页算法模版
/// </summary>
[Bindable(true)]
[Category("SQL语句模版")]
[DefaultValue("")]
[Localizable(true)]
public string SQLGetFirstPage
{
set { ViewState["FirstPageSQL"] = value; }
get
{
return ViewState["FirstPageSQL"] == null ? null : ViewState["FirstPageSQL"].ToString();
}
}
#endregion
指定页号的分页算法模版#region 指定页号的分页算法模版
/**//// <summary>
/// 指定页号的分页算法模版
/// </summary>
[Bindable(true)]
[Category("SQL语句模版")]
[DefaultValue("")]
[Localizable(true)]
public string SQLGetNextPage
{
set
{
ViewState["NextPageSQL"] = value;
}
get
{
return ViewState["NextPageSQL"]==null?null:ViewState["NextPageSQL"].ToString();
}
}
#endregion
指定页号的分页算法模版#region 指定页号的分页算法模版
/**//// <summary>
/// 最后一页的分页算法模版
/// </summary>
[Bindable(true)]
[Category("SQL语句模版")]
[DefaultValue("")]
[Localizable(true)]
public string SQLGetLastPage
{
set
{
ViewState["LastPageSQL"] = value;
}
get
{
return ViewState["LastPageSQL"] == null ? null : ViewState["LastPageSQL"].ToString();
}
}
#endregion
#endregion
//UI
页面显示 上一页、下一页#region 页面显示 上一页、下一页
上一页#region 上一页
/**//// <summary>
/// 上一页
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIPrev
{
get { return pPrevText; }
set { pPrevText = value; }
}
#endregion
下一页#region 下一页
/**//// <summary>
/// 下一页
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUINext
{
get { return pNextText; }
set { pNextText = value; }
}
#endregion
首页#region 首页
/**//// <summary>
/// 首页
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIFirst
{
get { return pFirstText; }
set { pFirstText = value; }
}
#endregion
末页#region 末页
/**//// <summary>
/// 末页
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUILast
{
get { return pLastText; }
set { pLastText = value; }
}
#endregion
GO#region GO
/**//// <summary>
/// GO
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIGO
{
get { return pGOText; }
set { pGOText = value; }
}
#endregion
#endregion
页面导航的数量#region 页面导航的数量
/**//// <summary>
///
/// </summary>
public Int32 NaviCount
{
set { ViewState["NaviCount"] = value; }
get
{
if (ViewState["NaviCount"] == null)
return 10;
else
return (Int32)ViewState["NaviCount"];
}
}
#endregion
页面显示 记录数、页数#region 页面显示 记录数、页数
共{0}条记录数#region 共{0}条记录数
/**//// <summary>
/// 共{0}条记录数
/// </summary>
[Bindable(true)]
[Category("记录信息")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIAllCount
{
set { ViewState["PageUIAllCount"] = value; }
get
{
if (ViewState["PageUIAllCount"] == null)
return "共<font style=\"color:Red;\">{0}</font>条记录数";
else
return ViewState["PageUIAllCount"].ToString();
}
}
#endregion
第{0}/{1}页#region 第{0}/{1}页
/**//// <summary>
/// 第{0}/{1}页
/// </summary>
[Bindable(true)]
[Category("记录信息")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIAllPage
{
set { ViewState["PageUIAllPage"] = value; }
get
{
if (ViewState["PageUIAllPage"] == null)
return "第<font style=\"color:Red;\">{0}</font>/<font style=\"color:Red;\">{1}</font>页";
else
return ViewState["PageUIAllPage"].ToString();
}
}
#endregion
每页{0}条记录#region 每页{0}条记录
/**//// <summary>
/// 共{0}条记录数
/// </summary>
[Bindable(true)]
[Category("记录信息")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIAllPageCount
{
set { ViewState["PageUIAllPageCount"] = value; }
get
{
if (ViewState["PageUIAllPageCount"] == null)
return "每页<font style=\"color:Red;\">{0}</font>条记录";
else
return ViewState["PageUIAllPageCount"].ToString();
}
}
#endregion
#endregion
显示数据的控件的ID#region 显示数据的控件的ID
/**//// <summary>
/// 共{0}条记录数
/// </summary>
[Bindable(true)]
[Category("显示数据的控件ID")]
[DefaultValue("")]
[Localizable(true)]
public string ControlGridID
{
set { ViewState["ControlGridID"] = value; }
get
{
if (ViewState["ControlGridID"] == null)
return null;
else
return ViewState["ControlGridID"].ToString();
}
}
#endregion
数据访问实例的设置#region 数据访问实例的设置
/**//// <summary>
/// 设置数据访问层的实例
/// </summary>
public DataAccessHelp DAL
{
set { dal = value; }
get
{
if (dal == null)
dal = new DataAccessHelp();
return dal;
}
}
#endregion
管理部分#region 管理部分
/**//// <summary>
/// 提取数据的实例
/// </summary>
public PageManage.PageGetData ManagerGetData
{
set { MgrGetData = value; }
get
{
PageManage.PageGetData tmp = MgrGetData;
if (tmp == null)
{
tmp = new JYK.Controls.PageManage.PageGetData();
MgrGetData = tmp;
}
if (tmp.myPage == null)
tmp.myPage = this;
return tmp;
}
}
/**//// <summary>
/// 提取数据的实例
/// </summary>
public PageManage.PageSQL ManagerPageSQL
{
set { MgrPageSQL = value; }
get
{
PageManage.PageSQL tmp = MgrPageSQL;
if (tmp == null)
{
tmp = new JYK.Controls.PageManage.PageSQL();
MgrPageSQL = tmp;
}
if (tmp.myPage == null)
tmp.myPage = this;
return tmp;
}
}
/**//// <summary>
/// 提取数据的实例
/// </summary>
public PageManage.PageUI ManagerPageUI
{
set { MgrPageUI = value; }
get
{
PageManage.PageUI tmp = MgrPageUI;
if (tmp == null)
{
tmp = new JYK.Controls.PageManage.PageUI();
MgrPageUI = tmp;
}
if (tmp.myPage == null)
tmp.myPage = this;
return tmp;
}
}
#endregion
#endregion
函数#region 函数
/**//// <summary>
/// 显示第一页的数据
/// </summary>
public void BindFirstPage()
{
//生成SQL语句和获取记录总数
this.ManagerPageSQL.CreateSQL();
//绑定第一页的数据
myDataBind(1);
}
#endregion
绘制UI CreateChildControls()#region 绘制UI CreateChildControls()
/**//// <summary>
/// 绘制UI
/// </summary>
protected override void CreateChildControls()
{
base.CreateChildControls();
LinkButton btn = new LinkButton();
btn.ID = "Page_Button";
btn.Text = "";//所有的回发事件
//btn.Click += new EventHandler(btn_Click); //添加事件
this.Controls.Add(btn);
ManagerPageUI.AddPageUI(); //添加页面显示
Page_Click(); //调用分页事件
}
#endregion
响应分页事件#region 响应分页事件
/**//// <summary>
/// 响应分页事件
/// </summary>
private void Page_Click()
{
//string a = base.Page.Request.Form["__EVENTTARGET"];
string PageIndex = base.Page.Request.Form["__EVENTARGUMENT"];
if (!Functions.IsInt(PageIndex))
return;
else
myDataBind(Int32.Parse(PageIndex));
}
/**//// <summary>
/// 绑定控件
/// </summary>
private void myDataBind(Int32 PageIndex)
{
if (ControlGrid == null)
{
string CID = this.ControlGridID;
if (CID == null)
return;
else
ControlGrid = (WebControl)base.Page.FindControl(CID);
}
Int32 NoCount = this.NaviCount; //一组页号的数量
bool isNavi = false;
Int32 tmpPageIndex = this.PageIndex;
switch (PageIndex)
{
case 1: //首页
isNavi = true;
break;
case -3:
//上一页
PageIndex = this.PageIndex - 1;
break;
case -2:
//下一页
PageIndex = this.PageIndex + 1;
if (PageIndex % NoCount == 1)
isNavi = true;
break;
case -99: //前导
if (tmpPageIndex % NoCount == 0)
PageIndex = tmpPageIndex - NoCount;
else
PageIndex = tmpPageIndex / NoCount * NoCount;
isNavi = true;
break;
case -88: //后导
if (tmpPageIndex % NoCount == 0)
PageIndex = tmpPageIndex + NoCount;
else
PageIndex = (this.PageIndex / NoCount + 1) * NoCount + 1;
isNavi = true;
break;
default:
isNavi = false ;
break;
}
if (PageIndex == this.PageCount)
isNavi = true; //末页
this.PageIndex = PageIndex;
//获取记录集
DataTable dt = this.ManagerGetData.GetDataTable(PageIndex);
//通过(好像是反射)来设置 DataSource属性。
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(ControlGrid, null, "datasource", new object[] { dt }, null, null);
ControlGrid.DataBind();
//重新显示当前页号
this.ManagerPageUI.UpdatePageIndex();
//重新显示页号当航
if (isNavi)
this.ManagerPageUI.ReloadPageNavi();
else
this.ManagerPageUI.UpdatePageNavi();
//base.Page.Response.Write(a + "+" + PageIndex);
}
#endregion
/**//// <summary>
/// 接收分页控件的回发事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void btn_Click(object sender, EventArgs e)
{
//throw new NotImplementedException();
//base.Page.Response.Write("ss");
}
/**//// <summary>
/// 分页的回发事件,没有成功
/// </summary>
/// <param name="PageIndex"></param>
public void RaisePostBackEvent(string PageIndex)
{
//base.Page.Response.Write("www");
//Page_Click();
}
设计时支持#region 设计时支持
/**//// <summary>
/// 设计时支持
/// </summary>
/// <param name="output"></param>
protected override void Render(HtmlTextWriter output)
{
if ((base.Site != null) && base.Site.DesignMode)
{
output.Write("<div style='TEXT-ALIGN: center;100%'>第1/100页 首页 上一页 [1][2][3] 下一页 末页 共1000条记录</div>");
}
else
{
//Page_Click();
output.Write("<div id='" + this.ClientID + "Page' style='TEXT-ALIGN: center;90%'>");
base.Render(output);
output.Write("</div>");
}
}
#endregion
}
}
{
/**//// <summary>
/// 分页控件
/// PageGetData.cs 负责提取数据
/// PageSQL.cs 负责生成SQl语句
/// PageUI.cs 负责分页控件的页面内容
/// </summary>
[DefaultProperty("Text")]
[ToolboxData("<{0}:JYKPage runat=server></{0}:JYKPage>")]
public class JYKPage : WebControl, INamingContainer, IPostBackEventHandler
{
/**//// <summary>
/// 访问数据库用的实例
/// </summary>
private DataAccessHelp dal = null;
/**//// <summary>
/// 生成SQL语句的部分
/// </summary>
private PageManage.PageSQL MgrPageSQL = null;
/**//// <summary>
/// 提取数据的部分
/// </summary>
private PageManage.PageGetData MgrGetData = null;
/**//// <summary>
/// 提取数据的部分
/// </summary>
private PageManage.PageUI MgrPageUI = null;
/**//// <summary>
/// 设置显示数据的控件
/// </summary>
public System.Web.UI.WebControls.WebControl ControlGrid;
成员#region 成员
页面显示#region 页面显示
/**//// <summary>
/// 上一页 的文字
/// </summary>
private string pPrevText = "上一页"; //上一页
/**//// <summary>
/// 下一页 的文字
/// </summary>
private string pNextText = "下一页"; //下一页
/**//// <summary>
/// 首页 的文字
/// </summary>
private string pFirstText = "首页"; //首页
/**//// <summary>
/// 末页 的文字
/// </summary>
private string pLastText = "末页"; //末页
/**//// <summary>
/// 去指定页号 的文字
/// </summary>
private string pGOText = "GO"; //GO
#endregion
#endregion
属性#region 属性
存放分页算法模版的属性#region 存放分页算法模版的属性
//记录数
记录相关#region 记录相关
一页的记录数#region 一页的记录数
/**//// <summary>
/// 一页的记录数
/// </summary>
[Bindable(true)]
[Category("记录集")]
[DefaultValue("")]
[Localizable(true)]
public Int32 PageSize
{
set { ViewState["PageSize"] = value; }
get
{
//没有设置的话,使用默认值:一页20条记录
if (ViewState["PageSize"] == null) { return 20; }
else { return (Int32)ViewState["PageSize"]; }
}
}
#endregion
符合条件的记录数#region 符合条件的记录数
/**//// <summary>
/// 符合条件的记录数
/// </summary>
[Bindable(true)]
[Category("记录集")]
[DefaultValue("")]
[Localizable(true)]
public Int32 PageRecordCount
{
set { ViewState["PageRecordCount"] = value; }
get
{
//没有设置的话,返回 0
if (ViewState["PageRecordCount"] == null) { return 0; }
else { return (Int32)ViewState["PageRecordCount"]; }
}
}
#endregion
页数#region 页数
/**//// <summary>
/// 页数
/// </summary>
[Bindable(true)]
[Category("记录集")]
[DefaultValue("")]
[Localizable(true)]
public Int32 PageCount
{
set { ViewState["PageCount"] = value; }
get
{
//没有设置的话,返回 0
if (ViewState["PageCount"] == null) { return 0; }
else { return (Int32)ViewState["PageCount"]; }
}
}
#endregion
想要查看哪一页的数据#region 想要查看哪一页的数据
/**//// <summary>
/// 想要查看那一页的数据
/// </summary>
[Bindable(true)]
[Category("记录集")]
[DefaultValue("")]
[Localizable(true)]
public Int32 PageIndex
{
set { ViewState["PageIndex"] = value; }
get
{
if (ViewState["PageIndex"] == null) { return 1; }
else { return (Int32)ViewState["PageIndex"]; }
}
}
#endregion
#endregion
//SQL语句的基础
分页算法需要的属性#region 分页算法需要的属性
表名、视图名#region 表名、视图名
/**//// <summary>
/// 表名、视图名
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableName
{
set { ViewState["TableName"] = value; }
get
{
if (ViewState["TableName"] == null)
{
if ((base.Site != null) && base.Site.DesignMode)
{
return "TableName";
}
else
{
CommandClass.MsgBox("没有设置TableName属性!", true);
return null;
}
}
else { return ViewState["TableName"].ToString(); }
}
}
#endregion
表的主键#region 表的主键
/**//// <summary>
/// 表的主键
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableIDColumns
{
set { ViewState["TableIDColumns"] = value; }
get
{
if (ViewState["TableIDColumns"] == null)
{
if ((base.Site != null) && base.Site.DesignMode)
{
return "TableIDColumns";
}
else
{
CommandClass.MsgBox("没有设置TableIDColumns属性!", true);
return null;
}
}
else { return ViewState["TableIDColumns"].ToString(); }
}
}
#endregion
显示的字段#region 显示的字段
/**//// <summary>
/// 显示的字段
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableShowColumns
{
set { ViewState["TableShowColumns"] = value; }
get
{
if (ViewState["TableShowColumns"] == null) { return "*"; }
else { return ViewState["TableShowColumns"].ToString(); }
}
}
#endregion
排序字段#region 排序字段
/**//// <summary>
/// 排序字段
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableOrderColumns
{
set { ViewState["TableOrderColumns"] = value; }
get
{
if (ViewState["TableOrderColumns"] == null)
{
if ((base.Site != null) && base.Site.DesignMode)
{
return "TableOrderColumns";
}
else
{
CommandClass.MsgBox("没有设置TableOrderColumns属性!", true);
return null;
}
}
else { return ViewState["TableOrderColumns"].ToString(); }
}
}
#endregion
查询条件#region 查询条件
/**//// <summary>
/// 查询条件
/// </summary>
[Bindable(true)]
[Category("SQL语句")]
[DefaultValue("")]
[Localizable(true)]
public string TableQuery
{
set { ViewState["TableQuery"] = value; }
get
{
if (ViewState["TableQuery"] == null)
return "";
else
return ViewState["TableQuery"].ToString();
}
}
#endregion
#endregion
//SQL模版
分页算法模版#region 分页算法模版
/**//// <summary>
/// 第一页的分页算法模版
/// </summary>
[Bindable(true)]
[Category("SQL语句模版")]
[DefaultValue("")]
[Localizable(true)]
public string SQLGetFirstPage
{
set { ViewState["FirstPageSQL"] = value; }
get
{
return ViewState["FirstPageSQL"] == null ? null : ViewState["FirstPageSQL"].ToString();
}
}
#endregion
指定页号的分页算法模版#region 指定页号的分页算法模版
/**//// <summary>
/// 指定页号的分页算法模版
/// </summary>
[Bindable(true)]
[Category("SQL语句模版")]
[DefaultValue("")]
[Localizable(true)]
public string SQLGetNextPage
{
set
{
ViewState["NextPageSQL"] = value;
}
get
{
return ViewState["NextPageSQL"]==null?null:ViewState["NextPageSQL"].ToString();
}
}
#endregion
指定页号的分页算法模版#region 指定页号的分页算法模版
/**//// <summary>
/// 最后一页的分页算法模版
/// </summary>
[Bindable(true)]
[Category("SQL语句模版")]
[DefaultValue("")]
[Localizable(true)]
public string SQLGetLastPage
{
set
{
ViewState["LastPageSQL"] = value;
}
get
{
return ViewState["LastPageSQL"] == null ? null : ViewState["LastPageSQL"].ToString();
}
}
#endregion
#endregion
//UI
页面显示 上一页、下一页#region 页面显示 上一页、下一页
上一页#region 上一页
/**//// <summary>
/// 上一页
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIPrev
{
get { return pPrevText; }
set { pPrevText = value; }
}
#endregion
下一页#region 下一页
/**//// <summary>
/// 下一页
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUINext
{
get { return pNextText; }
set { pNextText = value; }
}
#endregion
首页#region 首页
/**//// <summary>
/// 首页
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIFirst
{
get { return pFirstText; }
set { pFirstText = value; }
}
#endregion
末页#region 末页
/**//// <summary>
/// 末页
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUILast
{
get { return pLastText; }
set { pLastText = value; }
}
#endregion
GO#region GO
/**//// <summary>
/// GO
/// </summary>
[Bindable(true)]
[Category("页面显示")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIGO
{
get { return pGOText; }
set { pGOText = value; }
}
#endregion
#endregion
页面导航的数量#region 页面导航的数量
/**//// <summary>
///
/// </summary>
public Int32 NaviCount
{
set { ViewState["NaviCount"] = value; }
get
{
if (ViewState["NaviCount"] == null)
return 10;
else
return (Int32)ViewState["NaviCount"];
}
}
#endregion
页面显示 记录数、页数#region 页面显示 记录数、页数
共{0}条记录数#region 共{0}条记录数
/**//// <summary>
/// 共{0}条记录数
/// </summary>
[Bindable(true)]
[Category("记录信息")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIAllCount
{
set { ViewState["PageUIAllCount"] = value; }
get
{
if (ViewState["PageUIAllCount"] == null)
return "共<font style=\"color:Red;\">{0}</font>条记录数";
else
return ViewState["PageUIAllCount"].ToString();
}
}
#endregion
第{0}/{1}页#region 第{0}/{1}页
/**//// <summary>
/// 第{0}/{1}页
/// </summary>
[Bindable(true)]
[Category("记录信息")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIAllPage
{
set { ViewState["PageUIAllPage"] = value; }
get
{
if (ViewState["PageUIAllPage"] == null)
return "第<font style=\"color:Red;\">{0}</font>/<font style=\"color:Red;\">{1}</font>页";
else
return ViewState["PageUIAllPage"].ToString();
}
}
#endregion
每页{0}条记录#region 每页{0}条记录
/**//// <summary>
/// 共{0}条记录数
/// </summary>
[Bindable(true)]
[Category("记录信息")]
[DefaultValue("")]
[Localizable(true)]
public string PageUIAllPageCount
{
set { ViewState["PageUIAllPageCount"] = value; }
get
{
if (ViewState["PageUIAllPageCount"] == null)
return "每页<font style=\"color:Red;\">{0}</font>条记录";
else
return ViewState["PageUIAllPageCount"].ToString();
}
}
#endregion
#endregion
显示数据的控件的ID#region 显示数据的控件的ID
/**//// <summary>
/// 共{0}条记录数
/// </summary>
[Bindable(true)]
[Category("显示数据的控件ID")]
[DefaultValue("")]
[Localizable(true)]
public string ControlGridID
{
set { ViewState["ControlGridID"] = value; }
get
{
if (ViewState["ControlGridID"] == null)
return null;
else
return ViewState["ControlGridID"].ToString();
}
}
#endregion
数据访问实例的设置#region 数据访问实例的设置
/**//// <summary>
/// 设置数据访问层的实例
/// </summary>
public DataAccessHelp DAL
{
set { dal = value; }
get
{
if (dal == null)
dal = new DataAccessHelp();
return dal;
}
}
#endregion
管理部分#region 管理部分
/**//// <summary>
/// 提取数据的实例
/// </summary>
public PageManage.PageGetData ManagerGetData
{
set { MgrGetData = value; }
get
{
PageManage.PageGetData tmp = MgrGetData;
if (tmp == null)
{
tmp = new JYK.Controls.PageManage.PageGetData();
MgrGetData = tmp;
}
if (tmp.myPage == null)
tmp.myPage = this;
return tmp;
}
}
/**//// <summary>
/// 提取数据的实例
/// </summary>
public PageManage.PageSQL ManagerPageSQL
{
set { MgrPageSQL = value; }
get
{
PageManage.PageSQL tmp = MgrPageSQL;
if (tmp == null)
{
tmp = new JYK.Controls.PageManage.PageSQL();
MgrPageSQL = tmp;
}
if (tmp.myPage == null)
tmp.myPage = this;
return tmp;
}
}
/**//// <summary>
/// 提取数据的实例
/// </summary>
public PageManage.PageUI ManagerPageUI
{
set { MgrPageUI = value; }
get
{
PageManage.PageUI tmp = MgrPageUI;
if (tmp == null)
{
tmp = new JYK.Controls.PageManage.PageUI();
MgrPageUI = tmp;
}
if (tmp.myPage == null)
tmp.myPage = this;
return tmp;
}
}
#endregion
#endregion
函数#region 函数
/**//// <summary>
/// 显示第一页的数据
/// </summary>
public void BindFirstPage()
{
//生成SQL语句和获取记录总数
this.ManagerPageSQL.CreateSQL();
//绑定第一页的数据
myDataBind(1);
}
#endregion
绘制UI CreateChildControls()#region 绘制UI CreateChildControls()
/**//// <summary>
/// 绘制UI
/// </summary>
protected override void CreateChildControls()
{
base.CreateChildControls();
LinkButton btn = new LinkButton();
btn.ID = "Page_Button";
btn.Text = "";//所有的回发事件
//btn.Click += new EventHandler(btn_Click); //添加事件
this.Controls.Add(btn);
ManagerPageUI.AddPageUI(); //添加页面显示
Page_Click(); //调用分页事件
}
#endregion
响应分页事件#region 响应分页事件
/**//// <summary>
/// 响应分页事件
/// </summary>
private void Page_Click()
{
//string a = base.Page.Request.Form["__EVENTTARGET"];
string PageIndex = base.Page.Request.Form["__EVENTARGUMENT"];
if (!Functions.IsInt(PageIndex))
return;
else
myDataBind(Int32.Parse(PageIndex));
}
/**//// <summary>
/// 绑定控件
/// </summary>
private void myDataBind(Int32 PageIndex)
{
if (ControlGrid == null)
{
string CID = this.ControlGridID;
if (CID == null)
return;
else
ControlGrid = (WebControl)base.Page.FindControl(CID);
}
Int32 NoCount = this.NaviCount; //一组页号的数量
bool isNavi = false;
Int32 tmpPageIndex = this.PageIndex;
switch (PageIndex)
{
case 1: //首页
isNavi = true;
break;
case -3:
//上一页
PageIndex = this.PageIndex - 1;
break;
case -2:
//下一页
PageIndex = this.PageIndex + 1;
if (PageIndex % NoCount == 1)
isNavi = true;
break;
case -99: //前导
if (tmpPageIndex % NoCount == 0)
PageIndex = tmpPageIndex - NoCount;
else
PageIndex = tmpPageIndex / NoCount * NoCount;
isNavi = true;
break;
case -88: //后导
if (tmpPageIndex % NoCount == 0)
PageIndex = tmpPageIndex + NoCount;
else
PageIndex = (this.PageIndex / NoCount + 1) * NoCount + 1;
isNavi = true;
break;
default:
isNavi = false ;
break;
}
if (PageIndex == this.PageCount)
isNavi = true; //末页
this.PageIndex = PageIndex;
//获取记录集
DataTable dt = this.ManagerGetData.GetDataTable(PageIndex);
//通过(好像是反射)来设置 DataSource属性。
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(ControlGrid, null, "datasource", new object[] { dt }, null, null);
ControlGrid.DataBind();
//重新显示当前页号
this.ManagerPageUI.UpdatePageIndex();
//重新显示页号当航
if (isNavi)
this.ManagerPageUI.ReloadPageNavi();
else
this.ManagerPageUI.UpdatePageNavi();
//base.Page.Response.Write(a + "+" + PageIndex);
}
#endregion
/**//// <summary>
/// 接收分页控件的回发事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void btn_Click(object sender, EventArgs e)
{
//throw new NotImplementedException();
//base.Page.Response.Write("ss");
}
/**//// <summary>
/// 分页的回发事件,没有成功
/// </summary>
/// <param name="PageIndex"></param>
public void RaisePostBackEvent(string PageIndex)
{
//base.Page.Response.Write("www");
//Page_Click();
}
设计时支持#region 设计时支持
/**//// <summary>
/// 设计时支持
/// </summary>
/// <param name="output"></param>
protected override void Render(HtmlTextWriter output)
{
if ((base.Site != null) && base.Site.DesignMode)
{
output.Write("<div style='TEXT-ALIGN: center;100%'>第1/100页 首页 上一页 [1][2][3] 下一页 末页 共1000条记录</div>");
}
else
{
//Page_Click();
output.Write("<div id='" + this.ClientID + "Page' style='TEXT-ALIGN: center;90%'>");
base.Render(output);
output.Write("</div>");
}
}
#endregion
}
}