Example #1
0
        private void OnContactAdd(object sender, EventArgs e)
        {
            var form = new ContactForm();

            if (form.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            Compare(form);

            _contacts.Add(form.Contact);
            RefreshContacts();
        }
Example #2
0
 private void OnSafeAdd(ContactForm form)
 {
     try
     {
         _contacts.Add(form.Contact);
     } catch (NotImplementedException e)
     {
         //Rewriting an exception
         throw new Exception("Not implemented yet", e);
     } catch (Exception e)
     {
         throw;
     };
 }
Example #3
0
        private void EditContact()
        {
            ContactItem contactItem = GetSelectedContact();

            if (contactItem == null)
            {
                return;
            }
            ContactForm cf = new ContactForm();

            cf.Contact = contactItem;

            cf.ShowDialog(this);

            RefreshList();
        }
Example #4
0
        private void OnaddContact_Click(object sender, EventArgs e)
        {
            var form = new ContactForm();

            if (form.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }
            if (_database.ExistingContact(form.Contact))
            {
                MessageBox.Show(this, "Contact already exists", "Duplicate Contact", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            else
            {
                _database.Add(form.Contact);
                RefreshContacts();
            };
        }
Example #5
0
        private void EditContact()
        {
            var item = GetSelectedContact();

            if (item == null)
            {
                return;
            }

            var form = new ContactForm();

            //form.Text = "Edit Contact";
            form.Contact = item;
            if (form.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            _database.Edit(item.Name, form.Contact);
            RefreshContacts();
        }
        private void OnContactAdd(object sender, EventArgs e)
        {
            var form = new ContactForm();

            if (form.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            try
            {
                _contactDatabase.Add(form.Contact);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            RefreshContacts();
        }
Example #7
0
        private void OnContactsEdit(object sender, EventArgs e)
        {
            // display UI
            var form = new ContactForm();

            // change from title
            form.Text = "Edit Contact";

            // get selected contact, if any
            var contact = _listContacts.SelectedItem as Contact;

            if (contact == null)
            {
                return;
            }

            form.Contact = contact;

            while (true)
            {
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    _contacts.Update(contact.Id, form.Contact);
                    break;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Name must be unique.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            BindContactList();
        }
Example #8
0
        //on Contact add Event Handler
        private void OnContactAdd(object sender, EventArgs e)
        {
            var form = new ContactForm();

            while (true)
            {
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                try
                {
                    _contacts.Add(form.CurrentContact);
                    break;
                } catch (Exception ex)
                {
                    DisplayError(ex);
                };
            }
            ;

            BindList();
        }
Example #9
0
        private void EditContact()
        {
            //Get selected contact, if any
            var item = GetSelectedContact();

            if (item == null)
            {
                return;
            }

            //Show form with selected contact
            var form = new ContactForm();

            form.Contact = item;
            if (form.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            //Update database and refresh
            _database.Edit(item.Name, form.Contact);
            RefreshContacts();
        }
        private void OnEdit(object sender, EventArgs e)
        {
            var item = GetSelectedContact();

            if (item == null)
            {
                return;
            }

            var form = new ContactForm
            {
                Text    = "Edit Contact",
                Contact = item
            };

            if (form.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            _contactDatabase.Edit(item.Name, form.Contact);
            RefreshContacts();
        }
Example #11
0
        /// <summary>
        /// Edit a contact
        /// </summary>
        private void editContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = contactsListBox.SelectedIndex;

            if (index == -1)
            {
                return;
            }

            string   oldName = contactsListBox.SelectedItem.ToString();
            IContact contact = contactsList.FindContact(oldName);

            ContactForm form = new ContactForm(contact);

            while (true)
            {
                if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }

                try
                {
                    // Attempt to update
                    contactsList.UpdateContact(oldName, form.Contact);

                    // Dislay all contacts
                    RefreshContactsList();
                    return;
                }
                catch (Exception ex)
                {
                    // If there's an error, then re-do
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #12
0
        /// <summary>
        /// gets selected contact to be edited and opens ContactForm
        /// </summary>
        private void OnContactEdit(object sender, EventArgs e)
        {
            var form = new ContactForm();

            form.Text = "Edit Contact";
            var contact = GetSelectedContact();

            if (contact == null)
            {
                return;
            }

            // Contact to edit
            form.Contact = contact;

            while (true)
            {
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    _contacts.Update(contact.Id, form.Contact);
                    break;
                }
                catch (Exception ex)
                {
                    //recover
                    DisplayError(ex);
                };
            }
            ;
            BindList();
        }