第3章 主要程序編寫的代碼
- 前言
- 第1章 在win10下配置asp的運行環境
- 第2章 系統需求分析
- 第3章 主要程序編寫的代碼
- 結語
在頁面設計的程序中,本人覺得主要有下面幾個方面的代碼需記錄下來。
3.1顯示未填報的學生名單的SQL語句
select * from xs where xsclass='"&session("jsclass")&"' and not exists(select * from xsq where xs.xsno=xsq.xsno and xstimeid="&ymdnum&" and xsclass='"&session("jsclass")&"')
//表示通過學生學號查找xs和xsq兩個表的某個班的學生在某一天不存在的學生數據。
//xs表是學生基本信息表,xsq表是存儲學生每天填報的數據。Xs.xsno=xsq.xsno是對xs表中的xsno(學生學號)跟xsq表中的xsno進行配對,並將沒有配對上的學生找出來。
3.2統計填報數據代碼
rs.open"select * from xsq where xstimeid="&ymdnum&"",conn,1,1
if not(rs.eof or rs.bof) then
xsnum1=0 ‘初始化各個變量
xsnum2=0
……
xsnum9=0
xsnum10=0
do while not rs.eof ‘逐條計算各項數據的和
if trim(rs("xsdress"))="A" then
xsnum1=xsnum1+1
else
xsnum2=xsnum2+1
end if
……
if trim(rs("xsq4"))="A" then
xsnum9=xsnum9+1
else
xsnum10=xsnum10+1
end if
rs.movenext
loop
else
xsnum1=0
xsnum2=0
……
xsnum9=0
xsnum10=0
end if
3.3導出Excel報名的代碼
主要的代碼如下所示,導出的是Excel格式的報表。代碼比較簡單,大家百度一下也是可以找到的。
Response.AddHeader "Content-Disposition","attachment;filename="&ymdnum&"-"&jsclass&"-未填報健康數據的學生名單.xls" ‘導出的文件名稱
Response.ContentType = "application/vnd.ms-excel" ‘以excel的格式導出
rs.open"select * from xs where not exists(select * from xsq where xs.xsno=xsq.xsno and xstimeid="&ymdnum&")",conn,1,1
if not(rs.eof or rs.bof) then
response.write "<table width=""100%"" border=""1"" >"
response.write "<tr>"
response.write "<th width=""40%""><b>學號</b></th>"
response.write "<th width=""30%""><b>姓名</b></th>"
response.write "<th width=""30%""><b>年級</b></th>"
response.write "<th width=""30%""><b>班別</b></th>"
response.write "<th width=""30%""><b>是否填報</b></th>"
response.write "</tr>"
do while not rs.eof
response.write "<tr>"
response.write "<td width=""40%"">"&trim(rs("xsno"))&"</td>"
response.write "<td width=""30%"">"&trim(rs("xsname"))&"</td>"
response.write "<td width=""30%"">"&trim(rs("xsglass"))&"</td>"
response.write "<td width=""30%"">"&trim(rs("xsclass"))&"</td>"
response.write "<td width=""30%"">否</td>"
response.write "</tr>"
rs.movenext
loop
response.write "</table>"
end if
rs.close
set rs=nothing
結語
本案的架構比較簡單,所使用的也不是現在流行的編程語言,但是比較實用,而且在很多教育單位,使用的服務器都比較落後,安裝的操作系統可能也不是現在最新的。在這樣的情況下,本着只要能實現需求就行的想法開發的這個數據上報系統,經過一個多星期的運行,應付每天2000多條的數據上報,還是顯得綽綽有餘。現在使用本系統,可以很瀟灑地動動手指,就可將一天的數據統計導出來,直接轉發給學校疫情指揮部,自己也終於從數據搬運工和校對工中解放出來了。
最後形成的上報表如圖所示。