public void addButton_Click(object sender, EventArgs e) { var addReaderForm = new AddLibrarianForm(); DialogResult dialogResult = addReaderForm.ShowDialog(this); if (dialogResult == DialogResult.Cancel) { return; } string name = addReaderForm.nameTextBox.Text; string surname = addReaderForm.surnameTextBox.Text; string patronymic = addReaderForm.patronymicTextBox.Text; DateTime DoB = addReaderForm.dateTimePicker.Value; string telNumber = addReaderForm.telNumberTextBox.Text; var reader = new Librarian { Name = name, Surname = surname, Patronymic = patronymic, DateOfBirth = DoB, TelephoneNumber = telNumber }; var readerRepository = new LibrarianRepository(); readerRepository.Create(reader); _db.SaveChanges(); SetDataGridView(); }
public void changeButton_Click(object sender, EventArgs e) { if (!(dataGridView1.SelectedRows.Count > 0)) { return; } var addLibrarianForm = new AddLibrarianForm(); var librarianRepository = new LibrarianRepository(); int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Librarian librarian = librarianRepository.FindById(id); addLibrarianForm.nameTextBox.Text = librarian.Name; addLibrarianForm.surnameTextBox.Text = librarian.Surname; addLibrarianForm.patronymicTextBox.Text = librarian.Patronymic; addLibrarianForm.dateTimePicker.Value = librarian.DateOfBirth; addLibrarianForm.telNumberTextBox.Text = librarian.TelephoneNumber; DialogResult dialogResult = addLibrarianForm.ShowDialog(this); if (dialogResult == DialogResult.Cancel) { return; } string name = addLibrarianForm.nameTextBox.Text; string surname = addLibrarianForm.surnameTextBox.Text; string patronymic = addLibrarianForm.patronymicTextBox.Text; DateTime DoB = addLibrarianForm.dateTimePicker.Value; string telNumber = addLibrarianForm.telNumberTextBox.Text; librarian.Name = name; librarian.Surname = surname; librarian.Patronymic = patronymic; librarian.DateOfBirth = DoB; librarian.TelephoneNumber = telNumber; librarianRepository.Update(librarian); _db.SaveChanges(); SetDataGridView(); }