using System; using System.ComponentModel; using System.Drawing; using FastReport.Utils; using System.Windows.Forms; namespace FastReport.Dialog { /// /// Represents a Windows control that enables the user to select a date using a visual monthly calendar display. /// Wraps the control. /// public partial class MonthCalendarControl : DataFilterBaseControl { private MonthCalendar monthCalendar; private string dateChangedEvent; #region Properties /// /// Occurs when the date selected in the MonthCalendar changes. /// Wraps the event. /// public event DateRangeEventHandler DateChanged; /// /// Gets an internal MonthCalendar. /// [Browsable(false)] public MonthCalendar MonthCalendar { get { return monthCalendar; } } /// /// Gets or sets the number of columns and rows of months displayed. /// Wraps the property. /// [Category("Layout")] public Size CalendarDimensions { get { return MonthCalendar.CalendarDimensions; } set { MonthCalendar.CalendarDimensions = value; } } /// /// Gets or sets the first day of the week as displayed in the month calendar. /// Wraps the property. /// [DefaultValue(Day.Default)] [Category("Data")] public Day FirstDayOfWeek { get { return MonthCalendar.FirstDayOfWeek; } set { MonthCalendar.FirstDayOfWeek = value; } } /// /// Gets or sets the maximum allowable date. /// Wraps the property. /// [Category("Data")] public DateTime MaxDate { get { return MonthCalendar.MaxDate; } set { MonthCalendar.MaxDate = value; } } /// /// Gets or sets the maximum number of days that can be selected in a month calendar control. /// Wraps the property. /// [DefaultValue(7)] [Category("Data")] public int MaxSelectionCount { get { return MonthCalendar.MaxSelectionCount; } set { MonthCalendar.MaxSelectionCount = value; } } /// /// Gets or sets the minimum allowable date. /// Wraps the property. /// [Category("Data")] public DateTime MinDate { get { return MonthCalendar.MinDate; } set { MonthCalendar.MinDate = value; } } /// /// Gets or sets a value indicating whether the date represented by the TodayDate property is displayed at the bottom of the control. /// Wraps the property. /// [DefaultValue(true)] [Category("Appearance")] public bool ShowToday { get { return MonthCalendar.ShowToday; } set { MonthCalendar.ShowToday = value; } } /// /// Gets or sets a value indicating whether today's date is circled. /// Wraps the property. /// [DefaultValue(true)] [Category("Appearance")] public bool ShowTodayCircle { get { return MonthCalendar.ShowTodayCircle; } set { MonthCalendar.ShowTodayCircle = value; } } /// /// Gets or sets a value indicating whether the month calendar control displays week numbers (1-52) to the left of each row of days. /// Wraps the property. /// [DefaultValue(false)] [Category("Appearance")] public bool ShowWeekNumbers { get { return MonthCalendar.ShowWeekNumbers; } set { MonthCalendar.ShowWeekNumbers = value; } } /// /// Gets or sets the value that is used by MonthCalendar as today's date. /// Wraps the property. /// [Category("Data")] public DateTime TodayDate { get { return MonthCalendar.TodayDate; } set { MonthCalendar.TodayDate = value; } } /// /// Gets or sets the array of DateTime objects that determines which annual days are displayed in bold. /// Wraps the property. /// [Browsable(false)] public DateTime[] AnnuallyBoldedDates { get { return MonthCalendar.AnnuallyBoldedDates; } set { MonthCalendar.AnnuallyBoldedDates = value; } } /// /// Gets or sets the array of DateTime objects that determines which nonrecurring dates are displayed in bold. /// Wraps the property. /// [Browsable(false)] public DateTime[] BoldedDates { get { return MonthCalendar.BoldedDates; } set { MonthCalendar.BoldedDates = value; } } /// /// Gets or sets the array of DateTime objects that determine which monthly days to bold. /// Wraps the property. /// [Browsable(false)] public DateTime[] MonthlyBoldedDates { get { return MonthCalendar.MonthlyBoldedDates; } set { MonthCalendar.MonthlyBoldedDates = value; } } /// /// Gets or sets the end date of the selected range of dates. /// Wraps the property. /// [Browsable(false)] public DateTime SelectionEnd { get { return MonthCalendar.SelectionEnd; } set { MonthCalendar.SelectionEnd = value; } } /// /// Gets or sets the selected range of dates for a month calendar control. /// Wraps the property. /// [Browsable(false)] public SelectionRange SelectionRange { get { return MonthCalendar.SelectionRange; } set { MonthCalendar.SelectionRange = value; } } /// /// Gets or sets the start date of the selected range of dates. /// Wraps the property. /// [Browsable(false)] public DateTime SelectionStart { get { return MonthCalendar.SelectionStart; } set { MonthCalendar.SelectionStart = value; } } /// /// Gets or sets a script method name that will be used to handle the /// event. /// public string DateChangedEvent { get { return dateChangedEvent; } set { dateChangedEvent = value; } } #endregion #region Private Methods private void MonthCalendar_DateChanged(object sender, DateRangeEventArgs e) { OnDateChanged(e); } #endregion #region Protected Methods /// protected override void AttachEvents() { base.AttachEvents(); MonthCalendar.DateChanged += new DateRangeEventHandler(MonthCalendar_DateChanged); } /// protected override void DetachEvents() { base.DetachEvents(); MonthCalendar.DateChanged -= new DateRangeEventHandler(MonthCalendar_DateChanged); } /// protected override object GetValue() { return new DateTime[] { SelectionStart, SelectionEnd }; } #endregion #region Public Methods /// public override void Serialize(FRWriter writer) { MonthCalendarControl c = writer.DiffObject as MonthCalendarControl; base.Serialize(writer); if (CalendarDimensions != c.CalendarDimensions) writer.WriteValue("CalendarDimensions", CalendarDimensions); if (FirstDayOfWeek != c.FirstDayOfWeek) writer.WriteValue("FirstDayOfWeek", FirstDayOfWeek); if (MaxDate != c.MaxDate) writer.WriteValue("MaxDate", MaxDate); if (MaxSelectionCount != c.MaxSelectionCount) writer.WriteInt("MaxSelectionCount", MaxSelectionCount); if (MinDate != c.MinDate) writer.WriteValue("MinDate", MinDate); if (ShowToday != c.ShowToday) writer.WriteBool("ShowToday", ShowToday); if (ShowTodayCircle != c.ShowTodayCircle) writer.WriteBool("ShowTodayCircle", ShowTodayCircle); if (ShowWeekNumbers != c.ShowWeekNumbers) writer.WriteBool("ShowWeekNumbers", ShowWeekNumbers); if (TodayDate != c.TodayDate) writer.WriteValue("TodayDate", TodayDate); if (DateChangedEvent != c.DateChangedEvent) writer.WriteStr("DateChangedEvent", DateChangedEvent); } /// /// This method fires the DateChanged event and the script code connected to the DateChangedEvent. /// /// Event data. public virtual void OnDateChanged(DateRangeEventArgs e) { OnFilterChanged(); if (DateChanged != null) DateChanged(this, e); InvokeEvent(DateChangedEvent, e); } #endregion /// /// Initializes a new instance of the MonthCalendarControl class with default settings. /// public MonthCalendarControl() { monthCalendar = new MonthCalendar(); Control = monthCalendar; } } }