public static void ProceedCommand(int commandType, string command) { if (command == "exit") { return; } addedText.Clear(); PhoneScreen.Reload(); switch (commandType) { case 1: { bool numberFound = false; string isNumber = ""; if (command == "switch") { findingSwitch = !findingSwitch; PhoneScreen.Reload(); break; } for (int i = 0; i < command.Length; i++) { if (command[i] != ' ') { isNumber += command[i]; } } if (findingSwitch) { if (long.TryParse(isNumber, out long buffer)) { foreach (ContactClass findingNumber in PhoneDatabase.contacts) { bool exceptionFound = false; if (isNumber.Length > findingNumber.number.Length) { break; } for (int i = 0; i < isNumber.Length; i++) { if (findingNumber.BaseNumber[i] != isNumber[i]) { exceptionFound = true; break; } } if (!exceptionFound) { ShowResults(findingNumber, out numberFound); } } } else { foreach (ContactClass findingNumber in PhoneDatabase.contacts) { bool exceptionFound = false; if (command.Length > findingNumber.name.Length) { break; } for (int i = 0; i < command.Length; i++) { if (findingNumber.name[i] != command[i]) { exceptionFound = true; break; } } if (!exceptionFound) { ShowResults(findingNumber, out numberFound); } } } } else { if (long.TryParse(isNumber, out long buffer)) { foreach (ContactClass findingNumber in PhoneDatabase.contacts) { if (findingNumber.BaseNumber.Contains(isNumber)) { ShowResults(findingNumber, out numberFound); } } } else { foreach (ContactClass findingNumber in PhoneDatabase.contacts) { if (findingNumber.name.Contains(command)) { ShowResults(findingNumber, out numberFound); } } } } Console.WriteLine(""); if (!numberFound) { Console.WriteLine("Number not found!"); Console.WriteLine(""); } break; } case 2: { foreach (ContactClass contact in PhoneDatabase.contacts) { Console.WriteLine("{0}: {1}", contact.name, contact.number); } Console.ReadKey(true); PhoneCore.ForceReturn(); break; } case 3: { string recycledCommand = ""; for (int i = 0; i < command.Length; i++) { if (command[i] != ' ') { recycledCommand += command[i]; } } if (long.TryParse(recycledCommand, out long buffer)) { ContactClass contact = new ContactClass(); contact.number = recycledCommand; Console.Write("Phone name: "); contact.name = Console.ReadLine(); AddContact(contact); } else { ContactClass contact = new ContactClass(); contact.name = command; Console.Write("Phone number: "); string number = Console.ReadLine(); if (number.Contains(' ')) { number = contact.NumberConvertWithSpaces(number); } if (long.TryParse(number, out long secBuffer)) { contact.number = number; AddContact(contact); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Wrong Number!!!!"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("{Press any key to return}"); Console.ReadKey(true); PhoneCore.ForceReturn(); } } break; } case 4: { foreach (string titleText in removeContactMenu) { addedText.Add(titleText); } foreach (ContactClass contact in PhoneDatabase.contacts) { string textLine = contact.name + ": " + contact.number; addedText.Add(textLine); } PhoneScreen.LoadMenu(addedText); while (true) { ConsoleKey response = Console.ReadKey(true).Key; if (PhoneCore.CheckForSelectChange(response, out int value)) { PhoneScreen.MoveSelection(value); } else if (response == ConsoleKey.Backspace) { PhoneCore.ForceReturn(); break; } else if (response == ConsoleKey.Enter) { PhoneDatabase.contacts.Remove(PhoneDatabase.contacts[PhoneScreen.SelectionValue - 2]); PhoneCore.ForceReturn(); break; } } break; } } }
public static void Start() { PhoneScreen.Initialize(MenuManager.startMenu); while (true) { ConsoleKey response = new ConsoleKey(); string message = ""; if (typingMenu == 0) { response = Console.ReadKey(true).Key; } else if (typingMenu == 2) { MenuManager.ProceedCommand(2, ""); } else if (typingMenu == 4) { MenuManager.ProceedCommand(4, ""); } else { message = Console.ReadLine(); MenuManager.ProceedCommand(typingMenu, message); } if (CheckForSelectChange(response, out int value)) { PhoneScreen.MoveSelection(value); } if (CheckForConfirm(response)) { switch (PhoneScreen.SelectionValue) { case 0: { PhoneScreen.LoadMenu(MenuManager.findContactMenu); PhoneScreen.SetSelection(0); PhoneScreen.LockSelection(true); typingMenu = 1; break; } case 1: { PhoneScreen.LoadMenu(MenuManager.contactsListMenu); PhoneScreen.SetSelection(0); PhoneScreen.LockSelection(true); typingMenu = 2; break; } case 2: { PhoneScreen.LoadMenu(MenuManager.contactsListMenu); PhoneScreen.SetSelection(0); PhoneScreen.LockSelection(true); typingMenu = 3; break; } case 3: { PhoneScreen.LoadMenu(MenuManager.contactsListMenu); PhoneScreen.SetSelection(0); PhoneScreen.LockSelection(true); typingMenu = 4; break; } case 4: { Console.ForegroundColor = ConsoleColor.White; return; } } } if (CheckForReturn(message)) { ForceReturn(); } } }