XDownPage2.10是在2.0的基础上增加了sqlserver的分页支持。它依然支持oracle数据库。由于access与oracle很相似。所以也能很好的兼容access数据库。
'
=====================================================================
' XDOWNPAGE ASP版本
' 版本 1.00
' Code by zykj2000
' Email: [email protected]
' BBS: http://bbs.513soft.net
' 本程序可以免费使用、修改,希望我的程序能为您的工作带来方便
' 但请保留以上请息
'
'
' 升级版本:2.10
' Updated by doublel,northsnow
' email: [email protected]
'
' blog: http://blog.csdn.net/precipitant
' blog: http://blog.csdn.net/doublel
' 升级说明:
' 1 , 数据查询时只查询当前页所包含的记录,大大降低了数据传输量
' 2 , 如果正常的页导航,不用每次都查询总记录数,只要第一次查询后,后来通过参数传递即可
' 3 , 支持动态更改页大小
' 4 , 支持动态排序
' 5 , 本程序支持oracle 和 sqlserver,以前发了一个oracle版(2.0),也有例子,如果只是在oracle上面用,还是用2.0好.
' 如果今天的是在原来的基础上增加了对sqlserver的支持。由于sqlserver与
' oracle还是有区别的.所以大家如果想知道如何在sqlserver如何用,请查阅例子程序
'
' 程序特点
' 本程序主要是对数据分页的部分进行了封装,而数据显示部份完全由用户自定义,
' 支持URL多个参数
'
' 使用说明
' 程序参数说明
' PapgeSize 定义分页每一页的记录数
' GetRS 返回经过分页的Recordset此属性只读
' GetConn 得到数据库连接
' GetSQL 得到查询语句
' totalRecordCount 传递总记录数
' 程序方法说明
' ShowPage 显示分页导航条,唯一的公用方法
' ShowPageSizeChange() 显示改变页大小的列表
'
' 例一:(oracle)
'
' '包含文件
'
' Set mypage=new xdownpage '创建对象
' mypage.getconn=conn '得到数据库连接
' mypage.getsql="select * from productinfo order by id asc"
' mypage.pagesize=5 '设置每一页的记录条数据为5条
' mypage.totalRecordCount=rsTotalCount 设置总记录数
' set rs=mypage.getrs() '返回Recordset
' mypage.GetSubmitForm="frmQuery" ' 分页默认提交的表单,currentpage参数
' Response.write(mypage.GetSubmitForm1()) '输出分页提交的函数
' mypage.showpage() '显示分页信息,这个方法可以,在set rs=mypage.getrs()以后
' 任意位置调用,可以调用多次
' do while not rs.eof '接下来的操作就和操作一个普通Recordset对象一样操作
' response.write rs(0) & "
' " '这里就可以自定义显示方式了
' rs.movenext
' loop
'
' 添加了保存当前页面数量的提交脚本
' 函数为GetSubmitForm()
' 需要提交给函数GetSubmitForm一个表单名字
' 在这个提交的表单里面保存变量flag,currentpage,pagesize,rsTotalCount 四个参数
' 例子如下
' flag=request("flag")
' currentpage=request("currentpage")
' currentpage=request("pagesize")
' currentpage=request("rsTotalCount")
' 在提交的表单里面加入下面四个input
' <input name="flag" type="hidden" value="< % =flag% >">
' <input name="currentpage" type="hidden" value="< % =currentpage% >">
' <input name="pagesize" type="hidden" value="< % =pagesize% >">
' <input name="rsTotalCount" type="hidden" value="< % =rsTotalCount% >">
' =====================================================================
' 例二(sqlserver)
' 与oracle大致上相似,但是也有比较不同之处.那就是sqlserver不是将一个生成的完整的sql语句传给分页对象,而是执行
' CreateSql_MSSQL方法创建.
' Set mypage=new xdownpage '创建分页类对象
' mypage.getconn=conn '得到数据库连接
' mypage.pagesize=pagesize '设置每一页的记录条数据为5条
' mypage.totalRecordCount=rsTotalCount '传递总记录数,分页的时候不用每次都去查一次
' 创建查询语句 (这个是sqlserver与oracle特别的地方
' 参数讲解: 表或视图,查询的列的列表,条件串,排序串,关键字字段
' mypage.CreateSql_MSSQL "err_type","*",strOption,strOrder,"err_type_code" '******************************
' 生成分页和导航表单
' mypage.GetSubmitForm="frmHidden"
' Response.write(mypage.GetSubmitForm1())
' 执行查询并返回结果
' set rs=mypage.getrs() '返回Recordset
Const Btn_First = " <font face=""webdings"">9</font> " ' 定义第一页按钮显示样式
Const Btn_Prev = " <font face=""webdings"">3</font> " ' 定义前一页按钮显示样式
Const Btn_Next = " <font face=""webdings"">4</font> " ' 定义下一页按钮显示样式
Const Btn_Last = " <font face=""webdings"">:</font> " ' 定义最后一页按钮显示样式
Const XD_Align = " center " ' 定义分页信息对齐方式
Const XD_Width = " 100% " ' 定义分页信息框大小
Const XD_Height = " 20 "
Class Xdownpage ' 类 从这里开始
' 变量定义
public int_totalPage ' 总页数
public int_curcount ' 当前页的记录数
public XD_PageSize ' 页大小
Private int_curpage ' 当前页号
Private int_totalRecord ' 总记录数
Private XD_Conn ' 数据库连接对象
Private XD_Rs ' 记录集对象
Private XD_SQL ' 主sql语句
Private XD_Count_SQL ' 查询总记录数的sql语句
Private Str_errors
Private str_URL
Private XD_sURL
Private SubmitForm ' 所需的查询表单名字(隐藏表单名字)
Private XD_TableName ' 表名
Private XD_FieldList ' 字段列表
Private XD_Option ' 查询条件
Private XD_PK ' 一个主关键字字段名
Private XD_Order ' 排序串
' =================================================================
' PageSize 属性
' 设置每一页的分页大小
' =================================================================
Public Property Let PageSize(int_PageSize)
If IsNumeric (Int_Pagesize) Then
if clng (Int_Pagesize) > 0 then
XD_PageSize = CLng (int_PageSize)
else
XD_PageSize = 10
end if
Else
XD_PageSize = 10
End If
End Property
Public Property Get PageSize
If XD_PageSize = "" or ( not ( IsNumeric (XD_PageSize))) Then
PageSize = 10
Else
PageSize = XD_PageSize
End If
End Property
' =================================================================
' aTableName 属性
' 查询的表名,用于自动构造语句
' =================================================================
Public Property Let aTableName(str_TableName)
XD_TableName = str_TableName
End Property
Public Property Get aTableName
aTableName = XD_TableName
End Property
' =================================================================
' aFieldList 属性
' 查询的字段列表,用于自动构造语句
' =================================================================
Public Property Let aFieldList(str_FieldList)
XD_FieldList = str_FieldList
End Property
Public Property Get aFieldList
aFieldList = XD_FieldList
End Property
' =================================================================
' aOption 属性
' 查询的条件串,用于自动构造语句
' =================================================================
Public Property Let aOption(str_Option)
XD_Option = str_Option
End Property
Public Property Get aOption
aOption = XD_Option
End Property
' =================================================================
' aPK 属性
' 查询时可用的可唯一表示一条记录的字段,用于自动构造语句
' =================================================================
Public Property Let aPK(str_PK)
XD_PK = str_PK
End Property
Public Property Get aPK
aPK = XD_PK
End Property
' =================================================================
' aOrder 属性
' 查询的排序串,用于自动构造语句
' =================================================================
Public Property Let aOrder(str_Ordert)
XD_Order = str_Order
End Property
Public Property Get aOrder
aOrder = XD_Order
End Property
' =================================================================
' GetRS 属性
' 返回分页后的记录集
' =================================================================
Public Property Get GetRs()
Set XD_Rs = Server.createobject( " adodb.recordset " )
' XD_Rs.PageSize=PageSize
XD_Rs.CursorLocation = 3
' response.Write XD_SQL
XD_Rs.Open XD_SQL,XD_Conn, 3 , 1
int_curcount = XD_Rs.RecordCount
' 规范化int_totalRecord的值
if int_totalRecord = "" or not isNumeric (int_totalRecord) then int_totalRecord = 0
if int_totalRecord = 0 and (int_curcount >= PageSize or int_curpage > 1 ) then
call queryRsCount() ' 查询总记录数
end if
if int_totalRecord = 0 and int_curcount > 0 then int_totalRecord = int_curcount
if err.number <> 0 then
Response.Write err.Clear
end if
Set GetRs = XD_RS
End Property
' =================================================================
' queryRSCount 方法
' 查询总记录数
' =================================================================
Public sub queryRsCount()
' 下面代码用于计算总记录数
if XD_Count_SQL <> "" then
set rs_sqlcount = server.createobject( " adodb.recordset " )
rs_sqlcount.CursorLocation = 3
rs_sqlcount.open XD_Count_SQL,conn, 3 , 1
if (rs_sqlcount.eof and rs_sqlcount.bof) then
int_totalRecord = 0
else
int_totalRecord = rs_sqlcount( 0 )
int_totalRecord = clng (int_totalRecord)
end if
rs_sqlcount.close
set rs_sqlcount = nothing
end if
End sub
' ================================================================
' GetConn 得到数据库连接
'
' ================================================================
Public Property Let GetConn(obj_Conn)
Set XD_Conn = obj_Conn
End Property
' ================================================================
' GetSQL 得到查询语句,
'
' ================================================================
Public Property Let GetSQL(str_sql)
if (str_sql <> "" ) then
' 根据给定查询语句,生成最终的查询语句(只取当前页内容):适用于oracle数据库
XD_SQL = " select * from (select rownum r_n,temptable.* from ( "
XD_SQL = XD_SQL & str_sql
XD_SQL = XD_SQL & " ) temptable ) where r_n between " & cstr ((int_curpage - 1 ) * XD_PageSize + 1 ) & " and " & cstr (int_curpage * XD_PageSize)
' 查询总记录数的查询语句
XD_Count_SQL = " select count(*) from ( " & str_sql & " ) "
end if
End Property
' ================================================================
' CreateSql_MSSQL 为对sqlserver的查询构造查询串
'
' ================================================================
Public sub CreateSql_MSSQL(ooTableName,ooFieldList,ooOption,ooOrder,ooPK)
XD_TableName = ooTableName
XD_FieldList = ooFieldList
XD_Option = ooOption
XD_Order = ooOrder
XD_PK = ooPK
' response.Write XD_tablename
if (XD_TableName <> "" and XD_FieldList <> "" and XD_PK <> "" ) then
if (int_curpage > 1 ) then
XD_SQL = " select top " & XD_PageSize & " " & XD_FieldList & " from " & XD_TableName & " " & XD_Option
XD_SQL = XD_SQL & " and " & XD_PK & " not in(select top " & XD_PageSize * (int_curpage - 1 ) & " " & XD_PK & " from " & XD_TableName & " " & XD_Option & " " & XD_Order & " ) " & XD_Order
else
XD_SQL = " select top " & XD_PageSize & " " & XD_FieldList & " from " & XD_TableName & " " & XD_Option & " " & XD_Order
end if
' 查询总记录数的查询语句
XD_Count_SQL = " select count(*) from " & XD_TableName & " " & XD_Option
end if
' response.Write XD_SQL
End sub
' ================================================================
' GetSubmitForm属性 设置查询条件的表单
'
' ================================================================
Public Property Let GetSubmitForm(frmName)
SubmitForm = trim (frmName)
End Property
' ================================================================
' GetSubmitForm1方法 输出分页导航所需脚本
'
' ================================================================
public sub GetSubmitForm1()
' 页导航的javascript函数
Response.Write " " + vrcrlf
Response.Write ( " <Script language=""javascript""> " ) + vbcrlf
Response.Write " function generalSubmit(i) " + vbcrlf
Response.Write " { " + vbcrlf
Response.Write " document. " & SubmitForm & " .flag.value=""query1111111155555""; " + vbcrlf
Response.Write " document. " & SubmitForm & " .currentpage.value=i; " + vbcrlf
Response.Write " " & SubmitForm & " .submit(); " + vbcrlf
Response.Write " } " + vbcrlf
' 改变页大小的javascript函数
Response.Write " function changePageSize(ii) " + vbcrlf
Response.Write " { " + vbcrlf
Response.Write " document. " & SubmitForm & " .flag.value=""query1111111155555""; " + vbcrlf
Response.Write " document. " & SubmitForm & " .currentpage.value=1; " + vbcrlf
Response.Write " document. " & SubmitForm & " .pagesize.value=ii; " + vbcrlf
Response.Write " " & SubmitForm & " .submit(); " + vbcrlf
Response.Write " } " + vbcrlf
Response.Write ( " </Script> " ) + vbcrlf
Response.Write " " + vrcrlf
end sub
' ==================================================================
' totalRecordCount 属性
' 关于记录总数
'
' ==================================================================
Public Property Let totalRecordCount(int_totalRecordCount)
If IsNumeric (int_totalRecordCount) Then
int_totalRecord = CLng (int_totalRecordCount)
End If
End Property
Public Property Get totalRecordCount
If not (int_totalRecord = "" or ( not ( IsNumeric (int_totalRecord)))) Then
totalRecordCount = int_totalRecord
End If
End Property
' ==================================================================
' GetRecordCount 方法
' 返回当前记录数
'
' ==================================================================
public function GetRecordCount()
GetRecordCount = int_totalRecord
end function
' ==================================================================
' Class_Initialize 类的初始化
' 初始化当前页的值
'
' ==================================================================
Private Sub Class_Initialize
' ========================
' 设定一些参数的黙认值
' ========================
' XD_PageSize=10 '设定分页的默认值为10
' ========================
' 获取当前面的值
' ========================
If Request( " currentpage " ) = "" Then
int_curpage = 1
ElseIf not ( IsNumeric (Request( " currentpage " ))) Then
int_curpage = 1
ElseIf CInt ( Trim (Request( " currentpage " ))) < 1 Then
int_curpage = 1
Else
Int_curpage = CInt ( Trim (Request( " currentpage " )))
End If
End Sub
' ====================================================================
' ShowPage 创建分页导航条
' 有首页、前一页、下一页、末页、还有数字导航
'
' ====================================================================
Public Sub ShowPage()
Dim str_tmp
XD_sURL = GetUrl()
' int_totalRecord=XD_Rs.RecordCount
If int_totalRecord <= 0 Then
str_error = str_error & " 总记录数为零,请输入数据 "
Call ShowError()
End If
if clng (int_curpage) = 0 then int_curpage = 1
If int_totalRecord = "" then int_totalRecord = 0
if int_totalRecord = 0 then int_TotalPage = 1
if int_totalRecord > 0 then
' modify by wls 041215 For the right pages display---------------
If int_totalRecord mod PageSize = 0 Then
int_TotalPage = CLng (int_TotalRecord / XD_PageSize * - 1 ) *- 1
Else
int_TotalPage = CLng (int_TotalRecord / XD_PageSize * - 1 ) *- 1 + 1
End If
End If
If Int_curpage > int_Totalpage Then
int_curpage = int_TotalPage
End If
' response.Write "?? " & int_curpage & ":" & int_totalpage & ":" & xd_pagesize & ":" & int_totalrecord & "**"
' ===============================================================================
' 显示分页信息,各个模块根据自己要求更改显求位置
' ===============================================================================
' response.write " "
str_tmp = ShowFirstPrv
response.write str_tmp
str_tmp = showNumBtn
response.write str_tmp
str_tmp = ShowNextLast
response.write str_tmp
str_tmp = ShowPageInfo
response.write str_tmp
Response.write " "
ShowGoto
End Sub
' ====================================================================
' ShowFirstPrv 显示首页、前一页
'
'
' ====================================================================
Private Function ShowFirstPrv()
Dim Str_tmp,int_prvpage
If int_curpage = 1 Then
str_tmp = Btn_First & " " & Btn_Prev
Elseif int_curpage = 0 then
str_tmp = Btn_First & " " & Btn_Prev
else
int_prvpage = int_curpage - 1
str_tmp = " <a href=""#"" οnclick=""javascript:generalSubmit('1')"" alt=""第一页""> " & Btn_First & " </a> <a href=""#"" οnclick=""javascript:generalSubmit(' " & int_prvpage & " ')"" alt=""前一页""> " & Btn_Prev & " </a> "
End If
ShowFirstPrv = str_tmp
End Function
' ====================================================================
' ShowNextLast 下一页、末页
'
'
' ====================================================================
Private Function ShowNextLast()
Dim str_tmp,int_Nextpage
If Int_curpage >= int_totalpage Then
str_tmp = Btn_Next & " " & Btn_Last
Else
Int_NextPage = int_curpage + 1
str_tmp = " <a href=""#"" οnclick=""javascript:generalSubmit(' " & int_nextpage & " ')"" alt=""后一页""> " & Btn_Next & " </a> <a href=""#"" οnclick=""javascript:generalSubmit(' " & int_totalpage & " ')"" alt=""最后一页""> " & Btn_Last & " </a> "
End If
ShowNextLast = str_tmp
End Function
' End Function
' ====================================================================
' ShowNumBtn 修改后的数字导航
'
' ====================================================================
Function showNumBtn()
Dim i,str_tmp,end_page,start_page
start_page = 1
' add by sll 2005.05.20 int_curpage=0
if int_curpage = 0 then
str_tmp = str_tmp & " 0 "
else
if int_curpage > 1 then
start_page = int_curpage
if (int_curpage <= 5 ) then
start_page = 1
end if
if (int_curpage > 5 ) then
start_page = int_curpage - 2
end if
end if
end_page = start_page + 5
if end_page > int_totalpage then
end_page = int_totalpage
end if
For i = start_page to end_page
strTemp = XD_sURL & CStr (i)
str_tmp = str_tmp & " [<a href=""#"" οnclick=""javascript:generalSubmit(' " & i & " ')""> " & i & " </a>] "
Next
end if
showNumBtn = str_tmp
End Function
' ====================================================================
' ShowGoto 页面跳转
' 页面自动跳转
' add by sll 2005.05.20
' ====================================================================
Private Function ShowGoto()
' response.write int_totalPage
dim inti
if int_totalPage <= 0 then
response.write " <select name='goto' disabled> "
Response.Write " <option value='0'>0</option> "
response.write " </select> "
else
response.write " <select name='goto' οnchange='javascript:generalSubmit(this.value)'> "
for inti = 1 to int_totalPage
Response.Write " <option value=' " & inti & " ' "
if cstr (inti) = cstr (int_curpage) then
response.write " selected "
end if
response.write " > " & inti & " </option> "
next
response.write " </select> "
end if
End Function
' ====================================================================
' ShowPageInfo 分页信息
' 根据要求自行修改
'
' ====================================================================
Private Function ShowPageInfo()
Dim str_tmp
str_tmp = " [页次:<font color=red> " & int_curpage & " </font>/ " & int_totalpage & " 页] [共 " & int_totalrecord & " 条] [ " & XD_PageSize & " 条/页] "
ShowPageInfo = str_tmp
End Function
' ====================================================================
' ShowPageSizeChange 改变页大小
' 根据要求自行修改
'
' ====================================================================
public sub ShowPageSizeChange()
Dim str_tmp
dim eFlag:eFlag = 0
str_tmp = " 页大小:<select name='sssssPageSize' οnchange='changePageSize(this.value)'> "
str_tmp = str_tmp & " <option "
if XD_PageSize = 10 then
str_tmp = str_tmp & " selected "
eFlag = 1
end if
str_tmp = str_tmp & " value='10'>10</option> "
str_tmp = str_tmp & " <option "
if XD_PageSize = 20 then
str_tmp = str_tmp & " selected "
eFlag = 1
end if
str_tmp = str_tmp & " value='20'>20</option> "
str_tmp = str_tmp & " <option "
if XD_PageSize = 50 then
str_tmp = str_tmp & " selected "
eFlag = 1
end if
str_tmp = str_tmp & " value='50'>50</option> "
str_tmp = str_tmp & " <option "
if XD_PageSize = int_totalRecord then
str_tmp = str_tmp & " selected "
eFlag = 1
end if
str_tmp = str_tmp & " value=' " & int_totalRecord & " '>all</option> "
if eFlag = 0 then
str_tmp = str_tmp & " <option selected value=' " & XD_PageSize & " '> " & XD_PageSize & " </option> "
end if
str_tmp = str_tmp & " </select> "
response.Write str_tmp
End sub
' ====================================================================
' 修改后的获取当前Url参数的函数
' Codeing by Redsun
' northsnow注释:不知道用在何处,但是保留
' ====================================================================
Private Function GetUrl()
Dim ScriptAddress, M_ItemUrl, M_item
ScriptAddress = CStr (Request.ServerVariables( " SCRIPT_NAME " )) & " ? " ' 取得当前地址
If (Request.QueryString <> "" ) Then
M_ItemUrl = ""
For Each M_item In Request.QueryString
If InStr ( " page " ,M_Item) = 0 Then
M_ItemUrl = M_ItemUrl & M_Item & " = " & Server.URLEncode(Request.QueryString( "" & M_Item & "" )) & " & "
End If
Next
ScriptAddress = ScriptAddress & M_ItemUrl ' 取得带参数地址
End If
GetUrl = ScriptAddress ' & "page="
End Function
' ====================================================================
' 设置 Terminate 事件。
' ====================================================================
Private Sub Class_Terminate
' XD_RS.close
' Set XD_RS=nothing
End Sub
' ====================================================================
' ShowError 错误提示
' ====================================================================
Private Sub ShowError()
If str_Error <> "" Then
Response.Write( "" & SW_Error & "" )
Response.End
End If
End Sub
End class
' XDOWNPAGE ASP版本
' 版本 1.00
' Code by zykj2000
' Email: [email protected]
' BBS: http://bbs.513soft.net
' 本程序可以免费使用、修改,希望我的程序能为您的工作带来方便
' 但请保留以上请息
'
'
' 升级版本:2.10
' Updated by doublel,northsnow
' email: [email protected]
'
' blog: http://blog.csdn.net/precipitant
' blog: http://blog.csdn.net/doublel
' 升级说明:
' 1 , 数据查询时只查询当前页所包含的记录,大大降低了数据传输量
' 2 , 如果正常的页导航,不用每次都查询总记录数,只要第一次查询后,后来通过参数传递即可
' 3 , 支持动态更改页大小
' 4 , 支持动态排序
' 5 , 本程序支持oracle 和 sqlserver,以前发了一个oracle版(2.0),也有例子,如果只是在oracle上面用,还是用2.0好.
' 如果今天的是在原来的基础上增加了对sqlserver的支持。由于sqlserver与
' oracle还是有区别的.所以大家如果想知道如何在sqlserver如何用,请查阅例子程序
'
' 程序特点
' 本程序主要是对数据分页的部分进行了封装,而数据显示部份完全由用户自定义,
' 支持URL多个参数
'
' 使用说明
' 程序参数说明
' PapgeSize 定义分页每一页的记录数
' GetRS 返回经过分页的Recordset此属性只读
' GetConn 得到数据库连接
' GetSQL 得到查询语句
' totalRecordCount 传递总记录数
' 程序方法说明
' ShowPage 显示分页导航条,唯一的公用方法
' ShowPageSizeChange() 显示改变页大小的列表
'
' 例一:(oracle)
'
' '包含文件
'
' Set mypage=new xdownpage '创建对象
' mypage.getconn=conn '得到数据库连接
' mypage.getsql="select * from productinfo order by id asc"
' mypage.pagesize=5 '设置每一页的记录条数据为5条
' mypage.totalRecordCount=rsTotalCount 设置总记录数
' set rs=mypage.getrs() '返回Recordset
' mypage.GetSubmitForm="frmQuery" ' 分页默认提交的表单,currentpage参数
' Response.write(mypage.GetSubmitForm1()) '输出分页提交的函数
' mypage.showpage() '显示分页信息,这个方法可以,在set rs=mypage.getrs()以后
' 任意位置调用,可以调用多次
' do while not rs.eof '接下来的操作就和操作一个普通Recordset对象一样操作
' response.write rs(0) & "
' " '这里就可以自定义显示方式了
' rs.movenext
' loop
'
' 添加了保存当前页面数量的提交脚本
' 函数为GetSubmitForm()
' 需要提交给函数GetSubmitForm一个表单名字
' 在这个提交的表单里面保存变量flag,currentpage,pagesize,rsTotalCount 四个参数
' 例子如下
' flag=request("flag")
' currentpage=request("currentpage")
' currentpage=request("pagesize")
' currentpage=request("rsTotalCount")
' 在提交的表单里面加入下面四个input
' <input name="flag" type="hidden" value="< % =flag% >">
' <input name="currentpage" type="hidden" value="< % =currentpage% >">
' <input name="pagesize" type="hidden" value="< % =pagesize% >">
' <input name="rsTotalCount" type="hidden" value="< % =rsTotalCount% >">
' =====================================================================
' 例二(sqlserver)
' 与oracle大致上相似,但是也有比较不同之处.那就是sqlserver不是将一个生成的完整的sql语句传给分页对象,而是执行
' CreateSql_MSSQL方法创建.
' Set mypage=new xdownpage '创建分页类对象
' mypage.getconn=conn '得到数据库连接
' mypage.pagesize=pagesize '设置每一页的记录条数据为5条
' mypage.totalRecordCount=rsTotalCount '传递总记录数,分页的时候不用每次都去查一次
' 创建查询语句 (这个是sqlserver与oracle特别的地方
' 参数讲解: 表或视图,查询的列的列表,条件串,排序串,关键字字段
' mypage.CreateSql_MSSQL "err_type","*",strOption,strOrder,"err_type_code" '******************************
' 生成分页和导航表单
' mypage.GetSubmitForm="frmHidden"
' Response.write(mypage.GetSubmitForm1())
' 执行查询并返回结果
' set rs=mypage.getrs() '返回Recordset
Const Btn_First = " <font face=""webdings"">9</font> " ' 定义第一页按钮显示样式
Const Btn_Prev = " <font face=""webdings"">3</font> " ' 定义前一页按钮显示样式
Const Btn_Next = " <font face=""webdings"">4</font> " ' 定义下一页按钮显示样式
Const Btn_Last = " <font face=""webdings"">:</font> " ' 定义最后一页按钮显示样式
Const XD_Align = " center " ' 定义分页信息对齐方式
Const XD_Width = " 100% " ' 定义分页信息框大小
Const XD_Height = " 20 "
Class Xdownpage ' 类 从这里开始
' 变量定义
public int_totalPage ' 总页数
public int_curcount ' 当前页的记录数
public XD_PageSize ' 页大小
Private int_curpage ' 当前页号
Private int_totalRecord ' 总记录数
Private XD_Conn ' 数据库连接对象
Private XD_Rs ' 记录集对象
Private XD_SQL ' 主sql语句
Private XD_Count_SQL ' 查询总记录数的sql语句
Private Str_errors
Private str_URL
Private XD_sURL
Private SubmitForm ' 所需的查询表单名字(隐藏表单名字)
Private XD_TableName ' 表名
Private XD_FieldList ' 字段列表
Private XD_Option ' 查询条件
Private XD_PK ' 一个主关键字字段名
Private XD_Order ' 排序串
' =================================================================
' PageSize 属性
' 设置每一页的分页大小
' =================================================================
Public Property Let PageSize(int_PageSize)
If IsNumeric (Int_Pagesize) Then
if clng (Int_Pagesize) > 0 then
XD_PageSize = CLng (int_PageSize)
else
XD_PageSize = 10
end if
Else
XD_PageSize = 10
End If
End Property
Public Property Get PageSize
If XD_PageSize = "" or ( not ( IsNumeric (XD_PageSize))) Then
PageSize = 10
Else
PageSize = XD_PageSize
End If
End Property
' =================================================================
' aTableName 属性
' 查询的表名,用于自动构造语句
' =================================================================
Public Property Let aTableName(str_TableName)
XD_TableName = str_TableName
End Property
Public Property Get aTableName
aTableName = XD_TableName
End Property
' =================================================================
' aFieldList 属性
' 查询的字段列表,用于自动构造语句
' =================================================================
Public Property Let aFieldList(str_FieldList)
XD_FieldList = str_FieldList
End Property
Public Property Get aFieldList
aFieldList = XD_FieldList
End Property
' =================================================================
' aOption 属性
' 查询的条件串,用于自动构造语句
' =================================================================
Public Property Let aOption(str_Option)
XD_Option = str_Option
End Property
Public Property Get aOption
aOption = XD_Option
End Property
' =================================================================
' aPK 属性
' 查询时可用的可唯一表示一条记录的字段,用于自动构造语句
' =================================================================
Public Property Let aPK(str_PK)
XD_PK = str_PK
End Property
Public Property Get aPK
aPK = XD_PK
End Property
' =================================================================
' aOrder 属性
' 查询的排序串,用于自动构造语句
' =================================================================
Public Property Let aOrder(str_Ordert)
XD_Order = str_Order
End Property
Public Property Get aOrder
aOrder = XD_Order
End Property
' =================================================================
' GetRS 属性
' 返回分页后的记录集
' =================================================================
Public Property Get GetRs()
Set XD_Rs = Server.createobject( " adodb.recordset " )
' XD_Rs.PageSize=PageSize
XD_Rs.CursorLocation = 3
' response.Write XD_SQL
XD_Rs.Open XD_SQL,XD_Conn, 3 , 1
int_curcount = XD_Rs.RecordCount
' 规范化int_totalRecord的值
if int_totalRecord = "" or not isNumeric (int_totalRecord) then int_totalRecord = 0
if int_totalRecord = 0 and (int_curcount >= PageSize or int_curpage > 1 ) then
call queryRsCount() ' 查询总记录数
end if
if int_totalRecord = 0 and int_curcount > 0 then int_totalRecord = int_curcount
if err.number <> 0 then
Response.Write err.Clear
end if
Set GetRs = XD_RS
End Property
' =================================================================
' queryRSCount 方法
' 查询总记录数
' =================================================================
Public sub queryRsCount()
' 下面代码用于计算总记录数
if XD_Count_SQL <> "" then
set rs_sqlcount = server.createobject( " adodb.recordset " )
rs_sqlcount.CursorLocation = 3
rs_sqlcount.open XD_Count_SQL,conn, 3 , 1
if (rs_sqlcount.eof and rs_sqlcount.bof) then
int_totalRecord = 0
else
int_totalRecord = rs_sqlcount( 0 )
int_totalRecord = clng (int_totalRecord)
end if
rs_sqlcount.close
set rs_sqlcount = nothing
end if
End sub
' ================================================================
' GetConn 得到数据库连接
'
' ================================================================
Public Property Let GetConn(obj_Conn)
Set XD_Conn = obj_Conn
End Property
' ================================================================
' GetSQL 得到查询语句,
'
' ================================================================
Public Property Let GetSQL(str_sql)
if (str_sql <> "" ) then
' 根据给定查询语句,生成最终的查询语句(只取当前页内容):适用于oracle数据库
XD_SQL = " select * from (select rownum r_n,temptable.* from ( "
XD_SQL = XD_SQL & str_sql
XD_SQL = XD_SQL & " ) temptable ) where r_n between " & cstr ((int_curpage - 1 ) * XD_PageSize + 1 ) & " and " & cstr (int_curpage * XD_PageSize)
' 查询总记录数的查询语句
XD_Count_SQL = " select count(*) from ( " & str_sql & " ) "
end if
End Property
' ================================================================
' CreateSql_MSSQL 为对sqlserver的查询构造查询串
'
' ================================================================
Public sub CreateSql_MSSQL(ooTableName,ooFieldList,ooOption,ooOrder,ooPK)
XD_TableName = ooTableName
XD_FieldList = ooFieldList
XD_Option = ooOption
XD_Order = ooOrder
XD_PK = ooPK
' response.Write XD_tablename
if (XD_TableName <> "" and XD_FieldList <> "" and XD_PK <> "" ) then
if (int_curpage > 1 ) then
XD_SQL = " select top " & XD_PageSize & " " & XD_FieldList & " from " & XD_TableName & " " & XD_Option
XD_SQL = XD_SQL & " and " & XD_PK & " not in(select top " & XD_PageSize * (int_curpage - 1 ) & " " & XD_PK & " from " & XD_TableName & " " & XD_Option & " " & XD_Order & " ) " & XD_Order
else
XD_SQL = " select top " & XD_PageSize & " " & XD_FieldList & " from " & XD_TableName & " " & XD_Option & " " & XD_Order
end if
' 查询总记录数的查询语句
XD_Count_SQL = " select count(*) from " & XD_TableName & " " & XD_Option
end if
' response.Write XD_SQL
End sub
' ================================================================
' GetSubmitForm属性 设置查询条件的表单
'
' ================================================================
Public Property Let GetSubmitForm(frmName)
SubmitForm = trim (frmName)
End Property
' ================================================================
' GetSubmitForm1方法 输出分页导航所需脚本
'
' ================================================================
public sub GetSubmitForm1()
' 页导航的javascript函数
Response.Write " " + vrcrlf
Response.Write ( " <Script language=""javascript""> " ) + vbcrlf
Response.Write " function generalSubmit(i) " + vbcrlf
Response.Write " { " + vbcrlf
Response.Write " document. " & SubmitForm & " .flag.value=""query1111111155555""; " + vbcrlf
Response.Write " document. " & SubmitForm & " .currentpage.value=i; " + vbcrlf
Response.Write " " & SubmitForm & " .submit(); " + vbcrlf
Response.Write " } " + vbcrlf
' 改变页大小的javascript函数
Response.Write " function changePageSize(ii) " + vbcrlf
Response.Write " { " + vbcrlf
Response.Write " document. " & SubmitForm & " .flag.value=""query1111111155555""; " + vbcrlf
Response.Write " document. " & SubmitForm & " .currentpage.value=1; " + vbcrlf
Response.Write " document. " & SubmitForm & " .pagesize.value=ii; " + vbcrlf
Response.Write " " & SubmitForm & " .submit(); " + vbcrlf
Response.Write " } " + vbcrlf
Response.Write ( " </Script> " ) + vbcrlf
Response.Write " " + vrcrlf
end sub
' ==================================================================
' totalRecordCount 属性
' 关于记录总数
'
' ==================================================================
Public Property Let totalRecordCount(int_totalRecordCount)
If IsNumeric (int_totalRecordCount) Then
int_totalRecord = CLng (int_totalRecordCount)
End If
End Property
Public Property Get totalRecordCount
If not (int_totalRecord = "" or ( not ( IsNumeric (int_totalRecord)))) Then
totalRecordCount = int_totalRecord
End If
End Property
' ==================================================================
' GetRecordCount 方法
' 返回当前记录数
'
' ==================================================================
public function GetRecordCount()
GetRecordCount = int_totalRecord
end function
' ==================================================================
' Class_Initialize 类的初始化
' 初始化当前页的值
'
' ==================================================================
Private Sub Class_Initialize
' ========================
' 设定一些参数的黙认值
' ========================
' XD_PageSize=10 '设定分页的默认值为10
' ========================
' 获取当前面的值
' ========================
If Request( " currentpage " ) = "" Then
int_curpage = 1
ElseIf not ( IsNumeric (Request( " currentpage " ))) Then
int_curpage = 1
ElseIf CInt ( Trim (Request( " currentpage " ))) < 1 Then
int_curpage = 1
Else
Int_curpage = CInt ( Trim (Request( " currentpage " )))
End If
End Sub
' ====================================================================
' ShowPage 创建分页导航条
' 有首页、前一页、下一页、末页、还有数字导航
'
' ====================================================================
Public Sub ShowPage()
Dim str_tmp
XD_sURL = GetUrl()
' int_totalRecord=XD_Rs.RecordCount
If int_totalRecord <= 0 Then
str_error = str_error & " 总记录数为零,请输入数据 "
Call ShowError()
End If
if clng (int_curpage) = 0 then int_curpage = 1
If int_totalRecord = "" then int_totalRecord = 0
if int_totalRecord = 0 then int_TotalPage = 1
if int_totalRecord > 0 then
' modify by wls 041215 For the right pages display---------------
If int_totalRecord mod PageSize = 0 Then
int_TotalPage = CLng (int_TotalRecord / XD_PageSize * - 1 ) *- 1
Else
int_TotalPage = CLng (int_TotalRecord / XD_PageSize * - 1 ) *- 1 + 1
End If
End If
If Int_curpage > int_Totalpage Then
int_curpage = int_TotalPage
End If
' response.Write "?? " & int_curpage & ":" & int_totalpage & ":" & xd_pagesize & ":" & int_totalrecord & "**"
' ===============================================================================
' 显示分页信息,各个模块根据自己要求更改显求位置
' ===============================================================================
' response.write " "
str_tmp = ShowFirstPrv
response.write str_tmp
str_tmp = showNumBtn
response.write str_tmp
str_tmp = ShowNextLast
response.write str_tmp
str_tmp = ShowPageInfo
response.write str_tmp
Response.write " "
ShowGoto
End Sub
' ====================================================================
' ShowFirstPrv 显示首页、前一页
'
'
' ====================================================================
Private Function ShowFirstPrv()
Dim Str_tmp,int_prvpage
If int_curpage = 1 Then
str_tmp = Btn_First & " " & Btn_Prev
Elseif int_curpage = 0 then
str_tmp = Btn_First & " " & Btn_Prev
else
int_prvpage = int_curpage - 1
str_tmp = " <a href=""#"" οnclick=""javascript:generalSubmit('1')"" alt=""第一页""> " & Btn_First & " </a> <a href=""#"" οnclick=""javascript:generalSubmit(' " & int_prvpage & " ')"" alt=""前一页""> " & Btn_Prev & " </a> "
End If
ShowFirstPrv = str_tmp
End Function
' ====================================================================
' ShowNextLast 下一页、末页
'
'
' ====================================================================
Private Function ShowNextLast()
Dim str_tmp,int_Nextpage
If Int_curpage >= int_totalpage Then
str_tmp = Btn_Next & " " & Btn_Last
Else
Int_NextPage = int_curpage + 1
str_tmp = " <a href=""#"" οnclick=""javascript:generalSubmit(' " & int_nextpage & " ')"" alt=""后一页""> " & Btn_Next & " </a> <a href=""#"" οnclick=""javascript:generalSubmit(' " & int_totalpage & " ')"" alt=""最后一页""> " & Btn_Last & " </a> "
End If
ShowNextLast = str_tmp
End Function
' End Function
' ====================================================================
' ShowNumBtn 修改后的数字导航
'
' ====================================================================
Function showNumBtn()
Dim i,str_tmp,end_page,start_page
start_page = 1
' add by sll 2005.05.20 int_curpage=0
if int_curpage = 0 then
str_tmp = str_tmp & " 0 "
else
if int_curpage > 1 then
start_page = int_curpage
if (int_curpage <= 5 ) then
start_page = 1
end if
if (int_curpage > 5 ) then
start_page = int_curpage - 2
end if
end if
end_page = start_page + 5
if end_page > int_totalpage then
end_page = int_totalpage
end if
For i = start_page to end_page
strTemp = XD_sURL & CStr (i)
str_tmp = str_tmp & " [<a href=""#"" οnclick=""javascript:generalSubmit(' " & i & " ')""> " & i & " </a>] "
Next
end if
showNumBtn = str_tmp
End Function
' ====================================================================
' ShowGoto 页面跳转
' 页面自动跳转
' add by sll 2005.05.20
' ====================================================================
Private Function ShowGoto()
' response.write int_totalPage
dim inti
if int_totalPage <= 0 then
response.write " <select name='goto' disabled> "
Response.Write " <option value='0'>0</option> "
response.write " </select> "
else
response.write " <select name='goto' οnchange='javascript:generalSubmit(this.value)'> "
for inti = 1 to int_totalPage
Response.Write " <option value=' " & inti & " ' "
if cstr (inti) = cstr (int_curpage) then
response.write " selected "
end if
response.write " > " & inti & " </option> "
next
response.write " </select> "
end if
End Function
' ====================================================================
' ShowPageInfo 分页信息
' 根据要求自行修改
'
' ====================================================================
Private Function ShowPageInfo()
Dim str_tmp
str_tmp = " [页次:<font color=red> " & int_curpage & " </font>/ " & int_totalpage & " 页] [共 " & int_totalrecord & " 条] [ " & XD_PageSize & " 条/页] "
ShowPageInfo = str_tmp
End Function
' ====================================================================
' ShowPageSizeChange 改变页大小
' 根据要求自行修改
'
' ====================================================================
public sub ShowPageSizeChange()
Dim str_tmp
dim eFlag:eFlag = 0
str_tmp = " 页大小:<select name='sssssPageSize' οnchange='changePageSize(this.value)'> "
str_tmp = str_tmp & " <option "
if XD_PageSize = 10 then
str_tmp = str_tmp & " selected "
eFlag = 1
end if
str_tmp = str_tmp & " value='10'>10</option> "
str_tmp = str_tmp & " <option "
if XD_PageSize = 20 then
str_tmp = str_tmp & " selected "
eFlag = 1
end if
str_tmp = str_tmp & " value='20'>20</option> "
str_tmp = str_tmp & " <option "
if XD_PageSize = 50 then
str_tmp = str_tmp & " selected "
eFlag = 1
end if
str_tmp = str_tmp & " value='50'>50</option> "
str_tmp = str_tmp & " <option "
if XD_PageSize = int_totalRecord then
str_tmp = str_tmp & " selected "
eFlag = 1
end if
str_tmp = str_tmp & " value=' " & int_totalRecord & " '>all</option> "
if eFlag = 0 then
str_tmp = str_tmp & " <option selected value=' " & XD_PageSize & " '> " & XD_PageSize & " </option> "
end if
str_tmp = str_tmp & " </select> "
response.Write str_tmp
End sub
' ====================================================================
' 修改后的获取当前Url参数的函数
' Codeing by Redsun
' northsnow注释:不知道用在何处,但是保留
' ====================================================================
Private Function GetUrl()
Dim ScriptAddress, M_ItemUrl, M_item
ScriptAddress = CStr (Request.ServerVariables( " SCRIPT_NAME " )) & " ? " ' 取得当前地址
If (Request.QueryString <> "" ) Then
M_ItemUrl = ""
For Each M_item In Request.QueryString
If InStr ( " page " ,M_Item) = 0 Then
M_ItemUrl = M_ItemUrl & M_Item & " = " & Server.URLEncode(Request.QueryString( "" & M_Item & "" )) & " & "
End If
Next
ScriptAddress = ScriptAddress & M_ItemUrl ' 取得带参数地址
End If
GetUrl = ScriptAddress ' & "page="
End Function
' ====================================================================
' 设置 Terminate 事件。
' ====================================================================
Private Sub Class_Terminate
' XD_RS.close
' Set XD_RS=nothing
End Sub
' ====================================================================
' ShowError 错误提示
' ====================================================================
Private Sub ShowError()
If str_Error <> "" Then
Response.Write( "" & SW_Error & "" )
Response.End
End If
End Sub
End class