Пример #1
0
        private void btnAuthorAdd_Click(object sender, EventArgs e)
        {
            AuthorForm authorForm = new AuthorForm(_db);

            authorForm.Owner = this;
            authorForm.Show();
        }
Пример #2
0
        private void btnAuthorChange_Click(object sender, EventArgs e)
        {
            if (dataGridViewAuthors.SelectedRows.Count > 0)
            {
                int  index     = dataGridViewAuthors.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridViewAuthors[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Author author = _db.Authors.Find(id);

                AuthorForm authorForm = new AuthorForm(_db);
                authorForm.textBoxFirstName.Text  = author.FirstName;
                authorForm.textBoxSecondName.Text = author.SecondName;
                authorForm.textBoxBirthDate.Text  = author.BirthDate.ToString("dd.MM.yyyy");

                DialogResult result = authorForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                author.FirstName  = authorForm.textBoxFirstName.Text;
                author.SecondName = authorForm.textBoxSecondName.Text;

                DateTime birthDate = DateTime.Now;
                if (DateTime.TryParse(authorForm.textBoxBirthDate.Text, out birthDate))
                {
                    author.BirthDate        = birthDate;
                    _db.Entry(author).State = EntityState.Modified;
                    _db.SaveChanges();

                    MessageBox.Show($"Author {author.FullName} was updated");
                }
            }
        }