Exemplo n.º 1
0
        /// <summary>
        /// Добавляет в список новый контакт
        /// </summary>
        private void AddContact()
        {
            var addContactForm = new ContactForm();

            if (addContactForm.ShowDialog() == DialogResult.OK)
            {
                var newContact = addContactForm.Contact;

                _project.Contacts.Add(newContact);
                contactsListBox.Items.Add(newContact.Surname);

                _displayedContacts = _project.SortBySurname();
                ShowListBoxItems(_displayedContacts);
                ProjectManager.SaveToFile(_project, ProjectManager.DefaultFilePath);
                UpdateFormAfterChanges();     //TODO: нет пересохранения проекта
            }
        }
Exemplo 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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Добавление контакта.
        /// </summary>
        private void AddContact()
        {
            var newContact = new Contact {
                PhoneNumber = new PhoneNumber()
            };
            var contactForm = new ContactForm {
                TempContact = newContact
            };
            var dialogResult = contactForm.ShowDialog();

            if (dialogResult != DialogResult.OK)
            {
                return;
            }
            _project.Contacts.Add(contactForm.TempContact);
            _project.Contacts = Project.SortContacts(_project.Contacts);
            UpdateContactsList(contactForm.TempContact);
            ProjectManager.SaveToFile(_project, _filePath);
        }
Exemplo n.º 4
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);
            }
        }