コード例 #1
0
        /// <summary>
        /// Called when [cell clicked].
        /// </summary>
        /// <param name="cell">The cell.</param>
        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));
                    }
                }
            }
        }
コード例 #2
0
        internal bool DoSelectDates(DateTime date, MonthCellDescriptor cell)
        {
            var newlySelectedDate = date;

            SetMidnight(newlySelectedDate);

            //Clear any remaining range state.
            foreach (var selectedCell in SelectedCells)
            {
                selectedCell.RangeState = RangeState.None;
            }


            date = ApplyMultiSelect(date, newlySelectedDate);


            if (date > DateTime.MinValue)
            {
                if (SelectedCells.Count == 0 || !SelectedCells[0].Equals(cell))
                {
                    cell.IsSelected            = true;
                    cell.IsSelectedDatesMarked = true;
                    SelectedCells.Add(cell);
                }
                SelectedCals.Add(newlySelectedDate);
            }
            ValidateAndUpdate();
            return(date > DateTime.MinValue);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MonthCellWithMonthIndex"/> class.
 /// </summary>
 /// <param name="cell">The cell.</param>
 /// <param name="monthIndex">Index of the month.</param>
 public MonthCellWithMonthIndex(MonthCellDescriptor cell, int monthIndex)
 {
     Cell       = cell;
     MonthIndex = monthIndex;
 }
コード例 #4
0
        /// <summary>
        /// Does the select date.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <param name="cell">The cell.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        /// <exception cref="Java.Lang.IllegalStateException">Unknown SelectionMode  + Mode</exception>
        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);
        }
コード例 #5
0
			/// <summary>
			/// Initializes a new instance of the <see cref="MonthCellWithMonthIndex"/> class.
			/// </summary>
			/// <param name="cell">The cell.</param>
			/// <param name="monthIndex">Index of the month.</param>
			public MonthCellWithMonthIndex(MonthCellDescriptor cell, int monthIndex)
			{
				Cell = cell;
				MonthIndex = monthIndex;
			}
コード例 #6
0
		/// <summary>
		/// Does the select date.
		/// </summary>
		/// <param name="date">The date.</param>
		/// <param name="cell">The cell.</param>
		/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
		/// <exception cref="Java.Lang.IllegalStateException">Unknown SelectionMode  + Mode</exception>
		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;
		}
コード例 #7
0
		/// <summary>
		/// Called when [cell clicked].
		/// </summary>
		/// <param name="cell">The cell.</param>
		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));
					}
				}
			}
		}