public Task_manager_impl getAllTasks() { if (mainTable.Equals("")) { throw new Exception(); } Task_manager_impl tm = new Task_manager_impl(); DB.executeQuery("SELECT * FROM " + mainTable, true) .ForEach(e => tm.addTask(int.Parse(e[0]), e[1], DateTime.Parse(e[2]), bool.Parse(e[3]))); return(tm); }
public static void addTaskToTable(DB_impl DB, Task_manager_impl tm, ConsoleIO_impl IO) { IO.clear(); IO.print("Добавление новой задачи\n[Назад - esc]\nВведите задание:"); string text = ""; ConsoleKeyInfo cki = IO.getKeyFromUser(); while (cki.Key != ConsoleKey.Enter) { if (cki.Key == ConsoleKey.Escape) { throw new ProcessToShowTable(); } text += cki.KeyChar; cki = IO.getKeyFromUser(); } IO.print(text + "\nВведите дату:"); string date_string; 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Введите дату"); } else { break; } } tm = new Task_manager_impl(); tm.addTask(text, date); IO.getKeyFromUser(); DB.updateTasks(tm); IO.clear(); IO.print("Успешно добавлено"); IO.getKeyFromUser(); throw new ProcessToAddTaskToTable(); }