Example #1
0
        /// <summary>
        /// Clears any existing selection and then selects the current element.
        /// </summary>
        void ISelectionItemProvider.Select()
        {
            CalendarExButton button = OwningCalendarButton;

            if (!button.IsEnabled)
            {
                throw new ElementNotEnabledException();
            }

            CalendarEx calendar = OwningCalendar;

            if (calendar != null &&
                button.Visibility != Visibility.Collapsed &&
                !button.IsCalendarButtonFocused)
            {
                foreach (CalendarExButton child in calendar.MonthControl.YearView.Children)
                {
                    if (child.IsCalendarButtonFocused)
                    {
                        child.IsCalendarButtonFocused = false;
                        break;
                    }
                }

                button.IsCalendarButtonFocused = true;
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="T:System.Windows.Controls.CalendarBlackoutDatesCollection" />
        /// class.
        /// </summary>
        /// <param name="owner">
        /// The <see cref="T:System.Windows.Controls.Calendar" /> whose dates
        /// this object represents.
        /// </param>
        public CalendarExBlackoutDatesCollection(CalendarEx owner)
        {
            // TODO: This assert should be replaced with an exception.
            Debug.Assert(owner != null, "owner should not be null!");

            _owner = owner;
            _dispatcherThread = Thread.CurrentThread;
        }
        /// <summary>
        /// Inserts an item into the collection at the specified index.
        /// </summary>
        /// <param name="index">
        /// The zero-based index at which item should be inserted.
        /// </param>
        /// <param name="item">The object to insert.</param>
        /// <remarks>
        /// This implementation raises the CollectionChanged event.
        /// </remarks>
        protected override void InsertItem(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>();

                if (CheckSelectionMode())
                {
                    if (CalendarEx.IsValidDateSelection(_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 && !(_owner.SelectedDate.HasValue && DateTime.Compare(_owner.SelectedDate.Value, item) == 0))
                        {
                            _owner.SelectedDate = item;
                        }

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

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

                            if (monthDifference < 2 && monthDifference > -2)
                            {
                                _owner.UpdateMonths();
                            }
                        }
                        else
                        {
                            _addedItems.Add(item);
                        }
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException(System.Windows.Controls.Properties.Resources.Calendar_OnSelectedDateChanged_InvalidValue);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Raise an automation peer event for the selection of a day button.
        /// </summary>
        /// <param name="calendar">
        /// The Calendar associated with this automation peer.
        /// </param>
        /// <param name="date">The selected date.</param>
        /// <param name="eventToRaise">The selection event to raise.</param>
        private static void RaiseDayButtonSelectionEvent(CalendarEx calendar, DateTime date, AutomationEvents eventToRaise)
        {
            CalendarExDayButton button = calendar.FindDayButtonFromDay(date);

            if (button != null)
            {
                AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(button);
                if (peer != null)
                {
                    peer.RaiseAutomationEvent(eventToRaise);
                }
            }
        }
        /// <summary>
        /// Clear any existing selection and then selects the current element.
        /// </summary>
        void ISelectionItemProvider.Select()
        {
            if (EnsureSelection())
            {
                CalendarEx          calendar = OwningCalendar;
                CalendarExDayButton button   = OwningCalendarDayButton;

                calendar.SelectedDates.Clear();
                if (button.DataContext != null)
                {
                    calendar.SelectedDates.Add((DateTime)button.DataContext);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Sends a request to activate the control and initiate its single,
        /// unambiguous action.
        /// </summary>
        void IInvokeProvider.Invoke()
        {
            CalendarEx calendar = OwningCalendar;

            if (calendar != null && OwningCalendarButton.IsEnabled)
            {
                calendar.MonthControl.UpdateYearViewSelection(OwningCalendarButton);
                calendar.MonthControl.Month_CalendarButtonMouseUp(OwningCalendarButton, null);
            }
            else
            {
                throw new ElementNotEnabledException();
            }
        }
Example #7
0
        /// <summary>
        /// Gets the control pattern for this
        /// <see cref="T:System.Windows.Automation.Peers.CalendarExAutomationPeer" />.
        /// </summary>
        /// <param name="patternInterface">
        /// One of the enumeration values.
        /// </param>
        /// <returns>
        /// The object that implements the pattern interface, or null if the
        /// specified pattern interface is not implemented by this peer.
        /// </returns>
        public override object GetPattern(PatternInterface patternInterface)
        {
            if (patternInterface == PatternInterface.GridItem ||
                patternInterface == PatternInterface.Invoke ||
                patternInterface == PatternInterface.SelectionItem)
            {
                CalendarEx calendar = OwningCalendar;
                if (calendar != null && calendar.MonthControl != null)
                {
                    return(this);
                }
            }

            return(base.GetPattern(patternInterface));
        }
        /// <summary>
        /// Retrieves a collection of UI Automation providers that represent all
        /// the column headers that are associated with a table item or cell.
        /// </summary>
        /// <returns>A collection of UI Automation providers.</returns>
        IRawElementProviderSimple[] ITableItemProvider.GetColumnHeaderItems()
        {
            CalendarEx calendar = OwningCalendar;

            if (calendar != null && OwningCalendarAutomationPeer != null)
            {
                IRawElementProviderSimple[] headers = ((ITableProvider)CreatePeerForElement(calendar)).GetColumnHeaders();
                if (headers != null)
                {
                    int column = ((IGridItemProvider)this).Column;
                    return(new IRawElementProviderSimple[] { headers[column] });
                }
            }
            return(null);
        }
        /// <summary>
        /// Removes the current element from the collection of selected items.
        /// </summary>
        void ISelectionItemProvider.RemoveFromSelection()
        {
            // Return if the item is not already selected.
            CalendarExDayButton button = OwningCalendarDayButton;

            if (!button.IsSelected)
            {
                return;
            }

            CalendarEx calendar = OwningCalendar;

            if (calendar != null && button.DataContext != null)
            {
                calendar.SelectedDates.Remove((DateTime)button.DataContext);
            }
        }
        /// <summary>
        /// Ensure selection of the CalendarDayButton is possible.
        /// </summary>
        /// <returns>
        /// A value indicating whether selection of the CalendarDayButton is
        /// possible.
        /// </returns>
        private bool EnsureSelection()
        {
            CalendarExDayButton button = OwningCalendarDayButton;

            if (!button.IsEnabled)
            {
                throw new ElementNotEnabledException();
            }

            // If the day is a blackout day or the SelectionMode is None,
            // selection is not allowed
            CalendarEx calendar = OwningCalendar;

            return(!button.IsBlackout &&
                   button.Visibility != Visibility.Collapsed &&
                   calendar != null &&
                   calendar.SelectionMode != CalendarExSelectionMode.None);
        }
        /// <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 && CalendarEx.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();
                        }
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Raise selection AutomationEvents when the Calendar's SelectedDates
        /// collection changes.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        internal void RaiseSelectionEvents(SelectionChangedEventArgs e)
        {
            CalendarEx calendar      = OwningCalendar;
            int        selectedDates = calendar.SelectedDates.Count;

            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) && selectedDates == 1)
            {
                RaiseDayButtonSelectionEvent(
                    calendar,
                    (DateTime)e.AddedItems[0],
                    AutomationEvents.SelectionItemPatternOnElementSelected);
            }
            else
            {
                if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection))
                {
                    foreach (DateTime date in e.AddedItems)
                    {
                        RaiseDayButtonSelectionEvent(
                            calendar,
                            date,
                            AutomationEvents.SelectionItemPatternOnElementAddedToSelection);
                    }
                }

                if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
                {
                    foreach (DateTime date in e.RemovedItems)
                    {
                        RaiseDayButtonSelectionEvent(
                            calendar,
                            date,
                            AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection);
                    }
                }
            }
        }
        /// <summary>
        /// Adds the current element to the collection of selected items.
        /// </summary>
        void ISelectionItemProvider.AddToSelection()
        {
            // Return if the item is already selected
            CalendarExDayButton button = OwningCalendarDayButton;

            if (button.IsSelected)
            {
                return;
            }

            CalendarEx calendar = OwningCalendar;

            if (EnsureSelection() && button.DataContext != null)
            {
                if (calendar.SelectionMode == CalendarExSelectionMode.SingleDate)
                {
                    calendar.SelectedDate = (DateTime)button.DataContext;
                }
                else
                {
                    calendar.SelectedDates.Add((DateTime)button.DataContext);
                }
            }
        }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Automation.Peers.CalendarExAutomationPeer" />
 /// class.
 /// </summary>
 /// <param name="owner">
 /// The <see cref="T:System.Windows.Controls.Calendar" /> instance to
 /// associate with the
 /// <see cref="T:System.Windows.Automation.Peers.CalendarExAutomationPeer" />.
 /// </param>
 public CalendarExAutomationPeer(CalendarEx owner)
     : base(owner)
 {
 }
Example #15
0
        private Highcharts GetAssignmentsPlot(IEnumerable <Assignment> assignments)
        {
            var dateBegin = DateTime.Now.Date.AddDays(-30);
            var dateEnd   = DateTime.Now.Date.AddDays(1).AddSeconds(-1);

            var assignmentsByDates = new List <ViewModel.Primitives.AssignmentsCountPoint>();

            foreach (var serie in CalendarEx.GetSeriePeriodsWithMaxPointInPeriod(100, CalendarEx.StepType.Days, dateBegin, dateEnd))
            {
                var datePoint = new ViewModel.Primitives.AssignmentsCountPoint {
                    Name = serie.PeriodEnd.ToString("d", CultureInfo.CurrentCulture)
                };

                var dateAssignments = Model.Helpers.FilterAssignmentsForPeriodWithActive(assignments.ToList(), serie.PeriodBegin, serie.PeriodEnd);
                datePoint.Total = dateAssignments.Count;

                var overduedateAssignments = dateAssignments.Where(a => a.HasOverdueOnDate(serie.PeriodEnd)).ToList();
                datePoint.Overdue = overduedateAssignments.Count;

                assignmentsByDates.Add(datePoint);
            }

            var overdueAssignments = assignmentsByDates.Select(a => new Point()
            {
                Name = a.Name, Y = a.Overdue
            }).ToArray();
            var totalAssignments = assignmentsByDates.Select(a => new Point()
            {
                Name = a.Name, Y = a.Total
            }).ToArray();

            var chart = new Highcharts("AssignmentsPlot")
                        .InitChart(new Chart {
                Type = ChartTypes.Spline, PlotShadow = false, PlotBackgroundColor = null, PlotBorderWidth = null
            })
                        .SetExporting(new Exporting()
            {
                Enabled = false
            })
                        .SetTitle(new Title {
                Text = "", Align = HorizontalAligns.Left
            })
                        .SetTooltip(new Tooltip {
                Shared = true
            })
                        .SetLegend(new Legend {
                ItemStyle = "fontWeight: 'normal'"
            })
                        .SetPlotOptions(new PlotOptions
            {
                Line = new PlotOptionsLine
                {
                    AllowPointSelect = true,
                    Cursor           = Cursors.Pointer,
                    ShowInLegend     = true
                }
            })
                        .SetYAxis(new YAxis()
            {
                Min   = 0,
                Title = new YAxisTitle()
                {
                    Text = "Задания"
                }
            })
                        .SetXAxis(new XAxis
            {
                Type = AxisTypes.Datetime,
                DateTimeLabelFormats = new DateTimeLabel()
                {
                    Day = "%d.%m.%Y", Week = "%d.%m.%Y", Month = "%d.%m.%Y"
                }
            })
                        .SetSeries(new []
            {
                new Series
                {
                    Type              = ChartTypes.Line,
                    Name              = "Общее количество",
                    Data              = new Data(totalAssignments),
                    Color             = ChartColors.Color1,
                    PlotOptionsSeries = new PlotOptionsSeries()
                    {
                        PointStart    = new PointStart(DateTime.Now.AddDays(-30)),
                        PointInterval = 24 * 3600 * 1000 // Один день в миллисекундах.
                    }
                },
                new Series
                {
                    Type              = ChartTypes.Line,
                    Name              = "Просроченные",
                    Data              = new Data(overdueAssignments),
                    Color             = ChartColors.Red,
                    PlotOptionsSeries = new PlotOptionsSeries()
                    {
                        PointStart    = new PointStart(DateTime.Now.AddDays(-30)),
                        PointInterval = 24 * 3600 * 1000 // Один день в миллисекундах.
                    }
                },
            });


            return(chart);
        }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Controls.SelectedDatesCollection" />
 /// class.
 /// </summary>
 /// <param name="owner">
 /// The <see cref="T:System.Windows.Controls.Calendar" /> associated
 /// with this object.
 /// </param>
 public SelectedDatesExCollection(CalendarEx owner)
 {
     _owner            = owner;
     _addedItems       = new Collection <DateTime>();
     _dispatcherThread = Thread.CurrentThread;
 }
        /// <summary>
        /// Adds all the dates in the specified range, which includes the first
        /// and last dates, to the collection.
        /// </summary>
        /// <param name="start">The first date to add to the collection.</param>
        /// <param name="end">The last date to add to the collection.</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;

            _addedItems.Clear();

            rangeStart    = start;
            _isRangeAdded = true;

            if (_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 (CalendarEx.IsValidDateSelection(_owner, rangeStart))
                    {
                        Add(rangeStart.Value);
                    }
                    else
                    {
                        if (_owner.SelectionMode == CalendarExSelectionMode.SingleRange)
                        {
                            _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 (_owner.SelectionMode == CalendarExSelectionMode.SingleRange && Count > 0)
                {
                    foreach (DateTime item in this)
                    {
                        _owner.RemovedItems.Add(item);
                    }
                    ClearInternal();
                }

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

            _owner.OnSelectedDatesCollectionChanged(new SelectionChangedEventArgs(_owner.RemovedItems, _addedItems));
            _owner.RemovedItems.Clear();
            _owner.UpdateMonths();
            _isRangeAdded = false;
        }