Esempio n. 1
0
        private void addGroupToFaculty_Click(object sender, EventArgs e)
        {
            if (GroupList.SelectedValue == null)
            {
                return;
            }

            var groupToAdd = _repo.StudentGroups.GetStudentGroup((int)GroupList.SelectedValue);

            if (FacultiesListView.SelectedCells.Count > 0)
            {
                var faculty = ((List<Faculty>)FacultiesListView.DataSource)[FacultiesListView.SelectedCells[0].RowIndex];

                var gif = new GroupsInFaculty { StudentGroup = groupToAdd, Faculty = faculty };

                _repo.GroupsInFaculties.AddGroupsInFaculty(gif);

                RefreshView(RefreshType.GroupsOnly);
            }
            else
            {
                MessageBox.Show("Не выбран факультет.");
            }
        }
        public GroupsInFaculty AddGroupsInFaculty(GroupsInFaculty groupsInFaculty)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                groupsInFaculty.GroupsInFacultyId = 0;

                groupsInFaculty.StudentGroup = context.StudentGroups.FirstOrDefault(gif => gif.StudentGroupId == groupsInFaculty.StudentGroup.StudentGroupId);
                groupsInFaculty.Faculty = context.Faculties.FirstOrDefault(gif => gif.FacultyId == groupsInFaculty.Faculty.FacultyId);

                context.GroupsInFaculties.Add(groupsInFaculty);
                context.SaveChanges();

                return groupsInFaculty;
            }
        }
        public void UpdateGroupsInFaculty(GroupsInFaculty groupsInFaculty)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                var curGroupsInFaculty = context.GroupsInFaculties.FirstOrDefault(gif => gif.GroupsInFacultyId == groupsInFaculty.GroupsInFacultyId);

                curGroupsInFaculty.StudentGroup = groupsInFaculty.StudentGroup;
                curGroupsInFaculty.Faculty = groupsInFaculty.Faculty;

                context.SaveChanges();
            }
        }
Esempio n. 4
0
 public MySqlGroupsInFaculty(GroupsInFaculty gif)
 {
     GroupsInFacultyId = gif.GroupsInFacultyId;
     StudentGroupId = gif.StudentGroup.StudentGroupId;
     FacultyId = gif.Faculty.FacultyId;
 }
Esempio n. 5
0
        private void CopyDBEssentials(string dbFromName, string dbToName)
        {
            var repoFrom =
                new ScheduleRepository("data source=tcp:" + StartupForm.CurrentServerName + ",1433;Database=" +
                                       dbFromName + "; Integrated Security=SSPI;multipleactiveresultsets=True");
            var repoTo =
                new ScheduleRepository("data source=tcp:" + StartupForm.CurrentServerName + ",1433;Database=" + dbToName +
                                       "; Integrated Security=SSPI;multipleactiveresultsets=True");

            Dictionary<int, int> studentsDic = new Dictionary<int, int>();
            var students = repoFrom.Students.GetAllStudents();
            foreach (var student in students)
            {
                var prevKey = student.StudentId;
                repoTo.Students.AddStudent(student);
                studentsDic.Add(prevKey, student.StudentId);
            }


            Dictionary<int, int> studentGroupsDic = new Dictionary<int, int>();
            var studentGroups = repoFrom.StudentGroups.GetAllStudentGroups();
            foreach (var studentGroup in studentGroups)
            {
                var prevKey = studentGroup.StudentGroupId;
                repoTo.StudentGroups.AddStudentGroup(studentGroup);
                studentGroupsDic.Add(prevKey, studentGroup.StudentGroupId);
            }

            var studentInGroups = repoFrom.StudentsInGroups.GetAllStudentsInGroups();
            foreach (var studentInGroup in studentInGroups)
            {
                var s = repoTo.Students.GetStudent(studentsDic[studentInGroup.Student.StudentId]);
                var sg =
                    repoTo.StudentGroups.GetStudentGroup(studentGroupsDic[studentInGroup.StudentGroup.StudentGroupId]);

                var sig = new StudentsInGroups(s, sg);

                repoTo.StudentsInGroups.AddStudentsInGroups(sig);
            }


            Dictionary<int, int> facultyDic = new Dictionary<int, int>();
            var faculties = repoFrom.Faculties.GetAllFaculties();
            foreach (var faculty in faculties)
            {
                var prevKey = faculty.FacultyId;
                repoTo.Faculties.AddFaculty(faculty);
                facultyDic.Add(prevKey, faculty.FacultyId);
            }

            var groupInFaculties = repoFrom.GroupsInFaculties.GetAllGroupsInFaculty();
            foreach (var groupInFaculty in groupInFaculties)
            {
                var f = repoTo.Faculties.GetFaculty(facultyDic[groupInFaculty.Faculty.FacultyId]);
                var sg =
                    repoTo.StudentGroups.GetStudentGroup(studentGroupsDic[groupInFaculty.StudentGroup.StudentGroupId]);

                var gif = new GroupsInFaculty(sg, f);

                repoTo.GroupsInFaculties.AddGroupsInFaculty(gif);
            }

            Dictionary<int, int> buildingDic = new Dictionary<int, int>();
            var buildings = repoFrom.Buildings.GetAllBuildings();
            foreach (var building in buildings)
            {
                var prevKey = building.BuildingId;
                repoTo.Buildings.AddBuilding(building);
                buildingDic.Add(prevKey, building.BuildingId);
            }

            Dictionary<int, int> audDic = new Dictionary<int, int>();
            var auditoria = repoFrom.Auditoriums.GetAll();
            foreach (var auditorium in auditoria)
            {
                var prevKey = auditorium.AuditoriumId;
                repoTo.Auditoriums.Add(auditorium);
                audDic.Add(prevKey, auditorium.AuditoriumId);
            }

            var options = repoFrom.ConfigOptions.GetAll();
            repoTo.ConfigOptions.AddConfigOptionRange(options);
        }