customervalidationrules.vb
来自「讲解visual studio的应用」· VB 代码 · 共 45 行
VB
45 行
Imports System
Imports Databinding.ControlValidator
Public Class CustomerValidationRules
Implements IRulesList
Public Shared ReadOnly Property Instance() As CustomerValidationRules
Get
Return New CustomerValidationRules
End Get
End Property
Public ReadOnly Property Rules() As Predicate(Of IRulesList.RuleParams)() _
Implements IRulesList.Rules
Get
Return New Predicate(Of IRulesList.RuleParams)() { _
AddressOf TerritoryId, _
AddressOf FirstName}
End Get
End Property
<Validation("TerritoryID", "TerritoryID must be >0")> _
Public Function TerritoryId(ByVal data As IRulesList.RuleParams) As Boolean
Try
If Not TypeOf (data.NewData) Is Integer Then Return False
Dim newVal As Integer = CInt(data.NewData)
If newVal > 0 Then Return True
Return False
Catch ex As Exception
Return False
End Try
End Function
<Validation("FirstName", "First Name must be specified")> _
Public Function FirstName(ByVal data As IRulesList.RuleParams) As Boolean
Try
Dim newVal As String = TryCast(data.NewData, String)
If newVal = "" Then Return False
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?