예제 #1
0
        private CustomEventMonth AddEvent(CustomEvent evnt, ref CustomEventMonth month, ref CustomEventWeek week)
        {
            CustomEventMonth retMonth = null;

            var curDate  = evnt.StartDateTime;
            var newMonth = false;

            if (month == null || month.MonthNumber != curDate.Month)
            {
                // New month
                month = new CustomEventMonth(curDate.Month);
                //months.Add(month);
                retMonth = month;
                newMonth = true;
            }

            if (week == null || newMonth || curDate.GetWeekNumberOfYear() != week.WeekNumber)
            {
                // New week
                var weekNr = curDate.GetWeekNumberOfYear();
                week = new CustomEventWeek(weekNr, 1);

                month.Weeks.Add(week);
            }
            week.events.Add(evnt);
            return(retMonth);
        }
예제 #2
0
        public List <CustomEventMonth> GetEventsWithUser(StudentUser user, bool includeBeforeToday)
        {
            var months             = new List <CustomEventMonth>();
            CustomEventMonth month = null;
            CustomEventWeek  week  = null;
            var addedIDs           = new HashSet <long>();

            foreach (var evnt in AllEvents)
            {
                if (!addedIDs.Contains(evnt.ID) && (user.Course == SchoolCourses.VisAlt ||
                                                    (evnt.Courses.Contains(user.Course) && evnt.IsYear(user.ClassYear))))
                {
                    // Skip event if event if before today
                    if (includeBeforeToday == false && evnt.StartDateTime < DateTime.Today)
                    {
                        continue;
                    }

                    var m = AddEvent(evnt, ref month, ref week);
                    if (m != null)
                    {
                        months.Add(m);
                        addedIDs.Add(evnt.ID);
                    }
                }
            }
            return(months);
        }
예제 #3
0
        public List <CustomEventMonth> GetEventsWithName(StudentUser user)
        {
            var months             = new List <CustomEventMonth>();
            CustomEventMonth month = null;
            CustomEventWeek  week  = null;

            foreach (var evnt in AllEvents)
            {
                if (user.Course == SchoolCourses.VisAlt ||
                    (evnt.Courses.Contains(user.Course) && evnt.IsYear(user.ClassYear)))
                {
                    var m = AddEvent(evnt, ref month, ref week);
                    if (m != null)
                    {
                        months.Add(m);
                    }
                }
            }
            return(months);
        }
예제 #4
0
        public List <CustomEventMonth> GetEventsWithName(StudentUser user, string tags, bool lecture, bool assignment,
                                                         bool exam, bool includeBeforeToday)
        {
            var months             = new List <CustomEventMonth>();
            CustomEventMonth month = null;
            CustomEventWeek  week  = null;

            var temp = "";

            string[] array = null;
            if (!string.IsNullOrEmpty(tags))
            {
                temp  = FilterCharacters(tags).ToLower();
                array = temp.Split(' ');
            }

            foreach (var evnt in AllEvents)
            {
                if (user.Course == SchoolCourses.VisAlt ||
                    (evnt.Courses.Contains(user.Course) && evnt.IsYear(user.ClassYear)))
                {
                    if ((lecture && evnt.MainEventType == MainEventType.Forelesning) ||
                        (assignment && evnt.MainEventType == MainEventType.Innlevering) ||
                        (exam && evnt.MainEventType == MainEventType.Eksamen))
                    {
                        if (!string.IsNullOrEmpty(tags))
                        {
                            string[] eventInfo =
                            {
                                evnt.Subject.Name,                 evnt.RoomName,                                       evnt.Teacher, evnt.Comment, evnt.Subject.Code, evnt.eventType.ToString(),
                                evnt.StartDateTime.Day.ToString(), evnt.StartDateTime.GetWeekNumberOfYear().ToString(), evnt.GetMonthName()
                            };

                            var flagged = false;
                            for (var j = 0; j < array.Length; j++)
                            {
                                var empty = 0;
                                for (var k = 0; k < eventInfo.Length; k++)
                                {
                                    if (!eventInfo[k].Contains(array[j], StringComparison.OrdinalIgnoreCase))
                                    {
                                        empty++;
                                    }
                                }
                                if (empty == eventInfo.Length)
                                {
                                    flagged = true;
                                    break;
                                }
                            }
                            if (flagged)
                            {
                                continue;
                            }
                        }

                        // Skip event if event if before today
                        if (includeBeforeToday == false && evnt.StartDateTime < DateTime.Today)
                        {
                            continue;
                        }

                        var m = AddEvent(evnt, ref month, ref week);
                        if (m != null)
                        {
                            months.Add(m);
                        }
                    }
                }
            }
            return(months);
        }