示例#1
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();
        }
示例#2
0
        private void InstallApp()
        {
            StudyType Ochnaja = new StudyType
            {
                Name = "очная"
            };

            StudyType Zaochnaja = new StudyType
            {
                Name = "заочная"
            };

            StudyType unnamed3 = new StudyType
            {
                Name = "unnamed3"
            };

            StudyType unnamed4 = new StudyType
            {
                Name = "unnamed4"
            };

            Faculty IiVT = new Faculty
            {
                Name = "Информатика и вычислительная техника",
                Abbreviation = "ИиВТ",
            };

            FieldOfStudy Specialist = new FieldOfStudy
            {
                Name = "специалист"
            };

            FieldOfStudy Bakalavr = new FieldOfStudy
            {
                Name = "бакалавр"
            };

            FieldOfStudy Magistr = new FieldOfStudy
            {
                Name = "магистр"
            };

            LessonsType Lections = new LessonsType
            {
                Id = 1,
                Name = "лекция"
            };

            LessonsType Practics = new LessonsType
            {
                Id = 2,
                Name = "практика"
            };

            LessonsType Labs = new LessonsType
            {
                Id = 3,
                Name = "лабораторные"
            };

            LessonsSubType Comp = new LessonsSubType
            {
                Name = "компьютеры",
                LessonsTypeId = Labs.Id
            };

            LessonsSubType Stanki = new LessonsSubType
            {
                Name = "станки",
                LessonsTypeId = Labs.Id
            };

            Title prepod = new Title
            {
                Name = "преподаватель"
            };

            Faculty fac = new Faculty
            {
                Name = "факультет",
                Abbreviation = "фак"
            };

            Ring first = new Ring
            {
                Begin = "8:30",
                End = "9:50"
            };

            Ring second = new Ring
            {
                Begin = "10:00",
                End = "11:20"
            };

            Ring third = new Ring
            {
                Begin = "11:20",
                End = "12:50"
            };

            Ring fourth = new Ring
            {
                Begin = "13:30",
                End = "14:50"
            };

            Ring fifth = new Ring
            {
                Begin = "15:00",
                End = "16:20"
            };

            Ring sixth = new Ring
            {
                Begin = "16:30",
                End = "17:50"
            };

            Ring seventh = new Ring
            {
                Begin = "18:10",
                End = "19:30"
            };

            Auditorium a = new Auditorium
            {
                Building = 1,
                Number = "1-490",
                Seats = 50,
                OpeningDate = "",
                ClosingDate = "",
                DepartmentId = 1,
            };

            Degree d = new Degree
            {
                Name = "degree",
            };

            using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
            {
                cnt.StudyTypes.AddObject(Ochnaja);
                cnt.StudyTypes.AddObject(Zaochnaja);
                cnt.StudyTypes.AddObject(unnamed3);
                cnt.StudyTypes.AddObject(unnamed4);
                cnt.Faculties.AddObject(IiVT);
                cnt.FieldsOfStudy.AddObject(Specialist);
                cnt.FieldsOfStudy.AddObject(Bakalavr);
                cnt.FieldsOfStudy.AddObject(Magistr);
                cnt.LessonsTypes.AddObject(Lections);
                cnt.LessonsTypes.AddObject(Practics);
                cnt.LessonsTypes.AddObject(Labs);
                cnt.LessonsSubTypes.AddObject(Comp);
                cnt.LessonsSubTypes.AddObject(Stanki);
                cnt.Titles.AddObject(prepod);
                cnt.Faculties.AddObject(fac);
                cnt.Rings.AddObject(first);
                cnt.Rings.AddObject(second);
                cnt.Rings.AddObject(third);
                cnt.Rings.AddObject(fourth);
                cnt.Rings.AddObject(fifth);
                cnt.Rings.AddObject(sixth);
                cnt.Rings.AddObject(seventh);
                cnt.Degrees.AddObject(d);
                //cnt.Auditoriums.AddObject(a);
                // И финальный аккорд - сохраняем все изменения в БД
                cnt.SaveChanges();
            }
        }
示例#3
0
 private void EditEmploye()
 {
     using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
     {
         var emp = (from e in cnt.Employees where e.Id == selectedemploye.Id select e).First();
         emp.Name = selectedemploye.Name;
         emp.DegreeId = selectedemploye.DegreeId;
         emp.FacultyId = selectedemploye.FacultyId;
         emp.TitleId = selectedemploye.TitleId;
         //cnt.Refresh(System.Data.Objects.RefreshMode.ClientWins, emp);
         cnt.SaveChanges();
         var emplist = (from e in cnt.Employees select e);
         Employes = new ObservableCollection<Employe>(emplist);
     }
 }
 public void Import()
 {
     using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
     {
         foreach (var g in readeddepartment)
         {
             if (g.Add)
             {
                 Department newDepartment = new Department()
                 {
                     Abbreviation = g.Name,
                     Name = g.Name,
                     //Id = g.Id,
                     FacultyId = 1,
                 };
                 cnt.Departments.AddObject(newDepartment);
             }
         }
         cnt.SaveChanges();
         Department virtualDepartment = new Department()
         {
             Abbreviation = "VIRT",
             Name = "Virtual",
             FacultyId = 1,
         };
         cnt.Departments.AddObject(virtualDepartment);
         Auditorium virtualAudit = new Auditorium()
         {
             Building = 1,
             Number = "VIRTUAL",
             Seats = 9999999,
             Department = virtualDepartment,
             OpeningDate = "",
             ClosingDate = "",
         };
         cnt.Auditoriums.AddObject(virtualAudit);
         cnt.SaveChanges();
     }
 }
示例#5
0
 private void DelEmploye()
 {
     using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
     {
         var emp = (from e in cnt.Employees where e.Id == selectedemploye.Id select e).First();
         cnt.DeleteObject(emp);
         cnt.SaveChanges();
         var emplist = (from e in cnt.Employees select e);
         Employes = new ObservableCollection<Employe>(emplist);
     }
 }
示例#6
0
 private void AddEmploye()
 {
     using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
     {
         Employe emp = new Employe();
         emp.Name = selectedemploye.Name;
         emp.DegreeId = selectedemploye.DegreeId;
         emp.FacultyId = selectedemploye.FacultyId;
         emp.TitleId = selectedemploye.TitleId;
         cnt.Employees.AddObject(emp);
         cnt.SaveChanges();
         var emplist = (from e in cnt.Employees select e);
         Employes = new ObservableCollection<Employe>(emplist);
     }
 }
 public void Import()
 {
     using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
     {
         foreach (var g in readedgroups)
         {
             if (g.Add)
             {
                 Group newGroup = new Group()
                 {
                     GroupAbbreviation = g.groupCode,
                     Cource = g.course,
                     StudCount = g.studentAmount,
                     SpecialtyAbbreviation = g.specCode,
                     StudyTypeId = g.studyForm,
                     FieldOfStudyId = g.studyDirection,
                     FacultyId = 1,
                 };
                 cnt.Groups.AddObject(newGroup);
             }
         }
         cnt.SaveChanges();
     }
 }
        public void Import()
        {
            using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
            {
                foreach (var g in readedauditoriums)
                {
                    if (g.Add)
                    {
                        var deps = (from lt in cnt.Departments where lt.Id == g.Chair select lt);
                        if (deps.Count() == 0) continue;

                        Auditorium newAudit = new Auditorium()
                        {
                            Building = g.Corpus,
                            Department  = deps.First(),
                            Seats = g.Capacity,
                             Number = g.CorAndNum,
                             OpeningDate = "",
                             ClosingDate = "",
                        };
                        cnt.Auditoriums.AddObject(newAudit);
                    }
                }
                cnt.SaveChanges();
            }
        }
        public void Import()
        {
            int lines_count = readedstrings.Where(x => x.Add).Count();
            int i = 0;
            using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
            {
                int depId = ReadedStrings.First().KafedraId;
                //Department department = (from lt in cnt.Departments where lt.Id == depId select lt).First();
                foreach (var res in ReadedStrings.Where(x => x.Add))
                {
                    if (res.SubjectType == 0) continue;
                    //LessonsType lessontype = (from lt in cnt.LessonsTypes where lt.Id == res.SubjectType select lt).First();
                    RegulatoryAction regaction = new RegulatoryAction()
                    {
                        LessonsTypeId = res.SubjectType,
                        Hours = res.Time,
                        DepartmentId = depId,
                    };
                    cnt.RegulatoryActions.AddObject(regaction);

                    IEnumerable<Employe> teachers = (from e in cnt.Employees where e.Name == res.Name2 select e);
                    Employe teacher = null;
                    if (teachers.Count() == 0)
                    {
                        //нет такого преподавателя, добавим его
                        teacher = new Employe()
                        {
                            Name = res.Name2,
                            FacultyId = 1,
                            TitleId = 1,
                            DegreeId = 1,
                        };
                        cnt.Employees.AddObject(teacher);
                        //cnt.SaveChanges();
                    }
                    else teacher = teachers.First();

                    AcademicLoad academicload = new AcademicLoad()
                    {
                        RegulatoryAction = regaction,
                        Employe = teacher
                    };
                    cnt.AcademicLoadSet.AddObject(academicload);

                    ///
                    IEnumerable<Subject> subjects = (from e in cnt.Subjects where e.Name == res.Subject select e);
                    Subject subject = null;
                    if (subjects.Count() == 0)
                    {
                        //нет такого предмета, добавим его
                        subject = new Subject()
                        {
                            Name = res.Subject,
                            Abbreviation = "",
                        };
                        cnt.Subjects.AddObject(subject);
                        Console.WriteLine("subj not found = " + res.Subject);
                    }
                    else
                    {
                        subject = subjects.First();
                        Console.WriteLine("subj found = " + subject.Name);
                    }
                    ///

                    ///
                    string [] splitedGroups = res.Groups.Split(';');
                    foreach (var splitedGroup in splitedGroups)
                    {
                        string trimedGroup = splitedGroup.Trim();
                        Console.WriteLine(res.Groups + "       " + trimedGroup);
                        IEnumerable<Group> groups = (from e in cnt.Groups.Include("EduPeriod") where e.GroupAbbreviation == trimedGroup select e);
                        Group group = null;
                        if (groups.Count() == 0)
                        {
                            Console.WriteLine("group not found = " + trimedGroup);
                            continue;
                        }
                        else
                        {
                            group = groups.First();
                            Console.WriteLine("group found = " + trimedGroup);
                            if (group.EduPeriod.Count == 0)
                            {
                                EduPeriod e = new EduPeriod
                                {
                                    Begin = DateTime.Parse(res.Date.Substring(0, 10)),
                                    End = DateTime.Parse(res.Date.Substring(10, 10)),
                                    GroupId = group.Id,
                                };
                                cnt.EduPeriods.AddObject(e);
                            }
                        }
                        ///

                        Curriculum curr = new Curriculum()
                        {
                            RegulatoryAction = regaction,
                            Subject = subject,
                            Group = group,
                        };
                        cnt.Curriculums.AddObject(curr);
                        cnt.SaveChanges();
                    }
                    ++i;
                    Message = "Выполняется импорт нагрузки. Добавлено " + i + " из " + lines_count;
                    DoEvents();
                }
                //cnt.SaveChanges();
            }
        }