private void button1_Click(object sender, EventArgs e) { if (GroupNumber.Text != "") { GROUPS g = db.GROUPS.FirstOrDefault(p => (p.GROUP_NUMBER.ToString() == GroupNumber.Text)); if (g == null) { GROUPS gr = new GROUPS(); FACULTY fac = db.FACULTY.FirstOrDefault(p => (p.FACULTY_NAME.ToString() == FacultyName.SelectedItem.ToString())); if (fac == null) { FACULTY f = new FACULTY(); f.FACULTY_NAME = FacultyName.SelectedItem.ToString(); fac = f; db.FACULTY.Add(f); } gr.GROUP_NUMBER = GroupNumber.Text; gr.FACULTY_CODE = fac.FACULTY_CODE; db.GROUPS.Add(gr); db.SaveChanges(); MessageBox.Show("Объект обновлен"); } else { MessageBox.Show("Группа уже есть в базе данных"); } } else { MessageBox.Show("Введите группу"); } }
private void AddingTask_Click(object sender, EventArgs e) { try { TIMETABLE tt = new TIMETABLE(); WEEKDAY wd = db.WEEKDAY.FirstOrDefault(p => p.WEEKDAY_NAME == weekday); if (wd == null) { MessageBox.Show("Неверный день недели"); } TYPE type = db.TYPE.FirstOrDefault(p => p.TYPE_NAME == Schedule.SelectedValue.ToString()); if (type == null) { MessageBox.Show("Неверное расписание"); } ACTIVITY ac = db.ACTIVITY.FirstOrDefault(p => p.ACTIVITY_TYPE_NAME == Activity.SelectedValue.ToString()); if (ac == null) { MessageBox.Show("Неверный вид занятия"); } AUDITORIUM au = db.AUDITORIUM.FirstOrDefault( p => (p.AUDITORIUM_NUMBER == aud && p.BUILDING == build)); if (au == null) { MessageBox.Show("Неверная аудитория"); } DISCIPLINE dp = db.DISCIPLINE.FirstOrDefault(p => (p.DISCIPLINE_NAME == Discipline.SelectedValue.ToString())); if (dp == null) { MessageBox.Show("Неверная аудитория"); } GROUPS gr = db.GROUPS.FirstOrDefault(p => p.GROUP_NUMBER == Group.SelectedValue.ToString()); if (gr == null) { MessageBox.Show("Неверная группа"); } TEACHER te = db.TEACHER.FirstOrDefault(p => p.TEACHER_NAME == Teacher.SelectedValue.ToString()); if (te == null) { MessageBox.Show("Неверное имя преподавателя"); } TIME ti = db.TIME.FirstOrDefault(p => p.TIME_START == time); if (ti == null) { MessageBox.Show("Неверное время занятия"); } TIMETABLE timetable = new TIMETABLE(); timetable.WEEKDAY_CODE = wd.WEEKDAY_CODE; timetable.COURSE_CODE = Convert.ToInt32(Course.SelectedItem.ToString()); timetable.GROUP_CODE = gr.GROUP_CODE; timetable.TEACHER_CODE = te.TEACHER_CODE; timetable.DISCIPLINE_CODE = dp.DISCIPLINE_CODE; timetable.ACTIVITY_TYPE_CODE = ac.ACTIVITY_TYPE_CODE; timetable.AUDITORIUM_CODE = au.AUDITORIUM_CODE; timetable.WEEK_NUMBER = weeknumber; timetable.TIME_CODE = ti.TIME_CODE; timetable.TYPE_CODE = type.TYPE_CODE; timetable.CROSSES = checkBox1.Checked ? 2 : 1; db.TIMETABLE.Add(timetable); db.SaveChanges(); MessageBox.Show("Объект Добавлен"); } catch (Exception er) { MessageBox.Show("Все данные должны быть заполнены!"); } }