private void AddButton_Click(object sender, EventArgs e) { if (activeTable == "Author") { AddValuesForm AddForm = new AddValuesForm(); AddForm.Text = "Додання нового автора"; AddForm.NameLabel.Text = "Автор книги"; AddForm.ShowDialog(); if (AddForm.DialogResult == DialogResult.OK) { AddAuthor(AddForm.NameTextBox.Text); GetAuthors(); } } if (activeTable == "Publishing") { AddValuesForm AddForm = new AddValuesForm(); AddForm.Text = "Додання нового видавництва"; AddForm.NameLabel.Text = "Назва"; AddForm.ShowDialog(); if (AddForm.DialogResult == DialogResult.OK) { AddPublishing(AddForm.NameTextBox.Text); GetPublishings(); } } if (activeTable == "Student") { AddStudentForm AddForm = new AddStudentForm(); AddForm.ShowDialog(); if (AddForm.DialogResult == DialogResult.OK) { AddStudent(AddForm.NameTextBox.Text, AddForm.IDTextBox.Text); GetStudents(); } } if (activeTable == "Books") { AddBookForm AddForm = new AddBookForm(); AddForm.ShowDialog(); if (AddForm.DialogResult == DialogResult.OK) { int row, idAuthor, idPublishing; int year = int.Parse(AddForm.YearTextBox.Text); int pages = int.Parse(AddForm.PagesTextBox.Text); row = AddForm.AuthorDataGrid.CurrentCell.RowIndex; // взяли строку с AuthorDataGrid idAuthor = (int)AddForm.AuthorDataGrid[0, row].Value; row = AddForm.PublishingDataGrid.CurrentCell.RowIndex; // взяли строку с PublishingDataGrid idPublishing = (int)AddForm.PublishingDataGrid[0, row].Value; AddBook(AddForm.NameTextBox.Text, year, idAuthor, idPublishing, pages); GetBooks(); } } }
public MainForm() { InitializeComponent(); Authors = new AddValuesForm(); }