public static bool changeBalance(float change, char symbol) { balance = float.Parse(SQLoperator.CheckBalance(cardNumber)); float newBalance; if (symbol == '+') { newBalance = (balance + change); } else { newBalance = (balance - change); } try { if (balance + change < 0) { Console.WriteLine("You can't withdraw amount that is more than your current balance: " + balance.ToString() + "$"); return(false); } else { SQLoperator.ChangeBalance(cardNumber, newBalance); SQLoperator.CheckBalance(cardNumber); return(true); } } catch (Exception ex) { LogProvider.LogString(ex.ToString()); return(false); } }
public static void registerAccount() { Console.WriteLine("Welcome to our bank. You will need to write your name and desired pin-code."); while (true) { Console.WriteLine("Your name:"); name = Console.ReadLine(); if (name.Length <= 50) { Console.WriteLine("Your PIN code:"); var tempPin = Console.ReadLine(); if ((tempPin.Length == 4) & (Regex.IsMatch(tempPin, @"^\d+$"))) { pinCode = ConvertToSecureString(tempPin); break; } } } Console.WriteLine("Press Enter to be issued a new credit card."); Console.ReadKey(); cardNumber = IssueCard(); try { SQLoperator.AddEntry(name, cardNumber, pinCode); } catch (Exception e) { Console.WriteLine(e.ToString()); LogProvider.LogString(e.ToString()); } }
public static void Greet() { int inputN; Console.WriteLine("Welcome to Bank Accounting System! \nUse one of available commands by typing the number:"); while (true) { int n = 1; foreach (string c in commands) { Console.WriteLine(n + ". " + c); n++; } string input = Console.ReadLine(); if (Regex.IsMatch(input, @"^\d+$")) { Int32.TryParse(input, out inputN); if ((inputN < commands.Length) & inputN > 0) { break; } } Console.WriteLine("\nNo such command."); } string command = commands[inputN - 1].ToLower(); switch (command) { case "register": { registerAccount(); return; } case "log in": { logIn(); return; } default: { SQLoperator.CloseConnection(); LogProvider.EndLog(); Environment.Exit(0); return; } } }
static void Main(string[] args) { try { LogProvider.BeginLog(); SQLoperator.EstablishConnection(); BankAccount.Greet(); Console.ReadKey(); SQLoperator.CloseConnection(); LogProvider.EndLog(); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.ReadLine(); } }
public static void logIn() { int Tries = 0; while (Tries < 4) { Console.WriteLine("\nCard Number: "); string cardN = Console.ReadLine(); if (Regex.IsMatch(cardN, @"^\d+$")) { Console.WriteLine("\nPin Code: "); string pin = Console.ReadLine(); if (Regex.IsMatch(pin, @"^\d+$") & pin.Length == 4) { cardNumber = ConvertToSecureString(cardN); pinCode = ConvertToSecureString(pin); if (SQLoperator.CheckCard(cardNumber, pinCode)) { break; } else { Console.WriteLine("Wrong pin."); } } } Tries++; Console.WriteLine("Autorisation failed."); } if (Tries > 3) { LogProvider.LogString("Failed login attempt. Connection terminated."); SQLoperator.CloseConnection(); LogProvider.EndLog(); Environment.Exit(0); } AccountOperation(); }
static void AccountOperation() { string[] accountActions = new string[] { "Check balance", "Deposit money", "Withdraw money" }; Console.WriteLine("Select action:"); int inputN; while (true) { int n = 1; foreach (string c in accountActions) { Console.WriteLine(n + ". " + c); n++; } string input = Console.ReadLine(); if (Regex.IsMatch(input, @"^\d+$")) { Int32.TryParse(input, out inputN); if ((inputN <= commands.Length) & inputN > 0) { break; } } Console.WriteLine("\nNo such command."); } string command = accountActions[inputN - 1].ToLower(); switch (command) { case "check balance": { balance = float.Parse(SQLoperator.CheckBalance(cardNumber)); Console.WriteLine("Balance: " + balance.ToString("0.00") + "$"); return; } case "deposit money": { Console.WriteLine("Amount you want to deposit: "); while (true) { float amountF; string amount = Console.ReadLine(); if (Regex.IsMatch(amount, @"^\d+$")) { float.TryParse(amount, out amountF); changeBalance(amountF, '+'); break; } else { Console.WriteLine("Please, set the amount of money you want to depoit:"); } } return; } case "withdraw money": { SQLoperator.CheckBalance(cardNumber); Console.WriteLine("Amount you want to withdraw: "); while (true) { float amountF; string amount = Console.ReadLine(); if (Regex.IsMatch(amount, @"^\d+$")) { float.TryParse(amount, out amountF); if (changeBalance(amountF, '-')) { break; } } else { Console.WriteLine("Please, set the amount of money you want to withdraw:"); } } return; } default: { SQLoperator.CloseConnection(); LogProvider.EndLog(); Environment.Exit(0); return; } } }