Example #1
0
        public static void AddEntriesFromFile(PhoneDirectory input)
        {
            const string path     = "../../contacts.txt";
            var          readText = File.ReadAllLines(path);
            var          updated  = 0;
            var          created  = 0;

            foreach (var s in readText)
            {
                if (!s.Equals(" "))
                {
                    string[] line = s.Split(new string[] { ", " }, StringSplitOptions.None);
                    if (input.PutNumber(line[0], line[1]) == "updated")
                    {
                        updated++;
                    }
                    else
                    {
                        created++;
                    }
                }
            }
            Console.WriteLine($"{readText.Length} contacts processed!");
            Console.WriteLine($"{updated} contact(s) updated, {created} contact(s) created.");
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            PhoneDirectory phoneDir = new PhoneDirectory();
            int            choice;

            do
            {
                choice = ShowMenu.Menu();
                if (choice == 1)
                {
                    AddEntry.AddEntryToPb(phoneDir);
                    Console.Clear();
                }
                else if (choice == 2)
                {
                    AddEntries.AddEntriesFromFile(phoneDir);
                    Console.Clear();
                }
                else if (choice == 3)
                {
                    GetContact.GetContactFromPb(phoneDir);
                    Console.Clear();
                }
                else if (choice == 4)
                {
                    GetAllContacts.GetAllContactsFromPb(phoneDir);
                    Console.Clear();
                }
            } while (choice != 5);

            Console.Clear();
            Console.WriteLine(new string('=', 50));
            Console.WriteLine(new string(' ', 10) + "Thank you for using Phone Book" + new string(' ', 10));
            System.Threading.Thread.Sleep(1500);
        }
Example #3
0
        private static void Main(string[] args)
        {
            PhoneDirectory myDirectory = new PhoneDirectory("Marija B.", "22222222");

            myDirectory.PutNumber("Jon Snow", "999999999");
            myDirectory.PrintPhoneDirectory();
            myDirectory.GetNumber("Marija B.");
        }
Example #4
0
        public static void AddEntryToPb(PhoneDirectory input)
        {
            Console.WriteLine("Please enter contact name:");
            var name = Console.ReadLine();

            Console.WriteLine("Please enter contact number:");
            var number = Console.ReadLine();

            input.PutNumber(name, number);
            Console.WriteLine("Contact added!");
            Console.ReadKey();
        }
Example #5
0
 public static void GetAllContactsFromPb(PhoneDirectory input)
 {
     if (input.GetLength() == 0)
     {
         Console.WriteLine("Sorry, no entries in Phone Book!");
     }
     else
     {
         for (int i = 0; i < input.GetLength(); i++)
         {
             Console.WriteLine($"Name: {input.GetName(i)}, Number: {input.GetNumber(input.GetName(i))}");
         }
     }
     Console.ReadKey();
 }
        public static void GetContactFromPb(PhoneDirectory input)
        {
            Console.WriteLine("Please enter contact name:");
            var name = Console.ReadLine();

            if (input.GetNumber(name) == null)
            {
                Console.WriteLine($"Sorry, no contact {name} in Phone Book!");
            }
            else
            {
                Console.WriteLine($"Name: {name}, Number: {input.GetNumber(name)}");
            }
            Console.ReadKey();
        }
        private static void Main(string[] args)
        {
            PhoneDirectory person1 = new PhoneDirectory();

            person1.AddNumber("Jana", "1234567");

            // PhoneDirectory person1 = new PhoneDirectory();
            person1.AddNumber("Zane", "2345678");

            //PhoneDirectory person3 = new PhoneDirectory();
            person1.AddNumber("Ilze", "3456789");

            person1.PrintContacts();

            person1.FindByName("Zane");
            person1.FindByNumber("3456789");

            Console.ReadKey();
        }