创建新记录时,如何使用过滤器中的值填充某些字段?

发布于 2024-08-11 05:41:52 字数 552 浏览 5 评论 0原文

我正在开发一个 ASP.NET 页面,它基本上是围绕数据库进行的快速破解。它用于内部项目,并且该站点的设置方式可以为多个人提供对数据的读/写访问权限。我们每周一次从中收集大量数据,将其添加到 XML 文件中,并将其作为应用程序更新的一部分发送给我们的客户。 (这些客户没有直接访问权限。)

由于这只是一个内部项目,因此几乎没有可用于其开发的预算。所以我们选择让事情变得简单。我们将数据存储在 SQL Server 数据库中,围绕该数据库创建了一个实体框架类以进行数据访问,并围绕它创建了一个动态数据站点 Web 应用程序。基本上,不需要编写太多代码就可以快速设置。它的效果也很好。特别是通过布尔字段和表引用过滤记录真的很酷。

然而,在数据输入过程中,一些用户会犯一些小错误。他们将过滤器设置为仅过滤表的子集,然后单击“新建”将记录添加到该子集。不幸的是,新记录并未默认为这些过滤器中的值,因此用户必须再次设置正确的值。可惜他们偶尔会错过这一点,因此某些记录最终会得到错误的值。

那么,当用户创建新记录时,如何确保该新记录将默认复制过滤器值? (并且仍然允许用户选择其他值!)

I'm working on an ASP.NET page, which basically is a quick hack around a database. It's used for an internal project and the site is set up in a way to provide several people read/write access to the data. Once a week, we collect a bunch of data from it, add it to an XML file and send it as part of an application update to our customers. (Those customers don't have direct access.)

Since it's just an internal project, there's almost no budget available for it's development. So we chose to keep things simple. We stored the data in an SQL Server database, created an Entity Framework class around this for data access and we put a Dynamic Data Site web application around this. Basically, something that can be set up real fast and without writing much code. It works quite well, too. Especially the filtering of records through boolean fields and table references is real cool.

However, during data entry a few users make minor mistakes. They've set up the filters to just filter a subset of a table and then click "New" to add a record to this subset. Unfortunately, the new record isn't defaulting to the values in those filters so users have to set the right values again. Too bad they occasionally miss this, thus some records end up with the wrong values.

So, when a user creates a new record, how do I ensure that this new record will copy the filter values as default? (And still allow the user to pick other values!)

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

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

发布评论

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

评论(3

影子是时光的心 2024-08-18 05:41:52

当他们创建新记录时是否会触发一个事件?如果您可以实现一个事件处理程序,并且当前的过滤器集可以通过编程方式访问,那么在 newRecord() 事件处理程序中,您应该能够遍历每个当前的过滤器,确定过滤器的字段用于以及过滤器的值是什么,将新记录的字段设置为过滤器值。

如果有帮助的话,这里有一些伪代码:

NewRecordHandler(object sender, NewRecordEventArgs e)
{
    Record newRecord = (Record)e.NewRecord;
    foreach(Filter filter in m_dataSource.Filters)
    {
        newRecord[filter.FieldName] = filter.Value;
    }
}

您需要能够使用索引或字符串动态访问记录属性,例如 Record["ColumnName"] = value;。否则,您可能无法循环执行此操作,如图所示。希望这有帮助。

Is there an event that fires when they create a new record? If you can have implement an event handler, and the current set of filters is something you can programmatically access, then in your newRecord() event handler, you ought to be able to go through each of your current filters, determine which field the filter is for, and what the value of the filter is, setting the new record's field to the filter value.

Here's some pseudo-code if it helps:

NewRecordHandler(object sender, NewRecordEventArgs e)
{
    Record newRecord = (Record)e.NewRecord;
    foreach(Filter filter in m_dataSource.Filters)
    {
        newRecord[filter.FieldName] = filter.Value;
    }
}

You'll need to be able to dynamically access the records properties, using either an index or a string, like Record["ColumnName"] = value;. Otherwise you may not be able to do it in a loop, as illustrated. Hope this helps.

香橙ぽ 2024-08-18 05:41:52

我将使用一个连接到“新建”按钮 onclick 的Object Factory。我将使用 Filter 值或视图接口来初始化 Factory,以便 Factory 可以返回正确初始化的对象。

I'd use an Object Factory hooked into the New button onclick. I'd initialize the Factory with either the Filter values or an interface to the View so that the Factory can return the properly initialized objects.

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