Example #1
0
        private 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
                Console.Write("\n\n************All Records in the PhoneBook Table!************\n");
                phonebook.GetAll();

                // TODO: insert the new person objects into the database
                Console.Write("************\n\nNew Person Added in the PhoneBook Table !\n");
                phonebook.AddPerson();


                // TODO: find Cynthia Smith and print out just her entry
                Console.Write("************\n\n Find the Person in PhoneBook Table !\n");
                phonebook.FindPerson("Cynthia", "Smith");

                Console.Write("End !");
                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #2
0
        private static void Main(string[] args)
        {
            try{
                Console.WriteLine("Creating new DB. Wait...");
                var book = new PhoneBook();
                book.Initialize();
                Console.WriteLine("Done initializing. Adding 2 default persons.");
                var p = new Person {
                    Name        = "John Smith",
                    PhoneNumber = "(248) 123-4567",
                    Address     = "1234 Sand Hill Dr, Royal Oak, MI"
                };
                var c = new Person {
                    Name        = "Cynthia Smith",
                    PhoneNumber = "(824) 128-8758",
                    Address     = "875 Main St, Ann Arbor, MI"
                };
                book.AddPerson(p);
                book.AddPerson(c);

                Person[] pers = book.FindAll();

                foreach (Person s in pers)
                {
                    Console.WriteLine(s.Name + ", " + s.Address + ", " + s.PhoneNumber);
                }
                Console.WriteLine("Total count: " + pers.Length);
                Console.WriteLine("Searching for a given person.");

                Person n = book.FindPerson("Cynthia Smith");
                Console.WriteLine("Found: " + n.Name + " " + n.Address + " " + n.PhoneNumber);
                Console.WriteLine("Adding new person: ");
                Console.WriteLine("Enter the name, phone, address, separated by comma : ");

                string entry = Console.ReadLine();
                if (entry != null)
                {
                    string[] entries = entry.Split(',');

                    book.AddPerson(new Person {
                        Name = entries[0], PhoneNumber = entries[1], Address = entries[2]
                    });
                }

                Console.WriteLine("New entry added!");
                Console.WriteLine();
                pers = book.FindAll();

                foreach (Person s in pers)
                {
                    Console.WriteLine(s.Name + ", " + s.Address + ", " + s.PhoneNumber);
                }
                Console.WriteLine("New count: " + pers.Length);
                Console.ReadLine();
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Example #3
0
        private static void FindAndPrintPerson()
        {
            // TODO: find Cynthia Smith and print out just her entry
            var personFound = _phonebook.FindPerson("Cynthia", "Smith");

            Console.WriteLine("\n======TODO: find Cynthia Smith and print out just her entry======");
            PrintPerson(personFound);
        }
Example #4
0
        public void findPerson()
        {
            //Arrange
            var pBook = new PhoneBook();

            //Act
            var p = pBook.FindPerson("John Smith");

            Assert.IsNull(p);
        }
Example #5
0
        static void Main(string[] args)
        {
            PhoneBook phonebook = new PhoneBook();

            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
                 */

                //  The database does not exist so create it
                DatabaseUtil.initializeDatabase();

                //  Create person objects
                Person johnSmith = new Person()
                {
                    name        = "John Smith",
                    address     = "1234 Sand Hill Dr, Royaml Oak, MI",
                    phoneNumber = "(248) 123-4567"
                };

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


                // Insert the new person objects into the database
                phonebook.AddPerson(johnSmith);
                phonebook.AddPerson(cynthiaSmith);

                // Print the phone book out to System.out
                foreach (var person in phonebook.GetPeople())
                {
                    //  Write out list of people to console
                    Console.WriteLine("Name: {0}, Number: {1}, Address: {2}\n", person.name, person.phoneNumber, person.address);
                }


                // Find Cynthia Smith and print out just her entry
                Person cynthia = phonebook.FindPerson("Cynthia", "Smith");
                //  Print out Cynthias' details to console
                Console.WriteLine("Name: {0}, Number: {1}, Address: {2}\n", cynthia.name, cynthia.phoneNumber, cynthia.address);
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            try
            {
                Person[] persons =
                {
                    new Person("John Smith",    "(248) 123-4567", "1234 Sand Hill Dr, Royal Oak, MI"),
                    new Person("Cynthia Smith", "(824) 128-8758", "875 Main St, Ann Arbor, MI")
                };

                DatabaseUtil.InitializeDatabase(null);

                PhoneBook phoneBook = new PhoneBook();
                phoneBook.AddPerson(persons[0]);
                phoneBook.AddPerson(persons[1]);

                for (int i = 0; i < phoneBook.Length; ++i)
                {
                    Console.WriteLine(phoneBook[i].GetInfo);
                }

                Person p = phoneBook.FindPerson("Cynthia Smith");
                Console.WriteLine(p?.GetInfo);

                Console.ReadLine();

                #region Test



                //Console.ReadLine();
                ///* 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


                #endregion
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            try
            {
                var dbConnection = new SQLiteConnection("Data Source= MyDatabase.sqlite;Version=3;");
                dbConnection.Open();
                SQLiteCommand command =
                    new SQLiteCommand(
                        "drop table PHONEBOOK",
                        dbConnection);
                command.ExecuteNonQuery();
                DatabaseUtil.InitializeDatabase();

               //Add phonebooks to In-memory Phonebook Collection
                var phoneBook = new PhoneBook(new PersonRepository());
                phoneBook.AddPerson(new Person()
                {
                    Name = "John Smith",
                    Address = "1234 Sand Hill Dr, Royal Oak, MI",
                    PhoneNumber = "(248) 123-4567"
                });
                phoneBook.AddPerson(new Person()
                {
                    Name = "Cynthia Smith",
                    Address = "875 Main St, Ann Arbor, MI",
                    PhoneNumber = "(824) 128-8758"
                });

                //Print phonebook
                Console.WriteLine("---------PRINT Phonebook");
                Console.WriteLine(phoneBook.ToString());

                //get and print cynthia
                Console.WriteLine("---------PRINT Cynthia");
                var person = phoneBook.FindPerson("Cynthia Smith");
                Console.WriteLine(person.ToString());

                //persist in-memory phonebook collection to DB
                phoneBook.Persist();

                Console.WriteLine("Press Enter to exit");
                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #8
0
        /// <summary>
        /// Find Record With Given Name
        /// </summary>
        /// <param name="firstName">First Name Of Person</param>
        /// <param name="lastName">Last Name Of Person</param>
        private void FindRecordWithGivenName(string firstName, string lastName)
        {
            Person person = phonebook.FindPerson(firstName.Trim(), lastName.Trim());

            Console.WriteLine(Environment.NewLine);
            if (person != null && person.address != null)
            {
                Console.WriteLine("Found below Record");
                Console.WriteLine("Name = {0}, PhoneNumber = {1}, Address = {2}", person.name,
                                  person.phoneNumber, person.address);
            }
            else
            {
                Console.WriteLine("No Matching Record Found");
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            /* 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("John Smith", "(248) 123-4567", "1234 Sand Hill Dr, Royal Oak, MI"));
            phonebook.AddPerson(new Person("Cynthia Smith", "(824) 128-8758", "875 Main St, Ann Arbor, MI"));


            // TODO: print the phone book out to System.out
            Console.WriteLine("All phonebook entries \n");
            foreach (var person in phonebook)
            {
                Console.WriteLine(person);
            }
            Console.WriteLine("\n");


            // TODO: find Cynthia Smith and print out just her entry
            Console.WriteLine("Cythia's phonebook entry \n");
            var cynthia = phonebook.FindPerson("Cynthia", "Smith");

            Console.WriteLine(cynthia);

            try
            {
                DatabaseUtil.initializeDatabase();

                // TODO: insert the new person objects into the database
                DatabaseUtil.InsertPeople(phonebook);
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }

            Console.ReadLine();
        }