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(); } }
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); } }
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(); } }
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); } }
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(); } }
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(); } }
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(); } }