欢迎光临
我们一直在努力

函数方便制作管理界面-ASP教程,ASP应用

建站超值云服务器,限时71元/月

有的时候做管理界面的添加删除修改重复劳动很麻烦

试写了一个函数包含了分页显示添加删除修改

dim arrheadername,arrfieldname,arrfielddata,arrtdwidth,strtblname,strkeyname,strheadercss,strbodycss,strtablecss,strbuttomcss,ipagesize,itableborder,impdifymethod

arrheadername=array("编号","起始地址","结束地址","国家","地点")

arrfieldname=array("id","onip","offip","addj","addf")

arrfielddata=array("auto","num","num","char","char")

arrtdwidth=array("50","100","100","150","250")

strtblname="ip"

strkeyname="id"

strheadercss="headercss"

strbodycss="bodycss"

strtablecss="tablecss"

strbuttomcss="buttomcss"

ipagesize=20

itableborder=1

imodifymethod=7

数据表格(标题名数组,字段名数组,字段类型数组[auto:自动编号,num:数字型,char:字符型(备注型),date,日期型,time:时间型],单元格宽度数组,表名,标题样式,正文样式,表格整体样式,底部样式,分页数,表格边框,修改需求[0:无1:添加2:删除3:修改4:添加+修改5:删除+修改6:添加+删除7:添加+删除+修改])

datagrid arrheadername,arrfieldname,arrfielddata,arrtdwidth,strtblname,strkeyname,strheadercss,strbodycss,strtablecss,strbuttomcss,ipagesize,itableborder,imodifymethod

这个函数就完成了具有分页显示添加删除修改一个表中的几个字段功能的页面

http://www.musecn.com/new

函数如下:

<%@language="vbscript" codepage="936"%>

<%

定义全局变量

dim objconn

信息过滤(信息,类型)

function myrequest(info,itype)

if itype=0 then

myrequest=trim(cstr(replace(request(info),"","")))

else

if isnumeric(request(info)) then

myrequest=clng(request(info))

else

response.write "类型错误"

response.end

end if

end if

end function

页面头部(页面标题,样式地址)

sub pagestart(strpagetitle,strpagecss)

response.write "<html>"&vbcrlf

response.write "<head>"&vbcrlf

response.write "<meta http-equiv=""content-type"" content=""text/html; charset=gb2312"">"&vbcrlf

response.write "<link href="""&strpagecss&""" rel=""stylesheet"" type=""text/css"">"&vbcrlf

response.write "<title>"&strpagetitle&"</title>"&vbcrlf

response.write "</head>"&vbcrlf

response.write "<body>"&vbcrlf

end sub

连接数据库(数据库名)

sub dbconn(dbname)

set objconn=server.createobject("adodb.connection")

objconn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath(dbname)

end sub

sub pagelast()

response.write "</body>"&vbcrlf

response.write "</html>"&vbcrlf

end sub

数据表格(标题名数组,字段名数组,字段类型数组[auto:自动编号,num:数字型,char:字符型(备注型),date,日期型,time:时间型],单元格宽度数组,表名,主键名,标题样式,正文样式,表格整体样式,底部样式,分页数,表格边框,修改需求[0:无1:添加2:删除3:修改4:添加+修改5:删除+修改6:添加+删除7:添加+删除+修改])

sub datagrid(arrheadername,arrfieldname,arrfielddata,arrtdwidth,strtblname,strkeyname,strheadercss,strbodycss,strtablecss,strbuttomcss,ipagesize,itableborder,imodifymethod)

dim objrs

dim strexec

dim itmp,itmp2

dim ipagecount

dim ipage

dim irecordcount

dim ipagestart

dim ipageend

dim ilasttenpage

dim inexttenpage

set objrs=server.createobject("adodb.recordset")

objrs.open "select count(*) from "&strtblname,objconn,1,1

irecordcount=objrs(0)

objrs.close

if irecordcount mod ipagesize=0 then

ipagecount= irecordcount\ipagesize

else

ipagecount= irecordcount\ipagesize + 1

end if

ipage=myrequest("ipage",1)

if ipage<1 then ipage=1

if ipage>ipagecount then ipage=ipagecount

if myrequest("method",0)="delete" then

strexec="delete from "&strtblname&" where "&strkeyname&"="&myrequest(strkeyname,1)

objconn.execute strexec

response.redirect "?ipage="&ipage

end if

if myrequest("method",0)="modifypost" then

strexec="update "&strtblname&" set "

for itmp=0 to ubound(arrheadername)

if arrfieldname(itmp)<>strkeyname then

if arrfielddata(itmp)="num" then

strexec=strexec&arrfieldname(itmp)&"="&myrequest(arrfieldname(itmp),0)

else

strexec=strexec&arrfieldname(itmp)&"="&myrequest(arrfieldname(itmp),0)&""

end if

if itmp<>ubound(arrfieldname) then strexec=strexec&","

end if

next

strexec=strexec&" where "&strkeyname&"="&myrequest(strkeyname,1)

objconn.execute strexec

response.redirect "?ipage="&ipage

end if

if myrequest("method",0)="addnew" then

strexec="insert into "&strtblname&"("

for itmp=0 to ubound(arrfieldname)

if arrfieldname(itmp)<>strkeyname then

strexec=strexec&arrfieldname(itmp)

if itmp<>ubound(arrfieldname) then strexec=strexec&","

end if

next

strexec=strexec&")values("

for itmp=0 to ubound(arrfieldname)

if arrfieldname(itmp)<>strkeyname then

if arrfielddata(itmp)="num" then

strexec=strexec&myrequest(arrfieldname(itmp),0)

else

strexec=strexec&""&myrequest(arrfieldname(itmp),0)&""

end if

if itmp<>ubound(arrfieldname) then strexec=strexec&","

end if

next

strexec=strexec&")"

objconn.execute strexec

response.redirect "?ipage="&ipage

end if

if ipage-5>0 then

ipagestart=ipage-5

else

ipagestart=1

end if

if 10+ipagestart<=ipagecount then

ipageend=10+ipagestart

else

ipageend=ipagecount

end if

if 10+ipage<=ipagecount then

inexttenpage=ipage+10

else

inexttenpage=ipagecount

end if

if ipage-10>0 then

ilasttenpage=ipage-10

else

ilasttenpage=1

end if

strexec="select top "&ipagesize*ipage&" "

strexec=strexec&strkeyname&","

for itmp=0 to ubound(arrfieldname)

strexec=strexec&arrfieldname(itmp)

if itmp<>ubound(arrfieldname) then strexec=strexec&","

next

strexec=strexec&" from "&strtblname

objrs.open strexec,objconn,1,1

objrs.move ipagesize*(ipage-1)

response.write "<table border=""0"" cellpadding=""0"" cellspacing="""&itableborder&""" class="""&strtablecss&""">"&vbcrlf

response.write "<tr class="""&strheadercss&""">"&vbcrlf

for itmp=0 to ubound(arrheadername)

response.write "<td width="""&arrtdwidth(itmp)&""">"&arrheadername(itmp)&"</td>"&vbcrlf

next

if imodifymethod=2 or imodifymethod=5 or imodifymethod=6 or imodifymethod=7 then

response.write "<td width=""50"">删除</td>"

end if

if imodifymethod=3 or imodifymethod=4 or imodifymethod=5 or imodifymethod=7 then

response.write "<td width=""50"">修改</td>"

end if

response.write "</tr>"&vbcrlf

if imodifymethod=1 or imodifymethod=4 or imodifymethod=6 or imodifymethod=7 then

response.write "<form name=""addnew"" method=""get""><tr class="""&strbodycss&""">"&vbcrlf

for itmp=0 to ubound(arrheadername)

if arrfieldname(itmp)<>strkeyname then

response.write "<td><input name="""&arrfieldname(itmp)&""" type=""text"" size="""&arrtdwidth(itmp)/10&"""></td>"&vbcrlf

else

response.write "<td>-</td>"&vbcrlf

end if

next

response.write "<td colspan=""2""><input type=""hidden"" name=""ipage"" value="""&ipagecount&"""><input type=""hidden"" name=""method"" value=""addnew""><input type=""button"" value=""新增记录"" onclick=""addnew.submit()""></td>"

response.write "</tr></form>"&vbcrlf

end if

for itmp2=1 to ipagesize

if objrs.eof then exit for

response.write "<form name=""modify"&itmp2&""" method=""get""><tr class="""&strbodycss&""">"&vbcrlf

for itmp=0 to ubound(arrheadername)

if arrfieldname(itmp)<>strkeyname and myrequest("method",0)="modify" and objrs(strkeyname)=myrequest(strkeyname,1) then

response.write "<td><input name="""&arrfieldname(itmp)&""" type=""text"" size="""&arrtdwidth(itmp)/10&""" value="""&objrs(arrfieldname(itmp))&"""></td>"&vbcrlf

else

response.write "<td>"&objrs(arrfieldname(itmp))&"</td>"&vbcrlf

end if

next

if imodifymethod=2 or imodifymethod=5 or imodifymethod=6 or imodifymethod=7 then

response.write "<td width=""50""><input type=""button"" onclick=""location.href=?ipage="&ipage&"&method=delete&"&strkeyname&"="&objrs(strkeyname)&""" value=""删除""></td>"

end if

if imodifymethod=3 or imodifymethod=3 or imodifymethod=5 or imodifymethod=7 then

if myrequest("method",0)="modify" and objrs(strkeyname)=myrequest(strkeyname,1) then

response.write "<td width=""50""><input type=""hidden"" name=""method"" value=""modifypost""><input type=""hidden"" name="""&strkeyname&""" value="""&objrs(strkeyname)&"""><input type=""hidden"" name=""ipage"" value="""&ipage&"""><input type=""submit"" value=""确认""></td>"

else

response.write "<td width=""50""><input type=""button"" onclick=""location.href=?ipage="&ipage&"&method=modify&"&strkeyname&"="&objrs(strkeyname)&""" value=""修改""></td>"

end if

end if

response.write "</tr></form>"&vbcrlf

objrs.movenext

next

response.write "<tr class="""&strbuttomcss&""">"&vbcrlf

response.write "<td colspan="""&ubound(arrheadername)+3&""">"&vbcrlf

response.write "分页 ( "&ipage&"/"&ipagecount&" )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"

response.write "<a href=""?ipage=1"" title=首页><font face=webdings >9</font></a> "

response.write "<a href=""?ipage="&ilasttenpage&""" title=上十页><font face=webdings>7</font></a> "

for itmp=ipagestart to ipageend

response.write " <a href=""?ipage="&itmp&""">"&itmp&"</a>"

next

response.write " <a href=""?ipage="&inexttenpage&""" title=下十页><font face=webdings>8</font></a>"

response.write " <a href=""?ipage="&ipagecount&""" title=末页><font face=webdings>:</font></a> "

response.write "&nbsp;&nbsp;"

response.write "</td>"&vbcrlf

response.write "</tr>"&vbcrlf

response.write "</table>"&vbcrlf

end sub

%>

调用函数的页面

<!–#include file="func.asp"–>

<%

starttime=timer()

定义函数参数

dim strpagetitle,strpagecss

strpagetitle="标题"

strpagecss="css.css"

页面头部(页面标题,样式地址)

pagestart strpagetitle,strpagecss

定义函数参数

dim dbname

dbname="ip.mdb"

连接数据库(数据库名)

dbconn dbname

定义函数参数

dim arrheadername,arrfieldname,arrfielddata,arrtdwidth,strtblname,strkeyname,strheadercss,strbodycss,strtablecss,strbuttomcss,ipagesize,itableborder,impdifymethod

arrheadername=array("编号","起始地址","结束地址","国家","地点")

arrfieldname=array("id","onip","offip","addj","addf")

arrfielddata=array("auto","num","num","char","char")

arrtdwidth=array("50","100","100","150","250")

strtblname="ip"

strkeyname="id"

strheadercss="headercss"

strbodycss="bodycss"

strtablecss="tablecss"

strbuttomcss="buttomcss"

ipagesize=20

itableborder=1

imodifymethod=7

数据表格(标题名数组,字段名数组,字段类型数组[auto:自动编号,num:数字型,char:字符型(备注型),date,日期型,time:时间型],单元格宽度数组,表名,标题样式,正文样式,表格整体样式,底部样式,分页数,表格边框,修改需求[0:无1:添加2:删除3:修改4:添加+修改5:删除+修改6:添加+删除7:添加+删除+修改])

datagrid arrheadername,arrfieldname,arrfielddata,arrtdwidth,strtblname,strkeyname,strheadercss,strbodycss,strtablecss,strbuttomcss,ipagesize,itableborder,imodifymethod

页面底部()

pagelast

%>

页面执行时间<%=(timer()-starttime)*1000%>毫秒

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 函数方便制作管理界面-ASP教程,ASP应用
分享到: 更多 (0)