private void button_Click(object sender, RoutedEventArgs e) { if (comboBox.SelectedItem.ToString().Equals("") || textBox.Text.Equals("") || textBox1.Text.Equals("")) { MessageBox.Show(("Please Fill All Fields.")); } else { try { string Query1 = "SELECT COUNT(*) from user.blood_bank where group_name='" + comboBox.SelectedItem.ToString() + "';"; MySqlCommand MyCommand = new MySqlCommand(Query1, conn); result = int.Parse(MyCommand.ExecuteScalar().ToString()); //MessageBox.Show(testing().ToString()); if (testing().ToString().Equals("True")) { string Query = "insert into user.blood_bank values ('" + comboBox.SelectedItem + "','" + textBox.Text + "','" + textBox1.Text + "');"; MySqlCommand MyCommand2 = new MySqlCommand(Query, conn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Blood Added . . ."); MyReader2.Close(); textBox.Text = ""; textBox1.Text = ""; comboBox.Text = ""; LoadBloodBank(); } else if (testing().ToString().Equals("False")) { string v = ""; int j = 0; string Query01 = "SELECT quantity from user.blood_bank where group_name='" + comboBox.SelectedItem + "';"; MySqlCommand MyCommand01 = new MySqlCommand(Query01, conn); MySqlDataReader MyReader01; MyReader01 = MyCommand01.ExecuteReader(); while (MyReader01.Read()) { v = MyReader01.GetString(0); j = Int32.Parse(MyReader01.GetString(0)); MessageBox.Show(j.ToString()); } MyReader01.Close(); int i = Int32.Parse(textBox.Text); j = j + i; v = j.ToString(); string Query = "update user.blood_bank set quantity='" + v + "',storage_date='" + textBox1.Text + "' where group_name='" + comboBox.SelectedItem + "';"; MySqlCommand MyCommand2 = new MySqlCommand(Query, conn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Blood Updated . . ."); MyReader2.Close(); textBox.Text = ""; textBox1.Text = ""; comboBox.Text = ""; LoadBloodBank(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void button_Click(object sender, RoutedEventArgs e) { //try //{ conn.Open(); string Query1 = "SELECT COUNT(*) from user.blood_bank where group_name='" + comboBox.SelectedItem + "';"; MySqlCommand MyCommand = new MySqlCommand(Query1, conn); MySqlDataReader MyReader; MyReader = MyCommand.ExecuteReader(); //while(MyReader.Read()) //{ test = MyReader.Read().ToString(); MessageBox.Show(test); //} MyReader.Close(); if (test.Equals("False")) { string Query = "insert into user.blood_bank values ('" + comboBox.SelectedItem + "','" + textBox.Text + "','" + textBox1.Text + "');"; MySqlCommand MyCommand2 = new MySqlCommand(Query, conn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Blood Added . . ."); conn.Close(); MyReader2.Close(); textBox.Text = ""; textBox1.Text = ""; comboBox.Text = ""; LoadBloodBank(); } else if (test.Equals("True")) { string v = ""; int j; string Query01 = "SELECT quantity from user.blood_bank where group_name='" + comboBox.SelectedItem + "';"; MySqlCommand MyCommand01 = new MySqlCommand(Query01, conn); MySqlDataReader MyReader01; MyReader01 = MyCommand.ExecuteReader(); //v=MyReader01.Read().ToString(); while (MyReader01.Read()) { v = MyReader01.GetString(0); //j = Int32.Parse(MyReader01.GetString(0)); MessageBox.Show(v.ToString()); } MyReader01.Close(); //int i = Int32.Parse(textBox.Text); //j = j + i; //v = j.ToString(); //string Query = "update user.blood_bank set quantity='"+v+"',storage_date='"+textBox1.Text+"' where group_name='"+comboBox.SelectedItem+"';"; //MySqlCommand MyCommand2 = new MySqlCommand(Query, conn); //MySqlDataReader MyReader2; //MyReader2 = MyCommand2.ExecuteReader(); //MessageBox.Show("Blood Added . . ."); //MyReader2.Close(); //textBox.Text = ""; textBox1.Text = ""; //comboBox.Text = ""; //LoadBloodBank(); } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} }