/// <summary>
 /// Deprecated Method for adding a new object to the Lessons EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToLessons(Lesson lesson)
 {
     base.AddObject("Lessons", lesson);
 }
示例#2
0
        public void SaveShed()
        {
            bool saved_ok = true;
            int lessonNumber = 0;
            ErrorInfo = string.Empty;

            //
            int i = 0;
            using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
            {
                // узнаем форму обучения для группы
                int studytype = (from g in cnt.Groups where g.Id == selectedGroup.Id select g.StudyTypeId).First();

                foreach (var l in lessons) // проходим по расписанию на экране
                {
                    var res = (from c in cnt.Curriculums where c.RegulatoryActionId == l._Regaction select c);
                    if (res.Count() > 1)
                    {
                        // это поток, проверить все группы..
                        int day;
                        int number;
                        //MessageBox.Show("index = " + i);
                        HelperClasses.indexToNumberDay(i, out number, out day);
                        if (l._Number != number || l._Day != day) // мы передвинули день?
                            saved_ok = CheckFlowOk(res.First().RegulatoryActionId, number, day);
                        //MessageBox.Show("flow number "+number.ToString()+" day "+day.ToString());
                    }
                }
                ++i;

                if (!saved_ok)
                {
                    ErrorInfo = "В расписании имеются накладки! Исправте их и попробуйте снова!";
                    return;
                }

                int students;
                foreach (var s in lessons) // проходим по расписанию на экране
                {
                    if (s._Regaction != 0) // если в ячейке есть пара
                    {
                        //Console.WriteLine(s._Regaction.ToString());

                        var checklessons = (from l in cnt.Lessons where l.RegulatoryActionId == s._Regaction && l.Period == upweek select l);

                        /// !!!!а нужна ли эта проверка???????????????????????
                        /// можно просто всегда добавлять новую пару и предупредить о превышении часов если что...
                        if (checklessons.Count() == 0) // если пары с таким ID ещё не было в расписании
                        {
                            //var regaction = (from r in cnt.RegulatoryActions where r.Id == s._Regaction select r).First();
                            //Console.WriteLine("1) Number = {0} Day = {1}", (int)(lessonNumber / 7) + 1, lessonNumber % 7);

                            Lesson newLesson = new Lesson();
                            newLesson.RingId = (lessonNumber / 7) + 1;
                            newLesson.RegulatoryActionId = s._Regaction;
                            newLesson.Period = upweek;
                            newLesson.AuditoriumId = s._AudID != 0 ? s._AudID : 1;
                            if (studytype == 1) // очник
                            {
                                newLesson.Day = (lessonNumber % 7); // для заочников пока убрал
                                //Date = WeekDayNumberToDay(lessonNumber % 7), // для заочников получаем дату занятия
                                newLesson.Date = DateTime.Now; // дата не может быть пустой!! запишем что нибудь туда..
                            }
                            else if (studytype == 2) // заочник
                            {
                                newLesson.Date = HelperClasses.WeekDayNumberToDay(lessonNumber % 7, selecteddate); // для заочников получаем дату занятия
                            }
                            var aud = (from a in cnt.Auditoriums where a.Id == newLesson.AuditoriumId select a).First();
                            if (!CheckAuditoriumEmpty(newLesson.AuditoriumId, newLesson.RegulatoryActionId, newLesson.RingId, newLesson.Day, upweek) ||
                                !AuditoriumSizeOk(newLesson.RegulatoryActionId, aud, out students))
                            {
                                ErrorInfo += "Аудитория не подходит!";
                                newLesson.AuditoriumId = 1;
                            }
                            cnt.Lessons.AddObject(newLesson);
                        }
                        else // если мы её уже назанчали
                        {
                            var les = checklessons.First();
                            //Console.WriteLine("2) Number = {0} Day = {1}", (int)(lessonNumber / 7) + 1, lessonNumber % 7);
                            les.RingId = (lessonNumber / 7) + 1;
                            les.RegulatoryActionId = s._Regaction;
                            les.Period = upweek;
                            les.AuditoriumId = s._AudID;
                            //MessageBox.Show(s._AudID.ToString());
                            if (studytype == 1) // очник
                            {
                                les.Day = (lessonNumber % 7);
                                les.Date = DateTime.Now;
                            }
                            else if (studytype == 2) // заочник
                            {
                                les.Date = HelperClasses.WeekDayNumberToDay(lessonNumber % 7,selecteddate);
                            }
                            var aud = (from a in cnt.Auditoriums where a.Id == les.AuditoriumId select a).First();
                            if (!CheckAuditoriumEmpty(les.AuditoriumId, les.RegulatoryActionId, les.RingId, les.Day, upweek) ||
                                !AuditoriumSizeOk(les.RegulatoryActionId, aud, out students))
                            {
                                ErrorInfo += "Аудитория не подходит!";
                                les.AuditoriumId = 1;
                            }
                            cnt.Refresh(System.Data.Objects.RefreshMode.ClientWins, les);
                        }
                        cnt.SaveChanges();

                    }
                    ++lessonNumber;
                }
            }

            if (saved_ok) ShedLoadByGroup();
        }
 /// <summary>
 /// Create a new Lesson object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="period">Initial value of the Period property.</param>
 /// <param name="ringId">Initial value of the RingId property.</param>
 /// <param name="regulatoryActionId">Initial value of the RegulatoryActionId property.</param>
 /// <param name="auditoriumId">Initial value of the AuditoriumId property.</param>
 /// <param name="day">Initial value of the Day property.</param>
 public static Lesson CreateLesson(global::System.Int32 id, global::System.DateTime date, global::System.Boolean period, global::System.Int32 ringId, global::System.Int32 regulatoryActionId, global::System.Int32 auditoriumId, global::System.Int32 day)
 {
     Lesson lesson = new Lesson();
     lesson.Id = id;
     lesson.Date = date;
     lesson.Period = period;
     lesson.RingId = ringId;
     lesson.RegulatoryActionId = regulatoryActionId;
     lesson.AuditoriumId = auditoriumId;
     lesson.Day = day;
     return lesson;
 }