Auto add row to child bo when add row to parent bo


Author
Message
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
No problem Smile
Attila Dobozi
Attila Dobozi
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 14
You've answered all  my questions.  Thank you.Smile
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
I don't think the CopyDataFrom will work because that either adds new rows, which I don't want, or replaces the entire DataTable, again, not what I'm looking for.  I just want to update a couple of fields in the Parent current row. 

No.  You can definitely make the CopyDataFrom method work in this scenario.  Delete the record out the the current BO without updating the server:

'-- Remove the existing record
MyBo.DeleteCurentRow(True)
MyBo.CurrentDataTable.AcceptChanges()

'-- Get the new record
Using bo As New MyBoType
    bo.FillByPrimaryKey(changedPk)

   '-- Copy the data back into the source BO
   MyBo.CopyDataFrom(bo,AppendFromCurrentDataTable)
End Using

I solved this with a SqlCommand/SqlDataReader to fetch the fields for the current row then copying them from the reader back to Parent.currentRow.  Changing Parent field values set the form to edit mode so when I close the window it asks to save/cancel.  Is there a way to suppress changing edit states?

You can do that as well.  You cannot supress the states from changing but you can call AcceptChanges to accept the state of the data as it is in the BO which will then make the BO think that data in the BO and on the server are the same.

Attila Dobozi
Attila Dobozi
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 14
What I mean by refreshing the current Parent row from the database is that  out of the 100 rows in Parent I know that the current row's data has been changed by an sproc in the database so I want to update the current, one, Parent row with the data from the database.  I still want to keep the other 99 rows in the Parent. 

I don't think the CopyDataFrom will work because that either adds new rows, which I don't want, or replaces the entire DataTable, again, not what I'm looking for.  I just want to update a couple of fields in the Parent current row.   

I solved this with a SqlCommand/SqlDataReader to fetch the fields for the current row then copying them from the reader back to Parent.currentRow.  Changing Parent field values set the form to edit mode so when I close the window it asks to save/cancel.  Is there a way to suppress changing edit states?

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
So far I couldn't find a way in SF to refresh only the current Parent row from the database. 

I am not sure what you are referring to by Refresh.  Are you referring to updating the data back to the server or refreshing the UI?

I looked at the AppendDataTable function, hinted at by another post, but could not make it work and could not find it in the help.

Use the CopyDataFrom method on the BO.  If you only want a single record, then fitler out the records on the source BO or data tables default view, then either do an append or clear and fill on the second parameter using the view option.

Attila Dobozi
Attila Dobozi
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 14
Thank you for the warning.  I will make sure to turn off the parent's AutoChildFilter before adding a new child. 

I am loading all the GrandChild records for the Parent because even in an extreme case there would only be about a dozen of them.  I figured having them filtered locally would reduce hits on the server vs loading them a few at a time when navigating the Child data. 

Also, I have to rollup GrandChild data into the Parent so all the GrandChild records are needed locally.  I'm still figuring out if it is better to scan through (after turning off the child filter) the GrandChild records and updating the Parent before save or to call a sproc post save then repopulate the Parent with the updated info.  So far I couldn't find a way in SF to refresh only the current Parent row from the database.  Currently the Parent is a SELECT TOP 100 query.  I looked at the AppendDataTable function, hinted at by another post, but could not make it work and could not find it in the help.

The rolled up fields (from GrandChild to Parent) can't be calculated/custom fields because depending on user settings the user may desire to enter only the total, Parent, value instead of the detail, GrandChild, values.

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
You are correct in what you discovered, but one thing that I might caution you on here is using the AutoChildFilter option.  This is a great feature, but I thought I would give you a warning before you start "wondering where your records are going" or "something is moving the CurrentRowIndex." Smile

There is a time and place to use the ChildAutoFilter option but it is generally a better development practice to NOT use this on a maintenance form and only bring back the records that you intend to work with.  When you are using the auto filtering, generally you assume that you are bringing back more records back from the server that you are working with...though this is not the issue I was referring to, it can cause performance issues on larger record sets when retrieving the records from the server.

The issue that I was referring to is that when you add a new child or grandchild record that is filtered, the filter is dynamic, so it is immediately applied and you can be, in many cases, immediately modifying the wrong record since the filter may have moved the records around.  The same thing applies to a sort.  If you are going to use this approach then be sure to turn off the auto-filter when adding a new record and then set it back once the new record is added so that the foreign key can be set (which is what the filter would be setting in most cases).  Hope that makes sense Smile

Attila Dobozi
Attila Dobozi
StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)StrataFrame Beginner (4 reputation)
Group: Forum Members
Posts: 4, Visits: 14
I have three business objects on a maintenance form, Parent, Child, Grandchild.  The Child and Grandchild are both filled for the Parent.  The Grandchild contains all rows that belong to all Child rows for the current Parent.  The Child.ChildAutoFilterOption = MatchCurrentRow.

The Parent is tied to the MaintenanceToolstrip.  The Child is tied to a second, custom, toolstrip.
When Parent changes the Child and Grandchild are filled appropriately.  Navigation and editing work.

When adding a Child I want to also add a Grandchild.  In the custom toolstrip cmdAdd.Click() function I call Child.AddNew().  The Child.AfterAddNew() event calls GrandChild.Add().  When I trace into the GrandChild.SetDefaultValues() I see that the field values show the previous GrandChild row data instead of the new row data (the GrandChild pk is not -1).  It looks like I'm overwriting the previous GrandChild row's data with default values. 

There is a GrandChild_Navigated event on the form where I messagebox the Child and GrindChild pks.  The messagebox does not popup after the GrandChild.AddNew() or GrandChild.SetDefaultValues().  The messagebox pops once with Child.pk = -1 and GrandChild.pk = 88 (prev GrandChild.pk value) and immediately pops again with Child.pk=-1 and GrandChild.pk = -1. 

... a day later ...

Never mind.  If I call GrandChild.Add() in the cmdAdd.Click() after calling Child.Add() it works.  It looks like the Child_AfterAddNew() event occurs before the Child filter and GrandChild navigation occurs so GrandChild defaults are assigned to the wrong row.  So the lesson is don't call AddNew() on a child bo from the parent's AfterAddNew event.  I'm evaluating SF so couldn't trace into its source otherwise I would've figured this out sooner.

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