Newbie - validation version 1.53

Newbie - validation version 1.53

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


griff posted on Wednesday, October 25, 2006

How do I implement validation......like this....

in the save button

If mJobDate.BrokenRulesCollection.Count = 0 Then
                mJobDate.ApplyEdit()
                mJobDate = DirectCast(mJobDate.Save, TranslationLib.cJobDate)
                BindFields()
                Cursor.Current = Cursors.Default
                Return True
            Else
                Dim Message As CSLA.BrokenRules.Rule
                For Each Message In mJobDate.BrokenRulesCollection
                    MessageBox.Show("Cannot Save because.." & vbNewLine & Message.Description, "Error: " & Message.Property, MessageBoxButtons.OK, MessageBoxIcon.Error)
                Next
                Return False
            End If

For a new object how to I implement validation as the property may not be updated causing the broken rules bit to be actioned ??


Fintanv replied on Wednesday, October 25, 2006

Just curious, but is there a reason why you are not binding the enabled property of your save button, to the IsSavable property of the business object?  In this case the user would be unable to save while the bo is in an unchanged or invalid state.

griff replied on Wednesday, October 25, 2006

I could do this now you mention it but how would you report back to the user which fields are invalid.
Also (I may be doing something wrong) but when I create the new BO I notice IsValid is set to true.

Fintanv replied on Wednesday, October 25, 2006

There are several options including:

1. displaying the broken rules in a tree object.

2. use the error provider component.

For the second part of your question; are you checking the rules as part of the process for creating your object via Create or Fetch?

griff replied on Thursday, October 26, 2006

I don't want to use the tree. 

How do you implement the error provider with csla?  There does not seem to be any examples in the project tracker sample.

For the second part of your question......I assume that I add in the rules when I create the object

e.g. BrokenRules.Assert("NameLen", "Name too long", Len(Value) > 50)

Thanks

ajj3085 replied on Thursday, October 26, 2006

Just add the errorprovider component to your form.   Point it to the bindingsource to which your object will be bound.  Enjoy blinking error icons.

Copyright (c) Marimer LLC