面向对象的asp编程之七--分页对象(vbscript版)
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
' ************************************************************************
' Script Compont Object Model
' Design for Active Server Pages
'
' Copyright 2004 Version 2.0
' Made by 尹曙光
' ************************************************************************
function CreateCPageNavbar()
set CreateCPageNavbar=new CPageNavbar
end function
Class CPageNavbar
Public SplitSize '分页显示的容量
public PnWidth
public PnAlign
public PlWidth '表格宽度
public PlAlign ' 表格的对齐方式
private PageSize
private RecordCount '总记录数]
private PageCount '总页数
private CurrentPage '当前的页码
private SplitCount '分页的显示的总页数
private CurrentSplit '当前的分页的分页码
'===============================================================
Private Sub Class_Initialize ' Setup Initialize event.
SplitSize=10
PnWidth="100%"
PnAlign="right"
PlWidth="100%" //表格宽度
PlAlign="right" // 表格的对齐方式
PageSize=0
RecordCount=0
CurrentPage=1
PageCount=1
SplitCount=1
CurrentSplit=1
End Sub
Private Sub Class_Terminate ' Setup Terminate event.
End Sub
public sub InitPageNavbar(byval iPageSize,byval iRecordCount)
PageSize=cint(iPageSize)
RecordCount=clng(iRecordCount)
PageCount=fix(RecordCount/PageSize)+1
SplitCount=fix(PageCount/SplitSize)+1
end sub
public function GetCurrentPage()
'on error resume next
dim pageNo
pageNo =trim(Request.QueryString ("_Page_No_"))
'如果没有选择第几页,则默认显示第一页;
if ( (not IsNumeric(pageNo)) or pageNo="") then
pageNo =1
end if
CurrentPage=clng(pageNo)
if (CurrentPage<1) then
CurrentPage=1
end if
if (CurrentPage>PageCount) then
CurrentPage=PageCount
end if
CurrentSplit=fix(CurrentPage/SplitSize)+1
GetCurrentPage=CurrentPage
end function
public function plDisplay()
dim strBuilder,p,itmp
strBuilder=""
'首组为第0族
strBuilder=strBuilder+"<table border='0' cellpadding='0' cellspacing='0' "
strBuilder=strBuilder+" width='"&PlWidth&"' align='"&PlAlign&"'>"
strBuilder=strBuilder+" <tr> "
strBuilder=strBuilder+" <td valign='middle' align='right'>分页:"
if (CurrentSplit=1) then
strBuilder=strBuilder+"<font face='webdings' color='#ff0000'>9</font> "
strBuilder=strBuilder+"<font face='webdings' color='#ff0000'>7</font>"
else
strBuilder=strBuilder+"<a href='?_Page_No_=1' title='首页'><font face='webdings'>9</font></a> "
strBuilder=strBuilder+"<a href='?_Page_No_="&cstr((CurrentSplit-2)*SplitSize)&"' title='上"&cstr(SplitSize)&"页'><font face='webdings'>7</font></a> "
end if
strBuilder=strBuilder+"<b>"
'分页列表
itmp=(CurrentSplit-1)*SplitSize+1
for i=itmp to (itmp+SplitSize-1)
if (i=CurrentPage) then
strBuilder=strBuilder+"<font color='#000000'>"&cstr(i)&"</font> "
else
strBuilder=strBuilder+"<a href=?_Page_No_="&cstr(i)&" title='转到: 第"&cstr(i)&"页'>"&cstr(i)&"</a> "
end if
if (i>=PageCount) then
exit for
end if
next
strBuilder=strBuilder+"</b>"
'显示下十页
if (CurrentSplit<SplitCount) then
strBuilder=strBuilder+"<a href='?_Page_No_="&cstr((CurrentSplit)*SplitSize)&"' title='下十页'><font face='webdings'>8</font></a> "
strBuilder=strBuilder+"<a href=?_Page_No_="&cstr(PageCount)&" title='尾页'><font face='webdings'>:</font></a> "
else
strBuilder=strBuilder+"<font face='webdings' color='#ff0000'>8</font>"
strBuilder=strBuilder+"<font face='webdings' color='#ff0000'>:</font>"
end if
strBuilder=strBuilder+"</td></tr></table>"
Response.Write(strBuilder)
end function
public function pnDisplay()
dim strBuilder,nextPageNo
strBuilder=""
strBuilder=strBuilder+"<table border='0' cellpadding='0' cellspacing='0' "
strBuilder=strBuilder+" width='"&PnWidth&"' align='"&PnAlign&"'>"
strBuilder=strBuilder+"<tr>"
strBuilder=strBuilder+"<td valign='middle'>页次:[<b>"&cstr(CurrentPage)&"</b>/<b>"&cstr(PageCount)&"</b>]页 每页[<b>"&cstr(PageSize)&"</b>]条 总记录数:[<b>"&cstr(RecordCount)&"</b>]条</td>"
strBuilder=strBuilder+"<td align='right'>"
if (cint(CurrentPage)>1) then
nextPageNo=cint(CurrentPage)-1
strBuilder=strBuilder+"[<a href=?_Page_No_="&cstr(nextPageNo)&" title='转到上一页'>上一页</a>]"
end if
if (cint(CurrentPage)<cint(PageCount)) then
nextPageNo=cint(CurrentPage)+1
strBuilder=strBuilder+"[<a href=?_Page_No_="&cstr(nextPageNo)&" title='转到下一页'>下一页</a>]"
end if
strBuilder=strBuilder+"</td></tr></table>"
Response.Write(strBuilder)
end function
End Class
</SCRIPT>
' ************************************************************************
' Script Compont Object Model
' Design for Active Server Pages
'
' Copyright 2004 Version 2.0
' Made by 尹曙光
' ************************************************************************
function CreateCPageNavbar()
set CreateCPageNavbar=new CPageNavbar
end function
Class CPageNavbar
Public SplitSize '分页显示的容量
public PnWidth
public PnAlign
public PlWidth '表格宽度
public PlAlign ' 表格的对齐方式
private PageSize
private RecordCount '总记录数]
private PageCount '总页数
private CurrentPage '当前的页码
private SplitCount '分页的显示的总页数
private CurrentSplit '当前的分页的分页码
'===============================================================
Private Sub Class_Initialize ' Setup Initialize event.
SplitSize=10
PnWidth="100%"
PnAlign="right"
PlWidth="100%" //表格宽度
PlAlign="right" // 表格的对齐方式
PageSize=0
RecordCount=0
CurrentPage=1
PageCount=1
SplitCount=1
CurrentSplit=1
End Sub
Private Sub Class_Terminate ' Setup Terminate event.
End Sub
public sub InitPageNavbar(byval iPageSize,byval iRecordCount)
PageSize=cint(iPageSize)
RecordCount=clng(iRecordCount)
PageCount=fix(RecordCount/PageSize)+1
SplitCount=fix(PageCount/SplitSize)+1
end sub
public function GetCurrentPage()
'on error resume next
dim pageNo
pageNo =trim(Request.QueryString ("_Page_No_"))
'如果没有选择第几页,则默认显示第一页;
if ( (not IsNumeric(pageNo)) or pageNo="") then
pageNo =1
end if
CurrentPage=clng(pageNo)
if (CurrentPage<1) then
CurrentPage=1
end if
if (CurrentPage>PageCount) then
CurrentPage=PageCount
end if
CurrentSplit=fix(CurrentPage/SplitSize)+1
GetCurrentPage=CurrentPage
end function
public function plDisplay()
dim strBuilder,p,itmp
strBuilder=""
'首组为第0族
strBuilder=strBuilder+"<table border='0' cellpadding='0' cellspacing='0' "
strBuilder=strBuilder+" width='"&PlWidth&"' align='"&PlAlign&"'>"
strBuilder=strBuilder+" <tr> "
strBuilder=strBuilder+" <td valign='middle' align='right'>分页:"
if (CurrentSplit=1) then
strBuilder=strBuilder+"<font face='webdings' color='#ff0000'>9</font> "
strBuilder=strBuilder+"<font face='webdings' color='#ff0000'>7</font>"
else
strBuilder=strBuilder+"<a href='?_Page_No_=1' title='首页'><font face='webdings'>9</font></a> "
strBuilder=strBuilder+"<a href='?_Page_No_="&cstr((CurrentSplit-2)*SplitSize)&"' title='上"&cstr(SplitSize)&"页'><font face='webdings'>7</font></a> "
end if
strBuilder=strBuilder+"<b>"
'分页列表
itmp=(CurrentSplit-1)*SplitSize+1
for i=itmp to (itmp+SplitSize-1)
if (i=CurrentPage) then
strBuilder=strBuilder+"<font color='#000000'>"&cstr(i)&"</font> "
else
strBuilder=strBuilder+"<a href=?_Page_No_="&cstr(i)&" title='转到: 第"&cstr(i)&"页'>"&cstr(i)&"</a> "
end if
if (i>=PageCount) then
exit for
end if
next
strBuilder=strBuilder+"</b>"
'显示下十页
if (CurrentSplit<SplitCount) then
strBuilder=strBuilder+"<a href='?_Page_No_="&cstr((CurrentSplit)*SplitSize)&"' title='下十页'><font face='webdings'>8</font></a> "
strBuilder=strBuilder+"<a href=?_Page_No_="&cstr(PageCount)&" title='尾页'><font face='webdings'>:</font></a> "
else
strBuilder=strBuilder+"<font face='webdings' color='#ff0000'>8</font>"
strBuilder=strBuilder+"<font face='webdings' color='#ff0000'>:</font>"
end if
strBuilder=strBuilder+"</td></tr></table>"
Response.Write(strBuilder)
end function
public function pnDisplay()
dim strBuilder,nextPageNo
strBuilder=""
strBuilder=strBuilder+"<table border='0' cellpadding='0' cellspacing='0' "
strBuilder=strBuilder+" width='"&PnWidth&"' align='"&PnAlign&"'>"
strBuilder=strBuilder+"<tr>"
strBuilder=strBuilder+"<td valign='middle'>页次:[<b>"&cstr(CurrentPage)&"</b>/<b>"&cstr(PageCount)&"</b>]页 每页[<b>"&cstr(PageSize)&"</b>]条 总记录数:[<b>"&cstr(RecordCount)&"</b>]条</td>"
strBuilder=strBuilder+"<td align='right'>"
if (cint(CurrentPage)>1) then
nextPageNo=cint(CurrentPage)-1
strBuilder=strBuilder+"[<a href=?_Page_No_="&cstr(nextPageNo)&" title='转到上一页'>上一页</a>]"
end if
if (cint(CurrentPage)<cint(PageCount)) then
nextPageNo=cint(CurrentPage)+1
strBuilder=strBuilder+"[<a href=?_Page_No_="&cstr(nextPageNo)&" title='转到下一页'>下一页</a>]"
end if
strBuilder=strBuilder+"</td></tr></table>"
Response.Write(strBuilder)
end function
End Class
</SCRIPT>