123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using System;
- using System.ComponentModel;
- using System.Windows.Forms;
- using FastReport.Utils;
- namespace FastReport.Dialog
- {
- /// <summary>
- /// Represents a Windows control that allows the user to select a date and a time and to display the date and time with a specified format.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker"/> control.
- /// </summary>
- public partial class DateTimePickerControl : DataFilterBaseControl
- {
- private DateTimePicker dateTimePicker;
- private string valueChangedEvent;
- #region Properties
- /// <summary>
- /// Occurs after the date has been changed.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.ValueChanged"/> event.
- /// </summary>
- public event EventHandler ValueChanged;
- /// <summary>
- /// Gets an internal <b>DateTimePicker</b>.
- /// </summary>
- [Browsable(false)]
- public DateTimePicker DateTimePicker
- {
- get { return dateTimePicker; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the Value property has been set with a valid date/time value and the displayed value is able to be updated.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.Checked"/> property.
- /// </summary>
- [DefaultValue(false)]
- [Category("Behavior")]
- public bool Checked
- {
- get { return DateTimePicker.Checked; }
- set { DateTimePicker.Checked = value; }
- }
- /// <summary>
- /// Gets or sets the custom date/time format string.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.CustomFormat"/> property.
- /// </summary>
- [Category("Data")]
- public string CustomFormat
- {
- get { return DateTimePicker.CustomFormat; }
- set { DateTimePicker.CustomFormat = value; }
- }
- /// <summary>
- /// Gets or sets the alignment of the drop-down calendar on the DateTimePicker control.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.DropDownAlign"/> property.
- /// </summary>
- [DefaultValue(LeftRightAlignment.Left)]
- [Category("Appearance")]
- public LeftRightAlignment DropDownAlign
- {
- get { return DateTimePicker.DropDownAlign; }
- set { DateTimePicker.DropDownAlign = value; }
- }
- /// <summary>
- /// Gets or sets the format of the date and time displayed in the control.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.Format"/> property.
- /// </summary>
- [DefaultValue(DateTimePickerFormat.Long)]
- [Category("Data")]
- public DateTimePickerFormat Format
- {
- get { return DateTimePicker.Format; }
- set { DateTimePicker.Format = value; }
- }
- /// <summary>
- /// Gets or sets the maximum date and time that can be selected in the control.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.MaxDate"/> property.
- /// </summary>
- [Category("Data")]
- public DateTime MaxDate
- {
- get { return DateTimePicker.MaxDate; }
- set { DateTimePicker.MaxDate = value; }
- }
- /// <summary>
- /// Gets or sets the minimum date and time that can be selected in the control.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.MinDate"/> property.
- /// </summary>
- [Category("Data")]
- public DateTime MinDate
- {
- get { return DateTimePicker.MinDate; }
- set { DateTimePicker.MinDate = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether a check box is displayed to the left of the selected date.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.ShowCheckBox"/> property.
- /// </summary>
- [DefaultValue(false)]
- [Category("Appearance")]
- public bool ShowCheckBox
- {
- get { return DateTimePicker.ShowCheckBox; }
- set { DateTimePicker.ShowCheckBox = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether a spin button control (also known as an up-down control) is used to adjust the date/time value.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.ShowUpDown"/> property.
- /// </summary>
- [DefaultValue(false)]
- [Category("Appearance")]
- public bool ShowUpDown
- {
- get { return DateTimePicker.ShowUpDown; }
- set { DateTimePicker.ShowUpDown = value; }
- }
- /// <summary>
- /// Gets or sets the date/time value assigned to the control.
- /// Wraps the <see cref="System.Windows.Forms.DateTimePicker.Value"/> property.
- /// </summary>
- [Category("Data")]
- public DateTime Value
- {
- get { return DateTimePicker.Value; }
- set { DateTimePicker.Value = value; }
- }
- /// <summary>
- /// Gets or sets a script method name that will be used to handle the
- /// <see cref="ValueChanged"/> event.
- /// </summary>
- [Category("Events")]
- public string ValueChangedEvent
- {
- get { return valueChangedEvent; }
- set { valueChangedEvent = value; }
- }
- #endregion
- #region Private Methods
- private void DateTimePicker_ValueChanged(object sender, EventArgs e)
- {
- OnValueChanged(e);
- }
- #endregion
- #region Protected Methods
- /// <inheritdoc/>
- protected override void AttachEvents()
- {
- base.AttachEvents();
- DateTimePicker.ValueChanged += DateTimePicker_ValueChanged;
- }
- /// <inheritdoc/>
- protected override void DetachEvents()
- {
- base.DetachEvents();
- DateTimePicker.ValueChanged -= DateTimePicker_ValueChanged;
- }
- /// <inheritdoc/>
- protected override object GetValue()
- {
- if (Format == DateTimePickerFormat.Long || Format == DateTimePickerFormat.Short)
- return new DateTime(Value.Year, Value.Month, Value.Day);
- return Value;
- }
- #endregion
- #region Public Methods
- /// <inheritdoc/>
- public override void Serialize(FRWriter writer)
- {
- DateTimePickerControl c = writer.DiffObject as DateTimePickerControl;
- base.Serialize(writer);
- if (Checked != c.Checked)
- writer.WriteBool("Checked", Checked);
- if (CustomFormat != c.CustomFormat)
- writer.WriteStr("CustomFormat", CustomFormat);
- if (DropDownAlign != c.DropDownAlign)
- writer.WriteValue("DropDownAlign", DropDownAlign);
- if (Format != c.Format)
- writer.WriteValue("Format", Format);
- if (MaxDate != c.MaxDate)
- writer.WriteValue("MaxDate", MaxDate);
- if (MinDate != c.MinDate)
- writer.WriteValue("MinDate", MinDate);
- if (ShowCheckBox != c.ShowCheckBox)
- writer.WriteBool("ShowCheckBox", ShowCheckBox);
- if (ShowUpDown != c.ShowUpDown)
- writer.WriteBool("ShowUpDown", ShowUpDown);
- if (Value != c.Value)
- writer.WriteValue("Value", Value);
- if (ValueChangedEvent != c.ValueChangedEvent)
- writer.WriteStr("ValueChangedEvent", ValueChangedEvent);
- }
- /// <summary>
- /// This method fires the <b>ValueChanged</b> event and the script code connected to the <b>ValueChangedEvent</b>.
- /// </summary>
- /// <param name="e">Event data.</param>
- public virtual void OnValueChanged(EventArgs e)
- {
- OnFilterChanged();
- if (ValueChanged != null)
- ValueChanged(this, e);
- InvokeEvent(ValueChangedEvent, e);
- }
- #endregion
- /// <summary>
- /// Initializes a new instance of the <b>DateTimePickerControl</b> class with default settings.
- /// </summary>
- public DateTimePickerControl()
- {
- dateTimePicker = new DateTimePicker();
- Control = dateTimePicker;
- BindableProperty = this.GetType().GetProperty("Value");
- }
- }
- }
|