使用哪些技术将列表限制为活动项目,除非出于历史目的需要包含非活动项目?

发布于 2024-11-09 11:56:12 字数 907 浏览 0 评论 0原文

例如,假设我有 3 种可能的项目状态:

  1. 打开、
  2. 关闭
  3. 、非活动

假设我创建了两个项目,一个状态为“打开”,另一个状态为“非活动”。然后,在未来的某个地方,状态“Inactive”不再相关,因此通过状态表中的某些“IsActive”标志将其停用。这会导致它不再显示在绑定到 DropDownList 或等效列表的状态列表中。

因此,现在当用户创建新项目项时,“添加新项目”屏幕应该只显示两种活动状态:“打开”和“关闭”。但现在假设他们正在编辑过去的项目,这些项目的状态可能不再处于活动状态和可用状态。使用什么技术将非活动状态包含在列表中,至少直到使用活动状态重新保存为止? (尽管我可能会允许使用较旧的状态重新保存。)

我看到了一些选项,但在我不确定哪个是最容易维护之前从未解决过这个问题:

  1. 始终从存储库中选择所有可能的状态,并在托管代码中,过滤掉除项目上当前设置的状态之外的非活动状态,并使用此列表进行绑定。
  2. 仅从存储库中选择活动状态,并在托管代码中将项目中的状态附加(合并)到列表中,并与此列表绑定。
  3. 将项目的标识符传递给检索状态的 SQL,并使用它将项目的当前状态 UNION 到活动状态列表,并使用此列表进行绑定。

每一个看起来实施起来都相当简单,但就像我说的,我对这种情况没有经验。我有几个可以通过管理员可用的维护屏幕激活/停用的项目列表;有些将保持相当静止,但有些会无限增长。当列表变得相当大时,选项 2 和 3 是最有效的,但选项 1 似乎可能是最容易实现的。

在这一点上,我更关心时间而不是性能。我正在开发 ASP.NET 应用程序、.NET 2.0、C#、UI 的 Web 表单以及用于数据层的 (I/My)Batis.NET,该数据层与 SQL Server 数据库通信。

StackOverflow 的大神们,您建议我做什么?

For example, let's say I have 3 possible project statuses,

  1. Open
  2. Closed
  3. Inactive

Let's pretend I've created two projects, one with a status of "Open" and the other with status of "Inactive." Then, somewhere down the road, the status "Inactive" is no longer pertinent so it is deactivated via some "IsActive" flag in the table of statuses. This causes it to no longer show up in the list of statuses bound to a DropDownList or equivalent list.

So, now when users create new project items, the "Add New" screen should only show the two active statuses, Open and Closed. But now let's say they are editing past projects whose statuses may no longer be active and available. What techniques are used to include the inactive status in the list, at least until they have re-saved using an active status? (Though I would probably allow re-saving with the older status.)

I see a few options, but having never solved this problem before I'm not sure which would be the easiest to maintain:

  1. Always select all possible statuses from the repository, and in managed code, filter out the inactives except for the status currently set on the project, and bind using this list.
  2. Select only active statuses from the repository and append (merge), in managed code, the status from the project into the list, and bind with this list.
  3. Pass an identifier for the project through to the SQL that retrieves the statuses and use it to UNION the project's current status to the list of active statuses, and bind using this list.

Each seems like it would be fairly trivial to implement, but like I said, I'm not experienced with this situation. I have several lists of items that can be activated/deactivated through maintenance screens available to administrators; some will remain rather static, but a few will grow indefinitely large. Options 2 and 3 would be the most efficient when the lists grow rather large, but option 1 seems like it might be the easiest to implement.

I'm more concerned about time than I am about performance that this point. I'm working on an ASP.NET application, .NET 2.0, C#, web forms for the UI and (I/My)Batis.NET for the data layer, which talks to a SQL Server database.

What would you suggest I do, gods of StackOverflow?

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

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

发布评论

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

评论(1

鱼窥荷 2024-11-16 11:56:12

我通常使用以下方法:

  1. 检索状态值的方法将采用一个可选参数(或在 .NET 2.0~3.5 中具有重载),该参数将指定是否获取非活动值。因此,您可以选择仅获取活动状态或所有雕像 - 根据您的需要使用。

  2. 很多时候,会获取所有状态,因为屏幕将用于添加/编辑/查看目的。但是,添加/编辑/查看对话框是在客户端启动的,无需任何回发。因此,状态下拉列表将包含所有状态值,并且非活动值将用某些 CSS 类进行修饰,以便它们显示为红色以指示不活动。在添加模式下,js代码(使用jquery)将隐藏非活动状态值。当然,后端业务逻辑中有验证来检查状态代码的有效性。

I typically use following approach:

  1. The method that retrieves status values will take an optional parameter (or have an overload in .NET 2.0~3.5) that will specify whether to fetch inactive values or not. So you have a choice to fetch only active statuses or all statues - use as per your need.

  2. Many times, all statuses are fetched because the screen will be used for add/edit/view purpose. However, add/edit/view dialogs are launched at client side w/o any post-backs. So status drop-down will have all status values and inactive values will be decorated with certain CSS class so that they appear in red color to indicate being inactive. In add mode, js code (using jquery) will hide inactive status values. Of course, there are validations in back-end business logic to check validity of status code.

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