public static void findInTableByDate(DB_impl DB, Task_manager_impl tm, ConsoleIO_impl IO)
        {
            IO.clear();
            IO.print("Для поиска по дате введите дату\n"
                     + "[Назад - esc]");
            string         date_string;
            ConsoleKeyInfo cki;
            DateTime       date = DateTime.Now;

            while (true)
            {
                date_string = "";
                cki         = IO.getKeyFromUser();
                while (cki.Key != ConsoleKey.Enter)
                {
                    if (cki.Key == ConsoleKey.Escape)
                    {
                        throw new ProcessToShowTable();
                    }
                    date_string += cki.KeyChar;
                    cki          = IO.getKeyFromUser();
                }

                date_string = date_string.Replace(".", "/").Replace(",", "/")
                              .Replace(":", "/").Replace(";", "/").Replace("-", "/");
                if (new Regex(@"\d{2,2}/\d{2,2}/\d{4,4}").IsMatch(date_string))
                {
                    date_string = date_string.Substring(6) + "/" + date_string.Substring(3, 2) + "/" + date_string.Substring(0, 2);
                }

                date = new DateTime();
                if (!(new Regex(@"\d{4,4}/\d{2,2}/\d{2,2}").IsMatch(date_string)) ||
                    !DateTime.TryParse(date_string, out date))
                {
                    IO.clear();
                    IO.print("Ошибка! Неверный формат даты\nДля поиска по дате введите дату\n"
                             + "[Назад - esc]");
                }
                else
                {
                    break;
                }
            }

            IO.print("Поиск по дате - " + date.ToString().Substring(0, 10));
            tm.findTasksByDate(date);
            IO.printTable(new string[] { "id", "[X]/[ ]", "Дата", "Задание" }, tm.getTaskManagerDataGrid());
            IO.print("Нажмите любую клавишу для возврата.");
            IO.getKeyFromUser();
            throw new ProcessToShowTable();
        }
Esempio n. 2
0
        public static void editTasksAtTableByDate(DB_impl DB, Task_manager_impl tm, ConsoleIO_impl IO)
        {
            IO.clear();
            IO.print("Список " + DB.MainTable);
            tm = DB.getAllTasks();
            IO.printTable(new string[] { "id", "[X]/[ ]", "Дата", "Задание" }, tm.getTaskManagerDataGrid());
            IO.print("Для редактирования по дате введите дату\n"
                     + "[Назад - esc]");
            string         date_string;
            ConsoleKeyInfo cki;
            DateTime       date = DateTime.Now;

            while (true)
            {
                while (true)
                {
                    date_string = "";
                    cki         = IO.getKeyFromUser();
                    while (cki.Key != ConsoleKey.Enter)
                    {
                        if (cki.Key == ConsoleKey.Escape)
                        {
                            throw new ProcessToShowTable();
                        }
                        date_string += cki.KeyChar;
                        cki          = IO.getKeyFromUser();
                    }

                    date_string = date_string.Replace(".", "/").Replace(",", "/")
                                  .Replace(":", "/").Replace(";", "/").Replace("-", "/");
                    if (new Regex(@"\d{2,2}/\d{2,2}/\d{4,4}").IsMatch(date_string))
                    {
                        date_string = date_string.Substring(6) + "/" + date_string.Substring(3, 2) + "/" + date_string.Substring(0, 2);
                    }

                    date = new DateTime();
                    if (!(new Regex(@"\d{4,4}/\d{2,2}/\d{2,2}").IsMatch(date_string)) ||
                        !DateTime.TryParse(date_string, out date))
                    {
                        IO.clear();
                        IO.printTable(new string[] { "id", "[X]/[ ]", "Дата", "Задание" }, tm.getTaskManagerDataGrid());
                        IO.print("Ошибка! Неверный формат даты\nДля редактирования по дате введите дату\n"
                                 + "[Назад - esc]");
                    }
                    else
                    {
                        break;
                    }
                }
                tm.findTasksByDate(date);
                if (tm.getTasks().Count == 0)
                {
                    tm = DB.getAllTasks();
                    IO.clear();
                    IO.printTable(new string[] { "id", "[X]/[ ]", "Дата", "Задание" }, tm.getTaskManagerDataGrid());
                    IO.print("Не найдено совпадений! Введите дату еще раз!");
                }
                else
                {
                    break;
                }
            }

            IO.clear();
            tm.getTasks().ForEach(e => editSingleTask(e, tm, IO));
            DB.updateTasks(tm);
            IO.print("Редактирование выполнено успешно. Нажмите любую клавишу для возврата.");
            IO.getKeyFromUser();
            throw new ReturnToTableMenu();
        }