private void update_Click(object sender, RoutedEventArgs e) { iduser idus = new iduser(); int ID = idus.getiduser(); String id = Convert.ToString(ID); DB db = new DB(); MySqlCommand command = new MySqlCommand("SELECT `balance` FROM `users` WHERE `id` = @ID", db.GetConnection()); command.Parameters.Add("@ID", MySqlDbType.VarChar).Value = id; db.openConnection(); string balance = command.ExecuteScalar().ToString(); balanceuser.Text = balance; db.closeConnection(); }
private void Button_Click_11(object sender, RoutedEventArgs e) { int cash = Convert.ToInt32(cashuser.Text); DB db = new DB(); iduser idus = new iduser(); int ID = idus.getiduser(); String id = Convert.ToString(ID); MySqlCommand command = new MySqlCommand("SELECT `balance` FROM `users` WHERE `id` = @ID", db.GetConnection()); command.Parameters.Add("@ID", MySqlDbType.VarChar).Value = id; db.openConnection(); string balanc_user = command.ExecuteScalar().ToString(); int cash_user = Convert.ToInt32(balanc_user); Menu menu = new Menu(); if (cash <= cash_user) { cash_user = cash_user - cash; MySqlCommand command_2 = new MySqlCommand("UPDATE `users` SET `balance` = @balance WHERE `id` = @ID", db.GetConnection()); command_2.Parameters.Add("@ID", MySqlDbType.VarChar).Value = id; command_2.Parameters.AddWithValue("balance", cash_user); command_2.ExecuteNonQueryAsync(); db.closeConnection(); MessageBox.Show("Операція здійснена успішно!"); MySqlCommand command_3 = new MySqlCommand("SELECT * FROM `balance`", db.GetConnection()); db.openConnection(); string balanc_bankomat = command_3.ExecuteScalar().ToString(); MySqlCommand command_4 = new MySqlCommand("UPDATE `balance` SET `balance` = @balance", db.GetConnection()); int cash_bankomat = Convert.ToInt32(balanc_bankomat); cash_bankomat = cash_bankomat - cash; command_4.Parameters.AddWithValue("balance", cash_bankomat); command_4.ExecuteNonQueryAsync(); db.closeConnection(); this.Close(); menu.Show(); } else { MessageBox.Show("Недостатньо коштів!"); this.Close(); menu.Show(); } }