private static void DisplayModifyDebt() { bool goBack = false; do { Console.Clear(); Console.WriteLine("Remove Debt"); Console.WriteLine("-------------------------"); Console.WriteLine("Total Debt: {0:C}", DebtCollection.TotalDebt); Console.WriteLine("Total Required Income: {0:C}", DebtCollection.TotalRequiredIncome); Console.WriteLine("----- Current Debts -----"); DebtCollection.ListDebts(); Console.WriteLine("-------------------------"); Console.Write("Debt to modify (B to go back)"); var key = Console.ReadKey(); if (key.KeyChar == 'b' || key.KeyChar == 'B') { goBack = true; } if (int.TryParse(key.KeyChar.ToString(), out int keyNum)) { keyNum = keyNum - 1; if (DebtCollection.GetDebts.Count() > keyNum && keyNum >= 0) { ModifyDebt(DebtCollection.GetDebts[keyNum]); } } } while (!goBack); }
public static void DisplaySave() { string fileName = ""; do { Console.Clear(); Console.WriteLine("---------------------"); Console.WriteLine("Save current settings"); Console.WriteLine("---------------------"); 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); Console.WriteLine("---------------------"); DebtCollection.ListDebts(); Console.WriteLine("---------------------"); Console.Write("FileName (default \'debt.sav\', B to go back): "); fileName = Console.ReadLine(); if (fileName == "b" || fileName == "B") { return; } fileName = string.IsNullOrWhiteSpace(fileName) ? "debt.sav" : fileName; fileName = Directory.GetCurrentDirectory() + "\\" + fileName; try { File.Create(fileName).Close(); } catch (IOException e) { Console.WriteLine("Error trying to create file " + fileName + ": "); Console.WriteLine(e.Message); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } } while (!File.Exists(fileName)); using (var fs = new FileStream(fileName, FileMode.Truncate)) { using (var sw = new StreamWriter(fs)) { sw.WriteLine("totalIncome" + _delim + DebtCollection.TotalIncome); foreach (var debt in DebtCollection.GetDebts) { sw.WriteLine(debt.SaveString()); } } } Console.Write(Path.GetFileName(fileName) + " created successfully. Press any key to continue..."); Console.ReadKey(); Console.WriteLine(); }
internal static void DisplayDebtOptions() { bool goBack = false; ConsoleKeyInfo key; do { Console.Clear(); Console.WriteLine("Debt Options"); Console.WriteLine("-------------------------"); Console.WriteLine("Total Debt: {0:C}", DebtCollection.TotalDebt); Console.WriteLine("Total Required Income: {0:C}", DebtCollection.TotalRequiredIncome); Console.WriteLine("----- Current Debts -----"); DebtCollection.ListDebts(); Console.WriteLine("-------------------------"); Console.WriteLine("1: Add Debt"); Console.WriteLine("2: Remove Debt"); Console.WriteLine("3: Modify Debt"); Console.WriteLine("B: Go Back"); key = Console.ReadKey(); if (key.Key == ConsoleKey.B) { goBack = true; } if (key.Key == ConsoleKey.D1) { DisplayAddDebt(); } if (key.Key == ConsoleKey.D2) { DisplayRemoveDebt(); } if (key.Key == ConsoleKey.D3) { DisplayModifyDebt(); } } while (!goBack); }
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(); } }