static void DeletePerson(ref PersonList personList) { Console.Clear(); ShowTheList(ref personList); Console.WriteLine("Please, enter index of person that you want to delete:"); string n = Console.ReadLine(); int index; bool success = Int32.TryParse(n, out index); if (success) { if (index > personList.People.Length) { Console.WriteLine("There is no person with such index.\n"); } else { personList.People = personList.DeletePerson(index + 4); Console.Clear(); Console.WriteLine("Person is deleted.\n"); } } else { Console.Clear(); Console.WriteLine("Invalid index! Try again."); } }
static void AddPerson(ref PersonList peoplelist) { Person p1 = new Person(); Console.Clear(); Console.WriteLine("Please, follow the instructions and fill gaps. Enter the name: "); p1.name = Console.ReadLine(); Console.WriteLine("Surname: "); p1.surname = Console.ReadLine(); Console.WriteLine("SurSurName: "); p1.sursurname = Console.ReadLine(); Console.WriteLine("Sex: "); p1.sex = Console.ReadLine(); Console.WriteLine("Adres: "); p1.adres = Console.ReadLine(); Console.WriteLine("Telephone number: "); string telephone = Console.ReadLine(); long number; bool success = Int64.TryParse(telephone, out number); if (success) { p1.tnumber = number; peoplelist.AddPerson(p1); Console.WriteLine("Person is added to Database\n"); } else { Console.Clear(); Console.WriteLine("Invalid telephone number! Try again."); } }
static void FindPerson(ref PersonList peoplelist) { Console.Clear(); Console.WriteLine("Please enter surname of the person that you want to find:"); string find = Console.ReadLine(); peoplelist.FindPerson(find); }
static PersonList InitializePeopList() { Person[] pl = new Person[5]; for (int i = 0; i < pl.Length; ++i) { pl[i] = Person.GenPeop(i + 1); } PersonList ps = new PersonList(pl); return(ps); }
//Метод, который показывает список персон static void ShowTheList(ref PersonList peoplelist) { Console.Clear(); Console.WriteLine("List of people:"); if (peoplelist.People.Length > 5) { for (int i = 0; i < peoplelist.People.Length; ++i) { if (i > 4) { Console.WriteLine(i - 4 + ")" + peoplelist.People[i].surname); } } } else { Console.Clear(); Console.WriteLine("No people was added.\n"); } }
static void Main(string[] args) { PersonList peoplelist = InitializePeopList(); ConsoleKey button = ConsoleKey.P; Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Gray; Console.Clear(); Console.WriteLine("People DataBase Menu. Version 0.0.1. \n\n"); do { Console.WriteLine("Choose what do you want to do:\n" + "Press A: to add a person\n" + "Press B: to find a person\n" + "Press C: to show the list\n" + "Press D: to delete a person\n" + "Press E: to exit\n" + "\n\n"); button = Console.ReadKey().Key; switch (button) { case ConsoleKey.A: AddPerson(ref peoplelist); break; case ConsoleKey.B: FindPerson(ref peoplelist); break; case ConsoleKey.E: break; case ConsoleKey.C: ShowTheList(ref peoplelist); break; case ConsoleKey.D: DeletePerson(ref peoplelist); break; } }while (button != ConsoleKey.E); }