Is there a kind of design pattern or a methodology to delete a record on Db from UI?
Is there any commonly referred methodology or a kind of design-pattern or a model when it comes to delete a record from user interface which exists in a dat开发者_运维问答abase?
Basically what following steps should be taken and when (like validation, deleting the main record, how to handle when there is a
Conflict with the REFERENCE constraint
How to handle exceptions or notifying user on a failure (how to transfer the BL failure info to the UI; by catching exceptions or some report object etc.) and more or less the most common issues regarding to the deletion context.
- Delete link in Web UI should open "Delete page".
- On GET "Delete page" should validate preconditions like existing of related records. Do not display form if validation fails.
- POST to "Delete page" should validate preconditions again and delete database record in ONE database transaction
- If second validation fails or any database exception raised display general error message.
When you delete a record, you can do a few things:
- Check if the item is still in sync in the database. (this step can be optional depending on scenario)
- Execute the delete.
- If delete suceeds, then update the gui, if it fails, catch the exception and do not update/change the gui.
What are you using for your business layer, and what API's are you using to retreive and store data in your code?
First things first i think you need to separate your DataLayer from the actual back end data store. you could NHibernate or Microsoft's Entity Framework to make ORM (Object Relational Mapping) easier. So that your data your show in your GUI represents object which represents data in the DB.
you could use MS Entreprise Libraries Validation block to the validation.
Also depends if you are using Winforms or WPF. you have to make sure some sort of Service/Model is handling all the CRUD ops and not the GUI so that you can test the updating bit with unit tests
For database issues like you describe, consider a centralized exception management strategy so that exceptions are caught and thrown consistently in you data layer. You should:
- Identify the exceptions that should be caught and handled in the Data Access Layer (e.g deadlocks, connection issues can be resolved within the DAL)
- However, exceptions that you mention such as constraint violations should be surfaced the user for resolution
- Consider a SaveCustomer() method in your data layer, if a specific exception (not the base Exception class) is detected, allow this to bubble up to your business layer which is calling the data layer or service. The business layer could then collect any exceptions encountered and throw a custom exception which could be handled appropriately by your UI.
精彩评论