函數方便製作管理介面

來源:互聯網
上載者:User
函數 有的時候做管理介面的添加刪除修改重複勞動很麻煩

試寫了一個函數包含了分頁顯示添加刪除修改

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(arrF



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。