Ger Cannoll
|
|
Group: StrataFrame Users
Posts: 430,
Visits: 507
|
When I delete a row from within a Maintanance Form, I notice it deletes from the Database immediaitely, unlike when I edit rows, I can Undo before I save.
Is there a way of 'Holding' the deletes until I click on Save, so that any Deletes/ Edits are all done at the same time , an I am also given an option to 'Undo', for deletes
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hi Gerard. Have a look at the following: DeleteCurrentRow() - There are three overloads to this method. Depending on the parameters passed, this method will behave differently.DeleteCurrentRow() - When this overload is called, the record being deleted is immediately removed from the server and the internal data table is updated. DeleteCurrentRow(OnlyMarkAsDeleted) - When OnlyMarkAsDeleted is given a value of True, the current row is deleted within the internal data table only and a Save() must be executed before the changes are reflected back to the server. This is recommended when deleting a large number of records. DeleteCurrentRow(CheckSecurity, OnlyMarkAsDeleted) - When a value of True is passed to the CheckSecurity parameter, a security check will be forced by raising the CheckSecurity event on the business object, allowing the developer to place any Security on Delete code. The OnlyMarkAsDeleted parameter behaves identically to the DeleteCurrentRow(OnlyMarkAsDeleted) overload described above.
Note: All deletion methods return the number of records affected by the deletion. If a zero is returned, no records were deleted from the server.
|
|
|
Ger Cannoll
|
|
Group: StrataFrame Users
Posts: 430,
Visits: 507
|
Hi Ivan. Tnaks for replying.
How do I access the DeleteCurrentRow method with the various over-rides from a SF Maintanace Form ?
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Hi Gerard, Gerard O Carroll (7/20/2011) How do I access the DeleteCurrentRow method with the various over-rides from a SF Maintanace Form ?You can handle the BO.BeforeDelete event and manipulate the delete routine as you wish and then set the e.Cancel to True as shown in the code below:
Private Sub BizVendor1_BeforeDelete(e As MicroFour.StrataFrame.Business.BeforeDeleteEventArgs) Handles BizVendor1.BeforeDelete e.BusinessObject.DeleteCurrentRow(True) e.Cancel = True End Sub
Edhy Rijo
|
|
|
Ger Cannoll
|
|
Group: StrataFrame Users
Posts: 430,
Visits: 507
|
Hi Edhy. I put following code into the BeforeDeleteEvent: e.BusinessObject.DeleteCurrentRow(true, true); e.Cancel = true; It goes round in an infinite loop with following question: Are you sure you wish to delete the current record ? where I can select a yes or No button. My table only has about 10 records .This is on a Standard maintenance form and I dont have any other code in there.
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Hi Gerard, Why are you using the 2 overloads? are you checking security for deleting the record? if not, just use one parameter of True to mark the record as deleted without saving it to the database.
Edhy Rijo
|
|
|
Ger Cannoll
|
|
Group: StrataFrame Users
Posts: 430,
Visits: 507
|
Hi Edhy.
I was using the two overloads to 'Future Proof' tha app (I dont have Security switched on right now but do intend to )
I chnged just to have one overload and same thing... just keeps looping asking If I am sure I want to delete
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Gerard, you are getting an infinite loop because you are calling a Delete inside the BeforeDelete, which will trigger another BeforeDelete and so on.
You can either create your own Delete button and hide the one from the toolbar, or still use the BeforeDelete with the help of a flag. Something like:
#Region " Private Fields " Private _WeAreDeleting As Boolean = False #End Region #Region " Handled Events " Private Sub MyBO_BeforeDelete(ByVal e As MicroFour.StrataFrame.Business.BeforeDeleteEventArgs) Handles MyBO.BeforeDelete '-- if we are currently deleting, exit If _WeAreDeleting = True Then Exit Sub End If '-- set flag so we won't get into a looping _WeAreDeleting = True '-- mark for deletion MyBO.DeleteCurrentRow(True) '-- cancel standard deleting procedure e.Cancel = True '-- reset flag, since we are done
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Hi Ivan, Thanks for the clarification and the flag idea, it makes sense. Ivan George Borges (7/20/2011) Gerard, you are getting an infinite loop because you are calling a Delete inside the BeforeDelete, which will trigger another BeforeDelete and so on.That looks like a minor bug somewhere since the e.Cancel = True should be stopping any delete process, right?
Edhy Rijo
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hey Edhy!
Not really a bug. Remember we are starting a brand new Delete command right inside the BeforeDelete. This brand new Delete will call its own BeforeDelete, which is... this same BeforeDelete where we are. And then it will again hit the Delete call, which will trigger another one, and another one, and...
|
|
|