예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text.Trim() == "")
                {
                    MessageBox.Show(@"Enter scholarship id", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (textBox2.Text.Trim() == "")
                {
                    MessageBox.Show(@"Password can not be empty", @"Warning", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    return;
                }

                var con = new MySqlConnection("server=localhost;user id=root;database=kys");

                con.Open();

                var selectQuery = "update scholarship" +
                                  " set confirmation = 'confirmed' where id = " +
                                  textBox1.Text.Trim();
                var sqlCommand = new MySqlCommand(selectQuery, con);
                var dataReader = sqlCommand.ExecuteReader();

                while (dataReader.Read())
                {
                }

                con.Close();

                con.Open();

                selectQuery = "insert into" +
                              " scholarship_confirm values (" +
                              textBox1.Text.Trim() + ", '" +
                              textBox2.Text.Trim() + "')";
                sqlCommand = new MySqlCommand(selectQuery, con);
                try
                {
                    dataReader = sqlCommand.ExecuteReader();
                }
                catch (Exception)
                {
                    MessageBox.Show(@"Scholarship does not exist", @"Warning", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    return;
                }


                while (dataReader.Read())
                {
                }

                con.Close();

                MessageBox.Show(@"Scholarship Confirmed!");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            Close();
            var f = new Registrar();

            f.Show();
        }