如何扣除数据库中的项目数量?

时间:2014-01-15 23:25:43

标签: vb.net ms-access

我正在创建一个系统,如果项目被借用/退回,我必须扣除并添加一个系统。在我的系统中,我有两个表:

tblItems(_itemnumber_, _itemname_, _quantity_) 
tblBorrow(_dateborrowed_, _datedue_, _status_)

如果我借用了一个项目,状态将借用数量将扣除1,如果状态返回数量将增加1.这是我的想法(我已经如何添加和更新),但我不知道如何编码这个想法。我非常感谢你的帮助。

我正在使用import system.data.oledb

1 个答案:

答案 0 :(得分:0)

首先,可以删除下划线以提高可读性。

接下来,tblBorrow需要 itemnumber ,否则所有Borrowings看起来都一样。

tblBorrow(_itemnumber_,_dateborrowed_, _datedue_, _status_)

然后Borrow_Clicked按钮将具有

效果的代码
If tblItems for this _itemnumber_ has _quantity_ <= 0 then
    msg"There is no Quantity to Borrow"
    exit
else
    Update tblItems Set _quantity_ = _quantity_ - 1 Where _itemnumber_ = x
    Insert tblBorrow  Item#, Date, Due, "Borrowed"
End If

还会有一个Returned_Click按钮,其中包含

效果的代码
If tblBorrow  for this Item# exists with a "Borrowed" status then
    Update tblItems Set _quantity_ = _quantity_ + 1 Where _itemnumber_ = x
    Update tblBorrow  Set Status = "Returned"
else
    msg"Item status is not Borrowed"
End If

其中每一个都应编辑Item#以确保它有效。