private static void Import(ConsoleKey selectMenu, out bool exitMenuFiles) { if (File.Exists(Titles.FileXML)) { MainMenu.CommonStorage( Titles.FileXML, new FactoryXML(), false, string.Format(Titles.CorrectImport, Environment.CurrentDirectory, Titles.FileXML), string.Format(Titles.IncorrectImportWithLog, Environment.CurrentDirectory, Titles.FileXML, Titles.FileOfLog)); } else { Screen.ShowText(Titles.MenuToImport); bool exitMenuImport = false; try { while (!exitMenuImport) { Console.Clear(); Screen.ShowText(Titles.MenuToImport); selectMenu = Console.ReadKey().Key; switch (selectMenu) { case ConsoleKey.D1: case ConsoleKey.NumPad1: { MainMenu.CommonStorage( Titles.FileTXT, new FactoryTXTNotError(), false, string.Format(Titles.CorrectImport, Environment.CurrentDirectory, Titles.FileTXT), string.Format(Titles.ItemIsIncorrectInFile, Environment.CurrentDirectory, Titles.FileTXT)); exitMenuImport = true; break; } case ConsoleKey.D2: case ConsoleKey.NumPad2: { MainMenu.CommonStorage( Titles.FileTXT, new FactoryTXTWithError(), false, string.Format(Titles.CorrectImportWithLog, Environment.CurrentDirectory, Titles.FileTXT, Titles.FileOfLog), string.Format(Titles.EmptyFile, Environment.CurrentDirectory, Titles.FileTXT)); exitMenuImport = true; break; } case ConsoleKey.Q: exitMenuImport = true; break; default: break; } } } catch (FileNotFoundException ex) { Console.Clear(); Screen.ShowText(ex.Message); } } exitMenuFiles = true; }
internal static void SortByYear() { Console.Clear(); ConsoleKey selectSortMenu = ConsoleKey.A; if (Catalog.IsNotEmpty) { bool exitSortYear = false; List <ItemCatalog> catalogAfterSort = new List <ItemCatalog>(); var info = string.Empty; while (!exitSortYear) { Console.Clear(); Screen.ShowText(Titles.MenuToSortYear); selectSortMenu = Console.ReadKey().Key; Sorter.Sorting sortByYear = null; switch (selectSortMenu) { case ConsoleKey.D1: case ConsoleKey.NumPad1: sortByYear = Sorter.SortByYearASC; catalogAfterSort = Sorter.Sort(sortByYear, Catalog.AllItem); exitSortYear = true; break; case ConsoleKey.D2: case ConsoleKey.NumPad2: sortByYear = Sorter.SortByYearDESC; catalogAfterSort = Sorter.Sort(sortByYear, Catalog.AllItem); exitSortYear = true; break; case ConsoleKey.Q: exitSortYear = true; break; default: break; } } if (MainMenu.ConditionToAdd(selectSortMenu)) { Console.Clear(); info = Catalog.GetInfoSelectedItem(catalogAfterSort); Screen.ShowText(Titles.ShowCatalog, info, Titles.PressAnyKey); } } else { Screen.ShowText(Titles.EmptyCatalog); } if (selectSortMenu != ConsoleKey.Q) { Console.ReadKey(); } }
private static void SaveToFile(out bool exitMenuFiles) { if (Catalog.IsNotEmpty) { bool exitToUp = false; Screen.ShowText(Titles.SavedTypeMunu); ConsoleKey savedType = ConsoleKey.Q; while (!exitToUp) { Console.Clear(); Screen.ShowText(Titles.SavedTypeMunu); savedType = Console.ReadKey().Key; switch (savedType) { case ConsoleKey.D1: case ConsoleKey.NumPad1: { MainMenu.CommonStorage( Titles.FileTXT, new FactoryTXTNotError(), true, string.Format(Titles.MessageOfSaveFile, Environment.CurrentDirectory, Titles.FileTXT), string.Format(Titles.ErrorOfSaveFile, Environment.CurrentDirectory, Titles.FileTXT)); exitToUp = true; break; } case ConsoleKey.D2: case ConsoleKey.NumPad2: { MainMenu.CommonStorage( Titles.FileXML, new FactoryXML(), true, string.Format(Titles.MessageOfSaveFile, Environment.CurrentDirectory, Titles.FileXML), string.Format(Titles.ErrorOfSaveFile, Environment.CurrentDirectory, Titles.FileXML)); exitToUp = true; break; } case ConsoleKey.Q: exitToUp = true; break; default: break; } } } else { Screen.ShowText(Titles.EmptyCatalog); Console.ReadKey(); } exitMenuFiles = true; }
private static void Main(string[] args) { Console.Title = "Library"; bool exitMainMenu = false; while (!exitMainMenu) { Console.Clear(); Screen.ShowText(Titles.MainMenu); var selectMainMenu = Console.ReadKey().Key; switch (selectMainMenu) { case ConsoleKey.D1: case ConsoleKey.NumPad1: { MainMenu.Add(); break; } case ConsoleKey.D2: case ConsoleKey.NumPad2: { MainMenu.Edit(); break; } case ConsoleKey.D3: case ConsoleKey.NumPad3: { MainMenu.Delete(); break; } case ConsoleKey.D4: case ConsoleKey.NumPad4: { MainMenu.ShowCatalog(); break; } case ConsoleKey.D5: case ConsoleKey.NumPad5: { MainMenu.SearchByTitle(); break; } case ConsoleKey.D6: case ConsoleKey.NumPad6: { MainMenu.SortByYear(); break; } case ConsoleKey.D7: case ConsoleKey.NumPad7: { MainMenu.SearchBooksByAuthor(); break; } case ConsoleKey.D8: case ConsoleKey.NumPad8: { MainMenu.SearchBooksByPublisher(); break; } case ConsoleKey.D9: case ConsoleKey.NumPad9: { MainMenu.GroupByYear(); break; } case ConsoleKey.D0: case ConsoleKey.NumPad0: { MainMenu.WorkWithStorage(); break; } case ConsoleKey.Q: { exitMainMenu = true; break; } default: break; } } }