private void NewButton_Click(object sender, EventArgs e) { Author newAuthor = new Author(); AuthorForm authorForm = new AuthorForm(newAuthor); if (authorForm.ShowDialog() == DialogResult.OK) { ListOfAuthors.Items.Add(newAuthor.ToString()); _authors.Add(newAuthor); Author.WriteAuthorsToFile("authors", _authors); } else { MessageBox.Show("Changes was not saved"); } }
private void EditButton_Click(object sender, EventArgs e) { int selectedIndex = ListOfAuthors.SelectedIndex; if (selectedIndex < 0 || selectedIndex >= _authors.Count) { MessageBox.Show("Choose author"); return; } AuthorForm authorModal = new AuthorForm(_authors[selectedIndex]); if (authorModal.ShowDialog() == DialogResult.OK) { ListOfAuthors.Items[selectedIndex] = _authors[selectedIndex].ToString(); Author.WriteAuthorsToFile("authors", _authors); } else { MessageBox.Show("Changes was not saved"); } }