forked from siteserver/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTimeTextBox.cs
More file actions
92 lines (86 loc) · 2.66 KB
/
Copy pathDateTimeTextBox.cs
File metadata and controls
92 lines (86 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using SiteServer.Utils;
namespace SiteServer.BackgroundPages.Controls
{
public class DateTimeTextBox : TextBox
{
public bool Now
{
get
{
var o = ViewState["Now"];
if (o == null)
{
return false;
}
return (bool)o;
}
set { ViewState["Now"] = value; }
}
public bool ShowTime
{
get
{
var o = ViewState["ShowTime"];
if (o == null)
{
return false;
}
return (bool)o;
}
set { ViewState["ShowTime"] = value; }
}
public override string Text
{
get
{
var formatString = (ShowTime) ? DateUtils.FormatStringDateTime : DateUtils.FormatStringDateOnly;
if (Now && string.IsNullOrEmpty(base.Text))
{
base.Text = DateTime.Now.ToString(formatString);
}
if (!string.IsNullOrEmpty(base.Text))
{
base.Text = TranslateUtils.ToDateTime(base.Text).ToString(formatString);
}
return base.Text;
}
set
{
base.Text = value;
}
}
public virtual DateTime DateTime
{
get
{
return TranslateUtils.ToDateTime(Text);
}
set
{
var formatString = (ShowTime) ? DateUtils.FormatStringDateTime : DateUtils.FormatStringDateOnly;
Text = value.ToString(formatString);
}
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
var onfocus = (ShowTime) ? SiteServerAssets.DatePicker.OnFocus : SiteServerAssets.DatePicker.OnFocusDateOnly;
Attributes.Add("onfocus", onfocus);
base.AddAttributesToRender(writer);
}
protected override void OnLoad(EventArgs e)
{
if (Page != null)
{
if (!Page.ClientScript.IsStartupScriptRegistered("DateTimeTextBox_Calendar"))
{
Page.ClientScript.RegisterStartupScript(GetType(), "DateTimeTextBox_Calendar",
$@"<script language=""javascript"" src=""{SiteServerAssets.GetUrl(SiteServerAssets.DatePicker.Js)}""></script>");
}
}
base.OnLoad(e);
}
}
}