Example #1
0
        public void FindPersonDetails(string name)
        {
            var persondteils = phonebook.findPerson(name);

            Console.WriteLine("Name = {0}, Phonenumber = {1}, Address = {2}", persondteils.name, persondteils.phoneNumber, persondteils.address);
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                DatabaseUtil.initializeDatabase();

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                Program   program   = new Program();
                PhoneBook phonebook = new PhoneBook();
                Person    person    = new Person();

                phonebook.addPerson(program.FillPerson("John Smith", "(248) 123-4567", "1234 Sand Hill Dr, Royal Oak, MI"));
                phonebook.addPerson(program.FillPerson("Cynthia Smith", "(824) 128-8758", "875 Main St, Ann Arbor, MI"));

                // TODO: print the phone book out to System.out
                Console.WriteLine(phonebook.printPhonebook());
                // TODO: find Cynthia Smith and print out just her entry
                person = phonebook.findPerson("Cynthia", "Smith");
                Console.WriteLine("Result Found" + " ** " + person.name + " " + person.phoneNumber + " " + person.address);
                // TODO: insert the new person objects into the database
                phonebook.addPerson(program.FillPerson(person.name, person.phoneNumber, person.address));
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            try
            {
                DatabaseUtil.initializeDatabase();
                var phonebook = new PhoneBook();

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                var person1 = new Person()
                {
                    name = "John Smith", phoneNumber = "(248) 123-4567", address = "1234 Sand Hill Dr, Royal Oak, MI"
                };
                var person2 = new Person()
                {
                    name = "Cynthia Smith", phoneNumber = "(824) 128-8758", address = "875 Main St, Ann Arbor, MI"
                };

                phonebook.addPerson(person1);
                Console.WriteLine($"Adding John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI");
                phonebook.addPerson(person2);
                Console.WriteLine($"Adding Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI");

                // TODO: print the phone book out to System.out
                Console.WriteLine();
                Console.WriteLine($"Phonebook Items:");
                foreach (var person in phonebook.getPhonebook())
                {
                    Console.WriteLine($"Name: {person.name}, Phonenumber: {person.phoneNumber}, Address: {person.address}");
                }

                // TODO: find Cynthia Smith and print out just her entry
                var cynthia = phonebook.findPerson("CyNThiA", "smith");
                if (cynthia != null)
                {
                    Console.WriteLine();
                    Console.WriteLine($"Showing Just Cynthia");
                    Console.WriteLine($"Name: {cynthia.name}, Phonenumber: {cynthia.phoneNumber}, Address: {cynthia.address}");
                }
                else
                {
                    Console.WriteLine($"Cynthia not found!");
                }

                // TODO: insert the new person objects into the database isn't this the 1st step?

                Console.ReadKey();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #4
0
        private void PerformActions()
        {
            try
            {
                DatabaseUtil.initializeDatabase();

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                phonebook.addPerson(new Person()
                {
                    Name        = "John Smith",
                    PhoneNumber = "(248) 123-4567",
                    Address     = "1234 Sand Hill Dr, Royal Oak, MI"
                });
                phonebook.addPerson(new Person()
                {
                    Name        = "Cynthia Smith",
                    PhoneNumber = "(824) 128-8758",
                    Address     = "875 Main St, Ann Arbor, MI"
                });

                // TODO: print the phone book out to System.out
                List <Person> people = phonebook.GetPhoneBook();
                foreach (Person person in people)
                {
                    Console.WriteLine(person);
                    Console.WriteLine("--------------------------------------------------");
                }
                // TODO: find Cynthia Smith and print out just her entry
                Person cynthia = phonebook.findPerson("Cynthia", "Smith");
                if (null != cynthia)
                {
                    Console.WriteLine("-------Found - Cynthia Smith-------");
                    Console.WriteLine(cynthia);
                }
                else
                {
                    Console.WriteLine("'Cynthia Smith' can't be found");
                }
                // TODO: insert the new person objects into the database
                phonebook.addPerson(new Person()
                {
                    Name = "Donald Trump"
                });
                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #5
0
        //private PhoneBook phonebook = new PhoneBook();

        static void Main(string[] args)
        {
            try
            {
                // DatabaseUtil.initializeDatabase();

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */

                // TODO: print the phone book out to System.out
                // TODO: find Cynthia Smith and print out just her entry
                // TODO: insert the new person objects into the database

                PhoneBook phonebook = new PhoneBook();

                Person person = new Person();
                person.name        = "John Smith";
                person.phoneNumber = "(248) 123-4567";
                person.address     = "1234 Sand Hill Dr, Royal Oak, MI";
                phonebook.addPerson(person);
                Console.Write(phonebook);


                Person person1 = new Person();
                person1.name        = "Cynthia Smith ";
                person1.phoneNumber = "(824) 128-8758, 875";
                person1.address     = "875 Main St, Ann Arbor, MI";

                phonebook.addPerson(person1);

                string name = person.name;

                phonebook.findPerson(name);
                //Console.WriteLine("record added");
                // Console.ReadLine();
            }
            catch (Exception)
            {
                throw;
            }
            //finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            try
            {
                //DatabaseUtil.CleanUp();
                DatabaseUtil.initializeDatabase();
                PhoneBook phonebook = new PhoneBook();
                /* TODO: create person objects and put them in the PhoneBook and database
                * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                */

                // TODO: insert the new person objects into the database
                Person objPerson1 = new Person { name = "John Smith", phoneNumber = "(248) 123-4567", address = "1234 Sand Hill Dr, Royal Oak, MI" };
                Person objPerson2 = new Person { name = "Cynthia Smith", phoneNumber = "(824) 128-8758", address = "875 Main St, Ann Arbor, MI" };
                phonebook.addPerson(objPerson1);
                phonebook.addPerson(objPerson2);

                // TODO: print the phone book out to System.out
                Console.WriteLine("###########PHONE BOOK##############");
                foreach (Person person in phonebook.GetPhoneBook)
                {
                    Console.WriteLine("Name: {0}, Phone Number: {1}, Address: {2}", person.name, person.phoneNumber, person.address);
                }
                Console.WriteLine("###################################");
                // TODO: find Cynthia Smith and print out just her entry
                string strFN = "Cynthia";
                string strLN = "Smith";
                Person findpersion = phonebook.findPerson(strFN, strLN);
                Console.WriteLine("Name: " + findpersion.name);
                Console.WriteLine("Phone Number: " + findpersion.phoneNumber);
                Console.WriteLine("Address: "+ findpersion.address);

                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #7
0
 public void findPersonDetails(PhoneBook book, string firstName, string lastName)
 {
     try
     {
         Person foundPerson = book.findPerson(firstName, lastName);
         if (foundPerson != null)
         {
             printPersonDetails(foundPerson);
         }
         else
         {
             throw new Exception(string.Format("No Person found with the name: '{0} {1}'",
                                               firstName, lastName));
         }
     }
     catch (Exception ex)
     {
         Logger.Log(LoggerType.Console, "Find & Print Person object Failed!", ex.StackTrace);
         Logger.Log(LoggerType.File, "Find & Print Person object Failed!", ex.StackTrace);
         throw ex;
     }
 }
Example #8
0
        static void Main(string[] args)
        {
            try
            {
                DatabaseUtil.initializeDatabase();
                //create person objects and put them in the PhoneBook
                PhoneBook objPhonebook = new PhoneBook();
                objPhonebook.addPerson(new Person {
                    name = "John Smith", address = "1234 Sand Hill Dr, Royal Oak, MI", phoneNumber = "(248) 123-4567"
                });
                objPhonebook.addPerson(new Person {
                    name = "Cynthia Smith", address = "875 Main St, Ann Arbor, MI", phoneNumber = "(824) 128-8758"
                });
                //create person objects and put them in the Database
                DatabaseUtil.Savecontacts(objPhonebook.personList);

                // print the phone book out to System.out
                Console.Write("********** List of Contact details ************");
                foreach (var item in objPhonebook.personList)
                {
                    Console.WriteLine("Name:{0}, PhoneNumber: {1}, Address : {2}", item.name, item.phoneNumber, item.address);
                }
                // find Cynthia Smith and print out just her entry
                var foundPerson = objPhonebook.findPerson("Cynthia", "Smith");
                Console.WriteLine(foundPerson.name);
                //insert the new person objects into the database

                Console.Write("********** To Store a Person details in phonebook and Database************");
                bool          confirmed = false;
                Person        objPerson;
                List <Person> ObjpersonToAdd = new List <Person>();
                while (!confirmed)
                {
                    objPerson = new Person();

                    Console.Write("\n Enter Name: ");
                    objPerson.name = Console.ReadLine();
                    Console.Write("Enter Address: ");
                    objPerson.address = Console.ReadLine();
                    Console.Write("Enter Mobile Number: ");
                    objPerson.phoneNumber = Console.ReadLine();
                    objPhonebook.addPerson(objPerson);
                    ObjpersonToAdd.Add(objPerson);
                    Console.WriteLine("Do you want to add more contact? [yes/no]");

                    string option = Console.ReadLine();

                    if (option == "no")
                    {
                        confirmed = true;
                    }
                }
                DatabaseUtil.Savecontacts(ObjpersonToAdd);



                // TODO: print the phone book out to System.out
                // TODO: find Cynthia Smith and print out just her entry
                // TODO: insert the new person objects into the database
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #9
0
        //Dave Williams
        static void Main(string[] args)
        {
            try
            {
                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                // TODO: print the phone book out to System.out
                // TODO: find Cynthia Smith and print out just her entry
                // TODO: insert the new person objects into the database
                #region InitializeDataBase
                DatabaseUtil.CleanUp();
                DatabaseUtil.initializeDatabase();
                #endregion

                #region LoadData
                List <Person> personList = LoadJson.LoadData();
                #endregion

                #region AddDataToPhoneBook
                foreach (Person personItem in personList)
                {
                    phonebook.addPerson(personItem); //add data into phoneBook
                }
                #endregion

                #region AddDataToDataBase
                PhoneBookDL phoneBookOperations = new PhoneBookDL();
                phoneBookOperations.InsertPhoneBookToDataBase(); //Add data into DataBase
                #endregion
                string choice = "";
                do
                {
                    Console.WriteLine("1. DisplayPhoneBook");

                    Console.WriteLine("2. Insert Person Details in PhoneBook");

                    Console.WriteLine("3.Find Person By Name");

                    Console.WriteLine("4.Exit");

                    choice = Console.ReadLine();

                    switch (choice)

                    {
                    case "1":
                        #region DisplayPhoneBook
                        Console.WriteLine("------------------PhoneBook----------------");
                        phonebook.PrintPhoneBook(Display.Print);
                        #endregion
                        break;

                    case "2":     //Do that
                        #region AddNewPerson
                        Console.WriteLine("-----------------Enter New Person ----------------");

                        Console.WriteLine("Enter First Name:");
                        string firstName = Console.ReadLine();

                        Console.WriteLine("Enter Last Name:");
                        string lastName  = Console.ReadLine();
                        Person personObj = new Person();
                        if (Validation.ValidateName(firstName + " " + lastName))
                        {
                            personObj.Name = firstName + " " + lastName;
                        }
                        else
                        {
                            Console.WriteLine("Invalid Name ,\n should contain only Letters\n Firstname lastname should not be blank\n");
                            break;
                        }
                        Console.WriteLine("Enter PhoneNumber Name:");
                        personObj.PhoneNumber = Console.ReadLine();

                        Console.WriteLine("Enter Address Name:");
                        personObj.Address = Console.ReadLine();

                        PhoneDL phoneDL = new PhoneDL();
                        phoneDL.InsertPerson(personObj);
                        #endregion
                        break;

                    case "3":
                        #region FindPerson
                        Console.WriteLine("------------------Searched Record----------------");

                        Console.WriteLine("Enter First Name:");
                        firstName = Console.ReadLine();

                        Console.WriteLine("Enter Last Name:");
                        lastName = Console.ReadLine();

                        if (!Validation.ValidateName(firstName + " " + lastName))
                        {
                            Console.WriteLine("Invalid Name ,\n should contain only Letters\n Firstname lastname should not be blank\n");
                            break;
                        }
                        Person person = new Person();
                        person = phonebook.findPerson(firstName, lastName);
                        if (person != null)
                        {
                            Display.Print(person);
                        }
                        else
                        {
                            Console.WriteLine("Person " + firstName + " " + lastName + "Not found");
                            break;
                        }
                        #endregion
                        break;
                    }
                } while (choice != "4");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            try
            {
                DatabaseUtil.initializeDatabase();

                IPhoneBook phoneBook = new PhoneBook();

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                Console.WriteLine("Adding John Smith to the phone book...");
                phoneBook.addPerson(
                    new Person()
                {
                    Name        = "John Smith",
                    Address     = "1234 Sand Hill Dr, Royal Oak, MI",
                    PhoneNumber = "(248) 123-4567"
                });

                Console.WriteLine();
                Console.WriteLine("Adding Cynthia Smith to the phone book...");
                phoneBook.addPerson(
                    new Person()
                {
                    Name        = "Cynthia Smith",
                    Address     = "875 Main St, Ann Arbor, MI",
                    PhoneNumber = "(824) 128-8758"
                });

                // TODO: print the phone book out to System.out
                Console.WriteLine();
                Console.WriteLine("Printing the phone book to the console...");
                foreach (Person person in phoneBook.getAllPeople())
                {
                    Console.WriteLine(person);
                }

                // TODO: find Cynthia Smith and print out just her entry
                Console.WriteLine("Finding Cynthia Smith in the phone book...");
                Person cynthiaSmith = phoneBook.findPerson("Cynthia Smith");
                if (cynthiaSmith == null)
                {
                    Console.WriteLine("\"Cynthia Smith\" is not in the phone book.");
                }
                else
                {
                    Console.WriteLine(cynthiaSmith);
                }

                // TODO: insert the new person objects into the database
                // TODO: Didn't we already do that above?  The instructions say to "person objects and put them in the PhoneBook and database" above...

                Console.WriteLine("Press Enter or Return to close");
                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("\nHello, Welcome to Phone Book App! \n");

                DatabaseUtil.initializeDatabase();

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                Person objPerson = new Person()
                {
                    name        = "John Smith",
                    phoneNumber = "(248) 123-4567",
                    address     = "1234 Sand Hill Dr, Royal Oak, MI"
                };
                phonebook.AddPerson(objPerson);

                objPerson = new Person()
                {
                    name        = "Cynthia Smith",
                    phoneNumber = "(824) 128-8758",
                    address     = "875 Main St, Ann Arbor, MI"
                };
                phonebook.AddPerson(objPerson);


                // TODO: print the phone book out to System.out
                var phoneBookData = phonebook.GetPhoneBook();
                if (phoneBookData != null)
                {
                    Console.WriteLine("List of Contacts from Phone Book:");
                    for (var i = 0; i < phoneBookData.Rows.Count; i++)
                    {
                        var contactNum = i + 1;
                        Console.WriteLine("\n Contact " + contactNum + " : \n Name: " + phoneBookData.Rows[i][0] + "\n Phone: " + phoneBookData.Rows[i][1] + "\n Address: " + phoneBookData.Rows[i][2]);
                    }
                }

                // TODO: find Cynthia Smith and print out just her entry
                var person = phonebook.findPerson("Cynthia", "Smith");
                if (person.name != null)
                {
                    Console.WriteLine("\n Cynthia Smith is available in Phone book and below are the details.");
                    Console.WriteLine(" Name: " + person.name + "\n Phone: " + person.phoneNumber + "\n Address: " + person.address);
                }
                else
                {
                    Console.WriteLine("\n Oops!, Cynthia Smith is not available in Phone book.");
                }

                // TODO: insert the new person objects into the database
                Console.WriteLine("\nEnter 1 to add new contact Or any other key to Proceed.");
                var input = Console.ReadKey();
                if (input.KeyChar.ToString() == "1")
                {
                    AddNewContact();
                }


                Console.WriteLine("\n ***Thank you, Have a nice day.***");
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Encountered as exception while running the process with below message.\n" + ex.Message);
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }