我有一个我无法自己解决的问题。在我开始之前,让你们知道这一点很重要
这个问题是我从头到尾写的,想让大家明白我的问题是什么,懒得看的请见谅,这里不附代码,只附逻辑
可能这个论坛的人可以帮助我。但是,我已经找到了解决问题的方法(但只有逻辑,我无法通过代码证明,也不知道从哪里开始)
好吧,这是我的情况:
I got a Quantity column in DataGridView, and i got a feature where user could edit the Quantity column in DataGridView and automatically updating the Quantity value in the Database.
例如(仍然如此):
I have 1000 on Quantity in the Database, and i enter the value of 50 in the Quantity column in system and after that i add to the DataGridView by clicking a "OK" button, once clicked, the Quantity in the Database should update it Quantity become 950, from 1000. Because i use a formula
valueOfQuantityInDatabase - valueOfQuantityInSystem ,it update properly and successful
这是我的问题:
Let's say i got a DataGridView with Quantity column and the value of it is 50
(这使得数据库中的数量值变为 950) and let's say customer want to add his Quantity from 50 to 150, so i change the value of Quantity in DataGridView to 150 from 50, and when i click "OK" button, the Database should update based on the formula
valueOfQuantityInDatabase - valueOfQuantityInSystem,and the Quantity in Database should have 850 in Quantity value
(因为 1000 - 150),but it is not as i expected, the Quantity value in database is 800
(因为我第一次添加是 50,所以数据库中的数量是 950,接下来我添加另一个 150,数据库中的数量是800) ,so it is like first entered value + second entered value.
这是我想要的:
Whenever user edit the Quantity in DataGridView, it should goes to this formula
valueOfQuantityInDatabase - valueOfQuantityInSystem ------ (因此,每当用户更改 DataGridView 中的 Quantity 值时,假设它从 50 更改为 150,数据库中的 Quantity 应该识别它并减去 DataGridView 中 Quantity 的当前值(150),不是年长的 (50)
这是我附带的解决方案:
获取数据库中 Quantity 更改前的第一个值 (1000)
获取用户通过公式添加的数量值,
Quantity in DataGridView after changes - Quantity in DataGridView before changes
并将其与公式相加Quantity in DataGridView after changes - Quantity in DataGridView before changes
但我不知道如何获得解决方案 1 或 2。有人可以帮我吗?非常感谢!你的回答我非常感谢!