Esempio n. 1
0
 private void AddingTask_Click(object sender, EventArgs e)
 {
     try
     {
         TIMETABLE tt = new TIMETABLE();
         WEEKDAY   wd = db.WEEKDAY.FirstOrDefault(p => p.WEEKDAY_NAME == WeekDay.SelectedValue.ToString());
         if (wd == 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 == Auditor.SelectedItem.ToString() &&
                  p.BUILDING == Building.SelectedItem.ToString()));
         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.SelectedValue.ToString());
         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        = Convert.ToInt32(WeekNumber.SelectedItem.ToString());
         timetable.TIME_CODE          = ti.TIME_CODE;
         timetable.CROSSES            = checkBox1.Checked ? 2 : 1;
         db.TIMETABLE.Add(timetable);
         db.SaveChanges();
         MessageBox.Show("Объект Добавлен");
     }
     catch (Exception er)
     {
         MessageBox.Show("Все данные должны быть заполнены!");
     }
 }