private void button1_Click(object sender, EventArgs e)
 {
     if (DisciplineName.Text != "")
     {
         DISCIPLINE d = db.DISCIPLINE.FirstOrDefault(p => p.DISCIPLINE_NAME == DisciplineName.Text);
         if (d == null)
         {
             DISCIPLINE discipline = new DISCIPLINE();
             discipline.DISCIPLINE_NAME = DisciplineName.Text;
             db.DISCIPLINE.Add(discipline);
             db.SaveChanges();
             MessageBox.Show("Объект обновлен");
         }
         else
         {
             MessageBox.Show("Дисциплина уже есть в базе данных");
         }
     }
     else
     {
         MessageBox.Show("Введите название дисциплины");
     }
 }
Exemple #2
0
 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("Все данные должны быть заполнены!");
     }
 }