Esempio n. 1
0
        private void YearPresenter_Selected(object sender, SelectedDateChangedEventArgs e)
        {
            var dateTime = (DateTime)e.SelectedDate;

            _isInternalSet = true;
            if (SelectedDates == null)
            {
                SelectedDates = new ObservableCollection <DateTime>();
            }
            switch (Mode)
            {
            case CalendarXMode.Date:
            case CalendarXMode.DateRange:
            case CalendarXMode.MultipleDate:
            case CalendarXMode.YearMonth:
                CurrentPanel = 1;
                break;

            case CalendarXMode.Year:
                SelectedDate = dateTime;
                SelectedDates.Clear();
                SelectedDates.Add(dateTime);
                break;
            }
            UpdateYears(dateTime.Year, dateTime.Month);
            UpdateMonths(dateTime.Year, dateTime.Month);
            UpdateDays(dateTime.Year, dateTime.Month);
            _isInternalSet = false;
        }
 public IActionResult OnPostClearSelection([FromQuery] int?year, [FromQuery] int?month, [FromQuery] int?day)
 {
     if (!year.HasValue || !month.HasValue || !day.HasValue)
     {
         return(RedirectToPage("Index", new { year, month, day }));
     }
     SelectedDates.Clear();
     return(PageResult(year.Value, month.Value, day.Value));
 }
Esempio n. 3
0
        protected bool ChangeSelectedDate(DateTime?date, bool clicked = true)
        {
            if (!date.HasValue)
            {
                return(false);
            }

            if (SelectedDates.Count() > 0)//check if there is a selected date
            {
                int result = DateTime.Compare((System.DateTime)date, SelectedDates[0]);
                if (result == 0)//Equal Dates
                {
                    return(false);
                }
            }


            if (!MultiSelectDates)
            {
                buttons.FindAll(b => b.IsSelected).ForEach(b => ResetButton(b));
                SelectedDates.Clear();
            }

            SelectedDates.Add(SelectedDate.Value.Date);

            var button = buttons.Find(b => b.Date.HasValue && b.Date.Value.Date == date.Value.Date && b.IsEnabled);

            if (button == null)
            {
                return(false);
            }
            var deselect = button.IsSelected;

            if (button.IsSelected)
            {
                ResetButton(button);
            }
            else
            {
                SelectedDates.Add(SelectedDate.Value.Date);
                var spD = SpecialDates?.FirstOrDefault(s => s.Date.Date == button.Date.Value.Date);
                SetButtonSelected(button, spD);
            }
            if (clicked)
            {
                DateClicked?.Invoke(this, new DateTimeEventArgs {
                    DateTime = SelectedDate.Value
                });
                DateCommand?.Execute(SelectedDate.Value);
            }
            return(deselect);
        }
        public IActionResult OnPostSelectAll([FromQuery] int?year, [FromQuery] int?month, [FromQuery] int?day)
        {
            if (!year.HasValue || !month.HasValue || !day.HasValue)
            {
                return(RedirectToPage("Index", new { year, month, day }));
            }
            var pageResult = PageResult(year.Value, month.Value, day.Value);

            SelectedDates.Clear();
            foreach (var date in SelectedDate.ToYearMonth().ToDateInterval())
            {
                SelectedDates.Add(LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd").Format(date));
            }
            return(pageResult);
        }
        protected bool ChangeSelectedDate(DateTime?date, bool clicked = true)
        {
            if (!date.HasValue)
            {
                return(false);
            }

            if (!MultiSelectDates)
            {
                buttons.FindAll(b => b.IsSelected).ForEach(b => ResetButton(b));
                SelectedDates.Clear();
            }

            AddDateIfNotExist(SelectedDate.Value.Date);

            var button = buttons.Find(b => b.Date.HasValue && b.Date.Value.Date == date.Value.Date && b.IsEnabled);

            if (button == null)
            {
                return(false);
            }
            var deselect = button.IsSelected;

            if (button.IsSelected)
            {
                ResetButton(button);
            }
            else
            {
                AddDateIfNotExist(SelectedDate.Value.Date);
                var spD = SpecialDates?.FirstOrDefault(s => s.Date.Date == button.Date.Value.Date);
                SetButtonSelected(button, spD);
            }
            if (clicked)
            {
                DateClicked?.Invoke(this, new DateTimeEventArgs {
                    DateTime = SelectedDate.Value
                });
                DateCommand?.Execute(SelectedDate.Value);
            }
            return(deselect);
        }
Esempio n. 6
0
        public bool AddSelectedDate(DateTime currentDate)
        {
            SetCurrentValue(SelectedDateProperty, currentDate);

            _isInternalSet = true;
            if (SelectedDates == null)
            {
                var selectedDates = new SelectedDatesCollection(this);
                selectedDates.Add(currentDate);
                SetCurrentValue(SelectedDatesProperty, selectedDates);
            }
            else
            {
                SelectedDates.Clear();
                SelectedDates.Add(currentDate);
            }
            _isInternalSet = false;

            return(true);
        }
Esempio n. 7
0
        private void DayPresenter_Selected(object sender, SelectedDateChangedEventArgs e)
        {
            var dateTime = (DateTime)e.SelectedDate;

            _isInternalSet = true;
            if (SelectedDates == null)
            {
                SelectedDates = new ObservableCollection <DateTime>();
            }
            switch (Mode)
            {
            case CalendarXMode.MultipleDate:
                if (!SelectedDates.Any(x => x.Date.Equals(dateTime)))
                {
                    SelectedDates.Add(dateTime);
                }
                break;

            case CalendarXMode.Date:
                SelectedDates.Clear();
                SelectedDates.Add(dateTime);
                break;

            case CalendarXMode.DateRange:
                for (int i = 0; i < SelectedDates.Count - 1; i++)
                {
                    SelectedDates.RemoveAt(0);
                }
                SelectedDates.Add(dateTime);
                break;
            }

            SelectedDate = dateTime;
            UpdateDays(dateTime.Year, dateTime.Month);
            _isInternalSet = false;
        }
Esempio n. 8
0
        protected bool ChangeSelectedDate(DateTime?date, bool clicked = true)
        {
            if (!date.HasValue)
            {
                return(false);
            }

            if (!MultiSelectDates)
            {
                buttons.FindAll(b => b.IsSelected).ForEach(b => ResetButton(b));
                SelectedDates?.Clear();
            }

            if (MinDate.HasValue && date.Value < MinDate.Value)
            {
                return(false);
            }

            if (buttons.Count == 0)
            {
                SelectedDates?.Add(SelectedDate.Value.Date);
            }

            var button = buttons.Find(b => b.Date.HasValue && b.Date.Value.Date == date.Value.Date && b.IsEnabled);

            if (button == null)
            {
                return(false);
            }
            var deselect = button.IsSelected;

            if (button.IsSelected)
            {
                if (SelectRange && SelectedDates?.Count() > 2)
                {
                    UnfillSelectedRange(SelectedDate.Value.Date);
                }
                else
                {
                    ResetButton(button);
                    if (SelectedDates?.Count() == 1)
                    {
                        button = buttons.Find(b => b.Date.HasValue && b.Date.Value.Date == SelectedDates?.First() && b.IsEnabled);
                        if (button != null)
                        {
                            SetButton(button);
                        }
                    }
                }
            }
            else
            {
                if (SelectedDates != null)
                {
                    if (SelectRange && SelectedDates.Any())
                    {
                        FillSelectedRange(SelectedDate.Value.Date);
                    }
                    else
                    {
                        SelectedDates?.Add(SelectedDate.Value.Date);
                        var spD = SpecialDates?.FirstOrDefault(s => s.Date.Date == button.Date.Value.Date);
                        SetButtonSelected(button, spD);
                    }
                }
            }
            if (clicked)
            {
                DateClicked?.Invoke(this, new DateTimeEventArgs {
                    DateTime = SelectedDate.Value
                });
                DateCommand?.Execute(SelectedDate.Value);
            }
            return(deselect);
        }
Esempio n. 9
0
            // ====================================================================
            // Implementation of the IPostBackEventHandler.RaisePostBackEvent
            // event handler.
            // ====================================================================

            /// <summary>
            ///     Handles a post back event targeted at the control.
            /// </summary>
            /// <param name="eventArgument">
            ///     A <see cref="System.String" /> representing the event argument passed to the handler.
            /// </param>
            public new void RaisePostBackEvent(string eventArgument)
            {
                // Was the post back initiated by a previous or next month link
                if (eventArgument.StartsWith("V"))
                {
                    try
                    {
                        // Save the current visible date.
                        var previousDate = TargetDate;

                        // Extract the day count from the argument and use it to
                        // change the visible date.
                        var d = int.Parse(eventArgument.Substring(1));
                        VisibleDate = DateFromDayCount(d);

                        // Raise the VisibleMonthChanged event.
                        OnVisibleMonthChanged(VisibleDate, previousDate);
                    }
                    // ReSharper disable once EmptyGeneralCatchClause
                    catch (Exception)
                    { }
                    return;
                }

                // Was the post back initiated by a month or week selector link
                if (eventArgument.StartsWith("R"))
                {
                    try
                    {
                        // Extract the day count and number of days from the
                        // argument.
                        var d = int.Parse(eventArgument.Substring(1, eventArgument.Length - 3));
                        var n = int.Parse(eventArgument.Substring(eventArgument.Length - 2));

                        // Get the starting date.
                        var date = DateFromDayCount(d);

                        // Reset the selected dates collection to include all the
                        // dates in the given range.
                        SelectedDates.Clear();
                        SelectedDates.SelectRange(date, date.AddDays(n - 1));

                        // // If SelectAllInRange is false, remove any dates found
                        // // in the nonselectable date list.
                        // if (!this.SelectAllInRange)
                        // {
                        // ArrayList nonselectableDates = this.LoadNonselectableDates();
                        // foreach(DateTime badDate in nonselectableDates)
                        // this.SelectedDates.Remove(badDate);
                        // }

                        // Raise the SelectionChanged event.
                        OnSelectionChanged();
                    }
                    catch (Exception)
                    { }
                    return;
                }

                // The post back must have been initiated by a calendar day link.
                try
                {
                    // Get the day count from the argument.
                    var d = int.Parse(eventArgument);

                    // Reset the selected dates collection to include only the
                    // newly selected date.
                    SelectedDates.Clear();
                    SelectedDates.Add(DateFromDayCount(d));

                    // Raise the SelectionChanged event.
                    OnSelectionChanged();
                }
                catch (Exception)
                { }
            }
Esempio n. 10
0
 public void ClearButtonSelection()
 {
     buttons.FindAll(b => b.IsSelected).ForEach(b => ResetButton(b));
     SelectedDates.Clear();
     SelectedDate = null;
 }