Dim t1 As Table = Tables("仓库总表")
Dim dt1,dt2 As DataTable
Dim dr,dr1,dr2 As DataRow
Dim drs As List(of DataRow)
Dim flt,s1 As String
Dim Date1,Date2 As Date
Date1 = Tables("月末结账").Current("结账期_起")
Date2 = Tables("月末结账").Current("结账期_讫")
dt1 = DataTables("采购入库单明细表")
dt2 = DataTables("生产入库单明细表")
Dim dts As DataTable() ={dt1,dt2}
s1 = "[日期] >= #" & Date1 & "# And [日期]<= #" & Date2 & "#"
flt ="[期间] = '" & Date1.Month & "'"
t1.StopRedraw
For Each dt As DataTable In dts
drs = dt.Select(s1)
For Each dr In drs
dr1=t1.DataTable.Find(flt & " and [品号] = '" & dr("品号") & " 'and [仓库] = '" & dr("仓库") & "'")
If dr1 Is Nothing Then
dr2 = t1.DataTable.AddNew
dr2("期间") = Date1.Month
dr2("仓库") = dr("仓库")
dr2("品号") = dr("品号")
End If
Next
Next
t1.Filter = flt
For Each r2 As Row In t1.Rows
flt = s1 & " and [品号] = '" & r2("品号") & " 'and [仓库] = '" & r2("仓库") & "'"
r2("入库数量") = dt1.Compute("Sum(数量)",flt) + dt2.Compute("Sum(数量)",flt)
r2("入库金额") = dt1.Compute("Sum(金额)",flt) + dt2.Compute("Sum(金额)",flt)
Next
t1.ResumeRedraw
t1.DataTable.save