If e.DataCol.name = "出库数量" Then
If e.DataRow("出入库单号") <> "删除记录" Then
If e.DataRow.isnull("批号") = False Then
Dim dr221 As DataRow = DataTables("批号表").Find("物料编号 = '" & e.DataRow("物料编号") & "' and 批号 = '" & e.DataRow("批号") & "' and 仓库名称 = '" & e.DataRow("仓库名称") & "' and 库位代号 = '" & e.DataRow("库位代号") & "' ")
msgbox(dr221 IsNot Nothing)
If dr221 IsNot Nothing Then
msgbox("e.newvalue=" & e.newvalue )
msgbox("库存数量=" & dr221("库存数量") )
If e.newvalue * (-1) > dr221("库存数量") Then
msgbox(1)
Dim q1 As Single = e.newvalue * (-1) - dr221("库存数量")
msgbox("q1 =" & q1 )
e.DataRow("出库数量") = dr221("库存数量") * (-1)
msgbox("出库数量 =" & e.DataRow("出库数量"))
dr221("库存数量") = dr221("库存数量") + e.DataRow("入库数量") + e.DataRow("出库数量") - e.OldValue
dr221("批号变动记录") = "出入库变动:" & Date.now & " " & User.Name
dr221("库存数量变动记录") = "出入库变动:" & Date.now & " " & User.Name
Dim dra As Row = Tables("出入库").AddNew()
msgbox(2)
dra("出入库单号") = e.DataRow("出入库单号")
dra("指采销单号") = e.DataRow("指采销单号")
dra("指采销行号") = e.DataRow("指采销行号")
dra("物料编号") = e.DataRow("物料编号")
dra("要求交货日期") = e.DataRow("要求交货日期")
dra("出库数量") = q1 * (-1)
Else
dr221("库存数量") = dr221("库存数量") + e.DataRow("入库数量") + e.DataRow("出库数量") - e.OldValue
dr221("批号变动记录") = "出入库变动:" & Date.now & " " & User.Name
dr221("库存数量变动记录") = "出入库变动:" & Date.now & " " & User.Name
End If
End If
End If
End If
End If
我知道6楼问题的原因了,所以对代码修改为上面那样子了。当输入物料编号时,另有代码会从“批号表”自动寻找 "批号" 和 "库位代号" 并填入“出入库”(代码见下面两段)。现在出现新的问题:批号表的库存有两个批号,其中旧批号是 5 个的。我在“出入库2” 之 "出库数量" 输入 -10,所有 msgbox 都会提示,当前行数据也会变成 -5,也新增加了数据行。批号表的旧批号的数量5也会被扣减掉。问题是,新增加的数据行还是自动出现批号表里 旧批号那行 的 "批号" 和 "库位代号" 。那么,要怎么样修改上面的代码呢?谢谢。
If e.DataCol.Name = "物料编号" Then
If e.DataRow("出入") = "出库" Then
Dim dr1 As DataRow = DataTables("批号表").Find("物料编号 = " & "'" & e.DataRow("物料编号") & "' And 库存数量 > " & 0,"批号")
If dr1 IsNot Nothing Then
e.DataRow("批号") = dr1("批号")
End If
End If
End If
If e.DataCol.Name = "物料编号" Then
If e.DataRow("出入") = "出库" Then
' Dim dr2 As DataRow = DataTables("批号表").Find("物料编号 = " & "'" & e.DataRow("物料编号") & "' and 批号 = '" & e.DataRow("批号") & "' And 库存数量 > " & 0,"库位代号")
Dim dr2 As DataRow = DataTables("批号表").Find("物料编号 = " & "'" & e.DataRow("物料编号") & "' And 库存数量 > " & 0,"批号,库位代号")
If dr2 IsNot Nothing Then
e.DataRow("库位代号") = dr2("库位代号")
End If
End If
End If