今天是:
首 页信息查询网站SEO查询工具CSS编辑器建站素材
网海拾贝,电脑资讯,电脑快报,it资讯,网站建设资讯,教程基地
软件新闻
操作系统
Vista Winxp Win2003 Linux Windows综合
工具软件
系统工具 媒体工具 网络工具 杀毒软件 聊天
软件开发
C教程 C++ Java C# ASP.NET JSP PHP
数据库
Oracle MySQL DB2 SQL Server Sybase
安全
网络 病毒
办公应用
Word Excel Powerpoint Outlook 其他
平面设计
Photoshop Fireworks Coreldraw Flash Illustrator 3dsmax
网站运营
网站运营 网站优化 网站策划 策划书下载 建站心得 站长故事 网站盈利 网页制作 网页特效 建站素材 免费资源 QQ频道
  当前位置:首 页 >> 软件开发 >> ASP教程 >> ASP通用分页类

ASP通用分页类

  发布于2005-11-18 16:18 来源:网海拾贝

一、类的属性、方法

  这是一个ASP通用分页类。你可以用它方便的给记录集分页,当然在网上有许多的分页类和分页函数。本分页主要有GetConn、GetRS、SQL、URL、CSSFile、FldName、FldNote、FldWidth、FldAlign、ShowPageType、TleFTColor、TleWidth、PageSize、ShowWidth、Init、Pages、ShowData、Close等属性和方法。
  1.GetConn属性 :用来获取一个已创建的Connection对象。
  2.GetRS属性 :用来获取一个已创建的RecordSet对象,如果设置该属性后,不需要设置SQL属性。
  3.SQL属性 :根据传入的SQL语句,自动创建RecordSet对象
  4.PageSize属性 :设置第页的记录条数
  5.FldName属性 :如果需要显示库中的数据(即调用ShowData过程),一定要设置此属性。它是用来获取需要显示的正确的字段名。
  6.FldNote属性 :设置相应字段名的中文说明,需要跟FldName中的字段名一一对应。
  7.FldWidth属性 :设置显示相应字段数据的单元格的宽度,要跟FldName中的字段名一一对应。
  8.FldAlign属性 :设置显示相应字段数据的单元格的对齐方式,要跟FldName中的字段名一一对应。
  9.TleBGColor过程 :设置数据标题栏的背景颜色。如果要显示数据,可以设置此选项。
  10.TleFTColor属性 :设置数据标题栏的字体颜色。
  11.TleWidth属性 :设置数据标题栏的宽度,横排时可设置此属性。
  12.ShowPageType属性 :设置分页条的显示类型。有汉字、字符、英文之分。
  13.ShowType属性 :设置数据显示的类型,分横、竖两种。
  14.ShowWidth属性 :设置数据显示时表格的宽度。
  15.CSSFile属性 :设置相应的CSS文件名及相对路径。
  16.URL属性 :设置分页条中链接的文件地址。
  17.Init过程 :分页类初始化数据。
  18.ShowData过程 :显示数据。
  19.Pages过程 :显示分页条
  20.Close过程 :分页类结束

二、类的源代码(inc_clsPage.asp)

<%Option Explicit
 '/************************************************
 '*                        *
 '* Name  : Asp pagnation class         *
 '* Author : Sunway               *
 '* Version : V2.0                *
 '* Time  : 2003-12-26             *
 '* Email  : sunway8110@126.com                  *
 '* HomePage: None (Maybe Soon)          *
 '* Notice :  You can use and modify it freely, *
 '*      BUT PLEASE HOLD THIS ITEM.     *
 '*       If you modify it that i hope you *
 '*      can send a mail for me.       *
 '*                        *
 '************************************************/

 '#########声明变量#########
 'SWStyle Class
 Private SW_strBTNClass,SW_strTXTClass,SW_strBGColor,SW_intTBWidth,SW_intBDKind,SW_strBGImage,SW_strFTColor,SW_strBDColor,SW_strShowWidth
 '#########初始化变量##########
 SW_strFTColor = "#000000"  'Font color
 SW_strBGColor = "#FFFFFF"  'Background color
 SW_intBDKind = 1      'Default border kind is "thin border".
 SW_intTBWidth = "98%"    'Table's width.
 SW_strBDColor = "#000000"  'Table's border color.

 'SWPage Class
 Private SW_blnErrorFlag,SW_blnIsHaveRS,SW_strFields
 '#########初始化变量##########
 SW_blnErrorFlag = false   '设置错误标志为Fasle,就是无错误状态
 SW_blnIsHaveRS = false   '设置记录集获取标志为Fasle,就是无记录集状态
 SW_strShowWidth = "90%"
 SW_strFields  = ""

 '定义链接的显示类型
 Const SW_intShowChinese   = 0 '汉字,如"上一页、下一页"
 Const SW_intShowEnglish   = 1 '英文,如"Back、Next"
 Const SW_intShowCharacter  = 2 '特殊字符
' Const SW_intShowImage    = 3 '图片
 '定义数据的显示类型
 Const SW_intHorizontalView = 0 '横排
 Const SW_intVerticalView  = 1 '竖排
 '线的显示类型
 Const SW_intShowBigBorder  = 2 '粗线
 Const SW_intShowSmallBorder = 1 '细线
 Const SW_intShowNoBorder  = 0 '无线

 '显示的页数
 Const SW_intShowPages    = 10

 '*****************************************
 ' 类型:  类
 ' 目的:  控制分页信息显示的样式
 '*****************************************
 Class SWStyle
   '*****************************************
 ' 类型:  属性
   ' 目的:  设定背景颜色
   ' 输入:  a_strBGColor:  背景颜色。
   ' 返回:  无
   '*****************************************
   Public Property Let BGColor(a_strBGColor)
     SW_strBGColor = a_strBGColor
 End Property

   '*****************************************
 ' 类型:  属性
   ' 目的:  设定背景图像
   ' 输入:  a_strBGImage:  背景图像
   ' 返回:  无
   '*****************************************
   Public Property Let BGImage(a_strBGImage)
     SW_strBGImage = a_strBGImage
 End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  设定表格中字体的颜色
   ' 输入:  a_strFTColor:  字体的颜色
   ' 返回:  无
   '*****************************************
   Public Property Let FTColor(a_strFTColor)
     SW_strFTColor = a_strFTColor
 End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  设定表格线的颜色
   ' 输入:  a_strBDColor:  格线的颜色
   ' 返回:  无
   '*****************************************
   Public Property Let BDColor(a_strBDColor)
     SW_strBDColor = a_strBDColor
 End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  设定表格线的类型
   ' 输入:  a_intBDKind:  格线的类型
   '           0:  没线
   '           1:  细线
   '           2:  粗线
   ' 返回:  无
   '*****************************************
   Public Property Let BDKind(a_intBDKind)
     SW_intBDKind = a_intBDKind
 End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  设定表格宽度
   ' 输入:  a_intTBWidth:  表格的宽度
   ' 返回:  无
   '*****************************************
   Public Property Let TBWidth(a_intTBWidth)
     SW_intTBWidth = a_intTBWidth
   End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  设定按钮的样式
   ' 输入:  a_strBNStyle:  CSS样式代码
   ' 返回:  无
   '*****************************************
   Public Property Let BTNClass(a_strBTNClass)
     SW_strBTNClass = a_strBTNClass
   End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  设定文本框的样式
   ' 输入:  a_strTXTStyle:  CSS样式代码
   ' 返回:  无
   '*****************************************
   Public Property Let TXTClass(a_strTXTClass)
     SW_strTXTClass = a_strTXTClass
   End Property
 End Class

 '*****************************************
 ' 类型:  类
 ' 目的:  给记录集分页
 '*****************************************
 Class SWPage
   '声明类私有变量
   Private SW_objRS,SW_objConn

 Private SW_strSQL,SW_strURL,SW_strError,SW_strFormAction,SW_strCSSFile
   Private SW_strTleBGColor,SW_strTleFTColor,SW_strTleWidth

 Private SW_intPageSize
   Private SW_lngTotalPage,SW_lngTotalRecord,SW_lngPageNo,SW_lngShowType,SW_lngShowPageType
   Private SW_aryFldName,SW_aryFldNote,SW_aryFldWidth,SW_aryFldAlign
 Private SW_blnInit,SW_blnGetData,SW_blnGetConn,SW_blnPageSize,SW_blnFieldName,SW_blnGetURL,SW_blnShowType,SW_blnShowPageType


 '*****************************************
 ' 类型:  属性
   ' 目的:  设定或显示每页的记录数。
   ' 输入:  a_intPageSize:  每页显示的记录数。
   ' 返回:  每页显示的记录数。
   '*****************************************
 Public Property Let PageSize(a_intPageSize)
     Dim strError

  'PageSize获取失败标志
  SW_blnPageSize = false
  If Trim(a_intPageSize) = "" OR (Not(IsNumeric(a_intPageSize))) Then
       strError = strError & "<br>非法的pagesize"
  Else
       If (a_intPageSize <= 2147483647 And a_intPageSize>=-2147483648) Then
         SW_intPageSize = CLng(a_intPageSize)
       Else
         strError = strError & "<br>PageSize溢出"
  End If
  If (SW_intPageSize<=0) Then
         strError = strError & "<br>PageSize只能是正整数"
       End If
  End If
     If Trim(strError)="" Then
       SW_blnPageSize = True
     Else
       SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">PageSize属性:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
     End If
 End Property

   '*****************************************
 ' 类型:  属性
   ' 目的:  设定或显示SQL语句。
   ' 输入:  a_strSQL:  SQL语句。
   ' 返回:  SQL语句。
   '*****************************************
 Public Property Let SQL(a_strSQL)
     Dim strError

  SW_blnGetData = false
  SW_strSQL = a_strSQL
  If SW_blnIsHaveRS = false Then
     '创建RecordSet对象
     Set SW_objRS = CreateObject("adodb.RecordSet")
       On Error Resume Next
    SW_objRS.Open SW_strSQL,SW_objConn,1,1
    If Err.Number <> 0 Then
   strError = "<br>记录集打开失败"
         On Error Goto 0
       End If
     End If
     If Trim(strError)="" Then
       SW_blnGetData = true
     Else
       SW_strError = SW_strError & "  <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">SQL属性:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
     End If
 End Property
  
   '*****************************************
 ' 类型:  属性
   ' 目的:  设定css。
   ' 输入:  a_strCSSFilePath:  分页文件的样式文件。
   ' 返回:  无。
   '*****************************************
 Public Property Let CSSFile(a_strCSSFilePath)
     SW_strCSSFile = "<link rel=""stylesheet"" href=""" & a_strCSSFilePath & """ type=""text/css"">"
   End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  设定或显示URL。
   ' 输入:  a_strURL:  需要分页的文件地址。
   ' 返回:  需要分页的文件地址。
   '*****************************************
 Public Property Let URL(a_strURL)
     Dim strError,objFSO

  SW_blnGetURL = false
  If Trim(a_strURL)="" Then
       strError = "<br>非法的URL地址"
     Else
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FileExists(Server.Mappath(a_strURL)) Then
    SW_strURL = a_strURL
       Else
         strError = strError & "<br>你能确定文件 <font color=""#ff0000"">" & a_strURL & "</font> 存在么?"
  End If
  Set objFSO = Nothing
  End If
     If strError = "" Then
       SW_blnGetURL = true
     Else
       SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">URL属性:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
     End If
 End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  获取显示的方式
   ' 输入:  a_intType:显示方式如:1、2
   ' 返回:  无
   '*****************************************
   Public Property Let ShowPageType(a_intType)
     Dim strError

     SW_blnShowPageType = false
  If Trim(a_intType) <> "" And IsNumeric(a_intType) Then
       If (a_intType <= 2147483647 And a_intType>=-2147483648) Then
         SW_lngShowPageType = CLng(a_intType)
       Else
         strError = "<br>显示类型参数溢出"
  End If
     Else
       SW_lngShowPageType = SW_intHorizontalView
  End IF
     If Trim(strError) = "" Then
       SW_blnShowPageType = true
     Else
       SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">ShowPageType属性:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
     End If
 End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  获取显示的方式
   ' 输入:  a_intType:显示方式如:1、2
   ' 返回:  无
   '*****************************************
   Public Property Let ShowType(a_intType)
     Dim strError

  SW_blnShowType = false
  If Trim(a_intType) <> "" And IsNumeric(a_intType) Then
       If (a_intType <= 2147483647 And a_intType>=-2147483648) Then
         SW_lngShowType = CLng(a_intType)
       Else
         strError = "<br>显示类型参数溢出"
  End If
     Else
       SW_lngShowType = SW_intShowChinese
  End IF
     If Trim(strError)="" Then
       SW_blnShowType = true
     Else
       SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">ShowType属性:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
     End If
 End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  获取数据连接
   ' 输入:  a_objConn:已创建的Connection对象
   ' 返回:  无
   '*****************************************
   Public Property Let GetConn(a_objConn)
     Const adStateOpen = 1
     Dim intReturn,strError
     SW_blnGetConn = false

  If IsObject(a_objConn) Then
       If Not IsObject(SW_objConn) Then
         On Error Resume Next
         intReturn =a_objConn.State
         If err.Number<>0 Then
         strError = strError & "<br>试图创建非法的Connection对象"
           On Error Goto 0
   Else
           On Error Goto 0
   If Not (intReturn = adStateOpen) Then
           strError = strError & "<br>Connection对象打开失败"
   End If
   End If
   Set SW_objConn = a_objConn
       Else
       strError = strError & "<br>创建Connection对象失败"
  End If
  Else
       strError = strError & "<br>试图创建非法的Connection对象"
  End If
     If Trim(strError)="" Then
       SW_blnGetConn = true
     Else
       SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">GetConn属性:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
     End If
 End Property

   '*****************************************
 ' 类型:  属性
   ' 目的:  设置需要显示的数据的字段名
   ' 输入:  a_strFldName:字段名字符串,多个字段之间以逗号分隔
   ' 返回:  无
   '*****************************************
   Public Property Let FldName(a_strFldName)
     Dim strError

  SW_blnFieldName = false
  If Trim(a_strFldName) <> "" Then
       SW_aryFldName = Split(a_strFldName,",")
     Else
       strError = strError & "<br>你必须设置<font color=""#ff0000"">FldName</font>属性,否则无法显示数据"
  End If
     If Trim(strError)="" Then
       SW_blnFieldName = true
     Else
       SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">FldName属性:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
     End If
 End Property

   '*****************************************
 ' 类型:  属性
   ' 目的:  设置显示某些字段的中文说明
   ' 输入:  a_strFldNote:字段中文说明字符串,多个字段之间以逗号分隔
   ' 返回:  无
   '*****************************************
   Public Property Let fldNote(a_strFldNote)
     If Trim(a_strFldNote) <> "" Then
       SW_aryFldNote = Split(a_strFldNote,",")
  End If
   End Property

   '*****************************************
 ' 类型:  属性
   ' 目的:  设置显示某些字段数据时单元格的宽度
   ' 输入:  a_strFldWidth:单元格宽度字符串,多个字段之间以逗号分隔
   ' 返回:  无
   '*****************************************
   Public Property Let fldWidth(a_strFldWidth)
     If Trim(a_strFldWidth) <> "" Then
       SW_aryFldWidth = Split(a_strFldWidth,",")
  End If
   End Property

   '*****************************************
 ' 类型:  属性
   ' 目的:  设置显示某些字段数据时在单元格中的对齐方式
   ' 输入:  a_strFldAligbn:对齐方式字符串,多个字段之间以逗号分隔
   ' 返回:  无
   '*****************************************
   Public Property Let fldAlign(a_strFldAlign)
     If Trim(a_strFldAlign) <> "" Then
       SW_aryFldAlign = Split(a_strFldAlign,",")
  End If
   End Property

   '*****************************************
 ' 类型:  属性
   ' 目的:  设置表格标题栏的背景颜色
   ' 输入:  a_strTleColor:颜色参数,如#FFFFFF
   ' 返回:  无
   '*****************************************
   Public Property Let TleBGColor(a_strTleBGColor)
     SW_strTleBGColor = a_strTleBGColor
   End Property

   '*****************************************
 ' 类型:  属性
   ' 目的:  设置表格标题栏中文字的颜色
   ' 输入:  a_strTleColor:颜色参数,如#FFFFFF
   ' 返回:  无
   '*****************************************
   Public Property Let TleFTColor(a_strTleFTColor)
     SW_strTleFTColor = a_strTleFTColor
   End Property

 '*****************************************
 ' 类型:  属性
   ' 目的:  设置显示标题时单元格的宽度
   ' 输入:  a_strTleWidth:单元格宽度字符串
   ' 返回:  无
   '*****************************************
   Public Property Let TleWidth(a_strTleWidth)
     SW_strTleWidth = a_strTleWidth
   End Property


 '*****************************************
 ' 类型:  属性
   ' 目的:  设置显示标题时单元格的宽度
   ' 输入:  a_strTleWidth:单元格宽度字符串
   ' 返回:  无
   '*****************************************
   Public Property Let ShowWidth(a_strShowWidth)
     SW_strShowWidth = a_strShowWidth
   End Property

 '*****************************************
 ' 类型:  过程
   ' 目的:  获取数据记录集
   ' 输入:  a_objRS:已创建的RecordSet对象
   ' 返回:  无
   '*****************************************
   Public Property Let GetRS(a_objRS)
     Dim intTemp,strError

  SW_blnGetData = false
  If IsObject(a_objRS) Then
       If Not IsObject(SW_objRS) Then
         Set SW_objRS = a_objRS
         On Error Resume Next
         intTemp = SW_objRS.LockType
         If err.Number <> 0 Then
           strError = strError & "<br>试图创建非法的RecordSet对象"
           On Error Goto 0
         Else
     SW_blnIsHaveRS = true
           On Error Goto 0
   End If
       End If
  Else
       strError = strError & "<br>试图创建Connection对象失败"
  End If
     If Trim(strError)="" Then
       SW_blnGetData = true
     Else
       SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">GetRS属性:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
  End If
 End Property

 '*****************************************
 ' 类型:  过程
   ' 目的:  统计总记录数、计算总页数
   ' 输入:  无
   ' 返回:  无
   '*****************************************
 Sub Init()
     Dim intPostion,strError

     If Not (SW_blnGetConn and SW_blnGetData and SW_blnPageSize and SW_blnGetURL) Then
      SW_blnErrorFlag = true
  Call ShowErrors()
  Exit Sub
     End If

  If SW_objRS.Eof And SW_objRS.Bof Then
      strError = strError & "<br>库中无任何记录"
     End If

  '计算总计录数
  SW_lngTotalRecord = SW_objRS.RecordCount
     If (SW_lngTotalRecord<=2147483647 AND SW_lngTotalRecord>=-2147483648) Then
       SW_lngTotalRecord = CLng(SW_lngTotalRecord)
     Else
       strError = strError & "<br>分页初始化时:总记录数溢出"
  End If
     If SW_lngTotalRecord <=0 Then strError = strError & "<br>分页初始化时:总记录数小于零"

  '计算总页数
     If SW_lngTotalRecord Mod SW_intPageSize = 0 Then
    SW_lngTotalPage = CLng(SW_lngTotalRecord  SW_intPageSize * -1)*-1
     Else
  SW_lngTotalPage = CLng(SW_lngTotalRecord  SW_intPageSize * -1)*-1 + 1
     End If

  '获取页数
  SW_lngPageNo = Trim(Request.QueryString("pageno"))
  If SW_lngPageNo = "" Then SW_lngPageNo = Trim(Request.Form("PageNo"))
  If SW_lngPageNo = "" Then SW_lngPageNo = 1
     '如果没有选择第几页,则默认显示第一页
     If SW_lngPageNo <> "" And IsNumeric(SW_lngPageNo) Then
       If (SW_lngPageNo <= 2147483647 And SW_lngPageNo>=-2147483648) Then
         SW_lngPageNo = CLng(SW_lngPageNo)
       Else
         strError = strError & "<br>页数溢出,请检查!"
   End If
  If (SW_lngPageNo<=0) Then strError = strError & "<br>页数只能是正整数!"
     Else
       strError = strError & "<br>你确信此页数 <font color=""#FF0000"">" & SW_lngPageNo & "</font> 存在?"
   End If

  If (SW_lngPageNo > SW_lngTotalPage AND SW_lngTotalPage<>0) Then SW_lngPageNo = SW_lngTotalPage

     SW_objRS.PageSize   = SW_intPageSize
   SW_objRS.AbsolutePage = SW_lngPageNo

  intPostion = InstrRev(SW_strURL,"?")
   SW_strFormAction = SW_strURL
   If intPostion > 0 Then
     SW_strURL = SW_strURL & "&PageNo="
     Else
     SW_strURL = SW_strURL & "?PageNo="
   End If

     If Trim(SW_strFields) = "" Then
       For i = 0 To SW_objRS.Fields.Count-1
         SW_strFields = SW_strFields & SW_objRS(i).Name & ","
  Next
     End If

     SW_strFields = "," & Trim(SW_strFields)
  If IsArray(SW_aryFldName) Then
     For i = LBound(SW_aryFldName) To Ubound(SW_aryFldName)
   If Instr(SW_strFields,"," & SW_aryFldName(i) & ",") = 0 Then strError = strError & "<br>字段名 <font color=""#ff0000"">" & SW_aryFldName(i) & "</font> 正确吗?"
  Next

  If (IsArray(SW_aryFldNote) AND UBound(SW_aryFldName)>UBound(SW_aryFldNote)) Then strError = strError & "<br>字段相应中文说明项目不能小于字段个数"

    If (IsArray(SW_aryFldWidth) AND UBound(SW_aryFldName)>UBound(SW_aryFldWidth)) Then strError = strError & "<br>字段相应宽度项目不能小于字段个数"
 
    If (IsArray(SW_aryFldAlign) AND UBound(SW_aryFldName)>UBound(SW_aryFldAlign)) Then strError = strError & "<br>字段数据相应对齐方式项目不能小于字段个数"
  End If

  If Trim(strError) = "" Then
       SW_blnInit = true
     Else
       SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">Init过程:</font></td></tr>" & vbcrlf
       SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
     End If
     Response.Write(SW_strCSSFile & vbcrlf)
 End Sub

   '*****************************************
 ' 类型:  过程
   ' 目的:  显示分页信息
   ' 输入:  无
   ' 返回:  无
   '*****************************************
   Sub Pages()
     Dim strPages,k,intTemp,intTemp1

  If Not(SW_blnInit) Then Call ShowErrors()

  If SW_lngTotalPage = 1 Then Exit Sub

  SELECT CASE SW_intBDKind
  CASE SW_intShowNoBorder
       Response.Write("<table border=""0"" width=""" & SW_intTBWidth & """ cellspacing=""0"" cellpadding=""0"" bgcolor=""" & SW_strBDColor & """ align=""center"">" & vbcrlf)
     CASE SW_intShowBigBorder
       Response.Write("<table border=""1"" width=""" & SW_intTBWidth & """ cellspacing=""0"" cellpadding=""0"" bgcolor=""" & SW_strBDColor & """ align=""center"">" & vbcrlf)
     CASE SW_intShowSmallBorder
       Response.Write("<table border=""0"" width=""" & SW_intTBWidth & """ cellspacing=""1"" cellpadding=""0"" bgcolor=""" & SW_strBDColor & """ align=""center"">" & vbcrlf)
     End SELECT

     Response.Write(" <tr bgcolor=""" & SW_strBGColor & """>" & vbcrlf)
     Response.Write("  <td>" & vbcrlf)
     Response.Write("   <table width=""100%"">" & vbcrlf)
     Response.Write("     <tr>" & vbcrlf & "      <td align=""center"" valign=""middle"">" & vbcrlf)
  If SW_lngTotalPage >= 1 Then
       SELECT CASE SW_lngShowPageType
       Case SW_intShowChinese
         If SW_lngPageNo <= 1 Then
           Response.Write ("<font color=""" & SW_strFTColor & """>首页 前页 <a href=""" & SW_strURL & SW_lngPageNo+1 & """>后页</a> <a href=""" & SW_strURL & SW_lngTotalPage & """>末页</a>" & vbcrlf)
       Else
        If SW_lngPageNo >= SW_lngTotalPage Then
             Response.Write ("<font color=""" & SW_strFTColor & """><a href=""" & SW_strURL & "1"">首页</a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """>前页</a> " & "后页 末页" & vbcrlf)
           Else
             Response.Write ("<font color=""" & SW_strFTColor & """><a href=""" & SW_strURL & "1"">首页</a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """>前页</a> " & "<a href=""" & SW_strURL & SW_lngPageNo+1 & """>后页</a> <a href=""" & SW_strURL & SW_lngTotalPage & """>末页</a>" & vbcrlf)
         End If
       End If
       Response.Write (" 页次:<b>" & SW_lngPageNo & "</b>/" & SW_lngTotalPage & "页 共<b>" & SW_lngTotalRecord & "</b>条记录 <b>" & SW_intPageSize & "</b>条/页</td>" & vbcrlf)
         Response.Write("   <form name=""gopage"" action=""" & SW_strFormAction & """ method=""post"">" & vbcrlf)
         Response.Write("   <td> 第")
    Response.Write("  <input type=""text"" name=""pageno"" size=""3"" class=""" & SW_strTXTClass & """ maxlength=4 title=""请输入页号,然后回车"">页 " & vbcrlf)
         Response.Write("<input type=""submit"" value=""GO"" class=""" & SW_strBTNClass & """></td></form></font>" & vbcrlf)
       Case SW_intShowEnglish
         If SW_lngPageNo <= 1 Then
           Response.Write ("<font color=""" & SW_strFTColor & """>First Prev <a href=""" & SW_strURL & SW_lngPageNo+1 & """>Next</a> <a href=""" & SW_strURL & SW_lngTotalPage & """>Last</a>" & vbcrlf)
       Else
        If SW_lngPageNo >= SW_lngTotalPage Then
             Response.Write ("<font color=""" & SW_strFTColor & """><a href=""" & SW_strURL & "1"">First</a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """>Prev</a> " & "Next Last" & vbcrlf)
           Else
             Response.Write ("<font color=""" & SW_strFTColor & """><a href=""" & SW_strURL & "1"">First</a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """>Prev</a> " & "<a href=""" & SW_strURL & SW_lngPageNo+1 & """>Next</a> <a href=""" & SW_strURL & SW_lngTotalPage & """>Last</a>" & vbcrlf)
         End If
       End If
       Response.Write (" Page No:<b>" & SW_lngPageNo & "</b>/" & SW_lngTotalPage & " Total Records:<b>" & SW_lngTotalRecord & "</b> PageSize:<b>" & SW_intPageSize & "</b></td>" & vbcrlf)
         Response.Write("   <form name=""gopage"" action=""" & SW_strFormAction & """ method=""post"">" & vbcrlf)
         Response.Write("   <td> ")
    Response.Write("  <input type=""text"" name=""pageno"" size=""3"" class=""" & SW_strTXTClass & """ maxlength=4 title=""Please input pageno then enter""> " & vbcrlf)
         Response.Write("<input type=""submit"" value=""GO"" class=""" & SW_strBTNClass & """></td></form></font>" & vbcrlf)
       Case SW_intShowCharacter
         strPages = ""
         intTemp = (SW_lngPageNo  SW_intShowPages) * SW_intShowPages
   For k = 1 To SW_intShowPages
           intTemp1 = intTemp + k

   If intTemp1 > SW_lngTotalPage Then Exit For
   If SW_lngPageNo = intTemp1 Then
             If Len(Trim(CStr(intTemp1)))<2 Then
               strPages = strPages & " 0" & CStr(intTemp1)
             Else
               strPages = strPages & " " & CStr(intTemp1)
             End If
          Else
     strPages = strPages & " <a href=""" & SW_strURL & CStr(intTemp1) & """>"
             If Len(Trim(CStr(intTemp1)))<2 Then
               strPages = strPages & "0" & CStr(intTemp1)
             Else
               strPages = strPages & CStr(intTemp1)
             End If
             strPages = strPages & "</a>"
   End If
   Next
         If SW_lngPageNo <= 1 Then
           Response.Write ("<font face=""Webdings"">9 7</font>" & strPages & " <a href=""" & SW_strURL & SW_lngPageNo+1 & """><font face=""Webdings"">8</font></a> <a href=""" & SW_strURL & SW_lngTotalPage & """><font face=""Webdings"">:</font></a>" & vbcrlf)
       Else
        If SW_lngPageNo >= SW_lngTotalPage Then
             Response.Write ("<a href=""" & SW_strURL & "1""><font face=""Webdings"">9</font></a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """><font face=""Webdings"">7</font></a>" & strPages & " <font face=""Webdings"">8 :</font>" & vbcrlf)
           Else
             Response.Write ("<font ><a href=""" & SW_strURL & "1""><font face=""Webdings"">9</font></a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """><font face=""Webdings"">7</font></a> " & strPages & " <a href=""" & SW_strURL & SW_lngPageNo+1 & """><font face=""Webdings"">8</font></a> <a href=""" & SW_strURL & SW_lngTotalPage & """><font face=""Webdings"">:</font></a>" & vbcrlf)
         End If
       End If

   Response.Write ("</td>" & vbcrlf)
         Response.Write("   <form name=""gopage"" action=""" & SW_strFormAction & """ method=""post"">" & vbcrlf)
         Response.Write("   <td> ")
    Response.Write("  <input type=""text"" name=""pageno"" size=""3"" class=""" & SW_strTXTClass & """ maxlength=10 title=""Please input pageno then enter""> " & vbcrlf)
         Response.Write("<input type=""submit"" value=""GO"" class=""" & SW_strBTNClass & """></td></form></font>" & vbcrlf)
       Case SW_intShowImage
       Case Else
         Response.Write("<br>对不起,你设置的显示方式SWPage不支持。")
         Response.End
  End Select
  End If
     Response.Write("   </table>" & vbcrlf)
     Response.Write("  </td>" & vbcrlf)
     Response.Write(" </tr>" & vbcrlf)
     Response.Write("</table>" & vbcrlf)
   End Sub

   Sub ShowData()
     Dim i,j

  If Not(SW_blnInit) Then Call ShowError()

  j = 0
  If SW_objRS.Eof And SW_objRS.Bof Then
      Response.Write("库中无任何记录<br>")
      Response.End
  Else
       '空行
    Response.Write("<table><tr><td height=""5""></td></tr></table>" & vbcrlf)

  SELECT CASE SW_lngShowType
       Case SW_intHorizontalView '横排
    Do While (Not SW_objRS.Eof AND j<SW_intPageSize)
      Response.Write(" <table border=""0"" Cellpadding=""0"" cellspacing=""1"" bgcolor=""#000000"" width=""" & SW_strShowWidth & """ align=""center"">" & vbcrlf)
           For i = LBound(SW_aryFldName) To UBound(SW_aryFldName)
     Response.Write("  <tr bgcolor=""#FFFFFF"" height=""28"">" & vbcrlf)
             Response.Write("   <td bgcolor=""" & SW_strTleBGColor & """ width=""" & SW_strTleWidth & """ align=""center"">" & vbcrlf & "&nbsp;")
             If (IsArray(SW_aryFldNote)) Then
               Response.Write("<font color=""" & SW_strTleFTColor & """>" & SW_aryFldNote(i) & "</font>" & vbcrlf)
             Else
               Response.Write("<font color=""" & SW_strTleFTColor & """>" & SW_aryFldName(i) & "</font>" & vbcrlf)
    End If

    Response.Write("   </td>" & vbcrlf & "   <td")

    If (IsArray(SW_aryFldWidth)) Then Response.Write(" width=""" & SW_aryFldWidth(i) & """")

             If (IsArray(SW_aryFldAlign)) Then Response.Write(" align=""" & SW_aryFldAlign(i) & """")

    Response.Write(">" & vbcrlf)

    Response.Write(SW_objRS(SW_aryFldName(i)) & "</td>" & vbcrlf)

    Response.Write("  </tr>" & vbcrlf)
           Next
   Response.Write(" </table>" & vbcrlf)
           '空行
   Response.Write("<table><tr><td height=""5""></td></tr></table>" & vbcrlf)
           SW_objRS.MoveNext
           j = j + 1
   Loop
       CASE SW_intVerticalView '竖排
         Response.Write(" <table border=""0"" Cellpadding=""0"" cellspacing=""1"" bgcolor=""#000000"" width=""" & SW_strShowWidth & """ align=""center"">" & vbcrlf)
         Response.Write("  <tr bgcolor=""" & SW_strTleBGColor & """>" & vbcrlf)
         For i = LBound(SW_aryFldName) To UBound(SW_aryFldName)
           Response.Write("   <td align=""center""")
           If (IsArray(SW_aryFldWidth)) Then Response.Write(" width=""" & SW_aryFldWidth(i) & """>")
           If (IsArray(SW_aryFldNote)) Then
             Response.Write("<font color=""" & SW_strTleFTColor & """>" & SW_aryFldNote(i) & "</font>" & vbcrlf)
           Else
             Response.Write("<font color=""" & SW_strTleFTColor & """>" & SW_aryFldName(i) & "</font>" & vbcrlf)
           End If
           Response.Write("   </td>" & vbcrlf)
         Next
   Response.Write("  </tr>" & vbcrlf)

   Do While (Not SW_objRS.Eof AND j<SW_intPageSize)
           Response.Write("  <tr bgcolor=""" & SW_strBGColor & """ height=""28"">" & vbcrlf)
           For i = LBound(SW_aryFldName) To UBound(SW_aryFldName)
    Response.Write(    "<td")
             If (IsArray(SW_aryFldAlign)) Then Response.Write(" align=""" & SW_aryFldAlign(i) & """>")
             Response.Write(SW_objRS(SW_aryFldName(i)) & "</td>" & vbcrlf)
           Next

   Response.Write("  </tr>" & vbcrlf)
           SW_objRS.MoveNext
           j = j + 1
   Loop
         Response.Write(" </table>" & vbcrlf)
         Response.Write("<table><tr><td height=""5""></td></tr></table>" & vbcrlf)
       CASE ELSE
         Response.Write("<br>你还没设置数据的显示方式?或者你的设置的显示方式SWPage不支持!<br>")
         Response.End
  End SELECT
  End If
   End Sub

 '*****************************************
 ' 类型:  过程
   ' 目的:  显示分页类中出现的错误信息
   ' 输入:  无
   ' 返回:  无
   '*****************************************
 Private Sub ShowErrors()
   If SW_strError <> "" Then
       SW_strError = "<table bgcolor=""#0000"" cellspacing=""1"" cellpadding=""0"" width=""90%"" align=""center"">" & vbcrlf & " <tr bgcolor=""#ff9900"" height=""30""><td align=""center"" valign=""middle""><b>SWPage分页类错误信息<b></td></tr>" & vbcrlf & SW_strError & "</table>" & vbcrlf
       Response.Write(SW_strError)
    Response.End
  End If
 End Sub

   '*****************************************
 ' 类型:  过程
   ' 目的:  释放资源
   ' 输入:  无
   ' 返回:  无
   '*****************************************
   Sub Close()
   Set SW_objRS  = Nothing
  Set SW_objConn = Nothing
   End Sub
 End Class
%>


三、类的应用代码


<!--#include file="inc_clsPages.asp"-->
<%
 Dim clsPage,clsStyle,i,objRS,objConn,strConn,strSQL
 strConn = "Driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.Mappath("pages.mdb")
 Set objConn = CreateObject("Adodb.Connection")
 objConn.Open strConn
 strSQL = "SELECT * FROM classmates"
 
 Set clsStyle = New SWStyle
 clsStyle.TBWidth  = "80%"
 clsStyle.BGColor  = "#FFFFFF"
 clsStyle.BDColor  = "#FF0000"

 'SW_intShowSmallBorder,SW_intShowNoBorder,SW_intShowBigBorder
 clsStyle.BDKind  = SW_intShowSmallBorder
 Set clsStyle = Nothing
 
 Set clsPage = New SWPage

 clsPage.GetConn  = objConn

 clsPage.PageSize  = 1

 clsPage.SQL    = strSQL
 clsPage.URL    = "pages.asp"
 'SW_intShowChinese,SW_intShowEnglish,SW_intShowCharacter,SW_intShowImage
 clsPage.ShowPageType = SW_intShowCharacter

 '此CSS文件必须已存在,请用相对地址表示
 clsPage.CSSFile  = "styles.css"

 clsPage.FldName  = "id,username,birthday" '需要显示的字段名
 clsPage.FldNote  = "编号,姓名,生日"     '相应的中文注释
 clsPage.FldAlign  = "left,center,right"  '显示时的对齐方式
 clsPage.FldWidth  = "30%,30%,30%"     '显示时的对齐方式

 clsPage.TleBGColor = "#FF9966"       '标题栏的背景颜色
 clsPage.TleFTColor = "#336699"       '标题栏的字体颜色
 clsPage.TleWidth  = "15%"         '标题单元格的宽度

 clsPage.ShowType  = SW_intVerticalView 'SW_intHorizontalView:横排,SW_intVerticalView:竖排
 clsPage.ShowWidth = "80%"
 
 clsPage.Init()
 
 clsPage.Pages()
 clsPage.ShowData()

 clsPage.Pages()
 clsPage.Close

 Set clsPage = Nothing

 objConn.Close
 Set objConn = Nothing
%>



四、注意事项

  你可以随意修改、使用此代码,但是当你修改后,希望能给我一份拷贝(sunway8110@126.com)。如在使用中发现有Bug请通知我或帮我改正,需要注意的是本类需要用到FSO,主要是URL属性中用到它。

中查找“ASP通用分页类”更多相关内容

中查找“ASP通用分页类”更多相关内容



上一篇:单元格背景交替实现方法
下一篇:用ASP动态生成JavaScript的表单验证代码
最近更新 赞助商
·实例:ASP与ACCESS链接10-21
·ASP实现SQL语句日期格式的加减运算08-29
·初学ASP编程易犯的一个错误要注意08-29
·配置IIS蜜罐与黑客攻击08-25
·ASP程序中输出Excel文件实例一则08-22
·ASP中文验证码源码提供07-22
·ASP错误解决:800a003a错误04-01
·ASP关于类的Let,Set和Get的用法的异同03-19
·ASP操作XML的类的说明03-11
·asp控制xml数据库的6段代码03-11
·ASP操作XML文件的主要方法和实现03-11

共有评论 0 条 网友评分 0分 查看所有评论


发表评论→ 学而不思则罔,思而不学则殆,请大胆发表你的见解。

输验证码:

您对此篇文章的评分:1分 2分 3分 4分 5分

  • 站内搜索
关键词

搜索方式

搜索范围

精确匹配
Baidu
网站首页 - 关于本站 - 网站地图 - 广告合作 - 站点声明 - RSS订阅 - 联系我们
Copyright © 2005 网海拾贝.[新ICP备05003216号]. All Rights Reserved .