Dim dtre As DataTable = DataTables("表A")
Dim dr As DataRow
For Each dr1 As DataRow In dtre.DataRows
Dim con As Integer = DataTables("表A").Compute("sum(数量)","产品名称='" & dr1("产品名称") & "' and _sortkey < " & dr1("_sortkey"))
Dim s As String = ""
Dim drs As List(Of DataRow) = DataTables("表B").Select("产品名称= '" & dr1("产品名称") & "'","出货日期")
Dim sl As Integer = dr1("数量")
Do While drs.Count > 0
dr = drs(0)
If con >= dr("数量") Then
con = con - dr("数量")
Else
Dim c1 As Integer = dr("数量") - con
con = 0
If s > "" Then s = s & " + "
If c1 >= sl Then
s = s & dr("出货日期") & " /" & sl & "pc" & IIF(s.Contains("+"),"s","")
Exit Do
Else
s = s & dr("出货日期") & " /" & c1 & "pcs"
sl = sl - c1
End If
End If
drs.RemoveAt(0)
Loop
dr1("出货日期备注") = s
Next