Select Case e.DataCol.Name
Case "品名", "入库数量", "借库数量", "还库数量", "出库数量"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(Of DataRow)
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [品名] = '" & mr("品名") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
mr("库存结余") = mr("入库数量") + mr("还库数量") - mr("借库数量") - mr("出库数量")
mr("入库累计") = mr("入库数量")
mr("还库累计") = mr("还库数量")
mr("借库累计") = mr("借库数量")
mr("出库累计") = mr("出库数量")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [品名] = '" & dr("品名") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("库存结余") = drs(i - 1)("结余累计") + drs(i)("入库数量") + drs(i)("还库数量") - drs(i)("借库数量") - drs(i)("出库数量")
drs(i)("入库累计") = e.DataTable.Compute("sum(入库数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [品名] = '" & dr("品名") & "'")
drs(i)("还库累计") = e.DataTable.Compute("sum(还库数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [品名] = '" & dr("品名") & "'")
drs(i)("借库累计") = e.DataTable.Compute("sum(借库数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [品名] = '" & dr("品名") & "'")
drs(i)("出库累计") = e.DataTable.Compute("sum(出库数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [品名] = '" & dr("品名") & "'")
Next
If e.DataCol.Name = "品名" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [品名] = '" & e.OldValue & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[品名] = '" & e.OldValue & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("库存结余") = dr("入库数量") + dr("还库数量") - dr("借库数量") - dr("出库数量")
dr("入库累计") = dr("入库数量")
dr("还库累计") = dr("还库数量")
dr("借库累计") = dr("借库数量")
dr("出库累计") = dr("出库数量")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [品名] = '" & dr("品名") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("库存结余") = drs(i - 1)("库存结余") + drs(i)("入库数量") + drs(i)("还库数量") - drs(i)("借库数量") - drs(i)("出库数量")
drs(i)("入库累计") = e.DataTable.Compute("sum(入库数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [品名] = '" & dr("品名") & "'")
drs(i)("还库累计") = e.DataTable.Compute("sum(还库数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [品名] = '" & dr("品名") & "'")
drs(i)("借库累计") = e.DataTable.Compute("sum(借库数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [品名] = '" & dr("品名") & "'")
drs(i)("出库累计") = e.DataTable.Compute("sum(出库数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [品名] = '" & dr("品名") & "'")
Next
End If
End If
End Select