Beispiel #1
0
 /// <summary>
 /// Редактирование контакта.
 /// </summary>
 private void EditContact()
 {
     if (ContactsListBox.SelectedIndex == -1)
     {
         MessageBox.Show(@"Select the contact.", @"Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         var projectToList   = Project.SortContacts(findTextBox.Text, _project);
         var selectedIndex   = ContactsListBox.SelectedIndex;
         var selectedContact = projectToList.Contacts[selectedIndex];
         var contactForm     = new ContactForm {
             TempContact = selectedContact
         };
         var dialogResult = contactForm.ShowDialog();
         if (dialogResult != DialogResult.OK)
         {
             return;
         }
         var index = _project.Contacts.FindIndex(x => x == contactForm.TempContact);
         _project.Contacts.RemoveAt(index);
         _project.Contacts.Insert(index, contactForm.TempContact);
         _project.Contacts = Project.SortContacts(_project.Contacts);
         UpdateContactsList(contactForm.TempContact);
         ProjectManager.SaveToFile(_project, _filePath);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Выполняет редактирования выбранного в списке контакта
        /// </summary>
        private void EditContact()
        {
            if (contactsListBox.SelectedIndex == -1)
            {
                MessageBox.Show("Для редактирования необходимо выбрать контакт в списке",
                                "Error");
            }
            else
            {
                var         selectedContact = _displayedContacts[contactsListBox.SelectedIndex];
                ContactForm editContactForm = new ContactForm
                {
                    Contact = selectedContact
                };
                editContactForm.ShowDialog();

                if (editContactForm.DialogResult != DialogResult.Cancel)
                { //TODO: еще раз!! Грамошибки
                    var editedContact = editContactForm.Contact;

                    _project.Contacts.Add(editedContact);
                    contactsListBox.Items.Add(editedContact.Surname);
                    _project.Contacts.Remove(selectedContact);
                    contactsListBox.Items.Remove(selectedContact.Surname);

                    _displayedContacts = _project.SortBySurname();
                    ShowListBoxItems(_displayedContacts);
                    ProjectManager.SaveToFile(_project, ProjectManager.DefaultFilePath);
                    UpdateFormAfterChanges();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Метод добавления контакта.
        /// </summary>
        private void AddContact()
        {
            var form = new ContactForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                _project.ContactList.Add(form.Contact);
                RefreshList();
            }
        }
Beispiel #4
0
 /// <summary>
 /// Метод редактирования контакта.
 /// </summary>
 private void EditContact()
 {
     if (ContactListBox.SelectedItem != null)
     {
         var form = new ContactForm();
         form.Contact = (Contact)ContactListBox.SelectedItem;
         if (form.ShowDialog() == DialogResult.OK)
         {
             RefreshList();
         }
     }
 }
Beispiel #5
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: нет пересохранения проекта
            }
        }
Beispiel #6
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);
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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);
            }
        }