My question is to create a poll system for basically 2 condition which is single vote and mulitiple vote per poll.
For the single vote, it can be single vote per day or per duration.
In our system there is a few poll to vote. But the code that i had implement unable to remember the cookie base on the poll.
I am a newbie in vb.net.
I think i should use the HttpCookieCollection to differentiate the cookies that i want to store. But Can you guys give me some guide?
Really hope you guys can help.
thanks! ^^
this is part of the code.
Expand|Select|Wrap|Line Numbers
- Protected Sub rp_polls_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rp_polls.ItemCommand
- Dim alIn As ArrayList = New ArrayList
- Dim mclas As ExodusG2.dbOps = New ExodusG2.dbOps
- Dim ssql As String
- Dim r As RadioButtonList
- Dim strID As String
- r = e.Item.FindControl("rblAnswer")
- strID = r.SelectedValue
- ViewState("AnswerID") = strID
- Dim lbl As Label
- lbl = e.Item.FindControl("lblError")
- sLanguageCodeAndID = xTool.getPublicLanguage
- sLanguageID = Right(sLanguageCodeAndID, 36)
- sLanguageCode = Left(sLanguageCodeAndID, 5)
- sDefaultLanguageCode = Left(xTool.getDefaultLanguage, 5) & "_"
- If e.CommandName = "Vote" Then
- If strID = "" Then
- lbl.Text = xTool.getStatictext("9cfebdd1-7cc9-4e33-8707-943e0265fab5", sLanguageID, sDefaultLanguageCode)
- lbl.Visible = True
- MessageBox(xTool.getStatictext("9cfebdd1-7cc9-4e33-8707-943e0265fab5", sLanguageID, sDefaultLanguageCode))
- Exit Sub
- End If
- Dim GUID As String = System.Guid.NewGuid.ToString
- 'Dim aCookie As New HttpCookie("userInfo")
- 'aCookie.Values("userName") = "patrick"
- 'aCookie.Values("lastVisit") = DateTime.Now.ToString()
- 'aCookie.Expires = DateTime.Now.AddDays(1)
- 'Response.Cookies.Add(aCookie)
- Dim oCookiedu As New HttpCookie("VotedResultDu")
- Dim oCookieda As New HttpCookie("VotedResultDa")
- Dim oCookiem As New HttpCookie("VotedResultM")
- 'single Vote
- If ViewState(ViewState("QID") & "condition") = "1" Then
- If ViewState(ViewState("QID") & "sCondition") = "1" Then
- If oCookiedu.Values(e.CommandArgument) Is Nothing Then
- oCookiedu.Values(e.CommandArgument) = e.CommandArgument
- oCookiedu.Expires = DateTime.Now.AddDays(600)
- Response.Cookies.Add(oCookiedu)
- 'oCookie.Expires = DateTime.Now.AddDays(600)
- 'ViewState("QDuID") = e.CommandArgument
- 'oCookie.Value = e.CommandArgument
- 'Response.Cookies.Add(oCookie)
- lbl.Visible = False
- 'Insert Records
- ssql = "Insert into PollResult (pollResultID,pollID,pollAnswerID,IP_address,pollResult_addDate,pollResult_status,websiteID) values (@param1,@param2,@param3,@param4,@param5,@param6,@param7)"
- alIn.Clear()
- alIn.Add(System.Guid.NewGuid.ToString)
- alIn.Add(ViewState("QID"))
- alIn.Add(ViewState("AnswerID"))
- alIn.Add(Request.ServerVariables("REMOTE_ADDR"))
- alIn.Add(Date.Now.ToString)
- alIn.Add("1")
- 'Corp site
- alIn.Add("25e2f6f0-d842-4457-a613-409c6088fad3")
- mclas.execute_query(ssql, alIn)
- Response.Write("Duration")
- Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
- Else
- Response.Write("Duration failed")
- 'Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
- End If
- Else
- If oCookiedu.Values(e.CommandArgument) Is Nothing Then
- oCookiedu.Expires = DateTime.Now.AddDays(1)
- ViewState("QID") = e.CommandArgument
- oCookiedu.Value = e.CommandArgument
- Response.Cookies.Add(oCookiedu)
- lbl.Visible = False
- 'Insert Records
- ssql = "Insert into PollResult (pollResultID,pollID,pollAnswerID,IP_address,pollResult_addDate,pollResult_status,websiteID) values (@param1,@param2,@param3,@param4,@param5,@param6,@param7)"
- alIn.Clear()
- alIn.Add(System.Guid.NewGuid.ToString)
- alIn.Add(ViewState("QID"))
- alIn.Add(ViewState("AnswerID"))
- alIn.Add(Request.ServerVariables("REMOTE_ADDR"))
- alIn.Add(Date.Now.ToString)
- alIn.Add("1")
- 'Corp site
- alIn.Add("25e2f6f0-d842-4457-a613-409c6088fad3")
- mclas.execute_query(ssql, alIn)
- Response.Write("Day")
- 'Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
- Else
- Response.Write("Day failed")
- 'Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
- End If
- End If
- ' multiple vote
- Else
- oCookiem.Expires = DateTime.Now.AddDays(-1)
- Response.Cookies.Add(oCookiem)
- ViewState("QID") = e.CommandArgument
- oCookiem.Value = e.CommandArgument
- Response.Cookies.Add(oCookiem)
- lbl.Visible = False
- 'Insert Records
- ssql = "Insert into PollResult (pollResultID,pollID,pollAnswerID,IP_address,pollResult_addDate,pollResult_status,websiteID) values (@param1,@param2,@param3,@param4,@param5,@param6,@param7)"
- alIn.Clear()
- alIn.Add(System.Guid.NewGuid.ToString)
- alIn.Add(ViewState("QID"))
- alIn.Add(ViewState("AnswerID"))
- alIn.Add(Request.ServerVariables("REMOTE_ADDR"))
- alIn.Add(Date.Now.ToString)
- alIn.Add("1")
- 'Corp site
- alIn.Add("25e2f6f0-d842-4457-a613-409c6088fad3")
- mclas.execute_query(ssql, alIn)
- Response.Write("Multiple")
- 'Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
- End If
- End If
- If e.CommandName = "Result" Then
- Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
- End If
- End Sub