Imports System.Windows.Controls
Namespace Controls.Form
Public Class IntegerGreaterThan
Inherits ValidationRule
Public Property Title As String
Public Property Value As Integer
Sub New()
End Sub
Sub New(title As String, value As Integer)
Me.Title = title
Me.Value = value
End Sub
Public Overloads Overrides Function Validate(value As Object, cultureInfo As Globalization.CultureInfo) As ValidationResult
Dim v = CInt(value)
Return New ValidationResult(v >= Me.Value, String.Format("{0} is less than {1}", Title, Me.Value))
End Function
End Class
Public Class IntegerLessThan
Inherits ValidationRule
Public Property Title As String
Public Property Value As Integer
Sub New()
End Sub
Sub New(title As String, value As Integer)
Me.Title = title
Me.Value = value
End Sub
Public Overloads Overrides Function Validate(value As Object, cultureInfo As Globalization.CultureInfo) As ValidationResult
Dim v = CInt(value)
Return New ValidationResult(v <= Me.Value, String.Format("{0} is greater than {1}", Title, Me.Value))
End Function
End Class
Public Class IntegerRequired
Inherits ValidationRule
Public Property Title As String
Sub New()
End Sub
Sub New(title As String)
Me.Title = title
End Sub
Public Overloads Overrides Function Validate(value As Object, cultureInfo As Globalization.CultureInfo) As ValidationResult
Dim isValid = False
If IsNumeric(value) Then
Try
Dim v = CInt(value)
isValid = True
Catch ex As Exception
End Try
End If
Return New ValidationResult(isValid, String.Format("{0} is required", Title))
End Function
End Class
End Namespace