分页类,异常类

时间:2021-05-25

其它的一些,比如分页类,异常类(用于信息提示),文件操作类(未完成),经常用到的工具类及验证输入的表单验证类(ASP版,配合前台JS版使用更佳):
分页类Pager
<%
ClassPagerPrivateIUrl
PrivateIPage
PrivateIParam
PrivateIPageSize
PrivateIPageCount
PrivateIRecordCount
PrivateICurrentPageIndexPublicPropertyLetUrl(ByValPUrl)
IUrl=PUrl
EndPropertyPublicPropertyGetUrl()
IfIUrl=""Then
IfRequest.QueryString<>""Then
Dimquery
ForEachkeyInRequest.QueryString
Ifkey<>ParamThen
query=query&key&"="&Server.UrlEnCode(Request.QueryString(key))&"&"
EndIf
Next
IUrl=Page&"?"&query&Param&"="
Else
IUrl=Page&"?"&Param&"="
EndIf
EndIf
Url=IUrl
EndPropertyPublicPropertyLetPage(ByValPPage)
IPage=PPage
EndPropertyPublicPropertyGetPage()
Page=IPage
EndPropertyPublicPropertyLetParam(ByValPParam)
IParam=PParam
EndPropertyPublicPropertyGetParam()
Param=IParam
EndPropertyPublicPropertyLetPageSize(ByValPPageSize)
IPageSize=PPageSize
EndPropertyPublicPropertyGetPageSize()
PageSize=IPageSize
EndPropertyPublicPropertyGetPageCount()
If(NotIPageCount>0)Then
IPageCount=IRecordCount\IPageSize
If(IRecordCountMODIPageSize)>0OrIRecordCount=0Then
IPageCount=IPageCount+1
EndIf
EndIf
PageCount=IPageCount
EndPropertyPublicPropertyLetRecordCount(ByValPRecordCount)
IRecordCount=PRecordCount
EndPropertyPublicPropertyGetRecordCount()
RecordCount=IRecordCount
EndPropertyPublicPropertyLetCurrentPageIndex(ByValPCurrentPageIndex)
ICurrentPageIndex=PCurrentPageIndex
EndPropertyPublicPropertyGetCurrentPageIndex()
IfICurrentPageIndex=""Then
IfRequest.QueryString(Param)=""Then
ICurrentPageIndex=1
Else
IfIsNumeric(Request.QueryString(Param))Then
ICurrentPageIndex=CInt(Request.QueryString(Param))
IfICurrentPageIndex<1ThenICurrentPageIndex=1
IfICurrentPageIndex>PageCountThenICurrentPageIndex=PageCount
ElseICurrentPageIndex=1
EndIf
EndIf
EndIf
CurrentPageIndex=ICurrentPageIndex
EndPropertyPrivateSubClass_Initialize()
WithMe
.Param="page"
.PageSize=10
EndWith
EndSubPrivateSubClass_Terminate()
EndSubPrivateFunctionNavigation()
DimNav
IfCurrentPageIndex=1Then
Nav=Nav&"首页上页"
Else
Nav=Nav&"<ahref="""&Url&"1"">首页</a><ahref="""&Url&(CurrentPageIndex-1)&""">上页</a>"
EndIfIfCurrentPageIndex=PageCountOrPageCount=0Then
Nav=Nav&"下页尾页"
Else
Nav=Nav&"<ahref="""&Url&(CurrentPageIndex+1)&""">下页</a><ahref="""&Url&PageCount&""">尾页</a>"
EndIfNavigation=Nav
EndFunctionPrivateFunctionSelectMenu()
DimSelector
Dimi:i=1
Whilei<=PageCount
Ifi=ICurrentPageIndexThen
Selector=Selector&"<optionvalue="""&i&"""selected=""true"">"&i&"</option>"&vbCrLf
Else
Selector=Selector&"<optionvalue="""&i&""">"&i&"</option>"&vbCrLf
EndIf
i=i+1
Wend
SelectMenu=vbCrLf&"<selectstyle=""font:9pxTahoma""onchange=""location='"&Url&"'+this.value"">"&vbCrLf&Selector&vbCrLf&"</select>"&vbCrLf
EndFunctionPublicSubDisplay()
IfRecordCount>0Then
%>
<style>b{font:bold}</style>
<divstyle="text-align:right;width:100%">>>分页<%=Navigation()%>页次:<b><%=ICurrentPageIndex%></b>/<b><%=PageCount%></b>页<b><%=PageSize%></b>个记录/页转到<%=SelectMenu()%>页共<b><%=IRecordCount%></b>条记录</div>
<%
Else
Response.Write("<divstyle=""text-align:center"">暂无记录</div>")
EndIf
EndSubEndClass
%>异常类Exception:
<%
ClassException
PrivateIWindow
PrivateITarget
PrivateITimeOut
PrivateIMode
PrivateIMessage
PrivateIHasError
PrivateIRedirectPublicPropertyLetWindow(ByValValue)
IWindow=Value
EndProperty
PublicPropertyGetWindow()
Window=IWindow
EndPropertyPublicPropertyLetTarget(ByValValue)
ITarget=Value
EndProperty
PublicPropertyGetTarget()
Target=ITarget
EndPropertyPublicPropertyLetTimeOut(ByValValue)
IfIsNumeric(Value)Then
ITimeOut=CInt(Value)
Else
ITimeOut=3000
EndIf
EndProperty
PublicPropertyGetTimeOut()
TimeOut=ITimeOut
EndPropertyPublicPropertyLetMode(ByValValue)
IfIsNumeric(Value)Then
IMode=CInt(Mode)
Else
IMode=1
EndIf
EndProperty
PublicPropertyGetMode()
Mode=IMode
EndPropertyPublicPropertyLetMessage(ByValValue)
IfIHasErrorThen
IMessage=IMessage&"<li>"&Value&"</li>"&vbCrLf
Else
IHasError=True
IMessage="<li>"&Value&"</li>"&vbCrLf
EndIf
EndProperty
PublicPropertyGetMessage()
Message=IMessage
EndPropertyPublicPropertyLetHasError(ByValValue)
IHasError=CBool(Value)
EndProperty
PublicPropertyGetHasError()
HasError=IHasError
EndPropertyPublicPropertyLetRedirect(ByValValue)
IRedirect=CBool(Value)
EndProperty
PublicPropertyGetRedirect()
Redirect=IRedirect
EndPropertyPrivateSubClass_initialize()
WithMe
.Window="self"
.Target=PrePage()
.TimeOut=3000
IMode=1
IMessage="出现错误,正在返回,请稍候..."
.HasError=False
.Redirect=True
EndWith
EndSub

PrivateSubClass_Terminate()
EndSubPublicFunctionPrePage()
IfRequest.ServerVariables("HTTP_REFERER")<>""Then
PrePage=Request.ServerVariables("HTTP_REFERER")
Else
PrePage="/index.asp"
EndIf
EndFunctionPublicFunctionAlert()
Dimwords:words=Me.Message
words=Replace(words,"<li>","\n")
words=Replace(words,"</li>","")
words=Replace(words,vbCrLf,"")
words="提示信息:\t\t\t"&words
%>
<scripttype="text/javascript">
<!--
alert("<%=words%>")
<%=Me.Window%>.location="<%=Me.Target%>"
//-->
</script>
<%
EndFunctionPublicSubThrow()
IfNotHasErrorThenExitSub
Response.Clear()
SelectCaseCInt(Me.Mode)
Case1
%>
<linkhref="/css/admin.css"rel="stylesheet"type="text/css">
<TABLEclass="border-all"cellSpacing="1"cellPadding="5"width="50%"align="center"border="0">
<TBODY>
<TR>
<THheight="21"align="middle"background="images/th_bg.gif"class="title">提示信息</TH>
</TR>
<TR>
<TDalign="center"bgColor="#ffffff"height="40">
<TABLEcellSpacing="0"cellPadding="0"width="95%"border="0">
<TBODY>
<TR>
<TDheight="5"></TD>
</TR>
<TR>
<TD><%=Me.Message%></TD>
</TR>
<TR>
<TD>&nbsp;</TD>
</TR>
<TR>
<TDalign="center"><ahref="javascript:history.back()">[返回]</a><ahref="/">[首页]</a></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
<%IfRedirectThen%><scripttype="text/javascript">
<!--
setTimeout("<%=Me.Window%>.location='<%=Me.Target%>'",<%=Me.TimeOut%>)
//-->
</script><%endIf%>
<%
Case2
CallAlert()
CaseElse
Response.WriteMessage
EndSelect
Response.End()
EndSub
EndClass
%>文件操作类File:
<%
ClassFilePrivateFSO
PrivateIPath
PrivateIContentPublicPropertyLetPath(ByValPPath)
IPath=PPath
EndPropertyPublicPropertyGetPath()
Path=IPath
EndPropertyPublicPropertyLetContent(ByValPContent)
IContent=PContent
EndPropertyPublicPropertyGetContent()
Content=IContent
EndPropertyPrivateSubClass_Initialize()
SetFSO=Server.CreateObject("Scripting.FileSystemObject")
EndSubPrivateSubClass_Terminate()
SetFSO=Nothing
EndSubPublicSubSave()
Dimf
Setf=FSO.OpenTextFile(Server.MapPath(Path),2,true)
f.WriteContent
EndSubEndClass
%>
常用的工具类Utility:
<%
ClassUtilityPrivateRegPublicFunctionHTMLEncode(Str)
IfIsNull(Str)OrIsEmpty(Str)OrStr=""Then
HTMLEncode=""
Else
DimS:S=Str
S=Replace(S,"<","&lt;")
S=Replace(S,">","&gt;")
S=Replace(S,"","&nbsp;")
S=Replace(S,vbCrLf,"<br/>")
HTMLEncode=S
EndIf
EndFunctionPublicFunctionHtmlFilter(ByValCode)
IfIsNull(Code)OrIsEmpty(Code)ThenExitFunction
WithReg
.Global=True
.Pattern="<[^>]+?>"
EndWith
Code=Reg.Replace(Code,"")
HtmlFilter=Code
EndFunctionPublicFunctionLimit(ByValStr,ByValNum)
DimStrLen:StrLen=Len(Str)
IfStrLen*2<=NumThen
Limit=Str
Else
DimStrRlen
CallRlen(Str,StrRlen)
IfStrRlen<=NumThen
Limit=Str
Else
Dimi
DimreStr
IfStrLen>Num*2Then
i=Num\2
reStr=Left(Str,i)
CallRlen(reStr,StrRlen)
WhileStrRlen<Num
i=i+1
reStr=Left(Str,i)
CallRlen(reStr,StrRlen)
Wend
Else
i=StrLen
reStr=Str
CallRlen(reStr,StrRlen)
WhileStrRlen>Num
i=i-1
reStr=Left(Str,i)
CallRlen(reStr,StrRlen)
Wend
EndIf
CallRlen(Right(reStr,1),StrRlen)
IfStrRlen>1Then
Limit=Left(reStr,i-1)&"…"
Else
Limit=Left(reStr,i-2)&"…"
EndIf
EndIf
EndIf
EndFunctionPublicFunctionEncode(ByValStr)
Str=Replace(Str,"""","&#34;")
Str=Replace(Str,"'","&#39;")
Encode=Str
EndFunctionPublicFunctionEncodeAll(ByValStr)
DimM,MS
Reg.Pattern="[\x00-\xFF]"
SetMS=Reg.Execute(Str)
ForEachMInMS
Str=Replace(Str,M.Value,"&#"&Asc(M.Value)&";")
Next
EncodeAll=Str
EndFunction

PrivateSubClass_initialize()
SetReg=NewRegExp
Reg.Global=True
EndSub
PrivateSubClass_Terminate()
SetReg=Nothing
EndSubPublicSubRlen(ByRefStr,ByRefRl)
WithReg
.Pattern="[^\x00-\xFF]"
Rl=Len(.Replace(Str,".."))
EndWith
EndSubEndClass
%>
<%
DimUtil:SetUtil=NewUtility
%>输入验证类Validator:
<%@Language="VBScript"CodePage="936"%>
<%
'OptionExplicit
ClassValidator
'*************************************************
'ValidatorforASPbeta3服务器端脚本
'codeby我佛山人
'wfsr@cunite.com
'*************************************************
PrivateRe
PrivateICodeName
PrivateICodeSessionNamePublicPropertyLetCodeName(ByValPCodeName)
ICodeName=PCodeName
EndPropertyPublicPropertyGetCodeName()
CodeName=ICodeName
EndPropertyPublicPropertyLetCodeSessionName(ByValPCodeSessionName)
ICodeSessionName=PCodeSessionName
EndPropertyPublicPropertyGetCodeSessionName()
CodeSessionName=ICodeSessionName
EndPropertyPrivateSubClass_Initialize()
SetRe=NewRegExp
Re.IgnoreCase=True
Re.Global=True
Me.CodeName="vCode"
Me.CodeSessionName="vCode"
EndSubPrivateSubClass_Terminate()
SetRe=Nothing
EndSubPublicFunctionIsEmail(ByValStr)
IsEmail=Test("^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$",Str)
EndFunctionPublicFunctionIsUrl(ByValStr)
IsUrl=Test("^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>""])*$",Str)
EndFunctionPublicFunctionIsNum(ByValStr)
IsNum=Test("^\d+$",Str)
EndFunctionPublicFunctionIsQQ(ByValStr)
IsQQ=Test("^[1-9]\d{4,8}$",Str)
EndFunctionPublicFunctionIsZip(ByValStr)
IsZip=Test("^[1-9]\d{5}$",Str)
EndFunctionPublicFunctionIsIdCard(ByValStr)
IsIdCard=Test("^\d{15}(\d{2}[A-Za-z0-9])?$",Str)
EndFunctionPublicFunctionIsChinese(ByValStr)
IsChinese=Test("^[\u0391-\uFFE5]+$",Str)
EndFunctionPublicFunctionIsEnglish(ByValStr)
IsEnglish=Test("^[A-Za-z]+$",Str)
EndFunctionPublicFunctionIsMobile(ByValStr)
IsMobile=Test("^((\(\d{3}\))|(\d{3}\-))?13\d{9}$",Str)
EndFunctionPublicFunctionIsPhone(ByValStr)
IsPhone=Test("^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$",Str)
EndFunctionPublicFunctionIsSafe(ByValStr)
IsSafe=(Test("^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\""]*)|.{0,5})$|\s",Str)=False)
EndFunctionPublicFunctionIsNotEmpty(ByValStr)
IsNotEmpty=LenB(Str)>0
EndFunctionPublicFunctionIsDateFormat(ByValStr,ByValFormat)
IFNotIsDate(Str)Then
IsDateFormat=False
ExitFunction
EndIFIFFormat="YMD"Then
IsDateFormat=Test("^((\d{4})|(\d{2}))([-./])(\d{1,2})\4(\d{1,2})$",Str)
Else
IsDateFormat=Test("^(\d{1,2})([-./])(\d{1,2})\\2((\d{4})|(\d{2}))$",Str)
EndIF
EndFunctionPublicFunctionIsEqual(ByValSrc,ByValTar)
IsEqual=(Src=Tar)
EndFunctionPublicFunctionCompare(ByValOp1,ByValOperator,ByValOp2)
Compare=False
IFDic.Exists(Operator)Then
Compare=Eval(Dic.Item(Operator))
ElseifIsNotEmpty(Op1)Then
Compare=Eval(Op1&Operator&Op2)
EndIF
EndFunctionPublicFunctionRange(ByValSrc,ByValMin,ByValMax)
Min=CInt(Min):Max=CInt(Max)
Range=(Min<SrcAndSrc<Max)
EndFunctionPublicFunctionGroup(ByValSrc,ByValMin,ByValMax)
Min=CInt(Min):Max=CInt(Max)
DimNum:Num=UBound(Split(Src,","))+1
Group=Range(Num,Min-1,Max+1)
EndFunctionPublicFunctionCustom(ByValStr,ByValReg)
Custom=Test(Reg,Str)
EndFunctionPublicFunctionLimit(ByValStr,ByValMin,ByValMax)
Min=CInt(Min):Max=CInt(Max)
DimL:L=Len(Str)
Limit=(Min<=LAndL<=Max)
EndFunctionPublicFunctionLimitB(ByValStr,ByValMin,ByValMax)
Min=CInt(Min):Max=CInt(Max)
DimL:L=bLen(Str)
LimitB=(Min<=LAndL<=Max)
EndFunctionPrivateFunctionTest(ByValPattern,ByValStr)
IfIsNull(Str)OrIsEmpty(Str)Then
Test=False
Else
Re.Pattern=Pattern
Test=Re.Test(CStr(Str))
EndIf
EndFunctionPublicFunctionbLen(ByValStr)
bLen=Len(Replace(Str,"[^\x00-\xFF]",".."))
EndFunctionPrivateFunctionReplace(ByValStr,ByValPattern,ByValReStr)
Re.Pattern=Pattern
Replace=Re.Replace(Str,ReStr)
EndFunctionPrivateFunctionB2S(ByValiStr)
DimreVal:reVal=""
Dimi,Code,nCode
Fori=1toLenB(iStr)
Code=AscB(MidB(iStr,i,1))
IFCode<&h80Then
reVal=reVal&Chr(Code)
Else
nCode=AscB(MidB(iStr,i+1,1))
reVal=reVal&Chr(CLng(Code)*&h100+CInt(nCode))
i=i+1
EndIF
Next
B2S=reVal
EndFunctionPublicFunctionSafeStr(ByValName)
IfIsNull(Name)OrIsEmpty(Name)Then
SafeStr=False
Else
SafeStr=Replace(Trim(Name),"(\s*and\s*\w*=\w*)|['%&<>=]","")
EndIf
EndFunctionPublicFunctionSafeNo(ByValName)
IfIsNull(Name)OrIsEmpty(Name)Then
SafeNo=0
Else
SafeNo=(Replace(Trim(Name),"^[\D]*(\d+)[\D\d]*$","$1"))
EndIf
EndFunctionPublicFunctionIsValidCode()
IsValidCode=((Request.Form(Me.CodeName)=Session(Me.CodeSessionName))ANDSession(Me.CodeSessionName)<>"")
EndFunctionPublicFunctionIsValidPost()
DimUrl1:Url1=Cstr(Request.ServerVariables("HTTP_REFERER"))
DimUrl2:Url2=Cstr(Request.ServerVariables("SERVER_NAME"))
IsValidPost=(Mid(Url1,8,Len(Url2))=Url2)
EndFunctionEndClass
%>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章