您现在的位置是:网站首页> 编程资料编程资料

分页类,异常类_ASP CLASS类_

2023-05-25 201人已围观

简介 分页类,异常类_ASP CLASS类_

其它的一些,比如分页类,异常类(用于信息提示),文件操作类(未完成),经常用到的工具类及验证输入的表单验证类(ASP版,配合前台JS版使用更佳):
分页类Pager
<%
Class Pager Private IUrl
Private IPage
Private IParam
Private IPageSize
Private IPageCount
Private IRecordCount
Private ICurrentPageIndex Public Property Let Url(ByVal PUrl)
IUrl = PUrl
End Property Public Property Get Url()
If IUrl = "" Then
If Request.QueryString <> "" Then
Dim query
For Each key In Request.QueryString
If key <> Param Then
query = query & key & "=" & Server.UrlEnCode(Request.QueryString(key)) & "&"
End If
Next
IUrl = Page & "?" & query & Param & "="
Else
IUrl = Page & "?" & Param & "="
End If
End If
Url =IUrl
End Property Public Property Let Page(ByVal PPage)
IPage = PPage
End Property Public Property Get Page()
Page = IPage
End Property Public Property Let Param(ByVal PParam)
IParam = PParam
End Property Public Property Get Param()
Param = IParam
End Property Public Property Let PageSize(ByVal PPageSize)
IPageSize = PPageSize
End Property Public Property Get PageSize()
PageSize = IPageSize
End Property Public Property Get PageCount()
If (Not IPageCount > 0) Then
IPageCount = IRecordCount \ IPageSize
If (IRecordCount MOD IPageSize) > 0 Or IRecordCount = 0 Then 
IPageCount = IPageCount + 1
End If
End If
PageCount = IPageCount
End Property Public Property Let RecordCount(ByVal PRecordCount)
IRecordCount = PRecordCount
End Property Public Property Get RecordCount()
RecordCount = IRecordCount
End Property Public Property Let CurrentPageIndex(ByVal PCurrentPageIndex)
ICurrentPageIndex = PCurrentPageIndex
End Property Public Property Get CurrentPageIndex()
If ICurrentPageIndex = "" Then
If Request.QueryString(Param) = "" Then
ICurrentPageIndex = 1
Else
If IsNumeric(Request.QueryString(Param)) Then
ICurrentPageIndex = CInt(Request.QueryString(Param))
If ICurrentPageIndex < 1 Then ICurrentPageIndex = 1
If ICurrentPageIndex > PageCount Then ICurrentPageIndex = PageCount
Else ICurrentPageIndex = 1
End If
End If
End If
CurrentPageIndex = ICurrentPageIndex
End Property Private Sub Class_Initialize()
With Me
.Param = "page"
.PageSize = 10
End With
End Sub Private Sub Class_Terminate()
End Sub Private Function Navigation()
Dim Nav
If CurrentPageIndex = 1 Then
Nav = Nav & " 首页 上页 "
Else
Nav = Nav & " 首页 上页 "
End If If CurrentPageIndex = PageCount Or PageCount = 0 Then
Nav = Nav & " 下页 尾页 "
Else
Nav = Nav & " 下页 尾页 "
End If Navigation = Nav
End Function Private Function SelectMenu()
Dim Selector
Dim i : i = 1
While i <= PageCount
If i = ICurrentPageIndex Then
Selector = Selector & "" & i &"" & vbCrLf 
Else 
Selector = Selector & "" & i &"" & vbCrLf
End If
i = i + 1
Wend
SelectMenu = vbCrLf & "" & vbCrLf & Selector & vbCrLf & "" & vbCrLf
End Function Public Sub Display()
If RecordCount > 0 Then
%>

>>分页 <%=Navigation()%> 页次:<%=ICurrentPageIndex%>/<%=PageCount%>页 <%=PageSize%>个记录/页 转到<%=SelectMenu()%>页 共 <%=IRecordCount%>条记录

<%
Else
Response.Write("暂无记录
")
End If
End Sub End Class
%> 异常类Exception:
<%
Class Exception
Private IWindow
Private ITarget
Private ITimeOut
Private IMode
Private IMessage
Private IHasError
Private IRedirect Public Property Let Window(ByVal Value)
IWindow = Value
End Property
Public Property Get Window()
Window = IWindow
End Property Public Property Let Target(ByVal Value)
ITarget = Value
End Property
Public Property Get Target()
Target = ITarget
End Property Public Property Let TimeOut(ByVal Value)
If IsNumeric(Value) Then
ITimeOut = CInt(Value)
Else
ITimeOut = 3000
End If
End Property
Public Property Get TimeOut()
TimeOut = ITimeOut
End Property Public Property Let Mode(ByVal Value)
If IsNumeric(Value) Then
IMode = CInt(Mode)
Else
IMode = 1
End If
End Property
Public Property Get Mode()
Mode = IMode
End Property Public Property Let Message(ByVal Value)
If IHasError Then
IMessage = IMessage & "
  • " & Value & "
  • " & vbCrLf
    Else
    IHasError = True
    IMessage = "
  • " & Value & "
  • " & vbCrLf
    End If
    End Property
    Public Property Get Message()
    Message = IMessage
    End Property Public Property Let HasError(ByVal Value)
    IHasError = CBool(Value)
    End Property
    Public Property Get HasError()
    HasError = IHasError
    End Property Public Property Let Redirect(ByVal Value)
    IRedirect = CBool(Value)
    End Property
    Public Property Get Redirect()
    Redirect = IRedirect
    End Property Private Sub Class_initialize()
    With Me
    .Window = "self"
    .Target = PrePage()
    .TimeOut = 3000
    IMode = 1
    IMessage = "出现错误,正在返回,请稍候..."
    .HasError = False
    .Redirect = True
    End With
    End Sub 

    Private Sub Class_Terminate()
    End Sub Public Function PrePage()
    If Request.ServerVariables("HTTP_REFERER") <> "" Then
    PrePage = Request.ServerVariables("HTTP_REFERER")
    Else
    PrePage = "/index.asp"
    End If
    End Function Public Function Alert()
    Dim words : words = Me.Message
    words = Replace(words, "
  • ", "\n")
    words = Replace(words, "
  • ", "")
    words = Replace(words, vbCrLf, "")
    words = "提示信息:\t\t\t" & words
    %>



    <%
    End Function Public Sub Throw()
    If Not HasError Then Exit Sub
    Response.Clear()
    Select Case CInt(Me.Mode)
    Case 1
    %>



     
    提示信息

     
     


     


     
    <%=Me.Message%>


     


    [返回] [首页] 







    <% If Redirect Then%> 

    <%end If%>
    <%
    Case 2
    Call Alert()
    Case Else
    Response.Write Message
    End Select
    Response.End()
    End Sub
    End Class
    %> 文件操作类File:
    <%
    Class File Private FSO
    Private IPath
    Private IContent Public Property Let Path(ByVal PPath)
    IPath = PPath
    End Property Public Property Get Path()
    Path = IPath
    End Property Public Property Let Content(ByVal PContent)
    IContent = PContent
    End Property Public Property Get Content()
    Content = IContent
    End Property Private Sub Class_Initialize()
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    End Sub Private Sub Class_Terminate()
    Set FSO = Nothing
    End Sub Public Sub Save()
    Dim f
    Set f = FSO.OpenTextFile(Server.MapPath(Path), 2, true)
    f.Write Content
    End Sub End Class
    %>
    常用的工具类Utility:
    <%
    Class Utility Private Reg Public Function HTMLEncode(Str)
    If IsNull(Str) Or IsEmpty(Str) Or Str = "" Then
    HTMLEncode = ""
    Else
    Dim S : S = Str
    S = Replace(S, "<", "<")
    S = Replace(S, ">", ">")
    S = Replace(S, " ", " ")
    S = Replace(S, vbCrLf, "")
    HTMLEncode = S
    End If
    End Function Public Function HtmlFilter(ByVal Code)
    If IsNull(Code) Or IsEmpty(Code) Then Exit Function
    With Reg
    .Global = True
    .Pattern = "<[^>]+?>"
    End With
    Code = Reg.Replace(Code, "")
    HtmlFilter = Code
    End Function Public Function Limit(ByVal Str, ByVal Num)
    Dim StrLen : StrLen = Len(Str)
    If StrLen * 2 <= Num Then
    Limit = Str
    Else
    Dim StrRlen
    Call Rlen(Str, StrRlen)
    If StrRlen <= Num Then
    Limit = Str
    Else
    Dim i
    Dim reStr
    If StrLen > Num * 2 Then
    i = Num \ 2
    reStr = Left(Str, i)
    Call Rlen(reStr, StrRlen)
    While StrRlen < Num
    i = i + 1
    reStr = Left(Str, i)
    Call Rlen(reStr, StrRlen)
    Wend
    Else
    i = StrLen
    reStr = Str
    Call Rlen(reStr, StrRlen)
    While StrRlen > Num
    i = i - 1
    reStr = Left(Str, i)
    Call Rlen(reStr, StrRlen)
    Wend
    End If
    Call Rlen(Right(reStr, 1), StrRlen)
    If StrRlen > 1 Then
    Limit = Left(reStr, i-1) & "…"
    Else
    Limit = Left(reStr, i-2) & "…"
    End If
    End If
    End If
    End Function Public Function Encode(ByVal Str)
    Str = Replace(Str, """", """)
    Str = Replace(Str, "'", "'")
    Encode = Str
    End Function Public Function EncodeAll(ByVal Str)
    Dim M, MS
    Reg.Pattern = "[\x00-\xFF]"
    Set MS = Reg.Execute(Str)
    For Each M In MS
    Str = Replace(Str, M.Value, "&#" & Asc(M.Value) & ";")
    Next
    EncodeAll = Str
    End Function

    Private Sub Class_initialize()
    Set Reg = New RegExp
    Reg.Global = True
    End Sub
    Private Sub Class_Terminate()
    Set Reg = Nothing
    End Sub Public Sub Rlen(ByRef Str, ByRef Rl)
    With Reg
    .Pattern = "[^\x00-\xFF]"
    Rl = Len(.Replace(Str

    相关内容

    -六神源码网