/// <summary> /// Create a new EduPeriod object. /// </summary> /// <param name="begin">Initial value of the Begin property.</param> /// <param name="end">Initial value of the End property.</param> /// <param name="id">Initial value of the Id property.</param> /// <param name="groupId">Initial value of the GroupId property.</param> public static EduPeriod CreateEduPeriod(global::System.DateTime begin, global::System.DateTime end, global::System.Int32 id, global::System.Int32 groupId) { EduPeriod eduPeriod = new EduPeriod(); eduPeriod.Begin = begin; eduPeriod.End = end; eduPeriod.Id = id; eduPeriod.GroupId = groupId; return eduPeriod; }
/// <summary> /// Deprecated Method for adding a new object to the EduPeriods EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToEduPeriods(EduPeriod eduPeriod) { base.AddObject("EduPeriods", eduPeriod); }
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(); } }