Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                //Open database connection
                DBConnect();

                //Specify the SQL statement and stored procedure name to execute
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton1.Text); // Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);                                                                    //Specify the SQL statement to execute
                try
                {
                    command.ExecuteScalar();//Loop the entire object
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);//Interface conversion function
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();//close the connection
                }
            }
            if (radioButton2.Checked)
            {
                //Open database connection
                DBConnect();

                //Specify the SQL statement and stored procedure name to execute
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton2.Text); // Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);                                                                    //Specify the SQL statement to execute
                try
                {
                    command.ExecuteScalar();//Loop the entire object
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);//Interface conversion function
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();//close the connection
                }
            }
            if (radioButton3.Checked)
            {
                //Open database connection
                DBConnect();

                //Specify the SQL statement and stored procedure name to execute
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton3.Text); // Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);                                                                    //Specify the SQL statement to execute
                try
                {
                    command.ExecuteScalar();//Loop the entire object
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);//Interface conversion function
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();//close the connection
                }
            }
            if (radioButton4.Checked)
            {
                //Open database connection
                DBConnect();

                //Specify the SQL statement and stored procedure name to execute
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton4.Text); // Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);                                                                    //Specify the SQL statement to execute
                try
                {
                    command.ExecuteScalar();//Loop the entire object
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);//Interface conversion function
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();//close the connection
                }
            }
            if (radioButton5.Checked)
            {
                //Open database connection
                DBConnect();

                //Specify the SQL statement and stored procedure name to execute
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton5.Text); // Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);                                                                    //Specify the SQL statement to execute
                try
                {
                    command.ExecuteScalar();//Loop the entire object
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);//Interface conversion function
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();//close the connection
                }
            }
            if (radioButton6.Checked)
            {
                //Open database connection
                DBConnect();

                //Specify the SQL statement and stored procedure name to execute
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton6.Text); // Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);                                                                    //Specify the SQL statement to execute
                try
                {
                    command.ExecuteScalar();//Loop the entire object
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);//Interface conversion function
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();//close the connection
                }
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                DBConnect();

                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton1.Text);// Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);
                try
                {
                    command.ExecuteScalar();
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();
                }
            }
            if (radioButton2.Checked)
            {
                DBConnect();
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton2.Text);// Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);
                try
                {
                    command.ExecuteScalar();
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();
                }
            }
            if (radioButton3.Checked)
            {
                DBConnect();
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton3.Text);// Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);
                try
                {
                    command.ExecuteScalar();
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();
                }
            }
            if (radioButton4.Checked)
            {
                DBConnect();
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton4.Text);// Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);
                try
                {
                    command.ExecuteScalar();
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();
                }
            }
            if (radioButton5.Checked)
            {
                DBConnect();
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton5.Text);// Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);
                try
                {
                    command.ExecuteScalar();
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();
                }
            }
            if (radioButton6.Checked)
            {
                DBConnect();
                strsql  = string.Format("update Candidate set VoteNum = VoteNum +1 where Name = '{0}'", radioButton6.Text);// Voting candidate's vote +1
                command = new SqlCommand(strsql, mycon);
                try
                {
                    command.ExecuteScalar();
                    MessageBox.Show("Successfully Voting.");

                    HomePage HomePage = new HomePage();
                    this.Hide();
                    HomePage.ShowDialog(this);
                }
                catch
                {
                    MessageBox.Show("Voting Error.");
                }
                //Check register
                finally
                {
                    mycon.Close();
                }
            }
        }