public static void DeleteAccount(string iban) { string sqlIdAccount = $"select idUserAccount from user_account where iban = @iban;"; MySqlCommand command = DataBaseOperations.GetCommand(sqlIdAccount, new MySqlParameter[] { new MySqlParameter("@iban", iban) }); command.Connection.Open(); int id = Convert.ToInt32(command.ExecuteScalar()); string sqlClosureAccount = "insert into account_closure " + "(idUserAccount, Iban, FullName, Egn, Gender, Address, PostalCode, City, " + "Country, MobilePhone, HomePhone, Email, DataOfAccount) " + "select * from user_account as ua where ua.iban = @iban;"; command.CommandText = sqlClosureAccount; command.ExecuteScalar(); string sqlDelete = $"delete from user_account where iban = @iban;"; command.CommandText = sqlDelete; command.ExecuteScalar(); //Get fee //insert string sqlFeeChargesAccount = $"insert into fee_charges_account_closure" + $"(idUserAccount, date_fee, amount) values (" + $"@idUserAccount," + $"@date_fee," + $"@amount);"; MySqlParameter[] parameterFee = { new MySqlParameter("@idUserAccount", id), new MySqlParameter("@date_fee", DateTime.Now), new MySqlParameter("@amount", feeDeleteAccount.ToString().Replace(",", ".")) }; command.CommandText = sqlFeeChargesAccount; command.Parameters.AddRange(parameterFee); command.ExecuteScalar(); command.Connection.Close(); }
/// <summary> /// Retains the transfer service data in the database table /// and the transfer fee in another table /// </summary> /// <param name="sender"></param> /// <param name="receiver"></param> /// <param name="amountTransfer"></param> public static void TransferMoney(AccountCustomer sender, AccountCustomer receiver, decimal amountTransfer) { try { if (sender.Iban == null) { throw new ArgumentException("Sender IBAN is null."); } if (DataBaseOperations.getBalance(sender.Iban).Balance >= amountTransfer + GetFeeTransfer(amountTransfer)) { string sqlSender = $"select idUserAccount from user_account where iban = @ibanSender;"; MySqlCommand command = DataBaseOperations.GetCommand(sqlSender, new MySqlParameter[] { new MySqlParameter("@ibanSender", sender.Iban) }); command.Connection.Open(); int pkSender = Convert.ToInt32(command.ExecuteScalar()); string sqlReseiver = $"select idUserAccount from user_account where iban = @ibanReceiver;"; command.CommandText = sqlReseiver; command.Parameters.AddWithValue("@ibanReceiver", receiver.Iban); int pkReceiver = Convert.ToInt32(command.ExecuteScalar()); //Transfer string sqlTransfer = $"insert into transfer_customer" + $"(IDSender_Customer, IDRecipient_Customer, DataOfTransfer, Amount_Transfer) values (" + $"@IDSender_Customer," + $"@IDRecipient_Customer," + $"@DataOfTransfer," + $"@Amount_Transfer)"; MySqlParameter[] parametersTransfer = { new MySqlParameter("@IDSender_Customer", pkSender), new MySqlParameter("@IDRecipient_Customer", pkReceiver), new MySqlParameter("@DataOfTransfer", DateTime.Now), new MySqlParameter("@Amount_Transfer", amountTransfer.ToString().Replace(",", ".")) }; command.CommandText = sqlTransfer; command.Parameters.AddRange(parametersTransfer); command.ExecuteScalar(); //Get Fee //INSERT string sqlChargesTransfer = $"insert into fee_charges_transfer" + $"(iduser_account, date_fee, amount) values (" + $"@iduser_account," + $"@date_fee," + $"@amount)"; MySqlParameter[] parametersChargesTransfer = { new MySqlParameter("@iduser_account", pkSender), new MySqlParameter("@date_fee", DateTime.Now), new MySqlParameter("@amount", GetFeeTransfer(amountTransfer).ToString().Replace(",", ".")) }; command.CommandText = sqlChargesTransfer; command.Parameters.AddRange(parametersChargesTransfer); command.ExecuteScalar(); command.Connection.Close(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }