目前数据不多,数据已经很慢,可不可以优化
Select Case e.DataCol.Name
Case "清单ID", "完成数量"
Dim drs As List(of DataRow)
Dim Filter As String
Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [清单ID] = '" & e.DataRow("清单ID") & "'"
drs = e.DataTable.Select(Filter)
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And [清单ID] = '" & dr("清单ID") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(完成数量)",Filter)
dr("累计完成数量") = Val1
Next
If e.DataCol.Name = "清单ID" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [清单ID] = '" & e.OldValue & "'"
drs = e.DataTable.Select(Filter)
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And [清单ID] = '" & dr("清单ID") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(完成数量)",Filter)
dr("累计完成数量") = Val1
Next
End If
End Select
'
非等于比较中说是可以从390秒到2秒,再从2秒到0.9秒,可见代码的优化对于效率的提升是何其重要。但是我做的代码好像不对,没有按清单ID分类累计,请老师看看
Dim drs As List(of DataRow) = DataTables("完成明细").Select("", "清单ID,统计日期") '注意排序参数
drs(0)("累计完成数量") = drs(0)("完成数量") '设置第一行的累计完成数量
For i As Integer = 1 To drs.Count - 1 '从第二行开始逐行计算累计完成数量
If drs(i)("清单ID") = drs(i - 1)("清单ID") Then
drs(i)("累计完成数量") = drs(i-1)("累计完成数量") + drs(i)("完成数量")
Else
drs(i)("累计完成数量") = drs(i)("完成数量")
End If
Next
[此贴子已经被作者于2017/11/9 9:10:20编辑过]