1
/**//*ZLTextBox.NET Framework
2
*Copyright (C) 2006 ZLTextBox Project Team
3
*编写人:张铃
4
*编写日期:2007-01-14 20:00
5
*功能描述:针对各类业务系统B/S的数据录入模式,对微软的控制进行了扩展
6
*主要功能有:有得到焦点和失去焦点的颜色,得到焦点下拉日期选择框,数字型、浮点、电话、中文、大小写字母、IP地址等录入框,指定值的ID属性绑定值等。
7
*/
8
using System;
9
using System.ComponentModel;
10
using System.ComponentModel.Design;
11
using System.Drawing.Design;
12
using System.Web.UI;
13
using System.Web.UI.WebControls;
14
using System.Collections.Generic;
15
using System.Text;
16
17
[assembly: TagPrefix("NetFans .net blog", "zl")]
18
namespace BaseText
19
...{
20
[DesignerAttribute(typeof(ZLTextBoxDesigner), typeof(IDesigner)),
21
DefaultProperty("Text"), ToolboxData("<{0}:ZLTextBox runat=server></{0}:ZLTextBox>")]
22
public class ZLTextBox : TextBox
23
...{
24
/**//// <summary>
25
/// 主要功能是实现日期多语言选择枚举
26
/// </summary>
27
public enum LanguageType
28
...{
29
Chinese,
30
English
31
}
32
...#region
33
private textType inputtype;
34
/**//// <summary>
35
/// 文本框录入的模式
36
/// </summary>
37
[
38
Description(@"文本框输入的类型:
39
varchars------任意文本,
40
Upper---------大写,
41
Lower---------小写,
42
number--------任意数字,
43
formatNumber--格式化指定的小数,
44
date----------日期,
45
ChineseLanguage-中文,
46
email---------邮箱,
47
telephone-----手机,
48
phone---------固定电话,
49
其它有待新增。。。
50
")
51
]
52
public textType InputType
53
...{
54
get
55
...{
56
return inputtype;
57
}
58
set
59
...{
60
if ((value < textType.varchars) || (value > textType.phone))
61
...{
62
throw new ArgumentOutOfRangeException("无效属性值");
63
}
64
inputtype = value;
65
}
66
}
67
private string showMessage;
68
/**//// <summary>
69
/// 验证用户不通过的友好提示信息
70
/// </summary>
71
[
72
Description("验证用户不通过的友好提示信息")
73
]
74
[DefaultValue("请在此输入当验证数据不通过的友好提示!")]
75
public string ShowMessage
76
...{
77
get ...{
78
return this.showMessage;
79
}
80
set
81
...{
82
if (value.Length > 50)
83
throw new ArgumentOutOfRangeException("提示超出长度,50字符以内");
84
this.showMessage = value;
85
}
86
}
87
private string OnfocusCss;
88
/**//// <summary>
89
/// 控件得到焦点的样式
90
/// </summary>
91
[
92
Description("得到焦点或鼠标移上文本框的样式名称")
93
]
94
[DefaultValue("请在此输入当该文本框得到焦点样式的名称!")]
95
public string onfocusCssName
96
...{
97
get
98
...{
99
return this.OnfocusCss;
100
}
101
set
102
...{
103
this.OnfocusCss = value;
104
}
105
}
106
107
private string floatlength="2";
108
/**//// <summary>
109
/// 当是浮点数时,指定小数位数
110
/// </summary>
111
[
112
Description("当是浮点数时,指定保留的小数位数")
113
]
114
public string FloatLength
115
...{
116
get
117
...{
118
return this.floatlength;
119
}
120
set
121
...{
122
if(Int64.Parse(value)<0)
123
throw new ArgumentOutOfRangeException("小数位数至少保留一位小数,如无需保留请选择整形");
124
this.floatlength = value;
125
}
126
}
127
128
private string OnblurCss;
129
/**//// <summary>
130
/// 控件得到焦点的样式
131
/// </summary>
132
[
133
Description("失去焦点或鼠标移开文本框的样式名称")
134
]
135
[DefaultValue("请在此输入当该文本框失去焦点样式的名称!")]
136
public string onblurCssName
137
...{
138
get
139
...{
140
return OnblurCss;
141
}
142
set
143
...{
144
this.OnblurCss = value;
145
}
146
}
147
/**//// <summary>
148
/// 保存特定的值
149
/// </summary>
150
[Description("用于保存文本框的特定值,指定值的对应编号")]
151
[Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), Category("Appearance")]
152
public string textValue
153
...{
154
get
155
...{
156
string text1 = (string)this.ViewState["textValue"];
157
if (text1 != null)
158
...{
159
return text1;
160
}
161
return string.Empty;
162
163
}
164
set
165
...{
166
this.ViewState["textValue"] = value;
167
}
168
}
169
170
#endregion
171
172
private LanguageType m_language; //定义语言类型枚举变量
173
174
/**//// <summary>
175
/// 该属性用来表示日期显示类型:中/英文
176
/// </summary>
177
[
178
Description("该属性用来表示日期显示类型:中/英文")
179
]
180
public LanguageType Language
181
...{
182
get
183
...{
184
return m_language;
185
}
186
set
187
...{
188
189
m_language = value;
190
}
191
}
192
193
private bool m_IsDisplayTime = true; //是否显示时间
194
/**//// <summary>
195
/// 设置是否显示时间
196
/// </summary>
197
[
198
Description("是否在文本框中显示时间")
199
]
200
public bool IsDisplayTime
201
...{
202
get
203
...{
204
return m_IsDisplayTime;
205
}
206
set
207
...{
208
m_IsDisplayTime = value;
209
}
210
211
}
212
213
/**//// <summary>
214
/// 返回选择或输入的日期/时间
215
/// </summary>
216
[
217
Description("返回选择或输入的日期/时间")
218
]
219
public DateTime GetDateTime
220
...{
221
get
222
...{
223
if (this.Text.Trim() == string.Empty)
224
...{
225
return DateTime.MinValue;
226
}
227
return Convert.ToDateTime(this.Text.Trim());
228
}
229
}
230
/**//// <summary>
231
/// 该属性用来返回客户端脚本注册名称
232
/// </summary>
233
private string ScriptName
234
...{
235
get
236
...{
237
return "BaseTextDateScript";
238
}
239
}
240
private string RegName
241
...{
242
get
243
...{
244
return "reginputScript";
245
}
246
}
247
private string RegEnterName
248
...{
249
get
250
...{
251
return "baseTextBoxEnter";
252
}
253
}
254
重写基类方法#region 重写基类方法
255
/**//// <summary>
256
/// 重写Html输出函数
257
/// </summary>
258
/// <param name="writer">要写出到的 HTML 编写器</param>
259
protected override void Render(HtmlTextWriter writer)
260
...{
261
base.Render(writer);
262
//用于验证除日期以外的的脚本处理方法
263
if (InputType != textType.date)
264
...{
265
if (!this.Page.ClientScript.IsStartupScriptRegistered(this.RegName))
266
...{
267
this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.RegName, this.regBaseInputScript(),false);
268
}
269
}
270
else
271
...{
272
//日期
273
if (!this.Page.ClientScript.IsStartupScriptRegistered(this.ScriptName))
274
...{
275
this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ScriptName, this.GetDateJavascript(), false);
276
}
277
}
278
//日期
279
if (!this.Page.ClientScript.IsStartupScriptRegistered(this.RegEnterName))
280
