蓝老师,列stock 和Qc的值已经取出来了,如下程序。现在是要取列 demandafterstock 的值,这个值取自列 MissingQty * BOM用量。谢谢。
内函数
Dim pn As String = args(0)
Dim qty As String = args(1)
Dim idx As Integer = args(5)
Dim dic1 = vars("dic1")
Dim dic2 = vars("dic2")
For Each dr As DataRow In DataTables("BOM").Select("FNumber='" & pn & "'")
Dim ndr As DataRow = DataTables("物料需求").AddNew
ndr("PartNo") = dr("PN")
ndr("Date") = args(3)
ndr("批号") = args(4)
ndr("OrderDemand") = dr("FQty") * qty
ndr("层次") = "第" & idx & "层"
Dim flag = args(5)
If args.length < 6 OrElse args(5) = True Then
Dim aa As Integer
If args.length = 7 Then
aa = args(6) * dr("FQty")
End If
If dic1.ContainsKey(ndr("PartNo")) Then
If dic1(ndr("PartNo")) >= ndr("OrderDemand")-aa Then
ndr("Stock") = ndr("OrderDemand")-aa
dic1(ndr("PartNo")) -= ndr("Stock")
flag = False
ElseIf dic1(ndr("PartNo")) > 0 Then
ndr("Stock") = dic1(ndr("PartNo"))
dic1(ndr("PartNo")) -= ndr("Stock")
End If
If flag = True Then
If dic2.ContainsKey(ndr("PartNo")) Then
Dim qty1 = ndr("OrderDemand") - ndr("stock")
If qty1 > 0 Then
If dic2(ndr("PartNo")) >= qty1 Then
ndr("QC") = qty1
dic2(ndr("PartNo")) -= ndr("QC")
ElseIf dic2(ndr("PartNo")) > 0 Then
ndr("QC") = dic2(ndr("PartNo"))
dic2(ndr("PartNo")) -= ndr("QC")
End If
End If
End If
End If
End If
End If
Functions.Execute("sumChild",dr("PN"),ndr("OrderDemand"), args(2), args(3), args(4),idx+1)
Next
按钮:
DataTables("物料需求").datarows.clear
Dim dic1 As new Dictionary(of String, Double)
For Each dr As DataRow In DataTables("库存表").Select("part is not null")
dic1.add(dr("part"), dr("qty"))
Next
vars("dic1") = dic1
Dim dic2 As new Dictionary(of String, Double)
For Each dr As DataRow In DataTables("待检产品").Select("part is not null")
dic2.add(dr("part"), dr("qty"))
Next
vars("dic2") = dic2
For Each Ary As String() In DataTables("OrderList").GetValues("PartNo|ETD|批号","PartNo is not null")
Dim dr As DataRow = DataTables("物料需求").AddNew
dr("PartNo") = ary(0)
If ary(1) > ""
dr("Date") = cdate(ary(1))
End If
dr("批号") = ary(2)
Dim qty As Integer = DataTables("OrderList").Compute("sum(Qty)","PartNo='" & ary(0) & "' And " & IIf(ary(1) > "","ETD='" & ary(1) & "'","ETD is null") & " and 批号 ='" & ary(2) & "'")
dr("OrderDemand") = qty
Dim drr As DataRow = DataTables("BOM").find("Fnumber =" &"'"& dr("PartNo")&"'")
If drr IsNot Nothing
dr("层次") = "父层"
Else
dr("层次") = "单件出货"
End If
Dim flag As Boolean = True
If dic1.ContainsKey(dr("PartNo")) Then
If dic1(dr("PartNo")) >= qty Then
dr("Stock") = qty
dic1(dr("PartNo")) -= dr("Stock")
flag = False
ElseIf dic1(dr("PartNo")) > 0 Then
dr("Stock") = dic1(dr("PartNo"))
dic1(dr("PartNo")) -= dr("Stock")
End If
End If
If dic2.ContainsKey(dr("PartNo")) Then
If dic2(dr("PartNo")) >= qty Then
dr("QC") = qty
dic2(dr("PartNo")) -= dr("QC")
ElseIf dic2(dr("PartNo")) > 0 Then
dr("QC") = dic2(dr("PartNo"))
dic2(dr("PartNo")) -= dr("QC")
End If
End If
dr("MissingQty") = dr("Stock")+dr("QC") -dr("OrderDemand")
Functions.Execute("sumChild",ary(0),qty, ary(0), dr("Date"),ary(2),1)
Next