/// <summary> /// Called by DayButton /// </summary> /// <param name="date"></param> public void DayButtonClicked(DateTime date) { if (DateSelectionMode == Dates.DateSelectionMode.SingleDate) { SelectedDate = date; } else { if (SelectedDates.Any(d => d == date)) { SelectedDates.Remove(date); } else { SelectedDates.Add(date); } } if (Ref_DatePicker_DateRange != null) { Ref_DatePicker_DateRange.DateSelected(date); } if (Config.Events.OnDaySelected != null) { Config.Events.OnDaySelected.Invoke(date); } UpdateDisplay(); // I would have preferred to have this react automatically to changes, // but that would mean setting up an observable list, which is an added // complication we don't need right now UpdateInputFieldText(); }
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; }
private void OnSelectedDateChanged() { if (_dayPresenter == null) { return; } if (!_isInternalSet) { if (SelectedDates == null) { SelectedDates = new ObservableCollection <DateTime>(); } if (SelectedDate != null && !SelectedDates.Contains((DateTime)SelectedDate)) { _isInternalSet = true; SelectedDates.Add((DateTime)SelectedDate); _isInternalSet = false; } var date = SelectedDate ?? new DateTime(CurrentYear, CurrentMonth, 1); UpdateDays(date.Year, date.Month); UpdateMonths(date.Year, date.Month); UpdateYears(date.Year, date.Month); } RaiseSelectedDateChanged(); }
protected void SetButton(CalendarButton b, bool isFirst = false, bool isLast = false) { if (!SelectedDates.Contains(b.Date.Value.Date)) { SelectedDates.Add(b.Date.Value.Date); } var spD = SpecialDates?.FirstOrDefault(s => s.Date.Date == b.Date.Value.Date); SetButtonSelected(b, spD, isFirst, isLast); }
private void AddDateIfNotExist(DateTime date) { if (SpecialDates == null) { return; } if (!SelectedDates.Contains(date)) { SelectedDates.Add(date); } }
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 void calSelect_SelectionChanged(object sender, EventArgs e) { if (SelectedDates.Count() != 2 && calSelect.SelectedDate >= DateTime.Today) { if (!SelectedDates.Contains(calSelect.SelectedDate)) { SelectedDates.Add(calSelect.SelectedDate); } else { SelectedDates.Remove(calSelect.SelectedDate); } } else if (SelectedDates.Count() == 2 && SelectedDates.Contains(calSelect.SelectedDate)) { SelectedDates.Remove(calSelect.SelectedDate); } ViewState["SelectedDates"] = SelectedDates; int dayz = 0; if (SelectedDates.Count() == 2) { dayz = (SelectedDates[0] - SelectedDates[1]).Days; if (dayz < 0) { dayz = -dayz; lblDates.Text = SelectedDates[0].ToString("dd/MM/yyyy") + " - " + SelectedDates[1].ToString("dd/MM/yyyy"); } else { lblDates.Text = SelectedDates[1].Date.ToString("dd/MM/yyyy") + " - " + SelectedDates[0].Date.ToString("dd/MM/yyyy"); } txtDayz.Text = (dayz + 1).ToString(); } else if (SelectedDates.Count() == 1) { dayz = 1; txtDayz.Text = (dayz).ToString(); lblDates.Text = SelectedDates[0].ToString("dd/MM/yyyy"); } else { txtDayz.Text = "0"; lblDates.Text = ""; } }
public IActionResult OnGet([FromQuery] int year, [FromQuery] int month, [FromQuery] int day) { if (!ModelState.IsValid) { return(RedirectToPage("Index", new { year, month, day })); } StartTime = "09:00"; DurationMinutesForEachSlot = 30; CountOfSlotForEachSlot = 1; CountOfSlotsToCreate = 1; if (!SelectedDates.Any()) { SelectedDates.Add(LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd").Format(SelectedDate)); } return(PageResult(year, month, day)); }
private void OnDateLimitChanged() { _isInternalSet = true; if (SelectedDates == null) { SelectedDates = new ObservableCollection <DateTime>(); } if (SelectedDate != null && MinDate != null && SelectedDate < MinDate) { var date = (DateTime)SelectedDate; if (SelectedDates.Contains(date)) { SelectedDates.Remove(date); } SelectedDate = MinDate; SelectedDates.Add((DateTime)SelectedDate); } else if (SelectedDate != null && MaxDate != null && SelectedDate > MaxDate) { var date = (DateTime)SelectedDate; if (SelectedDates.Contains(date)) { SelectedDates.Remove(date); } SelectedDate = MaxDate; SelectedDates.Add((DateTime)SelectedDate); } if (SelectedDates != null) { for (int i = SelectedDates.Count - 1; i >= 0; i--) { var date = SelectedDates[i]; if (date < MinDate || date > MaxDate) { SelectedDates.RemoveAt(i); } } } UpdateDays(CurrentYear, CurrentMonth); UpdateMonths(CurrentYear, CurrentMonth); UpdateYears(CurrentYear, CurrentMonth); }
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); }
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; }
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); }
// ==================================================================== // 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) { } }