If e.DataCol.name = "销售数量"
Dim oldCount As Integer = e.DataTable.Compute("sum(销售数量)","货号='" & e.DataRow("货号") & "' and 日期 < #" & e.DataRow("日期") & "#")
Dim cnt As Integer = 0
Dim c1 As Integer = 0
Dim c2 As Integer = 0
Dim csum As Double = 0
Dim drs As List(of DataRow) = DataTables("采购").Select("货号='" & e.DataRow("货号") & "' and 日期 <= #" & e.DataRow("日期") & "#","日期")
Dim idx As Integer = -1
For i As Integer = 0 To drs.count - 1
cnt += drs(i)("数量")
If cnt > oldCount Then
idx = i
Exit For
End If
Next
If idx > -1
Dim dr As DataRow = drs(idx)
c1 = cnt - oldCount
csum = c1 * dr("单价")
For j As Integer = idx+1 To drs.count - 1
dr = drs(j)
c2 = dr("数量")
csum += c2 * dr("单价")
c1 += c2
Next
e.DataRow("平均价格") = csum / c1
End If
End If