ページングコンポーネントASP+VBScript
5927 ワード
<script
language="vbscript"
runat="server">
class pagerecordset
private o_rs
private o_cmd
private o_bpos
private o_epos
public pagerecordcount
public totalrecord
public firstpage
public prevpage
public pageindex
public totalpage
public nextpage
public lastpage
private sub class_initialize
totalpage = 1
pagerecordcount = 10
pageindex = 1
totalrecord = 0
firstpage = 1
prevpage = 1
nextpage = 1
lastpage = 1
end sub
private sub class_terminate
set o_rs = nothing
set o_cmd = nothing
end sub
private function errmsg(funcbody , errdescription)
dim msg
msg = ""
msg = msg & "<div style='padding:5px; background:#ffd700; color:#000; font-family:Verdana; font-size:11px;'>"
msg = msg & " <div>Fundation:<strong>" & funcbody & "</strong></div>"
msg = msg & " <div>Description:" & errdescription & "</div>"
msg = msg & "</div>"
errmsg = msg
end function
private function op3(condition , iftrue , iffalse)
dim o_return
o_return = null
if condition = true then
o_return = iftrue
else
o_return = iffalse
end if
op3 = o_return
end function
public function fetch(sql , constring)
on error resume next
set o_cmd = server.createobject("adodb.command")
o_cmd.activeconnection = constring
o_cmd.activeconnection.cursorlocation = 3
o_cmd.commandtext = sql
o_cmd.prepared = true
set o_rs = o_cmd.execute()
if o_rs.recordcount = 0 then
else
pagefloat = o_rs.recordcount / pagerecordcount
pageint = int(pagefloat)
totalpage = op3(pagefloat > pageint , pageint + 1 , pageint)
totalrecord = o_rs.recordcount
firstpage = 1
lastpage = totalpage
prevpage = pageindex - 1
nextpage = pageindex + 1
if prevpage < 1 then prevpAge = lastpage end if
if nextpage > lastpage then nextpage = firstpage end if
o_bpos = (pageindex - 1) * pagerecordcount + 1
o_epos = o_bpos + pagerecordcount
if o_epos > totalrecord then o_epos = totalrecord - o_bpos + o_bpos + 1 end if
o_rs.absoluteposition = o_bpos
end if
if err.number <> 0 then
response.Write(errmsg("pagerecordset.fetch()" , err.description))
response.End()
else
end if
err.clear()
end function
public function read()
on error resume next
dim o_return
o_return = false
if o_bpos >= o_epos then
else
o_rs.absoluteposition = o_bpos
o_bpos = o_bpos + 1
o_return = true
end if
read = o_return
if err.number <> 0 then
response.write(errmsg("pagerecordset.read()" , err.description))
response.end()
else
end if
err.clear()
end function
public function getfield(fieldname)
on error resume next
if o_rs.recordcount = 0 then
getfield = null
else
getfield = o_rs(fieldname)
end if
if err.number <> 0 then
response.write(errmsg("pagerecordset.getfield(fieldname)" , err.description))
response.end()
else
end if
err.clear()
end function
public function getposition()
on error resume next
if o_rs.recordcount = 0 then
getposition = 0
else
getposition = o_rs.absoluteposition
end if
if err.number <> 0 then
response.write(errmsg("pagerecordset.getposition()" , err.description))
response.end()
else
end if
err.clear()
end function
public function shownavigation(pagequery , otherquery)
on error resume next
if totalrecord > 0 then
dim html
html = ""
html = html & "<div style='text-align:center; padding:5px;'>"
html = html & " <div>"
html = html & " " & pageindex & "/" & totalpage & " , " & pagerecordcount & " , " & totalrecord & " 。"
html = html & " <a href='?" & pagequery & "=" & firstpage & otherquery & "' style='font-family:webdings; font-size:12px;' target='_self'>9</a>"
html = html & " <a href='?" & pagequery & "=" & prevpage & otherquery & "' style='font-family:webdings; font-size:12px;' target='_self'>7</a>"
html = html & " " & pageindex
html = html & " /"
html = html & " " & totalpage
html = html & " <a href='?" & pagequery & "=" & nextpage & otherquery & "' style='font-family:webdings; font-size:12px;' target='_self'>8</a>"
html = html & " <a href='?" & pagequery & "=" & lastpage & otherquery & "' style='font-family:webdings; font-size:12px;' target='_self'>:</a>"
html = html & " </div>"
html = html & "</div>"
response.write(html)
end if
if err.number <> 0 then
response.write(errmsg("pagerecordset.shownavigation(pagequery, otherquery)" , err.description))
response.end()
else
end if
err.clear()
end function
public function release()
on error resume next
o_rs.close()
set o_rs = nothing
totalpage = 1
pagerecordcount = 10
pageindex = 1
totalrecord = 0
firstpage = 1
prevpage = 1
nextpage = 1
lastpage = 1
if err.number <> 0 then
response.write(errmsg("pagerecordset.release()" , err.description))
response.end()
else
end if
err.clear()
end function
end class
</script>