Batman 翻译整理
一个很不错的建立自己的投票系统的ASP程序大家仔细读读,只要能够理解中间的关键技术,就能够在自己的网站上建立自己的投票站了。文件整理得很仓促,希望大家谅解。
版权所有:
ASP Polls
version 1.0
Tipped Cow Development and Adrenalin Labs
结构简单介绍:
ACCESS数据库设计结构:
poll表主要字段名称:PollName,PollCreator,PollQuestion,Password,Choice1,Choice2
Choice3,Choice4,Choice5,ID(自动编号),GetName
pollresults表字段:PollID,PollAnswer,Name
1.文件db.inc
1
2Application("ASP_Poll") = "ASP_Poll"
3cnString = "DRIVER={Microsoft Access Driver (*.mdb)}; "
4cnString = cnString & "DBQ=" & Server.MapPath("Events.mdb")
5Application("ASPPollDSN") = cnString
1.文件creat_poll1.asp
1 Title="Poll Generator"
1<head> <link href="style.css" rel="STYLESHEET" type="text/css"/>
2<title>```
3=Title
4```</title>
5</head>
1<body>
2<div align="left"><img height="90" src="asp_poll.gif" width="231"/><br/>Another joint product from <a href="http://www.ncws.com/tippycow">Tipped Cow Development</a> and <a href="http://dstoflet.calweb.com">Adrenalin Labs</a>
3<br/><br/>
4</div>
5<center>
6
Response.Write "<font face="arial">"
If Request("errormessage") <> "" Then
Response.Write "<b>Error! </b>" & Request("errormessage")
Else
Response.Write "Please complete the form below to begin creating your own poll."
End If
1
2<br/><br/>
3<table border="2" cellpadding="0" cellspacing="0"><tr><td>
4<form action="create_poll2.asp" method="post">
5<table border="0" cellpadding="10" cellspacing="0" width="500"><tr>
6<td align="center" bgcolor="#000000" class="bold2" colspan="2">
7Enter Your Name as the Poll Creator
8</td>
9</tr><tr>
10<td bgcolor="#ffffff" class="bold" width="25%">Poll Creator:</td>
11<td bgcolor="#ffffff">
12<input ```"="" class="input" creator")="" name="creator" size="20" type="text" value="```
13=Request("/>
14</td>
15</tr>
16</table>
17</form></td></tr>
18<tr><td>
19<table border="0" cellpadding="10" cellspacing="0" width="500"><tr>
20<td align="center" bgcolor="#000000" class="bold2" colspan="2">
21Create a Password For Your Poll So That You Can Modify It At A
22Later Time
23</td>
24</tr><tr>
25<td bgcolor="#ffffff" class="bold" width="25%">Poll Admin Password:</td>
26<td bgcolor="#ffffff">
27<input ```"="" class="input" maxlength="10" maxsize="10" name="password" password")="" size="10" type="password" value="```
28=Request("/>
29</td>
30</tr>
31</table>
32</td></tr>
33<tr><td>
34<table border="0" cellpadding="10" cellspacing="0" width="500"><tr>
35<td align="center" bgcolor="#000000" class="bold2" colspan="2">
36Give Your Poll a Unique Name
37</td>
38</tr><tr>
39<td bgcolor="#ffffff" class="bold" width="25%">Poll Name:</td>
40<td bgcolor="#ffffff">
41<input ```"="" class="input" name="name" name")="" size="20" type="text" value="```
42=Request("/>
43</td>
44</tr>
45</table>
46<table border="0" cellpadding="10" cellspacing="0" width="500"><tr>
47<td align="center" bgcolor="#000000" class="bold2" colspan="2">
48Do you want to have the user enter their name?
49</td>
50</tr><tr>
51<td bgcolor="#ffffff" class="bold" width="25%">Require user to enter their name:</td>
52<td bgcolor="#ffffff" class="bold">
53Yes<input name="GetName" type="radio" value="1"/><br/>
54No <input checked="" name="GetName" type="radio" value="0"/>
55</td>
56</tr>
57</table>
58</td></tr>
59<tr><td>
60<table border="0" cellpadding="10" cellspacing="0" width="500"><tr>
61<td align="center" bgcolor="#000000" class="bold2" colspan="3">
62Select Poll Type
63</td>
64</tr><tr>
65<td bgcolor="#ffffff" class="bold" colspan="2">What type of poll question
66do you wish to create?</td>
67<td bgcolor="#ffffff" class="bold">
68<input name="polltype" type="radio" value="yes_no"/>Yes/No<br/>
69<input name="polltype" type="radio" value="multiple_choice"/>Multiple Choice<br/>
70</td>
71</tr>
72</table>
73</td></tr></table>
74<table width="500"><tr>
75<td align="right" colspan="3">
76<input class="inline" type="submit" value=" Next "/>
77</td></tr>
78</table>
79</font></center>
80</body>
3.文件connect.asp
1
2id = Request("id")
3If id = "" Then
4id = 0
5End If
6num = Request("choice")
7
8If num <> "" Then
9
10Set conn = Server.CreateObject("ADODB.Connection")
11dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; "
12dsnpath = dsnpath & "DBQ=" & Server.MapPath("Events.mdb")
13conn.open dsnpath
14Set rs = Server.CreateObject("ADODB.RecordSet")
15rs.Open "PollResults", conn, 3, 3
16rs.AddNew
17rs("PollID") = Cint(id)
18rs("Name") = Request("Name")
19rs("PollAnswer") = Cint(num)
20rs.Update
21rs.Close
22set rs = Nothing
23conn.Close
24set conn = Nothing
25End If
26
27If Request("return_page") <> Empty Then
28Response.Cookies("PollID") = id
29Response.Redirect Request("return_page")
30End If
1<html>
2<body bgcolor="#4f4f4f" link="#f5fcdc" text="#c0c0c0" vlink="#f5fcdc">
3<center>
4
If num <> "" Then
1<br/><br/>
2<table border="0" cellpadding="0" cellspacing="0"><tr>
3<td align="center" colspan="3"><font face="verdana">
4Your selection has been recorded.
5</font></td></tr>
6</table>
7
End If
1<br/><br/>
Set conn = Server.CreateObject("ADODB.Connection")
sql = "select * from Poll where ID = " & Cint(id)
dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; "
dsnpath = dsnpath & "DBQ=" & Server.MapPath("Events.mdb")
conn.open dsnpath
Set rs = Conn.Execute(sql)
If rs.EOF = False Then
1<table border="1" bordercolor="#2f2f4f" cellpadding="5" cellspacing="0" width="500"><tr>
2<td align="center" bgcolor="#2f2f4f" colspan="3"><font color="#f5fcdc" face="verdana">
=rs("PollQuestion")
1</font></td></tr>
Dim Choices(6)
Dim Responses(6)
For I=1 To 5
choice = rs("Choice" & I)
Choices(I) = choice
If choice <> "" Then
Set conn2 = Server.CreateObject("ADODB.Connection")
sql = "select COUNT(PollAnswer) from PollResults where PollID = " & Cint(id) & " AND PollAnswer=" & I
dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; "
dsnpath = dsnpath & "DBQ=" & Server.MapPath("Events.mdb")
conn2.open dsnpath
Set rs2 = Conn.Execute(sql)
If rs2.EOF = False Then
Response.Write "<tr><td align="center" bgcolor="#4f4f4f" colspan="2" width="400"><font color="#f5fcdc" face="verdana">"
Response.Write choice
Response.Write "</font></td>"
Responses(I) = rs2(0)
Response.Write "<td align="right" bgcolor="#4f4f4f" colspan="1"><font color="#f5fcdc" face="verdana"><b>" & rs2(0) & "</b></font></td>"
Response.Write "</tr>"
End If
rs2.Close
conn2.Close
End If
Next
End If
1
2</table>
3<br/><br/>
4<table>
5<td align="center" colspan="3"><font face="arial">
6<font face="ms sans serif"><b> Polls Results</b></font>
7</font></td>
8
Total = 0
For I=1 To 5
responseCount = Responses(I)
If responseCount <> "" Then
Total = Total + Cint(responseCount)
End If
Next
For I=1 To 5
choice = Choices(I)
responseCount = Responses(I)
If choice <> "" Then
Response.Write "<tr><td align="left" colspan="1"><font face="arial">"
Response.Write choice
Response.Write "</font></td>"
Response.Write "<td colspan="2" width="400"><table border="1" cellspacing="0"><tr><td align="center" bgcolor="blue" width=" & ConvertToPix(responseCount) & "><font color="white" face="ms sans serif"><b>" & ConvertToPercent(responseCount) & "</b></font></td></tr></table></td>"
Response.Write "</tr>"
End If
Next
Function ConvertToPix(sz)
If sz = 0 Then
ConvertToPix = 0
Else
ConvertToPix = Cint(400/Total * sz)
End If
End Function
Function ConvertToPercent(sz)
If sz = 0 Then
ConvertToPercent = "0%"
Else
ConvertToPercent = FormatPercent(sz/Total, 2)
End If
End Function
1
2</table>
3
4
If num = "" Then
1<br/><br/>
2<table border="0" cellpadding="0" cellspacing="0"><tr>
3<td align="center" colspan="3"><font face="verdana">
4<a href="default.asp?ID=```
5=id
6```">Add Your Vote</a>
7</font></td></tr>
8</table>
9
End If
1
2<br/><br/>
3<table width="100%"><tr><td align="right">
4<table border="1" bordercolor="#f5fcdc" cellpadding="5" cellspacing="0"><tr><td bgcolor="#2f2f4f">
5<font face="verdana" size="+1"><a href="javascript:history.back()">Back</a>
6</font></td></tr></table>
7</td></tr></table>
8</center>
9</body>
10</html>