Exemple #1
0
        public static void Main()
        {
            PhoneBook phoneBook = new PhoneBook();

            string filePath = "../../TextFiles/phones.txt";
            using (StreamReader fileReader = new StreamReader(filePath))
            {
                string line;
                while ((line = fileReader.ReadLine()) != null)
                {
                    string[] personElements = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                    string personName = personElements[0].Trim();
                    string personTown = personElements[1].Trim();
                    string personPhone = personElements[2].Trim();
                    Person currentPerson = new Person(personName, personTown, personPhone);

                    phoneBook.Add(currentPerson);
                }
            }

            Console.WriteLine("---------- Test Find(string name) ----------");
            phoneBook.Find("Mimi Shmatkata");

            Console.WriteLine("\n---------- Test Find(string name, string town) ----------");
            phoneBook.Find("Mimi Shmatkata", "Sofia");
        }
Exemple #2
0
        private static void ReadPhoneEntries(
            string path, PhoneBook phoneBook)
        {
            string line;
            using (System.IO.StreamReader reader = new System.IO.StreamReader(path))
            {
                while ((line = reader.ReadLine()) != null)
                {
                    PhoneBookEntry newEntry;
                    var phoneEntry = line.Split('|');

                    var name = phoneEntry[0].Trim().Split(' ');
                    var town = phoneEntry[1].Trim();
                    var phone = phoneEntry[2].Trim();
                    if (name.Length < 3)
                    {
                        newEntry = new PhoneBookEntry(town, phone, phoneEntry[0].Trim());
                    }
                    else
                    {
                        newEntry = new PhoneBookEntry(name[0], name[1], name[2], town, phone);
                    }

                    phoneBook.Add(newEntry);
                }
            }
        }
Exemple #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
         return;
     StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.GetEncoding("euc-kr"));
     XmlSerializer xs = new XmlSerializer(typeof(PhoneBook));
     pb = (PhoneBook)xs.Deserialize(sr);
     textBox1.Text = pb.GetAllData();
 }
Exemple #4
0
    static void Main()
    {
        Console.WriteLine("Please enter your name");
        string name = Console.ReadLine();

        phoneBook = new PhoneBook.PhoneBook(name);
        Console.WriteLine("Hello " + name);
        Continue();
    }
Exemple #5
0
        static void Main(string[] args)
        {
            PhoneBook p1 = new PhoneBook();

            p1.AddContacts("Roy", "053-721-6094");
            p1.AddContacts("Guy", "696-696-6969");
            p1.AddContacts("Koma", "420-420-4200");
            Console.WriteLine(p1);
            p1.AddContacts("AdirKoma", "123-456-7888");
            Console.WriteLine(p1);
            p1.DelContact("Guy");
            Console.WriteLine(p1);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            PhoneBook phonebook = new PhoneBook();

            Console.WriteLine("ADD CONTACT --------------  Press 1");
            Console.WriteLine("REMOVE CONTACT -----------  Press 2");
            Console.WriteLine("FIND CONTACT -------------  Press 3");
            Console.WriteLine("PRINT ALL CONTACTS -------  Press 4");
            Console.WriteLine("EXIT ---------------------  Press 5");

            do
            {
                string keyWord = Console.ReadLine();
                switch (keyWord)
                {
                case "1":
                    Console.Write("Name:  ");
                    string name = Console.ReadLine();
                    Console.Write("Phone Number:   ");
                    string phoneNumber = Console.ReadLine();
                    phonebook.Add(new Record(name, phoneNumber));
                    Console.Write($"Contact \"{name}\" is added");
                    break;

                case "2":
                    Console.Write("NAME:  ");
                    name = Console.ReadLine();
                    phonebook.Remove(phonebook[name]);
                    Console.Write($"Contact \"{name}\" removed");
                    break;

                case "3":
                    Console.WriteLine("NAME:  ");
                    name = Console.ReadLine();
                    Console.Write(phonebook[name]);
                    break;

                case "4":
                    phonebook.Display();
                    break;

                case "5":
                    Environment.Exit(0);
                    break;

                default:
                    Console.Write("Enter valid number ");
                    break;
                }
            } while (true);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            FileReader       reader          = new FileReader("../../../phones.txt");
            IPhoneBookParser phoneBookParser = new PhoneBookParser();
            PhoneBook        phoneBook       = phoneBookParser.ParseData(reader);

            FileReader commandsReader = new FileReader("../../../commands.txt");
            CommandParser <PhoneBook>          commandsParser = new CommandParser <PhoneBook>();
            IEnumerable <Command <PhoneBook> > commandList    = commandsParser.ParseCommands(commandsReader);

            foreach (var c in commandList)
            {
                c.PrintCommandResult(phoneBook);
            }
        }
        public PhoneBook ParseData(IReader reader)
        {
            PhoneBook newPhoneBook = new PhoneBook();

            List <string> data = reader.ReadToEnd();

            ISplitter splitter = new Splitter();

            foreach (var item in  data)
            {
                string[] splittedData = splitter.SplitText(item, new char[] { '|' });
                newPhoneBook.AddPerson(new Person(splittedData[0].Trim(), splittedData[1].Trim(), splittedData[2].Trim()));
            }

            return(newPhoneBook);
        }
        public void buttonSubmit_Click(object sender, EventArgs e)
        {
            PhoneBook     phoneBook     = new PhoneBook();
            SqlConnection sqlConnection = new SqlConnection(phoneBook.sqlconnectionstring);

            try
            {
                sqlConnection.Open();
                SqlDataAdapter dataAdapter = new SqlDataAdapter("AuthorizedLogin", sqlConnection);
                dataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                dataAdapter.SelectCommand.Parameters.AddWithValue("@Login", LoginTextBox.Text);
                dataAdapter.SelectCommand.Parameters.AddWithValue("@Password", PasswordtextBox.Text);

                DataTable dataTable = new DataTable();
                dataAdapter.Fill(dataTable);

                if (dataTable.Rows.Count != 0)
                {
                    SqlCommand command = new SqlCommand("Truncate table PhoneBook", sqlConnection);
                    command.ExecuteNonQuery();

                    MessageBox.Show("Entire PhoneBook was deleted successfully.",
                                    "Success", MessageBoxButtons.OK);
                    this.Close();
                    phoneBook.Clear();
                    phoneBook.CurrentGridView();
                }
                else
                {
                    MessageBox.Show("You inserted wrong Login or Password.",
                                    "Wrong.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("Sorry,an error occured, while attempting to connect with DataBase.",
                                "Contact IT", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            finally
            {
                if (sqlConnection.State == ConnectionState.Open)
                {
                    sqlConnection.Close();
                }
            }
        }
Exemple #10
0
 public object this[string name]
 {
     get
     {
         if (name.Length > 2)
         {
             return(FindPhone(name));
         }
         throw new ArgumentException("Name is too short(It must be more than 2 characters)");
     }
     set {
         phones[PhoneIndex++] = new PhoneBook
         {
             Name        = name,
             PhoneNumber = (string)value
         };
     }
 }
Exemple #11
0
        private void Submit_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);

            con.Open();
            string    name            = NameTextBox.Text.ToString();
            string    surname         = SurnameTextBox.Text.ToString();
            string    phoneNumber     = PhoneNumberTextBox.Text.ToString();
            string    birth           = BirthTextBox.Text.ToString();
            PhoneBook phoneBookObject = new PhoneBook();

            if (name != "" || surname != "" || phoneNumber != "")
            {
                if (birth == "")
                {
                    SqlCommand command = new SqlCommand("AddPhoneNumberWithOutDate", con);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@Id", SqlDbType.Int).Value               = this.id + 1;
                    command.Parameters.AddWithValue("@Name", SqlDbType.NVarChar).Value        = name;
                    command.Parameters.AddWithValue("@Surname", SqlDbType.NVarChar).Value     = surname;
                    command.Parameters.AddWithValue("@PhoneNumber", SqlDbType.NVarChar).Value = phoneNumber;
                    command.ExecuteNonQuery();
                }
                else
                {
                    SqlCommand command = new SqlCommand("AddPhoneNumber", con);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@Id", SqlDbType.Int).Value               = this.id + 1;
                    command.Parameters.AddWithValue("@Name", SqlDbType.NVarChar).Value        = name;
                    command.Parameters.AddWithValue("@Surname", SqlDbType.NVarChar).Value     = surname;
                    command.Parameters.AddWithValue("@PhoneNumber", SqlDbType.NVarChar).Value = phoneNumber;
                    command.Parameters.AddWithValue("@BornDate", SqlDbType.Date).Value        = DateTime.Parse(birth);
                    command.ExecuteNonQuery();
                }
            }
            else
            {
                MessageBox.Show("Cant create empty contact", "Cant create empty contact");
            }

            con.Close();
            this.Hide();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string str;

            if (!(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK))
            {
                return;
            }
            StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.GetEncoding("euc-kr"));

            XmlSerializer xs = new XmlSerializer(typeof(PhoneBook));//PhoneBook을 시리얼라이즈 할거야.

            //XmlReader rd = XmlReader.Create(sr);

            pb = (PhoneBook)xs.Deserialize(sr);

            sr.Close();

            textBox1.Text = pb.getAllData();
        }
Exemple #13
0
        static void Main(string[] args)
        {
            PhoneBook phoneBook = new PhoneBook();

            // for testing purposes only
            phoneBook.Add("John Doe", "114 Market St", "St Louis", "MO", "63403", "6366435698");
            phoneBook.Add("John E Doe", "324 Main St", "St Charles", "MO", "63303", "8475390126");
            phoneBook.Add("John Michael West Doe", "574 Pole ave", "St Peters", "MO", "63333", "5628592375");

            new Player().Play(phoneBook);
            List <Person> people = new List <Person>();

            Helper.Filter(people, (p) => p.name = "Bob");
            foreach (Person p in people)
            {
                Console.WriteLine(p.name);
            }

            Console.ReadLine();
        }
Exemple #14
0
        public static void Main()
        {
            try
            {
                var phonesPath = @"..\..\phones.txt";
                var commandsPath = @"..\..\commands.txt";
                var pattern = @"(?<=\().+?(?=\))";

                Dictionary<string, List<PhoneBookEntry>> result =
                    new Dictionary<string, List<PhoneBookEntry>>();
                PhoneBook phoneBook = new PhoneBook();

                ReadPhoneEntries(phonesPath, phoneBook);
                ReadCommands(commandsPath, pattern, phoneBook, result);
                PrintResult(result);
            }
            catch (ArgumentException aex)
            {
                Console.WriteLine(aex.Message);
            }
        }
Exemple #15
0
        public static void Main(string[] args)
        {
            bool running   = true;
            var  phoneBook = new PhoneBook();

            while (running)
            {
                Console.WriteLine("What Do you want?");
                var readLine = Console.ReadLine();
                var comands  = readLine.Split(' ');
                switch (comands[0])
                {
                case "Location":
                    Console.WriteLine(value: phoneBook.EmployesFromLocation(comands[1]));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Exemple #16
0
 private static void ReadCommands(
     string path, string pattern,
     PhoneBook phoneBook,
     Dictionary<string, List<PhoneBookEntry>> collection)
 {
     string line;
     using (System.IO.StreamReader reader = new System.IO.StreamReader(path))
     {
         while ((line = reader.ReadLine()) != null)
         {
             var match = Regex.Match(line, pattern).ToString().Split(',');
             string name = match[0];
             if (match.Length > 1)
             {
                 string town = match[1].Trim();
                 collection.Add(name, phoneBook.Find(name, town));
             }
             else
             {
                 collection.Add(name, phoneBook.Find(name));
             }
         }
     }
 }
Exemple #17
0
 public User(string username, string password)
 {
     this.Username  = username;
     this.Password  = password;
     this.PhoneBook = new PhoneBook(username);
 }
 public SearchTelephone(PhoneBook phoneBook, String target) : base(phoneBook, target)
 {
 }
        private static void Test1()
        {
            var book = new PhoneBook();

            book.Add("Ivan", "1", "2");
            book.Add("Ivan Vankata", "3", "4");

            Console.WriteLine(book.Find("Ivan"));
            Console.WriteLine();
            Console.WriteLine(book.Find("Ivan", "3"));
        }
Exemple #20
0
 public Form1()
 {
     InitializeComponent();
     book   = new PhoneBook();
     source = new BindingSource();
 }
Exemple #21
0
 public Form1()
 {
     InitializeComponent();
     pb = new PhoneBook();
     saveFileDialog1.Filter = "저장파일|*.xml|전부|*.*";
 }
Exemple #22
0
 public abstract List <Person> Search(PhoneBook phoneBook);
Exemple #23
0
 public ASearch(PhoneBook phoneBook, String target)
 {
     this.phoneBook = phoneBook;
     this.target    = target;
     results        = new List <Person>();
 }
Exemple #24
0
        static void Main(string[] args)
        {
            PhoneBook ourPhoneBook = new PhoneBook();

            Console.WriteLine("Welcome!");
            Console.WriteLine("This app is an interactive phone book.");
            Console.WriteLine("For list of available commands type 'help'");
            while (true)
            {
                string commandInput = Console.ReadLine();
                if (commandInput == "exit")
                {
                    Console.WriteLine("Bye-bye!");
                    break;
                }
                else if (commandInput == "add")
                {
                    Console.Clear();
                    Console.WriteLine("Adding new record");
                    Console.WriteLine("*****************");
                    Console.WriteLine("Surname, Name, Phone and Country are mandatory. Other can be left empty.");
                    Console.WriteLine("Write each field on a new line in requested order.");
                    Console.WriteLine("Surname:");
                    string surname;
                    while (true)
                    {
                        surname = Console.ReadLine();
                        if (surname == "")
                        {
                            Console.WriteLine("You can't leave Surname empty. Try again.");
                        }
                        else
                        {
                            break;
                        }
                    }
                    Console.WriteLine("Name:");
                    string name;
                    while (true)
                    {
                        name = Console.ReadLine();
                        if (name == "")
                        {
                            Console.WriteLine("You can't leave Name empty. Try again.");
                        }
                        else
                        {
                            break;
                        }
                    }
                    Console.WriteLine("Lastname:");
                    string lastname = Console.ReadLine();
                    Console.WriteLine("Phone:");
                    string phoneStr;
                    long   phone;
                    while (true)
                    {
                        phoneStr = Console.ReadLine();
                        if (!Int64.TryParse(phoneStr, out phone))
                        {
                            Console.WriteLine("Can't understand such phone number. Try again.");
                        }
                        else
                        {
                            if (phone <= 0)
                            {
                                Console.WriteLine("Can't understand such phone number. Try again.");
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    Console.WriteLine("Country:");
                    string country;
                    while (true)
                    {
                        country = Console.ReadLine();
                        if (country == "")
                        {
                            Console.WriteLine("You can't leave Country empty. Try again.");
                        }
                        else
                        {
                            break;
                        }
                    }
                    Console.WriteLine("Birthday:");
                    string birthday = Console.ReadLine();
                    Console.WriteLine("Organization:");
                    string organization = Console.ReadLine();
                    Console.WriteLine("Position:");
                    string position = Console.ReadLine();
                    Console.WriteLine("Note:");
                    string          note      = Console.ReadLine();
                    PhoneBookRecord newRecord = new PhoneBookRecord(surname, name, lastname, phone, country, birthday, organization, position, note);
                    ourPhoneBook.AddNewRecord(newRecord);
                    Console.Clear();
                    Console.WriteLine("Record was saved");
                    Console.WriteLine("Waiting for command");
                }
                else if (commandInput == "delete")
                {
                    Console.Clear();
                    Console.WriteLine("Delete record");
                    Console.WriteLine("*************");
                    Console.WriteLine("Type order number of record you want to delete. Type 'exit' if you want to go back.");
                    string input;
                    int    num;
                    while (true)
                    {
                        input = Console.ReadLine();
                        if (input == "exit")
                        {
                            Console.Clear();
                            Console.WriteLine("Waiting for command");
                            break;
                        }
                        if (!(Int32.TryParse(input, out num)))
                        {
                            Console.WriteLine("Can't understand number you wrote. Try again");
                        }
                        else
                        {
                            if (ourPhoneBook.CheckIndex(num))
                            {
                                ourPhoneBook.DeleteRecord(num);
                                Console.Clear();
                                Console.WriteLine("Record was succesfully removed");
                                Console.WriteLine("Waiting for command");
                                break;
                            }
                            else
                            {
                                Console.WriteLine("There is no such index. Try again.");
                            }
                        }
                    }
                }
                else if (commandInput == "edit")
                {
                    Console.Clear();
                    Console.WriteLine("Editinig record");
                    Console.WriteLine("***************");
                    Console.WriteLine("First you need to choose record to edit.");
                    Console.WriteLine("Type order number of record you want to edit. Type 'exit' if you want to go back");
                    string input;
                    int    num = -1;
                    while (true)
                    {
                        input = Console.ReadLine();
                        if (input == "exit")
                        {
                            Console.Clear();
                            Console.WriteLine("Waiting for command");
                            break;
                        }
                        else
                        {
                            if (!(Int32.TryParse(input, out num)))
                            {
                                Console.WriteLine("Can't understand number you wrote. Try again");
                            }
                            else
                            {
                                if (ourPhoneBook.CheckIndex(num))
                                {
                                    Console.Clear();
                                    Console.WriteLine("Editing record {0}", num);
                                    Console.WriteLine("******************");
                                    Console.WriteLine("Second you need to edit fields of this record.");
                                    Console.WriteLine("You will see what was record and then would be able to type a new information");
                                    Console.WriteLine("Leave string empty if you don't want to change current field");
                                    PhoneBookRecord currentRecord = ourPhoneBook.ExtractPhoneBookRecord(num);
                                    // asd
                                    Console.WriteLine("Surname:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Surname);
                                    string surname = Console.ReadLine();
                                    if (surname != "")
                                    {
                                        currentRecord.Surname = surname;
                                    }
                                    Console.WriteLine("Name:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Name);
                                    string name = Console.ReadLine();
                                    if (name != "")
                                    {
                                        currentRecord.Name = name;
                                    }
                                    Console.WriteLine("Lastname:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Lastname);
                                    string lastname = Console.ReadLine();
                                    if (lastname != "")
                                    {
                                        currentRecord.Lastname = lastname;
                                    }
                                    Console.WriteLine("Phone:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Phone);
                                    string phoneStr;
                                    long   phone;
                                    while (true)
                                    {
                                        phoneStr = Console.ReadLine();
                                        if (phoneStr == "")
                                        {
                                            break;
                                        }
                                        if (!Int64.TryParse(phoneStr, out phone))
                                        {
                                            Console.WriteLine("Can't understand such phone number. Try again.");
                                        }
                                        else
                                        {
                                            if (phone <= 0)
                                            {
                                                Console.WriteLine("Can't understand such phone number. Try again.");
                                            }
                                            else
                                            {
                                                currentRecord.Phone = phone;
                                                break;
                                            }
                                        }
                                    }
                                    Console.WriteLine("Country:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Country);
                                    string country = Console.ReadLine();
                                    if (country != "")
                                    {
                                        currentRecord.Country = country;
                                    }
                                    Console.WriteLine("Birthday:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Birthday);
                                    string birthday = Console.ReadLine();
                                    if (birthday != "")
                                    {
                                        currentRecord.Birthday = birthday;
                                    }
                                    Console.WriteLine("Organization:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Organization);
                                    string organization = Console.ReadLine();
                                    if (organization != "")
                                    {
                                        currentRecord.Organization = organization;
                                    }
                                    Console.WriteLine("Position:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Position);
                                    string position = Console.ReadLine();
                                    if (position != "")
                                    {
                                        currentRecord.Position = position;
                                    }
                                    Console.WriteLine("Note:");
                                    Console.WriteLine("\"{0}\"", currentRecord.Note);
                                    string note = Console.ReadLine();
                                    if (note != "")
                                    {
                                        currentRecord.Note = note;
                                    }
                                    ourPhoneBook.EditRecord(num, currentRecord);
                                    Console.Clear();
                                    Console.WriteLine("Record number {0} was edited", num);
                                    Console.WriteLine("Waiting for command");
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine("There is no such index. Try again.");
                                }
                            }
                        }
                    }
                }
                else if (commandInput == "print")
                {
                    Console.Clear();
                    Console.WriteLine("Printing record info");
                    Console.WriteLine("********************");
                    Console.WriteLine("Type order number of record you want to print. Type 'exit' if you want to go back.");
                    string input;
                    int    num;
                    while (true)
                    {
                        input = Console.ReadLine();
                        if (input == "exit")
                        {
                            Console.Clear();
                            Console.WriteLine("Waiting for command");
                            break;
                        }
                        if (!(Int32.TryParse(input, out num)))
                        {
                            Console.WriteLine("Can't understand number you wrote. Try again");
                        }
                        else
                        {
                            if (ourPhoneBook.CheckIndex(num))
                            {
                                Console.Clear();
                                Console.WriteLine("Printing information about record number {0}", num);
                                PhoneBookRecord currentRecord = ourPhoneBook.ExtractPhoneBookRecord(num);
                                Console.WriteLine("Surname - {0}", currentRecord.Surname);
                                Console.WriteLine("Name - {0}", currentRecord.Name);
                                Console.WriteLine("Lastname - {0}", currentRecord.Lastname);
                                Console.WriteLine("Phone - {0}", currentRecord.Phone);
                                Console.WriteLine("Birthday - {0}", currentRecord.Birthday);
                                Console.WriteLine("Contry - {0}", currentRecord.Country);
                                Console.WriteLine("Organization - {0}", currentRecord.Organization);
                                Console.WriteLine("Position - {0}", currentRecord.Position);
                                Console.WriteLine("Note - {0}", currentRecord.Note);
                                Console.WriteLine("Press enter to continue");
                                input = Console.ReadLine();
                                Console.Clear();
                                Console.WriteLine("Waiting for command");
                                break;
                            }
                            else
                            {
                                Console.WriteLine("There is no such index. Try again.");
                            }
                        }
                    }
                }
                else if (commandInput == "print all")
                {
                    Console.Clear();
                    ourPhoneBook.PrintAllRecords();
                    Console.WriteLine("Press enter to continue");
                    string input = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine("Waiting for command");
                }
                else if (commandInput == "help")
                {
                    Console.Clear();
                    Console.WriteLine("Available comands:");
                    Console.WriteLine("add - add new record to phone book");
                    Console.WriteLine("edit - edit existing record in phone book");
                    Console.WriteLine("delete - delete existing record in phone book");
                    Console.WriteLine("print - print full information about one record");
                    Console.WriteLine("print all - print short information about all records");
                    Console.WriteLine("exit - quit program");
                    Console.WriteLine("*****************************************************");
                    Console.WriteLine("Press enter to continue");
                    string input = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine("Waiting for command");
                }
                else
                {
                    Console.WriteLine("I don't know such command");
                }
            }
        }
Exemple #25
0
 public SearchState(PhoneBook phoneBook, String target) : base(phoneBook, target)
 {
 }
Exemple #26
0
        static void Main(string[] args)
        {
            PhoneBook phoneBook = new PhoneBook();

            PromptUser();

            void Menu()
            {
                Console.WriteLine("TYPE:");
                Console.WriteLine("'Add' to add a contact: ");
                Console.WriteLine("'View' to view the list of contacts: ");
                Console.WriteLine("'Remove' to select and remove a contact: ");
                Console.WriteLine("'Update' to select and update a contact: ");
                Console.WriteLine("'Quit' at anytime to exit: ");
            }

            void AddPhonesBook(string userInput)
            {
                string name   = "";
                string family = "";
                string phone  = "";

                switch (userInput.ToLower())
                {
                case "add":
                    Console.Write("Enter a name: ");
                    name = Console.ReadLine().Trim();
                    switch (name)
                    {
                    case "quit":
                        break;

                    default:
                        Console.Write("Enter a family: ");
                        family = Console.ReadLine().Trim();
                        //phone = Console.ReadLine().Trim();
                        switch (family)
                        {
                        case "quit":
                            break;

                        default:
                            Console.Write("Enter a phone: ");
                            phone = Console.ReadLine().Trim();
                            switch (phone)
                            {
                            case "quit":
                                break;

                            default:
                                phoneBook.AddEntry(name, family, phone);
                                break;
                            }
                            break;
                        }


                        break;
                    }
                    break;

                case "remove":
                    Console.Write("Enter a name to remove: ");
                    name = Console.ReadLine();
                    switch (name)
                    {
                    case "quit":
                        break;

                    default:
                        phoneBook.RemoveEntry(name);
                        break;
                    }
                    break;

                case "view":
                    Console.WriteLine(phoneBook.ViewContactsList());
                    break;

                case "update":
                    Console.WriteLine("Please enter the name of the Contact you like to update");
                    name = Console.ReadLine();
                    phoneBook.UpdateContact(name);
                    break;
                }
            }

            void PromptUser()
            {
                Menu();
                string userInput = "";

                while (userInput != "quit")
                {
                    Console.WriteLine("What would you like to do?");
                    userInput = Console.ReadLine().Trim();
                    AddPhonesBook(userInput);
                }
            }
        }
Exemple #27
0
 public SearchLast(PhoneBook phoneBook, String target) : base(phoneBook, target)
 {
 }
Exemple #28
0
 public SearchCity(PhoneBook phoneBook, String target) : base(phoneBook, target)
 {
 }
Exemple #29
0
        public void Play(PhoneBook phoneBook)
        {
            Console.WriteLine("Phone Book");
            Boolean run = true;

            while (run)
            {
                Console.WriteLine("1. Add " +
                                  "\n2. Search " +
                                  "\n3. Update " +
                                  "\n4. Delete " +
                                  "\n5. Display all contacts" +
                                  "\n6. Exit\n");

                switch (Console.ReadLine())
                {
                case "1":     //Add
                    Console.WriteLine("Add...");
                    Console.WriteLine("Enter full name: ");
                    String name = Console.ReadLine();
                    Console.WriteLine("Enter street address (ex. 123 Fake St.): ");
                    String streetAddress = Console.ReadLine();
                    Console.WriteLine("Enter city: ");
                    String city = Console.ReadLine();
                    Console.WriteLine("Enter state abbreviation (ex. IL): ");
                    String state = Console.ReadLine();
                    Console.WriteLine("Enter zipcode: ");
                    String zipcode = Console.ReadLine();
                    Console.WriteLine("Enter telephone (1234567890): ");
                    String telephone = Console.ReadLine();
                    phoneBook.Add(name, streetAddress, city, state, zipcode, telephone);
                    break;

                case "2":     //Search
                    Boolean stayHere = true;

                    while (stayHere)
                    {
                        Console.WriteLine("Search...");
                        Console.WriteLine("1. Search by first name "
                                          + "\n2. Search by last name "
                                          + "\n3. Search by full name (first last)"
                                          + "\n4. Search by telephone number (xxx-xxx-xxxx)"
                                          + "\n5. Search by city"
                                          + "\n6. Search by state"
                                          + "\n7. go back");

                        switch (Console.ReadLine())
                        {
                        case "1":
                            phoneBook.Search(new SearchFirst(phoneBook, Helper.Prompt("first name")));
                            break;

                        case "2":
                            phoneBook.Search(new SearchLast(phoneBook, Helper.Prompt("last name")));
                            break;

                        case "3":
                            phoneBook.Search(new SearchFullName(phoneBook, Helper.Prompt("full name")));
                            break;

                        case "4":
                            phoneBook.Search(new SearchTelephone(phoneBook, Helper.Prompt("telephone number(xxx - xxx - xxxx")));
                            break;

                        case "5":
                            phoneBook.Search(new SearchCity(phoneBook, Helper.Prompt("city")));
                            break;

                        case "6":
                            phoneBook.Search(new SearchState(phoneBook, Helper.Prompt("state")));
                            break;

                        case "7":
                            stayHere = false;
                            break;

                        default:
                            Console.WriteLine("Invalid selection...");
                            continue;
                        }
                    }
                    break;

                case "3":     //Update
                    Console.WriteLine("Update...");
                    Console.WriteLine("Enter telephone of contact to update");
                    String number = Console.ReadLine();
                    Console.WriteLine("Enter new name for contact");
                    String newName  = Console.ReadLine();
                    Person toUpdate = phoneBook.Update(number, newName);
                    if (toUpdate != null)
                    {
                        Console.WriteLine("Changed contact with phone number {0}'s name to {1}...", number, toUpdate.name);
                    }
                    else
                    {
                        Console.WriteLine("number not found...");
                    }
                    break;

                case "4":     //Delete
                    Console.WriteLine("Delete...");
                    Console.WriteLine("Enter telephone number of contact to delete");
                    number = Console.ReadLine();
                    Person toDelete = phoneBook.Delete(number);
                    if (toDelete != null)
                    {
                        Console.WriteLine("Deleted contact {0} with phone number {1}...", toDelete.name, number);
                    }
                    else
                    {
                        Console.WriteLine("number not found...");
                    }
                    break;

                case "5":     //Display all
                    Console.WriteLine(phoneBook.DisplayAll());
                    break;

                case "6":     //Exit
                    Console.WriteLine("Exiting...");
                    run = false;
                    break;

                default:     //Invalid entry
                    Console.WriteLine("Invalid choice.  Please make another selection...");
                    break;
                }
            }
        }
Exemple #30
0
 public SearchFullName(PhoneBook phoneBook, String target) : base(phoneBook, target)
 {
 }