1
私はプログラミングとC#を初めて使いました。小さな電子投票システムを作ろうとしています。投票者が余分な数の候補者に投票すると、票を無効にする方法はありますか?例:ユーザーが評議員の位置に7つの候補の代わりに、6を投票し、どのように私は彼の投票は無効にすることができたり、彼がそれ6.データの妥当性確認
private void btn_submit_Click(object sender, EventArgs e)
{
con.Open();
if (MessageBox.Show("Confirm and View your Votes?", "Close Application", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
MessageBox.Show("Voting Successful", "Application Closed!", MessageBoxButtons.OK);
using (SqlCommand command = new SqlCommand("UPDATE candidate SET cTally = cTally + 1 where cName like @cname or cName like @vName", con))
{
command.Parameters.AddWithValue("@cname", cb_president.Text);
command.Parameters.AddWithValue("@vName", cb_vpresident.Text);
command.ExecuteNonQuery();
}
foreach (object item in lb_councilor.SelectedItems)
{
using (SqlCommand command = new SqlCommand("UPDATE candidate SET cTally = cTally + 1 where cName like @coname", con))
{
command.Parameters.AddWithValue("@coname", (item as DataRowView)["cName"].ToString());
Console.WriteLine((item as DataRowView)["cName"].ToString());
command.ExecuteNonQuery();
}
using (SqlCommand command = new SqlCommand("UPDATE voters SET isVoted = 1 where userName like @uname", con))
{
command.Parameters.AddWithValue("@uname", userid);
command.ExecuteNonQuery();
}
}
this.Close();
new Form4().Show();
this.Hide();
}
else
{
this.Activate();
}
}
private void Frm_voteview_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Properties.Settings.Default.VotingSystemv2ConnectionString);
con.Open();
// TODO: This line of code loads data into the 'votingSystemv2DataSet7.candidate' table. You can move, or remove it, as needed.
this.candidateTableAdapter2.Fill(this.votingSystemv2DataSet7.candidate);
// TODO: This line of code loads data into the 'votingSystemv2DataSet5.candidate' table. You can move, or remove it, as needed.
this.candidateTableAdapter1.Fill(this.votingSystemv2DataSet5.candidate);
// TODO: This line of code loads data into the 'votingSystemv2DataSet4.candidate' table. You can move, or remove it, as needed.
this.candidateTableAdapter.Fill(this.votingSystemv2DataSet4.candidate);
}
private void dgv_councilor_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
}
private void dgv_councilor_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
}
private void Frm_voteview_FormClosed(object sender, FormClosedEventArgs e)
{
SqlConnection con = new SqlConnection(Properties.Settings.Default.VotingSystemv2ConnectionString);
// TODO: This line of code loads data into the 'votingSystemv2DataSet7.candidate' table. You can move, or remove it, as needed.
this.candidateTableAdapter2.Fill(this.votingSystemv2DataSet7.candidate);
// TODO: This line of code loads data into the 'votingSystemv2DataSet5.candidate' table. You can move, or remove it, as needed.
this.candidateTableAdapter1.Fill(this.votingSystemv2DataSet5.candidate);
// TODO: This line of code loads data into the 'votingSystemv2DataSet4.candidate' table. You can move, or remove it, as needed.
this.candidateTableAdapter.Fill(this.votingSystemv2DataSet4.candidate);
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
new Form9().Show();
}
private void cb_president_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void lb_councilor_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
そこからあなたが票を得るコントロール:より詳細には
、あなたのオブジェクトは、次のようになります。これは、より多くのように見えるのでしょうか? –
投票権を得たコントロールはどういう意味ですか? @EmrahSüngü –
私はあなたのコードを完全に読むことができませんでしたが、私はあなたが誰が投票したのかわかりません。編集:ああ、あなたは直接テーブルを更新している –