Beispiel #1
0
        private void addFromGroup_Click(object sender, EventArgs e)
        {
            var groupToAdd = _repo.StudentGroups.GetStudentGroup((int)groupsList.SelectedValue);

            var studentsToAdd = _repo
                .StudentsInGroups
                .GetFiltredStudentsInGroups(sig => sig.StudentGroup.StudentGroupId == groupToAdd.StudentGroupId)
                .Select(sig => sig.Student)
                .Where(st => st.Expelled == false);

            if (StudentGroupListView.SelectedCells.Count > 0)
            {
                var studentGroup = ((List<StudentGroup>)StudentGroupListView.DataSource)[StudentGroupListView.SelectedCells[0].RowIndex];

                foreach (var studentToAdd in studentsToAdd)
                {
                    var sig = new StudentsInGroups { Student = studentToAdd, StudentGroup = studentGroup };
                    _repo.StudentsInGroups.AddStudentsInGroups(sig);
                }

                RefreshView((int)RefreshType.StudentsOnly);
            }
            else
            {
                MessageBox.Show("Ни одна группа не выделена.");
            }
        }
Beispiel #2
0
        private void SaveClick(object sender, EventArgs e)
        {
            if (_mode == StudentDetailsMode.New)
            {
                var s = new Student
                {
                    Address = AddressBox.Text,
                    BirthDate = BirthDateBox.Value,
                    Expelled = ExpelledBox.Checked,
                    F = FamilyBox.Text,
                    I = NameBox.Text,
                    NFactor = FromSchoolBox.Checked,
                    O = PatronymicBox.Text,
                    Orders = OrdersBox.Text,
                    PaidEdu = PaidLearningBox.Checked,
                    Phone = PhoneBox.Text,
                    Starosta = StarostaBox.Checked,
                    ZachNumber = IdNumBox.Text
                };

                _repo.Students.AddStudent(s);

                var group = _repo.StudentGroups.FindStudentGroup(StudentGroupBox.Text);
                if (group != null)
                {
                    var sig = new StudentsInGroups(s, group);
                    _repo.StudentsInGroups.AddStudentsInGroups(sig);
                }

                _studentList.UpdateSearchBoxItems();
                DialogResult = DialogResult.OK;
                Close();
            }

            if (_mode == StudentDetailsMode.Edit)
            {
                var s = _repo.Students.GetStudent(_student.StudentId);

                s.Address = AddressBox.Text;
                s.BirthDate = BirthDateBox.Value;
                s.Expelled = ExpelledBox.Checked;
                s.F = FamilyBox.Text;
                s.I = NameBox.Text;
                s.NFactor = FromSchoolBox.Checked;
                s.O = PatronymicBox.Text;
                s.Orders = OrdersBox.Text;
                s.PaidEdu = PaidLearningBox.Checked;
                s.Phone = PhoneBox.Text;
                s.Starosta = StarostaBox.Checked;
                s.ZachNumber = IdNumBox.Text;

                _repo.Students.UpdateStudent(s);

                _studentList.UpdateSearchBoxItems();
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Beispiel #3
0
        private void addStudentToGroup_Click(object sender, EventArgs e)
        {
            if (StudentList.SelectedValue == null)
            {
                return;
            }

            var studentToAdd = _repo.Students.GetStudent((int)StudentList.SelectedValue);

            if (StudentGroupListView.SelectedCells.Count > 0)
            {
                var studentGroup = ((List<StudentGroup>)StudentGroupListView.DataSource)[StudentGroupListView.SelectedCells[0].RowIndex];

                var sig = new StudentsInGroups { Student = studentToAdd, StudentGroup = studentGroup };

                _repo.StudentsInGroups.AddStudentsInGroups(sig);

                RefreshView((int)RefreshType.StudentsOnly);
            }
            else
            {
                MessageBox.Show("Ни одна группа не выделена.");
            }
        }
Beispiel #4
0
        private void ImportStudentData(string filename)
        {
            var studentList = new List<Student>();
            var studentGroups = new List<StudentGroup>();
            var studentsInGroups = new List<StudentsInGroups>();

            var sr = new StreamReader(filename);

            string line;

            var maxStudentId = _repo
                .GetAllStudents()
                .Select(s => s.StudentId)
                .Max();
            maxStudentId++;

            var StudentIdRemap = new Dictionary<int, int>();

            sr.ReadLine();
            while ((line = sr.ReadLine()) != "StudentGroups")
            {
                var studentParts = line.Split('@');
                var student = new Student() {
                    StudentId = maxStudentId,
                    F = studentParts[1],
                    I = studentParts[2],
                    O = studentParts[3],
                    Address = "",
                    BirthDate = new DateTime(2000,1,1),
                    Expelled = false,
                    NFactor = false,
                    Orders = "",
                    PaidEdu = false,
                    Phone = "",
                    Starosta = false,
                    ZachNumber = ""
                };

                StudentIdRemap.Add(int.Parse(studentParts[0]), maxStudentId);

                studentList.Add(student);

                _repo.AddStudent(student);

                maxStudentId++;
            }

            StudentGroup group = null;
            var maxGroupId = _repo
                .GetAllStudentGroups()
                .Select(s => s.StudentGroupId)
                .Max();
            maxGroupId++;

            var groupIdRemap = new Dictionary<int, int>();
            while ((line = sr.ReadLine()) != "StudentsInGroups")
            {
                var groupParts = line.Split('@');

                if (!_repo.GetFiltredStudentGroups(sg => sg.Name == groupParts[1]).Any())
                {
                    group = new StudentGroup()
                    {
                        StudentGroupId = maxGroupId,
                        Name = groupParts[1]
                    };

                    groupIdRemap.Add(int.Parse(groupParts[0]), maxGroupId);

                    studentGroups.Add(group);

                    _repo.AddStudentGroup(group);

                    maxGroupId++;
                }
                else
                {
                    var gr = _repo.GetFirstFiltredStudentGroups(sg => sg.Name == groupParts[1]);
                    studentGroups.Add(gr);

                    groupIdRemap.Add(int.Parse(groupParts[0]), gr.StudentGroupId);
                }
            }

            while ((line = sr.ReadLine()) != null)
            {
                var sigParts = line.Split('@');

                var studentId = int.Parse(sigParts[0]);
                studentId = StudentIdRemap[studentId];

                var studentGroupId = int.Parse(sigParts[1]);
                if (groupIdRemap.ContainsKey(studentGroupId))
                {
                    studentGroupId = groupIdRemap[studentGroupId];
                }
                else
                {
                    studentGroupId = _repo.GetFirstFiltredStudentGroups( sg => sg.Name ==
                        studentGroups.FirstOrDefault(stg => stg.StudentGroupId == studentGroupId).Name).StudentGroupId;
                }

                var sig = new StudentsInGroups()
                {
                    Student = _repo.GetStudent(studentId),
                    StudentGroup = _repo.GetStudentGroup(studentGroupId)
                };

                studentsInGroups.Add(sig);

                _repo.AddStudentsInGroups(sig);
            }

            sr.Close();
        }
        public StudentsInGroups AddStudentsInGroups(StudentsInGroups studentsInGroups)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                studentsInGroups.StudentsInGroupsId = 0;

                studentsInGroups.Student = context.Students.FirstOrDefault(s => s.StudentId == studentsInGroups.Student.StudentId);
                studentsInGroups.StudentGroup = context.StudentGroups.FirstOrDefault(sg => sg.StudentGroupId == studentsInGroups.StudentGroup.StudentGroupId);

                context.StudentsInGroups.Add(studentsInGroups);
                context.SaveChanges();

                return studentsInGroups;
            }
        }
        public void UpdateStudentsInGroups(StudentsInGroups studentsInGroups)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                var curStudentsInGroups = context.StudentsInGroups.FirstOrDefault(sig => sig.StudentsInGroupsId == studentsInGroups.StudentsInGroupsId);

                curStudentsInGroups.Student = context.Students.FirstOrDefault(s => s.StudentId == studentsInGroups.Student.StudentId);
                curStudentsInGroups.StudentGroup = context.StudentGroups.FirstOrDefault(sg => sg.StudentGroupId == studentsInGroups.StudentGroup.StudentGroupId);

                context.SaveChanges();
            }
        }
Beispiel #7
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);
        }
 public MySQLStudentsInGroups(StudentsInGroups sig)
 {
     StudentsInGroupsId = sig.StudentsInGroupsId;
     StudentId = sig.Student.StudentId;
     StudentGroupId = sig.StudentGroup.StudentGroupId;
 }