学习老朱例子做库存管理,但出现情况。在没保存的情况下,或修改后撤消修改时,DataColChanging事件不会动作,结果出库数量不准确。请问怎么处理?请大家指教。谢谢。
例子连接http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=29462&replyID=&skin=1
DataColChanging事件
If e.DataCol.Name = "出库数量" Then
Dim dr As DataRow = e.DataRow
Dim pf As String
pf = e.DataRow("产品名称")
Dim cmd1 As New SQLCommand
Dim cmd2 As New SQLCommand
Dim Key As Integer
cmd1.C
cmd2.C
If pf > "" Then
cmd1.commandText = "Select [库存数量] From [库存表] Where [产品名称] = '" & pf & "'"
Key = cmd1.ExecuteScalar() '从后台获得顺序号
e.DataRow("目前库存数")=key
If key <= e.NewValue Then
MessageBox.Show("库存数不够,不能发货!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
e.Cancel =True
Else
cmd2.commandText = "Update [库存表] Set [库存数量] = " & (Key - e.NewValue) & " Where [产品名称] = '" & pf & "'"
If cmd2.ExecuteNonQuery() > 0 Then '更新顺序号
MessageBox.Show("库存更新成功!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
End If
Return
End If
End If
End If