private void SubjectAddToolStripMenuItem1_Click(object sender, EventArgs e) { SubjectForm subjectForm = new SubjectForm(); if (subjectForm.ShowDialog() == DialogResult.OK) { db.Subjects.Add(subjectForm.Subject); db.SaveChanges(); } }
private void Change_Click(object sender, EventArgs e) { if (dataGridView.SelectedCells.Count == 0) { MessageBox.Show("Виберіть хочаб одну строку в таблиці", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // идентификатор записи // вызываем форму таблиц и редактируем выделенную строку var id = dataGridView.SelectedRows[0].Cells[0].Value; List <Commission> commissions = db.Commissions.ToList(); //принимаем данные с таблицы комиссии List <Subjects> subjects = db.Subjects.ToList(); //принимаем данные с таблицы предметов if (typeof(T) == typeof(Subjects)) { var subject = set.Find(id) as Subjects; if (subject != null) { var form = new SubjectForm(subject); if (form.ShowDialog() == DialogResult.OK) { subject = form.Subject; db.SaveChanges(); dataGridView.Refresh(); } } } else if (typeof(T) == typeof(Teacher)) { var teacher = set.Find(id) as Teacher; if (teacher != null) { TeacherForm teacherForm = new TeacherForm(teacher); //подключаем данные и выводим список комиссий в comboBox1 teacherForm.comboBox1.DataSource = commissions; teacherForm.comboBox1.ValueMember = "ComId"; teacherForm.comboBox1.DisplayMember = "ComName"; //подключаем данные и выводим список предметов в comboBox2 teacherForm.comboBox2.DataSource = subjects; teacherForm.comboBox2.ValueMember = "SubjId"; teacherForm.comboBox2.DisplayMember = "ShortName"; if (teacherForm.ShowDialog() == DialogResult.OK) { teacher = teacherForm.Teacher; db.SaveChanges(); dataGridView.Refresh(); } } } else if (typeof(T) == typeof(Groups)) { var groups = set.Find(id) as Groups; if (groups != null) { GroupForm groupForm = new GroupForm(); groupForm.comboBox1.DataSource = commissions; groupForm.comboBox1.ValueMember = "ComId"; groupForm.comboBox1.DisplayMember = "ComName"; if (groupForm.ShowDialog() == DialogResult.OK) { groups = groupForm.Groups; db.SaveChanges(); dataGridView.Refresh(); } } } else if (typeof(T) == typeof(Commission)) { var commission = set.Find(id) as Commission; if (commission != null) { var form = new CommissionForm(commission); if (form.ShowDialog() == DialogResult.OK) { commission = form.Commission; db.SaveChanges(); dataGridView.Refresh(); } } } }