高级文本框 Web 组件






1.88/5 (5投票s)
2005年3月21日
12分钟阅读

34492

389
支持字符大小写、过滤、小数和数字的文本框
忘掉自定义控件。让我们创建一个新的组件。这个组件继承自文本框类。将这个组件添加到您的工具箱面板中。右键单击工具箱面板,选择添加/删除项,点击浏览,然后指向 IMAWA.AdvCom.dll 文件。
导入System.Globalization
'编码者:I Made Agus W.A (bluechip_asia@yahoo.com / made.in.indonesia@gmail.com)
'本源代码仅用于教育目的
Public 类AdvTextBox
继承自System.Web.UI.WebControls.TextBox
DimvarUpperCaseAs 布尔值 = 假
DimvarLowerCaseAs 布尔值 = 假
DimvarNumericAs 布尔值 = 假
DimvarCharFilterAs 字符串 = ""
DimvarDecimalModeAs 布尔值 = 假
DimvarMarkIfEmptyAs 布尔值 = 假
DimvarMaskingAs 字符串 = ""
DimvarDataGroupAs 字符串 = ""
DimVarSqlDbTypeAsSqlDbType = SqlDbType.Char
DimVarDataLengthAs 整数 = 0
DimvarParameterDirectionAsParameterDirection = ParameterDirection.InputOutput
DimvarDataFieldAs 字符串 = ""
DimvarEnabledEncode95As 布尔值 = 假
DimvarDataTitleAs 字符串 = ""
DimvarShowOnGridAs 布尔值 = True
DimvarShowOnSearchAs 布尔值 = True
DimvarRegisteredControlAs 布尔值 = True
#区域"小数处理变量"
DimKomaAs Char = ","
DimTtkAs Char = "."
DimRataAs 整数 = 25
DimPerintahAs 字符串 = ""
#End 区域
#区域"小数属性"
Public 属性DecimalChar()As Char
Get
返回Koma
End Get
Set(ByVal值As Char)
Koma = 值
End Set
End 属性
Public 属性SeparatorChar()As Char
Get
返回Ttk
End Get
Set(ByVal值As Char)
Ttk = 值
End Set
End 属性
Public 属性DecimalAlign()As 字节型
Get
返回 CInt(Rata)
End Get
Set(ByVal值As 字节型)
Rata = Value.ToString.Trim
End Set
End 属性
#End 区域
#区域"小数私有函数"
Private 函数getmark()As Char
DimmystrAs 字符串= ((3 / 100) + 13).ToString
DimttkAs 整数= mystr.IndexOf(".")
Ifttk > 0那么
返回 "."
Else
返回 ","
End If
End 函数
Private 函数clearvalue(ByValmyvalueAs 字符串) As 字符串
DimiAs 整数 = 0
DimmystrAs 字符串 = ""
Fori = 0改为myvalue.Length - 1
Ifmyvalue.Chars(i) <> Ttk那么
Ifmyvalue.Chars(i) = Koma那么
mystr += getmark()
Else
mystr += myvalue.Chars(i)
End If
End If
下一篇
返回mystr
End 函数
Private 函数reversestring(ByValmydataAs 字符串) As 字符串
DimmyhasilAs 字符串 = ""
DimiAs 整数
Ifmydata.Length > 1那么
Fori = 0改为(mydata.Length - 1)
myhasil = mydata.Chars(i) + myhasil
下一篇
Else
myhasil = mydata
End If
返回myhasil
End 函数
Private 函数alignstring(ByValmydataAs 字符串)
DimmyhasilAs 字符串= mydata
If(Rata > 0)那么
While(myhasil.Length < Rata)
myhasil = " " + myhasil
End While
End If
返回myhasil
End 函数
Private 函数ParseMoney(ByValmyvalueAs 字符串) As 字符串
DimposAs 整数 = 0
DimekstensiAs 字符串 = ""
DimnegatifAs 字符串 = ""
DimiAs 整数
Fori = 0改为myvalue.Length - 1
If(myvalue.Chars(i) = Ttk)或者(myvalue.Chars(i) = Koma)那么
pos = i
End If
Ifmyvalue.Chars(i) = "-"那么
negatif = "-"
End If
下一篇
DimhasilAs 字符串 = ""
DimselesaiAs 字符串 = ""
Ifpos > 0那么
Fori = 0改为(pos - 1)
hasil += myvalue.Chars(i)
下一篇
Fori = (pos + 1)改为(myvalue.Length - 1)
ekstensi += myvalue.Chars(i)
下一篇
Else
hasil = myvalue
End If
Ifekstensi = ""那么
ekstensi = "0"
End If
Ifhasil.Length > 1那么
hasil = reversestring(hasil)
Fori = 0改为hasil.Length - 1
selesai += hasil.Chars(i)
If(i + 1)Mod 3 = 0 那么
If(i < (hasil.Length - 1))那么
selesai += Ttk
End If
End If
下一篇
返回alignstring(reversestring(selesai) + Koma + ekstensi)
Else
返回alignstring(negatif + hasil + Koma + ekstensi)
End If
End 函数
#End 区域
#区域"脚本处理"
Private SubRegisterInitialScript()
DimMyScriptAs 字符串= "" & vbCrLf
If 非Page.IsStartupScriptRegistered("InitialScript")那么
Page.RegisterStartupScript("InitialScript", MyScript)
End If
End Sub
Private SubRegisterDecimalScript()
DimMyScript, DateFormatAs 字符串
MyScript = ""
MyScript &= "" & vbCrLf
If 非Page.IsStartupScriptRegistered("CurrencyVerification")那么
Page.RegisterStartupScript("CurrencyVerification", MyScript)
End If
End Sub
#End 区域
#区域"通用属性"
Public 属性UpperCase()As 布尔值
Get
返回varUpperCase
End Get
Set(ByVal值As 布尔值)
varUpperCase = 值
IfUpperCase =True 那么
LowerCase =假
NumericMode =假
DecimalMode =假
我.Attributes.Add("onChange", "javascript:this.value=this.value.toUpperCase();")'uppertextbox('" + ClientID + "');
End If
End Set
End 属性
Public 属性LowerCase()As 布尔值
Get
返回varLowerCase
End Get
Set(ByVal值As 布尔值)
varLowerCase = 值
IfLowerCase那么
UpperCase =假
NumericMode =假
DecimalMode =假
Attributes.Add("OnChange", "javascript:this.value=this.value.toLowerCase();")
End If
End Set
End 属性
Public 属性NumericMode()As 布尔值
Get
返回varNumeric
End Get
Set(ByVal值As 布尔值)
varNumeric = 值
IfNumericMode =True 那么
PropertyOn("NumericMode")
Attributes.Add("OnChange", "javascript:textfilter('" + ClientID + "','0123456789');")
End If
End Set
End 属性
Public 属性TextFilter()As 字符串
Get
返回varCharFilter
End Get
Set(ByVal值As 字符串)
varCharFilter = 值
IfTextFilter.Length > 0那么
PropertyOn("textfilter")
我.Attributes.Add("OnChange", "javascript:this.value=stringfilter(this.value,'" + TextFilter + "');")
End If
End Set
End 属性
Public 属性DecimalMode()As 布尔值
Get
返回varDecimalMode
End Get
Set(ByVal值As 布尔值)
varDecimalMode = 值
IfDecimalMode =True 那么
PropertyOn("DecimalMode")
Attributes.Add("onChange", "javascript:valcurrnum('" + ClientID + "','" + Ttk + "','" + Koma + "'," + Rata.ToString + ");")
End If
End Set
End 属性
Public 属性MarkIfEmpty()As 布尔值
Get
返回varMarkIfEmpty
End Get
Set(ByVal值As 布尔值)
varMarkIfEmpty = 值
End Set
End 属性
Public ReadOnly 属性CustomMask()As 字符串
Get
返回varMasking
End Get
'Set(ByVal Value As String)
' varMasking = Value
'End Set
End 属性
Private SubPropertyOn(ByValActivePropertyAs 字符串)
If 非ActiveProperty.ToLower = "uppercase"那么
UpperCase =假
End If
If 非ActiveProperty.ToLower = "lowercase"那么
LowerCase =假
End If
If 非ActiveProperty.ToLower = "numericmode"那么
NumericMode =假
End If
If 非ActiveProperty.ToLower = "textfilter"那么
TextFilter = ""
End If
If 非ActiveProperty.ToLower = "decimalmode"那么
DecimalMode =假
End If
End Sub
#End 区域
#区域"数据访问处理"
Public 属性DataGroup()As 字符串
Get
返回varDataGroup.ToUpper
End Get
Set(ByVal值As 字符串)
varDataGroup = Value.ToUpper.Trim
IfDataField.Length > 0那么
ID = "tb_" + DataGroup.ToUpper + DataField.ToLower
End If
End Set
End 属性
Public 属性DataType()AsSqlDbType
Get
返回VarSqlDbType
End Get
Set(ByVal值AsSqlDbType)
VarSqlDbType = 值
End Set
End 属性
Public 属性DataLength()As 整数
Get
返回VarDataLength
End Get
Set(ByVal值As 整数)
VarDataLength = 值
End Set
End 属性
Public 属性ParameterDirection()AsParameterDirection
Get
返回varParameterDirection
End Get
Set(ByVal值AsParameterDirection)
varParameterDirection = 值
End Set
End 属性
Public 属性DataField()As 字符串
Get
返回varDataField
End Get
Set(ByVal值As 字符串)
varDataField = Value.Trim
IfDataField.Length > 0那么
ID = "tb_" + DataGroup.ToUpper + Value.ToLower
End If
IfDataTitle.Length > 0那么
DataTitle = DataField
End If
End Set
End 属性
Public 属性EnabledEncode95()As 布尔值
Get
返回varEnabledEncode95
End Get
Set(ByVal值As 布尔值)
varEnabledEncode95 = 值
End Set
End 属性
Public 属性DataTitle()As 字符串
Get
返回varDataTitle
End Get
Set(ByVal值As 字符串)
varDataTitle = Value.Trim
IfDataTitle.Length = 0那么
varDataTitle = DataField.ToUpper
End If
End Set
End 属性
Public 属性ShowOnGrid()As 布尔值
Get
返回varShowOnGrid
End Get
Set(ByVal值As 布尔值)
varShowOnGrid = 值
End Set
End 属性
Public 属性ShowOnSearch()As 布尔值
Get
返回varShowOnSearch
End Get
Set(ByVal值As 布尔值)
varShowOnSearch = 值
End Set
End 属性
Public 属性RegisteredControl()As 布尔值
Get
返回varRegisteredControl
End Get
Set(ByVal值As 布尔值)
varRegisteredControl = 值
End Set
End 属性
Public 函数GetSQLParameterGroup()AsSqlClient.SqlParameter()
DimiAs 整数
DimCountAs 整数 = 0
DimMyObjAs 对象
DimMyValueAs 字符串
Dimsqlparam()AsSqlClient.SqlParameter
DimMySession()As 字符串
试试
Fori = 0改为Page.Session.Count - 1
MySession = Page.Session.Item(i).ToString.Split("=")
IfPage.Session.Item(i).ToString.IndexOf("=") >= 0那么
IfMySession(1).ToLower =我.GetType.Name.ToLower那么
MyObj = FindControl(MySession(0))
IfMyObj.DataGroup =我.DataGroup那么
ReDim Preservesqlparam(i)
IfMyObj.EnabledEncode95那么
MyValue = MyObj.toEncode95Text
Else
MyValue = MyObj.Text.ToString.Trim
End If
sqlparam(i) =新建SqlClient.SqlParameter("@" + MyObj.DataField, MyObj.DataType, MyObj.DataLength, MyObj.ParameterDirection,True, 0, 0, "", DataRowVersion.Current, MyValue)
End If
End If
End If
下一篇
CatchexAs异常
End 试试
返回sqlparam
End 函数
Public 函数GetParameterString()As 字符串
End 函数
Public 函数GetCodeBlindString()As 字符串
End 函数
Public 函数GetListItemString()As 字符串
End 函数
#End 区域
#区域"加密"
Private 函数Encode95(ByValOriginalStringAs 字符串) As 字符串
End 函数
Private 函数Encode95(ByValOriginalStringAs 字符串, ByValHeaderKeyAs 字节型) As 字符串
End 函数
Private 函数Decode95(ByValEncodeStringAs 字符串) As 字符串
End 函数
Private 函数isValidCode95HeaderKey(ByValEncodeStringAs 字符串, ByValHeaderKeyAs 字节型) As 布尔值
End 函数
Public 函数toEncode95Text()As 字符串
返回Encode95(Text)
End 函数
Public SubEncode95Text(ByValvalueAs 字符串)
Text = Decode95(value)
End Sub
#End 区域
Private SubPage_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)句柄 MyBase.Load
RegisterInitialScript()
If(DecimalMode =True) 或者(TextFilter.Length > 0)那么
RegisterDecimalScript()
End If
IfPage.IsPostBack那么
If(Text.Length = 0)并且(MarkIfEmpty =True) 那么
BorderColor = System.Drawing.Color.Red
End If
End If
If 非Font.Name.Length > 0那么
Font.Name = "Times New Roman"
End If
Hidden()
If 我.ReadOnly那么
ForeColor = System.Drawing.Color.Silver
End If
End Sub
Private SubPage_Init(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)句柄 MyBase.Init
IfRegisteredControl那么
Page.Session.Add(ID, ID + "=AdvTextBox")
End If
End Sub
Public SubHidden()
IfVisible =假 那么
Page.RegisterHiddenField(ClientID, Text)
End If
End Sub
End 类