Best practice for changing form values


Author
Message
Andria Jensen
Andria Jensen
StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)
Group: Forum Members
Posts: 336, Visits: 497
I have several controls on a form, all with BindingField properties set on them.  When one changes, it affects the value of several others.  For example, I may have a Days field which affects the calculation of a Date2 field.  This would be something like Date2=Date1+Days.  When I type a value into the Days field I want it to update Date2 with whatever is in Date1 plus whatever I just typed into Days.

My question is how to best do this when binding to a BO field.  There seems to be some odd behavior in which it is struggling to know whether to use the data in the BO or the data in the field.  How do I make this work correctly??

Paul Chase
Paul Chase
Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
Andria,

I am doing this type of thing by having the BO raise a field changed or changing event and then handling that event and setting the values. It works out great except if with a business binding source, then you will run into some issues with this appoach.

You can also just add the code to the set method of the field to change the values of the other fields as well.

''' <summary>

''' cki_Amount

''' </summary>

''' <remarks></remarks>

<Browsable(False), _

BusinessFieldDisplayInEditor(), _

Description("cki_Amount"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _

Public Property [cki_Amount]() As System.Decimal

Get

Return CType(Me.CurrentRow.Item("cki_Amount"), System.Decimal)

End Get

Set(ByVal value As System.Decimal)

'Set the Value 's of whtever else

me.someproperty  = somevalue

'Set the Value

Me.CurrentRow.Item("cki_Amount") = value

End Set


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Andria,

Pauls example is very good and it will keep the logic within the BO using this approach and it is probably the cleanest solution.  There are also times that this may be more of a "one-time-thing" and I might handle a SelectedIndexChanged event or a TextChanged event, something of that nature, to add the logic.  However, this does break encapsulation and if the same logic is required in another location then you are asking for a bug.  The best and safest approach is Pauls example.

Andria Jensen
Andria Jensen
StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)
Group: Forum Members
Posts: 336, Visits: 497
Great thanks, that's just what I was looking for.  BigGrin
Andria Jensen
Andria Jensen
StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)
Group: Forum Members
Posts: 336, Visits: 497
Okay, I think maybe I found a bug with this.  When I went in and added the FieldPropertyChanged event, the code generated an extra 'End If' in 4 of my properties.  Turns out these are the only properties set to  'Return Alternate on Null/Set Null on Alternate (value type)' in this business object.  The code it generated looks like the following.  The extra 'End If' is bolded.

''' <summary>
''' NextRunDate
''' </summary>
''' <remarks></remarks>
<Browsable(False), _
BusinessFieldDisplayInEditor(), _
Description(
"NextRunDate"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Property [NextRunDate]() As System.DateTime
 
Get
    Dim loValue As Object
    loValue = Me.CurrentRow.Item("NextRunDate")
   
If loValue Is DBNull.Value Then
     
Return #1/1/1800#
   
Else
     
Return CType(loValue, System.DateTime)
   
End If
  End Get
  Set(ByVal value As System.DateTime)
   
Dim llRaiseEvent As Boolean = False
   
Dim loRow As DataRow = Me.CurrentRow
   
If value <> #1/1/1800# Then
     
If Not loRow.Item("NextRunDate").Equals(value) Then llRaiseEvent = True
   
Else
     
If Not loRow.Item("NextRunDate").Equals(DBNull.Value) Then llRaiseEvent = True
    End If
End If
    If value <> #1/1/1800# Then
     
loRow.Item("NextRunDate") = value
   
Else
     
loRow.Item("NextRunDate") = DBNull.Value
   
End If
    
If llRaiseEvent Then Me.OnFieldPropertyChanged(Me, New   ABLFacilityBOFieldChangedEventArgs(ABLFacilityBOFieldNames.NextRunDate))
 
End Set

End Property


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
This has already been fixed...and talked about a lot lately Smile

Get the fix here: http://forum.strataframe.net/Topic11831-10-1.aspx#bm11844 

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
So this is were all those missing end ifs went! Tongue
Andria Jensen
Andria Jensen
StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)
Group: Forum Members
Posts: 336, Visits: 497
Ah, I must have missed the big conversation.  Thanks for the fix.
Andria Jensen
Andria Jensen
StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)
Group: Forum Members
Posts: 336, Visits: 497
Wait a second....you linked me back to my post.  And since that's my post, I already have those files which means they didn't fix that issue for me.  Crazy
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I was making a joke Tongue



The problem reported about a hundred times in the forms is missing end ifs in a BO designer when the field has alternate values on null.



Then you discover that when you add events to the properties, there are extra end ifs (different bug for sure), so, I was like, you know, er...just saying that we found all those missing end ifs from the first bug Blush
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