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; } } }