/// <summary>
 /// Deprecated Method for adding a new object to the AcademicLoadSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAcademicLoadSet(AcademicLoad academicLoad)
 {
     base.AddObject("AcademicLoadSet", academicLoad);
 }
 /// <summary>
 /// Create a new AcademicLoad object.
 /// </summary>
 /// <param name="employeId">Initial value of the EmployeId property.</param>
 /// <param name="regulatoryActionId">Initial value of the RegulatoryActionId property.</param>
 public static AcademicLoad CreateAcademicLoad(global::System.Int32 employeId, global::System.Int32 regulatoryActionId)
 {
     AcademicLoad academicLoad = new AcademicLoad();
     academicLoad.EmployeId = employeId;
     academicLoad.RegulatoryActionId = regulatoryActionId;
     return academicLoad;
 }
예제 #3
0
        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();
            }
        }