分享
 
 
 

自己写的函数方便制作管理界面

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

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

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%>毫秒

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有