Пример #1
0
 /// <summary>
 /// Checks if a new contact exists 
 /// </summary>
 /// <param name="contact">A temp contact to check with</param>
 /// <returns>Boolean for if the contact exists</returns>
 public bool contactExists(Contact contact)
 {
     foreach (Contact item in contactlist) {
         if (item.Id.Equals(contact.Id))
             return true;
     }
     return false;
 }
Пример #2
0
 /// <summary>
 /// Start the form with information from a contact
 /// Disable textchange eventhandler for txtId to avoid NullReferenceException
 /// </summary>
 /// <param name="newContact">Contact with information to be entered in textboxes</param>
 /// <param name="cl">Reference to the contactlist</param>
 public ContactForm(Contact newContact, ref ContactList cl)
 {
     InitializeComponent();
     txtName.Text = newContact.Name;
     txtId.TextChanged -= txtId_TextChanged;
     txtId.Text = newContact.Id;
     txtId.TextChanged += txtId_TextChanged;
     txtTelPriv.Text = newContact.TelNrPriv;
     txtMailPriv.Text = newContact.MailPriv;
     txtMailWork.Text = newContact.MailWork;
     this.contactList = cl;
 }
Пример #3
0
        /// <summary>
        /// When a listitem is doubleclicked, open form to update contact 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void listContacts_DoubleClick(object sender, EventArgs e)
        {
            ListViewItem lvi = listContacts.SelectedItems[0];
            string[] contact = new string[4];
            Contact oldContactInfo = new Contact(lvi.SubItems[0].Text, lvi.SubItems[1].Text, lvi.SubItems[2].Text, lvi.SubItems[3].Text, lvi.SubItems[4].Text, lvi.SubItems[5].Text);
            ContactForm tempNewContact = new ContactForm(oldContactInfo, ref contactlist);
            DialogResult update = tempNewContact.ShowDialog(this);

            if (update == DialogResult.OK) {
                contactlist.updatecontact(oldContactInfo.Id, tempNewContact.getContact());
                lvi.SubItems[0].Text = tempNewContact.getContact().Name;
                lvi.SubItems[1].Text = tempNewContact.getContact().Id;
                lvi.SubItems[2].Text = tempNewContact.getContact().TelNrPriv;
                lvi.SubItems[3].Text = tempNewContact.getContact().TelNrWork;
                lvi.SubItems[4].Text = tempNewContact.getContact().MailPriv;
                lvi.SubItems[5].Text = tempNewContact.getContact().MailWork;
            }
            resizeListView();
        }
Пример #4
0
 /// <summary>
 /// Adds new contact from temp contact 
 /// </summary>
 /// <param name="c">Contact to be inserted</param>
 public void addcontact(Contact c)
 {
     contactlist.Add(c);
     updated = true;
 }
Пример #5
0
 /// <summary>
 ///	Update existing contact 
 /// </summary>
 /// <param name="id">Id of the contact to be updated</param>
 /// <param name="updatedContact">A contact containing new information</param>
 public void updatecontact(string id, Contact updatedContact)
 {
     int existingContact = contactlist.FindIndex(x => x.Id.Equals(id));
     contactlist[existingContact] = updatedContact;
     updated = true;
 }
Пример #6
0
 /// <summary>
 /// Deletes contact by id 
 /// </summary>
 /// <param name="id">Contact to be deleted</param>
 public void deletecontact(Contact id)
 {
     contactlist.Remove(id);
     updated = true;
 }