The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Validation problem - C#

Last post 05-20-2008, 8:53 AM by pritcham. 5 replies.
Sort Posts: Previous Next
  •  05-16-2008, 4:11 PM 9339

    Validation problem - C#

    I have a Customer class that has Validate implemented.

    I have a CustomerCollection class where I am doing the following:

    Code:
    coll = new CustomerCollection();
    coll.LoadAll();
    bindingSource1.DataSource = coll;

    I am using this with XtraGrid from DevExpress.

    All errors are displayed in the grid just fine.

    How do I prevent the collection from being saved when it has errors?

    I have tried everything I can think of ..

     

    Thanks

    Howard 

     

  •  05-16-2008, 4:35 PM 9340 in reply to 9339

    Re: Validation problem - C#

    Are you doing Windows.Forms or Web? Is there not even you can trap (I guess you have probably tried that?)

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  05-16-2008, 4:53 PM 9344 in reply to 9340

    Re: Validation problem - C#

    Mike.Griffin:
    Are you doing Windows.Forms or Web? Is there not even you can trap (I guess you have probably tried that?)

     

    I am using Windows.Form ...

     

    Howard

     

  •  05-18-2008, 8:41 AM 9350 in reply to 9344

    Re: Validation problem - C#

    Hi

    Depends on how you've implemented your validation logic but something like the following might set you in the right direction:

    1) the following would go in your EntityBase class (assuming you have one)

    Code:
            Public ReadOnly Property IsValid() As Boolean
                Get
                    For Each c As esColumnMetadata In Me.Meta.Columns
                        If Not Validate(c.Name, Me, c) Then Return False
                    Next
                    Return True
                End Get
            End Property
    

    Note that the above assumes your Validate() method returns a Boolean - if it returns a string instead then you'd need to change the following line:

    Code:
    If Not Validate(c.Name, Me, c) Then Return False
     

    to -

    Code:
    If Not Validate(c.Name,Me,c) = "" Then Return False

    2) This would go in your CollectionBase class

    Code:
            Public ReadOnly Property IsValid() As Boolean
                Get
                    For Each e As EntityBase In Me
                        If Not e.IsValid Then Return False
                    Next
                    Return True
                End Get
            End Property
    

    3) And you'd call it like this:

    If not myCollection.IsValid then ....show your "Not valid" message or whatever, else....Save

     

    Hope that helps a little

    Martin

  •  05-20-2008, 8:32 AM 9361 in reply to 9350

    Re: Validation problem - C#

    Martin,

    That was a big help!!!

    It got me headed in the right direction and my problem is now solved.

     

    Thanks for your help,

    Howard 

     

     

  •  05-20-2008, 8:53 AM 9362 in reply to 9361

    Re: Validation problem - C#

    Great - glad you got it sorted Howard

    Martin

View as RSS news feed in XML