人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

本文教你做在線調查(4)

本文教你做在線調查(4)

更新時間:2021-01-25 文章作者:未知 信息來源:網絡 閱讀次數:

續上篇
上一篇中,我們完成了顯示統計結果和調查列表的程序,最后我們來完成后臺
管理頁面,也是最重要的一個程序。

一、后臺管理
在后臺管理頁面survey_manage.asp中,前面我們已經列出來它所要實現的
管理功能。管理的流程是先顯示出所有調查,對于還沒有開始的調查,可以進行修
改、刪除;對于已經結束的調查,可以刪除,不能修改;對于正在進行的調查,只
能修改它的結束時間。用一個參數action來表示動作,含義如下:
1、無參數。表示第一次進入,顯示登錄表單
2、login 表示執行登錄
3、logout 表示執行退出登錄
4、showaddquestion 表示顯示增加一個調查
5、showsurvey 表示顯示一個調查
6、doaddsurvey 表示執行增加一個調查
7、doaddanswer 表示執行增加一個答案
8、dodelsurvey 表示刪除一個調查
9、dodelanswer 表示刪除一個答案
10、domodify 表示修改一個調查及答案

<!--#include file="inc.asp" -->
<%
opendb my '打開數據庫
'獲取參數。action表示動作,分別對應上面的功能。
action=request.querystring("action")
id=request.querystring("id")
'獲取當前文件名
scr=Request.ServerVariables("SCRIPT_NAME")
'根據動作來轉向相應的子程序
select case action
case "login"
login() '執行登錄
case "logout"
logout() '執行退出登錄
case "doaddsurvey"
doaddsurvey() '執行增加一個調查
case "dodelsurvey"
dodelsurvey() '執行刪除一個調查
case "dodelanswer"
dodelanswer() '執行刪除一個答案
case "domodify"
domodify() '執行修改一個調查及答案
end select
'----登錄子程序----
sub login()
username=request.form("username") '獲取用戶名
password=request.form("password") '獲取密碼
if username<>"" and password<>"" then
sql="select * from manage where manage_username='"& username &"'" '查詢用戶
searchtable my,sql,rs
if not rs.eof then '如果有
if rs("manage_password")=password then '密碼也正確
session("survey_login")=true '登錄
end if
end if
closetable rs '關閉表
end if
response.redirect scr '不管有沒登錄,最后都回到管理頁
end sub
'----退出登錄子程序----
sub logout()
'刪除session變量
session.contents.remove "survey_login"
response.redirect scr '回到管理頁面
end sub
'----執行增加調查子程序----
sub doaddsurvey()
question=request.form("question")
stime=request.form("stime")
etime=request.form("etime")
stype=request.form("stype")
if question<>"" and stime<>"" and etime<>"" and isdate(stime)_
and isdate(etime) and session("survey_login") then
sql="select * from survey where survey_id is null"
changetable my,sql,rs
rs.addnew
rs("survey_question")=question
rs("survey_stime")=cdate(stime)
rs("survey_etime")=cdate(etime)
rs("survey_type")=cbool(stype)
rs.update
id=rs("survey_id")
closetable rs
response.redirect scr&"?action=showsurvey&id="&id '回到顯示頁面
end if
response.redirect scr '回到顯示頁面
end sub

'----執行增加調查答案子程序----
sub doaddanswer()
answer=request.form("newanswer")
if session("survey_login") then
sql="select * from survey_vote where vote_no is null"
changetable my,sql,rs
rs.addnew
rs("vote_answer")=answer
rs("vote_id")=id
rs.update
closetable rs
end if
'response.redirect scr&"?action=showsurvey&id="&id '回到顯示頁面
end sub

'----執行修改調查子程序----
sub domodify()
question=request.form("question")
stime=request.form("stime")
etime=request.form("etime")
stype=request.form("stype")
answer=request.form("newanswer")
if session("survey_login") then
sql="select * from survey where survey_id="&id
changetable my,sql,rs
if not rs.eof then
if question<>"" then rs("survey_question")=question
if stime<>"" and isdate(stime) then rs("survey_stime")=cdate(stime)
if etime<>"" and isdate(etime) then
if cdate(etime)>rs("survey_stime") then rs("survey_etime")=cdate(etime)
end if
if stype<>"" then rs("survey_type")=cbool(stype)
rs.update
end if
closetable rs
if answer<>"" then doaddanswer()
sql="select vote_answer from survey_vote where vote_id="&id
changetable my,sql,rs
for i=1 to rs.recordcount
if request.form("no"&i) <>"" then
txt=request.form("txt"&i)
response.write "修改了第"&i&"條記錄的內容為:"&txt&br
'把修改的內容寫入數據庫
rs("vote_answer")=txt
rs.update
end if
rs.movenext
next
closetable rs '關閉數據庫和表
end if
response.redirect scr&"?action=showsurvey&id="&id '回到顯示頁面
end sub
'----執行刪除調查問題子程序----
sub dodelsurvey()
id=request.form("id")
if session("survey_login") then
sql="select * from survey where survey_id in ("&id&")"
changetable my,sql,rs
do while not rs.eof
stime=rs("survey_stime")
etime=rs("survey_etime")
'判斷狀態
if now()<stime then
stat="未開始"
else
if now<etime then
stat="進行中"
else
stat="已結束"
end if
end if
if stat<>"進行中" then
sql="delete from survey_vote where vote_id="&rs("survey_id")
my.execute sql
rs.delete
end if
rs.movenext
loop
end if
response.redirect scr '回到管理頁面
end sub

'----執行刪除調查答案子程序----
sub dodelanswer()
no=request.querystring("no")
if session("survey_login") then
sql="delete from survey_vote where vote_no="&no
my.execute sql
end if
response.redirect scr&"?action=showsurvey&id="&id '回到顯示頁面
end sub
%>
<html>
<head>
<title>在線調查后臺管理</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<%
'判斷是否登錄,沒有則顯示登錄表單
if session("survey_login")<>true then
showlogin()
else
showtop() '顯示已經登錄的信息
'根據動作顯示相應表單
select case action
case "showsurvey"
showsurvey() '顯示單個調查
case "showaddsurvey"
showaddsurvey() '顯示增加調查表單
case ""
showall() '顯示所有調查
end select
end if
closedb my '關閉數據庫
'----顯示已經登錄的信息----
sub showtop()
%>
<table width="750" border="0" align="center">
<tr valign="bottom" height=20>
<td width=50 align="center"><a href="<%=scr%>">返回</a>
<td align="center"><B>在線調查后臺管理程序</B></td>
<td width=50 align="center"><a href="<%=scr%>?action=logout">退出</a>
</td>
</tr>
<table>
<%
end sub
'----顯示所有調查子程序----
sub showall()
opentable my,"survey",rs '直接打開表
'下面用表格顯示每個記錄
'先顯示表頭
%>
<form action="<%=scr%>?action=dodelsurvey" method='post'>
<table width="760" border="1" cellspacing="0" cellpadding="2" align="center"
bordercolorligh="#000000" bordercolordark="#ffffff">
<tr>
<td colspan="8" align="center"><b>所有調查列表</b></td>
</tr>
<tr >
<td width="50" align="center" height="20">選擇</td>
<td width="200" align="center" height="20">調查問題</td>
<td width="50" align="center" height="20">類型</td>
<td width="140" align="center" height="20">起啟時間</td>
<td width="140" align="center" height="20">結束時間</td>
<td width="50" align="center" height="20">狀態</td>
<td width="80" align="center" height="20">已投票數</td>
<td width="50" align="center" height="20">查看</td>
</tr>
<%
'下面輸出每個記錄
do while not rs.eof
'先讀出每個字段
id=rs("survey_id")
question=rs("survey_question")
'讀出類型
if rs("survey_type") then
stype="多選"
else
stype="單選"
end if
stime=rs("survey_stime")
etime=rs("survey_etime")
'判斷狀態
if now()<stime then
stat="未開始"
else
if now<etime then
stat="進行中"
else
stat="已結束"
end if
end if
'定義SQL語句,得到答案的數量總和
sql="select sum(vote_count) as total from survey_vote where vote_id="& id
searchtable my,sql,tmprs '查詢
if isnull(tmprs("total")) then
total="-"
else
total=tmprs("total")
end if
closetable tmprs '關閉表
'下面輸出一條記錄
%>
<tr >
<td align="center" height="20">
<INPUT TYPE="checkbox" NAME="id" value="<%=id%>"></td>
<td height="25">
<a href="<%=scr%>?action=showsurvey&id=<%=id%>" title="點擊此處編輯">
<%=question%></a>
</td>
<td align="center" height="25"><%=stype%></td>
<td align="center" height="25"><%=stime%></td>
<td align="center" height="25"><%=etime%></td>
<td align="center" height="25"><%=stat%></td>
<td align="center" height="25"><%=total%></td>
<td align="center" height="25">
<a href="survey_vote.asp?id=<%=id%>" target="_blank">查看</a>
</td>
</tr>
<%
rs.movenext
loop
%>
<tr>
<td colspan="8" align="center">
<INPUT TYPE="submit" value="刪除記錄">&nbsp;
<INPUT TYPE="reset" value="重新選擇">&nbsp;
<INPUT TYPE="button" value="增加調查"
onclick="window.location='<%=scr%>?action=showaddsurvey'">
</td>
</tr>

</form>
<%
closetable rs
end sub
'----顯示單個調查子程序----
sub showsurvey()
'定義SQL語句,得到調查
sql="select * from survey where survey_id=" & id
searchtable my,sql,rs '執行查詢
if not rs.eof then
'先讀出每個字段
question=rs("survey_question")
stime=rs("survey_stime")
etime=rs("survey_etime")
'讀出類型
if rs("survey_type") then
stype="多選"
else
stype="單選"
end if
'判斷狀態
if now()<stime then
stat="未開始"
else
if now<etime then
stat="進行中"
else
stat="已結束"
end if
end if
%>
<form name="addnew" action="<%=scr%>?action=domodify&id=<%=id%>" method='post'>
<table width="760" border="1" cellspacing="0" cellpadding="2" align="center"
bordercolorligh="#000000" bordercolordark="#ffffff">
<tr height=25>
<td colspan="2" align="center"><b>修改調查</b></td>
</tr>
<tr height=25>
<td align="right" width="300">編號:</td><td><%=id%></td>
</tr>
<tr height=25>
<td align="right" width="300">問題:</td><td>
<%if stat<>"未開始" then
response.write question
else%>
<INPUT size=40 TYPE="text" NAME="question" value="<%=question%>">
<%end if%></td>
</tr>
<tr height=25>
<td align="right" width="300">起啟時間:</td><td>
<%if stat<>"未開始" then
response.write stime
else%>
<INPUT TYPE="text" NAME="stime" value="<%=stime%>"><%end if%></td>
</tr>
<tr height=25>
<td align="right" width="300">結束時間:</td><td>
<%if stat="已結束" then
response.write etime
else%>
<INPUT TYPE="text" NAME="etime" value="<%=etime%>"><%end if%></td>
</tr>
<tr height=25>
<td align="right" width="300">類型:</td>
<td><%if stat<>"未開始" then
response.write stype
else%>
<INPUT TYPE="radio" NAME="stype" value="false"
<%if not rs("survey_type") then response.write "checked"%>>單選&nbsp;
<INPUT TYPE="radio" NAME="stype" value="true"
<%if rs("survey_type") then response.write "checked"%>>多選<%end if%></td>
</tr>
<tr height=25>
<td align="right" width="300">狀態:</td><td><%=stat%></td>
</tr>
<tr>
<td valign="top" align="right" width="300">答案:</td>
<td><%
sql="select vote_no,vote_answer from survey_vote where vote_id=" & id
searchtable my,sql,tmprs '執行查詢
if tmprs.recordcount=0 then
response.write "&nbsp;"
else
for i=1 to tmprs.recordcount
no=tmprs("vote_no")
answer=tmprs("vote_answer")
if stat="已結束" then
response.write i&"、"&answer&br&vbcrlf
else
response.write i&"、<INPUT TYPE='checkbox' NAME='no"&i&"' value='"&no&"'>&nbsp;"
response.write vbcrlf&"<INPUT TYPE='text' NAME='txt"&i&"' value='"&answer&"'>&nbsp;"
response.write vbcrlf&"<a href='"&scr&"?action=dodelanswer&id="&id&"&no="&no&"'>刪除</a>"&br
end if
tmprs.movenext
next
end if
closetable tmprs
%></td>
</tr>
<%if stat<>"已結束" then%>
<tr height=25>
<td align="right" width="300">增加答案:</td><td>
<INPUT TYPE="text" NAME="newanswer">
</td>
</tr><%end if%>
<tr>
<td colspan="2" align="center">
<INPUT TYPE="submit" value=" 確 定 ">
<INPUT TYPE="reset" value= "重新選擇">
</td>
</tr>

</from>
<%
end if
closetable rs
end sub
'----顯示增加調查子程序----
sub showaddsurvey()
%>
<form action="<%=scr%>?action=doaddsurvey" method='post'>
<table width="760" border="1" cellspacing="0" cellpadding="2" align="center"
bordercolorligh="#000000" bordercolordark="#ffffff">
<tr height=25>
<td colspan="2" align="center"><b>增加調查</b></td>
</tr>
<tr height=25>
<td align="right" width="300">問題:</td>
<td><INPUT TYPE="text" NAME="question"></td>
</tr>
<tr height=25>
<td align="right" width="300">起啟時間:</td><td>
<INPUT TYPE="text" NAME="stime" value="<%=DateAdd("h",1,now())%>">&nbsp;&nbsp;默認為1小時后</td>
</tr>
<tr height=25>
<td align="right" width="300">結束時間:</td><td>
<INPUT TYPE="text" NAME="etime" value="<%=DateAdd("m",1,now())%>">&nbsp;&nbsp;默認為1個月后</td>
</tr>
<tr height=25>
<td align="right" width="300">類型:</td><td>
<INPUT TYPE="radio" NAME="stype" value="false" checked>單選&nbsp;
<INPUT TYPE="radio" NAME="stype" value="true">多選</td>
</tr>
<tr>
<td colspan="2" align="center">
<INPUT TYPE="submit" value=" 確 定 ">
<INPUT TYPE="reset" value= " 重 寫 ">
</td>
</tr>

</from>
<%
end sub
'----顯示登錄表單子程序----
sub showlogin()
%>
<form action="<%=scr%>?action=login" method=post>
<table width="500" border="1" align="center" cellpadding="2" cellspacing="0"
bordercolorligh="#000000" bordercolordark="#ffffff">
<tr>
<td colspan='2' align="center"><B>管理員登錄</B></td>
</tr>
<tr>
<td align="right" width=200>用戶名:</td>
<td align="left" width=300>
<INPUT TYPE="text" NAME="username" size=15 maxlength=15>
</td>
</tr>
<tr>
<td align="right" width=200>密碼:</td>
<td align="left" width=300>
<INPUT TYPE="password" NAME="password" size=15 maxlength=15>
</td>
</tr>
<tr>
<td colspan='2' align="center">
<INPUT TYPE="submit" value="登錄">&nbsp;<INPUT TYPE="reset" value="重寫">
</td>
</tr>

</form>
<%
end sub
%>
</body>
</html>


二、后話
到這里我們已經完成了所有的頁面。當然在管理頁面中,有些規則還是要根
據個人的使用情況來定,比如對于正在進行的調查,你要改成可刪除,也是可以的。
另外,還可以擴展一些功能,比如:
1、可以把調查改成不能同時進行。即同一時間只能有一個調查在進行中。
2、可以修改顯示調查表單的代碼,改為自動選擇一個正在進行的調查來顯示。
結合上面兩點功能,你可以做出一個能預先安排一整年調查的系統來。
3、在確定結束時間的地方,你可以改為用一個文本框來輸入調查的時間長度。
當然,如果這樣的話,需要加一個下拉框來選擇單位,單位可以是小時、天、星期、
月、季度、年。這樣的組合靈活性更高。
4、你可以更改投票的限制。比如改為一個IP投票一次。
5、你可以給每個投票指定一個管理員。這樣一來就成為一個多用戶的調查系統了。
更多的功能等待朋友們自己去發揮想像。

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 彩票| 阜南县| 登封市| 张家川| 东光县| 砚山县| 福泉市| 陈巴尔虎旗| 潜江市| 神木县| 息烽县| 黔西县| 阿坝| 靖安县| 横山县| 安吉县| 温宿县| 屯门区| 敖汉旗| 临漳县| 皮山县| 阆中市| 顺昌县| 厦门市| 剑川县| 北川| 微山县| 来宾市| 宝鸡市| 卓尼县| 江口县| 永昌县| 财经| 清水河县| 湘潭县| 大邑县| 安西县| 峡江县| 涟水县| 绩溪县| 绥江县|