<!--#include file="../conn.asp"-->
<!--#include file="Function.asp"-->
<%
'*****************************************判断投票项目是否已经过期
Set rs = Server.CreateObject(YWNT_TMS_RS)
sql="select EndDate,VoteMaxNum from YWNT_TMS_VoteClass where id="&NoSqlHack(request("id"))
rs.open sql,conn,1,1
EndDate=rs("EndDate")
VoteMaxNum=rs("VoteMaxNum")
rs.close
set rs=nothing
if datediff("d",date(),EndDate)<0 then
response.write "<script>alert('这个项目已经到截至日期了。');window.close()</script>"
call show()
end if


'****************************************判断是否已经投票过了
if request.cookies("cardnumber")<>"" then
response.write "<script>alert('你已经投过票了。');window.close()</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>"
response.end
end if
Set rs = Server.CreateObject(YWNT_TMS_RS)
sql="select * from YWNT_TMS_Vote where id="&NoSqlHack(request("voted"))
rs.open sql,conn,1,3
rs("VoteNum")=rs("VoteNum")+1
rs.update
rs.close
set rs=nothing
elseif request("style")="checkbox" then
if request("voted").count=0 then
response.write "<script>alert('请选择投票项目。');window.close()</script>"
response.end
end if
for i=1 to request("voted").count
Set rs = Server.CreateObject(YWNT_TMS_RS)
sql="select * from YWNT_TMS_Vote where id="&NoSqlHack(request("voted")(i))
rs.open sql,conn,1,3
rs("VoteNum")=rs("VoteNum")+1
rs.update
rs.close
set rs=nothing
next
end if
response.cookies("cardnumber")=request("id")
response.cookies("cardnumber").Expires=Date+365
response.write "<script>alert('投票成功。');</script>"
call show()

function show
response.write "<script>location.href='showvote.asp?id="&request("id")&"';</script>"
response.end
end function
call connclose()%>
