佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > asp的通用數(shù)據(jù)分頁(yè)類(lèi)

asp的通用數(shù)據(jù)分頁(yè)類(lèi)

熱門(mén)標(biāo)簽:科大訊飛語(yǔ)音識(shí)別系統(tǒng) 團(tuán)購(gòu)網(wǎng)站 銀行業(yè)務(wù) 服務(wù)器配置 阿里云 Mysql連接數(shù)設(shè)置 Linux服務(wù)器 電子圍欄
 (原創(chuàng))!--#include file="Conn.asp" -->
通用數(shù)據(jù)分頁(yè)類(lèi)
    通用分頁(yè)類(lèi),以后寫(xiě)分頁(yè)顯示數(shù)據(jù)時(shí)就輕松多啦.直接調(diào)用此類(lèi),然后再Execute即可以取得當(dāng)前頁(yè)的所有數(shù)據(jù).
    此類(lèi)所做的工作是只取得當(dāng)前頁(yè)的數(shù)據(jù),和總頁(yè)數(shù)和總記錄數(shù)等等數(shù)據(jù).

ASP代碼:
%
'/*****************************分頁(yè)顯示類(lèi)**************************
'/* 作者:哇哇魚(yú)
'/* 日期:2004年11月18日
'/* 作用:取得某一頁(yè)的數(shù)據(jù)并返回給外部
'/* 說(shuō)明示例:
'/* Dim MyPage=New PageClass
'/* MyPage.Conn=Conn                '設(shè)置連接對(duì)象
'/* MyPage.PageSize=20                 '設(shè)置一頁(yè)顯示多少條數(shù)據(jù) (默認(rèn)為10條)
'/* MyPage.CurPage=2                   '設(shè)置當(dāng)前要顯示的頁(yè)碼
'/*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'/* MyPage.TableName="Member"       '設(shè)置表名
'/* MyPage.Fields="ID,MemberName,MemberPass"   '設(shè)置顯示字段列表
'/* MyPage.Condition="ID>100"          '設(shè)置查詢(xún)條件
'/* MyPage.OrderBy="ID DESC"           '設(shè)置排序條件(一定要設(shè)置該屬性)
'/* Set PageRs=MyPage.Execute          '返回當(dāng)前第2頁(yè)的數(shù)據(jù)(RecordSet對(duì)象),如果出錯(cuò)則返回Nothing值
'/*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'/*'以上的定義也可以用以下的方法:ExecuteBy("表名","字段列表","查詢(xún)條件","排序條件")
'/* Set PageRs=MyPage.ExecuteBy("Member","ID,MemberName,MemberPass","ID>100","ID DESC")
'/*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'/* PageCount=MyPage.PageCount         '返回頁(yè)碼總數(shù)
'/* RecordCount=MyPage.RecordCount     '返回記錄總數(shù)
'/* NextPage=MyPage.NextPage           '返回下頁(yè)的頁(yè)碼
'/* PrePage=MyPage.PrePage             '返回上一頁(yè)的頁(yè)碼
'/*****************************************************************
Class PageClass
    Private Connection               '連接數(shù)據(jù)庫(kù)的外部Connection對(duì)象
    Private Rs
    Private List_Fields
    Private Table_Name
    Private Query_Where
    Private OrderBy_SQL              '字段排序語(yǔ)句部分
    Private Page_Count               '返回當(dāng)前查詢(xún)的記錄頁(yè)總數(shù)
    Private Page_Size                '設(shè)置一頁(yè)顯示多少條的記錄
    Private Cur_Page                 '設(shè)置當(dāng)前的頁(yè)碼
    Private Record_Count             '返回當(dāng)前查詢(xún)的記錄總數(shù)

    '/****************設(shè)置Connection對(duì)象****************************
    Public Property Let Conn(ByRef ObjConn)
        Set Connection=ObjConn
    End Property
    Public Property Get Conn()
        Set Conn=Connection
    End Property
    '/****************End******************************************

    '/****************設(shè)置查詢(xún)SQL語(yǔ)句*******************************
    ''查詢(xún)顯示字段
    Public Property Let Fields(ByVal Value)
        List_Fields=Value
    End Property
    Public Property Get Fields()
        Fields=List_Fields
    End Property
    ''查詢(xún)表名
    Public Property Let TableName(ByVal Value)
        Table_Name=Value
    End Property
    Public Property Get TableName()
        TableName=Table_Name
    End Property
    ''查詢(xún)條件
    Public Property Let Condition(ByVal Value)
        Query_Where=Value
    End Property
    Public Property Get Condition()
        Condition=Query_Where
    End Property
    ''*****************排序部分********************************************
    ''Value 語(yǔ)不用寫(xiě)上Order By 。如: [object].OrderBy="ID Desc,PostTime Asc"
    Public Property Let OrderBy(ByVal Value)
        OrderBy_SQL=Value
    End Property
    Public Property Get OrderBy()
        OrderBy=OrderBy_SQL
    End Property
    '/****************End******************************************

    '/****************返回當(dāng)前查詢(xún)結(jié)果的總頁(yè)數(shù)***********************
    Public Property Get PageCount()
        PageCount=Page_Count
    End Property
    Public Property Get RecordCount()
        RecordCount=Record_Count
    End Property
    Public Property Get NextPage()
        If Cur_PagePage_Count Then
            NextPage=Cur_Page+1
        Else
            NextPage=Page_Count
        End If
    End Property
    Public Property Get PrePage()
        If Cur_Page>1 Then
            PrePage=Cur_Page-1
        Else
            PrePage=Cur_Page
        End If
    End Property
    '/****************End******************************************

    '/****************設(shè)置一頁(yè)顯示的記錄數(shù)***************************
    Public Property Let PageSize(ByVal Value)
        If Not IsNumeric(Value) Or Value="" Then
            Value=10
        Else
            Value=Cint(Value)
        End If
        If Value1 Then Value=10
        Page_Size=Value
    End Property
    Public Property Get PageSize()
        PageSize=Page_Size
    End Property
    ''設(shè)置當(dāng)前的頁(yè)碼數(shù)**************************
    Public Property Let Page(ByVal Value)
        If Not IsNumeric(Value) Or Value="" Then
            Value=1
        Else
            Value=CLng(Value)
        End If
        If Value1 Then Value=1
        Cur_Page=Value
    End Property
    Public Property Get Page()
        Page=Cur_Page
    End Property
    '/****************End******************************************

    Private Sub Class_Initialize
    '初始化RecordSet對(duì)象
        Page_Size=10            '默認(rèn)一頁(yè)為10條數(shù)據(jù)
        CurPage=1                   '默認(rèn)當(dāng)前為第一頁(yè)
        Record_Count=0
        Page_Count=0
    End Sub

    Private Sub Class_Terminate
        Call CloseRecordSet
    End Sub

    '/***關(guān)閉數(shù)據(jù)庫(kù)的連接*******
    Private Sub CloseRecordSet
        On Error Resume Next
        If IsObject(Rs) Then
            Rs.Close
            Set Rs=Nothing
        End If
        On Error Goto 0
    End Sub

    '/**********執(zhí)行查詢(xún)返回對(duì)應(yīng)頁(yè)碼的數(shù)據(jù)***********************************************
    Public Function ExecuteBy(ByVal oTableName,ByVal oFields,ByVal oCondition,ByVal oOrderBy)
        Table_Name=oTableName
        List_Fields=oFields
        Query_Where=oCondtion
        OrderBy_SQL=oOrderBy
        Set ExecuteBy=Execute()
    End Function
    '查詢(xún)并返回當(dāng)前CurPage的頁(yè)碼記錄
    Public Function Execute()
        Call CloseRecordSet
        On Error Resume Next
        Dim TSQL,TopMod,sWhere
        If Not IsObject(Connection) Or Table_Name="" Or OrderBy_SQL="" Then
            Set Execute=Nothing
            Record_Count=0
            Page_Count=0
            Exit Function
        End If
        If Trim(Query_Where)>"" Then 
            sWhere="Where "Query_Where
        Else
            sWhere=""
        End If
        TSQL="Select Count(*) From ["Table_Name"] "sWhere
        Record_Count=Connection.Execute(TSQL)(0)    '獲取記錄總數(shù)
        If Err Then
            Err.Clear
            Set Execute=Nothing
            Record_Count=0
            Page_Count=0
            Exit Function
        End If
        If Record_Count1 Then
            Set Execute=Nothing
            Record_Count=0
            Page_Count=0
            Exit Function
        End If
        '取得頁(yè)的總數(shù)
        If Record_Count Mod Page_Size >0 Then
            TopMod=Record_Count Mod Page_Size
            Page_Count=Fix(Record_Count/Page_Size)+1
            If Cur_PagePage_Count Then
                TopMod=Page_Size
            End If
        Else
            TopMod=Page_Size
            Page_Count=Fix(Record_Count/Page_Size)
        End If
        If Cur_Page>Page_Count Then Cur_Page=Page_Count
        If Cur_Page1 Then Cur_Page=1
        If Trim(List_Fields)="" Then List_Fields="*"
        TSQL="Select * From (Select Top "TopMod" * From (Select Top "(Cur_Page*Page_Size)" "List_Fields" From ["Table_Name"] "sWhere" Order By "OrderBy_SQL") Order By "TransformOrder(OrderBy_SQL)")Order By "OrderBy_SQL
        Set Rs=Connection.Execute(TSQL)
        If Err Then
            Err.Clear
            Set Execute=Nothing
            Record_Count=0
            Page_Count=0
            Exit Function
        End If
        Set Execute=Rs
    End Function

    '轉(zhuǎn)換OrderBy的順序 ASC->DESC   DESC->ASC
    Private Function TransformOrder(ByVal Value)
        If Value="" Then
            TransformOrder=""
            Exit Function
        End If
        Dim OrderArray,i,Result,ByString,Fields,InPos
        OrderArray=Split(Value,",")   '分解每個(gè)字段值
        For i=0 To Ubound(OrderArray)
            If OrderArray(i)>"" Then
                InPos=InStrRev(Trim(OrderArray(i))," ")  '找出排序的順序
                If InPos1 Then  '如果找不到則是ASC排序
                    ByString="ASC"
                    Fields=OrderArray(i)+" "
                Else
                    ByString=Trim(Mid(OrderArray(i),InPos+1))
                    Fields=Left(OrderArray(i),InPos)
                    If ByString>"" Then
                        ByString=UCase(ByString)
                    Else
                        ByString="ASC"
                    End If
                End If
                ''轉(zhuǎn)換排序
                If ByString="ASC" Then
                    ByString="DESC"
                Else
                    ByString="ASC"
                End If
                Result=Result+Fields+ByString+","
            End If
        Next
        If Result>"" Then Result=Left(Result,Len(Result)-1)
        TransformOrder=Result
    End Function
End Class


'示例代碼:
Sub Show_List
    Dim Page,PageRs
    Page=Request("Page")
    Dim MyPage
    Set MyPage=New PageClass
    MyPage.Conn=Conn
    MyPage.PageSize=20
    MyPage.Page=Page
    MyPage.TableName="table1"
    MyPage.Fields="*"
    MyPage.OrderBy="ID Asc"
    Set PageRs=MyPage.Execute
    'Set PageRs=MyPage.ExecuteBy("table1","*","","ID Asc")
    If PageRs Is Nothing Then Exit Sub
    Do Until PageRs.Eof
        Response.Write " tr bgcolor=""#FDFDFD"" style=""cursor:hand"" onmouseover=""this.style.background='#F3F3F3'"" onmouseout=""this.style.background='#FDFDFD'"">"
        Response.Write "    td height=""20"">div align=""center"">"PageRs("ID")"/div>/td>"
        Response.Write "    td>"PageRs("aaaa")"/td>"
        Response.Write "    td>a href="""PageRs("bbbb")""">font color='#000000'>"PageRs("bbbb")"/font>/a>/td>"
        Response.Write "    td>"PageRs("cccc")"/td>"
        Response.Write "  /tr>"
        PageRs.MoveNext
    Loop
    PageRs.Close
    PageCount=MyPage.PageCount
    Page=MyPage.Page            '取得當(dāng)前正確的頁(yè)碼數(shù)
    NextPage=MyPage.NextPage
    PrePage=MyPage.PrePage
    Set PageRs=Nothing
    Set MyPage=Nothing
End Sub
Show_List
%> 




標(biāo)簽:大理 萍鄉(xiāng) 江蘇 廣元 棗莊 衡水 蚌埠 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp的通用數(shù)據(jù)分頁(yè)類(lèi)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266
    黄冈市| 丰城市| 建瓯市| 赤水市| 马边| 彭水| 贞丰县| 上虞市| 怀远县| 六盘水市| 青田县| 富蕴县| 县级市| 棋牌| 长汀县| 阿合奇县| 双江| 克山县| 蒙城县| 江津市| 上蔡县| 循化| 水富县| 德阳市| 乌鲁木齐市| 沅陵县| 潮州市| 黄冈市| 永丰县| 阜宁县| 安达市| 库车县| 萨迦县| 长沙市| 闸北区| 五峰| 临颍县| 张家口市| 平顶山市| 沾益县| 门头沟区|