开发者

Is there a kind of design pattern or a methodology to delete a record on Db from UI?

开发者 https://www.devze.com 2023-02-24 08:22 出处:网络
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?

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.


  1. Delete link in Web UI should open "Delete page".
  2. On GET "Delete page" should validate preconditions like existing of related records. Do not display form if validation fails.
  3. POST to "Delete page" should validate preconditions again and delete database record in ONE database transaction
  4. If second validation fails or any database exception raised display general error message.


When you delete a record, you can do a few things:

  1. Check if the item is still in sync in the database. (this step can be optional depending on scenario)
  2. Execute the delete.
  3. 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.
0

精彩评论

暂无评论...
验证码 换一张
取 消