Exemplo n.º 1
0
        /// <summary>
        /// Adds a range of dates to the Calendar SelectedDates.
        /// </summary>
        /// <remarks>
        /// Helper version of AddRange for mouse drag selection.
        /// This version guarantees no exceptions will be thrown by removing blackout days from the range before adding to the collection
        /// </remarks>
        internal void AddRangeInternal(DateTime start, DateTime end)
        {
            BeginAddRange();

            // In Mouse Selection we allow the user to be able to add multiple ranges in one action in MultipleRange Mode
            // In SingleRange Mode, we only add the first selected range
            DateTime lastAddedDate = start;

            foreach (DateTime current in GetDaysInRange(start, end))
            {
                if (Calendar.IsValidDateSelection(this._owner, current))
                {
                    this.Add(current);
                    lastAddedDate = current;
                }
                else
                {
                    if (this._owner.SelectionMode == CalendarSelectionMode.SingleRange)
                    {
                        this._owner.CurrentDate = lastAddedDate;
                        break;
                    }
                }
            }

            EndAddRange();
        }
 // Token: 0x060055D0 RID: 21968 RVA: 0x0017C858 File Offset: 0x0017AA58
 internal void Toggle(DateTime date)
 {
     if (Calendar.IsValidDateSelection(this._owner, date))
     {
         CalendarSelectionMode selectionMode = this._owner.SelectionMode;
         if (selectionMode != CalendarSelectionMode.SingleDate)
         {
             if (selectionMode != CalendarSelectionMode.MultipleRange)
             {
                 return;
             }
             if (!base.Remove(date))
             {
                 base.Add(date);
             }
         }
         else
         {
             if (this._owner.SelectedDate == null || DateTimeHelper.CompareDays(this._owner.SelectedDate.Value, date) != 0)
             {
                 this._owner.SelectedDate = new DateTime?(date);
                 return;
             }
             this._owner.SelectedDate = null;
             return;
         }
     }
 }
 // Token: 0x060055CC RID: 21964 RVA: 0x0017C5E0 File Offset: 0x0017A7E0
 protected override void SetItem(int index, DateTime item)
 {
     if (!this.IsValidThread())
     {
         throw new NotSupportedException(SR.Get("CalendarCollection_MultiThreadedCollectionChangeNotSupported"));
     }
     if (!base.Contains(item))
     {
         Collection <DateTime> collection  = new Collection <DateTime>();
         Collection <DateTime> collection2 = new Collection <DateTime>();
         if (index >= base.Count)
         {
             base.SetItem(index, item);
             this.UpdateMinMax(item);
             return;
         }
         if (DateTime.Compare(base[index], item) != 0 && Calendar.IsValidDateSelection(this._owner, item))
         {
             collection2.Add(base[index]);
             base.SetItem(index, item);
             this.UpdateMinMax(item);
             collection.Add(item);
             if (index == 0 && (this._owner.SelectedDate == null || DateTime.Compare(this._owner.SelectedDate.Value, item) != 0))
             {
                 this._owner.SelectedDate = new DateTime?(item);
             }
             this.RaiseSelectionChanged(collection2, collection);
             int num = DateTimeHelper.CompareYearMonth(item, this._owner.DisplayDateInternal);
             if (num < 2 && num > -2)
             {
                 this._owner.UpdateCellItems();
             }
         }
     }
 }
Exemplo n.º 4
0
        // iT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE DATETIME VALUE IF IT IS VALID

        /// <summary>
        ///     Input text is parsed in the correct format and changed into a DateTime object.
        ///     If the text can not be parsed TextParseError Event is thrown.
        /// </summary>
        private DateTime?ParseText(string text)
        {
            DateTime newSelectedDate;

            // TryParse is not used in order to be able to pass the exception to the TextParseError event
            try
            {
                newSelectedDate = DateTime.Parse(text, DateTimeHelper.GetDateFormat(DateTimeHelper.GetCulture(this)));

                if (Calendar.IsValidDateSelection(_calendar, newSelectedDate))
                {
                    return(newSelectedDate);
                }
                var dateValidationError = new DatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException("text", System.Windows.SR.Get(SRID.Calendar_OnSelectedDateChanged_InvalidValue)), text);
                OnDateValidationError(dateValidationError);

                if (dateValidationError.ThrowException)
                {
                    throw dateValidationError.Exception;
                }
            }
            catch (FormatException ex)
            {
                var textParseError = new DatePickerDateValidationErrorEventArgs(ex, text);
                OnDateValidationError(textParseError);

                if (textParseError.ThrowException && textParseError.Exception != null)
                {
                    throw textParseError.Exception;
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a range of dates to the Calendar SelectedDates.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        public void AddRange(DateTime start, DateTime end)
        {
            DateTime?rangeStart;
            //increment parameter specifies if the Days were selected in Descending order or Ascending order
            //based on this value, we add the days in the range either in Ascending order or in Descending order
            int increment = (DateTime.Compare(end, start) >= 0) ? 1 : -1;

            this._addedItems.Clear();

            rangeStart    = start;
            _isRangeAdded = true;

            if (this._owner._isMouseSelection)
            {
                //In Mouse Selection we allow the user to be able to add multiple ranges in one action in MultipleRange Mode
                //In SingleRange Mode, we only add the first selected range
                while (rangeStart.HasValue && DateTime.Compare(end, rangeStart.Value) != -increment)
                {
                    if (Calendar.IsValidDateSelection(this._owner, rangeStart))
                    {
                        this.Add(rangeStart.Value);
                    }
                    else
                    {
                        if (this._owner.SelectionMode == CalendarSelectionMode.SingleRange)
                        {
                            this._owner.HoverEnd = rangeStart.Value.AddDays(-increment);
                            break;
                        }
                    }

                    rangeStart = DateTimeHelper.AddDays(rangeStart.Value, increment);
                }
            }
            else
            {
                //If CalendarSelectionMode.SingleRange and a user programmatically tries to add multiple ranges, we will throw away the old range and replace it with the new one.
                //in order to provide the removed items without an additional event, we are calling ClearInternal
                if (this._owner.SelectionMode == CalendarSelectionMode.SingleRange && this.Count > 0)
                {
                    foreach (DateTime item in this)
                    {
                        this._owner._removedItems.Add(item);
                    }
                    this.ClearInternal();
                }

                while (rangeStart.HasValue && DateTime.Compare(end, rangeStart.Value) != -increment)
                {
                    this.Add(rangeStart.Value);
                    rangeStart = DateTimeHelper.AddDays(rangeStart.Value, increment);
                }
            }

            _owner.OnSelectedDatesCollectionChanged(new SelectionChangedEventArgs(this._owner._removedItems, this._addedItems));
            this._owner._removedItems.Clear();
            this._owner.UpdateMonths();
            _isRangeAdded = false;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Inserts the item in the specified position of the SelectedDates collection.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="item"></param>
        protected override void InsertItem(int index, DateTime item)
        {
            if (!IsValidThread())
            {
                throw new NotSupportedException(Resource.CalendarCollection_MultiThreadedCollectionChangeNotSupported);
            }

            if (!this.Contains(item))
            {
                Collection <DateTime> addedItems = new Collection <DateTime>();

                if (CheckSelectionMode())
                {
                    if (Calendar.IsValidDateSelection(this._owner, item))
                    {
                        //If the Collection is cleared since it is SingleRange and it had another range
                        //set the index to 0
                        if (_isCleared)
                        {
                            index      = 0;
                            _isCleared = false;
                        }

                        base.InsertItem(index, item);

                        //The event fires after SelectedDate changes
                        if (index == 0 && !(this._owner.SelectedDate.HasValue && DateTime.Compare(this._owner.SelectedDate.Value, item) == 0))
                        {
                            this._owner.SelectedDate = item;
                        }

                        if (!_isRangeAdded)
                        {
                            addedItems.Add(item);


                            _owner.OnSelectedDatesCollectionChanged(new SelectionChangedEventArgs(this._owner._removedItems, addedItems));
                            this._owner._removedItems.Clear();
                            int monthDifference = DateTimeHelper.CompareYearMonth(item, this._owner.DisplayDateInternal);

                            if (monthDifference < 2 && monthDifference > -2)
                            {
                                this._owner.UpdateMonths();
                            }
                        }
                        else
                        {
                            this._addedItems.Add(item);
                        }
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException(Resource.Calendar_OnSelectedDateChanged_InvalidValue);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// The object in the specified index is replaced with the provided item.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="item"></param>
        protected override void SetItem(int index, DateTime item)
        {
            if (!IsValidThread())
            {
                throw new NotSupportedException(SR.Get(SRID.CalendarCollection_MultiThreadedCollectionChangeNotSupported));
            }

            if (!this.Contains(item))
            {
                Collection <DateTime> addedItems   = new Collection <DateTime>();
                Collection <DateTime> removedItems = new Collection <DateTime>();

                if (index >= this.Count)
                {
                    base.SetItem(index, item);
                    UpdateMinMax(item);
                }
                else
                {
                    if (item != null && DateTime.Compare(this[index], item) != 0 && Calendar.IsValidDateSelection(this._owner, item))
                    {
                        removedItems.Add(this[index]);
                        base.SetItem(index, item);
                        UpdateMinMax(item);

                        addedItems.Add(item);

                        // The event fires after SelectedDate changes
                        if (index == 0 && !(this._owner.SelectedDate.HasValue && DateTime.Compare(this._owner.SelectedDate.Value, item) == 0))
                        {
                            this._owner.SelectedDate = item;
                        }

                        RaiseSelectionChanged(removedItems, addedItems);

                        int monthDifference = DateTimeHelper.CompareYearMonth(item, this._owner.DisplayDateInternal);

                        if (monthDifference < 2 && monthDifference > -2)
                        {
                            this._owner.UpdateCellItems();
                        }
                    }
                }
            }
        }
        // Token: 0x060055CD RID: 21965 RVA: 0x0017C6F4 File Offset: 0x0017A8F4
        internal void AddRangeInternal(DateTime start, DateTime end)
        {
            this.BeginAddRange();
            DateTime currentDate = start;

            foreach (DateTime dateTime in SelectedDatesCollection.GetDaysInRange(start, end))
            {
                if (Calendar.IsValidDateSelection(this._owner, dateTime))
                {
                    base.Add(dateTime);
                    currentDate = dateTime;
                }
                else if (this._owner.SelectionMode == CalendarSelectionMode.SingleRange)
                {
                    this._owner.CurrentDate = currentDate;
                    break;
                }
            }
            this.EndAddRange();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Replaces the element at the specified index.
        /// </summary>
        /// <param name="index">
        /// The zero-based index of the element to replace.
        /// </param>
        /// <param name="item">
        /// The new value for the element at the specified index.
        /// </param>
        /// <remarks>
        /// This implementation raises the CollectionChanged event.
        /// </remarks>
        protected override void SetItem(int index, DateTime item)
        {
            if (!IsValidThread())
            {
                throw new NotSupportedException(System.Windows.Controls.Properties.Resources.CalendarCollection_MultiThreadedCollectionChangeNotSupported);
            }

            if (!Contains(item))
            {
                Collection <DateTime> addedItems   = new Collection <DateTime>();
                Collection <DateTime> removedItems = new Collection <DateTime>();

                if (index >= Count)
                {
                    base.SetItem(index, item);
                }
                else
                {
                    if (item != null && DateTime.Compare(this[index], item) != 0 && Calendar.IsValidDateSelection(_owner, item))
                    {
                        removedItems.Add(this[index]);
                        base.SetItem(index, item);
                        addedItems.Add(item);

                        // The event fires after SelectedDate changes
                        if (index == 0 && !(_owner.SelectedDate.HasValue && DateTime.Compare(_owner.SelectedDate.Value, item) == 0))
                        {
                            _owner.SelectedDate = item;
                        }
                        _owner.OnSelectedDatesCollectionChanged(new SelectionChangedEventArgs(removedItems, addedItems));

                        int monthDifference = DateTimeHelper.CompareYearMonth(item, _owner.DisplayDateInternal);

                        if (monthDifference < 2 && monthDifference > -2)
                        {
                            _owner.UpdateMonths();
                        }
                    }
                }
            }
        }
 // Token: 0x060055CA RID: 21962 RVA: 0x0017C3F4 File Offset: 0x0017A5F4
 protected override void InsertItem(int index, DateTime item)
 {
     if (!this.IsValidThread())
     {
         throw new NotSupportedException(SR.Get("CalendarCollection_MultiThreadedCollectionChangeNotSupported"));
     }
     if (!base.Contains(item))
     {
         Collection <DateTime> collection = new Collection <DateTime>();
         bool flag = this.CheckSelectionMode();
         if (!Calendar.IsValidDateSelection(this._owner, item))
         {
             throw new ArgumentOutOfRangeException(SR.Get("Calendar_OnSelectedDateChanged_InvalidValue"));
         }
         if (flag)
         {
             index = 0;
         }
         base.InsertItem(index, item);
         this.UpdateMinMax(item);
         if (index == 0 && (this._owner.SelectedDate == null || DateTime.Compare(this._owner.SelectedDate.Value, item) != 0))
         {
             this._owner.SelectedDate = new DateTime?(item);
         }
         if (this._isAddingRange)
         {
             this._addedItems.Add(item);
             return;
         }
         collection.Add(item);
         this.RaiseSelectionChanged(this._removedItems, collection);
         this._removedItems.Clear();
         int num = DateTimeHelper.CompareYearMonth(item, this._owner.DisplayDateInternal);
         if (num < 2 && num > -2)
         {
             this._owner.UpdateCellItems();
             return;
         }
     }
 }
Exemplo n.º 11
0
        internal void Toggle(DateTime date)
        {
            if (Calendar.IsValidDateSelection(this._owner, date))
            {
                switch (this._owner.SelectionMode)
                {
                case CalendarSelectionMode.SingleDate:
                {
                    if (!this._owner.SelectedDate.HasValue || DateTimeHelper.CompareDays(this._owner.SelectedDate.Value, date) != 0)
                    {
                        this._owner.SelectedDate = date;
                    }
                    else
                    {
                        this._owner.SelectedDate = null;
                    }

                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    if (!Remove(date))
                    {
                        Add(date);
                    }

                    break;
                }

                default:
                {
                    Debug.Assert(false);
                    break;
                }
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Input text is parsed in the correct format and changed into a DateTime object.
        /// If the text can not be parsed TextParseError Event is thrown.
        /// </summary>
        private DateTime?ParseText(string text)
        {
            DateTime newSelectedDate;

            //TryParse is not used in order to be able to pass the exception to the TextParseError event
            try
            {
                newSelectedDate = DateTime.Parse(text, DateTimeHelper.GetCurrentDateFormat());

                if (Calendar.IsValidDateSelection(this._calendar, newSelectedDate))
                {
                    return(newSelectedDate);
                }
                else
                {
                    DatePickerDateValidationErrorEventArgs dateValidationError = new DatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException("text", Resource.Calendar_OnSelectedDateChanged_InvalidValue), text);
                    OnDateValidationError(dateValidationError);

                    if (dateValidationError.ThrowException)
                    {
                        throw dateValidationError.Exception;
                    }
                }
            }
            catch (FormatException ex)
            {
                DatePickerDateValidationErrorEventArgs textParseError = new DatePickerDateValidationErrorEventArgs(ex, text);
                OnDateValidationError(textParseError);

                if (textParseError.ThrowException)
                {
                    throw textParseError.Exception;
                }
            }
            return(null);
        }