Hi
I have done this so far:
Protected Overrides Sub AddBusinessRules()ValidationRules.AddRule(
Of Q1)(AddressOf ValueNotZero(Of Q1), "InWork")ValidationRules.AddRule(
Of Q1)(AddressOf ValueNotZero1(Of Q1), "OtherHouseholderWorking") End Sub Private Shared Function ValueNotZero(Of T As Q1)( ByVal target As T, ByVal e As Validation.RuleArgs) As Boolean If target.m_inWork = 0 Thene.Description =
"1) Please answer this question - In/out Work?" Return False Else Return True End If Return False End Function Private Shared Function ValueNotZero1(Of T As Q1)( ByVal target As T, ByVal e As Validation.RuleArgs) As Boolean If target.m_otherHouseholderWorking = 0 Thene.Description =
"8a) Please answer this question" Return False Else Return True End If End FunctionBut I have serveral more fields that require the same validation i.e. > 0. I didn't want to repeat ValueNotZero2,3,4,5....... and so on
How can I combine into one ValueNotZero function and implement. My guess I'm being somewhat thick here.
Thanks
Richard
Richard,
You can do this by moving the rule into a class like Rocky's Common Rules. I basically copied his rules into my own class and namespace and then continued to add my own.
So you might have a rule like this:
Public Function KeyNotZero(ByVal target As Object, ByVal e As RuleArgs) As BooleanThis rule can call other functions to determine e.Description if you need to vary it.
Joe
Thanks for the reply.
I have copied in common rules and added in your function - but I'm having difficulty calling the validation
ValidationRules.AddRule(
AddressOf CustomValidation.KeyNotZero(Of Q1), New CustomValidation.RuleArgs("InWork", "1. Are you in work"), "InWork")How would you call?
Thanks
Richard
I call it like this:
ValidationRules.AddRule(AddressOf KeyNotZero, New MyRuleArgs("AKeyPropertyName"))
If you have extra parameters in your rule args you might call it like this:
ValidationRules.AddRule(AddressOf KeyNotZero, New MyRuleArgs("InWork", "1. Are you in work"))
Joe
Hi
thank Joe, I have done this but get compile error
Error 1 Overload resolution failed because no accessible 'AddRule' can be called with these arguments:
'Public Sub AddRule(Of T, R As Csla.Validation.RuleArgs)(handler As Csla.Validation.RuleHandler(Of T, R), args As R)': Type parameter 'T' for 'Public Sub AddRule(Of T, R As Csla.Validation.RuleArgs)(handler As Csla.Validation.RuleHandler(Of T, R), args As R)' cannot be inferred.
'Public Sub AddRule(handler As Csla.Validation.RuleHandler, args As Csla.Validation.RuleArgs)': Method 'Public Function KeyNotZero(target As Object, e As InsiteLib.CustomValidation.RuleArgs) As Boolean' does not have the same signature as delegate 'Delegate Function RuleHandler(target As Object, e As Csla.Validation.RuleArgs) As Boolean'.
'Public Sub AddRule(handler As Csla.Validation.RuleHandler, args As Csla.Validation.RuleArgs)': Value of type 'InsiteLib.CustomValidation.KeyNotZeroRuleArgs' cannot be converted to 'Csla.Validation.RuleArgs'.
'Public Sub AddRule(Of T)(handler As Csla.Validation.RuleHandler(Of T, Csla.Validation.RuleArgs), propertyName As String)': Type parameter 'T' for 'Public Sub AddRule(Of T)(handler As Csla.Validation.RuleHandler(Of T, Csla.Validation.RuleArgs), propertyName As String)' cannot be inferred.
'Public Sub AddRule(handler As Csla.Validation.RuleHandler, propertyName As String)': Method 'Public Function KeyNotZero(target As Object, e As InsiteLib.CustomValidation.RuleArgs) As Boolean' does not have the same signature as delegate 'Delegate Function RuleHandler(target As Object, e As Csla.Validation.RuleArgs) As Boolean'.
'Public Sub AddRule(handler As Csla.Validation.RuleHandler, propertyName As String)': Value of type 'InsiteLib.CustomValidation.KeyNotZeroRuleArgs' cannot be converted to 'String'. C:\Inetpub\wwwroot\Insite\InsiteLib\InsiteLib\Q1.designer.vb 1908 9 InsiteLib
I call using:
ValidationRules.AddRule(
AddressOf CustomValidation.KeyNotZero, New CustomValidation.KeyNotZeroRuleArgs("InWork", 0))Must be doing something wrong
Richard
Copyright (c) Marimer LLC