参考
Dim dic_kc As new Dictionary(Of String ,String) '可用库存
Dim dic_aqkc As new Dictionary(Of String ,String) '安全库存
Dim dic_bhxq As new Dictionary(Of String ,String) '补货需求
Dim t As Table = Tables("调拨操作表")
For Each c2 As Col In t.Cols
If c2.Caption.Contains("可用库存_") And c2.Caption.Contains("店仓名称") = False Then
Dim v = c2.Caption.Replace("可用库存_","")
dic_kc.add(v, c2.name)
End If
If c2.Caption.Contains("安全库存_") And c2.Caption.Contains("店仓名称") = False Then
Dim v = c2.Caption.Replace("安全库存_","")
dic_aqkc.add(v, c2.name)
End If
If c2.caption.Contains("补货需求_") Then
Dim v = c2.caption.Replace("补货需求_","")
dic_bhxq.add(v, c2.name)
End If
Next
For Each r2 As Row In t.Rows
For Each key As String In dic_aqkc.Keys
If r2(dic_aqkc(key)) > 0 Then '
r2(dic_bhxq(key)) = r2(dic_aqkc(key)) - r2(dic_kc(key)) '算出的补货需求
End If
Next
Next
Dim r1 As Row = t.Rows(0)
For Each zh As String In t.DataTable.GetValues("组合", "组合 is not null")
Dim drs As List(Of DataRow) = t.DataTable.Select("组合 = '" & zh & "'", "排名")
For i As Integer = 1 To drs.count-1
For Each key As String In dic_bhxq.Keys
If dic_kc.ContainsKey(key) = False Then Continue For
Dim kcname As String = dic_kc(key)
Dim bhname As String = dic_bhxq(key)
If val(drs(i)(bhname)) > 0 Then
Dim count = val(drs(i)(bhname))
If val(r1(kcname)) > 0 Then
If val(r1(kcname)) >= val(drs(i)(bhname)) Then
Dim ndr As DataRow = DataTables("调拨单据").AddNew
ndr("创建时间") = Date.now
ndr("调出门店") = r1("店仓ID")
ndr("商品款号") = r1("商品款号")
ndr("颜色") = drs(i)("颜色")
ndr("调入门店") = drs(i)("店仓id")
ndr("调拨数量_" & key) = count
'r1(kcname) -= count
count = 0
Else
Dim ndr As DataRow = DataTables("调拨单据").AddNew
ndr("创建时间") = Date.now
ndr("调出门店") = r1("店仓ID")
ndr("商品款号") = r1("商品款号")
ndr("颜色") = drs(i)("颜色")
ndr("调入门店") = drs(i)("店仓id")
ndr("调拨数量_" & key) = r1(kcname)
'r1(kcname) = 0
count -= r1(kcname)
End If
Return i '调试代码
End If
If count > 0 Then
For j As Integer = drs.count-1 To i Step -1
Dim r As DataRow = drs(j)
If r(kcname) > 0 Then
If r(kcname) >= count Then
Dim ndr As DataRow = DataTables("调拨单据").AddNew
ndr("创建时间") = Date.now
ndr("调出门店") = r("店仓ID")
ndr("商品款号") = r("商品款号")
ndr("颜色") = drs(i)("颜色")
ndr("调入门店") = drs(i)("店仓id")
ndr("调拨数量_" & key) = count
'r(kcname) -= count
count = 0
Else
Dim ndr As DataRow = DataTables("调拨单据").AddNew
ndr("创建时间") = Date.now
ndr("调出门店") = r("店仓ID")
ndr("商品款号") = r("商品款号")
ndr("颜色") = drs(i)("颜色")
ndr("调入门店") = drs(i)("店仓id")
ndr("调拨数量_" & key) = r(kcname)
count -= r(kcname)
'r(kcname) = 0
End If
End If
If count = 0 Then Exit For
Next
End If
End If
Next
Next
Next