private void OnCellClicked(MonthCellDescriptor cell) { var clickedDate = cell.DateTime; if (!IsBetweenDates(clickedDate, MinDate, MaxDate) || !IsSelectable(clickedDate)) { if (OnInvalidDateSelected != null) { OnInvalidDateSelected(this, new DateSelectedEventArgs(clickedDate)); } } else { bool wasSelected = DoSelectDate(clickedDate, cell); if (OnDateSelected != null) { if (wasSelected) { OnDateSelected(this, new DateSelectedEventArgs(clickedDate)); } else if (OnDateUnselected != null) { OnDateUnselected(this, new DateSelectedEventArgs(clickedDate)); } } } }
public MonthCellWithMonthIndex(MonthCellDescriptor cell, int monthIndex) { Cell = cell; MonthIndex = monthIndex; }
internal bool DoSelectDate(DateTime date, MonthCellDescriptor cell) { var newlySelectedDate = date; SetMidnight(newlySelectedDate); //Clear any remaining range state. foreach (var selectedCell in SelectedCells) { selectedCell.RangeState = RangeState.None; } switch (Mode) { case SelectionMode.Range: if (SelectedCals.Count > 1) { //We've already got a range selected: clear the old one. ClearOldSelection(); } else if (SelectedCals.Count == 1 && newlySelectedDate.CompareTo(SelectedCals[0]) < 0) { //We're moving the start of the range back in time: clear the old start date. ClearOldSelection(); } break; case SelectionMode.Multi: date = ApplyMultiSelect(date, newlySelectedDate); break; case SelectionMode.Single: ClearOldSelection(); break; default: throw new IllegalStateException("Unknown SelectionMode " + Mode); } if (date > DateTime.MinValue) { if (SelectedCells.Count == 0 || !SelectedCells[0].Equals(cell)) { SelectedCells.Add(cell); cell.IsSelected = true; } SelectedCals.Add(newlySelectedDate); if (Mode == SelectionMode.Range && SelectedCells.Count > 1) { //Select all days in between start and end. var startDate = SelectedCells[0].DateTime; var endDate = SelectedCells[1].DateTime; SelectedCells[0].RangeState = RangeState.First; SelectedCells[1].RangeState = RangeState.Last; foreach (var month in Cells) { foreach (var week in month) { foreach (var singleCell in week) { var singleCellDate = singleCell.DateTime; if (singleCellDate.CompareTo(startDate) >= 0 && singleCellDate.CompareTo(endDate) <= 0 && singleCell.IsSelectable) { singleCell.IsSelected = true; singleCell.RangeState = RangeState.Middle; SelectedCells.Add(singleCell); } } } } } } ValidateAndUpdate(); return(date > DateTime.MinValue); }