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(); }; }
private void OnSafeAdd(ContactForm form) { try { _contacts.Add(form.Contact); } catch (Exception e) { throw new Exception("Error!", e); }; }
private void OnNewContact(object sender, EventArgs e) { ContactForm cf = new ContactForm(); cf.ShowDialog(this); if (cf.Contact != null) { _contactDB.Add(cf.Contact); } RefreshList(); }
public static async Task <List <Contact> > ImportContact(Window owner, StatusStrip statusStrip, string rootFolder = null) { statusStrip.UpdateMainStatus("IMPORTING..."); FileDialog open = new FileDialog(owner, rootFolder == null ? Environment.GetFolderPath(Environment.SpecialFolder.Personal) : rootFolder, FileDialogType.Open, ListViewMode.Detail); open.Title = "Import Contact"; open.Filter = "VCard Contact Files (*.vcf)|.vcf"; //open.IconSize = IconSize.Small; open.FilterIndex = 0; //open.RootFolder = rootFolder == null ? Environment.GetFolderPath(Environment.SpecialFolder.Personal) : rootFolder; openDialog = open; List <Contact> list = null; if (open.ShowDialog() == true) { try { string file = open.SelectedFile; await Task.Factory.StartNew(() => { list = Contact.ParseVCard(file); foreach (Contact each in list) { ContactDatabase.Add(each); } }); statusStrip.UpdateMainStatus("READY"); } catch (Exception exc) { list = null; statusStrip.UpdateMainStatus("ERROR: " + exc.Message.ToUpper()); } } else { statusStrip.UpdateMainStatus("READY"); } return(list); }