123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using FastReport.Dialog;
- using System;
- using System.ComponentModel;
- using System.Globalization;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace FastReport.Web
- {
- public partial class WebReport : WebControl, INamingContainer
- {
- /// <summary>
- /// Gets or sets date time format in jqueryui datepicker style
- /// </summary>
- [DefaultValue(WebReportProperties.DEFAULT_DATE_TIME_PICKER_FORMAT)]
- [Category("Data")]
- [Browsable(true)]
- public string DateTimePickerFormat
- {
- get { return Prop.DateTimePickerFormat; }
- set { Prop.DateTimePickerFormat = value; }
- }
-
- private void DateTimePickerChange(DateTimePickerControl dp, string value)
- {
- dp.Value = DateTime.ParseExact(value, "d", CultureInfo.InvariantCulture);
- }
- private string GetDateTimePickerHtml(DateTimePickerControl control)
- {
- control.FillData();
- ControlFilterRefresh(control);
- string id = Prop.ControlID + control.Name;
- StringBuilder html = new StringBuilder();
- if(DateTimePickerFormat == null || DateTimePickerFormat == "" || DateTimePickerFormat == WebReportProperties.DEFAULT_DATE_TIME_PICKER_FORMAT)
- {
- string s = control.Value.Month.ToString() + "/" + control.Value.Day.ToString() + "/" + control.Value.Year.ToString();
- string ev = GetEvent("onchange", control, string.Format("document.getElementById('{0}').value", id));
- html.AppendFormat("<input type=\"text\" value=\"{4}\" class=\"{0}\" style=\"{1}\" onchange=\"{2}\" id=\"{3}\" {5}/>",
- "",
- GetDateTimePickerStyle(control),
- ev,
- id,
- s,
- control.Enabled ? "" : "disabled"
- );
- html.Append("<script>$(function() {$( \"#").Append(id).Append("\" ).datepicker();");
- html.Append("$( \"#").Append(id).Append("\" ).datepicker( \"option\", \"dateFormat\", \"").
- Append(WebReportProperties.DEFAULT_DATE_TIME_PICKER_FORMAT).Append("\" );");
- html.Append("});</script>");
- }
- else
- {
- string value = "(function(){{ var tStr = function(k){{ if( k < 10) return '0' + k; return k; }}; var dateTime=$('#{0}').datepicker('getDate'); if(dateTime) return tStr(dateTime.getMonth() + 1 ) + '/' + tStr(dateTime.getDate()) + '/' + tStr(dateTime.getFullYear()); return '01/01/2019';}})()";
- string ev = GetEvent("onchange", control, string.Format(value, id));
- html.AppendFormat("<input type=\"text\" class=\"{0}\" style=\"{1}\" onchange=\"{2}\" id=\"{3}\"/>",
- "",
- GetDateTimePickerStyle(control),
- ev,
- id
- );
- html.Append("<script>$(function() {$( \"#").Append(id).Append("\" ).datepicker();");
- html.Append("$( \"#").Append(id).Append("\" ).datepicker( \"option\", \"dateFormat\", \"").
- Append(DateTimePickerFormat).Append("\" );");
-
- html.Append("$( \"#").Append(id).Append("\" ).datepicker( \"setDate\", new Date( ")
- .Append(control.Value.Year).Append(",").Append(control.Value.Month - 1).Append(",").Append(control.Value.Day)
- .Append("));");
- html.Append("});</script>");
- }
-
-
- //control.FilterData();
- return html.ToString();
- }
- private string GetDateTimePickerStyle(DateTimePickerControl control)
- {
- return GetStandardStyle(control);
- }
- }
- }
|