private void ChangeBalance(int a) { int amount = 0; bool exists = false; string input = ""; while (amount <= 0 || exists == false) { Accounts.Show(); Console.WriteLine(Literals.getLiterals("Input the name of account or it's identity describer , or 123 to exit")); input = Console.ReadLine(); if (input.CompareTo("123") == 0) { Console.Clear(); break; } exists = Accounts.AccountExists(input); if (exists) { Console.WriteLine(Literals.getLiterals("Input amount")); try { amount = Int32.Parse(Console.ReadLine().ToString()); if (amount <= 0) { throw new Exception(); } if (a == 1) { Accounts.IncreaseAccountAmount(input, amount); } else if (a == -1) { AccountNameId = input; Amount = amount; } } catch (Exception) { amount = 0; } } else { Console.WriteLine(Literals.getLiterals("Account does not exist")); Console.ReadKey(true); } Console.Clear(); } }
private void AddAccount() { string pattern = "^[A-Za-z0-9]{3,20}$"; while (true) { Accounts.Show(); Console.WriteLine(Literals.getLiterals("Input the name of account or it's identity describer , or 123 to exit")); string idName = Console.ReadLine(); if (idName.Equals("123")) { Console.Clear(); break; } int amount = 0; if (Regex.IsMatch(idName, pattern, RegexOptions.IgnoreCase)) { if (!Accounts.AccountExists(idName)) { try { Console.WriteLine(Literals.getLiterals("Input amount")); amount = Int32.Parse(Console.ReadLine().ToString()); if (amount <= 0) { throw new Exception(); } Accounts.AddAccount(idName, amount); Console.Clear(); break; } catch (Exception) { amount = 0; } } else { Console.WriteLine(Literals.getLiterals("Account exists")); Console.ReadKey(true); } } else { Console.WriteLine(Literals.getLiterals("Invalid account pattern")); Console.ReadKey(true); } Console.Clear(); } }
private void RemoveAccount() { string pattern = "^[A-Za-z0-9]{3,20}$"; while (true) { Accounts.Show(); Console.WriteLine(Literals.getLiterals("Input the name of account or it's identity describer , or 123 to exit")); string idName = Console.ReadLine(); int amount = 0; if (idName.Equals("123")) { Console.Clear(); break; } if (Regex.IsMatch(idName, pattern, RegexOptions.IgnoreCase)) { if (Accounts.AccountExists(idName)) { try { Accounts.RemoveAccount(idName); Console.Clear(); break; } catch (Exception) { amount = 0; } } else { Console.WriteLine(Literals.getLiterals("Account does not exist")); Console.ReadKey(true); } } else { Console.WriteLine(Literals.getLiterals("Invalid account pattern")); Console.ReadKey(true); } Console.Clear(); } }