[导入][分页类]Jorkin 自定义类 翻页优化代码

可以与网上流行的 《24款超实用的Web 2.0风格翻页页码css代码》 完美无缝连接。你所做的,就是改个div的名字而已。

<%
'//-----------------------------------------------------------------------------
'// Jorkin 自定义类 翻页优化代码
'// 来源: KinJAVA日志 (http://jorkin.reallydo.com/)
'// 最后更新: 2008-07-12
'//-----------------------------------------------------------------------------
'// 改自COCOON Db_Pager 类 (Ver: 1.05)
'// 感谢以下大大的分页类思想及代码:
'// Sunrise_Chen (http://www.ccopus.com/)
'// 才子 (http://www.54caizi.com/)
'// 叶子 (http://www.ye.vg/)
'//-----------------------------------------------------------------------------
'// 可先用 Eg() 查看本类的使用方法
'//-----------------------------------------------------------------------------

Class Kin_db_Pager

    '//-------------------------------------------------------------------------
    '// 定义变量 开始

    
Private oConn '//连接对象
    
Private sDbType '//数据库类型
    
Private sTableName '//表名
    
Private sPKey '//主键
    
Private sFields '//输出的字段名
    
Private sOrderBy '//排序字符串
    
Private sSql '//当前的查询语句
    
Private sSqlString '//自定义Sql语句
    
Private aCondition() '//查询条件(数组)
    
Private sCondition '//查询条件(字符串)
    
Private iPage '//当前页码
    
Private iPageSize '//每页记录数
    
Private iPageCount '//总页数
    
Private iRecordCount '//当前查询条件下的记录数
    
Private iTotalRecordCount '//总记录数
    
Private sPage '//当前页 替换字符串
    
Private sPageCount '//总页数 替换字符串
    
Private sRecordCount '//当前查询条件下的记录数 替换字符串
    
Private sProjectName '//项目名
    
Private sVersion '//版本号
    
Private bShowError '//是否显示错误信息
    
Private bDistionct '//是否显示唯一记录
    
Private sPageInfo '//记录数、页码等信息
    
Private bDistinct '//是否Distinct
    
Private sPageParam '//page参数名称
    
Private iStyle '//翻页的样式
    
Private iPagerSize '//翻页按钮的数值
    
Private sPagerStyle '//翻页按钮的数值
    
Private sPagerCSS '//翻页按钮的数值
    
Private sReWrite '//用ISAP REWRITE做的路径
    
Private iTableKind '//表的类型, 是不是需要加 [ ]
    
Private sFirstPage '//首页 样式
    
Private sPreviewPage '//上一页 样式
    
Private sCurrentPage '//当前页 样式
    
Private sListPage '//分页列表 样式
    
Private sNextPage '//下一页 样式
    
Private sLastPage '//末页 样式
    
Private iPagerTop '//分页列表头尾数量
    
Private sPagerClass '//分页列表头尾样式
    
Private sJumpPage '//分页跳转功能
    
Private sJumpPageType '//分页跳转类型
    
Private sJumpPageStyle '//分页跳转样式 需要自己写style=""和class=""
    
Private ss, iStart, iEnd, PgStart

    '//定义变量 结束
    '//-------------------------------------------------------------------------

    '//-------------------------------------------------------------------------
    '//事件、方法: 类初始化事件 开始

    
Private Sub Class_Initialize()
        
ReDim aCondition( -1)
        
sProjectName = "Jorkin 类系列 数据库翻页优化类"
        
sDbType = "MSSQL"
        
sVersion = "1.3 Build: 080712"
        
sPKey = "ID"
        
sFields = "*"
        
sCondition = ""
        
sOrderBy = ""
        
sSqlString = ""
        
iPageSize = 20
        
iPage = 1
        
iRecordCount = Null
        
iTotalRecordCount = Null
        
iPageCount = Null
        
bShowError = True
        
bDistionct = False
        
iPagerTop = 0
        
sPage = "{$Kin_Page}"
        
sPageCount = "{$Kin_PageCount}"
        
sRecordCount = "{$Kin_RecordCount}"
        
sPageInfo = "共有 {$Kin_RecordCount} 条记录 页次: {$Kin_Page}/{$Kin_PageCount}"
        
sPageParam = "page"
        
iStyle = -1
        
iTableKind = 0
        
iPagerSize = 7
        
sFirstPage = "[首页]"
        
sPreviewPage = "[上一页]"
        
sCurrentPage = "[{$CurrentPage}]"
        
sListPage = "[{$ListPage}]"
        
sNextPage = "[下一页]"
        
sLastPage = "[末页]"
        
sJumpPage = ""
        
sJumpPageType = "Select"
        
sPagerClass = ""
    
End Sub

    
'//类结束事件

    
Private Sub Class_Terminate()
        
Set oConn = Nothing
    End Sub

    
'//事件、方法: 类初始化事件 结束
    '//-------------------------------------------------------------------------

    '//-------------------------------------------------------------------------
    '//函数、方法 开始

    '功能:ASP里的IIF
    '用法:IIF(条件表达式,为真时返回值,为假时返回值)
    '来源:http://jorkin.reallydo.com/article.asp?id=26

    
Private Function IIf(bExp1, sVal1, sVal2)
        
If (bExp1) Then
            
IIf = sVal1
        Else
            
IIf = sVal2
        End If
    End Function

    
'功能:返回字符串,其中指定数目的某子字符串 全部 被替换为另一个子字符串。
    '来源:http://jorkin.reallydo.com/article.asp?id=406
    '需要Bint函数:http://jorkin.reallydo.com/article.asp?id=395

    
Private Function ReplaceAll(sExpression, sFind, sReplaceWith, bAll)
        
If IsNull(sExpression) Then
            
ReplaceAll = ""
            
Exit Function
        End If
        If
(StrComp(bAll, "True", 1) = 0) Or (CBool(Bint(bAll)) = True) Then
            Do While
InStr( 1, sExpression, sFind, 1) > 0
                
sExpression = Replace(sExpression, sFind, sReplaceWith, 1, -1, 1)
                
If InStr( 1, sReplaceWith , sFind , 1) >0 Then Exit Do
            Loop
        Else
            Do While
InStr(sExpression, sFind) > 0
                
sExpression = Replace(sExpression, sFind, sReplaceWith)
                
If InStr(sReplaceWith, sFind ) > 0 Then Exit Do
            Loop
        End If
        
ReplaceAll = sExpression
    End Function


    
'功能:只取数字
    '来源:http://jorkin.reallydo.com/article.asp?id=395

    
Private Function Bint(sValue)
        
On Error Resume Next
        
Bint = 0
        
Bint = Fix(sValue)
    
End Function


    
'功能:判断是否是空值
    '来源:http://jorkin.reallydo.com/article.asp?id=386

    
Private Function IsBlank(byref TempVar)
        
IsBlank = False
        Select Case
VarType(TempVar)
            
Case 0, 1 '--- Empty & Null
                
IsBlank = True
            Case
8 '--- String
                
If Len(TempVar) = 0 Then
                    
IsBlank = True
                End If
            Case
9 '--- Object
                
tmpType = TypeName(TempVar)
                
If (tmpType = "Nothing") Or (tmpType = "Empty") Then
                    
IsBlank = True
                End If
            Case
8192, 8204, 8209 '--- Array
                
If UBound(TempVar) = -1 Then
                    
IsBlank = True
                End If
        End Select
    End Function

    
'//处理错误信息

    
Public Sub doError(s)
        
On Error Resume Next
        Dim
objASPError
        Set objASPError = Server.GetLastError
        Dim nRnd
        Randomize()
        
nRnd = CLng(Rnd() * 2925)
        
Response.Clear
        Response.Expires = 0
        
Response.Write "<br />" & vbCrLf
        Response.Write "<div style=""width:100%; font-size:12px; cursor:pointer;"">" & vbCrLf
        Response.Write "  <label onClick=""ERRORDIV" & nRnd & ".style.display=(ERRORDIV" & nRnd & ".style.display=='none'?'':'none')"">"
        
Response.Write "  <span style=""background-color:820222; color:#FFFFFF;"">〖 Kin_db_Pager 提示信息 ERROR:" & nRnd & " 〗</span><br />" & vbCrLf
        Response.Write "  </label>" & vbCrLf
        Response.Write "  <div id=""ERRORDIV" & nRnd & """ style=""display:none;width:100%;border:1px solid #820222;padding:5px;overflow:hidden;"">" & vbCrLf
        Response.Write " <span style=""color:#FF0000;"">Description</span> " & s & "<br />" & vbCrLf
        Response.Write " <span style=""color:#FF0000;"">Provider</span> " & sProjectName & "<br />" & vbCrLf
        Response.Write " <span style=""color:#FF0000;"">Version</span> " & sVersion & "<br />" & vbCrLf
        Response.Write "  </div>" & vbCrLf
        Response.Write "</div>" & vbCrLf
        Response.Write "<br />" & vbCrLf
        Response.End()
    
End Sub

    
'//产生分页的SQL语句

    
Public Function getSql()
        
Dim iStart, iEnd
        Call makeCondition()
        
iStart = ( iPage - 1 ) * iPageSize
        iEnd = iStart + iPageSize
        Select Case sDbType
            Case "MSSQL", "SQL"
                
getSql = " Select " & IIf(bDistinct, "DISTINCT", "") & " " & sFields & " FROM " & TableFormat(sTableName) & " " _
                         & " Where ["&sPKey&"] IN ( " _
                         & "   Select TOP "&iEnd&" ["&sPKey&"] FROM " & TableFormat(sTableName) & " " & sCondition & " " & sOrderBy & " " _
                         & " )"
                
If iPage>1 Then
                    
getSql = getSql & " AND ["&sPKey&"] NOT IN ( " _
                             & "   Select TOP "&iStart&" ["&sPKey&"] FROM " & TableFormat(sTableName) & " " & sCondition & " " & sOrderBy & " " _
                             & " )"
                
End If
                
getSql = getSql & " " & sOrderBy & " "
            
Case "MYSQL" '//这个不会...抄袭叶子分页类.
                
getSql = "Select " & sFields & " FROM " & TableFormat(sTableName)& " " & sCondition & " " & sOrderBy & " LIMIT "&(iPage -1) * iPageSize&"," & iPageSize
            Case "MSSQLPRODUCE", "MSSQLPR", "MSSQL_PR" '//可能不用拼接SQL语句, 先放着

            
Case "ACCESS"
                
getSql = " Select " & IIf(bDistinct, "DISTINCT", "") & " " & sFields & " FROM " & TableFormat(sTableName) & " " & sCondition & " " & sOrderBy & " "
            
Case Else
                
getSql = ""
        
End Select
    End Function

    
'//产生条件字符串

    
Private Sub makeCondition()
        
If Not IsBlank(sCondition) Then Exit Sub
        If
UBound(aCondition)>= 0 Then
            
sCondition = " Where " & Join(aCondition, " AND ")
        
End If
    End Sub

    
'//计算记录数

    
Private Sub CaculateRecordCount()
        
On Error Resume Next
        Dim
oRs
        Call makeCondition()
        
sSqlString = "Select COUNT([" & sPKey & "]) FROM " & TableFormat(sTableName) & " " & IIf(IsBlank(sCondition), "", sCondition)
        
Set oRs = oConn.Execute( sSqlString )
        
If Err Then
            
doError Err.Description
            Response.End()
        
End If
        
iRecordCount = oRs.Fields.Item(0).Value
        Set oRs = Nothing
    End Sub

    
'//计算总记录数

    
Private Sub CaculateTotalRecordCount()
        
Dim oRs
        Set oRs = oConn.Execute( "Select COUNT(*) FROM " & TableFormat(sTableName) & "" )
        
iTotalRecordCount = oRs.Fields.Item(0).Value
        Set oRs = Nothing
    End Sub

    
'//计算页数

    
Private Sub CaculatePageCount()
        
If IsNull(iRecordCount) Then CaculateRecordCount()
        
If iRecordCount = 0 Then
            
iPageCount = 0
            
Exit Sub
        End If
        
iPageCount = Abs( Int( 0 - (iRecordCount / iPageSize) ) )
    
End Sub

    
'//设置页码

    
Private Function setPage(n)
        
iPage = Bint(n)
        
If iPage < 1 Then iPage = 1
    
End Function

    
'//增加条件

    
Public Sub AddCondition(s)
        
If IsBlank(s) Then Exit Sub
        ReDim Preserve
aCondition(UBound(aCondition) + 1)
        
aCondition(UBound(aCondition)) = s
    End Sub

    
'//版本信息

    
Public Function Information()
        
doError "Coding By <a href=""http://jorkin.reallydo.com"">Jorkin</a>.<a href=""http://www.reallydo.com"">ReallyDo.Com</a> ."
    
End Function

    
'//判断页面连接

    
Private Function ReWrite(n)
        
n = Bint(n)
        
If Not IsBlank(sRewrite) Then
            
ReWrite = Replace(sReWrite, "*", n)
        
Else
            Dim
sUrl, sQueryString, x
            sUrl = Request.ServerVariables("URL")
            
sQueryString = ""
            
For Each x In Request.QueryString
                If x <> sPageParam Then sQueryString = "&" & x & "=" & Server.UrlEncode(Request.QueryString(x)) & sQueryString
            Next
            
sQueryString = Mid(sQueryString, 2)
            
ReWrite = sUrl & "?" & sQueryString
            If n > 0 Then
                If
IsBlank(sQueryString) Then
                    
ReWrite = ReWrite & sPageParam & "=" & n
                Else
                    
ReWrite = ReWrite & "&" & sPageParam & "=" & n
                End If
            Else
                If
IsBlank(sQueryString) Then
                    
ReWrite = ReWrite & sPageParam & "="
                
Else
                    
ReWrite = ReWrite & "&" & sPageParam & "="
                
End If
            End If
        End If
    End Function

    
'//数据库表加 []

    
Private Function TableFormat(s)
        
Select Case iTableKind
            Case 0
                
TableFormat = "[" & s & "]"
            
Case 1
                
TableFormat = " " & s & " "
        
End Select
    End Function

    
'//函数、方法 结束
    '//-------------------------------------------------------------------------

    '//-------------------------------------------------------------------------
    '//输入属性 开始

    '//定义连接对象

    
Public Property Set ActiveConnection(o)
        
Set oConn = o
    End Property

    
'//连接字符串

    
Public Property Let ConnectionString(s)
        
Set oConn = Server.CreateObject("ADODB.Connection")
        
oConn.ConnectionString = s
        oConn.Open()
    
End Property

    
'//定义数据库类型

    
Public Property Let DBType(s)
        
sDBType = UCase(s)
    
End Property

    
'//定义 首页 样式

    
Public Property Let FirstPage(s)
        
sFirstPage = s
    End Property

    
'//定义 上一页 样式

    
Public Property Let PreviewPage(s)
        
sPreviewPage = s
    End Property

    
'//定义 当前页 样式

    
Public Property Let CurrentPage(s)
        
sCurrentPage = s
    End Property

    
'//定义 分页列表页 样式

    
Public Property Let ListPage(s)
        
sListPage = s
    End Property

    
'//定义 下一页 样式

    
Public Property Let NextPage(s)
        
sNextPage = s
    End Property

    
'//定义 末页 样式

    
Public Property Let LastPage(s)
        
sLastPage = s
    End Property

    
'//定义 列表前后多加几页

    
Public Property Let PagerTop(i)
        
iPagerTop = Bint(i)
    
End Property

    
'//定义 分页链接 样式

    
Public Property Let PagerClass(s)
        
sPagerClass = s
    End Property

    
'//定义查询表名

    
Public Property Let TableName(s)
        
sTableName = s
        '//如果发现表名包含 ([. ,那么就不要用 []
        
If InStr(s, "(")>0 Then iTableKind = 1
        
If InStr(s, "[")>0 Then iTableKind = 1
        
If InStr(s, ".")>0 Then iTableKind = 1
    
End Property

    
'//定义需要输出的字段名

    
Public Property Let Fields(s)
        
sFields = s
    End Property

    
'//定义主键

    
Public Property Let PKey(s)
        
If Not IsBlank(s) Then sPKey = s
    End Property

    
'//定义排序规则

    
Public Property Let OrderBy(s)
        
If Not IsBlank(s) Then sOrderBy = " orDER BY " & s & " "
    
End Property

    
'//定义每页的记录条数

    
Public Property Let PageSize(s)
        
iPageSize = Bint(s)
        
iPageSize = IIf(iPageSize<1, 1, iPageSize)
    
End Property

    
'//定义当前页码

    
Public Property Let Page(i)
        
setPage Bint(i)
    
End Property

    
'//定义当前页码(同Property Page)

    
Public Property Let AbsolutePage(s)
        
setPage s
    End Property

    
'//自定义查询语句

    
Public Property Let Sql(s)
        
sSqlString = s
    End Property

    
'//是否DISTINCT

    
Public Property Let Distinct(b)
        
bDistinct = b
    End Property

    
'//设定分页变量的名称

    
Public Property Let PageParam(s)
        
sPageParam = LCase(s)
    
End Property

    
'//选择分页的样式,可以后面自己添加新的

    
Public Property Let Style(s)
        
iStyle = s
    End Property

    
'//分页列表显示数量

    
Public Property Let PagerSize(i)
        
iPagerSize = Bint(i)
    
End Property

    
'//自定义ISAPI_REWRITE路径 *将被替换为当前页数

    
Public Property Let ReWritePath(s)
        
sReWrite = s
    End Property

    
'//强制TABLE类型

    
Public Property Let TableKind(i)
        
iTableKind = i
    End Property

    
'//自定义分页信息

    
Public Property Let PageInfo(s)
        
sPageInfo = s
    End Property

    
'//输入分页信息

    
Public Property Let JumpPageType(s)
        
sJumpPageType = UCase(s)
    
End Property

    
'//输入分页信息

    
Public Property Let JumpPageStyle(s)
        
sJumpPageStyle = s
    End Property


    
'//输入属性 结束
    '//-------------------------------------------------------------------------


    '//-------------------------------------------------------------------------
    '//输出属性 开始

    '//输出数据库类型

    
Public Property Get DBType()
        
DBType = sDBType
    End Property

    
'//输出查询表名

    
Public Property Get TableName()
        
TableName = sTableName
    End Property

    
'//输出需要输出的字段名

    
Public Property Get Fields()
        
Fields = sFields
    End Property

    
'//输出主键

    
Public Property Get PKey()
        
PKey = sPKey
    End Property

    
'//输出排序规则

    
Public Property Get OrderBy()
        
OrderBy = sOrderBy
    End Property

    
'//取得当前条件下的记录数

    
Public Property Get RecordCount
        If IsNull(iRecordCount) Then CaculateRecordCount()
        
RecordCount = iRecordCount
    End Property

    
'//取得每页记录数

    
Public Property Get PageSize
        PageSize = iPageSize
    End Property

    
'//取得当前查询的条件

    
Public Property Get Condition
        If IsBlank(sCondition) Then makeCondition()
        
Condition = sCondition
    End Property

    
'//取得当前页码

    
Public Property Get Page
        Page = iPage
    End Property

    
'//取得当前页码

    
Public Property Get AbsolutePage
        AbsolutePage = iPage
    End Property

    
'//取得总的记录数

    
Public Property Get TotalRecordCount
        If IsNull(iTotalRecordCount) Then CaculateTotalRecordCount()
        
TotalRecordCount = iTotalRecordCount
    End Property

    
'//取得总页数

    
Public Property Get PageCount
        If IsNull(iPageCount) Then CaculatePageCount()
        
PageCount = iPageCount
    End Property

    
'//得到分页后的记录集

    
Public Property Get RecordSet()
        
On Error Resume Next
        Select Case
sDbType
            Case "ACCESS", "AC" '//ACCESS
                
sSql = getSql()
                
Set RecordSet = Server.CreateObject ("ADODB.RecordSet")
                
RecordSet.Open sSql, oConn, 1, 1, &H0001
                RecordSet.PageSize = iPageSize
                iPage = IIf(iPage > RecordSet.PageCount, RecordSet.PageCount, iPage)
                
If iPage > 0 Then RecordSet.AbsolutePage = iPage
'               If iPage > 0 Then RecordSet.AbsolutePosition=(iPage-1)*iPageSize+1
            
Case "MSSQL", "SQL" '// MSSQL2000
                
sSql = getSql()
                
Set RecordSet = oConn.Execute( sSql )
            
Case "MSSQLProduce", "MSSQL_PR" '// SqlServer2000数据库存储过程版, 暂时不支持.请用叶子分页类
                
Set oRs = Server.CreateObject("ADODB.RecordSet")
                
Set oCommand = Server.CreateObject("ADODB.Command")
                
oCommand.CommandType = 4
                
oCommand.ActiveConnection = oConn
                oCommand.CommandText = "sp_Util_Page"
                
oCommand.Parameters(1) = i
                oCommand.Parameters(2) = iPageCurr
                oCommand.Parameters(3) = iPageSize
                oCommand.Parameters(4) = sPkey
                oCommand.Parameters(5) = sFields
                oCommand.Parameters(6) = sTableName
                oCommand.Parameters(7) = Join(aCondition, " AND ")
                
oCommand.Parameters(8) = Replace(sOrderBy, " orDER BY ", "")
                
oRs.CursorLocation = 3
                
oRs.LockType = 1
                
oRs.Open oCommand
            Case "MYSQL" 'MYSQL数据库,不会,暂时空着
                
sSql = getSql()
                
Set oRs = oConn.Execute(sSql)
            
Case Else '其他情况按最原始的ADO方法处理
                
sSql = getSql()
                
Set RecordSet = Server.CreateObject ("ADODB.RecordSet")
                
RecordSet.Open sSql, oConn, 1, 1, &H0001
                RecordSet.PageSize = iPageSize
                iPage = IIf(iPage>RecordSet.PageCount, RecordSet.PageCount, iPage)
                
RecordSet.AbsolutePage = iPage
        End Select
        If
Err Then
            If
bShowError Then doError Err.Description
            If Not IsBlank(sSqlString) Then
                Set
RecordSet = oConn.Execute( sSqlString )
                
If Err Then
                    
doError Err.Description
                    Response.End()
                
End If
            Else
                
doError Err.Description
                Response.End()
            
End If
        End If
        
Err.Clear()
    
End Property

    
'//版本信息

    
Public Property Get Version
        Version = sVersion
    End Property

    
'//输出页码及记录数等信息

    
Public Property Get PageInfo
        CaculatePageCount()
        
PageInfo = Replace(sPageInfo, sRecordCount, iRecordCount)
        
PageInfo = Replace(PageInfo, sPageCount, iPageCount)
        
PageInfo = Replace(PageInfo, sPage, iPage)
    
End Property

    
'//输出连接语句

    
Public Property Get ConnectionString()
        
ConnectionString = oConn.ConnectionString
    End Property

    
'//输出 首页 样式

    
Public Property Get FirstPage()
        
FirstPage = sFirstPage
    End Property

    
'//输出 上一页 样式

    
Public Property Get PreviewPage()
        
PreviewPage = sPreviewPage
    End Property

    
'//输出 当前页 样式

    
Public Property Get CurrentPage()
        
CurrentPage = sCurrentPage
    End Property

    
'//输出 列表页 样式

    
Public Property Get ListPage()
        
ListPage = sListPage
    End Property

    
'//输出 下一页 样式

    
Public Property Get NextPage()
        
NextPage = sNextPage
    End Property

    
'//输出 末页 样式

    
Public Property Get LastPage()
        
LastPage = sLastPage
    End Property

    
'//输出 末页 样式

    
Public Property Get PagerTop()
        
PagerTop = iPagerTop
    End Property


    
'//输出连接对象

    
Public Property Get Conn()
        
Set Conn = oConn
    End Property

    
'//条件有 Where In 时按 In 条件的顺序进行排序, 未完成

    
Public Property Get OrderIn(s, aWithc)
        
OrderIn = ReplaceAll(s, ", ", ",", False)
        
OrderIn = ReplaceAll(OrderIn, " ,", ",", False)
        
OrderIn = ReplaceAll(OrderIn, ",,", ",", False)
'       orderIn = "CHARINDEX(' ' + CONVERT(nvarchar(4000), " & aWithc & ") + ' ', ' ' + CONVERT(nvarchar(4000), Replace('" & s & "', ',',' , ')) + ' ')  "
        
OrderIn = "PATINDEX('% ' + CONVERT(nvarchar(4000), " & aWithc & ") + ' %', ' ' + CONVERT(nvarchar(4000), Replace('" & s & "', ',',' , ')) + ' ')  "
    
End Property

    
'//输出分页样式模板

    
Public Property Get CSS()
        
CSS = CSS & "<style type=""text/css"">" & vbCrLf
        CSS = CSS & "<!--" & vbCrLf
        CSS = CSS & ".kindbpager {" & vbCrLf
        CSS = CSS & "    background-color: #FFFFFF;" & vbCrLf
        CSS = CSS & "    color: #313031;" & vbCrLf
        CSS = CSS & "    font-family: Verdana,Tahoma,Arial,Helvetica,Sans-Serif;" & vbCrLf
        CSS = CSS & "    font-size: 12px;" & vbCrLf
        CSS = CSS & "    padding: 1px 2px 1px 0px;" & vbCrLf
        CSS = CSS & "}" & vbCrLf
        CSS = CSS & ".kindbpager a {" & vbCrLf
        CSS = CSS & "    border: #B7D8EE 1px solid;" & vbCrLf
        CSS = CSS & "    color: #0030CE;" & vbCrLf
        CSS = CSS & "    margin: 0px 3px;" & vbCrLf
        CSS = CSS & "    padding: 2px 4px 1px 4px;" & vbCrLf
        CSS = CSS & "    text-decoration: none;" & vbCrLf
        CSS = CSS & "    height:20px;" & vbCrLf
        CSS = CSS & "}" & vbCrLf
        CSS = CSS & ".kindbpager a:hover, .kindbpager a:active {" & vbCrLf
        CSS = CSS & "    background-color: #D2EAF6;" & vbCrLf
        CSS = CSS & "    color: #0066A7;" & vbCrLf
        CSS = CSS & "}" & vbCrLf
        CSS = CSS & ".kindbpager span.current {" & vbCrLf
        CSS = CSS & "    background-color: #D2EAF6;" & vbCrLf
        CSS = CSS & "    border: #B7D8EE 1px solid;" & vbCrLf
        CSS = CSS & "    color: #444444;" & vbCrLf
        CSS = CSS & "    font-weight: bold;" & vbCrLf
        CSS = CSS & "    margin: 0px 3px;" & vbCrLf
        CSS = CSS & "    padding: 2px 4px 1px 4px;" & vbCrLf
        CSS = CSS & "    height:18px;" & vbCrLf
        CSS = CSS & "}" & vbCrLf
        CSS = CSS & ".kindbpager span.disabled {" & vbCrLf
        CSS = CSS & "    display: none;" & vbCrLf
        CSS = CSS & "}" & vbCrLf
        CSS = CSS & "-->" & vbCrLf
        CSS = CSS & "</style>" & vbCrLf
    End Property

    
'//输出翻页按钮

    
Public Property Get Pager
        Dim sUrl, sQueryString, x
        Pager = ""
        
Select Case iStyle
            Case 0
                
If iPageCount>0 Then
                    If
iPage>1 Then
                        
Pager = Pager & "<a href=""" & Rewrite(1) & """ >" & sFirstPage & "</a> "
                        
Pager = Pager & "<a href=""" & Rewrite((iPage -1)) & """ >" & sPreviewPage & "</a> "
                    
Else
                        
Pager = Pager & "<span class=""disabled"">" & sFirstPage & "</span> "
                        
Pager = Pager & "<span class=""disabled"">" & sPreviewPage & "</span> "
                    
End If

                    
'//-----------------------------------------------------------------------------
                    '//分页 列表 样式 开始

                    
ss = (iPagerSize \ 2)
                    
iEnd = iPage + ss
                    iStart = iPage - (ss + (iPagerSize Mod 2)) + 1
                    
If iEnd > iPageCount Then
                        
iEnd = iPageCount
                        iStart = iPageCount - iPagerSize + 1
                    
End If
                    If
iStart < 1 Then
                        
iStart = 1
                        
iEnd = iStart + iPagerSize -1
                    
End If
                    If
iEnd > iPageCount Then
                        
iEnd = iPageCount
                    End If

                    If
iPagerTop > 0 Then
                        If
iPagerTop < iStart Then
                            For
i = 1 To iPagerTop
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
Next
                        Else
                            For
i = 1 To iStart - 1
                                
Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
Next
                        End If
                        If
iPagerTop < iStart -1 Then Pager = Pager & "... "
                    
End If

                    If
iPagerSize >0 Then
                        For
i = iStart To iEnd
                            If i = iPage Then
                                
Pager = Pager & "<span class=""current"">" & Replace(sCurrentPage, "{$Currentpage}", i, 1, -1, 1) & "</span> "
                            
Else
                                
Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
End If
                        Next
                    End If

                    If
iPagerTop > 0 Then
                        If
iPageCount - iPagerTop > iEnd Then Pager = Pager & "... "
                        
If iPageCount - iPagerTop > iEnd Then
                            For
i = iPageCount - iPagerTop + 1 To iPageCount
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
Next
                        Else
                            For
i = iEnd + 1 To iPageCount
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
Next
                        End If
                    End If

                    
'//分页 列表 样式 结束
                    '//-----------------------------------------------------------------------------
                    
If iPageCount>iPage Then
                        
Pager = Pager & "<a href=""" & Rewrite(iPage + 1) & """ >" & sNextPage & "</a> "
                        
Pager = Pager & "<a href=""" & Rewrite(iPageCount) & """ >" & sLastPage & "</a> "
                    
Else
                        
Pager = Pager & "<span class=""disabled"">" & sNextPage & "</span> "
                        
Pager = Pager & "<span class=""disabled"">" & sLastPage & "</span> "
                    
End If
                End If

            Case
1

                
If iPageCount>0 Then
                    If
iPage>1 Then
                        
Pager = Pager & "<a href=""" & Rewrite(1) & """ >" & sFirstPage & "</a> "
                        
Pager = Pager & "<a href=""" & Rewrite((iPage -1)) & """ >" & sPreviewPage & "</a> "
                    
Else
                        
Pager = Pager & sFirstPage & " "
                        
Pager = Pager & sPreviewPage & " "
                    
End If

                    
'//-----------------------------------------------------------------------------
                    '//分页 列表 样式 开始

                    
ss = (iPagerSize \ 2)
                    
iEnd = iPage + ss
                    iStart = iPage - (ss + (iPagerSize Mod 2)) + 1
                    
If iEnd > iPageCount Then
                        
iEnd = iPageCount
                        iStart = iPageCount - iPagerSize + 1
                    
End If
                    If
iStart < 1 Then
                        
iStart = 1
                        
iEnd = iStart + iPagerSize -1
                    
End If
                    If
iEnd > iPageCount Then
                        
iEnd = iPageCount
                    End If

                    If
iPagerTop > 0 Then
                        If
iPagerTop < iStart Then
                            For
i = 1 To iPagerTop
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
Next
                        Else
                            For
i = 1 To iStart - 1
                                
Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
Next
                        End If
                        If
iPagerTop < iStart -1 Then Pager = Pager & "... "
                    
End If

                    If
iPagerSize >0 Then
                        For
i = iStart To iEnd
                            If i = iPage Then
                                
Pager = Pager & Replace(sCurrentPage, "{$Currentpage}", i, 1, -1, 1) & " "
                            
Else
                                
Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
End If
                        Next
                    End If

                    If
iPagerTop > 0 Then
                        If
iPageCount - iPagerTop > iEnd Then Pager = Pager & "... "
                        
If iPageCount - iPagerTop > iEnd Then
                            For
i = iPageCount - iPagerTop + 1 To iPageCount
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
Next
                        Else
                            For
i = iEnd + 1 To iPageCount
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ >" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</a> "
                            
Next
                        End If
                    End If

                    
'//分页 列表 样式 结束
                    '//-----------------------------------------------------------------------------
                    
If iPageCount>iPage Then
                        
Pager = Pager & "<a href=""" & Rewrite(iPage + 1) & """ >" & sNextPage & "</a> "
                        
Pager = Pager & "<a href=""" & Rewrite(iPageCount) & """ >" & sLastPage & "</a> "
                    
Else
                        
Pager = Pager & sNextPage & " "
                        
Pager = Pager & sLastPage & " "
                    
End If

                End If


            Case Else


                If
iPageCount>0 Then
                    If
iPage>1 Then
                        
Pager = Pager & "<a href=""" & Rewrite(1) & """ ><font color=""#220282"">" & sFirstPage & "</font></a> "
                        
Pager = Pager & "<a href=""" & Rewrite((iPage -1)) & """ ><font color=""#220282"">" & sPreviewPage & "</font></a> "
                    
Else
                        
Pager = Pager & "<font color=""#220282"">" & sFirstPage & "</font> "
                        
Pager = Pager & "<font color=""#220282"">" & sPreviewPage & "</font> "
                    
End If

                    
'//-----------------------------------------------------------------------------
                    '//分页 列表 样式 开始

                    
ss = (iPagerSize \ 2)
                    
iEnd = iPage + ss
                    iStart = iPage - (ss + (iPagerSize Mod 2)) + 1
                    
If iEnd > iPageCount Then
                        
iEnd = iPageCount
                        iStart = iPageCount - iPagerSize + 1
                    
End If
                    If
iStart < 1 Then
                        
iStart = 1
                        
iEnd = iStart + iPagerSize -1
                    
End If
                    If
iEnd > iPageCount Then
                        
iEnd = iPageCount
                    End If

                    If
iPagerTop > 0 Then
                        If
iPagerTop < iStart Then
                            For
i = 1 To iPagerTop
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ ><font color=""#220282"">" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</font></a> "
                            
Next
                        Else
                            For
i = 1 To iStart - 1
                                
Pager = Pager & "<a href=""" & ReWrite(i) & """ ><font color=""#220282"">" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</font></a> "
                            
Next
                        End If
                        If
iPagerTop < iStart -1 Then Pager = Pager & "... "
                    
End If

                    If
iPagerSize >0 Then
                        For
i = iStart To iEnd
                            If i = iPage Then
                                
Pager = Pager & "<font color=""#820222"">" & Replace(sCurrentPage, "{$Currentpage}", i, 1, -1, 1) & "</font> "
                            
Else
                                
Pager = Pager & "<a href=""" & ReWrite(i) & """ ><font color=""#220282"">" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</font></a> "
                            
End If
                        Next
                    End If

                    If
iPagerTop > 0 Then
                        If
iPageCount - iPagerTop > iEnd Then Pager = Pager & "... "
                        
If iPageCount - iPagerTop > iEnd Then
                            For
i = iPageCount - iPagerTop + 1 To iPageCount
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ ><font color=""#220282"">" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</font></a> "
                            
Next
                        Else
                            For
i = iEnd + 1 To iPageCount
                                Pager = Pager & "<a href=""" & ReWrite(i) & """ ><font color=""#220282"">" & Replace(sListPage, "{$Listpage}", i, 1, -1, 1) & "</font></a> "
                            
Next
                        End If
                    End If

                    
'//分页 列表 样式 结束
                    '//-----------------------------------------------------------------------------
                    
If iPageCount>iPage Then
                        
Pager = Pager & "<a href=""" & Rewrite(iPage + 1) & """ ><font color=""#220282"">" & sNextPage & "</font></a> "
                        
Pager = Pager & "<a href=""" & Rewrite(iPageCount) & """ ><font color=""#220282"">" & sLastPage & "</font></a> "
                    
Else
                        
Pager = Pager & "<font color=""#220282"">" & sNextPage & "</font> "
                        
Pager = Pager & "<font color=""#220282"">" & sLastPage & "</font> "
                    
End If

                End If
        End Select
    End Property

    
'//页面跳转

    
Public Property Get JumpPage()
        
Dim x, sQueryString, aQueryString
        Dim nRnd
        Randomize()
        
nRnd = CLng(Rnd() * 2925)
        
sJumpPage = vbCrLf
        Select Case sJumpPageType
            Case "INPUT"
                
sJumpPage = "<input type=""text"" name=""KinDbPager" & nRnd & """ title=""请输入数字,回车跳转"" size=""3"" onKeyDown=""if(event.keyCode==13&&!isNaN(this.value))document.location.href='" & ReWrite(0) & "'+this.value"" " & IIf(IsBlank(sJumpPageStyle), "", sJumpPageStyle) & " />"
            
Case "Select"
                
sJumpPage = sJumpPage & "<select name=""KinDbPager" & nRnd & """ onChange=""javascript:window.location.href=this.options[this.selectedIndex].value;"" " & IIf(IsBlank(sJumpPageStyle), "", sJumpPageStyle) & " >" & vbCrLf

                iStart = iPage - 50
                
iEnd = iPage + 50
                
If iEnd > iPageCount Then
                    
iEnd = iPageCount
                    iStart = iPageCount - 100 + 1
                
End If
                If
iStart < 1 Then
                    
iStart = 1
                    
iEnd = iStart + 100 -1
                
End If
                If
iEnd > iPageCount Then
                    
iEnd = iPageCount
                End If
                
sJumpPage = sJumpPage & "<option value=""javascript:void(0)"" >-</option>" & vbCrLf
                For i = iStart To iEnd
                    sJumpPage = sJumpPage & "<option value=""" & ReWrite(i) & """" & IIf(i = iPage, " selected=""selected"" ", "") & ">"&i&"</option>" & vbCrLf
                Next

                
sJumpPage = sJumpPage & "</select>"
            
Case Else
                
sJumpPage = ""
        
End Select
        
JumpPage = sJumpPage
    End Property

    
'//输出属性 结束
    '//-------------------------------------------------------------------------

End Class
%>
<%
Sub Eg()
    
Response.Write "Dim i, iCols, iPageSize<br />" & vbCrLf
    Response.Write "Dim iCurrPage, iRecordCount, iPageCount<br />" & vbCrLf
    Response.Write "Dim sPageInfo, sPager, sJumpPage<br />" & vbCrLf
    Response.Write "iPageSize = 20<br />" & vbCrLf
    Response.Write "Dim oDbPager<br />" & vbCrLf
    Response.Write "Set oDbPager = New Kin_db_Pager<br />" & vbCrLf
    Response.Write "Set oDbPager.ActiveConnection = oConn '//指定数据库连接<br />" & vbCrLf
    Response.Write "oDbPager.DbType = ""ACCESS"" '//指定数据库类型<br />" & vbCrLf
    Response.Write "oDbPager.TableName = ""Kin_Article"" '//指定目标表 可用临时表<br />" & vbCrLf
    Response.Write "oDbPager.Fields = ""*"" '//选择列<br />" & vbCrLf
    Response.Write "oDbPager.PKey = ""Article_ID"" '//主建<br />" & vbCrLf
    Response.Write "oDbPager.OrderBy = ""Article_ID DESC"" '//排序 把Order By 后面的都写在这里<br />" & vbCrLf
    Response.Write "oDbPager.AddCondition ""Article_ID >0"" '//添加条件,可多次使用 如果用Or条件需要(条件1 or 条件2)<br />" & vbCrLf
    Response.Write "oDbPager.PageSize = iPageSize '//排序<br />" & vbCrLf
    Response.Write "oDbPager.Page = Request.QueryString(""page"") '//当前页数<br />" & vbCrLf
    Response.Write "'oDbPager.PageParam = ""page"" '//页数URL变量<br />" & vbCrLf
    Response.Write "'oDbPager.PagerTop = 2 '//定义首尾要显示几个页面 如12...456...78<br />" & vbCrLf
    Response.Write "'oDbPager.PagerSize = 5 '//定义分页列表数量<br />" & vbCrLf
    Response.Write "'oDbPager.JumpPageType = ""INPUT"" '//定义跳转列表为&lt;INPUT&gt;文本框,默认为Select<br />" & vbCrLf
    Response.Write "'oDbPager.FirstPage = ""&lt;&lt;"" '//定义 首页 样式<br />" & vbCrLf
    Response.Write "'oDbPager.PreviewPage = ""&lt;"" '//定义 上一页 样式<br />" & vbCrLf
    Response.Write "'oDbPager.NextPage = ""&gt;"" '//定义 下一页 样式<br />" & vbCrLf
    Response.Write "'oDbPager.LastPage = ""&gt;&gt;"" '//定义 末页 样式<br />" & vbCrLf
    Response.Write "'oDbPager.CurrentPage = ""{$CurrentPage}"" '//定义 当前页 样式<br />" & vbCrLf
    Response.Write "'oDbPager.ListPage = ""{$ListPage}"" '//定义 列表页 样式<br />" & vbCrLf
    Response.Write "'oDbPager.Style = 0 '//选择 分页 输出样式<br />" & vbCrLf
    Response.Write "'WriteLn(oDbPager.CSS) '//输出默认样式表<br />" & vbCrLf
    Response.Write "'oDbPager.RewritePath = ""*.html"" '//自定义ISAPI_REWRITE路径 * 号 将被替换为当前页数<br />" & vbCrLf
    Response.Write "'WriteLn(oDbPager.GetSql()) : Response.End()'//输出 SQL 语句,方便调试<br />" & vbCrLf
    Response.Write "Set ors = oDbPager.Recordset<br />" & vbCrLf
    Response.Write "iCurrPage = oDbPager.Page '//当前页<br />" & vbCrLf
    Response.Write "iRecordCount = oDbPager.RecordCount '//记录集数量<br />" & vbCrLf
    Response.Write "iPageCount = oDbPager.PageCount '//共计多少页<br />" & vbCrLf
    Response.Write "sPageInfo = oDbPager.PageInfo '//输出默认记录集信息<br />" & vbCrLf
    Response.Write "sPager = oDbPager.Pager '//输出分页信息<br />" & vbCrLf
    Response.Write "sJumpPage = oDbPager.JumpPage '//输出跳转列表<br />" & vbCrLf
    Response.Write "<br />" & vbCrLf
    Response.Write "'//例子: 动态输出M行N列, 多行多列, 循环行列, 循环TABLE<br />" & vbCrLf
    Response.Write "i = 0 '//初始化i准备循环<br />" & vbCrLf
    Response.Write "iCols = 5 '//定义一行最多有几列(正整数)<br />" & vbCrLf
    Response.Write "WriteLn(""&lt;table width=""""100%"""" border=""""0"""" cellspacing=""""1"""" cellpadding=""""2"""" bgcolor=""""#000000"""">&lt;tr>"")<br />" & vbCrLf
    Response.Write "Do While (Not ors.EOF) And (i < iPageSize) '// (i < iPageSize)条件为ACCESS分页时必要<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; If i > 0 And i Mod iCols = 0 Then WriteLn(""&lt;/tr>&lt;tr>"")<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; i = i + 1<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; WriteLn(""&lt;td width=""""""&FormatPercent(1 / iCols, 0)&"""""" bgcolor=""""#FFFFFF"""">"" & Server.HTMLEncode(oRs(2)) & ""&lt;/td>"")<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; ors.MoveNext<br />" & vbCrLf
    Response.Write "Loop<br />" & vbCrLf
    Response.Write "Do While i < iPageSize<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; If i Mod iCols = 0 Then '//以下两个条件二选一<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; &nbsp; &nbsp; WriteLn(""&lt;/tr>&lt;tr>"") '//如果要补满表格就输出&lt;/tr>&lt;tr><br />" & vbCrLf
    Response.Write "'&nbsp; &nbsp; &nbsp;  Exit Do '//如果要补满最后一行就直接结束<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; End If<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; i = i + 1<br />" & vbCrLf
    Response.Write "&nbsp; &nbsp; WriteLn(""&lt;td width=""""""&FormatPercent(1 / iCols, 0)&"""""" bgcolor=""""#CCCCCC"""">&amp;nbsp;&lt;/td>"")<br />" & vbCrLf
    Response.Write "Loop<br />" & vbCrLf
    Response.Write "WriteLn(""&lt;/tr>&lt;tr>&lt;td colspan="""""" & iCols & """""" bgcolor=""""#FFFFFF"""">&lt;div class=""""kindbpager"""">&lt;span style=""""float:right;"""">"" & sPager & "" 跳至: "" & sJumpPage & "" 页&lt;/span>"" & sPageInfo & ""&lt;/div>&lt;/td>&lt;/tr>"")<br />" & vbCrLf
    Response.Write "WriteLn(""&lt;/table>"")<br />" & vbCrLf
    Response.Write "oRs.Close<br />" & vbCrLf
End Sub
%>


文章来源: http://Jorkin.Reallydo.Com/default.asp?id=534

你可能感兴趣的:(自定义)