Пример #1
0
        static void ShowTasks(List <TaskModel> tasks)
        {
            ConsoleEx.Write("\nZadanie".PadRight(15), ConsoleColor.Cyan);
            ConsoleEx.Write("Start zadania".PadRight(25), ConsoleColor.Cyan);
            ConsoleEx.Write("Koniec zadania".PadRight(25), ConsoleColor.Cyan);
            ConsoleEx.Write("Ważne".PadRight(10), ConsoleColor.Cyan);
            ConsoleEx.WriteLine("Cały dzień".PadRight(10), ConsoleColor.Cyan);
            ConsoleEx.WriteLine("".PadRight(80, '-'), ConsoleColor.Cyan);

            // show important tasks
            foreach (var task in tasks)
            {
                if (task.IsImportant)
                {
                    ShowTask(task);
                }
            }

            // show others
            foreach (var task in tasks)
            {
                if (!task.IsImportant)
                {
                    ShowTask(task);
                }
            }
        }
Пример #2
0
        static void ShowTask(TaskModel task)
        {
            ConsoleEx.Write($"{task.Description}".PadRight(15), ConsoleColor.Cyan);
            ConsoleEx.Write($"{task.StartDate}".PadRight(25), ConsoleColor.Cyan);

            if (task.EndDate == null)
            {
                ConsoleEx.Write("---".PadRight(25), ConsoleColor.Cyan);
            }
            else
            {
                ConsoleEx.Write($"{task.EndDate}".PadRight(25), ConsoleColor.Cyan);
            }

            if (task.IsImportant)
            {
                ConsoleEx.Write("Y".PadRight(10), ConsoleColor.Cyan);
            }
            else
            {
                ConsoleEx.Write("N".PadRight(10), ConsoleColor.Cyan);
            }

            if (task.IsAllday)
            {
                ConsoleEx.WriteLine("Y".PadRight(10), ConsoleColor.Cyan);
            }
            else
            {
                ConsoleEx.WriteLine("N".PadRight(10), ConsoleColor.Cyan);
            }

            ConsoleEx.WriteLine("".PadRight(80, '-'), ConsoleColor.Cyan);
        }
Пример #3
0
        public static void Filter()
        {
            Console.Write("Enter the index of the filter: ");
            int    userFilter = Convert.ToInt32(Console.ReadLine().Trim().ToLower());
            string word;

            try
            {
                switch (userFilter)
                {
                case 1:
                    Console.Write("Enter the search word: ");
                    word = Console.ReadLine().Trim();
                    wordFilter(word);
                    break;

                case 2:
                    startTimeFilter();
                    break;

                case 3:
                    endTimeFilter();
                    break;

                case 4:
                    allDayFilter();
                    break;

                case 5:
                    importantTaskFilter();
                    break;

                default:
                    ConsoleEx.Write("Wrong index number!", ConsoleColor.Red);
                    break;
                }
            }
            catch (IndexOutOfRangeException)
            {
                ConsoleEx.Write("Wrong index number!", ConsoleColor.Red);
                Console.ReadLine();
            }
            catch (FormatException)
            {
                ConsoleEx.Write("Wrong data!", ConsoleColor.Red);
                Console.ReadLine();
            }
            catch (Exception)
            {
                ConsoleEx.Write("Something went wrong...", ConsoleColor.Red);
                Console.ReadLine();
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            string command = "";

            do
            {
                Console.Clear();
                MainMenu.Menu();
                Console.Write("Enter the command: ");
                command = Console.ReadLine().Trim().ToLower();

                if (command == "exit")
                {
                    break;
                }

                switch (command)
                {
                case "add":
                    AddTask(taskList);
                    break;

                case "remove":
                    RemoveTask(taskList);
                    break;

                case "show":
                    ShowTasks(taskList);
                    break;

                case "sort":
                    SortTasks(taskList);
                    break;

                case "save":
                    SaveTasks(taskList);
                    break;

                case "load":
                    LoadTasks(taskList);
                    break;

                case "help":
                    HelpMenu.Help();
                    break;

                default:
                    ConsoleEx.Write("Wrong command.", ConsoleColor.Red);
                    Console.ReadKey();
                    break;
                }
            }while (true);
        }
Пример #5
0
        static void RemoveTask(List <TaskModel> tasks)
        {
            Console.WriteLine();

            for (int i = 0; i < tasks.Count; i++)
            {
                ConsoleEx.WriteLine($"[{i+1}] {tasks[i].Description} ({tasks[i].StartDate})", ConsoleColor.Red);
            }

            ConsoleEx.Write("\nKtóre zadanie usunąć? (podaj numer): ", ConsoleColor.Red);
            int index = Convert.ToInt32(Console.ReadLine());

            tasks.RemoveAt(index - 1);
            ConsoleEx.WriteLine("Zadanie usunięte.", ConsoleColor.Red);
        }
Пример #6
0
        /// <summary>
        /// Display task list in console
        /// </summary>
        /// <param name="list"> TaskModel list </param>
        public void ShowTasks(List <TaskModel> list)
        {
            try
            {
                int i = 0;
                foreach (var element in list)
                {
                    if (element.Allday == true)
                    {
                        ConsoleEx.Write(
                            $"{i + 1}. Describtion: {element.Description}, Start date: {element.Start}, Allday: True, ",
                            ConsoleColor.Magenta);
                    }
                    else
                    {
                        ConsoleEx.Write(
                            $"{i + 1}. Describtion: {element.Description}, Start date: {element.Start}, End date: {element.End}, ",
                            ConsoleColor.Magenta);
                    }

                    if (element.Important == true)
                    {
                        ConsoleEx.Write("Important: Yes", ConsoleColor.Magenta);
                    }
                    else
                    {
                        ConsoleEx.Write("Important: No", ConsoleColor.Magenta);
                    }

                    Console.WriteLine();
                    i++;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #7
0
        // RemoveTask method delete a task
        private static void RemoveTask(List <TaskModel> taskList)
        {
            int taskIndex = 0;

            Console.Clear();
            MainMenu.Menu();
            ConsoleEx.WriteLine(" :: REMOVE TASK ::", ConsoleColor.DarkCyan);
            ConsoleEx.WriteLine("".PadLeft(115, '^'), ConsoleColor.DarkCyan);
            ConsoleEx.WriteLine(">>> List of tasks:", ConsoleColor.Gray);
            ConsoleEx.WriteLine("".PadLeft(115, '-'), ConsoleColor.DarkCyan);

            for (int i = 0; i < taskList.Count; i++) // shows all tasks from the taskList
            {
                ConsoleEx.WriteLine($"Task number {i + 1}:", ConsoleColor.DarkRed);
                Console.WriteLine($"{taskList[i].ExportToString()}");
                Console.WriteLine();
            }
            ConsoleEx.WriteLine("".PadLeft(115, '='), ConsoleColor.DarkCyan);
            Console.WriteLine();

            Console.Write("Enter the index of the task to delete: ");
            taskIndex = int.Parse(Console.ReadLine().Trim());
            try
            {
                taskList.RemoveAt(taskIndex - 1);
                ConsoleEx.WriteLine($"Task number {taskIndex} has been deleted.", ConsoleColor.Green);
            }
            catch (FormatException)
            {
                ConsoleEx.Write("Wrong data format.", ConsoleColor.Red);
            }
            catch (IndexOutOfRangeException)
            {
                ConsoleEx.Write($"There is no #{taskIndex} task.", ConsoleColor.Red);
            }
            Console.Write("Press ENTER to continue... ");
            Console.ReadLine();
        }
Пример #8
0
 public static void Menu()
 {
     Console.WriteLine();
     Console.WriteLine();
     ConsoleEx.WriteLine("".PadLeft(115, '='), ConsoleColor.DarkCyan);
     ConsoleEx.WriteLine(":: T A S K  M A N A G E R ::".PadLeft(70), ConsoleColor.DarkCyan);
     ConsoleEx.WriteLine("".PadLeft(115, '-'), ConsoleColor.DarkCyan);
     ConsoleEx.Write(" add ".PadLeft(30), ConsoleColor.DarkGreen);
     Console.Write("::");
     ConsoleEx.Write(" remove ", ConsoleColor.DarkRed);
     Console.Write("::");
     ConsoleEx.Write(" show ", ConsoleColor.DarkYellow);
     Console.Write("::");
     ConsoleEx.Write(" sort ", ConsoleColor.DarkMagenta);
     Console.Write("::");
     ConsoleEx.Write(" save ", ConsoleColor.DarkGray);
     Console.Write("::");
     ConsoleEx.Write(" load ", ConsoleColor.Gray);
     Console.Write("::");
     ConsoleEx.Write(" exit ", ConsoleColor.Blue);
     Console.Write("::");
     ConsoleEx.WriteLine(" help ", ConsoleColor.Blue);
     ConsoleEx.WriteLine("".PadLeft(115, '='), ConsoleColor.DarkCyan);
 }
Пример #9
0
        static void AddTask(List <TaskModel> tasks)
        {
            ConsoleEx.Write("\nOpis zadania: ", ConsoleColor.Green);
            string descr = Console.ReadLine();

            ConsoleEx.Write("Start zadania: ", ConsoleColor.Green);
            string   start = Console.ReadLine();
            DateTime date;
            bool     isDateOk = DateTime.TryParse(start, out date);

            while (!isDateOk)
            {
                ConsoleEx.Write("Start zadania (rrrr-mm-dd [hh:mm]): ", ConsoleColor.Green);
                start    = Console.ReadLine();
                isDateOk = DateTime.TryParse(start, out date);
            }


            ConsoleEx.Write("Ważne? Y/N: ", ConsoleColor.Green);
            string important = Console.ReadLine().ToLower();

            while (!(important == "n" || important == "y"))
            {
                ConsoleEx.Write("Ważne? Y/N: ", ConsoleColor.Green);
                important = Console.ReadLine().ToLower();
            }


            ConsoleEx.Write("Całodzienne? Y/N: ", ConsoleColor.Green);
            string allday = Console.ReadLine().ToLower();

            while (!(allday == "n" || allday == "y"))
            {
                ConsoleEx.Write("Całodzienne? Y/N: ", ConsoleColor.Green);
                allday = Console.ReadLine().ToLower();
            }



            var tm = new TaskModel(descr, date);

            if (important == "y")
            {
                tm.IsImportant = true;
            }

            if (allday == "y")
            {
                tm.IsAllday = true;
                tm.EndDate  = null;
            }
            else
            {
                ConsoleEx.Write("Data zakończena zadania: ", ConsoleColor.Green);
                string   end = Console.ReadLine();
                DateTime edate;
                bool     iseDateOk = DateTime.TryParse(end, out edate);

                while (!iseDateOk)
                {
                    ConsoleEx.Write("Data zakończena zadania (rrrr-mm-dd [hh:mm]): ", ConsoleColor.Green);
                    end       = Console.ReadLine();
                    iseDateOk = DateTime.TryParse(end, out edate);
                }

                tm.EndDate = edate;
            }

            tasks.Add(tm);
            ConsoleEx.WriteLine("Zadanie dodane.", ConsoleColor.Green);
            SaveTasks(tasks);
        }
Пример #10
0
        // AddTask method take  data from user and create new TaskModel
        private static TaskModel CreateTask()
        {
            Console.Clear();
            MainMenu.Menu();

            string   description;
            DateTime startTime;
            DateTime?endTime;
            bool?    allDayTask;
            bool?    importantTask;

            ConsoleEx.WriteLine(":: NEW TASK ::", ConsoleColor.DarkCyan);
            ConsoleEx.WriteLine("".PadLeft(115, '^'), ConsoleColor.DarkCyan);
            Console.WriteLine(">>> Insert the data according to the scheme below (use comma [,] as a separator): ");
            ConsoleEx.WriteLine("".PadLeft(115, '-'), ConsoleColor.DarkCyan);
            ConsoleEx.WriteLine(">>> TASK SCHEME:\ndescription,start_time,end_time,[all-day task (optional)],[important task (optional)]", ConsoleColor.Green);
            Console.WriteLine();
            ConsoleEx.WriteLine("Description [required]:\ncontent of the task", ConsoleColor.Gray);
            Console.WriteLine();
            ConsoleEx.WriteLine("Start_time [required]:\nthe start date of the task in format: [YYYY-MM-DD]", ConsoleColor.Gray);
            Console.WriteLine();
            ConsoleEx.WriteLine("End_time [optional]:\nthe end date of the task in format: [YYYY-MM-DD] --> leave empty if it is all-day task", ConsoleColor.Gray);
            Console.WriteLine();
            ConsoleEx.WriteLine("All-day task [optional]:\nenter [true] or [false]", ConsoleColor.Gray);
            Console.WriteLine();
            ConsoleEx.WriteLine("Important task [optional]:\nenter [true] or [false]", ConsoleColor.Gray);
            ConsoleEx.WriteLine("".PadLeft(115, '='), ConsoleColor.DarkCyan);
            Console.WriteLine();
            Console.Write("Enter new task [in scheme]: ");

            string taskData = Console.ReadLine().Trim();

            string[] checkData = taskData.Split(",");

            try
            {
                if (checkData[0] == null)
                {
                    throw new NullReferenceException();
                }
                else
                {
                    description = checkData[0]; // set Description
                }
            }
            catch (NullReferenceException)
            {
                ConsoleEx.Write("Missing task description.", ConsoleColor.Red);
                return(null);
            }

            try
            {
                char[] chars = checkData[1].ToCharArray();
                if (checkData[1].Trim().Length == 10 && chars[4] == '-' && chars[7] == '-')
                {
                    startTime = DateTime.Parse(checkData[1].Trim()); // set StartTime
                }
                else
                {
                    throw new FormatException();
                }
            }
            catch (FormatException)
            {
                ConsoleEx.Write("Incorrect date format.", ConsoleColor.Red);
                return(null);
            }

            if (string.IsNullOrWhiteSpace(checkData[2])) // EndTime is optional - set null if it is empty
            {
                endTime = null;
            }
            else
            {
                try
                {
                    char[] chars = checkData[1].ToCharArray();
                    if (checkData[2].Trim().Length == 10 && chars[4] == '-' && chars[7] == '-')
                    {
                        endTime = DateTime.Parse(checkData[2].Trim()); // set EndTime
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
                catch (Exception)
                {
                    ConsoleEx.Write("Incorrect date format.", ConsoleColor.Red);
                    return(null);
                }
            }

            if (checkData[3].Trim() == "true") // set AllDayTask flag
            {
                allDayTask = true;
            }
            else if (checkData[3].Trim() == "false")
            {
                allDayTask = false;
            }
            else
            {
                allDayTask = null;
            }

            if (checkData[4].Trim() == "true") // set ImportantTask flag
            {
                importantTask = true;
            }
            else if (checkData[4].Trim() == "false")
            {
                importantTask = false;
            }
            else
            {
                importantTask = null;
            }
            return(new TaskModel(description, startTime, endTime, allDayTask, importantTask));
        }
Пример #11
0
        // LoadTasks method loads all tasks form a file
        private static void LoadTasks(List <TaskModel> taskList)
        {
            string path = "";

            string[] listUpload = null;

            Console.Clear();
            MainMenu.Menu();
            ConsoleEx.WriteLine(" :: LOADING TASKS FROM A FILE :: ", ConsoleColor.DarkCyan);
            ConsoleEx.WriteLine("".PadLeft(115, '^'), ConsoleColor.DarkCyan);
            Console.WriteLine();
            Console.Write("Enter the file name: ");
            path = Console.ReadLine().Trim();

            if (File.Exists(path) == false)
            {
                ConsoleEx.Write("File was not found.", ConsoleColor.Red);
                Console.ReadLine();
                return;
            }

            string[]        linesFromLoadedFile = File.ReadAllLines(path);
            List <string[]> tasksFromLoadedFile = new List <string[]>();

            char[] separators = { ',', ';' };

            foreach (string item in linesFromLoadedFile)
            {
                tasksFromLoadedFile.Add(item.Split(separators));
                try
                {
                    foreach (string[] loadedTask in tasksFromLoadedFile)
                    {
                        DateTime?endTime;
                        if (string.IsNullOrWhiteSpace(loadedTask[2]))
                        {
                            endTime = null;
                        }
                        else
                        {
                            endTime = DateTime.Parse(loadedTask[2]);
                        }

                        bool?allDayTask;
                        if (string.IsNullOrWhiteSpace(loadedTask[3]))
                        {
                            allDayTask = null;
                        }
                        else
                        {
                            allDayTask = bool.Parse(loadedTask[3]);
                        }

                        bool?importantTask;
                        if (string.IsNullOrWhiteSpace(loadedTask[4]))
                        {
                            importantTask = null;
                        }
                        else
                        {
                            importantTask = bool.Parse(loadedTask[4]);
                        }

                        taskList.Add(new TaskModel(loadedTask[0], DateTime.Parse(loadedTask[1]), endTime, allDayTask, importantTask));
                    }
                    tasksFromLoadedFile.Clear();
                }
                catch (FormatException)
                {
                    ConsoleEx.Write("Wrong file format.", ConsoleColor.Red);
                    Console.ReadLine();
                    return;
                }
                catch (Exception)
                {
                    ConsoleEx.Write("An unknown error occurred.", ConsoleColor.Red);
                    Console.ReadLine();
                    return;
                }
            }
            Console.WriteLine();
            ConsoleEx.WriteLine(" >>> Tasks from the file was successfully loaded.\n", ConsoleColor.Green);
            Console.Write("Press ENTER to continue... ");
            Console.ReadLine();
        }