Esempio n. 1
0
 public Contact(string firstName, string lastName, PhoneNumber phoneNumber, string email)
 {
     FirstName = firstName;
     LastName = lastName;
     PhoneNumber = phoneNumber;
     Email = email;
 }
        private void editExistingContactButton_Click(object sender, EventArgs e)
        {
            toEdit.FirstName = firstNameEditTextBox.Text;
            toEdit.LastName  = lastNameEditTextbox.Text;

            int areaCode = int.Parse(areaCodeEditTextBox.Text);
            int firstPart = int.Parse(firstPartEditTextBox.Text);
            int secondPart = int.Parse(secondPartEditTextBox.Text);

            PhoneNumber newPhoneNumber = new PhoneNumber(areaCode, firstPart, secondPart);

            toEdit.PhoneNumber = newPhoneNumber;
            toEdit.Email = emailEditTextbox.Text;

            Close();
        }
Esempio n. 3
0
        //calls this method after the MainWindow(); loads/is drawn
        private void MainWindow_Load(object sender, EventArgs e)
        {
            string open = File.ReadAllText("saved.xml");

            XElement parsed = XElement.Parse(open);

            foreach (XElement child in parsed.Elements("contact"))
            {
                string savedFirstName = child.Element("firstName").Value;
                string savedLastName = child.Element("lastName").Value;
                string savedAreaCode = child.Element("PhoneNumber").Element("areaCode").Value;
                string savedFirstPart = child.Element("PhoneNumber").Element("firstPart").Value;
                string savedSecondPart = child.Element("PhoneNumber").Element("secondPart").Value;
                PhoneNumber savedPhoneNumber = new PhoneNumber(int.Parse(savedAreaCode), int.Parse(savedFirstPart), int.Parse(savedSecondPart));
                string savedEmail = child.Element("email").Value;

                virtualContactList.Add(new Contact(savedFirstName, savedLastName, savedPhoneNumber, savedEmail));

            }

            DisplayVirtualListInBox();

            UpdateContactNumberLabel();//Takes another look at how many contacts there are
        }
Esempio n. 4
0
        //Menu screen when 1.Create Contact has been selected
        public static void CreateContact(Collect collect, SQL sql)
        {
            //creating variables for adding user input to the classes.
            var contact = new Contact();

            while (true)
            {
                Console.Clear();

                //display
                Console.WriteLine("0.=>Previous Menu");
                Console.WriteLine($"\n1.FirstName: {(contact.FirstName == "No name" ? "" : contact.FirstName)}");
                Console.WriteLine($"2.Last Name: {(contact.LastName == "NULL" ? "" : contact.LastName)}");
                Console.Write($"3.Phone Number: ");
                foreach (var phoneNumbers in contact.PhoneNumbers)
                {
                    Console.Write("" +
                                  $"Number:{phoneNumbers.Number} / Type:{phoneNumbers.Type}");
                }

                Console.Write($"\n4.Email: ");
                foreach (var Emails in contact.Emails)
                {
                    Console.Write("" +
                                  $"Text:{Emails.Text} / Type:{Emails.Type}");
                }

                Console.Write($"\n5.Address: ");
                foreach (var addresses in contact.Addresses)
                {
                    Console.Write("" +
                                  $"Street Name:{addresses.StreetName}" +
                                  $" / City:{addresses.City}" +
                                  $" / State:{addresses.State}" +
                                  $" / ZipCode:{addresses.ZipCode}\n");
                }
                Console.WriteLine("\n\n6.Save");

                Console.Write("\nSelect an option:");

                var input = Console.ReadLine();

                //adding input to database once case is declared.
                switch (input)
                {
                case "0":
                    Console.Clear();
                    Main(new string[1]);
                    break;

                case "1":
                    contact.FirstName = collect.CollectField(fieldName: "First Name", previousValue: contact.FirstName, required: true);
                    break;

                case "2":
                    contact.LastName = collect.CollectField(fieldName: "Last Name", previousValue: contact.LastName, required: false);
                    break;

                case "3":
                    var phoneNumber = new PhoneNumber();

                    phoneNumber.Number = collect.CollectField(fieldName: "Number", previousValue: phoneNumber.Number, required: false);
                    phoneNumber.Type   = collect.CollectField(fieldName: "Type", previousValue: phoneNumber.Type, required: false);

                    contact.PhoneNumbers.Add(phoneNumber);
                    break;

                case "4":
                    var email = new Email();

                    email.Text = collect.CollectField(fieldName: "Text", previousValue: email.Text, required: false);
                    email.Type = collect.CollectField(fieldName: "Type", previousValue: email.Type, required: false);

                    contact.Emails.Add(email);
                    break;

                case "5":
                    var address = new Address();

                    address.StreetName = collect.CollectField(fieldName: "Street Name", previousValue: address.StreetName, required: false);
                    address.City       = collect.CollectField(fieldName: "City", previousValue: address.City, required: false);
                    address.State      = collect.CollectField(fieldName: "State", previousValue: address.State, required: false);
                    address.ZipCode    = collect.CollectField(fieldName: "ZipCode", previousValue: address.ZipCode, required: false);
                    address.Type       = collect.CollectField(fieldName: "Type", previousValue: address.Type, required: false);



                    contact.Addresses.Add(address);
                    break;

                case "6":
                    sql.CreateContact(contact);
                    CreateContact(collect, sql);
                    break;
                }
            }
        }
Esempio n. 5
0
        public static void EditPhoneNumbers(Collect collect, SQL sql, Contact contact)
        {
            while (true)
            {
                Console.Clear();
                DisplayPhoneNumbers(contact);

                Console.WriteLine("\n\n0.=>Previous Menu");
                Console.WriteLine("\n1.Add a new phone number");
                Console.WriteLine("\n2.Delete a phone number");


                Console.Write("\nSelect an option: ");

                //Console.WriteLine("\nEnter the ID of the number you wish you wish to edit");

                var input = Console.ReadLine();

                switch (input)
                {
                case "0":
                    Console.Clear();
                    return;

                case "1":    //Add number
                    // Store new numbers in a list
                    var phoneNumbers = new List <PhoneNumber>();

                    // Create new number and collect fields
                    var phoneNumber = new PhoneNumber()
                    {
                        Number = collect.CollectField(fieldName: "Number", previousValue: "", required: false),
                        Type   = collect.CollectField(fieldName: "Type", previousValue: "", required: false)
                    };

                    // Add number to list
                    phoneNumbers.Add(phoneNumber);

                    // Insert number
                    sql.InsertPhoneNumbers(contact, phoneNumbers);
                    contact = sql.GetContact(contact.ID);

                    break;

                case "2":    //Delete number
                    Console.Clear();

                    Console.WriteLine("0.=>Previous Menu\n");
                    DisplayPhoneNumbers(contact);

                    var phoneNumberID = collect.CollectID("\nEnter the ID of the phone number you want to delete");
                    sql.DeletePhoneNumber(contact.ID, phoneNumberID);
                    contact = sql.GetContact(contact.ID);
                    break;

                default:
                    // Check if input is number and output the phone number ID
                    bool isNumber;
                    isNumber = int.TryParse(input, out int numberID);

                    // Edit existing number if user typed in phone number ID
                    if (isNumber)
                    {
                        var phoneNumberNumber = collect.CollectField(fieldName: "Number", previousValue: contact.PhoneNumbers.Find(number => number.ID == numberID).Number, required: false);
                        var phoneNumberType   = collect.CollectField(fieldName: "Type", previousValue: contact.PhoneNumbers.Find(type => type.ID == numberID).Type, required: false);
                        sql.UpdatePhoneNumber(contact.ID, numberID, phoneNumberNumber, phoneNumberType);
                        contact = sql.GetContact(contact.ID);
                    }

                    break;
                }
            }
        }