private static bool CheckAmountInput(string amount, string userName) // eos position 6 { bool isNotDecimal = false; decimal num = 0.00m; if (!decimal.TryParse(amount, out num)) { Console.Clear(); string message = "Not valid input!"; ConsoleLayout.Attention(message, 0); ConsoleLayout.Position(2); Console.WriteLine("To choose a correct amount please press 'Enter'"); ConsoleLayout.Position(4); Console.WriteLine("To go back to menou please type 'M' and press enter"); string message1 = "What's this?"; ConsoleLayout.Speech(message1, -4); ConsoleLayout.Position(6); string userinput = Convert.ToString(Console.ReadLine()); if ((userinput == "M") || (userinput == "m")) { ShowMenus.ChooseUser(userName); } isNotDecimal = true; Console.Clear(); } return(isNotDecimal); }
private static bool CheckUsernameToTransfer(string userName, string userToTransfer)// eos position 6 { string query = "SELECT COUNT (username) FROM users WHERE username = '******'"; int result = Convert.ToInt32(AddQuerryInt(query)); bool invalidUsername = false; if (result == 0.000) { Console.Clear(); string message = "The user you are looking for does not exists."; ConsoleLayout.Attention(message, 0); ConsoleLayout.Position(2); Console.WriteLine("To choose an other username please press 'Enter'"); ConsoleLayout.Position(4); Console.WriteLine(" To go back to menou please type 'M'"); string message1 = "Who's that?"; ConsoleLayout.Speech(message1, -4); ConsoleLayout.Position(6); string userinput = Convert.ToString(Console.ReadLine()); if ((userinput == "M") || (userinput == "m")) { ShowMenus.ChooseUser(userName); } invalidUsername = true; } return(invalidUsername); }
public static void Withdraw(string userName) { string userToWithdraw = ""; string message1 = "Please choose the name of the user you wish to withdraw from: "; userToWithdraw = CheckUserToTransferMethod(userName, userToWithdraw, message1); string amount = ""; string message2 = "Please insert the amount to be withdrawn"; amount = CheckAmountMethod(userName, amount, message2); decimal amountToWithdraw = Convert.ToDecimal(amount); string query1 = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) and (username = '******'))"; decimal availableUsersAmount = Convert.ToDecimal(AddQuerry(query1)); while (availableUsersAmount < amountToWithdraw) { Console.Clear(); string message = "Sorry, no available amount to withdraw, try again!"; ConsoleLayout.Attention(message, 0); System.Threading.Thread.Sleep(2000); amount = CheckAmountMethod(userName, amount, message2); amountToWithdraw = Convert.ToDecimal(amount); } string query2 = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) and (username = '******'))"; decimal adminsAmount = Convert.ToDecimal(AddQuerry(query2)); decimal usersNewbal = availableUsersAmount - amountToWithdraw; decimal adminsNewBal = amountToWithdraw + adminsAmount; decimal newBalance = 0; string query3 = "UPDATE accounts SET amount = " + usersNewbal + " WHERE exists (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******')); UPDATE accounts SET amount = " + adminsNewBal + "WHERE exists (SELECT username FROM users WHERE (id = accounts.user_id) and (username = '******'))"; ExecuteQuery(query3); string query4 = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******'))"; newBalance = Convert.ToDecimal(AddQuerry(query4)); ConsoleLayout.Position(6); Console.WriteLine("Transaction was successfully completed!"); ConsoleLayout.Position(8); Console.WriteLine("New bank balance: {0} euros", newBalance); System.Threading.Thread.Sleep(3000); Login.CloseConnection(); DateTime time = DateTime.Now; BankAccount Transaction = new BankAccount(time, "admin", amountToWithdraw, KindOfTransaction.Withdrawal, userToWithdraw); BankAccount.AddList("admin", Transaction); }
public static void DepositTo(string userName) { string receiversUsername = ""; string message = "Please enter the username you wish to deposit to: "; receiversUsername = CheckUserToTransferMethod(userName, receiversUsername, message); string amount = ""; string message2 = "Please enter the amount you wish to transfer: "; amount = CheckAmountMethod(userName, amount, message2); decimal amountToTransfer = Convert.ToDecimal(amount); string query1 = "SELECT amount FROM accounts WHERE EXISTS(SELECT username FROM users WHERE id = accounts.user_id AND username = '******')"; decimal availableDepositersAmount = Convert.ToDecimal(AddQuerry(query1)); while (availableDepositersAmount < amountToTransfer) { Console.Clear(); string message1 = "Sorry, no available amount to transfer, try again!"; ConsoleLayout.Attention(message1, 0); System.Threading.Thread.Sleep(2000); amount = CheckAmountMethod(userName, amount, message2); amountToTransfer = Convert.ToDecimal(amount); } string query2 = "SELECT amount FROM accounts WHERE EXISTS(SELECT username FROM users WHERE id = accounts.user_id AND username = '******')"; decimal receiversAccount = Convert.ToDecimal(AddQuerry(query2)); decimal depositorsNewbal = availableDepositersAmount - amountToTransfer; decimal receiversNewBal = receiversAccount + amountToTransfer; decimal newBalance = 0; string query3 = "UPDATE accounts SET amount = " + depositorsNewbal + " WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******')); UPDATE accounts SET amount = " + receiversNewBal + "WHERE exists (SELECT username FROM users WHERE (id = accounts.user_id) and (username = '******'))"; ExecuteQuery(query3); string query4 = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******'))"; newBalance = Convert.ToDecimal(AddQuerry(query4)); ConsoleLayout.Position(8); Console.WriteLine("Transaction was successfully completed!"); ConsoleLayout.Position(9); Console.WriteLine("New bank balance: {0}", newBalance); System.Threading.Thread.Sleep(3000); Login.CloseConnection(); DateTime time = DateTime.Now; BankAccount Transaction = new BankAccount(time, userName, amountToTransfer, KindOfTransaction.Deposit, receiversUsername); BankAccount.AddList(userName, Transaction); }
public static void CheckUser(SqlConnection sqlconn) { Welcome(); int result = 0; int i = 2; do { // Console.WriteLine("{0," + Console.WindowWidth / 2 + "}", " "); ConsoleLayout.Position(0); Console.WriteLine("Please enter your username"); ConsoleLayout.Position(2); string userName = Convert.ToString(Console.ReadLine()); ConsoleLayout.Position(4); Console.WriteLine("Please enter your password"); ConsoleLayout.Position(6); string passWord = GenerateSHA256String(Hide()); //sc.Parameters.AddWithValue("@password", GetHashedText(pass.Text)); SqlCommand cmd = new SqlCommand("SELECT COUNT (*) FROM users WHERE username = @username AND password = @password", sqlconn); cmd.Parameters.AddWithValue("@username", userName); cmd.Parameters.AddWithValue("@password", passWord); result = (int)cmd.ExecuteScalar(); if (result > 0) { ConsoleLayout.Position(10); Console.WriteLine("Successful Connection"); System.Threading.Thread.Sleep(1000); Console.Clear(); ShowMenus.ChooseUser(userName); break; } else if (i == 0) { string message1 = "Where is your mind?"; ConsoleLayout.Speech(message1, 0); string message = "Sorry, invalid user!!!"; ConsoleLayout.Attention(message, 10); ConsoleLayout.Position(12); Environment.Exit(0); } else { i--; string message = "Unsuccessfull Connection"; ConsoleLayout.Attention(message, 10); ConsoleLayout.Position(12); Console.WriteLine("Please try again, {0} tries left!!!", i + 1); System.Threading.Thread.Sleep(1000); Console.Clear(); } }while ((result == 0) && (i >= 0)); }