Re: Help with Validation rules

Re: Help with Validation rules

Old forum URL: forums.lhotka.net/forums/t/3118.aspx


ozitraveller posted on Thursday, June 28, 2007

  Hi

I'd appreciate it some could help me. I want to be able to validate a dollar amount, ie. required, and > 0. Also a percent figure (x) which is required, between 0 and 100, and x <= a limit percent (y) .

Thanks

RockfordLhotka replied on Friday, June 29, 2007

The >0 rule is already in CSLA, it is CommonRules.MinValue(). For a dollar amount you can probably use a mininum value of 0.01 or 0.005 or something.

The between 0 and y rule can be done a couple ways. You could use both MinValue() and MaxValue() rules if y is known at the time the object is created.

Or you could use MinValue() for the bottom and create a custom rule method that takes your dynamic y value into account. To create a custom rule method, the best infomation source is the CSLA .NET Version 2.1 Handbook, or look at the Project class in ProjectTracker.Library because it implements a custom rule method.

ozitraveller replied on Friday, June 29, 2007

Thanks Rocky

 

ozitraveller replied on Saturday, June 30, 2007

Hi

I must have missed something setting up this rule. Hopefully someone can tell me what I have done wrong.

I've implemented the following in the BO.

private const double minPercent = 0.005D;
private const double maxPercent = 1.00D;


ValidationRules.AddRule(CommonRules.MinValue<double>,
 new CommonRules.MinValueRuleArgs<double>("DmfFirst", minPercent));
ValidationRules.AddRule(CommonRules.MaxValue<double>,
 new CommonRules.MaxValueRuleArgs<double>("DmfFirst", maxPercent));

and this is in BindingSource_CurrentItemChanged event


this.applyButton.Enabled = _recurrentCharges.IsSavable;
SD.Debug.WriteLine(string.Format("IsDirty: {0}", _recurrentCharges.IsDirty));
SD.Debug.WriteLine(string.Format("IsValid: {0}", _recurrentCharges.IsValid));
SD.Debug.WriteLine(string.Format("IsSavable: {0}", _recurrentCharges.IsSavable));

and when I change the value in my test field, I get the following:

IsDirty: True
IsValid: False
IsSavable: False

So the BO knows it's invalid and the data I entered definitely was invalid. However, the errorprovider doesn't indicate there was an error nor display an error message.

Is there something more I need to do?

Any help would be greatly appreciated.

Thanks

ozitraveller replied on Sunday, July 01, 2007

Resolved

jpm replied on Monday, May 03, 2010

how was it resolved?

I have the same problem where the child object knows its invalid but the error provider doesn't seem to be picking it up.

any ideas would be greatly appriciated

cheers jm

Copyright (c) Marimer LLC