繁体中文
设为首页
加入收藏
当前位置:ASP技术首页 >> ASP基础 >> 跟我学做在线调查(四)

跟我学做在线调查(四)

2006-07-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:续上篇 上一篇中,我们完成了显示统计结果和调查列表的程序,最后我们来完成后台 管理页面,也是最重要的一个程序。 一、后台管理 在后台管理页面survey_manage.ASP中,前面我们已经列出来它所要实现的 管理功能...
关键字:跟我学 在线调查

续上篇

上一篇中,我们完成了显示统计结果和调查列表的程序,最后我们来完成后台

管理页面,也是最重要的一个程序。

一、后台管理

在后台管理页面survey_manage.ASP中,前面我们已经列出来它所要实现的

管理功能。管理的流程是先显示出所有调查,对于还没有开始的调查,可以进行修

改、删除;对于已经结束的调查,可以删除,不能修改;对于正在进行的调查,只

能修改它的结束时间。用一个参数action来表示动作,含义如下:

1、无参数。表示第一次进入,显示登录表单

2、login 表示执行登录

3、LOGOut 表示执行退出登录

4、showaddquestion 表示显示增加一个调查

5、showsurvey 表示显示一个调查

6、doaddsurvey 表示执行增加一个调查

7、doaddanswer 表示执行增加一个答案

8、dodelsurvey 表示删除一个调查

9、dodelanswer 表示删除一个答案

10、domodify 表示修改一个调查及答案

<%

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

stat="未开始"

else

if now

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

%>

在线调查后台管理

<%

'判断是否登录,没有则显示登录表单

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

%>

">返回

在线调查后台管理程序 ?action=LOGOut">退出

<%

end sub

'----显示所有调查子程序----

sub showall()

opentable my,"survey",rs '直接打开表

'下面用表格显示每个记录

'先显示表头

%>

bordercolorligh="#000000" bordercolordark="#ffffff">

<%

'下面输出每个记录

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

stat="未开始"

else

if now

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 '关闭表

'下面输出一条记录

%>

<%

rs.movenext

loop

%>

所有调查列表
选择 调查问题 类型 起启时间 结束时间 状态 已投票数 查看

?action=showsurvey&id=<%=id%>" title="点击此处编辑">

<%=question%>

<%=stype%> <%=stime%> <%=etime%> <%=stat%> <%=total%>

" target="_blank">查看

onclick="window.location='<%=scr%>?action=showaddsurvey'">

<%

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

stat="未开始"

else

if now

stat="进行中"

else

stat="已结束"

end if

end if

%>

bordercolorligh="#000000" bordercolordark="#ffffff">

<%if stat<>"已结束" then%>

<%end if%>

修改调查
编号:<%=id%>
问题:

<%if stat<>"未开始" then

response.write question

else%>

<%end if%>

起启时间:

<%if stat<>"未开始" then

response.write stime

else%>

<%end if%>

结束时间:

<%if stat="已结束" then

response.write etime

else%>

<%end if%>

类型: <%if stat<>"未开始" then

response.write stype

else%>

<%if not rs("survey_type") then response.write "checked"%>>单选

<%if rs("survey_type") then response.write "checked"%>>多选<%end if%>

状态:<%=stat%>
答案: <%

sql="select vote_no,vote_answer from survey_vote where vote_id=" & id

searchtable my,sql,tmprs '执行查询

if tmprs.recordcount=0 then

response.write " "

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&"、 "

response.write vbcrlf&" "

response.write vbcrlf&"删除"&br

end if

tmprs.movenext

next

end if

closetable tmprs

%>

增加答案:

<%

end if

closetable rs

end sub

'----显示增加调查子程序----

sub showaddsurvey()

%>

bordercolorligh="#000000" bordercolordark="#ffffff">

增加调查
问题:
起启时间:

"> 默认为1小时后

结束时间:

"> 默认为1个月后

类型:

单选

多选

<%

end sub

'----显示登录表单子程序----

sub showlogin()

%>

bordercolorligh="#000000" bordercolordark="#ffffff">

管理员登录
用户名:

密码:

<%

end sub

%>

二、后话

到这里我们已经完成了所有的页面。当然在管理页面中,有些规则还是要根

据个人的使用情况来定,比如对于正在进行的调查,你要改成可删除,也是可以的。

另外,还可以扩展一些功能,比如:

1、可以把调查改成不能同时进行。即同一时间只能有一个调查在进行中。

2、可以修改显示调查表单的代码,改为自动选择一个正在进行的调查来显示。

结合上面两点功能,你可以做出一个能预先安排一整年调查的系统来。

3、在确定结束时间的地方,你可以改为用一个文本框来输入调查的时间长度。

当然,如果这样的话,需要加一个下拉框来选择单位,单位可以是小时、天、星期、

月、季度、年。这样的组合灵活性更高。

4、你可以更改投票的限制。比如改为一个IP投票一次。

5、你可以给每个投票指定一个管理员。这样一来就成为一个多用户的调查系统了。

更多的功能等待朋友们自己去发挥想像。

责任编辑:admin
相关文章