Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void ViewList()
        {
            bool loop = true;

            do
            {
                Console.Clear();
                _currentList.Sort();
                Console.WriteLine(_currentList);
                Console.WriteLine("\n[1] Modify\t[2] Delete\t[3] Save\t[0] Go back\n");
                _userKey = Console.ReadKey();
                switch (_userKey.KeyChar)
                {
                case '1':
                    EditList();
                    break;

                case '2':
                    if (GetDecision(string.Format("Are you sure you want to delete list '{0}'?", _currentList.listName)))
                    {
                        var path = Directory.GetCurrentDirectory();
                        path  = Path.GetFullPath(Path.Combine(path, @"..\..\..\Lists\"));
                        path += _currentList.listName + ".txt";
                        File.Delete(path);

                        Console.Clear();
                        Console.WriteLine("List '{0}' successfully deleted!", _currentList.listName);
                        Console.WriteLine("(Press any key to continue)");
                        Console.ReadKey();
                        Console.Clear();

                        _currentList = new EntryList();
                        loop         = false;
                    }
                    break;

                case '3':
                    SaveToFile();
                    break;

                case '0':
                    if (!_currentList.Same(LoadFromFile(_currentList.listName)))                //todo (not working)
                    {
                        if (GetDecision(string.Format("Do you want to save '{0}'?", _currentList.listName)))
                        {
                            SaveToFile();
                        }
                    }
                    Console.Clear();
                    loop = false;
                    break;
                }
            } while (loop);
        }
Ejemplo n.º 3
0
 public bool Same(EntryList entryList)
 {
     if (Count() != entryList.Count())
     {
         return(false);
     }
     for (int i = 0; i < Count(); i++)
     {
         if (!entryList.GetEntry(i).Same(GetEntry(i)))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 4
0
 public TaskListSaver(EntryList entryList)
 {
     _entryList = entryList;
 }