/// <summary> /// Remove the element /// </summary> private void RemoveElement() { var selectedIndex = ContactsListBox.SelectedIndex; if (selectedIndex != -1) { var choice = MessageBox.Show("Are you sure you want to delete", "To delete", MessageBoxButtons.YesNo); if (choice == DialogResult.Yes) { var selectedContact = _contacts[selectedIndex]; _project.Contacts.Remove(selectedContact); ProjectManager.SaveProject(_project); SearchContact(); UpdatesListBox(_contacts); ContactsListBox.ClearSelected(); ClearTextBoxes(); } } else { MessageBox.Show("No contact selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void MainForm_Load(object sender, EventArgs e) { try { _project = ProjectManager.ReadProject(); _project.Contacts = _project.SearchContacts(); _contacts = _project.Contacts; } catch (AccessViolationException exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK); _project = new Project(); ProjectManager.CreatePath(null, null); } BirthdayLabel.Text = "Today birthday have:\n"; var birthdayContacts = _project.FindBirthdayContacts(DateTime.Now); if (birthdayContacts.Count != 0) { for (int i = 0; i < birthdayContacts.Count - 1; i++) { BirthdayLabel.Text += birthdayContacts[i].Surname + ", "; } BirthdayLabel.Text += birthdayContacts[birthdayContacts.Count - 1].Surname; } else { this.Controls.Remove(birthdayTableLayoutPanel); } UpdatesListBox(_contacts); ContactsListBox.ClearSelected(); }
private void Add_Click(object sender, EventArgs e) { var addForm = new ContactForm(); addForm.ShowDialog(); if (addForm.DialogResult == DialogResult.OK) { var newContact = addForm.Contact; _project.Contacts.Add(newContact); ProjectManager.SaveProject(_project); _project.Contacts = _project.SearchContacts(); SearchContact(); UpdatesListBox(_contacts); ChangeTextBoxes(newContact); var selectContact = _project.FindIndex(newContact); ContactsListBox.ClearSelected(); ContactsListBox.SetSelected(selectContact, true); } }
private void Edit_Click(object sender, EventArgs e) { var selectedIndex = ContactsListBox.SelectedIndex; if (selectedIndex != -1) { var selectedContact = _contacts[selectedIndex]; var editForm = new ContactForm() { Contact = selectedContact }; editForm.ShowDialog(); var updateContact = editForm.Contact; if (editForm.DialogResult == DialogResult.OK) { var selectIndexForProjectContacts = _project.FindIndex( selectedContact); _project.Contacts.RemoveAt(selectIndexForProjectContacts); _project.Contacts.Insert(selectIndexForProjectContacts, updateContact); _project.Contacts = _project.SearchContacts(); } ProjectManager.SaveProject(_project); SearchContact(); UpdatesListBox(_contacts); ChangeTextBoxes(updateContact); var selectContact = _project.FindIndex(updateContact); ContactsListBox.ClearSelected(); ContactsListBox.SetSelected(selectContact, true); } else { MessageBox.Show("No contact selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }