1、导入的时候查询是否有此物料的数据在决定是否新增,如:
Dim Cols1() As String = {"进货日期","物料号","品名","型号","数量","单价"} '来源表-入库单要引入的字段
Dim Cols2() As String = {"日期","物料号","品名","型号","入库数量","入库价"} '接收表-库存表要接收的字段
For Each dr1 As DataRow In DataTables("进货单").Select("[审核] = 1") '
Dim dr2 As DataRow = DataTables("流水帐").Find("物料号='" & dr1("物料号") & "' and 日期=#" & dr1("进货日期") & "#")
If dr2 Is Nothing Then
dr2 = DataTables("流水帐").AddNew()
End If
For i As Integer = 0 To Cols1.Length -1
dr2(Cols2(i)) = dr1(Cols1(i))
Next
Next
2、计算期末库存就是计算日期最大的数据,如:
For Each n As String In DataTables("流水帐").GetValues("物料号")
Dim dr As DataRow = DataTables("流水帐").Find("物料号='" & n & "'","日期 desc")
Output.Show("物料号" & n & "期末库存为:" & dr("库存数"))
Next
每月最后一天凌晨的时候计算期末库存,即是下月的期初库存。