示例#1
0
        private static void CalculateDayTotal(DateTime currentWeekStart, WeekItemInfo item, TimeTrackingBlock[] userBlocks)
        {
            DateTime currentWeekEnd = currentWeekStart.AddDays(7);

            foreach (TimeTrackingBlock block in userBlocks)
            {
                // Process if block.StartDate IN [currentWeekStart, currentWeekStart)
                if (block.StartDate < currentWeekStart)
                {
                    continue;
                }
                if (block.StartDate >= currentWeekEnd)
                {
                    continue;
                }

                item.Day1 += block.Day1;
                item.Day2 += block.Day2;
                item.Day3 += block.Day3;
                item.Day4 += block.Day4;
                item.Day5 += block.Day5;
                item.Day6 += block.Day6;
                item.Day7 += block.Day7;
            }
        }
示例#2
0
        /// <summary>
        /// Gets the week items for user.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public static WeekItemInfo[] GetWeekItemsForUser(DateTime from, DateTime to, int userId)
        {
            List <WeekItemInfo> retVal = new List <WeekItemInfo>();

            // Load User TT blocks
            TimeTrackingBlock[] userBlocks = TimeTrackingBlock.List(FilterElement.EqualElement("OwnerId", userId),
                                                                    new IntervalFilterElement("StartDate", from, to));

            // Sort Block By Start Date
            Array.Sort <TimeTrackingBlock>(userBlocks, CompareTimeTrackingBlockByStartDate);

            // Create Week Item Info list
            DateTime currentWeekStart = GetRealWeekStart(from);

            // TODO: Current
            while (currentWeekStart < to)
            {
                // Calculate aggregated status of all blocks
                WeekItemStatus status = CalculateWeekStatusByBlocks(currentWeekStart, userBlocks);

                WeekItemInfo item = new WeekItemInfo(currentWeekStart,
                                                     Iso8601WeekNumber.GetWeekNumber(currentWeekStart.AddDays(3)),
                                                     status);

                CalculateDayTotal(currentWeekStart, item, userBlocks);

                retVal.Add(item);

                // Go to next week
                currentWeekStart = currentWeekStart.AddDays(7);
            }

            return(retVal.ToArray());
        }