Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
0
        public void addNewPerson(PhoneBook book)
        {
            try
            {
                Console.Write("Enter Person First Name: ");
                string pFName = Console.ReadLine();
                Console.Write("Enter Person Last Name: ");
                string pLName = Console.ReadLine();
                Console.Write("Enter Person Phone: ");
                string pPhone = Console.ReadLine();
                Console.Write("Enter Person Address: ");
                string pAddress = Console.ReadLine();

                book.addPerson(createPerson(pFName, pLName, pPhone, pAddress));
            }
            catch (Exception ex)
            {
                Logger.Log(LoggerType.Console, "Adding Person object into phonebook Failed!", ex.StackTrace);
                Logger.Log(LoggerType.File, "Adding Person object into phonebook Failed!", ex.StackTrace);
                throw ex;
            }
        }
Exemplo n.º 7
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();
            }
        }
Exemplo n.º 8
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();
            }
        }
Exemplo n.º 9
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();
            }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            bool quit = false;

            try
            {
                Logger.Log(LoggerType.File, "Main", "Program Started");
                try
                {
                    DatabaseUtil.initializeDatabase();
                }
                catch (Exception ex)
                {
                    Logger.Log(LoggerType.Console, "Database init", " Error Occurred" + ex.StackTrace);
                }

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

                PersonUtil personUtil = new PersonUtil();

                Console.WriteLine("Print all phonebook contacts:");
                Console.WriteLine("====================================");
                phonebook.addPerson(personUtil.createPerson("John", "Smith", "(248) 123-4567", "1234 Sand Hill Dr, Royal Oak, MI"));
                phonebook.addPerson(personUtil.createPerson("Cynthia", "Smith", "(824) 128-8758", "875 Main St, Ann Arbor, MI"));

                // TODO: print the phone book out to System.out
                personUtil.printPhonebook(phonebook);

                // TODO: find Cynthia Smith and print out just her entry
                Console.WriteLine();
                Console.WriteLine("Search & Print Cynthia Smith details:");
                Console.WriteLine("====================================");
                personUtil.findPersonDetails(phonebook, "Cynthia Smith".Split(" ".ToCharArray())[0], "Cynthia Smith".Split(" ".ToCharArray())[1]);

                // TODO: insert the new person objects into the database
                Console.WriteLine();
                Console.WriteLine("Add new person into phonebook:");
                Console.WriteLine("====================================");
                personUtil.addNewPerson(phonebook);

                while (!quit)
                {
                    Console.WriteLine();
                    Console.WriteLine("Choose a number from the list below:");
                    Console.WriteLine("1.PRINT PHONEBOOK 2.FIND A PERSON 3. ADD NEW PERSON 4. QUIT");
                    string option = Console.ReadLine();

                    switch (option)
                    {
                    case "1":     //PRINT PHONEBOOK
                        try
                        {
                            personUtil.printPhonebook(phonebook);
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(LoggerType.Console, "Printing phone book Failed!", ex.StackTrace);
                            Logger.Log(LoggerType.File, "Printing phone book Failed!", ex.StackTrace);
                        }
                        break;

                    case "2":     //FIND A PERSON
                        string fName = string.Empty, lName = string.Empty;
                        try
                        {
                            Console.WriteLine("Enter person First Name to find from phonebook:");
                            fName = Console.ReadLine();
                            Console.WriteLine("Enter person Last Name to find from phonebook:");
                            lName = Console.ReadLine();
                            personUtil.findPersonDetails(phonebook, fName, lName);
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(LoggerType.Console, "Finding: " + fName + " " + lName, "No Person find with this name.");
                            Logger.Log(LoggerType.File, "Finding: " + fName + " " + lName, ex.StackTrace);
                        }
                        break;

                    case "3":     // ADD NEW PERSON
                        try
                        {
                            personUtil.addNewPerson(phonebook);
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(LoggerType.Console, "Adding new Person Failed!", ex.StackTrace);
                            Logger.Log(LoggerType.File, "Adding new Person Failed!", ex.StackTrace);
                        }
                        break;

                    default:     //CLEAN UP
                        DatabaseUtil.CleanUp();
                        quit = true;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LoggerType.Console, "Main Program", ex.Message);
            }

            finally
            {
                if (!quit)
                {
                    DatabaseUtil.CleanUp();
                }
                Console.Read();
                Logger.Log(LoggerType.File, "Main", "Program Ended.");
            }
        }