private void SaveDiscipline() { if (comboBoxDiscpline.Text != "") { if (DBobjects.Entities.Discipline.Where(p => p.nameDiscipline == comboBoxDiscpline.Text).Count() == 0) { discipline = new Discipline(); discipline.nameDiscipline = comboBoxDiscpline.Text; DBobjects.Entities.Discipline.Add(discipline); DBobjects.Entities.SaveChanges(); } else { discipline = DBobjects.Entities.Discipline.FirstOrDefault(p => p.nameDiscipline == comboBoxDiscpline.Text); } RatingMark ratingMark = new RatingMark(); ratingMark.idDiscipline = discipline.idDiscipline; ratingMark.idJournal = JournalForm.Journal.idJournal; ratingMark.idRating = DBobjects.Entities.Rating.First().idRating; ratingMark.idStudent = DBobjects.Entities.Student.FirstOrDefault(p => p.idGroup == JournalForm.Journal.idGroup).idStudent; ratingMark.ratingMark1 = 0; DBobjects.Entities.RatingMark.Add(ratingMark); DBobjects.Entities.SaveChanges(); comboBoxDiscpline.SelectedItem = discipline.nameDiscipline; fillDiscipline(); comboBoxDiscpline.SelectedIndex = comboBoxDiscpline.Items.Count - 1; } }
private void SaveRatingMark() { foreach (DataGridViewRow dgvr in dgvStudentMark.Rows) { RatingMark ratingMark; foreach (Rating rating in DBobjects.Entities.Rating.ToList()) { if (Convert.ToInt32(dgvr.Cells["ID" + rating.nameRating].Value) == 0) { ratingMark = new RatingMark(); } else { int id = Convert.ToInt32(dgvr.Cells["ID" + rating.nameRating].Value); ratingMark = DBobjects.Entities.RatingMark.FirstOrDefault(p => p.idRatingMark == id); } ratingMark.idRatingMark = Convert.ToInt32(dgvr.Cells["ID" + rating.nameRating].Value); ratingMark.idRating = rating.idRating; ratingMark.idJournal = JournalForm.Journal.idJournal; ratingMark.idStudent = Convert.ToInt32(dgvr.Cells[0].Value); ratingMark.ratingMark1 = Convert.ToInt32(dgvr.Cells[rating.nameRating].Value); if (comboBoxDiscpline.Text != "") { ratingMark.idDiscipline = DBobjects.Entities.Discipline.FirstOrDefault(p => p.nameDiscipline == comboBoxDiscpline.Text).idDiscipline; if (DBobjects.Entities.RatingMark.Where(p => p.idRatingMark == ratingMark.idRatingMark).Count() == 0) { DBobjects.Entities.RatingMark.Add(ratingMark); } DBobjects.Entities.SaveChanges(); } else { MessageBox.Show("Заполните поле дисциплина"); } } } }