Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
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
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
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.
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
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
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
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
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
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
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
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
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Is it this? myBO.CurrentDataTable.Columns[myCol.ColumnName] The DataRow has a similar definition: myDataRow.Table.Columns[myCol.ColumnName]
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
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?
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Here is the offending code: private class Field_lentolerance_Descriptor : MicroFour.StrataFrame.Business.FieldPropertyDescriptor { public Field_lentolerance_Descriptor() : base("lentolerance") { } private System.Type _PropertyType = typeof(System.String); public override object GetValue(Object component) { return ((PartsBO)component).lentolerance; } public override void SetValue(Object component, object Value) { ((PartsBO)component).lentolerance = (System.String)Value; <----THIS IS THE OFFENDING LINE } public override System.Type PropertyType { get { return this._PropertyType; } } public override System.Type ComponentType { get { return _ComponentType; } } }Since this code is in the designer class, I assume there is a way to handle this via the Object Mapper. I'm just not seeing it. Bill
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
You cannot set a NULL value through the strong-typed property... and the .Item property (the indexer in C#, where you just use the []) uses those strong-typed properties. In order to copy over the NULL values, you will need to bypass the strong-typed properties by using the .CurrentRow property like so: In your foreach loop, change the: partsBO1.Items(mCol.ColumnName) = mCurrentPart.Items(mCol.ColumnName); to: partsBO1.CurrentRow[mCol] = mCurrentPart.CurrentRow[mCol.ColumnName]; If you noticed, I used the column reference on the first and the column name on the second... that's because the fastest way to reference a column of a DataRow is by passing the column reference, but since the column belongs to the first BO and not the second, you have to use the name to reference the second one. You could use the name on both, but then the DataRow would just use the name to find the column reference and then use it, so you might as well pass the column reference since you have it.
|
|
|