Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            AddGenre addGenre = new AddGenre();

            DialogResult result = addGenre.ShowDialog(this);

            if (result == DialogResult.Cancel)
                Hide();
            if (result == DialogResult.OK)
            {
                Genre genre = new Genre();
                genre.genre1 = addGenre.textBox1.Text;
                db.Genres.Add(genre);
                db.SaveChanges();
                dataGridView1.Refresh();
                Refresh();
                MessageBox.Show("Добавлен новый жанр!");
            }
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int index = dataGridView1.SelectedRows[0].Index;
                int id = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                    return;

                Genre genre = db.Genres.Find(id);

                AddGenre addGenre = new AddGenre();

                addGenre.textBox1.Text = genre.genre1;

                DialogResult result = addGenre.ShowDialog(this);

                if (result == DialogResult.Cancel)
                    Hide();

                genre.genre1 = addGenre.textBox1.Text;
                

                db.SaveChanges();
                dataGridView1.Refresh();
                Refresh();
                MessageBox.Show("Объект обновлен");

            }
        }