예제 #1
0
        /// <summary>
        /// Calculate the end period from startPeriodId and duration (minutes)
        /// </summary>
        /// <param name="startPeriod"></param>
        /// <param name="duration"></param>
        /// <returns>end period Id. returns -1 if there is no valid end period</returns>
        static public int CalcEndPeriod(int startPeriodId, int duration)
        {
            PERIOD_TIMERANGE startPeriod = DataProvider.Ins.DB.PERIOD_TIMERANGE.Find(startPeriodId);
            int startMinute = (int)Math.Round(startPeriod.StartTime.TotalMinutes);
            int endMinute   = startMinute + duration;

            int bestEndMinute = int.MaxValue;
            int bestPeriodId  = -1;

            foreach (var period in DataProvider.Ins.DB.PERIOD_TIMERANGE)
            {
                int endPeriodMinute = (int)Math.Round(CalcEndTime(period).TotalMinutes);

                // firstly, the period must end after the end of the duration
                if (endPeriodMinute >= endMinute)
                {
                    if (endPeriodMinute < bestEndMinute)
                    {
                        bestEndMinute = endPeriodMinute;
                        bestPeriodId  = period.PeriodID;
                    }
                }
            }

            return(bestPeriodId);
        }
예제 #2
0
        /// <summary>
        /// calculate the duration from startPeriod to endPeriod in Minute
        /// </summary>
        /// <param name="startPeriodId"></param>
        /// <param name="endPeriodId"></param>
        /// <returns></returns>
        static public int CalcDuration(int startPeriodId, int endPeriodId)
        {
            PERIOD_TIMERANGE startPeriod = DataProvider.Ins.DB.PERIOD_TIMERANGE.Find(startPeriodId);

            int startMinute = (int)Math.Round(startPeriod.StartTime.TotalMinutes);
            int endMinute   = (int)Math.Round(CalcEndTime(endPeriodId).TotalMinutes);

            return(endMinute - startMinute);
        }
예제 #3
0
 bool IsExistRoomRow(ROOM rm, PERIOD_TIMERANGE period)
 {
     foreach (var roomTableRow in listRoomTableRow)
     {
         if (roomTableRow.room.RoomID == rm.RoomID && roomTableRow.period.PeriodID == period.PeriodID)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #4
0
 static public TimeSpan CalcEndTime(PERIOD_TIMERANGE period)
 {
     return(period.StartTime + period.Duration);
 }
예제 #5
0
        static public TimeSpan CalcEndTime(int periodId)
        {
            PERIOD_TIMERANGE period = DataProvider.Ins.DB.PERIOD_TIMERANGE.Find(periodId);

            return(CalcEndTime(period));
        }