Beispiel #1
0
        /// <summary>
        /// Get intersection of two TimeWindow.
        /// </summary>
        /// <param name="first">First timewindow.</param>
        /// <param name="second">Second timewindow.</param>
        /// <returns>If they intersects - return intersection
        /// timewindow, otherwise - return 'null'.</returns>
        public TimeWindow Intersection(TimeWindow second)
        {
            // If one of timewindow is null - return null.
            if (second == null)
            {
                return(null);
            }

            // If one of timewindows is wideopen - return other.
            if (this.IsWideOpen)
            {
                return(second.Clone() as TimeWindow);
            }
            else if (second.IsWideOpen)
            {
                return(this.Clone() as TimeWindow);
            }

            // Detect intersection of two timewindows.
            var start = this.EffectiveFrom > second.EffectiveFrom ?
                        this.EffectiveFrom : second.EffectiveFrom;
            var finish = this.EffectiveTo < second.EffectiveTo ?
                         this.EffectiveTo : second.EffectiveTo;

            if (start <= finish)
            {
                return(CreateFromEffectiveTimes(start, finish));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <c>TimeWindowBreak</c> class.
        /// </summary>
        public TimeWindowBreak()
        {
            // Set defaults.
            var from = new TimeSpan(DEFAULT_FROM_HOURS, 0, 0);
            var to   = new TimeSpan(DEFAULT_TO_HOURS, 0, 0);

            _timeWindow = new TimeWindow(from, to);
            Duration    = DefautDuration;
        }
Beispiel #3
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            TimeWindow obj = new TimeWindow();

            obj._from       = _from;
            obj._to         = _to;
            obj._day        = _day;
            obj._isWideOpen = _isWideOpen;

            return(obj);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new instance of <c>TimeWindow<c> class using effective times.
        /// </summary>
        /// <param name="effectiveFrom">Time offset of time window start from planned date.</param>
        /// <param name="effectiveTo">Time offset of time window end from planned date.</param>
        /// <exception cref="ArgumentException">Invalid time window parameter(s).</exception>
        /// <returns>Created time window.</returns>
        internal static TimeWindow CreateFromEffectiveTimes(TimeSpan effectiveFrom, TimeSpan effectiveTo)
        {
            if (!_ValidateTimeWindowEffectiveTime(effectiveFrom, effectiveTo))
            {
                throw new ArgumentException(Properties.Messages.Error_TimeWindowParameters);
            }

            TimeSpan fromTime = _GetTimeWithoutDays(effectiveFrom);
            TimeSpan toTime   = _GetTimeWithoutDays(effectiveTo);

            TimeWindow newTimeWindow = new TimeWindow(fromTime, toTime, (uint)effectiveFrom.Days);

            return(newTimeWindow);
        }
Beispiel #5
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Checks if stop's arrive date time violates given time windows.
        /// </summary>
        /// <param name="timeWindow1">First time window.</param>
        /// <param name="timeWindow2">Second time window.</param>
        /// <returns>True - if both time windows violated, false - otherwise.</returns>
        private bool _AreTimeWindowsViolated(TimeWindow timeWindow1, TimeWindow timeWindow2)
        {
            Debug.Assert(timeWindow1 != null);
            Debug.Assert(timeWindow2 != null);

            // Violation check result.
            bool isViolated = false;

            // Location's time window is violated when 1-st and 2-d time window is violated.
            if (ArriveTime.HasValue && Route.Schedule.PlannedDate.HasValue)
            {
                DateTime arriveDateTime  = ArriveTime.Value;
                DateTime plannedDateTime = Route.Schedule.PlannedDate.Value;

                isViolated = !timeWindow1.DoesIncludeTime(arriveDateTime, plannedDateTime) &&
                             !timeWindow2.DoesIncludeTime(arriveDateTime, plannedDateTime);
            }
            else
            {
                isViolated = false;
            }

            return(isViolated);
        }
Beispiel #6
0
        /// <summary>
        /// Compares this time window with another one using values of their properties.
        /// </summary>
        /// <param name="secondTimeWindow">TimeWindow to compare with this.</param>
        /// <returns>True - if either both time windows are wide open or have equal
        /// values of properties From, To and Day, otherwise - false.</returns>
        internal bool EqualsByValue(TimeWindow secondTimeWindow)
        {
            bool result = false;

            // If input parameter is invalid.
            if (secondTimeWindow == null || this.GetType() != secondTimeWindow.GetType())
            {
                result = false;
            }
            // If one of TimeWindow is WideOpen they both must be wide open.
            else if (IsWideOpen || secondTimeWindow.IsWideOpen)
            {
                result = IsWideOpen == secondTimeWindow.IsWideOpen;
            }
            // Compare From, To and Day properties.
            else
            {
                result = (From == secondTimeWindow.From &&
                          To == secondTimeWindow.To &&
                          Day == secondTimeWindow.Day);
            }

            return(result);
        }
 /// <summary>
 /// Checks is time windows intersects or not.
 /// </summary>
 /// <param name="timeWindow">Second time window.</param>
 /// <returns>'True' if they are intersect, 'false' otherwise.</returns>
 public bool Intersects(TimeWindow timeWindow)
 {
     return (Intersection(timeWindow) != null);
 }
        /// <summary>
        /// Get intersection of two TimeWindow.
        /// </summary>
        /// <param name="first">First timewindow.</param>
        /// <param name="second">Second timewindow.</param>
        /// <returns>If they intersects - return intersection 
        /// timewindow, otherwise - return 'null'.</returns>
        public TimeWindow Intersection(TimeWindow second)
        {
            // If one of timewindow is null - return null.
            if (second == null)
                return null;

            // If one of timewindows is wideopen - return other.
            if (this.IsWideOpen)
                return second.Clone() as TimeWindow;
            else if (second.IsWideOpen)
                return this.Clone() as TimeWindow;

            // Detect intersection of two timewindows.
            var start = this.EffectiveFrom > second.EffectiveFrom ?
                this.EffectiveFrom : second.EffectiveFrom;
            var finish = this.EffectiveTo < second.EffectiveTo ?
                this.EffectiveTo : second.EffectiveTo;
            if (start <= finish)
            {
                return CreateFromEffectiveTimes(start, finish);
            }
            else
                return null;
        }
        /// <summary>
        /// Gets TimeWindow property and update control's layout accordingly.
        /// </summary>
        /// <param name="tw"></param>
        protected void _TimeWindowToControlState(TimeWindow tw)
        {
            if (tw != null)
                if (tw.IsWideOpen)
                    _IsWideopen.IsChecked = true;

            _ToText.Time = tw.To;
            _ToText.TimeSpan = _ToText.Time;
            _FromText.Time = tw.From;
            _FromText.TimeSpan = _FromText.Time;
            _CellLabel.Text = tw.ToString();
        }
        /// <summary>
        /// Gets TimeWindow property and update control's layout accordingly.
        /// </summary>
        /// <param name="timeWindow"></param>
        protected void _TimeWindowToControlState(TimeWindow timeWindow)
        {
            if (timeWindow != null)
                if (timeWindow.IsWideOpen)
                    _isWideopenCheckBox.IsChecked = true;

            _toTimeTextBox.Time = timeWindow.To;
            _toTimeTextBox.TimeSpan = _toTimeTextBox.Time;
            _fromTimeTextBox.Time = timeWindow.From;
            _fromTimeTextBox.TimeSpan = _fromTimeTextBox.Time;
            _isDay2CheckBox.IsChecked = timeWindow.Day > 0;

            _UpdateCellTextBlockText();
        }
Beispiel #11
0
 /// <summary>
 /// Updates time window data in database.
 /// </summary>
 /// <param name="timeWindow">Time window data.</param>
 /// <param name="isFirst">Defines which time window should be updated: 
 /// true - 1-st time window, otherwise 2-nd time window.</param>
 private void _UpdateTimeWindowEntityData(TimeWindow timeWindow, bool isFirst)
 {
     if (isFirst)
     {
         if (!timeWindow.IsWideOpen)
         {
             _Entity.TW1From = timeWindow.EffectiveFrom.Ticks;
             _Entity.TW1To = timeWindow.EffectiveTo.Ticks;
         }
         else
         {
             _Entity.TW1From = null;
             _Entity.TW1To = null;
         }
     }
     else
     {
         if (!timeWindow.IsWideOpen)
         {
             _Entity.TW2From = timeWindow.EffectiveFrom.Ticks;
             _Entity.TW2To = timeWindow.EffectiveTo.Ticks;
         }
         else
         {
             _Entity.TW2From = null;
             _Entity.TW2To = null;
         }
     }
 }
Beispiel #12
0
 /// <summary>
 /// Initializes time window using effective to and effective from ticks.
 /// </summary>
 /// <param name="ticksFrom">Low boundary of time window in ticks.</param>
 /// <param name="ticksTo">High boundary of time window in ticks.</param>
 /// <param name="timeWindow">Time window to initialize.</param>
 private void _InitTimeWindow(long? ticksFrom, long? ticksTo, ref TimeWindow timeWindow)
 {
     if ((null != ticksFrom) && (null != ticksTo))
         _SetTimeWindow((long)ticksFrom, (long)ticksTo, ref timeWindow);
     else
         _ClearTimeWindow(ref timeWindow);
 }
        /// <summary>
        /// Method creates time windows from route break.
        /// </summary>
        /// <param name="routeBreak">Route break to get time information.</param>
        /// <returns>Time Window.</returns>
        private TimeWindow _GetBreakTimeWindow(Break routeBreak)
        {
            TimeWindow breakTimeWindow = new TimeWindow
            {
                IsWideOpen = true
            };

            if (routeBreak is TimeWindowBreak)
            {
                var twBreak = routeBreak as TimeWindowBreak;
                breakTimeWindow.From = twBreak.From;
                breakTimeWindow.To = twBreak.To;
                breakTimeWindow.IsWideOpen = false;
            }
            else
            {
                // Do nothing: any another break types have
                // wideopen time windows.
            }

            return breakTimeWindow;
        }
        /// <summary>
        /// Method set attributes for both time windows.
        /// </summary>
        /// <param name="attributes">Attributes.</param>
        /// <param name="timeWindow1">Time window 1.</param>
        /// <param name="timeWindow2">Time window 2.</param>
        private void _SetTimeWindowsAttributes(AttrDictionary attributes,
            ref TimeWindow timeWindow1, ref TimeWindow timeWindow2)
        {
            Debug.Assert(attributes != null);
            Debug.Assert(timeWindow1 != null);
            Debug.Assert(timeWindow2 != null);

            // Swap time windows in case first is Wideopen but second isn't.
            if (timeWindow1.IsWideOpen && !timeWindow2.IsWideOpen)
            {
                var temp = timeWindow1;
                timeWindow1 = timeWindow2;
                timeWindow2 = temp;
            }

            // Time window 1.
            _SetTimeWindowAttribute(timeWindow1, NAAttribute.TW_START1, NAAttribute.TW_END1,
                attributes);

            // Time window 2.
            _SetTimeWindowAttribute(timeWindow2, NAAttribute.TW_START2, NAAttribute.TW_END2,
                attributes);
        }
 /// <summary>
 /// Method fills TimeWindow attributes in correct format.
 /// </summary>
 /// <param name="timeWindow">TimeWindow value.</param>
 /// <param name="attrNameStart">Format string for Start TimeWindow.</param>
 /// <param name="attrNameEnd">Format string for End TimeWindow</param>
 /// <param name="attributes">Attributes to fill in.</param>
 private void _SetTimeWindowAttribute(TimeWindow timeWindow,
     string attrNameStart,
     string attrNameEnd,
     AttrDictionary attributes)
 {
     attributes.SetTimeWindow(timeWindow, _plannedDate, attrNameStart, attrNameEnd);
 }
        /// <summary>
        /// Checks if time window includes stop's arrive time.
        /// </summary>
        /// <param name="timeWindow">Time window.</param>
        /// <param name="stop">Stop object (expected it has associated object either Location or Order).</param>
        /// <returns>True if stop's arrive time is inside time window, false - otherwise.</returns>
        private static bool _DoesTimeWindowIncludeStopArriveTime(TimeWindow timeWindow, Stop stop)
        {
            Debug.Assert(timeWindow != null);
            Debug.Assert(stop != null);

            // Stop's arrive time.
            DateTime? arriveDateTime = stop.ArriveTime;

            // Stop's planned time.
            DateTime? plannedDateTime = stop.Route.Schedule.PlannedDate;

            // Check if time window includes stop's arrive time.
            bool result =
                _DoesTimeWindowIncludeTime(timeWindow, arriveDateTime, plannedDateTime);

            return result;
        }
        /// <summary>
        /// Checks if time window includes given time.
        /// </summary>
        /// <param name="timeWindow">Time window.</param>
        /// <param name="arriveDateTime">Arrive date time.</param>
        /// <param name="plannedDateTime">Planned date time.</param>
        /// <returns>True - if arrive time is inside time window, false - otherwise.</returns>
        private static bool _DoesTimeWindowIncludeTime(TimeWindow timeWindow, DateTime? arriveDateTime, DateTime? plannedDateTime)
        {
            Debug.Assert(timeWindow != null);

            bool result = false;

            // Check if arrive and planned date time have values.
            if (arriveDateTime.HasValue && plannedDateTime.HasValue)
            {
                // Check if arrive time is inside the time window.
                result = timeWindow.DoesIncludeTime(arriveDateTime.Value, plannedDateTime.Value);
            }
            else
            {
                result = false;
            }

            return result;
        }
Beispiel #18
0
 /// <summary>
 /// Checks is time windows intersects or not.
 /// </summary>
 /// <param name="timeWindow">Second time window.</param>
 /// <returns>'True' if they are intersect, 'false' otherwise.</returns>
 public bool Intersects(TimeWindow timeWindow)
 {
     return(Intersection(timeWindow) != null);
 }
        /// <summary>
        /// Gets time window of stop by index (0 or 1).
        /// </summary>
        /// <param name="stop">Stop object (expected it has associated object either Location or Order).</param>
        /// <param name="twIndex">Index of time window (use constants FIRST_TIME_WINDOW, SECOND_TIME_WINDOW).</param>
        /// <returns>Requested time window.</returns>
        private static TimeWindow _GetTimeWindowByIndex(Stop stop, int twIndex)
        {
            Debug.Assert(stop != null);
            Debug.Assert(twIndex == FIRST_TIME_WINDOW || twIndex == SECOND_TIME_WINDOW);

            // Requested time window.
            TimeWindow timeWindow;

            // If stop is Location.
            if (stop.AssociatedObject is Location)
            {
                Location location = stop.AssociatedObject as Location;

                timeWindow = (twIndex == FIRST_TIME_WINDOW) ?
                             location.TimeWindow :
                             location.TimeWindow2;
            }
            // If stop is Order.
            else if (stop.AssociatedObject is Order)
            {
                Order order = stop.AssociatedObject as Order;

                timeWindow = (twIndex == FIRST_TIME_WINDOW) ?
                             order.TimeWindow :
                             order.TimeWindow2;
            }
            else
            {
                // Unknown object.
                Debug.Assert(false);

                // Create default time window.
                timeWindow = new TimeWindow();
            }

            return timeWindow;
        }
        /// <summary>
        /// Creates a new instance of <c>TimeWindow<c> class using effective times.
        /// </summary>
        /// <param name="effectiveFrom">Time offset of time window start from planned date.</param>
        /// <param name="effectiveTo">Time offset of time window end from planned date.</param>
        /// <exception cref="ArgumentException">Invalid time window parameter(s).</exception>
        /// <returns>Created time window.</returns>
        internal static TimeWindow CreateFromEffectiveTimes(TimeSpan effectiveFrom, TimeSpan effectiveTo)
        {
            if (!_ValidateTimeWindowEffectiveTime(effectiveFrom, effectiveTo))
                throw new ArgumentException(Properties.Messages.Error_TimeWindowParameters);

            TimeSpan fromTime = _GetTimeWithoutDays(effectiveFrom);
            TimeSpan toTime = _GetTimeWithoutDays(effectiveTo);

            TimeWindow newTimeWindow = new TimeWindow(fromTime, toTime, (uint)effectiveFrom.Days);

            return newTimeWindow;
        }
Beispiel #21
0
 /// <summary>
 /// Sets time window 2 using data from database.
 /// </summary>
 /// <param name="entity">Entity object Locations.</param>
 private void _SetTimeWindow2(DataModel.Locations entity)
 {
     _timeWindow2 =
         TimeWindow.CreateFromEffectiveTimes(new TimeSpan((long)entity.OpenFrom2),
                                             new TimeSpan((long)entity.OpenTo2));
 }
        /// <summary>
        /// Compares this time window with another one using values of their properties.
        /// </summary>
        /// <param name="secondTimeWindow">TimeWindow to compare with this.</param>
        /// <returns>True - if either both time windows are wide open or have equal 
        /// values of properties From, To and Day, otherwise - false.</returns>
        internal bool EqualsByValue(TimeWindow secondTimeWindow)
        {
            bool result = false;

            // If input parameter is invalid.
            if (secondTimeWindow == null || this.GetType() != secondTimeWindow.GetType())
            {
                result = false;
            }
            // If one of TimeWindow is WideOpen they both must be wide open.
            else if (IsWideOpen || secondTimeWindow.IsWideOpen)
            {
                result = IsWideOpen == secondTimeWindow.IsWideOpen;
            }
            // Compare From, To and Day properties.
            else
            {
                result = (From == secondTimeWindow.From &&
                          To == secondTimeWindow.To &&
                          Day == secondTimeWindow.Day);
            }

            return result;
        }
 /// <summary>
 /// Add Time window
 /// </summary>
 /// <param name="timeWindow">Source time window</param>
 /// <param name="second">Is second time window</param>
 /// <param name="inlines">Inlines to fill</param>
 /// <param name="bolded">Is need to be bold inline</param>
 private static void _AddTimeWindow(TimeWindow timeWindow, bool second, InlineCollection inlines, bool bolded)
 {
     string value = timeWindow.ToString();
     string timewindowCaption = _timewindowCaption;
     if (second)
         timewindowCaption += "2";
     _AddLine(timewindowCaption, value, inlines, bolded);
 }
Beispiel #24
0
 /// <summary>
 /// Clears given time window.
 /// </summary>
 /// <param name="timeWindow">Time window to clear.</param>
 private void _ClearTimeWindow(ref TimeWindow timeWindow)
 {
     timeWindow.From = new TimeSpan();
     timeWindow.To = new TimeSpan();
     timeWindow.Day = 0;
     timeWindow.IsWideOpen = true;
 }
Beispiel #25
0
 /// <summary>
 /// Sets time window using entity data.
 /// </summary>
 /// <param name="entity"></param>
 private void _SetTimeWindow(DataModel.Routes entity)
 {
     _timeWindow =
         TimeWindow.CreateFromEffectiveTimes(new TimeSpan((long)entity.WorkFrom),
                                             new TimeSpan((long)entity.WorkTo));
 }
Beispiel #26
0
        /// <summary>
        /// Creates time window using effective to and effective from ticks and stores result to
        /// the output parameter.
        /// </summary>
        /// <param name="ticksFrom">Low boundary of time window in ticks.</param>
        /// <param name="ticksTo">High boundary of time window in ticks.</param>
        /// <param name="timeWindow">Output parameter to store time window.</param>
        private void _SetTimeWindow(long ticksFrom, long ticksTo, ref TimeWindow timeWindow)
        {
            // Create time window using effective times.
            TimeWindow newTimeWindow =
                TimeWindow.CreateFromEffectiveTimes(new TimeSpan(ticksFrom), new TimeSpan(ticksTo));

            timeWindow.From = newTimeWindow.From;
            timeWindow.To = newTimeWindow.To;
            timeWindow.Day = newTimeWindow.Day;
            timeWindow.IsWideOpen = false;
        }
Beispiel #27
0
 /// <summary>
 /// Sets time window 2 using data from database.
 /// </summary>
 /// <param name="entity">Entity object Locations.</param>
 private void _SetTimeWindow2(DataModel.Locations entity)
 {
     _timeWindow2 =
         TimeWindow.CreateFromEffectiveTimes(new TimeSpan((long)entity.OpenFrom2),
                                             new TimeSpan((long)entity.OpenTo2));
 }
        /// <summary>
        /// Transform values from control fields to TimeWindow value
        /// </summary>
        protected void _GetTimeWindowFromControl()
        {
            TimeWindow timeWindow = new TimeWindow();

            timeWindow.IsWideOpen = (bool)_isWideopenCheckBox.IsChecked;
            timeWindow.From = _fromTimeTextBox.Time;
            timeWindow.To = _toTimeTextBox.Time;
            timeWindow.Day = (bool)_isDay2CheckBox.IsChecked ? 1u : 0u;

            TimeWindow = timeWindow;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            TimeWindow obj = new TimeWindow();

            obj._from = _from;
            obj._to = _to;
            obj._day = _day;
            obj._isWideOpen = _isWideOpen;

            return obj;
        }
 /// <summary>
 /// Initializes a new instance of the <c>TimeWindowBreak</c> class.
 /// </summary>
 public TimeWindowBreak()
 {
     // Set defaults.
     var from = new TimeSpan (DEFAULT_FROM_HOURS, 0, 0);
     var to = new TimeSpan(DEFAULT_TO_HOURS, 0, 0);
     _timeWindow = new TimeWindow(from, to);
     Duration = DefautDuration;
 }
        /// <summary>
        /// Transform values from control fields to TimeWindow value.
        /// </summary>
        protected void _GetTimeWindowFromControl()
        {
            TimeWindow tw = new TimeWindow();
            tw.IsWideOpen = (bool)_IsWideopen.IsChecked;
            tw.From = _FromText.Time;
            tw.To = _ToText.Time;

            TimeWindow = tw;
        }