Click here to Skip to main content
15,921,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to multitier programming and I'm searching answers for some 'simple' questions. I hope you can help me out.

All the examples about multitier programming I found on the internet make changes permanent to the database immediately. This is understandable for a web-application but not for a desktop-application. For example in the following situation:

A user edits an existing order in the system. An order screen opens and the user changes some products. Changes of these products are handled by the business layar, which automatically adds new jobs (which the user can change if needed). Now the user clicks on the cancel button of the order. So the order, the changed products and the new jobs don't need to be stored to the database. But the business layar already made these changes permanent!

Code example:
Order = OrderAdapter.GetOrderByID(OrderID)
Order.Date = Date.Now
OrderAdapter.SaveOrder(Order)

Product = ProductAdapter.GetProductByID(ProductID)
Product.Name = "Software"
ProductAdapter.SaveProduct(Product) 'A new Job is automatically added by the business layar.

'How to handle a click on the Cancel-button on the order form?


How do you handle such a situation? In 'old fashioned programming', I would save the order to the database only when the OK-button on the order form was pressed. But in a multitier environnement the business layar changed the products and jobs already to the database, before the OK-button of the order was pressed.

Any help would be greatly appreciated!!!
Posted

1 solution

Use transactions.

When the user begins some process, start a transaction. For each step the user takes the transaction can keep track of each operation and maintain it in memory - the in memory part here is important. Every step in the transaction is not permanent, instead it's only a token or a reminder of what needs to be done when the transaction as a whole is committed. At the end of the transaction - here when they click OK - the transaction can cycle through operations that the user has done and actually do what the user wants. This is where things are written to the database, orders are submitted or whatever else has to be done.

With this design the user can hit CANCEL at any time and you can simply throw out the current transaction object without committing it and without making any changes to the system.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900