Пример #1
0
        public DateBoundTimeRanges RemoveTimeRange(TimeRange timeRange)
        {
            var timeRangesTemp = TimeRanges.ToList();

            for (var i = 0; i < timeRangesTemp.Count; i++)
            {
                var storedTimeRange = timeRangesTemp[i];
                if (storedTimeRange.Equals(timeRange))
                {
                    timeRangesTemp.RemoveAt(i);
                    i--;
                }
                else if (TimeRangeSplitsStoredTimeRange(timeRange, storedTimeRange))
                {
                    var newTimeRangeLower = new TimeRange(storedTimeRange.StartTime, timeRange.StartTime - storedTimeRange.StartTime);
                    var newTimeRangeUpper = new TimeRange(timeRange.EndTime, storedTimeRange.EndTime - timeRange.EndTime);
                    timeRangesTemp.RemoveAt(i);
                    timeRangesTemp.AddRange(new[] { newTimeRangeUpper, newTimeRangeLower });
                    break;
                }
                else if (TimeRangeCutsStartOfStoredTimeRange(timeRange, storedTimeRange))
                {
                    // storedTimeRange.StartTime = timeRange.EndTime;
                    var newTimeRange = new TimeRange(timeRange.EndTime, storedTimeRange.Duration);
                    timeRangesTemp[i] = newTimeRange;
                }
                else if (TimeRangeCutsEndOfStoredTimeRange(timeRange, storedTimeRange))
                {
                    storedTimeRange.Duration -= storedTimeRange.EndTime - timeRange.StartTime;
                    timeRangesTemp[i]         = storedTimeRange;
                }
            }
            TimeRanges = timeRangesTemp;
            return(this);
        }
Пример #2
0
        public DateBoundTimeRanges Clear()
        {
            var timeRangesTemp = TimeRanges.ToList();

            timeRangesTemp.Clear();
            TimeRanges = timeRangesTemp;
            return(this);
        }
Пример #3
0
        public DateBoundTimeRanges AddTimeRange(TimeRange newTimeRange)
        {
            ValidateTimeRange(newTimeRange);
            var timeRangesTemp = TimeRanges.ToList();

            if (CheckIfTimeRangeToAddFitsWithinAnyStoredTimeRange(newTimeRange, timeRangesTemp))
            {
                return(this);
            }

            if (timeRangesTemp.Count != 0)
            {
                newTimeRange = MergePotentialOverlaps(newTimeRange, timeRangesTemp);
            }

            timeRangesTemp.Add(newTimeRange);
            TimeRanges = timeRangesTemp;
            return(this);
        }
Пример #4
0
        /// <summary>
        /// Az adott időintervallumot kiveszi a listából.
        /// </summary>
        public void RemoveTimeRange(TimeRange timeRange)
        {
            ReloadData();

            if (TimeUnit == TimeUnit.Infinity)
            {
                foreach (var tr in TimeRanges.ToList())
                {
                    RemoveTimeRangeFromList(tr);
                }
            }
            else
            {
                var tcTimeRange = newTaskControl_TimeRange(timeRange.DateTimeStart, timeRange.DurationCount);
                //1. megnézem, van e olyan intervallum, amit a törlendő időszak kezdetével összeér. Ha van ilyen, kettébontom 2 időszakra.

                var startIntersecting = TimeRanges
                                        .Where(x => x.DateTimeStart <= tcTimeRange.DateTimeStart && x.EndOfTimeRange(TimeUnit) >= tcTimeRange.DateTimeStart)
                                        .FirstOrDefault();
                SplitInList(startIntersecting, tcTimeRange.DateTimeStart);
                //2. megnézem, van e olyan intervallum, amit a törlendő időszak végével összeér. Ha van ilyen, kettébontom 2 időszakra.
                var entIntersecting = TimeRanges
                                      .Where(x => x.DateTimeStart <= tcTimeRange.EndOfTimeRange(TimeUnit) && x.EndOfTimeRange(TimeUnit) >= tcTimeRange.EndOfTimeRange(TimeUnit))
                                      .FirstOrDefault();
                SplitInList(entIntersecting, tcTimeRange.EndOfTimeRange(TimeUnit));

                //3. kitörlöm az összes intervallumot, amit teljesen befed a törlendő intervallum.
                var toDelete = TimeRanges
                               .Where(x => x.DateTimeStart >= tcTimeRange.DateTimeStart && x.EndOfTimeRange(TimeUnit) <= tcTimeRange.EndOfTimeRange(TimeUnit))
                               .ToList();
                foreach (var tr in toDelete)
                {
                    RemoveTimeRangeFromList(tr);
                }
            }
            //Az új időintervallumot felveszem a listába
            SaveChanges();
        }