/// <summary> /// Method for displaying the current values of class fields /// </summary> /// <param name="p"></param> public static void DisplayPersonAccaunt(PersonAccaunt p) { Console.Clear(); Console.WriteLine("----------------------------"); Console.WriteLine("First name : {0}", p.FirstName); Console.WriteLine("Last name : {0}", p.LastName); Console.WriteLine("City : {0}", p.CityOfResidence); if (p.PostIndex == 0) { Console.WriteLine("Post index : unknown"); } else { Console.WriteLine("Post index : {0}", p.PostIndex); } Console.WriteLine("Street : {0}", p.CityStreet); if (p.NumberOfHous == 0) { Console.WriteLine("Hous : unknown"); } else { Console.WriteLine("Hous : {0}", p.NumberOfHous); } if (p.ApartmentNumber == 0) { Console.WriteLine("Apartment : unknown"); } else { Console.WriteLine("Apartment : {0}", p.ApartmentNumber); } if (p.MobilPhone == 0) { Console.WriteLine("Phone : unknown"); } else { Console.WriteLine("Phone : +380{0}", p.MobilPhone); } Console.WriteLine("Time of registration : {0}", p.DateOfRegistration); Console.WriteLine("Date of registration : {0}", p.TimeOfRegistration); }
/// <summary> /// This method, before starting its work, asks the user type absolute path for file of the future phonebook by wich it will be created. /// If this path exists, the method displays message about this, otherwise it offers to create a folder with a file in the current directory. /// After that, it requests with verification from the user abonent's data and displays their final set on the screen. /// If everything is correct, data is added to the phonebook, otherwise user can enter the data again. /// </summary> public static void CreateNewPhoneBook() { StringBuilder sb = new StringBuilder(); var currentDirectory = Directory.GetCurrentDirectory(); var phoneBookDirectory = Directory.CreateDirectory(Path.Combine(currentDirectory, "PhoneBookDir")); var continueInputOk = true; string abonentName, abonentLastName, abonentCity, abonentStreet; uint abonentIndex, abonentHous, abonentApartment, abonentPhoneNamber; while (continueInputOk) { var enteredPath = GetPathForFile(); try { if (Directory.Exists(enteredPath)) { Console.WriteLine("Directory exist."); try { var phoneBookDirectory1 = Directory.CreateDirectory(Path.Combine(enteredPath, "PhoneBookDir")); phoneBookDirectory = phoneBookDirectory1; continueInputOk = false; } catch (Exception ex) { Console.WriteLine("Imposible to create file by entered path.\n"); Console.WriteLine(ex.Message + "\n\n"); Console.WriteLine("Press any key..."); Console.ReadLine(); } } else { Console.WriteLine("Imposible to create file by entered path.\n"); Console.WriteLine("Create new Phone book in this directory: \n" + phoneBookDirectory + " ? y/n "); if (Console.ReadLine() == "y") { Console.WriteLine("File whill be created by this path: \n" + phoneBookDirectory); continueInputOk = false; break; } } } catch (Exception ex) { Console.WriteLine("Imposible to create file by this path.\n"); Console.WriteLine(ex.ToString() + "\n\n"); Console.WriteLine("Press any key..."); Console.ReadLine(); } } continueInputOk = true; while (continueInputOk) { CheckInputDataPerson(out abonentName, out abonentLastName, out abonentCity, out abonentIndex, out abonentStreet, out abonentHous, out abonentApartment, out abonentPhoneNamber); var person = new PersonAccaunt(abonentName, abonentLastName, abonentCity, abonentIndex, abonentStreet, abonentHous, abonentApartment, abonentPhoneNamber); PersonAccaunt.DisplayPersonAccaunt(person); Console.WriteLine("===============================================\n"); Console.Write("Is all right? Add this person in Phone Book? y/n "); if (Console.ReadLine() == "y") { p = person; p.WritePersonInFile(sb, phoneBookDirectory); Console.WriteLine("Abonent added..."); Console.Write("Add new abonent? y/n "); if (Console.ReadLine() == "y") { Console.Clear(); } else { continueInputOk = false; } } }