Ejemplo n.º 1
0
        /// <summary>
        /// Отредактировать контакт
        /// </summary>
        private void Edit()
        {
            var selectedIndex = ContactsListBox.SelectedIndex;

            if (selectedIndex == -1)
            {
                MessageBox.Show("Выберите запись для редактирования", "Отсутствие записи");
                return;
            }
            var selectedContact = _project._contactlist[selectedIndex];
            var form            = new ContactForm();

            form.Contact = selectedContact;
            var dialogResult = form.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                var updatedContact = form.Contact;
                _project._contactlist.RemoveAt(selectedIndex);
                _project._contactlist.Insert(selectedIndex, updatedContact);
                CheckForBirthday();
                ResetListBox();
                _project._contactlist = _project.SortList();
                ProjectManager.SaveToFile(_project, ProjectManager.DefaultfilePath);
                ContactsListBox.SetSelected(selectedIndex, true);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }