<% 'ASP Recordset 代理类,包含分页 Class TRSProxy Private FRS Private FPageSize,FAbsPage,FPageCount,FRecordCount Private FURL Dim QS_PAGE,QS_FIELD,QS_SORT Dim C_TITLE_IMG,C_TITLE_LINK,C_IMG_ASC,C_IMG_DESC Dim MSG_VOID,MSG_OBJ_ERR,MSG_STATUS_ERR Dim MSG_TOTAL,MSG_FIRST,MSG_LAST,MSG_PAGE,MSG_CUR_PAGE,MSG_SELECT_BEGIN,MSG_SELECT_END,MSG_OPTION Sub class_initialize QS_PAGE = "page" QS_FIELD = "field" QS_SORT = "order" C_TITLE_IMG = "<span class=""{0}""></span>" C_TITLE_LINK = "<a href=""{0}"">{1}</a>" C_IMG_ASC = "asc" C_IMG_DESC = "desc" MSG_OBJ_ERR = "必须传入对象" MSG_STATUS_ERR = "记录集未打开" MSG_TOTAL = vbCrLf & "{0} 条信息 {1}条/页 共 {2} 页" & vbCrLf MSG_FIRST = "<a href=""{0}"" class='page'>最前页</a>" & vbCrLf MSG_LAST = vbCrLf & "<a href=""{0}"" class='page'>最后页</a>" MSG_PAGE = "[<a href=""{0}"" class='page'> {1} </a>] " MSG_CUR_PAGE = "<span class=""bold"">{0}</span> " MSG_SELECT_BEGIN = vbCrLf & "<select onChange=""location.href='{0}' + this.value"">" & vbCrLf MSG_SELECT_END = vbCrLf & "</select>" & vbCrLf MSG_OPTION = "<option value=""{0}""{1}>{0}</option>" FPageSize = 15 FAbsPage = 1 FPageCount = 1 FRecordCount = 1 FURL = getURL() End Sub Sub class_terminate If IsObject(FRS) Then If opened Then FRS.close Set FRS = nothing End if End Sub '-------------------property begin ------------------ Private Property Get opened() If Not IsObject(FRS) Then opened = False Else opened = (FRS.state = 1) End if End Property private Property Let PageSize(ByVal value) If IsNumeric(value) Then If value >= 1 Then FPageSize = CInt(value) End If If opened Then FRS.PageSize = FPageSize End Property private Property Let AbsPage(ByVal value) FAbsPage = getPage(value) If opened Then FRS.absolutepage = FAbsPage End Property Property Set rs(ByRef value) If Not IsObject(value) Then printErr MSG_OBJ_ERR Set FRS = value If Not opened Then printErr MSG_STATUS_ERR If isVoid Then Exit Property '空数据集停止 PageSize = FPageSize '指定页大小 FPageCount = FRS.PageCount FRecordCount = FRS.RecordCount AbsPage = request(QS_PAGE) '指定当前页,不能乱序 End Property '---------------------- page property ------------- Private Property Get Total() Total = sys.format(MSG_TOTAL,Array(FRS.recordcount,FRS.PageSize,FRS.PageCount)) End Property Private Property Get First() Dim url If FAbsPage = 1 Then url = "#" Else url = FURL & "1" End If First = Replace(MSG_FIRST,"{0}",url) End Property Private Property Get Last() Dim url If FAbsPage = FPageCount Then url = "#" Else url = FURL & FPageCount End If Last = Replace(MSG_LAST,"{0}",url) End Property Private Property Get Pages() Dim iBegin,iEnd,i,sPages : sPages = "" iBegin = FAbsPage - 3 If iBegin < 1 Then iBegin = 1 iEnd = FabsPage + 3 If iEnd > FRS.PageCount Then iEnd = FRS.PageCount For i = iBegin To iEnd If i = FabsPage then sPages = sPages & Replace(MSG_CUR_PAGE,"{0}",i) Else sPages = sPages & sys.format(MSG_PAGE,Array(FURL & i,i)) End if Next Pages = sPages End Property Private Property Get Skip() Dim i,selected,sSkip sSkip = Replace(MSG_SELECT_BEGIN,"{0}",FURL) For i = 1 To FRS.pagecount selected = "" : If i = FAbsPage Then selected = " selected" sSkip = sSkip & Replace(Replace(MSG_OPTION,"{0}",i),"{1}",selected) Next sSkip = sSkip & MSG_SELECT_END Skip = sSkip End Property '============================= property end ======================== '---------------- paging ----------------- Sub Paging() sys.print Total sys.print First sys.print Pages sys.print Last sys.print Skip End Sub Function getPaging() getPaging = Total & First & Pages & Last & Skip End Function Private Sub printErr(msg) sys.print msg sys.halt End Sub Private Function getURL() Dim sURL,sQuery,item sURL = sys.getVar("PATH_INFO") sQuery = "" For Each item In Request.QueryString '可剔除多个page参数 If item <> QS_PAGE Then sQuery = sQuery & item & "=" & request(item) & "&" End If Next sURL = sURL & "?" & sQuery & QS_PAGE & "=" '刚刚好达到想要的效果 getURL = sURL End Function Function isVoid() Dim b b = (FRS.eof And FRS.bof) isVoid = b End function '验证传入的page值,需要赋FPageCount后调用 Function getPage(value) getPage = 1 If IsNumeric(value) Then If CInt(value) > 1 And CInt(value) <= FPageCount Then getPage = CInt(value) End if End Function '数据集显示标题 Function getHeader(aTitle,aField) Dim sImg,sQuery,sURL,sSort,item sSort = request(QS_SORT) If request(QS_FIELD) = aField Then If sSort = "asc" Or sSort = "" Then sImg = C_IMG_ASC sSort = "desc" Else sImg = C_IMG_DESC sSort = "asc" End If sImg = Replace(C_TITLE_IMG,"{0}",sImg) End if ' 获取并修正链接的地址 sQuery = "" For Each item In Request.QueryString If item <> QS_PAGE And item <> QS_FIELD And item <> QS_SORT Then ' 剔除这3个参数 sQuery = sQuery & item & "=" & Request(item) & "&" End If Next sURL = "?{0}{1}={2}&{3}={4}" sURL = sys.format(sURL,Array(sQuery,QS_FIELD,aField,QS_SORT,sSort)) getHeader = sys.format(C_TITLE_LINK,Array(sURL,aTitle & sImg)) End Function End class %>