public EntryList LoadFromFile() { EntryList loadedList = new EntryList(); Entry loadedEntry = new Entry(""); short lineCodeCounter = 0; if (_taskListFile.Peek() != -1) { using (_taskListFile) { while (!_taskListFile.EndOfStream) { var line = _taskListFile.ReadLine(); switch (lineCodeCounter) { case 0: //first line contains P or nothing, declaring whether entry is a priority if (line.StartsWith("P") && line.Length == 1) { loadedEntry.IsPriority = true; } break; case 1: //next line contains entry content loadedEntry.Content = line; break; case 2: //next one contains add date var dateCode = line.Split(" "); loadedEntry.AddDate = new DateTime(int.Parse(dateCode[0]), int.Parse(dateCode[1]), int.Parse(dateCode[2])); break; case 3: //and last one contains (or does not contain) a due date if (line.Length > 1) { dateCode = line.Split(" "); loadedEntry.DueDate = new DateTime(int.Parse(dateCode[0]), int.Parse(dateCode[1]), int.Parse(dateCode[2])); } break; } lineCodeCounter = (short)((lineCodeCounter + 1) % 4); if (lineCodeCounter == 0) { var completeEntry = loadedEntry.Copy(); loadedList.Add(completeEntry); loadedEntry.IsPriority = false; loadedEntry.DueDate = DateTime.MaxValue; } } } } loadedList.listName = _listName; loadedList.Sort(); _taskListFile.Dispose(); return(loadedList); }
private void EditList() //todo { bool loop = true; do { Console.Clear(); Console.WriteLine(_currentList); Console.WriteLine("\n[1] Add a new entry\t[2] Modify existing entry\t[3] Delete an entry\t[0] Go back"); switch (Console.ReadKey().KeyChar) { case '1': Console.Clear(); Console.WriteLine("Type your entry here: "); var newEntry = new Entry(Console.ReadLine()); if (GetDecision("Is is a priority?")) { newEntry.IsPriority = true; } Console.Clear(); Console.WriteLine("Provide a due date [YYYY MM DD] (otherwise type nothing)"); var date = Console.ReadLine().Split(" "); if (date.GetLength(0) == 3) { newEntry.DueDate = new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2])); } _currentList.Add(newEntry); Console.Clear(); Console.WriteLine("Entry added!"); Console.ReadKey(); Console.Clear(); break; case '2': Console.Clear(); Console.WriteLine(_currentList + "\nWhich entry to modify?"); ModifyEntry(_currentList.GetEntry(Console.ReadKey().KeyChar - 49)); break; case '3': Console.Clear(); Console.WriteLine(_currentList + "\nWhich entry to delete?"); _currentList.Remove(Console.ReadKey().KeyChar - 49); break; case '0': loop = false; Console.Clear(); break; } } while (loop); }