DataTables("参数计算").ReplaceFor("值",Nothing,"来源表 is not null Or 公式 is not null")
DataTables("参数计算").ReplaceFor("字符值","","来源表 is not null Or 公式 is not null")
Dim dr As Row = Tables("输入参数").Current
DataTables("货物密度").ReplaceFor("选择",0,"选择 = 1")
Dim drmd As DataRow '货物密度
If dr("货物名称") = "蛋类" AndAlso dr("冷库温度") < -2 Then
drmd = DataTables("货物密度").Find("名称 = '冰蛋'")
Else
drmd = DataTables("货物密度").Find("名称 = '" & dr("货物名称") & "'")
End If
If drmd IsNot Nothing Then
drmd("选择") = 1
End If
'新建临时表
Dim dtb As New DataTableBuilder("参数计算ls")
For Each drjs As DataRow In DataTables("参数计算").DataRows '临时表添加列,列名为参数计算表各行代码
If drjs("值类型") = 0 Then
dtb.AddDef("" & drjs("代码") & "", Gettype(Double))
Else
dtb.AddDef("" & drjs("代码") & "", Gettype(String))
End If
Next
dtb.Build()
Dim drjsn As Row = Tables("参数计算ls").AddNew
Dim maxi As Integer = DataTables("参数计算").Compute("Max(计算顺序)")'最大计算顺序号
For i As Integer = 1 To maxi
Dim drjss As List(of DataRow)
'动态设置来源列
drjss = DataTables("参数计算").Select("动态设置来源列 is not null and 计算顺序 = " & i)
If drjss.Count > 0 Then
For Each drjs As DataRow In drjss
drjs("来源列") = drjsn("" & drjs("动态设置来源列") & "")'将计算值填入参数计算表
Next
End If
'根据来源列设置值
drjss = DataTables("参数计算").Select("计算顺序 = " & i)
For Each drjs As DataRow In drjss
If drjs.IsNull("来源表") = False And drjs.IsNull("来源列") = False And drjs.IsNull("动态设置行值") Then '值列查找设置代码
Dim drdm As DataRow = DataTables("" & drjs("来源表") & "").Find("选择 = 1")
If drdm IsNot Nothing Then
If drjs("值类型") = 0 Then
drjs("值") = drdm("" & drjs("来源列") & "")
Else
drjs("字符值") = drdm("" & drjs("来源列") & "")
End If
End If
End If
If drjs.IsNull("来源表") = False And drjs.IsNull("来源列") = False And drjs.IsNull("动态设置行值") = False Then '值列查找设置代码
Dim drdm As DataRow = DataTables("" & drjs("来源表") & "").Find("" & drjs("设置选择行") & " = '" & drjsn("" & drjs("动态设置行值") & "") & "'")'根据动态行值设置
If drdm IsNot Nothing Then
If drjs("值类型") = 0 Then
drjs("值") = drdm("" & drjs("来源列") & "")
Else
drjs("字符值") = drdm("" & drjs("来源列") & "")
End If
End If
End If
'将参数计算表各代码值填入临时表新增行的对应列
If drjs("值类型") = 0 Then
drjsn("" & drjs("代码") & "") = drjs("值")
Else
drjsn("" & drjs("代码") & "") = drjs("字符值")'
End If
drjs.Save
Next
'根据公式设置值
drjss = DataTables("参数计算").Select("计算顺序 = " & i & " And 公式 Is not null")
If drjss.Count > 0 Then
For Each drjs As DataRow In drjss
drjsn("" & drjs("代码") & "") = Eval(drjs("公式"),drjsn)'根据公式计算
If drjs("值类型") = 0 Then
drjs("值") = drjsn("" & drjs("代码") & "")'将计算值填入参数计算表
Else
drjs("字符值") = drjsn("" & drjs("代码") & "")'
End If
drjs.Save
Next
End If
Next