private void button5_Click(object sender, EventArgs e) { if (dataGridView2.SelectedRows.Count > 0) { int index = dataGridView2.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView2[0, index].Value.ToString(), out id); if (converted == false) { return; } Authos au = db.Authos.Find(id); db.Authos.Remove(au); db.SaveChanges(); MessageBox.Show("Объект удален"); } else { MessageBox.Show("Выберите строку таблицы)!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void button7_Click(object sender, EventArgs e) { addau adu = new addau(); DialogResult result = adu.ShowDialog(this); if (result == DialogResult.Cancel) { return; } Authos au = new Authos(); au.idauthor = int.Parse(adu.textBox1.Text); au.lastname = adu.textBox2.Text; au.firstname = adu.textBox3.Text; au.backname = adu.textBox4.Text; au.birthyear = int.Parse(adu.textBox5.Text); au.deathyear = int.Parse(adu.textBox6.Text); db.Authos.Add(au); db.SaveChanges(); MessageBox.Show("Новый объект добавлен"); }
private void button6_Click(object sender, EventArgs e) { if (dataGridView2.SelectedRows.Count > 0) { int index = dataGridView2.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView2[0, index].Value.ToString(), out id); if (converted == false) { return; } Authos au = db.Authos.Find(id); addau adu = new addau(); adu.textBox1.Text = au.idauthor.ToString(); adu.textBox2.Text = au.lastname; adu.textBox3.Text = au.firstname; adu.textBox4.Text = au.backname; adu.textBox5.Text = au.birthyear.ToString(); adu.textBox6.Text = au.deathyear.ToString(); DialogResult result = adu.ShowDialog(this); if (result == DialogResult.Cancel) { return; } au.idauthor = int.Parse(adu.textBox1.Text); au.lastname = adu.textBox2.Text; au.firstname = adu.textBox3.Text; au.backname = adu.textBox4.Text; au.birthyear = int.Parse(adu.textBox5.Text); au.deathyear = int.Parse(adu.textBox6.Text); db.SaveChanges(); dataGridView2.Refresh(); // обновляем грид MessageBox.Show("Объект обновлен"); } }