下面是按楼主的意思写的代码,不知道行不?我在命令窗口中测试过ok。(注意焦点要在出库表上 如:最后一行)
Dim drs As List(Of DataRow)
drs = DataTables("库存").Select("[药品名称] = '" & currenttable.current("药品名称") & "'","批号")
dim sl as string
dim n as integer
For Each dr As Datarow In drs
sl = sl & dr("库存量") & "|"
dim k as integer = sl.split("|")(n)
dim s as integer
if k <= currenttable.current("数量") and currenttable.current("数量") -k>0 then
s = dr("库存量")
dr("库存量") = 0
n=n+1
elseif k> currenttable.current("数量") and currenttable.current("数量") -s>0 then
dr("库存量") = k - (currenttable.current("数量") - s)
exit for
end if
next
其实‘库存’表有必要按批号来反映库存量吗? 如果因价格问题进行成本核算,应该选择‘入库’表中先入库的价格即可。
[此贴子已经被作者于2009-7-4 12:07:46编辑过]