123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using System;
- using System.Globalization;
- using FastReport.Dialog;
- using System.Windows.Forms;
- using static FastReport.Web.Constants;
- namespace FastReport.Web
- {
- public partial class Dialog
- {
- /// <summary>
- /// Gets or sets date format in html input type="date"
- /// </summary>
- public static string DatePickerFormat {
- get;
- set;
- } = DEFAULT_DATE_PICKER_FORMAT;
- /// <summary>
- /// Gets or sets time format in html input type="time"
- /// </summary>
- public static string TimePickerFormat
- {
- get;
- set;
- } = DEFAULT_TIME_PICKER_FORMAT;
- private void DateTimePickerChangeDate(DateTimePickerControl dp, string value)
- {
- DateTime oldValue = dp.Value;
- DateTime parsedValue = DateTime.Parse(value);
- DateTime newDateTime = new DateTime(
- parsedValue.Year,
- parsedValue.Month,
- parsedValue.Day,
- oldValue.Hour,
- oldValue.Minute,
- oldValue.Second,
- oldValue.Kind);
- dp.Value = newDateTime;
- dp.OnValueChanged(null);
- }
- private void DateTimePickerChangeTime(DateTimePickerControl dp, string value)
- {
- DateTime oldValue = dp.Value;
- DateTime parsedValue = DateTime.Parse(value);
- DateTime newDateTime = new DateTime(
- oldValue.Year,
- oldValue.Month,
- oldValue.Day,
- parsedValue.Hour,
- parsedValue.Minute,
- parsedValue.Second,
- oldValue.Kind);
- dp.Value = newDateTime;
- dp.OnValueChanged(null);
- }
- private string OnChangeDate(DateTimePickerControl control, bool needReload = true)
- {
- return OnChangeDateTimePicker(control, "-date", needReload);
- }
- private string OnChangeTime(DateTimePickerControl control, bool needReload = true)
- {
- return OnChangeDateTimePicker(control, "-time", needReload);
- }
- private string OnChangeDateTimePicker(DateTimePickerControl control, string suffix, bool needReload)
- {
- var eventType = needReload ? ONCHANGE : ONBLUR;
- return $"{eventType}=\"{GetEvent(ONCHANGE, control.Name + suffix, needReload ? SILENT_RELOAD : DIALOG, $"this.value")}\"";
- }
- private string GetDateTimePickerHtml(DateTimePickerControl control)
- {
- control.FillData();
- ControlFilterRefresh(control);
- string id = GetControlID(control);
- string date = string.Empty;
- string time = string.Empty;
- string disabled = control.Enabled ? "" : "disabled";
- bool needUpdate = NeedRefresh(control);
- if (control.Format == DateTimePickerFormat.Short)
- {
- // we draw only date
- date = $"<input style=\"{GetDateTimePickerStyle(control)}\"" +
- $" type=\"date\" value=\"{control.Value.ToString(DatePickerFormat)}\"" +
- $" {OnChangeDate(control, needUpdate)}" +
- $" id=\"{id}-date\" {disabled} required/>";
- }
- else if (control.Format == DateTimePickerFormat.Time)
- {
- // we draw only time
- var timeValue = control.Value.ToString(TimePickerFormat);
- time = $"<input style=\"{GetDateTimePickerStyle(control)} min-width:5rem;\"" +
- $" type=\"time\" value=\"{timeValue}\"" +
- $" {OnChangeTime(control, needUpdate)}" +
- $" id=\"{id}-time\" {disabled} required/>";
- }
- else
- {
- // we draw date and time in one container
- date = $"<input style=\"{GetControlFont(control.Font)} {GetBackColor(control.BackColor)} border-right-width:0px; padding-right:0px\"" +
- $" type=\"date\" value=\"{control.Value.ToString(DatePickerFormat)}\"" +
- $" {OnChangeDate(control, needUpdate)}" +
- $" id=\"{id}-date\" {disabled} required/>";
- var timeValue = control.Value.ToString(TimePickerFormat);
- time = $"<input style=\"{GetControlFont(control.Font)} {GetBackColor(control.BackColor)} border-left-width:0px; padding-left:0px; min-width:5rem;\"" +
- $" type=\"time\" value=\"{timeValue}\"" +
- $" {OnChangeTime(control, needUpdate)}" +
- $" id=\"{id}-time\" {disabled} required/>";
- }
- string datetimepicker = $"<div class=\"datetimepicker\" name=\"{control.Name}\" style=\"{GetDateTimePickerDivStyle(control)}\">" +
- date +
- time +
- "</div>";
- return datetimepicker;
- }
- private string GetDateTimePickerDivStyle(DateTimePickerControl control)
- {
- return $"{GetControlPosition(control)} display:inline-flex";
- }
- private string GetDateTimePickerStyle(DateTimePickerControl control)
- {
- return $"{GetControlFont(control.Font)} {GetBackColor(control.BackColor)}";
- }
- }
- }
|