コード例 #1
0
ファイル: DbService.cs プロジェクト: pavelSimek/projektPO
 public static void StudyGroupSubjectDelete(StudyGroupSubjectModel model)
 {
     using (var db = OpenSqlConnection())
     {
         db.Query <StudyGroupSubjectModel>("dbo.ProcSubjectStudyGroupDelete", model, commandType: CommandType.StoredProcedure);
     }
 }
コード例 #2
0
        public static void GenerateEventsAfterPairing(StudyGroupSubjectModel model)
        {
            var subject    = DbService.Subject(model.SubjectID.Value);
            var studyGroup = DbService.StudyGroup(model.StudyGroupID.Value);

            DbService.StudyGroupSubjectDelete(
                new StudyGroupSubjectModel()
            {
                StudyGroupID = model.StudyGroupID,
                SubjectID    = model.SubjectID
            });

            double numberOfEvents    = Math.Ceiling(((double)studyGroup.NumberOfStudents / (double)subject.ClassSize));
            double studentsRemaining = studyGroup.NumberOfStudents;

            for (int i = 0; i < numberOfEvents; i++)
            {
                var finalStudentsNumber = Math.Ceiling(studentsRemaining / (numberOfEvents - i));
                studentsRemaining = studentsRemaining - finalStudentsNumber;

                if (subject.ExerciseHours > 0)
                {
                    var createdEvent = PrepareEvent(subject, Enums.ScheduleEventType.Exercise);
                    createdEvent.Hours            = subject.ExerciseHours;
                    createdEvent.NumberOfStudents = (int)finalStudentsNumber;
                    createdEvent.StudyGroupId     = model.StudyGroupID;
                    DbService.EventInsert(createdEvent);
                }
                if (subject.SeminarHours > 0)
                {
                    var createdEvent = PrepareEvent(subject, Enums.ScheduleEventType.Seminar);
                    createdEvent.Hours            = subject.SeminarHours;
                    createdEvent.NumberOfStudents = (int)finalStudentsNumber;
                    createdEvent.StudyGroupId     = model.StudyGroupID;
                    DbService.EventInsert(createdEvent);
                }
            }

            if (subject.LectureHours > 0)
            {
                var createdEvent = PrepareEvent(subject, Enums.ScheduleEventType.Lecture);
                createdEvent.Hours            = subject.LectureHours;
                createdEvent.NumberOfStudents = studyGroup.NumberOfStudents;
                createdEvent.StudyGroupId     = model.StudyGroupID;
                DbService.EventInsert(createdEvent);
            }
        }
コード例 #3
0
        private void bAdd_Click(object sender, EventArgs e)
        {
            var studyGroupIndex   = cbStudyGroup.SelectedIndex;
            var subjectIndex      = cbSubject.SelectedIndex;
            var studyGroupSubject = new StudyGroupSubjectModel()
            {
                SubjectID    = _subjects[subjectIndex].Id.Value,
                StudyGroupID = _studyGroups[studyGroupIndex].Id
            };
            var subjectExist = DbService.StudyGroupSubject(studyGroupSubject.StudyGroupID, studyGroupSubject.SubjectID);

            if (subjectExist.Count == 0)
            {
                EventGenerator.GenerateEventsAfterPairing(studyGroupSubject);
                DbService.StudyGroupSubjectInsert(studyGroupSubject);
            }
            CheckSubjects();
            this.Close();
        }