Esempio n. 1
0
        private void PlansGrid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var studentPlanPeriod = ((List <StudentLearningPlanWithPeriodsView>)PlansGrid.DataSource)[e.RowIndex];

            currentLearningPlan            = lpRepo.get(studentPlanPeriod.learning_plan_id);
            currentLearningPlanDisciplines = lpdRepo.learningPlanAll(currentLearningPlan.id);
            var discIdDict = currentLearningPlanDisciplines.ToDictionary(d => d.id, d => d.name);

            currentLearningPlanDisciplineSemesters = lpdsRepo.learningPlanAll(studentPlanPeriod.learning_plan_id);

            var semesters = currentLearningPlanDisciplineSemesters
                            .Select(lpds => lpds.semester)
                            .OrderBy(sn => sn)
                            .Distinct()
                            .ToList();
            var semesterSpans = semesters.ToDictionary(s => s, s => new Tuple <DateTime, DateTime>(
                                                           new DateTime(currentLearningPlan.starting_year + ((s % 2 == 0) ? 1 : 0) + (int)Math.Floor((double)(s - 1) / 2), (s % 2 == 0) ? 2 : 9, 1),
                                                           new DateTime(currentLearningPlan.starting_year + 1 + (int)Math.Floor((double)(s - 1) / 2), (s % 2 == 0) ? 8 : 1, 31)
                                                           ));

            var studentSemestersWithYear = new List <Tuple <int, int> >();
            var studentSemesters         = new List <int>();

            for (int i = 0; i < semesters.Count; i++)
            {
                var semester = semesters[i];
                if (studentPlanPeriod.from <= semesterSpans[semester].Item2 &&
                    semesterSpans[semester].Item1 <= studentPlanPeriod.to)
                {
                    studentSemesters.Add(semester);
                    studentSemestersWithYear.Add(
                        new Tuple <int, int>(currentLearningPlan.starting_year + (int)Math.Floor((double)(semester - 1) / 2),
                                             (semester % 2 == 1) ? 1 : 2));
                }
            }

            var studentDisciplineSemesters = currentLearningPlanDisciplineSemesters
                                             .Where(sm => studentSemesters.Contains(sm.semester))
                                             .ToList();

            dsViews = DisciplineSemesterView.FromLpdsList(studentDisciplineSemesters, discIdDict);

            var semesterIntList = dsViews
                                  .Select(dsv => dsv.semester)
                                  .Distinct()
                                  .OrderBy(s => s)
                                  .ToList();
            var semesterViews = IntegerView.FromIntegerList(semesterIntList);

            SemestersGrid.DataSource = semesterViews;
            SemestersGrid.Columns["value"].HeaderText = "Семестр";
            SemestersGrid.Columns["value"].Width      = SemestersGrid.Width - 20;
        }
Esempio n. 2
0
        private void PlansGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var studentPlanPeriod = ((List <StudentLearningPlanWithPeriodsView>)PlansGridView.DataSource)[e.RowIndex];

            currentLearningPlan            = lpRepo.get(studentPlanPeriod.learning_plan_id);
            currentLearningPlanDisciplines = lpdRepo.learningPlanAll(currentLearningPlan.id);
            var discIdDict = currentLearningPlanDisciplines.ToDictionary(d => d.id, d => d.name);

            currentLearningPlanDisciplineSemesters = lpdsRepo.learningPlanAll(studentPlanPeriod.learning_plan_id);

            var semesters = currentLearningPlanDisciplineSemesters
                            .Select(lpds => lpds.semester)
                            .OrderBy(sn => sn)
                            .Distinct()
                            .ToList();
            var semesterSpans = semesters.ToDictionary(s => s, s => new Tuple <DateTime, DateTime>(
                                                           new DateTime(currentLearningPlan.starting_year + ((s % 2 == 0) ? 1 : 0) + (int)Math.Floor((double)(s - 1) / 2), (s % 2 == 0) ? 2 : 9, 1),
                                                           new DateTime(currentLearningPlan.starting_year + 1 + (int)Math.Floor((double)(s - 1) / 2), (s % 2 == 0) ? 8 : 1, 31)
                                                           ));

            var studentSemestersWithYear = new List <Tuple <int, int> >();
            var studentSemesters         = new List <int>();

            for (int i = 0; i < semesters.Count; i++)
            {
                var semester = semesters[i];
                if (studentPlanPeriod.from <= semesterSpans[semester].Item2 &&
                    semesterSpans[semester].Item1 <= studentPlanPeriod.to)
                {
                    studentSemesters.Add(semester);
                    studentSemestersWithYear.Add(
                        new Tuple <int, int>(currentLearningPlan.starting_year + (int)Math.Floor((double)(semester - 1) / 2),
                                             (semester % 2 == 1) ? 1 : 2));
                }
            }

            var studentDisciplineSemesters = currentLearningPlanDisciplineSemesters
                                             .Where(sm => studentSemesters.Contains(sm.semester))
                                             .OrderBy(s => s.semester)
                                             .ThenBy(s => discIdDict[s.learning_plan_discipline_id])
                                             .ToList();
            var dsViews = DisciplineSemesterView.FromLpdsList(studentDisciplineSemesters, discIdDict);

            PlanGridView.DataSource = dsViews;
            FormatSemesterView();

            var studentCardItems = new List <TeacherCardAndItem>();

            for (int i = 0; i < studentSemestersWithYear.Count; i++)
            {
                var semesterStudentCardItems = tciRepo.yearSemesterStudentIdAll(
                    studentSemestersWithYear[i].Item1,
                    studentSemestersWithYear[i].Item2,
                    studentPlanPeriod.student_id);

                studentCardItems.AddRange(semesterStudentCardItems);
            }

            var teachersDict = tRepo.all().ToDictionary(t => t.id, t => t);

            for (int i = 0; i < studentCardItems.Count; i++)
            {
                studentCardItems[i].semester = studentCardItems[i].semester + (studentCardItems[i].starting_year - currentLearningPlan.starting_year) * 2;

                if (teachersDict.ContainsKey(studentCardItems[i].teacher_id))
                {
                    var teacher = teachersDict[studentCardItems[i].teacher_id];
                    studentCardItems[i].teacher_fio = teacher.f + " " + teacher.i + " " + teacher.o;
                }

                if (teachersDict.ContainsKey(studentCardItems[i].real_teacher_id))
                {
                    var realTeacher = teachersDict[studentCardItems[i].real_teacher_id];
                    studentCardItems[i].real_teacher_fio = realTeacher.f + " " + realTeacher.i + " " + realTeacher.o;
                }
            }

            studentCardItems = studentCardItems
                               .OrderBy(i => i.semester)
                               .ThenBy(i => i.discipline_name)
                               .ToList();

            CardsGridView.DataSource = studentCardItems;

            FormatCardsView();

            var eprst = 999;
        }