Universal Data Page Class

xiaoxiao2021-03-06  42

Source: Unknown Author: Unknown Recommended rating: Visits: 16

Universal Page Class, easy to write to display data in later ways. Call this class directly, then you can get all the data on the current page. The job made is only the data of the current page, and the total number of pages And total record number, etc. ASP code: <% '/ **************************** Biographic display class *** ************************************************************ '/ * author: wah-wah fish' / * date: November 18, 2004 '/ * role: to obtain a page Data and return to external '/ * description example:' / * DIM mypage = new pageclass '/ * mypage.conn = conn' Settings connection object '/ * mypage.pagesize = 20' Setting up a page display How to display how many data (default Ten) '/ * mypage.curbage = 2' Set the page number current to display '/ *' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' / * Mypage.tablename = "MEMBER" set Table name '/ * mypage.fields = "id, membername, memberpass" set display field list' / * mypage.condition = "id> 100" set query criteria '/ * mypage.orderby = "ID DESC" setting Sorting Conditions (Be sure to set this property) '/ * set pagers = mypage.execute' Returns the data of the current page 2 (Recordset object), returning the nothing value '/ *' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' The definition of '' '' '' '' / * 'can also use the following methods: Executeby ("Table Name", "Field List", Query Conditions, "Sort Condition"' / * Set Pagers = MyPage. Executeby ("MEMBER", "ID, Membername, Memberpass", "ID> 100", "ID DESC") '/ *' '' '

'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' / * Pagecount = mypage.pagecount 'Return Page Total' / * RecordCount = MyPage.RecordCount 'Return Record Total' / * NextPage = MyPage.NextPage 'Return to the page page number' / * Prepage = mypage.prepage 'Returns the page number of the previous page' / ****************************************** ****************************** Class PageClass Private Connection 'Connecting Database External Connection Object Private Rs Private List_fields Private Table_name Private Query_where PRIVATE ORDERBY_SQL 'Field Sort Statement Page PRIVATE Page_Count' Returns the current query record page Total number PRIVATE PAGE_SIZE 'Setting up the number of records of the number of records private cur_page' Set the current page number private record_count 'Return the current query record total number' / **** ************ Sets the connection object ************************************* Public property let conn (byref objconn) ) SET Connection = Objconn End Property Public Property Get CONN () SET CONN = Connection End Property '/ ************** * ******* * ******* * ******* * ********************************************** Settings query SQL statement *********************************** The query display field public property letfilds (byval value) list_fields = value end Property Public Property Get Fields () FI elds = List_Fields End Property '' lookup table name Public Property Let TableName (ByVal Value) Table_Name = Value End Property Public Property Get TableName () TableName = Table_Name End Property '' query Public Property Let Condition (ByVal Value) Query_Where = Value End Property Public Property Get Condition () Condition = query_where End Property ''

**************** Sort part *************************************** ************* '' Value does not need to write on the order by.

Such as: [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 '/ ********* ******* **************************************************** '/ *************** Return to the current number of pages of the current query result ********************************** PUBLIC Property Get PageCount () PageCount = page_Count End Property Public Property Get RecordCount () RecordCount = Record_Count End Property Public Property Get NextPage () If Cur_Page 1 THEN PREPAGE = CUR_PAGE-1 ELSE PREPAGE = CUR_PAGE END IF End Property '/ ************** * ******************* ************************************ Settled one Number of records ************************************* Public property lettsize (byval value) if not isnumeric (value) or value = " "THEN value = 10 else value = cint (value) end if if value <1 Then value = 10 Page_size = value endproperty public property get pagesize () Pagesize () Pagesize () Pagesize () Pagesize () Pagesize () Pages = Value = 10 Page_SIZE = VALUE End Property Public Property Get Pagesize () Ize = Page_Size End Property '' Set the current page number *********************************** PUBLIC Property Let Page (byval value) if not isnumeric Value) or value = "" "" = 1 else value = clng (value) end if if value <1 Then value = 1 cur_page = value endproperty public property get page () Page = cur_page endproperty '/ **** *********** * End *********************************************** ***** Private Sub Class_Initialize 'initialization RecordSet object Page_Size = 10' as a default data 10 CurPage = 1 'as a first current default page Record_Count = 0 page_Count = 0 End Sub Private Sub Class_Terminate Call CloseRecordSet End Sub'

/ *** Close the connection of the database ******* Private subclosecordset on error resume next if isobject (rs) Then Rs.close set = Nothing end if on error goto 0 End Sub '/ ***** ***** Execute the query to return the data of the corresponding page number ******************************************************** ********* 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 'queries and return the current CurPage page number recording 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) 'Get the total number of records if err dam ket execute = Nothing record_count = 0 Page_count = 0 exit function end if if Record_count <1 THEN SET EXECUTE = Nothing Record_ Count = 0 Page_Count = 0 Exit Function End If 'the total number of acquired pages If Record_Count Mod Page_Size <> 0 Then TopMod = Record_Count Mod Page_Size Page_Count = Fix (Record_Count / Page_Size) 1 If Cur_Page page_Count Then Cur_Page = page_Count If Cur_Page <1 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 = order 0 Exit Function End If Set Execute = Rs End Function 'OrderBy conversion of ASC-> DESC DESC-> ASC Private Function TransformOrder (ByVal Value) If Value = "" THEN TRANSFORMORDER = "" EXIT FUNCTION END IF DIM ORDERARRAY, I, RESULT, BYSTRING, FIELDS, INPOS ORDERARRING, FIELDS, INPOS OrderaRray = Split (Value, ",") 'Decomposition Each field value for i = 0 to Ubound (OrderaRray) if Orderay (i <> "" "" "" "" "" "" "" "" "Finding the order of order if INPOS <1 Then 'If not found, the ASC sorted byString =" ASC "fields = Orderay ( I) "" Else Bystring = Trim (MID (OrderaRray (i), INPOS 1)) Fields = Left (Orderarray (I), INPOS) IF BYSTRING <> "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " ASC "end if end if '' conversion sorting IF bystring =" ASC "dam", "Else Bystring =" END IF RESULT = Result Fields Bystring "," end if next if result <> " Then Result = Left (Result, Len (Result) -1) TransformOrder = Result End Function End Class%> Sample Code: 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 = "movie"' mypage.fields = "*" 'mypage.Orderby = "

转载请注明原文地址:https://www.9cbs.com/read-70425.html

New Post(0)