<!--#include file="conn.asp"-->
<%
dim rs,sql
if isnull(request.cookies("cardnumber")) or request.cookies("cardnumber")=empty then
response.cookies("cardnumber")="|"
response.cookies("cardnumber").Expires=Date+365
end if

set rs=server.createobject("adodb.recordset")

'*********************************判断投票项目是否已经关闭
sql="select kg,overtime from voteclass where id="&request("classid")
rs.open sql,conn,3,1
if rs("kg")=1 then
response.write "<script>alert('这个项目已经关闭了。');</script>"
call show()
response.end
end if

'*****************************************判断投票项目是否已经过期
if left(rs("overtime"),2)<>"0-"then
if datediff("s",now,formatdatetime(rs("overtime")))<0 then
response.write "<script>alert('这个项目已经到截至日期了。');</script>"
call show()
response.end
end if
end if
rs.close

'****************************************判断是否已经投票过了
if instr(request.cookies("cardnumber"),"|"&request("classid")&"|")<>0 then
response.write "<script>alert('这个项目你已经投过了。');</script>"
call show()
response.end
end if

'*********************************************进行数据库操作
if request("style")="radio" then
if isnull(request("voted")) or request("voted")=empty then
response.write "<script>alert('请选择投票项目。');window.close()</script>"
call EndConnection()
response.end
end if
sql="select * from vote where id="&request("voted")
rs.open sql,conn,3,2
rs("count")=rs("count")+1
rs.update
rs.close
elseif request("style")="checkbox" then
if request("voted").count=0 then
response.write "<script>alert('请选择投票项目。');window.close()</script>"
call EndConnection()
response.end
end if
for i=1 to request("voted").count
sql="select * from vote where id="&request("voted")(i)
rs.open sql,conn,3,2
rs("count")=rs("count")+1
rs.update
rs.close
next
end if
response.cookies("cardnumber")=request.cookies("cardnumber")&request("classid")&"|"
response.cookies("cardnumber").Expires=Date+365
'*************************************显示投票结果
call show()

sub show()
response.write "<script>location.href='Class_voteshow.asp?classid="&request("classid")&"';</script>"
rs.close
set rs=nothing
call EndConnection()
response.end
end sub
%>