Looping through BO fields


Author
Message
Ben Kim
Ben Kim
StrataFrame Novice (115 reputation)StrataFrame Novice (115 reputation)StrataFrame Novice (115 reputation)StrataFrame Novice (115 reputation)StrataFrame Novice (115 reputation)StrataFrame Novice (115 reputation)StrataFrame Novice (115 reputation)StrataFrame Novice (115 reputation)StrataFrame Novice (115 reputation)
Group: Forum Members
Posts: 99, Visits: 253
I want to create a generic sub that will loop through the BO field collection, picking up only the database fields of course, determine the field type and if it is of type String, trimend.

Right now I have code like this in the CheckRulesOnCurrentRow event:

' Trim off trailing spaces
Me.ClassType = Me.ClassType.TrimEnd()
Me.LocalState = Me.LocalState.TrimEnd()
Me.OffenseClass = Me.OffenseClass.TrimEnd()
Me.DescriptionText = Me.DescriptionText.TrimEnd()

and so forth for every string based field.  I would like to do something like (pseudo code):

Public Sub TrimAll(ByRef MyBO As BusinessObject)

    For Each DBField In MyBO ' How to determine the property is a DBField???
          If DBField.Type = StringType  ' Is it stored in the BO as a String or as the DBType?
               DBField.FieldValue = Me.DBField.TrimEnd()
          End If

    End For
End Sub

Again this way I can create a generic sub, pass the BO to the function from the CheckRulesOncurrentRow event and have the fields trimmed for me instead of listing dozens sometimes hundreds (depends on table) of fields to do the same.

Sorry for all of the newbie type questions!

Ideas?

Ben


StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You could cycle through the fields in the AllFields collection like this:

For Each field As String In BO.AllFields
    Select Case BO.FieldDbTypes(field)
        Case System.Data.DbType.String, System.Data.DbType.StringFixedLength, _
            System.Data.DbType.AnsiString, System.Data.DbType.AnsiStringFixedLength
            '-- Trim the field
            BO.Item(field) = CType(BO.Item(field), String).Trim()
        Case Else
            '-- Do whatever else you want to do to the other data types
Next

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Oh, and you won't have to pass the business object by reference... ByVal will work fine since you aren't going to return a different business object to the calling method... business objects are classes, which are already reference types.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search