我希望有一个投票系统,注册学生只能投票一次。我有这个代码,我使用注册的Firstname和Surname作为他们的登录访问。你能帮助我们,我怎么可能让投票的学生已经损害了他/她两次投票的权利?谢谢。
Private Sub MetroButton2_Click(sender As Object, e As EventArgs) Handles MetroButton2.Click
Dim sql As String
If FirstName2MetroTextBox.Text = "" Then
MsgBox("Type in your First Name.")
ElseIf SurnameMetroTextBox.Text = "" Then
MsgBox("Type in your Surname.")
Else
Try
If FirstName2MetroTextBox.Text = "" And SurnameMetroTextBox.Text = "" Then
MsgBox("First Name and Surname doesn't match.")
Else
sql = "select * from student_registrants where Firstname = '" & FirstName2MetroTextBox.Text & "' and Surname = '" & SurnameMetroTextBox.Text & "'"
With cmd
.Connection = conn
.CommandText = sql
End With
Timer1.Start()
da.Dispose()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Clone()
End If
End Sub
它最终将登录我的投票表格。在他/她选择了他/她想要的候选人之后,我制作了这段代码。
Private Sub TileItem26_ItemClick(sender As Object, e As DevExpress.XtraEditors.TileItemEventArgs) Handles ConfirmTileItem.ItemClick
If PresidentMetroLabel.Text = "" Then
MsgBox("Choose your next President.")
ElseIf VicePresidentMetroLabel.Text = "" Then
MsgBox("Choose your next Vice President.")
ElseIf SecretaryMetroLabel.Text = "" Then
MsgBox("Choose your next Secretary.")
ElseIf AuditorMetroLabel.Text = "" Then
MsgBox("Choose your next Auditor.")
ElseIf Senator1MetroLabel.Text = "" Then
MsgBox("Choose your next Senator(s).")
ElseIf Senator2MetroLabel.Text = "" Then
MsgBox("Choose your next Senator(s).")
ElseIf Senator3MetroLabel.Text = "" Then
MsgBox("Choose your next Senator(s).")
ElseIf Senator4MetroLabel.Text = "" Then
MsgBox("Choose your next Senator(s).")
Else
Try
conn.ConnectionString = ("server=localhost;user id=root;password=;database=university_election")
conn.Open()
With cmd
.Connection = conn
.CommandText = "UPDATE `election_tally_presidents` SET Votes = Votes + 1 WHERE President_ID = '" & presidentint & "'; UPDATE `election_tally_vicepresidents` SET Votes = Votes + 1 WHERE VicePresident_ID = '" & vicepresidentint & "'; UPDATE `election_tally_secretary` SET Votes = Votes + 1 WHERE Secretary_ID = '" & secretaryint & "'; UPDATE `election_tally_auditor` SET Votes = Votes + 1 WHERE Auditor_ID = '" & auditorint & "'; UPDATE `election_tally_senators` SET Votes = Votes + 1 WHERE Senator_ID = '" & senator1int & "'; UPDATE `election_tally_senators` SET Votes = Votes + 1 WHERE Senator_ID = '" & senator2int & "'; UPDATE `election_tally_senators` SET Votes = Votes + 1 WHERE Senator_ID = '" & senator3int & "'; UPDATE `election_tally_senators` SET Votes = Votes + 1 WHERE Senator_ID = '" & senator4int & "';"
result = cmd.ExecuteNonQuery
Timer1.Start()
MetroProgressBar1.Show()
MetroLabel1.Visible = True
End With
Catch ex As Exception
MsgBox("Cannot register to the database: " & ex.Message)
Finally
conn.Dispose()
End Try
End If
End Sub
那么最符合我系统的代码是什么?谢谢。