如下代码
If e.DataCol.Name = "本次数量" Then
If e.DataRow.IsNull("中标工程名称") = False AndAlso e.DataRow.IsNull("产品编号") = False _
AndAlso e.DataRow.IsNull("本次数量") = False AndAlso e.DataRow.IsNull("第几次采购") = False Then
Dim sum As Double = e.DataTable.Compute("Sum(本次数量)","中标工程名称 = '" & e.DataRow("中标工程名称") & "' And SubString([产品编号],1,6) = '" & _
e.DataRow("产品编号").Substring(0,6) & "' And 第几次采购 <= '" & e.DataRow("第几次采购") & "'")
e.DataRow("剩余数量") = e.DataRow("成本预算数量") - sum
End If
End If
If e.DataCol.Name = "产品编号" AndAlso e.NewValue <> Nothing Then
Dim fdr As DataRow = DataTables("材料费预算表").Find("中标工程名称 = '" & e.DataRow("中标工程名称") & "' and SubString([产品编号],1,6) = '" & e.NewValue & "'")
If fdr IsNot Nothing Then
e.DataRow("成本预算数量") = fdr("数量")
e.DataRow("成本预算单价") = fdr("单价")
Else
fdr = DataTables("产品价格库").Find("SubString([产品编号],1,6) = '" & e.NewValue.Substring(0,6) & "'")
e.DataRow("成本预算数量") = 0
If fdr IsNot Nothing Then
e.DataRow("成本预算单价") = fdr("单价")
End If
End If
End If