StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      


12»»

Copy Current RecordExpand / Collapse
Author
Message
Posted 01/21/2008 4:47:18 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 7:34:01 AM
Posts: 437, Visits: 1,755
I searched the forum in vain for an answer to this.  How do I copy the current record of  BO to a new record in the same BO, reset a couple of values, navigate to that new record and allow the user to alter any necessary fields before saving?  This seems very simple.

Thanks,
Bill

Post #13603
Posted 01/21/2008 4:59:09 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 4:52:53 AM
Posts: 4,586, Visits: 4,571
Yeah, you can just create a shared (sorry static since you are C# ) method that copies the data out of the row.  This is probably something we could add to the Tools.Common class, but just haven't as of yet.

'-- Save off the current row
Dim copyRow As DataRow = MyBo.CurrentRow
MyBo.NewRow()

'-- Now update each of the columns within the new row.  You may want to test
'    on certain column names to be excluded, such as PK fields.
For each col as DataColumn In MyBo.CurrentDataTable.Columns
    MyBo.Items(col.ColumnName) = copyRow.Item(col.ColumnName)       
Next

I didn't run this to make sure that the copyRow didn't move (I just typed it in here) but it should be close enough to get you going.

Post #13606
Posted 01/21/2008 5:17:39 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 7:34:01 AM
Posts: 437, Visits: 1,755
I did something similar a couple of minutes ago.  I added a BO to the form and named it PartTempBO.  When the user clicks the button, I fill that BO with the FillByPrimaryIndex method from the index of the primary BO.  Then, I run the Add() method on the primary BO.  I manually set the properties of the new record to the properties of the temp record (except the differentiating field...partnum); however, after reading your reply, I think I will try the walk the collection route.  That would be easier...especially, since I know we will be modifying that data table's structure over the next several weeks.

Thanks a lot for your help!
Bill

Post #13608
Posted 01/21/2008 6:41:53 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 7:34:01 AM
Posts: 437, Visits: 1,755
There does not appear to be an items collection within the business object.  Here is my code:

DataRow mCurrentPart = partsBO1.CurrentRow;
partsBO1.Add();
foreach (DataColumn mCol in partsBO1.CurrentDataTable.Columns)
{
   
if (mCol.ColumnName!="partindex")
    {
        partsBO1.Items(mCol.ColumnName) = mCurrentPart.Items(mCol.ColumnName);
    }
}

The items (in red) do not exist (at least, not by intellisense; therefore, compiler won't like it either).  I cannot seem to find anything comparable in the BO.

Also, is there a way to tell if the column is a PK or not?

Oh, I am using Add() rather than NewRow() because I need the user to save the data after he is done updating the record.  The NewRow() adds the appropriate empty row, but leaves the state unchanged.  The Add() method does create a new row, but it also places the item into an editable state.  The beauty there is that all of the bound controls are refreshed, too.

Thanks!
Bill

Post #13613
Posted 01/22/2008 8:43:43 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 7:42:15 AM
Posts: 359, Visits: 2,323
Bill you can just drop the .items.

For example MyBO("ColumnName") = proposed value or you could do mybo.currentdatatable.items("columnname") = proposed value. the first example is probably better has it calls through SF logic thus events are raised etc.

To find the primary key you can check the primary key field property .

if mCol.ColumnName = mybo.primarykeyfield then

 it is the primary key

endif

However if you are using compound pk's then there is a primarykeyfields collection you would have to loop through the collection to check if it was a PK.

Hope that helps

Paul

Post #13617
Posted 01/22/2008 10:55:52 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 7:34:01 AM
Posts: 437, Visits: 1,755
Excellent Paul!  Thanks!!

I am wondering, though, why no property explicitly exists in the business object called "FieldName".  Over time I have forced myself not to use shortcuts like this one (e.g. myBO[myCol.ColumnName]).  I would rather do something like myBO.FieldName[myCol.ColumnName].  The code is a tad more readable.  The default property can change (doubt it will, but I have no control over that) so this would eliminate a lot of code fixups later down the road.

Maybe it is there and I just am not referencing it correctly.  Still learning. 

Bill

Post #13621
Posted 01/22/2008 11:00:24 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 7:34:01 AM
Posts: 437, Visits: 1,755
Is it this?

myBO.CurrentDataTable.Columns[myCol.ColumnName]

The DataRow has a similar definition:

myDataRow.Table.Columns[myCol.ColumnName]

Post #13622
Posted 01/22/2008 12:34:35 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 7:34:01 AM
Posts: 437, Visits: 1,755
Ran into another issue while testing...null values.  These things just get everywhere...like a bad rash!  Even after I have the replace value option set on a specific column, the error thrown is a null value issue.  It is trying to copy a null and it doesn't like it.  Any words of wisdom on this one?
Post #13631
Posted 01/22/2008 1:55:01 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 7:34:01 AM
Posts: 437, Visits: 1,755