Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / WPF

CurionLib Dynamic Data Entry Forms

Rate me:
Please Sign up or sign in to vote.
5.00/5 (20 votes)
11 Aug 2013CPOL16 min read 54.6K   5.5K   44  
Dynamic data forms.
Imports System.Windows.Controls

Namespace Controls.Form
	Public Class DoubleGreaterThan
		Inherits ValidationRule
		Public Property Title As String
		Public Property Value As Double
		Sub New()
		End Sub
		Sub New(title As String, value As Double)
			Me.Title = title
			Me.Value = value
		End Sub
		Public Overloads Overrides Function Validate(value As Object, cultureInfo As Globalization.CultureInfo) As ValidationResult
			Dim v = CDbl(value)
			Return New ValidationResult(v >= Me.Value, String.Format("{0} is less than {1}", Title, Me.Value))
		End Function
	End Class
	Public Class DoubleLessThan
		Inherits ValidationRule
		Public Property Title As String
		Public Property Value As Double
		Sub New()
		End Sub
		Sub New(title As String, value As Double)
			Me.Title = title
			Me.Value = value
		End Sub
		Public Overloads Overrides Function Validate(value As Object, cultureInfo As Globalization.CultureInfo) As ValidationResult
			Dim v = CDbl(value)
			Return New ValidationResult(v <= Me.Value, String.Format("{0} is greater than {1}", Title, Me.Value))
		End Function
	End Class
	Public Class DoubleRequired
		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 = CDbl(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

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
I enjoy my wife, living in the woods, my 7 dogs, and learning new things. I like to play with UI stuff and model based coding.

Comments and Discussions