// Menu for listing persons in my class public static void ListAllClassmates(List <Classmates> listOfClassmates) { do { top = 7; left = 35; FileHandling.LogoPrint("start"); PrintMenu(listAllClassmatesMenu); Console.SetCursorPosition(left, top); Print.Yellow($"Det finns {listOfClassmates.Count} st i klassen, och dessa är:"); for (int i = 0; i < listOfClassmates.Count; i++) { top++; Console.SetCursorPosition(left, top); Console.WriteLine($"{i+1}. {listOfClassmates[i].Name}, {listOfClassmates[i].Age} år"); } if (listOfClassmates.Count == 0) { Console.SetCursorPosition(left, top); Print.Yellow("Inga personer finns i klassen "); } top = listAllClassmatesMenu.Count + 10; left = 0; Console.SetCursorPosition(left, top); Print.Blue(@"Ange ett alternativ \>"); string userInput = Console.ReadLine().ToLower(); switch (userInput) { case "b": StartMenu(listOfClassmates); break; case "a": Environment.Exit(0); break; default: top = listAllClassmatesMenu.Count + 11; left = 0; Console.SetCursorPosition(left, top); Print.Red("Felaktigt val, försök igen"); Thread.Sleep(1500); ListAllClassmates(listOfClassmates); break; } } while (true); }
/*---------------------------------------------------------- * DIFFERENT MENUES * ----------------------------------------------------------*/ public static void StartMenu(List <Classmates> listOfClassmates) { do { Console.Clear(); FileHandling.LogoPrint("start"); PrintMenu(startMenu); Print.Blue(@"Ange ett alternativ \>"); int menuChoice; int.TryParse(Console.ReadLine(), out menuChoice); switch (menuChoice) { case 1: Menus.ListAllClassmates(listOfClassmates); break; case 2: Menus.ListDetailsClassmates(listOfClassmates, listBasicClassmatesMenu); break; case 3: RemoveMenu(listOfClassmates, listBasicClassmatesMenu); break; case 4: listOfClassmates.Clear(); Classmates.Populate(listOfClassmates); FileHandling.BinarySerializer(listOfClassmates); top = startMenu.Count + 11; left = 0; Console.SetCursorPosition(left, top); Print.Yellow("Mockdata återställd"); Thread.Sleep(1500); break; case 5: Environment.Exit(0); break; case 0: default: top = startMenu.Count + 11; left = 0; Console.SetCursorPosition(left, top); Print.Red("Felaktigt val, försök igen"); Thread.Sleep(1500); break; } } while (true); }
// Menu for removing persons public static void RemoveMenu(List <Classmates> listOfClassmates, List <string> menuList) { do { top = menuList.Count + 5; left = 35; FileHandling.LogoPrint("remove"); PrintMenu(menuList); Console.SetCursorPosition(left, top); Print.Yellow($"Välj person att ta bort:"); for (int i = 0; i < listOfClassmates.Count; i++) { top++; Console.SetCursorPosition(left, top); Console.WriteLine($"{i + 1}. {listOfClassmates[i].Name}"); } if (listOfClassmates.Count == 0) { Console.SetCursorPosition(left, top); Print.Yellow("Inga personer finns i klassen"); } top = menuList.Count + 11; left = 0; Console.SetCursorPosition(left, top); Print.Blue(@"Ange ett alternativ \>"); string userInput = Console.ReadLine().ToLower(); int convertedInput = 100; try { convertedInput = Convert.ToInt32(userInput); } catch { switch (userInput) { case "b": StartMenu(listOfClassmates); break; case "a": Environment.Exit(0); break; default: top = listAllClassmatesMenu.Count + 12; left = 0; Console.SetCursorPosition(left, top); Print.Red("Felaktigt val, försök igen"); Thread.Sleep(1500); break; } } if (convertedInput != 100) { switch (convertedInput) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: if (convertedInput > listOfClassmates.Count) { Console.SetCursorPosition(left, top); Print.Red("Felaktigt val, försök igen"); } else { listOfClassmates.RemoveAt(convertedInput - 1); FileHandling.BinarySerializer(listOfClassmates); } break; default: top = listAllClassmatesMenu.Count + 12; left = 0; Console.SetCursorPosition(left, top); Print.Red("Felaktigt val, försök igen"); Thread.Sleep(1500); break; } } } while (true); }
// Menu for listing details of my classmates public static void ListDetailsClassmates(List <Classmates> listOfClassmates, List <string> menuList) { do { top = menuList.Count + 6; left = 35; FileHandling.LogoPrint("details"); //Prints menu PrintMenu(menuList); Console.SetCursorPosition(left, top); //List all the classmates from listOfClassmates Print.Yellow($"Visa info om:"); for (int i = 0; i < listOfClassmates.Count; i++) { top++; Console.SetCursorPosition(left, top); Console.WriteLine($"{i + 1}. {listOfClassmates[i].Name}"); } if (listOfClassmates.Count == 0) { Console.SetCursorPosition(left, top); Print.Yellow("Inga personer finns i klassen"); } top = menuList.Count + 11; left = 0; Console.SetCursorPosition(left, top); Print.Blue(@"Ange ett alternativ \>"); string userInput = Console.ReadLine().ToLower(); int convertedInput = 100; //Try Catch for checking if the user pressed an integer button or chars 'a' or 'b' try { convertedInput = Convert.ToInt32(userInput); } catch { switch (userInput) { case "b": StartMenu(listOfClassmates); break; case "a": Environment.Exit(0); break; default: top = listAllClassmatesMenu.Count + 12; left = 0; Console.SetCursorPosition(left, top); Print.Red("Felaktigt val, försök igen"); Thread.Sleep(1500); break; } } if (convertedInput != 100) { switch (convertedInput) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: if (convertedInput > listOfClassmates.Count) { Console.SetCursorPosition(left, top); Print.Red("Felaktigt val, försök igen"); } else { listOfClassmates[convertedInput - 1].ShowDetails(); } break; default: top = listAllClassmatesMenu.Count + 12; left = 0; Console.SetCursorPosition(left, top); Print.Red("Felaktigt val, försök igen"); Thread.Sleep(1500); break; } } } while (true); }