private static void DisplayAddDebt() { decimal balance = 0.00m; decimal apr = 0.00m; string name = ""; string input = ""; bool validName = false; Console.Clear(); Console.WriteLine("Adding Debt"); Console.WriteLine("-----------"); Console.WriteLine("Blank entry will cancel addition"); do { Console.Write("Debt Name: "); input = Console.ReadLine(); validName = !DebtCollection.GetDebts.Exists(x => x.Name == input); if (!validName) { Console.WriteLine("Loan Name {0} already exists!", input); } } while (!validName); if (string.IsNullOrWhiteSpace(input)) { return; } name = input; do { Console.Write("Balance (e.g. 5000): "); input = Console.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { return; } } while (!decimal.TryParse(input, out balance)); do { Console.Write("APR (e.g. 22.99): "); input = Console.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { return; } } while (!decimal.TryParse(input, out apr)); apr = apr / 100.0m; var newDebt = new Debt(name, apr, balance); DebtCollection.AddDebt(newDebt); }
public static void DisplayLoad() { bool validInput = false; ConsoleKeyInfo key; do { Console.Clear(); Console.WriteLine("-------------------------"); Console.WriteLine("Load settings (this will remove all unsaved information)"); Console.WriteLine("Total Debt: {0:C}", DebtCollection.TotalDebt); Console.WriteLine("Total Required Income: {0:C}", DebtCollection.TotalRequiredIncome); Console.WriteLine("Total Income: {0:C}", DebtCollection.TotalIncome); DebtCollection.ListDebts(); Console.WriteLine("-------------------------"); Console.Write("Continue(Y/N): "); key = Console.ReadKey(); Console.WriteLine(); validInput = key.Key == ConsoleKey.Y || key.Key == ConsoleKey.N; } while (!validInput); if (key.Key == ConsoleKey.N) { return; } OpenFileDialog fd = new OpenFileDialog(); fd.InitialDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); if (fd.ShowDialog() == DialogResult.OK) { using (var fs = new FileStream(fd.FileName, FileMode.Open)) { // clear any current debts DebtCollection.ClearDebts(); using (var sr = new StreamReader(fs)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); var items = line.Split(new string[] { _delim }, StringSplitOptions.RemoveEmptyEntries); if (items.Contains("totalIncome")) { DebtCollection.TotalIncome = decimal.Parse(items[1]); Console.WriteLine("Total Income Loaded ({0:C})", DebtCollection.TotalIncome); } if (items.Contains("debtInfo")) { Debt d = new Debt(); d.LoadString(line); if (string.IsNullOrEmpty(d.Name)) { continue; } DebtCollection.AddDebt(d); Console.WriteLine("Loaded Debt ({0}, {1:C}, {2:P2})", d.Name, d.Balance, d.Apr); } } } } Console.Write("Loaded " + Path.GetFileName(fd.FileName) + " successfully. Press any key to continue..."); Console.ReadKey(); Console.WriteLine(); } }