设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > ASP

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

作者:佚名 出处:网络转载 时间:06-26 点击:

内容载入中...
 

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

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

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
document.getElementById('loading').style.display="none";

收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息