Select Case e.DataCol.Name
Case "客户名称", "提货地点", "提油数量", "品种", "实际提油数量"
If e.DataRow.IsNull("客户名称") OrElse e.DataRow.IsNull("提货地点") OrElse e.DataRow.IsNull("实际提油数量") Then
e.DataRow("单价") = Nothing
Else
Dim psum As Double = e.DataTable.Compute("sum(实际提油数量)", "_Identify < " & e.DataRow("_Identify") & " and 客户名称 = '" & e.DataRow("客户名称") & "' and 提货地点 = '" & e.DataRow("提货地点") & "' and 品种 = '" & e.DataRow("品种") & "'")
Dim drs As List(Of DataRow) = DataTables("订单").Select("客户名称 = '" & e.DataRow("客户名称") & "' and 提货地点 = '" & e.DataRow("提货地点") & "' and 品种 = '" & e.DataRow("品种") & "'", "订单日期")
Dim sum As Double = 0
Dim zj As Double = 0
Dim sl As Double = 0
For i As Integer = 0 To drs.count - 1
Dim dr = drs(i)
sum += dr("数量")
If sum >= psum Then
If sum - psum >= e.DataRow("实际提油数量") Then
e.DataRow("单价") = ((e.DataRow("实际提油数量")-sl) * dr("单价") + zj) / e.DataRow("实际提油数量")
Exit For
Else
Dim temp As Double = iif(sum-psum-sl<dr("数量"), sum-psum-sl, dr("数量"))
sl += temp
zj += temp * dr("单价")
End If
End If
Next
End If
End Select
我按照你的方法 在提油明细表中增加了一个【金额】列 你这段代码 也没有关于这个金额列的字段,也没关系啊