向多个用户显示由另一个用户插入的数据更新 [英] displaying updation of data to multiple users which is inserted by another user

查看:24
本文介绍了向多个用户显示由另一个用户插入的数据更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在用户输入数据库时​​立即向用户显示更新的数据,即在线查看.

i need to show the updated data immediately to a user as he inputs into the database , i.e. online view.

我正在使用 sql server 并构建一个 c# .net winform 应用程序.该应用程序将由 3 个用户(U1、U2、U3)在 LAN 上使用.

i am using sql server and building a c# .net winform application. the application would be used on LAN by 3 users, U1,U2,U3.

用户将使用应用程序将数据输入到ITEMS表中,当U2单击插入按钮时,他应该在gridview底部的同一表单上查看更新的数据,否则,U1,U3也将自动在应用程序中查看他们 PC 上的更新表.

the users would input data into an ITEMS table using the application and as U2 clicks the insert button , he should view the updated data on the same Form at the bottom in a gridview or else , and also, U1,U3 would also automatically see the updated table on their PCs in the application.

我该怎么做?

U1、U2、U3 已打开应用程序.

U1,U2,U3 have opened the application.

U2 已导航到 INSERT 项目表单.

U2 has navigated to the INSERT items Form.

U1、U3 在视图项表单上.

U1,U3 are on the view items Form.

我希望当 U2 插入数据时,U1、U3 应用程序上的网格视图会自动更新,他们可以看到 U2 在 ITEMS 表中插入的新数据.他们甚至不需要刷新或重新打开视图项表单.

i want that as U2 inserts data, then automatically the grid view on the application of U1,U3 is updated and they could see the new data inserted by U2 in the ITEMS table. they don't even need to refresh or reopen the view items Form.

必须在ITEMS 表上使用触发器.有什么办法可以避免触发吗?

Trigger have to be used on the ITEMS table. is there any way to avoid triggers here?

推荐答案

你不需要触发器(至少不是为了描述的目的).

You do not need a trigger (at least not for the purpose described).

通常的做法是实现按需刷新功能(通常是 F5).

The common practice is to implement a refresh-on-demand capability (usually F5).

让 PC 或屏幕始终与数据库保持同步有点荒谬.考虑网络流量.考虑到当 U1 或 U2 接听电话、去吃午饭或休息时,没有人在那里阅读屏幕.按需刷新能力更合理.

It is a bit absurd to keep the PCs or screens up-to-date with the database all the time. Consider the network traffic. Consider that no -one is there to read the screen when U1 or U2 answer the phone, go for lunch or a comfort break. A Refresh on demand capability is more reasonable.

另外,如果非要实现这样的功能,在表中添加Last-Updated-TimeStamp或DateTime列,只检索自上次检索以来更新过的行.

Further, if you have to implement such a function, add a Last-Updated-TimeStamp or DateTime column to the table, and only retrieve the rows that have been updated since the last retrieval.

谢谢.

  1. 在每个表上,包括一个 TimestampDatetime 列,名称类似于 UpdatedDateTime.设置默认值 GETDATE().

  1. On each table, include a Timestamp or Datetime column, named something like UpdatedDateTime. Set a default of GETDATE().

每当更新行时更新此列.请注意,您只能有意义地让一个数据窗口聚焦,即.在前面,所有其他窗口都失焦,无法看到.所以没有必要将刷新或自动刷新编码到每个窗口中;只有那些真正需要自动刷新的窗口.

Update this column whenever you update the row. Note that you can only meaningfully have one data window in focus, ie. in front, all other windows are out of focus, cannot be seen. So there is no point in coding the refresh or automatic refresh into every window; only those windows that actually need automatic refresh.

在客户端或 .NET 端,对于每个需要刷新的窗口,为 Function-5 按钮编写代码.每当 F5 被激活时,刷新窗口.这意味着:

On the client or .NET side, for each window that needs refresh, write code for the Function-5 button. Whenever F5 is activated, refresh the window. That means:

  • 为该窗口填充您的列表对象(包含逻辑数据行):
  • fill your List Object (containing the logical data rows) for that window:
SELECT column_list
    FROM table t1
    JOIN join_table t2 ...
    WHERE t1.UpdatedDateTime > @SavedDateTime
    OR    t2.UpdatedDateTime > @SavedDateTime
    ... other_conditions

  • SET @SavedDateTime = GETDATE()
  • 粉刷窗户这将避免在整个网络中移动大量不变的数据;并仅将那些已更改的行移动到窗口中.智能刷新.
  • 测试一下.确保手动刷新按预期工作.在另一台 PC 上更新数据,在这台 PC 上按 F5,并验证窗口中的数据是否发生变化以反映更新;并且当数据没有改变时,窗口现在会重新绘制.

    Test that. Ensure that the manual refresh works as intended. Update the data on another PC, press F5 on this PC, and verify that the data in the window changes to reflect the updates; and that the window is now repainted when data does not change.

    现在进行自动刷新.编写一个无限循环(总是坏的新),等待 30 秒,然后执行 F5 按钮代码.现在检查 是否按预期工作.

    Now for the automatic refresh. Write an endless loop (always bad new), that waits 30 seconds, and executes the F5 button code. Now check that that works as intended.

    如果非常资深的人想要更频繁地刷新窗口(超过 30 秒),请将等待参数更改为 15 秒.如果非常高级的人希望他们的窗口更频繁地刷新(超过 15 秒),请将该等待参数更改为 10 秒.等等.切勿将等待时间设置为 1 秒或 2 秒或 5 秒开始.并允许每台 PC 设置自己的等待时间(大老板 5 秒,小老板 30 秒).

    If and when someone very senior wants their window refreshed more frequently (than 30 seconds), change that wait parameter to 15 seconds. If and when someone very senior wants their window refreshed more frequently (than 15 seconds), change that wait parameter to 10 seconds. Et cetera. Never set the wait to 1 or 2 or 5 seconds to begin with. And allow each PC to set its own wait period (big boss 5 seconds, little boss 30 seconds).

    当老板抱怨网络慢时,向他们展示当没有人坐在电脑前阅读窗口时正在淹没网络的数据包,并建议他们关闭自动刷新.手动刷新仍然可供实际坐在窗前且手指未断的任何人使用.

    When the bosses wail about the network being slow, show them the packets that are flooding the network when no one is sitting in front of the PC to read the window, and suggest that they turn the Automatic Refresh off. The manual refresh remains available for anyone who is actually sitting in front of the window, whose fingers are not broken, to use.

    这篇关于向多个用户显示由另一个用户插入的数据更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆