以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  为什么重置二次才出现正确结果  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=34211)

--  作者:xzc1221
--  发布时间:2013/6/2 21:59:00
--  为什么重置二次才出现正确结果

\'下面的代码为什么重置二次才出现正确结果

Select Case e.DataCol.Name
    Case "应分面积"
    Dim drr As  DataRow = e.DataRow
    drr("垂长累计") =( Math.Sqrt(2 * drr("累计面积") * drr("南北垂长") * (drr("北长_下底") - drr("南长_上底")) + drr("南长_上底") * drr("南长_上底") * drr("南北垂长") * drr("南北垂长") ) _
 - drr("南长_上底") * drr("南北垂长") ) / (drr("北长_下底") - drr("南长_上底"))
End Select

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("西长累计")
            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-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("东长累计")
                    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-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


--  作者:kylin
--  发布时间:2013/6/3 8:46:00
--  
这个需要你做个实例发上来,大家才可以帮你测试和发现问题。
数据就模拟一些会出现这样问题的数据就可以了。

--  作者:Bin
--  发布时间:2013/6/3 8:46:00
--  
能不能上个例子? 另外你是点击第一次重置没有计算?还是计算错误?  
--  作者:狐狸爸爸
--  发布时间:2013/6/3 8:46:00
--  

没有例子? 也不做任何解释?

什么列输入数据? 在什么列得出计算结果? 第一次得出的错误结果是什么? 第二次重置后得出的正确的结果是社么?


--  作者:xzc1221
--  发布时间:2013/6/3 21:57:00
--  

\'这样写后正确了,是计算顺序错误引起的。谢谢大家的关心!

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