コード例 #1
0
ファイル: Form1.cs プロジェクト: jkotsev/Address-book
 private void Form1_Load(object sender, EventArgs e)
 {
     string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
     if (!Directory.Exists(path + "\\Address Book"))
         Directory.CreateDirectory(path + "\\Address Book");
     if (!File.Exists(path + "\\Address Book\\store.xml"))
     {
         XmlTextWriter xw = new XmlTextWriter(path + "\\Address Book\\store.xml", Encoding.UTF8);
         xw.WriteStartElement("Contacts");
         xw.WriteEndElement();
         xw.Close();
     }
     XmlDocument xDoc = new XmlDocument();
     xDoc.Load(path + "\\Address Book\\store.xml");
     foreach (XmlNode xNode in xDoc.SelectNodes("Contacts/Contacts"))
     {
         Contact c = new Contact();
         c.Name = xNode.SelectSingleNode("Name").InnerText;
         c.Email = xNode.SelectSingleNode("Email").InnerText;
         c.Phone = xNode.SelectSingleNode("Phone").InnerText;
         c.Address = xNode.SelectSingleNode("Address").InnerText;
         contacts.Add(c);
         listViewContacts.Items.Add(c.Name);
     }
 }
コード例 #2
0
 public ContactViewModel(INavigation navigation, Contact contact)
 {
     _navigation = navigation;
     _contactData = new ContactDataService();
     FillingCurrentContact(contact);
     AddContactCommand = new Command(() => NewContact(contact));
 }
コード例 #3
0
 private void CommandBinding_AddContact_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     Contact ct = new Contact();
     _currentBook.Add(ct);
     lstContacts.SelectedIndex = lstContacts.Items.Count - 1;
     if (contactEditor.Visibility == System.Windows.Visibility.Collapsed) contactEditor.Visibility = System.Windows.Visibility.Visible;
 }
コード例 #4
0
        public ContactViewModel(Contact contact)
        {
            Items = new ObservableCollection<ContactViewModelItem>();
            _contact = contact;
            IMAccounts = new RefreshableCollection<IMAccount>();

            foreach (var acc in _contact.IMAccounts) IMAccounts.Add(acc);

            foreach (PropertyInfo prop in _contactProps)
            {
                AutoDisplayAttribute attr = prop.GetCustomAttributes(typeof(AutoDisplayAttribute), false).SingleOrDefault() as AutoDisplayAttribute;

                ContactViewModelItem item = new ContactViewModelItem();

                if (attr != null)
                {
                    if (!attr.AutoDisplay) continue;
                    item.DisplayName = attr.DisplayName + ": ";
                }
                else continue;

                item.PropertyName = prop.Name;
                object val = prop.GetValue(_contact, null) ?? "";
                item.Value = val.ToString();
                Items.Add(item);
            }
        }
コード例 #5
0
ファイル: MainWindow.cs プロジェクト: jonator/AddressBook
        //adds new contact to the virtual list
        public void AddContact(Contact newContact)
        {
            virtualContactList.Add(newContact);

            contactListBox.Items.Add(newContact.FirstName + " " + newContact.LastName);//Adds to the listbox

            UpdateContactNumberLabel();//Takes another look at how many contacts there are
        }
コード例 #6
0
ファイル: ContactViewer.cs プロジェクト: jonator/AddressBook
 //to view is the contact that is selected in the contactListBox
 public ContactViewer(Contact toView)
 {
     InitializeComponent();
     this.Text = toView.FirstName + " " + toView.LastName;//Sets the title of the form to the first and last name
     phoneNumberLabel.Text = toView.PhoneNumber.ToString();//In phone number label's text, we added the class called phonenumbers imformation based on the (contact toView)
     emailLabel.Text = toView.Email;//We called the email based on the toView contact from the Contact class
     contactToView = toView;
 }
コード例 #7
0
ファイル: NewContactForm.cs プロジェクト: jonator/AddressBook
        public void WriteNewContact()
        {
            int areaCode = int.Parse(areaCodeTextbox.Text); //All these look for the data input in the textboxes and the parse does not crash if there is nothing
            int firstPart = int.Parse(firstPartTextbox.Text);
            int secondPart = int.Parse(secondPartTextbox.Text);

            Contact contact = new Contact(firstNameTextbox.Text, lastNameTextbox.Text, new PhoneNumber(areaCode, firstPart, secondPart), emailTextbox.Text);
            //^^^Adds new contact to the virtualContactList that is later used in the contactListBox
            home.AddContact(contact);
        }
コード例 #8
0
        //contactToView is set equal to toView which is set equal to the selected contact in contactListBox
        public EditExistingContactWindow(Contact contactToView)
        {
            InitializeComponent();
            firstNameEditTextBox.Text = contactToView.FirstName;
            lastNameEditTextbox.Text = contactToView.LastName;
            areaCodeEditTextBox.Text = contactToView.PhoneNumber.AreaCode.ToString();
            firstPartEditTextBox.Text = contactToView.PhoneNumber.FirstPart.ToString();
            secondPartEditTextBox.Text = contactToView.PhoneNumber.SecondPart.ToString();
            emailEditTextbox.Text = contactToView.Email;

            toEdit = contactToView;
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: jkotsev/Address-book
        private void button2_Click(object sender, EventArgs e)
        {
            Contact c = new Contact();
            c.Name = textBoxName.Text;
            c.Email = textBoxEmail.Text;
            c.Phone = textBoxPhone.Text;
            c.Address = textBoxAddress.Text;
            c.Photo = pictureBoxPhoto.Image;

            contacts.Add(c);
            listViewContacts.Items.Add(c.Name);
            textBoxName.Text = "";
            textBoxEmail.Text = "";
            textBoxPhone.Text = "";
            textBoxAddress.Text = "";
            pictureBoxPhoto.Image = pictureBoxPhoto.Image;
        }
コード例 #10
0
 void FillingCurrentContact(Contact contact)
 {
     FirstName = contact.FirstName;
     LastName = contact.LastName;
     MobNumber = contact.MobileNumber;
     HomeNumber = contact.HomeNumber;
     Notes = contact.Notes;
 }
コード例 #11
0
ファイル: Utils.cs プロジェクト: panfeng0007/AddressBook
        public static void DoPost(Contact c, string table)
        {
            string buffer = string.Format("ID={0}&firstname={1}&lastname={2}&gender={3}&phone={4}&phoneRaw={5}&phoneType={6}&addressLineOne={7}&addressLineTwo={8}&city={9}&state={10}&zip={11}&country={12}&countryCode={13}&addressFull={14}&email={15}&dob={16}&tableName={17}",
                c.ID, c.FirstName, c.LastName, c.Gender, c.PhoneNumberRefined, c.PhoneNumber, c.PhoneType, c.AddressLineOne, c.AddressLineTwo, c.City, c.State, c.Zip, c.Country, c.CountryCode, c.AddressFull, c.Email, c.DateOfBirth, table);

            byte[] byteBuffer = Encoding.ASCII.GetBytes(buffer);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://addressbookdb.fengpanhome.com/database_update.php");
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteBuffer.Length;
            Stream postData = request.GetRequestStream();
            postData.Write(byteBuffer, 0, byteBuffer.Length);
            postData.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream s = response.GetResponseStream();
            StreamReader r = new StreamReader(s);

            MessageBox.Show(r.ReadToEnd());
        }
コード例 #12
0
ファイル: Utils.cs プロジェクト: panfeng0007/AddressBook
        public static ObservableCollection<Contact> DoPost(string table)
        {
            ObservableCollection<Contact> ret = new ObservableCollection<Contact>();

            string buffer = string.Format("tableName={0}", table);
            byte[] byteBuffer = Encoding.ASCII.GetBytes(buffer);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://addressbookdb.fengpanhome.com/database_display.php");
            request.Method = "POST";

            request.ContentLength = byteBuffer.Length;
            request.ContentType = "application/x-www-form-urlencoded";

            Stream postData = request.GetRequestStream();
            postData.Write(byteBuffer, 0, byteBuffer.Length);
            postData.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream stream = response.GetResponseStream();
            StreamReader reader = new StreamReader(stream);
            string jsonString = reader.ReadToEnd();
            if (jsonString != "[]")
            {
                DataSet dataSet = JsonConvert.DeserializeObject<DataSet>(jsonString);
                DataTable dataTable = dataSet.Tables["contacts"];

                foreach (DataRow row in dataTable.Rows)
                {
                    Contact c = new Contact();
                    c.ID = Int32.Parse(row["ID"].ToString());
                    c.FirstName = row["firstname"].ToString();
                    c.LastName = row["lastname"].ToString();
                    c.Gender = row["gender"].ToString();
                    if (c.Gender == "Male")
                    {
                        c.MaleChecked = true;
                        c.FemaleChecked = false;
                    }
                    else if (c.Gender == "Female")
                    {
                        c.MaleChecked = false;
                        c.FemaleChecked = true;
                    }
                    else
                    {
                        c.MaleChecked = false;
                        c.FemaleChecked = false;
                    }
                    c.PhoneNumber = row["phoneRaw"].ToString();
                    c.PhoneNumberRefined = row["phone"].ToString();
                    c.PhoneType = row["phoneType"].ToString();
                    c.AddressLineOne = row["addressLineOne"].ToString();
                    c.AddressLineTwo = row["addressLineTwo"].ToString();
                    c.City = row["city"].ToString();
                    c.State = row["state"].ToString();
                    c.Zip = row["zip"].ToString();
                    c.Country = row["country"].ToString();
                    c.CountryCode = row["countryCode"].ToString();
                    c.AddressFull = row["addressFull"].ToString();
                    c.Email = row["email"].ToString();
                    c.DateOfBirth = row["dob"].ToString();

                    ret.Add(c);
                }
            }
            return ret;
        }
コード例 #13
0
        private void PopulateEditControls(Contact contact)
        {
            lastNameTextBox.Text = contact.LastName;
            firstNameTextBox.Text = contact.FirstName;
            addressTextBox.Text = contact.Address;
            addressExtTextBox.Text = contact.AddressExt;
            cityTextBox.Text = contact.City;
            postalCodeTextBox.Text = contact.PostalCode;
            phoneNumberPrimaryTextBox.Text = contact.PhonePrimary;
            phoneNumberAlternateTextBox.Text = contact.PhoneAlternate;
            birthdayDateTimePicker.Value = contact.Birthday;
            emailTextBox.Text = contact.Email;
            portraitPictureBox.Image = contact.Portrait;
            mapPictureBox.Image = contact.MapImage;
            middleInitialTextBox.Text = contact.MiddleInitial;

            if (contact.State != null)
            {
                stateComboBox.SelectedIndex = stateComboBox.FindStringExact(contact.State.Abbreviation);
            }
        }
コード例 #14
0
 void NewContact(Contact contact)
 {
     contact.FirstName = FirstName;
     contact.LastName = LastName;
     contact.MobileNumber =  MobNumber;
     contact.HomeNumber =  HomeNumber;
     contact.Notes = Notes;
     _contactData.UpdateContact(contact);
     _navigation.PopAsync(true);
 }
コード例 #15
0
 public ContactPage(Contact contact)
 {
     InitializeComponent();
     BindingContext = new ContactViewModel ( this.Navigation, contact); // HERE
 }
コード例 #16
0
ファイル: ContactBook.cs プロジェクト: Chronix/AddressBook
 public void Add(Contact ct)
 {
     Contacts.Add(ct);
 }
コード例 #17
0
 public void UpdateContact(Contact contact)
 {
     data.Update(contact);
 }
コード例 #18
0
ファイル: AddressBook.cs プロジェクト: zabertooth/AddressBook
        /// <summary>
        /// Add a new contact to the Address Book
        /// </summary>
        /// <returns>Array index of the newly added Contact</returns>
        public static int Add()
        {
            Contact newContact = new Contact();
            Instance._contacts.Add(newContact);
            Instance._contacts.Sort();

            return Instance._contacts.IndexOf(newContact);
        }
コード例 #19
0
ファイル: AddressBook.cs プロジェクト: zabertooth/AddressBook
 /// <summary>
 /// Remove a contact from the AddressBook
 /// </summary>
 /// <param name="contact"></param>
 public static void Remove(Contact contact)
 {
     Instance._contacts.Remove(contact);
     Instance._contacts.Sort();
 }
コード例 #20
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     if (!editMode)
     {
         contactToModify = new Contact();
         contactToModify.PhoneType = "Home";
     }
     this.contactListView.DataContext = contactToModify;
 }
コード例 #21
0
 public void SetContact(Contact contact)
 {
     DataContext = new ContactViewModel(contact);
 }
コード例 #22
0
 public void AddContact(string  firstName, string  lastName, string mobileNumber, string homeNumber, string notes)
 {
     var contact = new Contact {FirstName = firstName, LastName = lastName, MobileNumber = mobileNumber,HomeNumber = homeNumber, Notes = notes };
     data.Insert(contact);
 }
コード例 #23
0
        static void Main(string[] args)
        {
            AddressBookBinder binder = new AddressBookBinder();

            Console.WriteLine("Welcome to Address Book Program");
            int result = 1;

            while (result == 1)
            {
                Console.WriteLine("Enter the name of the Address Book to be used");
                string      addrName = Console.ReadLine();
                AddressBook book     = new AddressBook();
                book.People = binder.AddAddrBook(addrName, book.People);
                int loop = 1;
                while (loop == 1)
                {
                    Console.WriteLine("\nSelect the option. \n1. Add new contact. \n2. Edit existing contact.\n3. Delete Contact \n4. Search By City \n5. Count citywise contacts \n6. Display Alphabetically \n7. Sort By Zipcode \n8. Sort By City \n9. Sort By State \n10. Exit.");
                    int option = int.Parse(Console.ReadLine());
                    switch (option)
                    {
                    case 1:
                        Console.WriteLine("Enter the person details to be added in the address book");
                        Console.WriteLine("First Name");
                        string FirstName = Console.ReadLine();
                        Console.WriteLine("Last Name");
                        string LastName = Console.ReadLine();
                        Console.WriteLine("Address");
                        string Address = Console.ReadLine();
                        Console.WriteLine("City");
                        string City = Console.ReadLine();
                        Console.WriteLine("State");
                        string State = Console.ReadLine();
                        Console.WriteLine("Zip code");
                        string ZipCode = Console.ReadLine();
                        Console.WriteLine("Phone Number");
                        string PhoneNumber = Console.ReadLine();
                        Console.WriteLine("Email");
                        string Email = Console.ReadLine();
                        if (book.AddContact(FirstName, LastName, Address, City, State, ZipCode, PhoneNumber, Email))
                        {
                            Console.WriteLine("Contact added successfully");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Contact already exists");
                            break;
                        }

                    case 2:
                        Console.WriteLine("Enter the first name of the contact to be edited ");
                        string  name = Console.ReadLine();
                        Contact c    = book.FindContact(name);
                        if (c == null)
                        {
                            Console.WriteLine("Address for {0} count not be found.", name);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("New Last Name");
                            c.LastName = Console.ReadLine();
                            Console.WriteLine("New Address");
                            c.Address = Console.ReadLine();
                            Console.WriteLine("New City");
                            c.City = Console.ReadLine();
                            Console.WriteLine("New State");
                            c.State = Console.ReadLine();
                            Console.WriteLine("New Zip code");
                            c.ZipCode = Console.ReadLine();
                            Console.WriteLine("New Phone Number");
                            c.PhoneNumber = Console.ReadLine();
                            Console.WriteLine("New Email");
                            c.Email = Console.ReadLine();
                            Console.WriteLine("Details updated for " + name);
                            break;
                        }

                    case 3:
                        Console.WriteLine("Enter the first name of the contact to be deleted ");
                        string name1 = Console.ReadLine();
                        if (book.RemoveContact(name1))
                        {
                            Console.WriteLine("Contact removed successfully");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Contact not found");
                            break;
                        }

                    case 4:
                        binder.CreateDictionary();
                        Console.WriteLine("Enter city whose contacts need to be searched");
                        string city = Console.ReadLine();
                        foreach (Contact contact in binder.CityDictionary[city])
                        {
                            Console.WriteLine(contact.FirstName + "\t" + contact.LastName + "\t" + contact.Address + "\t" + contact.City + "\t" + contact.State + "\t" + contact.ZipCode + "\t" + contact.PhoneNumber + "\t" + contact.Email);
                        }
                        break;

                    case 5:
                        binder.CreateDictionary();
                        foreach (var key in binder.CityDictionary.Keys)
                        {
                            Console.WriteLine(key + "\t" + binder.CityDictionary[key].Count);
                        }
                        break;

                    case 6:
                        book.AlphabeticallyArrange();
                        break;

                    case 7:
                        book.SortByPincode();
                        break;

                    case 8:
                        book.SortByCity();
                        break;

                    case 9:
                        book.SortByState();
                        break;

                    case 10:
                        loop = 0;
                        break;
                    }
                    binder.Binder[addrName] = (book.People);
                }
                Console.WriteLine("Do you want to enter an address book. \n1. yes \n2. no");
                result = int.Parse(Console.ReadLine());
            }
            foreach (var key in binder.Binder.Keys)
            {
                foreach (Contact c in binder.Binder[key])
                {
                    data.Add(c);
                }
            }
            ReadWrite.WriteToJsonFile(data);
            ReadWrite.ReadJsonFile();
        }