You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

247 lines
6.7 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Collections;
namespace OT.Controls
{
[ValidationPropertyAttribute("Text")]
public class AmtTextBox : CompositeControl
{
#region Private Member
private TextBox m_TextBox = new TextBox(); //多狀態文本框
private HiddenField m_HidStats; //檢測狀態
public enum AmtType //枚舉類型Digital(數字)、Letter(字母)、Email(郵件地址)
{
Digital = 0,
Letter = 1,
Email = 2
}
private string stronblur = string.Empty;//onblur事件
#endregion
#region Public property
[Bindable(true), Category("Appearance"), Description("類型選擇"), Localizable(true),]
//定义属性-選擇類型
public virtual AmtType TextBoxType
{
get
{
object obj = ViewState["TextBoxType"];
return (obj == null) ? AmtType.Digital : (AmtType)obj;
}
set { ViewState["TextBoxType"] = value; }
}
[Bindable(true), Description("檢測狀態"), Localizable(true), Browsable(false)]
//定义属性-返回檢測狀態
public string isStats
{
get
{
return (m_HidStats == null) ? "Y" : m_HidStats.Value;
}
set { m_HidStats.Value = value; }
}
//定义属性-返回值
public string Text
{
get
{
return m_TextBox.Text.Replace(",", "");
}
set
{
if (value != "" && TextBoxType == AmtType.Digital)
{
if (!value.Trim().Equals("-"))
{
m_TextBox.Text = Convert.ToDecimal(value).ToString("###,##0");
}
}
else
{
m_TextBox.Text = value;
}
}
}
public string onblur
{
set
{
stronblur = value;
}
}
public override string CssClass
{
get
{
return m_TextBox.CssClass;
}
set
{
m_TextBox.CssClass = value;
}
}
public override Unit Width
{
get
{
return m_TextBox.Width;
}
set
{
m_TextBox.Width = value;
}
}
//最大長度
public int MaxLength
{
get
{
return m_TextBox.MaxLength;
}
set { m_TextBox.MaxLength = value; }
}
//Readonly
public bool ReadOnly
{
get
{
return m_TextBox.ReadOnly;
}
set { m_TextBox.ReadOnly = value; }
}
[Bindable(true), Category("Behavior"), Description("是否可以為空"), Localizable(true)]
public bool isNULL
{
get
{
object obj = ViewState[ClientID + "isNULL"];
return (obj == null) ? true : (bool)obj;
}
set
{
ViewState[ClientID + "isNULL"] = value;
}
}
#endregion
#region Override Function
protected override void OnInit(EventArgs e)
{
if (this.Page != null)
{
//引入內嵌腳本資源
Page.ClientScript.RegisterClientScriptResource(this.GetType(), "OT.Controls.Js.AmtTextBox.js");
}
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Page.IsPostBack)
{
}
}
protected override void RecreateChildControls()
{
EnsureChildControls();
}
protected override void CreateChildControls()
{
Controls.Clear();
m_TextBox.ID = "AmtTextBox";
//m_TextBox.Width = this.Width;
//m_TextBox.MaxLength = miLong;
m_HidStats = new HiddenField();
m_HidStats.ID = "AmtHidStats";
if (this.ClientIDMode == System.Web.UI.ClientIDMode.Static)
{
m_TextBox.ID = this.ID;
m_HidStats.ID = this.ID + "_AmtHidStats";
}
this.Controls.Add(m_TextBox);
this.Controls.Add(m_HidStats);
}
protected override void Render(HtmlTextWriter writer)
{
EnsureChildControls();
SetProptyToRender();//控件添加屬性
if (m_TextBox.ID.IndexOf("txtDivExpTotIncome") > -1)
{
}
m_TextBox.RenderControl(writer);
m_HidStats.RenderControl(writer);
}
#endregion
#region Public Function
#endregion
#region Private Function
/// <summary>
/// 在Render之前為子控件添加屬性
/// </summary>
private void SetProptyToRender()
{
switch (TextBoxType)
{
case AmtType.Digital://數字類型
m_TextBox.Attributes.Add("onkeypress", "return KeyPress(this);");
m_TextBox.Attributes.Add("onclick", "clearComma(this.id);");
m_TextBox.Attributes.Add("onfocus", "moveEnd(this);");
m_TextBox.Attributes.Add("onblur", "isMubmer(this.id);" + stronblur);
m_TextBox.Attributes.Add("ismoney","true");
m_TextBox.Style.Add(HtmlTextWriterStyle.Direction, "rtl");
break;
case AmtType.Letter://字母類型
m_TextBox.Attributes.Add("onkeypress", "return inputLetter();");
m_TextBox.Attributes.Add("onblur", "isLetter(this.id);");
break;
case AmtType.Email://Email類型
m_TextBox.Attributes.Add("onblur", "return checkEmail(this.id);");
break;
}
foreach (string strKey in this.Attributes.Keys)
{
m_TextBox.Attributes.Add(strKey, m_TextBox.Attributes[strKey] ?? "" + ";" + this.Attributes[strKey]);
}
m_TextBox.TabIndex = this.TabIndex;
}
#endregion
}
}