By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

a poll system with different condition

P: 1
hi guy,

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
  1. Protected Sub rp_polls_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rp_polls.ItemCommand
  2.  
  3.         Dim alIn As ArrayList = New ArrayList
  4.         Dim mclas As ExodusG2.dbOps = New ExodusG2.dbOps
  5.         Dim ssql As String
  6.  
  7.         Dim r As RadioButtonList
  8.         Dim strID As String
  9.         r = e.Item.FindControl("rblAnswer")
  10.  
  11.         strID = r.SelectedValue
  12.         ViewState("AnswerID") = strID
  13.  
  14.         Dim lbl As Label
  15.         lbl = e.Item.FindControl("lblError")
  16.  
  17.         sLanguageCodeAndID = xTool.getPublicLanguage
  18.         sLanguageID = Right(sLanguageCodeAndID, 36)
  19.         sLanguageCode = Left(sLanguageCodeAndID, 5)
  20.         sDefaultLanguageCode = Left(xTool.getDefaultLanguage, 5) & "_"
  21.  
  22.  
  23.         If e.CommandName = "Vote" Then
  24.  
  25.             If strID = "" Then
  26.  
  27.                 lbl.Text = xTool.getStatictext("9cfebdd1-7cc9-4e33-8707-943e0265fab5", sLanguageID, sDefaultLanguageCode)
  28.                 lbl.Visible = True
  29.                 MessageBox(xTool.getStatictext("9cfebdd1-7cc9-4e33-8707-943e0265fab5", sLanguageID, sDefaultLanguageCode))
  30.                 Exit Sub
  31.             End If
  32.  
  33.  
  34.             Dim GUID As String = System.Guid.NewGuid.ToString
  35.  
  36.             'Dim aCookie As New HttpCookie("userInfo")
  37.             'aCookie.Values("userName") = "patrick"
  38.             'aCookie.Values("lastVisit") = DateTime.Now.ToString()
  39.             'aCookie.Expires = DateTime.Now.AddDays(1)
  40.             'Response.Cookies.Add(aCookie)
  41.  
  42.             Dim oCookiedu As New HttpCookie("VotedResultDu")
  43.             Dim oCookieda As New HttpCookie("VotedResultDa")
  44.             Dim oCookiem As New HttpCookie("VotedResultM")
  45.  
  46.             'single Vote
  47.             If ViewState(ViewState("QID") & "condition") = "1" Then
  48.                 If ViewState(ViewState("QID") & "sCondition") = "1" Then
  49.                     If oCookiedu.Values(e.CommandArgument) Is Nothing Then
  50.                         oCookiedu.Values(e.CommandArgument) = e.CommandArgument
  51.                         oCookiedu.Expires = DateTime.Now.AddDays(600)
  52.                         Response.Cookies.Add(oCookiedu)
  53.  
  54.                         'oCookie.Expires = DateTime.Now.AddDays(600)
  55.                         'ViewState("QDuID") = e.CommandArgument
  56.                         'oCookie.Value = e.CommandArgument
  57.                         'Response.Cookies.Add(oCookie)
  58.                         lbl.Visible = False
  59.  
  60.                         'Insert Records
  61.                         ssql = "Insert into PollResult (pollResultID,pollID,pollAnswerID,IP_address,pollResult_addDate,pollResult_status,websiteID) values (@param1,@param2,@param3,@param4,@param5,@param6,@param7)"
  62.  
  63.                         alIn.Clear()
  64.                         alIn.Add(System.Guid.NewGuid.ToString)
  65.                         alIn.Add(ViewState("QID"))
  66.                         alIn.Add(ViewState("AnswerID"))
  67.                         alIn.Add(Request.ServerVariables("REMOTE_ADDR"))
  68.                         alIn.Add(Date.Now.ToString)
  69.                         alIn.Add("1")
  70.                         'Corp site
  71.                         alIn.Add("25e2f6f0-d842-4457-a613-409c6088fad3")
  72.                         mclas.execute_query(ssql, alIn)
  73.  
  74.                         Response.Write("Duration")
  75.                         Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
  76.  
  77.                     Else
  78.                         Response.Write("Duration failed")
  79.                         'Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
  80.  
  81.                     End If
  82.  
  83.                 Else
  84.                     If oCookiedu.Values(e.CommandArgument) Is Nothing Then
  85.                         oCookiedu.Expires = DateTime.Now.AddDays(1)
  86.  
  87.                         ViewState("QID") = e.CommandArgument
  88.                         oCookiedu.Value = e.CommandArgument
  89.                         Response.Cookies.Add(oCookiedu)
  90.                         lbl.Visible = False
  91.  
  92.                         'Insert Records
  93.                         ssql = "Insert into PollResult (pollResultID,pollID,pollAnswerID,IP_address,pollResult_addDate,pollResult_status,websiteID) values (@param1,@param2,@param3,@param4,@param5,@param6,@param7)"
  94.  
  95.                         alIn.Clear()
  96.                         alIn.Add(System.Guid.NewGuid.ToString)
  97.                         alIn.Add(ViewState("QID"))
  98.                         alIn.Add(ViewState("AnswerID"))
  99.                         alIn.Add(Request.ServerVariables("REMOTE_ADDR"))
  100.                         alIn.Add(Date.Now.ToString)
  101.                         alIn.Add("1")
  102.                         'Corp site
  103.                         alIn.Add("25e2f6f0-d842-4457-a613-409c6088fad3")
  104.                         mclas.execute_query(ssql, alIn)
  105.  
  106.                         Response.Write("Day")
  107.                         'Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
  108.  
  109.                     Else
  110.                         Response.Write("Day failed")
  111.                         'Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
  112.  
  113.                     End If
  114.  
  115.                 End If
  116.  
  117.                 ' multiple vote
  118.             Else
  119.                 oCookiem.Expires = DateTime.Now.AddDays(-1)
  120.                 Response.Cookies.Add(oCookiem)
  121.  
  122.                 ViewState("QID") = e.CommandArgument
  123.                 oCookiem.Value = e.CommandArgument
  124.                 Response.Cookies.Add(oCookiem)
  125.                 lbl.Visible = False
  126.  
  127.                 'Insert Records
  128.                 ssql = "Insert into PollResult (pollResultID,pollID,pollAnswerID,IP_address,pollResult_addDate,pollResult_status,websiteID) values (@param1,@param2,@param3,@param4,@param5,@param6,@param7)"
  129.  
  130.                 alIn.Clear()
  131.                 alIn.Add(System.Guid.NewGuid.ToString)
  132.                 alIn.Add(ViewState("QID"))
  133.                 alIn.Add(ViewState("AnswerID"))
  134.                 alIn.Add(Request.ServerVariables("REMOTE_ADDR"))
  135.                 alIn.Add(Date.Now.ToString)
  136.                 alIn.Add("1")
  137.                 'Corp site
  138.                 alIn.Add("25e2f6f0-d842-4457-a613-409c6088fad3")
  139.                 mclas.execute_query(ssql, alIn)
  140.  
  141.                 Response.Write("Multiple")
  142.                 'Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
  143.  
  144.             End If
  145.  
  146.         End If
  147.         If e.CommandName = "Result" Then
  148.             Response.Redirect("result_polls.aspx?pollID=" & e.CommandArgument & "")
  149.         End If
  150.  
  151.     End Sub
  152.  
Dec 22 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.