是否有一种设计模式或方法可以从 UI 中删除 Db 上的记录?

发布于 2024-10-31 17:35:00 字数 228 浏览 1 评论 0原文

当涉及从数据库中存在的用户界面删除记录时,是否有任何常用的方法或一种设计模式或模型?

基本上应该采取以下步骤以及何时采取(例如验证、删除主记录、出现异常时如何处理)

与 REFERENCE 约束冲突

如何处理异常或通知用户失败(如何将 BL 失败信息传输到 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 database?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浮华 2024-11-07 17:35:00
  1. Web UI 中的删除链接应打开“删除页面”。
  2. 在 GET 上,“删除页面”应验证先决条件,例如相关记录是否存在。如果验证失败,则不显示表单。
  3. POST 到“删除页面”应再次验证先决条件,并删除一个数据库事务中的数据库记录。
  4. 如果第二次验证失败或引发任何数据库异常,则会显示一般错误消息。
  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.
人疚 2024-11-07 17:35:00

删除记录时,您可以执行以下操作:

  1. 检查该项目是否仍在数据库中同步。 (根据场景,此步骤可以是可选的)
  2. 执行删除。
  3. 如果删除成功,则更新 gui,如果失败,捕获异常并且不更新/更改 gui。

您的业​​务层使用什么?您使用什么 API 在代码中检索和存储数据?

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?

青瓷清茶倾城歌 2024-11-07 17:35:00

首先,我认为您需要将数据层与实际的后端数据存储分开。你可以使用 NHibernate 或 Microsoft 的实体框架来使 ORM(对象关系映射)更容易。这样,您在 GUI 中显示的数据就代表了代表数据库中数据的对象。

您可以使用 MS Entreprise Libraries Validation 块进行验证。

还取决于您使用的是 Winforms 还是 WPF。您必须确保某种服务/模型正在处理所有 CRUD 操作而不是 GUI,以便您可以通过单元测试来测试更新位

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

泅人 2024-11-07 17:35:00

对于您描述的数据库问题,请考虑采用集中式异常管理策略,以便在数据层中一致地捕获和抛出异常。您应该:

  • 确定应在数据访问层中捕获和处理的异常(例如,死锁、连接问题可以在 DAL 中解决)
  • 但是,您提到的异常(例如违反约束)应向用户显示以供解决
  • 考虑 SaveCustomer () 方法,如果检测到特定异常(不是基本异常类),请允许该异常向上冒泡到调用数据层或服务的业务层。然后,业务层可以收集遇到的任何异常并抛出自定义异常,该异常可以由您的 UI 进行适当处理。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文