如何限制Windows Froms中多个用户的更新 [英] How to restrict updation from multiple users in windows froms

查看:99
本文介绍了如何限制Windows Froms中多个用户的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家晚上好.

我正在用Windows窗体进行酒店管理项目.
那是当客户离开房间时.我必须采取最大checkoutid并增加到一个并更新.
此逻辑保留在结帐按钮中.

我的项目有多个用户.
所以有一个问题
即两个或两个以上的用户选中了结帐按钮,同时所有用户都拥有相同的最大编号并增加1并更新.
所以多个房间的结帐号码相同.
我不知道如何避免这种情况.
checkoutno列是唯一的.

Good Evening All.,

I am doing hotel management project in windows forms.
In that when customer vacate the room. i have to take maximum checkoutid and increased to one and update.
This logic is kept in checkout button.

my project have multiple users.
so one problem is there
i.e. two or more user checked checkout button same time all user having same maximum no. and increased by 1 and updated.
so multiple rooms having same checkoutno.
i don''t known how to avoid this.
checkoutno column is unique.

推荐答案

该问题称为并发性,对于任何系统架构师来说都是一个巨大的问题.基本上,您可以选择两门课程.悲观并发和乐观并发.

1.悲观并发是您主动锁定要更新的任何对象的位置.以您的情况为例,假设有一个用户打开了签出表单,您将在数据库的checkoutid列上设置了一个锁,直到第一个用户通过并释放锁之后,其他用户才能访问该签出.这样做的好处是易于实现,并且您还知道不会意外覆盖任何数据.这样做的缺点是,如果您有多个用户,则该系统无法很好地扩展;如果您的用户打开表单,然后去吃午餐,则该表可能会被锁定,直到他们回来为止.

2.考虑到并发性,您将考虑让2个或更多用户同时更新记录,并建立一个系统,以检查自上次检索数据以来是否已更改数据,如果交易属实,您将中止交易.在您的情况下,您可以在表中放置一个timestamp列以进行更新,并且每当checkoutid更新时,该列将被更新为当前时间.当用户访问签出表单时,您将检索时间戳并将其保存在内存中.然后,您将在每次要更新checkoutid时检查当前时间戳,如果它与您的内存时间戳不匹配,则中止事务,或使用当前数据等创建新的checkoutid.

希望这会有所帮助
The issue is called concurrency, and is a huge issue for any system architect. Basically there are two courses that you can take. Pessimistic Concurrency and Optimistic Concurrency.

1. Pessimistic concurrency is where you actively put a lock on any object that is being updated. In your case, say one user opened the check out form, you would put a lock on the checkoutid column in your database, and no other user could access the check out till the first user was through and released the lock. The advantage of this is that it is easy to implement and you also know that no data can be overwritten unintentionally. The disadvantage of this is that if you have more than a few users, this system does not scale well, and if your user opens up the form, then goes to lunch, that table could be locked till they get back.

2. Optimistic concurrency is where you take into account that you will get 2 or more users updating the record at the same time, and you put into place a system whereby you check to see if the data has been changed since it was last retrieved, and you abort the transaction if it is true. In your case, you could maybe put a timestamp column in the table to be updated, and this column will be updated to the current time whenever the checkoutid is updated. When your user accesses the check out form, you retrieve the timestamp and keep it in memory. Then you would check the current timestamp each time you want to update checkoutid, and if it does not match your in memory timestamp then abort the transaction, or create a new checkoutid with the current data etc.

Hope this helps


希望 [ ^ ]可能会为您提供帮助.
Hope this[^] might help you.


这篇关于如何限制Windows Froms中多个用户的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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