'这样写后正确了,是计算顺序错误引起的。谢谢大家的关心!
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("应分面积")
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)("应分面积")
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("应分面积")
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)("应分面积")
Next
End If
End If
'对某列开平方
Case "南长_上底","北长_下底","南北垂长","累计面积"
If e.DataRow("南长_上底") = e.DataRow("北长_下底") Then
e.DataRow("垂长累计") = e.DataRow("累计面积") / e.DataRow("南长_上底")
Else
'对某列开平方
e.DataRow("垂长累计") =( Math.Sqrt(2 * e.DataRow("累计面积") * e.DataRow("南北垂长") * (e.DataRow("北长_下底") - e.DataRow("南长_上底")) + e.DataRow("南长_上底") * e.DataRow("南长_上底") * e.DataRow("南北垂长") * e.DataRow("南北垂长") ) _
- e.DataRow("南长_上底") * e.DataRow("南北垂长") ) / (e.DataRow("北长_下底") - e.DataRow("南长_上底"))
End If
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("西长累计")
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)("垂长累计") - drs(i-1)("垂长累计")
drs(i)("实分面积") = drs(i)("验证面积") - drs(i-1)("验证面积")
drs(i)("户分东长") = drs(i)("东长累计") - drs(i-1)("东长累计")
drs(i)("户分西长") = drs(i)("西长累计") - drs(i-1)("西长累计")
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("西长累计")
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)("垂长累计") - drs(i-1)("垂长累计")
drs(i)("实分面积") = drs(i)("验证面积") - drs(i-1)("验证面积")
drs(i)("户分东长") = drs(i)("东长累计") - drs(i-1)("东长累计")
drs(i)("户分西长") = drs(i)("西长累计") - drs(i-1)("西长累计")
Next
End If
End If
End Select