/// <summary> /// Метод добавляет записи из указанного файла к текущим записям из ежедневника /// </summary> public static void AddFromFile() { Console.Clear(); Console.WriteLine("МЕНЮ ДОБАВЛЕНИЯ ЗАПИСЕЙ ИЗ ФАЙЛА (нажмите ESC для возврата в главное Меню)"); if (Console.ReadKey(true).Key == ConsoleKey.Escape) { PlannerMain.Main(); } Console.SetCursorPosition(33, 0); Console.Write($"{" ",42}"); Console.SetCursorPosition(0, 2); Console.Write("Введите адрес файла для экспорта записей в текущий ежедневник: "); string newpath = Console.ReadLine(); //C:\Users\alien\Documents\Planner.txt try { StreamReader sr = new StreamReader(newpath, Encoding.Unicode); while (!sr.EndOfStream) { string[] text = sr.ReadLine().Split(','); Planner.daystring[Planner.index] = new DailyString(Convert.ToDateTime(text[0]), text[1], Convert.ToUInt32(text[2]), text[3], text[4]); Planner.index++; } sr.Close(); File.Delete(Planner.path); for (int i = 0; i < Planner.index; i++) { SaveInFile(i, Planner.path); } Console.WriteLine("Записи успешно добавлены!"); Thread.Sleep(4000); } catch (Exception) { Console.WriteLine("Файл не найден!"); Thread.Sleep(4000); try { throw; } catch (Exception) { PlannerMain.Main(); throw; } } }
/// <summary> /// Метод удаляет записи /// </summary> public static void Remove() { Console.Clear(); Planner.Print(); Console.WriteLine("\n\nМЕНЮ УДАЛЕНИЯ ЗАПИСЕЙ (нажмите ESC для возврата в главное Меню)\n"); if (Console.ReadKey(true).Key == ConsoleKey.Escape) { PlannerMain.Main(); } Console.SetCursorPosition(21, Planner.index + 2); Console.Write($"{" ",42}"); Console.SetCursorPosition(0, Planner.index + 4); Console.Write("Введите номер события или интервал для удаления(например: 4 или 1-5): "); string[] index = Console.ReadLine().Split('-'); try { uint i1 = Convert.ToUInt32(index[0]); if (i1 == 0) { i1 = 1 / i1; } if (i1 > Planner.index) { i1 = 1 / (i1 - i1); } uint i2; if (index.Length == 1) { i2 = i1; } else { i2 = Convert.ToUInt32(index[1]); } if (i1 > i2) { i1 = 1 / (i1 - i1); } File.Delete(Planner.path); for (uint i = 0; i < Planner.index; i++) { if (i == i1 - 1) { i = i2; } if (i == Planner.index) { break; } SaveInFile((int)i, Planner.path); } if (i1 != i2) { Console.WriteLine("События успешно удалены!"); } else { Console.WriteLine("Событие успешно удалено!"); } Thread.Sleep(4000); } catch (Exception) { Console.WriteLine("Неразборчиво написано! Давай еще разок, только теперь как на примере выше"); Thread.Sleep(4000); Remove(); try { throw; } catch (Exception) { PlannerMain.Main(); throw; } } }
/// <summary> /// Метод импортирует записи за указанный промежуток времени в указанный файл /// </summary> public static void ImportToFile() { Console.Clear(); Console.WriteLine("МЕНЮ ИМПОРТИРОВАНИЯ ЗАПИСЕЙ В ФАЙЛ (нажмите ESC для возврата в главное Меню)"); if (Console.ReadKey(true).Key == ConsoleKey.Escape) { PlannerMain.Main(); } Console.SetCursorPosition(35, 0); Console.Write($"{" ",42}"); Console.SetCursorPosition(0, 2); Console.Write($"Введите диапазон дат для импорта: от \n{"дд.мм.гггг",47}"); Console.SetCursorPosition(37, 2); string tempDate1 = Console.ReadLine(); DateTime start; try { start = Convert.ToDateTime(tempDate1); Console.SetCursorPosition(37 + tempDate1.Length, 2); Console.Write("(V)"); } catch (Exception) { try { Console.SetCursorPosition(37 + tempDate1.Length, 2); } catch (Exception) { Console.WriteLine("-10 очков Гриффиндору! Теперь вводи все заново"); Thread.Sleep(4000); ImportToFile(); } Console.Write("(X)"); Thread.Sleep(4000); ImportToFile(); try { throw; } catch (Exception) { PlannerMain.Main(); throw; } } Console.SetCursorPosition(41 + tempDate1.Length, 2); Console.Write($"до "); InterSecondDate: Console.SetCursorPosition(44 + tempDate1.Length, 3); Console.Write("дд.мм.гггг"); Console.SetCursorPosition(44 + tempDate1.Length, 2); string tempDate2 = Console.ReadLine(); DateTime end; try { end = Convert.ToDateTime(tempDate2); Console.SetCursorPosition(44 + tempDate2.Length + tempDate1.Length, 2); Console.Write("(V)"); } catch (Exception) { try { Console.SetCursorPosition(44 + tempDate2.Length + tempDate1.Length, 2); } catch (Exception) { Console.WriteLine("-10 очков Гриффиндору! Теперь вводи все заново"); Thread.Sleep(4000); ImportToFile(); try { throw; } catch (Exception) { PlannerMain.Main(); throw; } } Console.Write("(X)"); Thread.Sleep(4000); Console.Clear(); Console.WriteLine("МЕНЮ ИМПОРТИРОВАНИЯ ЗАПИСЕЙ В ФАЙЛ\n"); Console.Write($"Введите диапазон дат для импорта: от {tempDate1}(V) до "); goto InterSecondDate; } var example = "C:\\Users\\Public\\Documents\\Calendar.txt"; enterPath: Console.Write($"\nВведите путь к файлу для сохранения (например - {example}): "); string newpath = Console.ReadLine(); try { for (int i = 0; i < Planner.index; i++) { if (Planner.daystring[i].Date >= start && Planner.daystring[i].Date <= end.AddDays(1)) { SaveInFile(i, newpath); } } Console.WriteLine("Записи успешно импортированы!"); Thread.Sleep(4000); } catch (Exception) { Console.WriteLine("Кажется указанный путь не подходит для записи. Попробуй еще раз!"); Thread.Sleep(4000); Console.Clear(); Console.Write($"Введите диапазон дат для импорта: от {tempDate1}(V) до {tempDate2}(V)"); goto enterPath; } }
/// <summary> /// Метод редактирует существующие записи /// </summary> public static void Replace() { Console.Clear(); Planner.Print(); Console.WriteLine("\n\nМЕНЮ РЕДАКТИРОВАНИЯ ЗАПИСЕЙ (нажмите ESC для возврата в главное Меню)\n"); if (Console.ReadKey(true).Key == ConsoleKey.Escape) { PlannerMain.Main(); } Console.SetCursorPosition(28, Planner.index + 2); Console.Write($"{" ",42}"); Console.SetCursorPosition(0, Planner.index + 4); Console.Write($"Введите номер записи для изменения (1-{Planner.index}): "); uint index; try { index = Convert.ToUInt32(Console.ReadLine()) - 1; if (index >= Planner.index) { throw new OverflowException(); } } catch (Exception) { Console.WriteLine("Неразборчиво написано! Давай еще разок, только теперь как на примере выше"); Thread.Sleep(4000); Replace(); try { throw; } catch (Exception) { PlannerMain.Main(); throw; } } interNumber: Console.Write("Введите номер столбца для изменения (1-6): "); uint number; try { number = Convert.ToUInt32(Console.ReadLine()); if (number < 1 || number > 6) { throw new OverflowException(); } } catch (Exception) { Console.WriteLine("Неразборчиво написано! Давай еще разок, только теперь как на примере выше"); Thread.Sleep(4000); Console.Clear(); Planner.Print(); Console.WriteLine("\n\nМЕНЮ РЕДАКТИРОВАНИЯ ЗАПИСЕЙ\n"); Console.WriteLine($"Введите номер записи для изменения (1-{Planner.index}): {index+1}"); goto interNumber; } internewData: Console.Write("Введите новые данные: "); string newData = Console.ReadLine(); switch (number) { case 1: DateTime date; try { date = Convert.ToDateTime(newData).Add(Planner.daystring[index].Date.TimeOfDay); } catch (Exception) { Console.WriteLine("Неразборчиво написано! Давай еще разок, только теперь как на примере выше"); Thread.Sleep(4000); Console.Clear(); Planner.Print(); Console.WriteLine("\n\nМЕНЮ РЕДАКТИРОВАНИЯ ЗАПИСЕЙ\n"); Console.WriteLine($"Введите номер записи для изменения (1-{Planner.index}): {index + 1}"); Console.WriteLine($"Введите номер столбца для изменения (1-6): {number}"); goto internewData; } Planner.daystring[index].Date = date; File.Delete(Planner.path); for (uint i = 0; i < Planner.index; i++) { SaveInFile((int)i, Planner.path); } break; case 2: try { date = Planner.daystring[index].Date.Date.Add(Convert.ToDateTime(newData).TimeOfDay); } catch (Exception) { Console.WriteLine("Неразборчиво написано! Давай еще разок, только теперь как на примере выше"); Thread.Sleep(4000); Console.Clear(); Planner.Print(); Console.WriteLine("\n\nМЕНЮ РЕДАКТИРОВАНИЯ ЗАПИСЕЙ\n"); Console.WriteLine($"Введите номер записи для изменения (1-{Planner.index}): {index + 1}"); Console.WriteLine($"Введите номер столбца для изменения (1-6): {number}"); goto internewData; } Planner.daystring[index].Date = date; File.Delete(Planner.path); for (uint i = 0; i < Planner.index; i++) { SaveInFile((int)i, Planner.path); } break; case 3: Planner.daystring[index].Event = newData; File.Delete(Planner.path); for (uint i = 0; i < Planner.index; i++) { SaveInFile((int)i, Planner.path); } break; case 4: try { Planner.daystring[index].Duration = Convert.ToUInt32(newData); } catch (Exception) { Console.WriteLine("Неразборчиво написано! Давай еще разок, только теперь как на примере выше"); Thread.Sleep(4000); Console.Clear(); Planner.Print(); Console.WriteLine("\n\nМЕНЮ РЕДАКТИРОВАНИЯ ЗАПИСЕЙ\n"); Console.WriteLine($"Введите номер записи для изменения (1-{Planner.index}): {index + 1}"); Console.WriteLine($"Введите номер столбца для изменения (1-6): {number}"); goto internewData; } File.Delete(Planner.path); for (uint i = 0; i < Planner.index; i++) { SaveInFile((int)i, Planner.path); } break; case 5: Planner.daystring[index].Place = newData; File.Delete(Planner.path); for (uint i = 0; i < Planner.index; i++) { SaveInFile((int)i, Planner.path); } break; case 6: Planner.daystring[index].Note = newData; File.Delete(Planner.path); for (uint i = 0; i < Planner.index; i++) { SaveInFile((int)i, Planner.path); } break; } }
/// <summary> /// Метод добавляет записи введеные с консоли /// </summary> public static void Add() { Console.Clear(); int lastindex = Planner.index + 1; Console.WriteLine("МЕНЮ ДОБАВЛЕНИЯ НОВОЙ ЗАПИСИ (нажмите ESC для возврата в главное Меню)"); Console.WriteLine("\nПример полной записи: 12.12.12 12:00,Встреча с Аленой,2,Аквамарин,Обсудить цветы"); Console.WriteLine("Пример сокращенной записи: Встреча с Аленой,Аквамарин,Обсудить цветы"); if (Console.ReadKey(true).Key == ConsoleKey.Escape) { PlannerMain.Main(); } Console.SetCursorPosition(29, 0); Console.Write($"{" ",42}"); Console.SetCursorPosition(0, 5); Console.Write("Новое событие: "); string[] text = Console.ReadLine().Split(','); while (text.Length != 3 && text.Length != 5) { Console.Write("Неразборчиво написано! Давай еще разок, только теперь как на примере выше"); Thread.Sleep(4000); Add(); } try { switch (text.Length) { case 3: Planner.daystring[lastindex] = new DailyString(text[0], text[1], text[2]); break; case 5: Planner.daystring[lastindex] = new DailyString(Convert.ToDateTime(text[0]), text[1], Convert.ToUInt32(text[2]), text[3], text[4]); break; } } catch (Exception) { Console.WriteLine("Неразборчиво написано! Давай еще разок, только теперь как на примере выше"); Thread.Sleep(4000); Add(); try { throw; } catch (Exception) { PlannerMain.Main(); throw; } } SaveInFile(lastindex, Planner.path); Console.Write("Событие успешно добавлено!"); Thread.Sleep(4000); }
/// <summary> /// Основной метод, который вызывает метод Load() и Print(), а также методы для работы с записями, в зависимости от ввода пользователя /// </summary> /// <returns>Возвращает 0</returns> public static int Menu() { Console.Clear(); Load(); Print(); Console.WriteLine("\n\nМЕНЮ"); Console.WriteLine(); Console.WriteLine("1 - добавить запись; 5 - сортировать список по длительности;"); Console.WriteLine("2 - удалить записи; 6 - сортировать список по дате; "); Console.WriteLine("3 - редактировать запись; 7 - добавить записи из нового файла;"); Console.WriteLine("4 - прочитать инструкцию; 8 - импортировать записи в новый файл;"); Console.Write("\nВвод: "); try { input = Convert.ToInt32(Console.ReadLine()); } catch (Exception) { PlannerMain.Main(); throw; } switch (input) { case 1: EditPlanner.Add(); break; case 2: EditPlanner.Remove(); break; case 3: EditPlanner.Replace(); break; case 4: EditPlanner.Instruction(); break; case 5: EditPlanner.SortBy(); break; case 6: EditPlanner.SortBy(); break; case 7: EditPlanner.AddFromFile(); break; case 8: EditPlanner.ImportToFile(); break; default: break; } PlannerMain.Main(); return(0); }