ASP的自定义实用函数表(3)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

ASP的自定义实用函数表(3)2004-9-247:20:00作者:模板天下收集整理来源:未知网友评论0条论坛纯编码实现Access数据库的建立或压缩%'#######以下是一个类文件,下面的注解是调用类的方法################################################'#注意:如果系统不支持建立Scripting.FileSystemObject对象,那么数据库压缩功能将无法使用'#Access数据库类'#CreateDbFile建立一个Access数据库文件'#CompactDatabase压缩一个Access数据库文件'#建立对象方法:'#Seta=NewDatabaseTools'#by(萧寒雪)s.f.'#########################################################################################ClassDatabaseToolsPublicfunctionCreateDBfile(byValdbFileName,byValDbVer,byValSavePath)'建立数据库文件'IfDbVeris0ThenCreateAccess97dbFile'IfDbVeris1ThenCreateAccess2000dbFileOnerrorresumeNextIfRight(SavePath,1)\OrRight(SavePath,1)/ThenSavePath=Trim(SavePath)&\IfLeft(dbFileName,1)=\OrLeft(dbFileName,1)=/ThendbFileName=Trim(Mid(dbFileName,2,Len(dbFileName)))IfDbExists(SavePath&dbFileName)ThenResponse.Write(对不起,该数据库已经存在!)CreateDBfile=FalseElseDimCaSetCa=Server.CreateObject(ADOX.Catalog)IfErr.number0ThenResponse.Write(无法建立,请检查错误信息br&Err.number&br&Err.Description)Err.ClearExitfunctionEndIfIfDbVer=0ThencallCa.Create(Provider=Microsoft.Jet.OLEDB.3.51;DataSource=&SavePath&dbFileName)ElsecallCa.Create(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&SavePath&dbFileName)EndIfSetCa=NothingCreateDBfile=TrueEndIfEndfunctionPublicfunctionCompactDatabase(byValdbFileName,byValDbVer,byValSavePath)'压缩数据库文件'0为access97'1为access2000OnErrorresumenextIfRight(SavePath,1)\OrRight(SavePath,1)/ThenSavePath=Trim(SavePath)&\IfLeft(dbFileName,1)=\OrLeft(dbFileName,1)=/ThendbFileName=Trim(Mid(dbFileName,2,Len(dbFileName)))IfDbExists(SavePath&dbFileName)ThenResponse.Write(对不起,该数据库已经存在!)CompactDatabase=FalseElseDimCdSetCd=Server.CreateObject(JRO.JetEngine)IfErr.number0ThenResponse.Write(无法压缩,请检查错误信息br&Err.number&br&Err.Description)Err.ClearExitfunctionEndIfIfDbVer=0ThencallCd.CompactDatabase(Provider=Microsoft.Jet.OLEDB.3.51;DataSource=&SavePath&dbFileName,Provider=Microsoft.Jet.OLEDB.3.51;DataSource=&SavePath&dbFileName&.bak.mdb;JetOLEDB;EncryptDatabase=True)ElsecallCd.CompactDatabase(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&SavePath&dbFileName,Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&SavePath&dbFileName&.bak.mdb;JetOLEDB;EncryptDatabase=True)EndIf'删除旧的数据库文件callDeleteFile(SavePath&dbFileName)'将压缩后的数据库文件还原callRenameFile(SavePath&dbFileName&.bak.mdb,SavePath&dbFileName)SetCd=FalseCompactDatabase=TrueEndIfendfunctionPublicfunctionDbExists(byValdbPath)'查找数据库文件是否存在OnErrorresumeNextDimcSetc=Server.CreateObject(ADODB.Connection)c.OpenProvider=Microsoft.Jet.OLEDB.4.0;DataSource=&dbPathIfErr.number0ThenErr.ClearDbExists=falseelseDbExists=TrueEndIfsetc=nothingEndfunctionPublicfunctionAppPath()'取当前真实路径AppPath=Server.MapPath(./)EndfunctionPublicfunctionAppName()'取当前程序名称AppName=Mid(Request.ServerVariables(SCRIPT_NAME),(InStrRev(Request.ServerVariables(SCRIPT_NAME),/,-1,1))+1,Len(Request.ServerVariables(SCRIPT_NAME)))EndFunctionPublicfunctionDeleteFile(filespec)'删除一个文件DimfsoSetfso=CreateObject(Scripting.FileSystemObject)IfErr.number0ThenResponse.Write(删除文件发生错误!请查看错误信息br&Err.number&br&Err.Description)Err.ClearDeleteFile=FalseEndIfcallfso.DeleteFile(filespec)Setfso=NothingDeleteFile=TrueEndfunctionPublicfunctionRenameFile(filespec1,filespec2)'修改一个文件DimfsoSetfso=CreateObject(Scripting.FileSystemObject)IfErr.number0ThenResponse.Write(修改文件名时发生错误!请查看错误信息br&Err.number&br&Err.Description)Err.ClearRenameFile=FalseEndIfcallfso.CopyFile(filespec1,filespec2,True)callfso.DeleteFile(filespec1)Setfso=NothingRenameFile=TrueEndfunctionEndClass%----------------------------------------一套加解密字符串的函数%FunctionEncrypt(theNumber)OnErrorResumeNextDimn,szEnc,t,HiN,LoN,in=CDbl((theNumber+1570)^2-7*(theNumber+1570)-450)Ifn0ThenszEnc=RElseszEnc=Jn=CStr(abs(n))Fori=1ToLen(n)step2t=Mid(n,i,2)IfLen(t)=1ThenszEnc=szEnc&tExitForEndIfHiN=(CInt(t)And240)/16LoN=CInt(t)And15szEnc=szEnc&Chr(Asc(M)+HiN)&Chr(Asc(C)+LoN)NextEncrypt=szEncEndFunctionFunctionDecrypt(theNumber)OnErrorResumeNextDime,n,sign,t,HiN,LoN,NewN,ie=theNumberIfLeft(e,1)=RThensign=-1Elsesign=1e=Mid(e,2)NewN=Fori=1ToLen(e)step2t=Mid(e,i,2)IfAsc(t)=Asc(0)AndAsc(t)=Asc(9)ThenNewN=NewN&tExitForEndIfHiN=Mid(t,1,1)LoN=Mid(t,2,1)HiN=(Asc(HiN)-Asc(M))*16LoN=Asc(LoN)-Asc(C)t=CStr(HiNOrLoN)IfLen(t)=1Thent=0&tNewN=NewN&tNexte=CDbl(NewN)*signDecrypt=CLng((7+sqr(49-4*(-450-e)))/2-1570)EndFunction%htmlbodyOriginalnumber:69brEncrypt(69)returns:JNMQMOJ8brDecrypt(JNMQMOJ8)returns:69pAnotherexampleusingvariablesinstead:brEncrypt(Request.Form(ID))brEncrypt(myVar)brDecrypt(Request.QueryString(id))brDecrypt(JNMQMOJ8)brDecrypt(myVar)/body/html-------------------------------------------------在ASP控制数字及字母输入方法一:str=Request(string)temp=Server.URLEncode(str)ifstr=tempthenresponse.write你输入的不是英文或数字endif文法二:str=Request(string)fori=1tolen(str)a=mid(string,i,1)if((asc(a)0andasc(a)9)or(asc(a)asc(a)andasc(a)asc(z)))thenresponse.write你输入的不是英文或数字endifnexti-----------------------------------------------access数据库表改名的一段代码%CallRenameTable(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\example

1 / 20
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功