예제 #1
0
        private ExamEntity specialArrange(CourseEntity course, SpecialEntity special, TimeValueInterval timeData, List <SessionEntity> remainSessions, List <SpecialEntity> specialsOfThisCourse)
        {
            int        sessionCt    = remainSessions.Count;
            int        sessionIndex = 0;
            RoomEntity room         = null;

            foreach (RoomEntity r in allRoom)
            {
                if (special.roomId > 0)
                {
                    if (r.roomId == special.roomId)
                    {
                        room = r;
                        break;
                    }
                }
                else
                {
                    if (r.roomType == course.requiredRoomType && getConflictTimeData(r.occupied, timeData) == null)
                    {
                        room = r;
                        foreach (SpecialEntity sot in specialsOfThisCourse)
                        {
                            if (sot.roomId <= 0)
                            {
                                continue;
                            }
                            if (r.roomId == sot.roomId)
                            {
                                room = null;
                                break;
                            }
                        }

                        if (room != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (room == null)
            {
                return(null);
            }

            bool       hasSpecialProtor = special.protorId > 0;
            ExamEntity exam             = new ExamEntity();

            exam.courseId    = special.courseId;
            exam.roomId      = special.roomId;
            exam.roomType    = room.roomType;
            exam.startMinute = TimeValueInterval.value2Min(timeData.startValue);
            exam.startHour   = TimeValueInterval.value2Hour(timeData.startValue);
            exam.weekDay     = TimeValueInterval.value2Weekday(timeData.startValue);

            exam.endMinute = TimeValueInterval.value2Min(timeData.endValue);
            exam.endHour   = TimeValueInterval.value2Hour(timeData.endValue);

            int sessionsThisRoom = room.roomCapacity / SESSION_CAPACITY;

            if (special.sessionId > 0)
            {
                SessionEntity target = null;
                foreach (SessionEntity s in remainSessions)
                {
                    if (s.sessionId == special.sessionId)
                    {
                        target = s;
                        break;
                    }
                }

                if (target != null)
                {
                    exam.sessionIds.Add(target);
                    remainSessions.Remove(target);
                }
                --sessionsThisRoom;
            }

            for (int i = 0; i < sessionsThisRoom; ++sessionIndex)
            {
                if (sessionIndex >= remainSessions.Count)
                {
                    break;
                }

                bool sessionInSpecial = false;
                foreach (SpecialEntity e in specialsOfThisCourse)
                {
                    if (e.courseId == course.courseId && e.roomId != room.roomId && e.sessionId == remainSessions[sessionIndex].sessionId)
                    {
                        sessionInSpecial = true;
                        break;
                    }
                }

                if (!sessionInSpecial)
                {
                    exam.sessionIds.Add(remainSessions[sessionIndex]);
                    ++i;
                }
            }

            remainSessions.RemoveRange(0, sessionIndex);

            if (hasSpecialProtor)
            {
                exam.protorId = special.protorId;
                ProtorEntity pe = null;
                foreach (ProtorEntity p in allProtor)
                {
                    if (p.protorId == special.protorId)
                    {
                        pe = p;
                        break;
                    }
                }

                if (pe != null)
                {
                    pe.arrangeExam(timeData);
                }
            }
            else
            {
                ProtorEntity sessionFaculty = null;
                foreach (SessionEntity ss in exam.sessionIds)
                {
                    foreach (ProtorEntity pe in allProtor)
                    {
                        if (ss.facultyId == pe.protorId)
                        {
                            sessionFaculty = pe;
                            break;
                        }
                    }

                    if (sessionFaculty != null)
                    {
                        if (getConflictTimeData(sessionFaculty.occupied, timeData) == null)
                        {
                            break;
                        }
                        else
                        {
                            sessionFaculty = null;
                        }
                    }
                }

                if (sessionFaculty != null)
                {
                    exam.protorId = sessionFaculty.protorId;
                    sessionFaculty.arrangeExam(timeData);
                }
                else
                {
                    foreach (ProtorEntity pe in allProtor)
                    {
                        sessionFaculty = pe;
                        foreach (SpecialEntity e in specialsOfThisCourse)
                        {
                            if (sessionFaculty.protorId == e.protorId)
                            {
                                sessionFaculty = null;
                                break;
                            }
                        }

                        if (sessionFaculty == null)
                        {
                            continue;
                        }

                        if (getConflictTimeData(sessionFaculty.occupied, timeData) == null && sessionFaculty.protorId != special.protorId)
                        {
                            exam.protorId = sessionFaculty.protorId;
                            sessionFaculty.arrangeExam(timeData);
                            break;
                        }
                    }
                }
            }

            room.arrangeExam(timeData);

            // Jane: added null check 20180426 if (allLevelTimeLine[ce.level] != null)
            if (allLevelTimeLine[course.level] != null)
            {
                allLevelTimeLine[course.level].Add(timeData);
            }

            return(exam);
        }
예제 #2
0
        private void getProtorRoomAndSpecial()
        {
            allProtor.Clear();
            allRoom.Clear();
            allSpecial.Clear();

            foreach (faculty f in context.faculties)
            {
                if (f.is_deleted == false)
                {
                    allProtor.Add(new ProtorEntity(f.id));
                }
            }

            foreach (room r in context.rooms)
            {
                if (r.room_type_id != null && r.capacity != null && r.is_deleted == false)
                {
                    allRoom.Add(new RoomEntity(r.id, r.room_type_id ?? 0, r.capacity ?? 0));
                }
            }

            foreach (special_arrangement s in context.special_arrangement)
            {
                SpecialEntity se = new SpecialEntity(s.course_code, s.room, s.section_number ?? 0, s.proctor, s.weekday, s.time, s.exam_length);
                if (se.timeData.isValid()) // special arrangement is valid only time is set
                {
                    allSpecial.Add(se);
                }
            }

            sortSessionsByRoom();

            foreach (CourseEntity ce in allExamCourse)
            {
                if (ce.sessionIds == null || ce.sessionIds.Count <= 0)
                {
                    continue;
                }

                int startValue = ce.sessionIds[0].startValue;
                if (startValue <= 0)
                {
                    continue;
                }

                int seCt = ce.sessionIds.Count;
                for (int i = 0; i < seCt;)
                {
                    SessionEntity si = ce.sessionIds[i];
                    SpecialEntity ss = new SpecialEntity(ce.courseId, si.requiredRoom, si.sessionId, -1, startValue, ce.duration);
                    if (ss.timeData.isValid()) // special arrangement is valid only time is set
                    {
                        allSpecial.Add(ss);
                    }

                    int j = i + 1;
                    for (; j < seCt; ++j)
                    {
                        SessionEntity sj = ce.sessionIds[j];
                        if (si.requiredRoom == sj.requiredRoom && sj.startValue == startValue)
                        {
                            continue;
                        }

                        if (sj.startValue != startValue && si.requiredRoom == sj.requiredRoom)
                        {
                            continue;
                        }

                        break;
                    }

                    i = j;
                }
            }

            sortSessionsByProtor();

            allSpecial.Sort(
                delegate(SpecialEntity s1, SpecialEntity s2)
            {
                return(s1.courseId - s2.courseId);
            });
        }