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(); } }
public void Button_Click_11(object sender, RoutedEventArgs e) { String NumberUser = numberuser.Text; String PinUser = pinuser.Password; DB db = new DB(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand("SELECT `id` FROM `users` WHERE `number` = @UN AND `pin` = @UP", db.GetConnection()); command.Parameters.Add("@UN", MySqlDbType.VarChar).Value = NumberUser; command.Parameters.Add("@UP", MySqlDbType.Int64).Value = PinUser; adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { db.openConnection(); string update = command.ExecuteScalar().ToString(); int iduser = Convert.ToInt32(update); iduser idus = new iduser(); idus.setiduser(iduser); db.closeConnection(); MessageBox.Show("Успішний вхід!", "Повідомлення"); Menu Menu = new Menu(); this.Close(); Menu.Show(); } else { MessageBox.Show("Не правильний номер картки або ПІН-код!", "Повідомлення"); pinuser.Password = ""; numberuser.Text = ""; } }