Esempio n. 1
0
        public void SaveToFile()
        {
            short lineCodeCounter = 0;
            var   path            = Directory.GetCurrentDirectory();

            path  = Path.GetFullPath(Path.Combine(path, @"..\..\..\Lists\"));
            path += _entryList.listName + ".txt";
            using (var writer = new StreamWriter(path))
            {
                for (int i = 0; i < _entryList.Count();)
                {
                    switch (lineCodeCounter)
                    {
                    case 0:
                        if (_entryList.GetEntry(i).IsPriority)
                        {
                            writer.WriteLine("P");
                        }
                        else
                        {
                            writer.WriteLine();
                        }
                        break;

                    case 1:
                        writer.WriteLine(_entryList.GetEntry(i).Content);
                        break;

                    case 2:
                        var date = _entryList.GetEntry(i).AddDate.Year.ToString() + " " + _entryList.GetEntry(i).AddDate.Month.ToString() + " " + _entryList.GetEntry(i).AddDate.Day.ToString();
                        writer.WriteLine(date);
                        break;

                    case 3:
                        date = _entryList.GetEntry(i).DueDate.Year.ToString() + " " + _entryList.GetEntry(i).DueDate.Month.ToString() + " " + _entryList.GetEntry(i).DueDate.Day.ToString();
                        writer.WriteLine(date);
                        break;
                    }
                    lineCodeCounter = (short)((lineCodeCounter + 1) % 4);
                    if (lineCodeCounter == 0)
                    {
                        i++;
                    }
                }
            }
            Console.Clear();
            Console.WriteLine("Successfully saved '{0}' to {1} ", _entryList.listName, path);
            Console.WriteLine("(Press any key to continue)");
            Console.ReadKey();
        }
Esempio n. 2
0
        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);
        }
Esempio 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);
 }