/*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; * DB.Groups groupe = db.Groups.Find(id); * * GroupeForm GF = new GroupeForm(); * * GF.comboBox1.SelectedValue = groupe.Specialty_Id; * GF.comboBox2.SelectedValue = groupe.Course_Id; * GF.numericUpDown1.Value = groupe.Year; * GF.numericUpDown2.Value = groupe.Number; * * DialogResult result = GF.ShowDialog(this); * * if (result == DialogResult.Cancel) * return; * * * DB.Groups Group = new DB.Groups(); * Group.Specialty_Id = (int)GF.comboBox1.SelectedValue; * Group.Course_Id = (int)GF.comboBox2.SelectedValue; * Group.Year = (int)GF.numericUpDown1.Value; * Group.Number = (int)GF.numericUpDown2.Value; * Group.Faculty_Id = this.FacultyId; * db.SaveChanges(); * DGV2fill(); * MessageBox.Show("Группа изменена"); * } * }*/ private void button4_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; } Entity_DB.Groups groupe = db.Groups.Find(id); db.Groups.Remove(groupe); db.SaveChanges(); DGV2fill(); MessageBox.Show("Группа удалена"); } }
private void button6_Click(object sender, EventArgs e) { GroupeForm GF = new GroupeForm(); DialogResult result = GF.ShowDialog(this); if (result == DialogResult.Cancel) { return; } Entity_DB.Groups Group = new Entity_DB.Groups(); Group.Specialty_Id = (int)GF.comboBox1.SelectedValue; Group.Course_Id = (int)GF.comboBox2.SelectedValue; Group.Year = (int)GF.numericUpDown1.Value; Group.Number = (int)GF.numericUpDown2.Value; Group.Faculty_Id = this.FacultyId; db.Groups.Add(Group); db.SaveChanges(); DGV2fill(); MessageBox.Show("Новая группа добавлена"); }