asp分页的一个类

时间:2021-05-28

asp分页的一个类
在50,000条记录下测试过,速度比ado的那个要快多了

<%

'************************************************************************************
'具体用法
DimstrDbPath
Dimconnstr
Dimmp
Setmp=NewMyPage
strDbPath="fenye/db.mdb"
connstr="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="
connstr=connstr&Server.MapPath(strDbPath)
Setconn=Server.CreateObject("Adodb.Connection")
conn.openconnstr
setrs=mp.Execute("select*fromtable1",conn,29)
whilenotrs.eof
response.writers("aaaa")&"<br>"
rs.MoveNext
wend
mp.pageDispaly()
'************************************************************************************
ClassMyPage
privateMyPage_Conn,MyPage_StrSql,MyPage_TotalStrSql,MyPage_RS,MyPage_TotalRS
privateMyPage_PageSize
privateMyPage_PageAbsolute,MyPage_PageTotal,MyPage_RecordTotal
privateMyPage_Url
publicpropertyletconn(strConn)
setMyPage_Conn=strConn
endproperty

publicpropertyletPageSize(intPageSize)
MyPage_PageSize=Cint(intPageSize)
endproperty

publicfunctionPageExecute(strSql)
MyPage_PageAbsolute=MyPage_PageAbsoluteRequest()
MyPage_TotalStrSql=FormatMyPage_TotalStrSql(strSql)
setMyPage_TotalRS=MyPage_Conn.execute(MyPage_TotalStrSql)
MyPage_RecordTotal=MyPage_TotalRS("total")
MyPage_PageTotal=Cint(MyPage_RecordTotal/MyPage_PageSize)
MyPage_StrSql=FormatMyPage_StrSql(strSql)
setMyPage_RS=MyPage_Conn.execute(MyPage_StrSql)
dimi
i=0
whilenotMyPage_RS.eofandi<(MyPage_PageAbsolute-1)*MyPage_PageSize
i=i+1
MyPage_RS.MoveNext
wend
setPageExecute=MyPage_RS
endfunction

publicfunctionExecute(strSql,strConn,intPageSize)
conn=strConn
PageSize=intPageSize
setExecute=PageExecute(strSql)
endfunction

publicfunctionpageDispaly()
MyPage_Url=ReadMyPage_Url
firstPageTag="<fontface=webdings>9</font>"'|<<
LastPageTag="<fontface=webdings>:</font>"'>>|
previewPageTag="<fontface=webdings>7</font>"'<<
nextPageTag="<fontface=webdings>8</font>"'>>
dimstrAnd
ifinstr(MyPage_Url,"?")=0then
strAnd="?"
else
strAnd="&"
endif
response.write"<tablewidth=100%border=0cellspacing=0cellpadding=0>"
response.write"<tr>"
response.write"<tdalign=left>"
response.write"页次:"&MyPage_PageAbsolute&"/"&MyPage_PageTotal&"页&nbsp"
response.write"主题数:"&MyPage_RecordTotal
response.write"</td>"
response.write"<tdalign=right>"
response.write"分页:"
ifMyPage_PageAbsolute>10then
response.write"<ahref='"&MyPage_Url&strAnd&"MyPage_PageNo=1'>"&firstPageTag&"</a>"
response.write"<ahref='"&MyPage_Url&strAnd&"MyPage_PageNo="&(MyPage_PageAbsolute-10)&"'>"&previewPageTag&"</a>"
else
response.writefirstPageTag
response.writepreviewPageTag
endif
response.write"&nbsp"
dimCurrentStartPage,i
i=1
CurrentStartPage=(Cint(MyPage_PageAbsolute)\10)*10+1
ifCint(MyPage_PageAbsolute)mod10=0then
CurrentStartPage=CurrentStartPage-10
endif
whilei<11andCurrentStartPage<MyPage_PageTotal+1
ifCurrentStartPage<10then
FormatCurrentStartPage="0"&CurrentStartPage
else
FormatCurrentStartPage=CurrentStartPage
endif
response.write"<ahref='"&MyPage_Url&strAnd&"MyPage_PageNo="&CurrentStartPage&"'>"&FormatCurrentStartPage&"</a>&nbsp"
i=i+1
CurrentStartPage=CurrentStartPage+1
wend
ifMyPage_PageAbsolute<(MyPage_PageTotal-10)then
response.write"<ahref='"&MyPage_Url&strAnd&"MyPage_PageNo="&(MyPage_PageAbsolute+10)&"'>"&nextPageTag&"</a>"
response.write"<ahref='"&MyPage_Url&strAnd&"MyPage_PageNo="&MyPage_PageTotal&"'>"&LastPageTag&"</a>"
else
response.writenextPageTag
response.writeLastPageTag
endif
response.write""
response.write"</td>"
response.write"</tr>"
response.write"</table>"
endfunction

publicfunctionGetPageNo()
GetPageNo=cint(MyPage_PageAbsolute)
endfunction

publicfunctionGetPageCount()
GetPageCount=cint(MyPage_PageTotal)
endfunction

publicfunctionGetPageNoName()
GetPageNoName="MyPage_PageNo"
endfunction

publicfunctionGetPageSize()
GetPageSize=MyPage_PageSize
endfunction

publicfunctionGetRecordTotal()
GetRecordTotal=MyPage_RecordTotal
endfunction



privatefunctionFormatMyPage_TotalStrSql(strSql)
FormatMyPage_TotalStrSql="selectcount(*)astotal"
FormatMyPage_TotalStrSql=FormatMyPage_TotalStrSql&Mid(strSql,instr(strSql,"from"))
FormatMyPage_TotalStrSql=Mid(FormatMyPage_TotalStrSql,1,instr(FormatMyPage_TotalStrSql&"orderby","orderby")-1)
endfunction

privatefunctionFormatMyPage_StrSql(strSql)
FormatMyPage_StrSql=replace(strSql,"select","selecttop"&(MyPage_PageAbsolute*Cint(MyPage_PageSize)))
endfunction

privatefunctionMyPage_PageAbsoluteRequest()
ifrequest("MyPage_PageNo")=""then
MyPage_PageAbsoluteRequest=1
else
ifIsNumeric(request("MyPage_PageNo"))then
MyPage_PageAbsoluteRequest=request("MyPage_PageNo")
else
MyPage_PageAbsoluteRequest=1
endif
endif
endfunction

privatefunctionReadMyPage_Url()
ReadMyPage_Url=Request.ServerVariables("URL")
ifRequest.QueryString<>""then
ReadMyPage_Url=ReadMyPage_Url&"?"&Request.QueryString
endif
setre=newRegExp
re.Pattern="[&|?]MyPage_PageNo=\d+?"
re.IgnoreCase=true
re.multiLine=true
re.global=true
SetMatches=re.Execute(ReadMyPage_Url)
ForEachMatchinMatches
tmpMatch=Match.Value
ReadMyPage_Url=replace(ReadMyPage_Url,tmpMatch,"")
next
endfunction
endClass

%>


声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章