Copy Current Record


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
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

Replies
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Here is my implementation of copying the current record into the same business object in a ListView control.

Private Sub tsbCopyAndAddRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbCopyAndAddRecord.Click

     '-- If there is not item selected in the list, then

     '-- instruct the user to select a record first.

     If Me.lstItems.SelectedItems.Count = 0 Then

          Me.ShowMessageByKey("SelectRecordToCopy")

          Exit Sub    

     End If

     Try

          '-- Save off the current row

          Dim copyRow As DataRow = Me.BizItems1.CurrentRow

          If Me.BizItems1.NewRow() Then

               '-- Now update each of the columns within the new row.

               For Each col As DataColumn In Me.BizItems1.CurrentDataTable.Columns

                    '-- Skip the Primary Field, since the field is autoincremented or

                    '-- a generated GUID

                    If col.ColumnName = Me.BizItems1.PrimaryKeyField Then

                         Continue For

                    End If

                    '-- Do the actual copy of each field or column here.

                    Me.BizItems1.CurrentRow(col) = copyRow(col)

               Next

               '-- Show the ChildForm for the copied record.

               Me.EditChildRecord()

          End If

     Catch ex As Exception

     End Try

End Sub

In the above code I am using a method EditChildRecord() that I created from the source code of the listview, which I requested an enhancement to make this method public or shared here http://forum.strataframe.net/Topic19108-9-1.aspx for this kind of functionality.  I am not including my version here since I hope it will be made available to use in the framework.

Edhy Rijo

Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Hi Edhy

Thanks for your commentes. Can you post a sample of how to make the EditChildRecord?

Regards

Smile Everything is possible, just keep trying...

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Juan Carlos Pazos (02/15/2009)
Hi Edhy

Thanks for your commentes. Can you post a sample of how to make the EditChildRecord?

Regards

Juan Carlos, here ae the two mehods need for this functionality, I simply copied them from the source to the form where the ListView is being used and modified as needed.

''' <summary>

''' 09/08/2008 Edhy Rijo

''' Edits the currently selected child record

''' This method should be use temporarily until the internal one in the listview

''' is made available by SF Team

''' </summary>

''' <remarks></remarks>

Private Sub EditChildRecord()

     Dim bo As BusinessLayer = Me.lstItems.BusinessObject

     '-- If no business object is attached then there is nothing to do

     If bo Is Nothing Then Exit Sub

'-- See if a snapshot should be taken

If Me.lstItems.AutoSnapshotBusinessObject Then bo.SaveCurrentDataTableToSnapshot(Me.lstItems.AutoSnapshotKey)

'-- Ensure the the correct record is selected in case it had been moved by the developer

               bo.NavigateToPrimaryKey(Me.lstItems.SelectedItems(0).Tag)

               '-- Place the record in edit mode

               bo.Edit()

               '-- See if there is a child dialog

               If lstItems.ChildForm IsNot Nothing Then

                    '-- Raise the before child form executed event

                    ' OnBeforeChildFormExecuted(New ListViewBeforeChildExecuteEventArgs(ListViewChildFormAction.Edit))

                    '-- Call the child form and create the args

                    Dim args As New MicroFour.StrataFrame.UI.Windows.Forms.ListViewChildFormResultsEventArgs(MicroFour.StrataFrame.UI.ListViewChildFormAction.Edit, Me.lstItems.ChildForm.ShowDialog())

                    ''-- Raise the event

                    Me.lstItems_ChildFormResults(Me.lstItems, args)

                    '-- See if the list should be requeried

                    If args.Requery Then

                         '-- Save off the primary key value

                         Dim reselect As Boolean = True

                         Dim pk As Object = Nothing

                         Try

                              pk = bo.CurrentRow(bo.PrimaryKeyField)

                         Catch ex As Exception

                              reselect = False

                         End Try

                         '-- Requery the list

                         Me.lstItems.Requery()

                         '-- Attempt to select the item

                         If reselect Then SelectIndexByPrimaryKey(pk)

                    End If

               End If

End Sub

''' <summary>

''' 09/08/2008 Edhy Rijo

''' Attempts to select the row index associated with the specified primary key

''' This method is used by EditChildRecord

''' This method should be use temporarily until the internal one in the listview

''' is made available by SF Team

''' </summary>

''' <param name="primaryKey"></param>

''' <remarks></remarks>

Private Sub SelectIndexByPrimaryKey(ByVal primaryKey As Object)

     For Each i As ListViewItem In Me.lstItems.Items

          If i.Tag.Equals(primaryKey) Then

               '-- Select the item

               i.Selected = True

               '-- Ensure this item is visible

               Me.lstItems.EnsureVisible(Me.lstItems.Items.IndexOf(i))

               '-- Nothing left to do

               Exit For

          End If

     Next

End Sub



Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Bill Cunnien - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
Paul Chase - 17 Years Ago
                         Excellent Paul! Thanks!! I am wondering, though, why no property...
Bill Cunnien - 17 Years Ago
                             Is it this? myBO .CurrentDataTable.Columns[myCol.ColumnName] The...
Bill Cunnien - 17 Years Ago
                                 Ran into another issue while testing...null values. These things just...
Bill Cunnien - 17 Years Ago
                                     Here is the offending code: private class...
Bill Cunnien - 17 Years Ago
                                         You cannot set a NULL value through the strong-typed property... and...
StrataFrame Team - 17 Years Ago
                                             [quote][b]Ben Chase (01/23/2008)[/b][hr] partsBO1.CurrentRow[mCol] =...
Bill Cunnien - 17 Years Ago
                                                 Woops, didn't look at the sample closely enough... didn't realize you...
StrataFrame Team - 17 Years Ago
                                                     [quote][b]Ben Chase (01/24/2008)[/b][hr]try this instead:...
Bill Cunnien - 17 Years Ago
Edhy Rijo - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Edhy Rijo - 17 Years Ago
                         There is not a framework function to do this....you are really better...
Trent L. Taylor - 17 Years Ago
                             Thanks again, will follow your advice.
Edhy Rijo - 17 Years Ago
                                 Here is my implementation of copying the current record into the same...
Edhy Rijo - 17 Years Ago
                                     Hi Edhy Thanks for your commentes. Can you post a sample of how to...
Juan Carlos Pazos - 16 Years Ago
                                         [quote][b]Juan Carlos Pazos (02/15/2009)[/b][hr]Hi Edhy Thanks for...
Edhy Rijo - 16 Years Ago
Juan Carlos Pazos - 16 Years Ago
Edhy Rijo - 16 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search