MonthCalendarControl.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using FastReport.Utils;
  5. using System.Windows.Forms;
  6. namespace FastReport.Dialog
  7. {
  8. /// <summary>
  9. /// Represents a Windows control that enables the user to select a date using a visual monthly calendar display.
  10. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar"/> control.
  11. /// </summary>
  12. public partial class MonthCalendarControl : DataFilterBaseControl
  13. {
  14. private MonthCalendar monthCalendar;
  15. private string dateChangedEvent;
  16. #region Properties
  17. /// <summary>
  18. /// Occurs when the date selected in the MonthCalendar changes.
  19. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.DateChanged"/> event.
  20. /// </summary>
  21. public event DateRangeEventHandler DateChanged;
  22. /// <summary>
  23. /// Gets an internal <b>MonthCalendar</b>.
  24. /// </summary>
  25. [Browsable(false)]
  26. public MonthCalendar MonthCalendar
  27. {
  28. get { return monthCalendar; }
  29. }
  30. /// <summary>
  31. /// Gets or sets the number of columns and rows of months displayed.
  32. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.CalendarDimensions"/> property.
  33. /// </summary>
  34. [Category("Layout")]
  35. public Size CalendarDimensions
  36. {
  37. get { return MonthCalendar.CalendarDimensions; }
  38. set { MonthCalendar.CalendarDimensions = value; }
  39. }
  40. /// <summary>
  41. /// Gets or sets the first day of the week as displayed in the month calendar.
  42. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.FirstDayOfWeek"/> property.
  43. /// </summary>
  44. [DefaultValue(Day.Default)]
  45. [Category("Data")]
  46. public Day FirstDayOfWeek
  47. {
  48. get { return MonthCalendar.FirstDayOfWeek; }
  49. set { MonthCalendar.FirstDayOfWeek = value; }
  50. }
  51. /// <summary>
  52. /// Gets or sets the maximum allowable date.
  53. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.MaxDate"/> property.
  54. /// </summary>
  55. [Category("Data")]
  56. public DateTime MaxDate
  57. {
  58. get { return MonthCalendar.MaxDate; }
  59. set { MonthCalendar.MaxDate = value; }
  60. }
  61. /// <summary>
  62. /// Gets or sets the maximum number of days that can be selected in a month calendar control.
  63. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.MaxSelectionCount"/> property.
  64. /// </summary>
  65. [DefaultValue(7)]
  66. [Category("Data")]
  67. public int MaxSelectionCount
  68. {
  69. get { return MonthCalendar.MaxSelectionCount; }
  70. set { MonthCalendar.MaxSelectionCount = value; }
  71. }
  72. /// <summary>
  73. /// Gets or sets the minimum allowable date.
  74. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.MinDate"/> property.
  75. /// </summary>
  76. [Category("Data")]
  77. public DateTime MinDate
  78. {
  79. get { return MonthCalendar.MinDate; }
  80. set { MonthCalendar.MinDate = value; }
  81. }
  82. /// <summary>
  83. /// Gets or sets a value indicating whether the date represented by the <b>TodayDate</b> property is displayed at the bottom of the control.
  84. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.ShowToday"/> property.
  85. /// </summary>
  86. [DefaultValue(true)]
  87. [Category("Appearance")]
  88. public bool ShowToday
  89. {
  90. get { return MonthCalendar.ShowToday; }
  91. set { MonthCalendar.ShowToday = value; }
  92. }
  93. /// <summary>
  94. /// Gets or sets a value indicating whether today's date is circled.
  95. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.ShowTodayCircle"/> property.
  96. /// </summary>
  97. [DefaultValue(true)]
  98. [Category("Appearance")]
  99. public bool ShowTodayCircle
  100. {
  101. get { return MonthCalendar.ShowTodayCircle; }
  102. set { MonthCalendar.ShowTodayCircle = value; }
  103. }
  104. /// <summary>
  105. /// Gets or sets a value indicating whether the month calendar control displays week numbers (1-52) to the left of each row of days.
  106. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.ShowWeekNumbers"/> property.
  107. /// </summary>
  108. [DefaultValue(false)]
  109. [Category("Appearance")]
  110. public bool ShowWeekNumbers
  111. {
  112. get { return MonthCalendar.ShowWeekNumbers; }
  113. set { MonthCalendar.ShowWeekNumbers = value; }
  114. }
  115. /// <summary>
  116. /// Gets or sets the value that is used by MonthCalendar as today's date.
  117. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.TodayDate"/> property.
  118. /// </summary>
  119. [Category("Data")]
  120. public DateTime TodayDate
  121. {
  122. get { return MonthCalendar.TodayDate; }
  123. set { MonthCalendar.TodayDate = value; }
  124. }
  125. /// <summary>
  126. /// Gets or sets the array of DateTime objects that determines which annual days are displayed in bold.
  127. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.AnnuallyBoldedDates"/> property.
  128. /// </summary>
  129. [Browsable(false)]
  130. public DateTime[] AnnuallyBoldedDates
  131. {
  132. get { return MonthCalendar.AnnuallyBoldedDates; }
  133. set { MonthCalendar.AnnuallyBoldedDates = value; }
  134. }
  135. /// <summary>
  136. /// Gets or sets the array of DateTime objects that determines which nonrecurring dates are displayed in bold.
  137. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.BoldedDates"/> property.
  138. /// </summary>
  139. [Browsable(false)]
  140. public DateTime[] BoldedDates
  141. {
  142. get { return MonthCalendar.BoldedDates; }
  143. set { MonthCalendar.BoldedDates = value; }
  144. }
  145. /// <summary>
  146. /// Gets or sets the array of DateTime objects that determine which monthly days to bold.
  147. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.MonthlyBoldedDates"/> property.
  148. /// </summary>
  149. [Browsable(false)]
  150. public DateTime[] MonthlyBoldedDates
  151. {
  152. get { return MonthCalendar.MonthlyBoldedDates; }
  153. set { MonthCalendar.MonthlyBoldedDates = value; }
  154. }
  155. /// <summary>
  156. /// Gets or sets the end date of the selected range of dates.
  157. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.SelectionEnd"/> property.
  158. /// </summary>
  159. [Browsable(false)]
  160. public DateTime SelectionEnd
  161. {
  162. get { return MonthCalendar.SelectionEnd; }
  163. set { MonthCalendar.SelectionEnd = value; }
  164. }
  165. /// <summary>
  166. /// Gets or sets the selected range of dates for a month calendar control.
  167. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.SelectionRange"/> property.
  168. /// </summary>
  169. [Browsable(false)]
  170. public SelectionRange SelectionRange
  171. {
  172. get { return MonthCalendar.SelectionRange; }
  173. set { MonthCalendar.SelectionRange = value; }
  174. }
  175. /// <summary>
  176. /// Gets or sets the start date of the selected range of dates.
  177. /// Wraps the <see cref="System.Windows.Forms.MonthCalendar.SelectionStart"/> property.
  178. /// </summary>
  179. [Browsable(false)]
  180. public DateTime SelectionStart
  181. {
  182. get { return MonthCalendar.SelectionStart; }
  183. set { MonthCalendar.SelectionStart = value; }
  184. }
  185. /// <summary>
  186. /// Gets or sets a script method name that will be used to handle the
  187. /// <see cref="DateChanged"/> event.
  188. /// </summary>
  189. public string DateChangedEvent
  190. {
  191. get { return dateChangedEvent; }
  192. set { dateChangedEvent = value; }
  193. }
  194. #endregion
  195. #region Private Methods
  196. private void MonthCalendar_DateChanged(object sender, DateRangeEventArgs e)
  197. {
  198. OnDateChanged(e);
  199. }
  200. #endregion
  201. #region Protected Methods
  202. /// <inheritdoc/>
  203. protected override void AttachEvents()
  204. {
  205. base.AttachEvents();
  206. MonthCalendar.DateChanged += new DateRangeEventHandler(MonthCalendar_DateChanged);
  207. }
  208. /// <inheritdoc/>
  209. protected override void DetachEvents()
  210. {
  211. base.DetachEvents();
  212. MonthCalendar.DateChanged -= new DateRangeEventHandler(MonthCalendar_DateChanged);
  213. }
  214. /// <inheritdoc/>
  215. protected override object GetValue()
  216. {
  217. return new DateTime[] { SelectionStart, SelectionEnd };
  218. }
  219. #endregion
  220. #region Public Methods
  221. /// <inheritdoc/>
  222. public override void Serialize(FRWriter writer)
  223. {
  224. MonthCalendarControl c = writer.DiffObject as MonthCalendarControl;
  225. base.Serialize(writer);
  226. if (CalendarDimensions != c.CalendarDimensions)
  227. writer.WriteValue("CalendarDimensions", CalendarDimensions);
  228. if (FirstDayOfWeek != c.FirstDayOfWeek)
  229. writer.WriteValue("FirstDayOfWeek", FirstDayOfWeek);
  230. if (MaxDate != c.MaxDate)
  231. writer.WriteValue("MaxDate", MaxDate);
  232. if (MaxSelectionCount != c.MaxSelectionCount)
  233. writer.WriteInt("MaxSelectionCount", MaxSelectionCount);
  234. if (MinDate != c.MinDate)
  235. writer.WriteValue("MinDate", MinDate);
  236. if (ShowToday != c.ShowToday)
  237. writer.WriteBool("ShowToday", ShowToday);
  238. if (ShowTodayCircle != c.ShowTodayCircle)
  239. writer.WriteBool("ShowTodayCircle", ShowTodayCircle);
  240. if (ShowWeekNumbers != c.ShowWeekNumbers)
  241. writer.WriteBool("ShowWeekNumbers", ShowWeekNumbers);
  242. if (TodayDate != c.TodayDate)
  243. writer.WriteValue("TodayDate", TodayDate);
  244. if (DateChangedEvent != c.DateChangedEvent)
  245. writer.WriteStr("DateChangedEvent", DateChangedEvent);
  246. }
  247. /// <summary>
  248. /// This method fires the <b>DateChanged</b> event and the script code connected to the <b>DateChangedEvent</b>.
  249. /// </summary>
  250. /// <param name="e">Event data.</param>
  251. public virtual void OnDateChanged(DateRangeEventArgs e)
  252. {
  253. OnFilterChanged();
  254. if (DateChanged != null)
  255. DateChanged(this, e);
  256. InvokeEvent(DateChangedEvent, e);
  257. }
  258. #endregion
  259. /// <summary>
  260. /// Initializes a new instance of the <b>MonthCalendarControl</b> class with default settings.
  261. /// </summary>
  262. public MonthCalendarControl()
  263. {
  264. monthCalendar = new MonthCalendar();
  265. Control = monthCalendar;
  266. }
  267. }
  268. }