Subject saving atomic data :)
Author Duilio Foschi
I want to save an invoice which is made of a header and N detail rows (with
N>=1).

The user inputs invoice data via a normal master/detail form with 2 grids,
2 navigators, 2 queries and 2 datasources.

I need to prevent:

1. an orphaned header (i.e. that a header is inserted with no detail row)
2. an orphaned detail row (i.e. that one or more detail rows are inserted
with no header)

If I had to test condition 1. only, I would insert the detail rows first,
then perform the check in the BeforePost event of the header table.

If I had to test condition 2. only, I would insert the header first, then
perform the check in the BeforePost event of the detail table.

However, I cannot understand how I can easily test both conditions.

I have deviced a clever method so that the AfterInsert event of the header
table inserts a new record in the detail table, then the AfterPost event of
the header table issues a Post of the detail table, etc.

But I can see tons of subtle problems.

I thought to use the BeforeCommit event of the current transaction, but
several invoices could have been inserted by the user before he issues a
commit, and I don't know how to go back to everyone of them.

On top of it, it would be very unconvenient to have to rollback several
input invoices.

There must be a clean, smart way to do what I want, but I cannot see it.

Any help ?

Thank you

Duilio Foschi