public void Transfer() { DbConnection.Instance().OpenConnection(); // đảm bảo rằng đã kết nối đến db thành công. Console.WriteLine("Transfer."); Console.WriteLine("---------------------------------"); Console.WriteLine("Please enter ReceiverAccountNumber: "); var accountNumber = Console.ReadLine(); // 1. Lấy thông tin số dư mới nhất của tài khoản. DbConnection.Instance().OpenConnection(); var queryString = "select * from `account` where accountNumber = @accountNumber"; var cmd = new MySqlCommand(queryString, DbConnection.Instance().Connection); cmd.Parameters.AddWithValue("@accountNumber", accountNumber); var reader = cmd.ExecuteReader(); var isExist = reader.Read(); if (!isExist) { throw new SpringHeroTransactionException("Invalid accountNumber"); } DbConnection.Instance().CloseConnection(); Console.WriteLine("Please enter amount to transfer: "); var amount = Utility.GetUnsignDecimalNumber(); Console.WriteLine("Please enter message content: "); var content = Console.ReadLine(); var historyTransaction = new YYTransaction { Id = Guid.NewGuid().ToString(), Type = YYTransaction.TransactionType.TRANSFER, Amount = amount, Content = content, SenderAccountNumber = Program.currentLoggedInYyAccount.AccountNumber, ReceiverAccountNumber = accountNumber, Status = YYTransaction.ActiveStatus.DONE }; if (model.YTransaction(accountNumber, historyTransaction)) { Console.WriteLine("Transaction success!"); } else { Console.WriteLine("Transaction fails, please try again!"); } Program.currentLoggedInYyAccount = model.GetByUsername(Program.currentLoggedInYyAccount.Username); Console.WriteLine("Current balance: " + Program.currentLoggedInYyAccount.Balance); Console.WriteLine("Press enter to continue!"); Console.ReadLine(); }