using System;
using System.Globalization;
using FastReport.Dialog;
using System.Windows.Forms;
using static FastReport.Web.Constants;
namespace FastReport.Web
{
public partial class Dialog
{
///
/// Gets or sets date format in html input type="date"
///
public static string DatePickerFormat {
get;
set;
} = DEFAULT_DATE_PICKER_FORMAT;
///
/// Gets or sets time format in html input type="time"
///
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 = $"";
}
else if (control.Format == DateTimePickerFormat.Time)
{
// we draw only time
var timeValue = control.Value.ToString(TimePickerFormat);
time = $"";
}
else
{
// we draw date and time in one container
date = $"";
var timeValue = control.Value.ToString(TimePickerFormat);
time = $"";
}
string datetimepicker = $"
" +
date +
time +
"
";
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)}";
}
}
}