欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp分页的一个类

程序员文章站 2023-11-29 18:20:16
asp分页的一个类  在50,000条记录下测试过,速度比ado的那个要快多了  <% '****************************...
asp分页的一个类 
在50,000条记录下测试过,速度比ado的那个要快多了 

<%

'************************************************************************************
'具体用法
dim strdbpath
dim connstr
dim mp
set mp = new mypage
strdbpath = "fenye/db.mdb"
connstr  = "provider=microsoft.jet.oledb.4.0;data source="
connstr  = connstr & server.mappath(strdbpath)
set conn  = server.createobject("adodb.connection")
conn.open connstr
set rs = mp.execute("select * from table1",conn,29)
while not rs.eof
    response.write rs("aaaa")&"<br>"
    rs.movenext
wend
mp.pagedispaly()
'************************************************************************************
class mypage
    private mypage_conn,mypage_strsql,mypage_totalstrsql,mypage_rs,mypage_totalrs
    private mypage_pagesize
    private mypage_pageabsolute,mypage_pagetotal,mypage_recordtotal
    private mypage_url
    public property let conn(strconn)
    set mypage_conn = strconn
    end property

    public property let pagesize(intpagesize)
        mypage_pagesize = cint(intpagesize)
    end property

    public function pageexecute(strsql)
        mypage_pageabsolute = mypage_pageabsoluterequest()
        mypage_totalstrsql = formatmypage_totalstrsql(strsql) 
        set mypage_totalrs = mypage_conn.execute(mypage_totalstrsql)
        mypage_recordtotal = mypage_totalrs("total")
        mypage_pagetotal = cint(mypage_recordtotal/mypage_pagesize)
        mypage_strsql = formatmypage_strsql(strsql)
        set mypage_rs = mypage_conn.execute(mypage_strsql)
        dim i
        i = 0 
        while not mypage_rs.eof and  i<(mypage_pageabsolute-1)*mypage_pagesize
            i = i + 1
            mypage_rs.movenext
        wend
        set pageexecute = mypage_rs 
    end function

    public function execute(strsql,strconn,intpagesize)
        conn = strconn
        pagesize = intpagesize
        set execute = pageexecute(strsql)
    end function

    public function pagedispaly()
        mypage_url = readmypage_url
        firstpagetag = "<font face=webdings>9</font>"  '|<<
        lastpagetag = "<font face=webdings>:</font>"  '>>|
        previewpagetag = "<font face=webdings>7</font>"  '<<
        nextpagetag = "<font face=webdings>8</font>"  '>>
        dim strand
        if instr(mypage_url,"?")=0 then
            strand = "?"
        else
            strand = "&"
        end if
        response.write "<table width=100%  border=0 cellspacing=0 cellpadding=0>"
        response.write "<tr>"
        response.write "<td align=left>"
        response.write  "页次:"&mypage_pageabsolute&"/"&mypage_pagetotal&"页&nbsp"
        response.write  "主题数:"&mypage_recordtotal
        response.write "</td>"
        response.write "<td align=right>"
        response.write  "分页:"
        if mypage_pageabsolute>10 then
            response.write  "<a href='"&mypage_url&strand&"mypage_pageno=1'>"&firstpagetag&"</a>"
            response.write  "<a href='"&mypage_url&strand&"mypage_pageno="&(mypage_pageabsolute-10)&"'>"&previewpagetag&"</a>"
        else
            response.write  firstpagetag
            response.write  previewpagetag
        end if
        response.write "&nbsp"
        dim currentstartpage,i
        i = 1
        currentstartpage=(cint(mypage_pageabsolute)\10)*10+1
        if cint(mypage_pageabsolute) mod 10=0 then
            currentstartpage = currentstartpage - 10
        end if
        while i<11 and currentstartpage<mypage_pagetotal+1
            if currentstartpage < 10 then
                formatcurrentstartpage = "0" & currentstartpage
            else
                formatcurrentstartpage = currentstartpage
            end if
            response.write  "<a href='"&mypage_url&strand&"mypage_pageno="&currentstartpage&"'>"&formatcurrentstartpage&"</a>&nbsp"
            i = i + 1
            currentstartpage = currentstartpage + 1
        wend
        if mypage_pageabsolute<(mypage_pagetotal-10) then
            response.write  "<a href='"&mypage_url&strand&"mypage_pageno="&(mypage_pageabsolute+10)&"'>"&nextpagetag&"</a>"
            response.write  "<a href='"&mypage_url&strand&"mypage_pageno="&mypage_pagetotal&"'>"&lastpagetag&"</a>"
        else
            response.write  nextpagetag
            response.write  lastpagetag
        end if
        response.write  ""
        response.write "</td>"
        response.write "</tr>" 
        response.write "</table>"
    end function

    public function getpageno()
        getpageno = cint(mypage_pageabsolute)
    end function

    public function getpagecount()
        getpagecount = cint(mypage_pagetotal)
    end function

    public function getpagenoname()
        getpagenoname = "mypage_pageno"
    end function

    public function getpagesize()
        getpagesize = mypage_pagesize
    end function

    public function getrecordtotal()
        getrecordtotal = mypage_recordtotal
    end function

    

    private function formatmypage_totalstrsql(strsql)
        formatmypage_totalstrsql = "select count(*) as total "
        formatmypage_totalstrsql = formatmypage_totalstrsql & mid(strsql,instr(strsql,"from"))
        formatmypage_totalstrsql = mid(formatmypage_totalstrsql,1,instr(formatmypage_totalstrsql&"order by","order by")-1)
    end function

    private function formatmypage_strsql(strsql)
        formatmypage_strsql = replace(strsql,"select","select top "&(mypage_pageabsolute*cint(mypage_pagesize)))
    end function

    private function mypage_pageabsoluterequest()
        if request("mypage_pageno")="" then 
            mypage_pageabsoluterequest = 1
        else
            if isnumeric(request("mypage_pageno")) then
                mypage_pageabsoluterequest = request("mypage_pageno")
            else
                mypage_pageabsoluterequest = 1
            end if
        end if
    end function

    private function readmypage_url()
        readmypage_url = request.servervariables("url")
        if request.querystring<>"" then
            readmypage_url = readmypage_url & "?" & request.querystring 
        end if
        set re = new regexp
        re.pattern = "[&|?]mypage_pageno=\d+?"
        re.ignorecase = true
        re.multiline = true
        re.global = true
        set matches = re.execute(readmypage_url) 
        for each match in matches  
            tmpmatch = match.value
            readmypage_url = replace(readmypage_url,tmpmatch,"")
        next
    end function
end class

%>