internal static void LoadTaskList() { try { string fileContents = File.ReadAllText(filename); if (fileContents == "") { return; } Console.WriteLine(" Loading previous files...\n"); string task; string[] stringArray = Regex.Split(fileContents, ", "); int number; int i = 0; for (; i < stringArray.Length;) { task = stringArray[i]; if (i == stringArray.Length - 1) { number = Convert.ToInt32(task); Program.currentPosition = number; } else { string action = stringArray[i + 1]; string reentries = stringArray[i + 2]; Program.tasks.Add(task); Program.actions.Add(action); Program.reentries.Add(reentries); } //if (Int32.TryParse(task, out number) == true) //{ // Program.currentPosition = Convert.ToInt32(task); // Console.WriteLine(task); // return; //} i += 3; } } catch (FileNotFoundException) { Console.WriteLine("Exception thrown"); return; } Cleanup.OnView(); Program.currentPosition = 0; }
internal static void Reset() { Cleanup.OnView(); int i = 0; for (; i >= 0; i++) { if (Program.actions[i] == "complete") { continue; } if (Program.actions[i] == "none" || Program.actions[i] == "crossed") { Program.currentPosition = i; return; } } }
static void Main(string[] args) { FileManager.LoadTaskList(); if (currentPosition == -1) { FileManager.FirstTask(); } bool quit = false; do { View.DisplayMenu(); //Console.WriteLine($"\n Current Task: {displayTask}\n"); try { Console.Write("\n Task: "); userGlobal = Console.ReadLine(); int userInput = Convert.ToInt32(userGlobal); if (12 > userInput && userInput > 0) { switch (userInput) { case 1: Cleanup.OnView(); View.TaskList("first page"); Console.WriteLine("\n"); break; case 2: Cleanup.OnView(); View.TaskList("previous page"); Console.WriteLine("\n"); break; case 3: Cleanup.OnView(); View.TaskList("next page"); Console.WriteLine("\n"); break; case 4: Actions.Skip(); Cleanup.OnView(); break; case 5: Program.actions[currentPosition] = Actions.Crossed(); Actions.Skip(); Cleanup.OnView(); break; case 6: Actions.Reenter(); Actions.Skip(); Cleanup.OnView(); break; case 7: Program.actions[Program.currentPosition] = Actions.Complete(); Actions.Skip(); Cleanup.OnView(); break; case 8: Cleanup.OnView(); View.Reentries(tasks, reentries); break; case 9: quit = true; break; case 10: Actions.Reset(); break; case 11: View.PrintList(Program.tasks, Program.actions, Program.reentries); break; } Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Program.displayTask = View.DisplayTask(); Console.Write($" Current Task: {displayTask}"); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\n"); } } catch (FormatException) { Console.WriteLine(" Task Added\n"); Program.tasks.Add(userGlobal); Program.actions.Add("none"); Program.reentries.Add("0"); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Program.displayTask = View.DisplayTask(); Console.Write($" Current Task: {displayTask}"); Console.ResetColor(); Console.WriteLine("\n"); } } while (!quit); Console.WriteLine("\nExiting Program...\n"); FileManager.SaveTaskList(tasks, actions, reentries, currentPosition); Environment.Exit(0); }