ASP常用的几个功能模块.docx

上传人:b****1 文档编号:2850947 上传时间:2023-05-04 格式:DOCX 页数:31 大小:25.02KB
下载 相关 举报
ASP常用的几个功能模块.docx_第1页
第1页 / 共31页
ASP常用的几个功能模块.docx_第2页
第2页 / 共31页
ASP常用的几个功能模块.docx_第3页
第3页 / 共31页
ASP常用的几个功能模块.docx_第4页
第4页 / 共31页
ASP常用的几个功能模块.docx_第5页
第5页 / 共31页
ASP常用的几个功能模块.docx_第6页
第6页 / 共31页
ASP常用的几个功能模块.docx_第7页
第7页 / 共31页
ASP常用的几个功能模块.docx_第8页
第8页 / 共31页
ASP常用的几个功能模块.docx_第9页
第9页 / 共31页
ASP常用的几个功能模块.docx_第10页
第10页 / 共31页
ASP常用的几个功能模块.docx_第11页
第11页 / 共31页
ASP常用的几个功能模块.docx_第12页
第12页 / 共31页
ASP常用的几个功能模块.docx_第13页
第13页 / 共31页
ASP常用的几个功能模块.docx_第14页
第14页 / 共31页
ASP常用的几个功能模块.docx_第15页
第15页 / 共31页
ASP常用的几个功能模块.docx_第16页
第16页 / 共31页
ASP常用的几个功能模块.docx_第17页
第17页 / 共31页
ASP常用的几个功能模块.docx_第18页
第18页 / 共31页
ASP常用的几个功能模块.docx_第19页
第19页 / 共31页
ASP常用的几个功能模块.docx_第20页
第20页 / 共31页
亲,该文档总共31页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

ASP常用的几个功能模块.docx

《ASP常用的几个功能模块.docx》由会员分享,可在线阅读,更多相关《ASP常用的几个功能模块.docx(31页珍藏版)》请在冰点文库上搜索。

ASP常用的几个功能模块.docx

ASP常用的几个功能模块

ASP常用的几个功能模块

1,经常写些系统,那么一般都是从登录程序开始,每接一个系统就写一次登录,好麻烦。

干脆直接做个登录验证函数吧,对我来说,大都情况可以胜任了:

[code]

<%

Functionchk_regist(requestname,requestpwd,tablename,namefield,pwdfield,reurl)dimcn_name,cn_pwdcn_name=trim(request.form(""&requestname&""))cn_pwd=trim(request.form(""&requestpwd&""))ifcn_name=""orcn_pwd=""thenresponse.Write("alert(""请将帐号密码填写完整,谢谢合作。

"");history.go(-1)")endifSetrs=server.CreateObject("ADODB.Recordset")sql="Select*from"&tablename&"where"&namefield&"=''''"&cn_name&"''''"rs.opensql,conn,1,1ifrs.eofthenresponse.Write("alert(""没有该会员ID,请确认有没有被申请。

"");history.go(-1)")elseifrs(""&pwdfield&"")=cn_pwdthensession("cn_name")=rs(""&namefield&"")response.Redirect(reurl)elseresponse.Write("alert(""提醒,您的帐号和密码是不吻合。

注意数字和大小写。

"");history.go(-1)")endifendifrs.closeSetrs=NothingEndFunction%>

[code]

参数说明:

chk_regist(requestname,requestpwd,tablename,namefield,pwdfield,reurl)

requestname为接受HTML页中输入名称的INPUT控件名

requestpwd为接受HTML页中输入密码的INPUT控件名

tablename为数据库中保存注册信息的表名

namefield为该信息表中存放用户名称的字段名

pwdfield为该信息表中存放用户密码的字段名

reurl为登录正确后跳转的页

引用示例如下:

<%callchk_regist("b_name","b_pwd","cn_admin","cn_name","cn_pwd","admin.asp")%>

2,经常有可能对某个事物进行当前状态的判断,一般即做一字段(数值类型,默认值为0)

通过对该字段值的修改达到状态切换的效果。

那么,我又做了个函数,让自己轻松轻松。

<%Functionpvouch(tablename,fildname,autoidname,indexid)dimfildvalueSetrs=Server.CreateObject("ADODB.Recordset")sql="Select*from"&tablename&"where"&autoidname&"="&indexidrs.Opensql,conn,2,3fildvalue=rs(""&fildname&"")iffildvalue=0thenfildvalue=1elsefildvalue=0endifrs(""&fildname&"")=fildvaluers.updaters.closeSetrs=NothingEndFunction%>

参数说明:

pvouch(tablename,fildname,autoidname,indexid)

tablename该事物所在数据库中的表名

fildname该事物用以表明状态的字段名(字段类型是数值型)

autoidname在该表中的自动编号名

indexid用以修改状态的对应自动编号的值

引用示例如下:

<%dowhat=request.QueryString("dowhat")p_id=cint(request.QueryString("p_id"))ifdowhat="tj"andp_id<>""thencallpvouch("cn_products","p_vouch","p_id",p_id)endif%><%ifrs("p_vouch")=0then%>>推荐<%else%>>取消推荐<%endif%>

3,为很多中小企业写站点,一般产品展示是个大项目,那么做成的页面也就不同。

要不就是横排来几个,要不就是竖排来几个,甚至全站要翻来覆去的搞个好几次,麻烦也很累。

索性写个函数能缓解一下,于是就成了下面

<%functionshowpros(tablename,topnum,fildname,loopnum,typenum)Setrs=Server.CreateObject("ADODB.Recordset")sql="Selecttop"&topnum&"*from"&tablenamers.Opensql,conn,1,1ifrs.eofandrs.bofthenresponse.Write("暂时无该记录")elseresponse.Write("")fori=1tors.recordcountif(imodloopnum=1)thenresponse.write""endifselectcasetypenumcase"1"response.Write("")response.Write(rs(""&fildname&""))response.Write("")response.Write("方式1之"&i&"记录")''''此处的“方式1”可以替换显示为其余字段的值response.Write("")''''如果字段比较多,继续添加新个表格行来显示response.Write(" ")case"2"response.Write("")response.Write(rs(""&fildname&""))response.Write("")response.Write("")response.Write("方式2之"&i&"记录")response.Write("")response.Write(" ")endselectif(imodloopnum=0)thenresponse.write""endifrs.movenextnextresponse.Write("")endifrs.closeSetrs=Nothingendfunction%>

参数说明:

showpros(tablename,topnum,fildname,loopnum,typenum)

whichpro为选择何类型的产品种类

topnum表示提取多少条记录

fildname表示调试显示的字段,具体应用的时候可以省去该参数,在函数内部直接使用

loopnum表示显示的循环每行的记录条数

typenum表示循环显示的方法:

目前分了两类,横向并列、纵向并列显示同一数据记录行的不同记录

引用示例如下:

<%ifrequest.form("submit")<>""thentopnum=request.form("topnum")loopnum=request.form("loopnum")typenum=request.form("typenum")elsetopnum=8loopnum=2typenum=1endif%><%callshowpros("cn_products",topnum,"p_name",loopnum,typenum)%>

1.文件上传(单个)

  upload.asp   ''文件上传参数及数据库插入页面

--#include file="upLoad_class.asp"-->

--#include file="conn.asp"-->

<%

Set myrequest=new UpLoadClass

    myrequest.MaxSize=5000*1024 ''如果不写这行,默认最大为500K

    myrequest.FileType="zip/rar/jpeg/jpg/doc/txt/pdf/ppt/xls" ''如果不写这行,默认文件类型限制为gif/jpg

    myrequest.Savepath="file/" ''如果不写这行,默认为UpLoadFile/

    myrequest.open

path="file/"+myrequest.Form("photo")

a=date()

ftime=FormatDateTime(a)

conn.execute("insert into filetable(path,ftime) values(''"& path &"'',''"& ftime &"'')")

response.Redirect("upload_ok.asp")

%>

  upLoad_class.asp   ''上传类

<%

Class UpLoadClass

 Private Ver,Err,FormD,FormStream,ItemStream

 Dim MaxSize,FileType,SavePath,AutoSave

 Private Sub Class_Initialize

  MaxSize=150*1024

  FileType="jpg/gif"

  SavePath="UpLoadFile/"

  AutoSave=true

  Ver ="Rumor UpLoadClass Version 1.02"

  Err=0

  Set FormD = Server.CreateObject ("Scripting.Dictionary")

  FormD.CompareMode = 1  

  Set FormStream=server.CreateObject("ADODB.Stream")   

  Set ItemStream=server.CreateObject("ADODB.Stream")

 End Sub

 

 Private Sub Class_Terminate

  Set ItemStream=nothing

  FormStream.Close()

  Set FormStream=nothing

  FormD.RemoveAll

  Set FormD=nothing 

 End Sub

 Public Sub Open()

  Dim RequestSize,RequestData

  RequestSize=Request.TotalBytes

  if RequestSize<1 then

   Err=4

   Exit Sub

  end if

  RequestData=Request.BinaryRead(RequestSize)

  

  Dim FormSize,CrLf,bCrLf,ListSeparator,LenListSep,FormData

   FormStream.Type = 1

   FormStream.Open 

   FormStream.Write RequestData

   FormSize=FormStream.Size

  bCrLf=ChrB(13)&ChrB(10)

  Separator=MidB(RequestData,1,InstrB(1,RequestData,bCrLf)-1)  

  

  Dim pStart,pEnd,pTemp,ItemInfo,ItemName,ItemData

  pStart=LenB(Separator)+2

  Do

   pEnd = InStrB (pStart,RequestData,bCrLf&bCrLf)+3

   ItemStream.Type=1

   ItemStream.Open

   FormStream.Position=pStart

   FormStream.CopyTo ItemStream,pEnd-pStart

   ItemStream.Position=0

   ItemStream.Type=2

   ItemStream.Charset="gb2312"

   ItemInfo=ItemStream.ReadText

   ItemStream.Close()

   

   pStart=pEnd 

   pEnd = InStrB (pStart,RequestData,Separator)-1

   ItemStream.Type=1

   ItemStream.Open

   FormStream.Position=pStart

   FormStream.CopyTo ItemStream,pEnd-pStart-2

   ItemName=Mid(ItemInfo,39,Instr(39,ItemInfo,"""")-39)

   

   if Instr(40,ItemInfo,"filename=""")>0 then

    if ItemStream.Size<>0 then

     Dim SourceFile,TargetFile

     pTemp=52+Len(ItemName)     

     SourceFile=Mid(ItemInfo,pTemp,Instr(pTemp,ItemInfo,"""")-pTemp)

     FormD.Add ItemName&"_Type",Mid(ItemInfo,Instr(pTemp,ItemInfo,"Content-Type:

 ")+14)

     FormD.Add ItemName&"_Name",Mid(SourceFile,InstrRev(SourceFile,"\")+1)

     FormD.Add ItemName&"_Path",Left(SourceFile,InstrRev(SourceFile,"\"))

     if InstrRev(SourceFile,".")<>0 then

      FormD.Add ItemName&"_Ext",Mid(SourceFile,InstrRev(SourceFile,".")+1)

     else

      FormD.Add ItemName&"_Ext",""

     end if

     FormD.Add ItemName&"_From",pStart

     FormD.Add ItemName&"_Size",ItemStream.Size

     FormD.Add ItemName&"_Err",0

     if Instr(1,LCase("/"&FileType&"/"),LCase("/"&FormD(ItemName&"_Ext")&"/"))=0 then

      if Err<2 then Err=Err+2

      FormD(ItemName&"_Err")=FormD(ItemName&"_Err")+2

     end if

     if FormD(ItemName&"_Size")>MaxSize then

      if Err<1 then Err=Err+1

      FormD(ItemName&"_Err")=FormD(ItemName&"_Err")+1

     end if

     if FormD(ItemName&"_Err")=0 then

      if AutoSave then

       tarFileName=GetTimeStr()

       if FormD(ItemName&"_Ext")<>"" then tarFileName=tarFileName&"."&FormD(ItemName&"_Ext")     

       FormD.Add ItemName,tarFileName

       ItemStream.SaveToFile Server.MapPath(SavePath&tarFileName),2

      else

       FormD.Add ItemName,"Please save first"

      end if

     end if

    else

     FormD.Add ItemName,""

    end if

   else

    ItemStream.Position=0

    ItemStream.Type=2

    ItemStream.Charset="gb2312"

    ItemData=ItemStream.ReadText

    if FormD.Exists(ItemName) then

     FormD(ItemName) = FormD (ItemName)&","&ItemData

    else

     FormD.Add ItemName,ItemData

    end if

   end if

   

   ItemStream.Close()   

   pStart = pEnd+LenB(Separator)+2

  loop Until pStart+3>FormSize

 End Sub

 

 Public Function GetTimeStr()

  GetTimeStr=Cstr(Date())&FormatNumber(Timer()*1000,0)

  GetTimeStr=replace(replace(GetTimeStr,"-",""),",","")

 End Function

 

 Public Sub Save(Item,FileName)

  if Not AutoSave and FormD.Exists(Item&"_From") then

   if FormD(Item&"_Err")<>0 then

    FormD(Item)=""

    Exit Sub

   End if

   ItemStream.Type = 1

   ItemStream.Open

   FormStream.Position = FormD(Item&"_From")

   FormStream.CopyTo ItemStream,FormD(Item&"_Size")

   ItemStream.SaveToFile Server.MapPath(SavePath&FileName),2

   ItemStream.Close()

   FormD(Item)=FileName

  end if 

 End Sub

 Public Function GetData(Item)

  GetData=""

  if FormD.Exists(Item&"_From") then

   if FormD(Item&"_Err")<>0 then Exit Function    

   FormStream.Position = FormD(Item&"_From")

   GetData=FormStream.Read(FormD(Item&"_Size"))

  end if

 End Function

 Public Function Form(Item)

  if FormD.Exists(Item) then

   Form=FormD(Item)

  else

   Form=""

  end if

 End Function

 

 Public Function QueryString(Item)

  QueryString=request.QueryString(Item)

 End Function

 

 Public Function Version()

  Version=Ver

 End Function

 

 Public Function Error()

  Error=Err

 End Function

 

End Class

%>

2.生成数字图片(验证码)

<%

Class UpLoadClass

 Private Ver,Err,FormD,FormStream,ItemStream

 Dim MaxSize,FileType,SavePath,AutoSave

 Private Sub Class_Initialize

  MaxSize=150*1024

  FileType="jpg/gif"

  SavePath="UpLoadFile/"

  AutoSave=true

  Ver ="Rumor UpLoadClass Version 1.02"

  Err=0

  Set FormD = Server.CreateObject ("Scripting.Dictionary")

  FormD.CompareMode = 1  

  Set FormStream=server.CreateObject("ADODB.Stream")   

  Set ItemStream=server.CreateObject("ADODB.Stream")

 End Sub

 

 Private Sub Class_Terminate

  Set ItemStream=nothing

  FormStream.Close()

  Set FormStream=nothing

  FormD.RemoveAll

  Set FormD=nothing 

 End Sub

 Public Sub Open()

  Dim RequestSize,RequestData

  RequestSize=Request.TotalBytes

  if RequestSize<1 then

   Err=4

   Exit Sub

  end if

  RequestData=Request.BinaryRead(RequestSize)

  

  Dim FormSize,CrLf,bCrLf,ListSeparator,LenListSep,FormData

   FormStream.Type = 1

   FormStrea

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2