private void AcceptButton_Click(object sender, EventArgs e) { try { Ltr parentForm = Owner as Ltr; ILiterature newBook = new Book( Title: book.title, AuthorLastname: book.authorLastname, PagesTotal: book.pagesTotal, PagesReaded: (readedPagesTextBox.Text.Length == 0) ? 0 : Int32.Parse(readedPagesTextBox.Text), Commentary: book.commentary, Status: book.status); parentForm.library.RemoteBook((string)parentForm.dataGrid.CurrentRow.Cells[0].Value); parentForm.dataGrid.Rows.Remove(parentForm.dataGrid.CurrentRow); parentForm.dataGrid.Rows.Add(newBook.title, newBook.authorLastname, newBook.pagesReaded, newBook.pagesTotal, newBook.progress); library.StoreBook(newBook); library.Save(parentForm.libraryPath); this.Close(); } catch (Exception exception) { errorLabel.Text = exception.ToString(); } }
/// <summary> /// Кнопка добавить книгу /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddEditButton_Click(object sender, System.EventArgs e) { try { Ltr parentForm = Owner as Ltr; if (obligatoryField()) { ILiterature newBook = new Book( Title: titleTextBox.Text, AuthorLastname: authorLastnameTextBox.Text, PagesTotal: Int32.Parse(pagesTotalTextBox.Text), PagesReaded: (pagesReadedTexBox.Text.Length == 0) ? 0 : Int32.Parse(pagesReadedTexBox.Text), Commentary: commentaryTextBox.Text, Status: statusComboBox.Text); if (addEditButton.Text == "Редактировать") { parentForm.library.RemoteBook((string)parentForm.dataGrid.CurrentRow.Cells[0].Value); parentForm.dataGrid.Rows.Remove(parentForm.dataGrid.CurrentRow); } parentForm.dataGrid.Rows.Add(newBook.title, newBook.authorLastname, newBook.pagesReaded, newBook.pagesTotal, newBook.progress); library.StoreBook(newBook); library.Save(parentForm.libraryPath); if (addEditButton.Text == "Добавить") { titleTextBox.Clear(); authorLastnameTextBox.Clear(); pagesTotalTextBox.Clear(); pagesReadedTexBox.Clear(); commentaryTextBox.Clear(); } this.Close(); } else { errorLabel.ForeColor = Color.Maroon; errorLabel.Visible = true; errorLabel.Text = "ВНИМАНИЕ! Одно из полей не заполнено!"; } parentForm.LoadDataToGrid(parentForm.statusComboBox.Text, parentForm.searchBox.Text); } catch (Exception exeption) { errorLabel.Text = exeption.ToString(); } }