分页组件 ASP+VBScript

<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>

转载于:https://www.cnblogs.com/shinewaycn/archive/2005/06/19/177285.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值