以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]计算过程中突然退出  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=159873)

--  作者:lgj716330
--  发布时间:2021/1/12 9:20: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("采购成本金额")+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-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("采购成本金额")+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-1)("结余数量")+drs(i)("采购数量"))
                Next
            End If
        End If
End Select

Select Case e.DataCol.Name
    Case "结余成本单价","零售数量"
        e.DataRow("零售成本金额")=e.DataRow("零售数量")*e.DataRow("结余成本单价")
End Select

Select Case e.DataCol.Name
    Case "结余成本单价","结余数量"
        e.DataRow("结余成本金额")=e.DataRow("结余数量")*e.DataRow("结余成本单价")
End Select

--  作者:有点蓝
--  发布时间:2021/1/12 9:29:00
--  
Select Case e.DataCol.Name
    Case "款式编号","采购成本金额","结余成本金额","采购数量","结余数量"
systemready=false
        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("结余数量"))
            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-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("采购成本金额")+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-1)("结余数量")+drs(i)("采购数量"))
                Next
            End If
        End If
systemready=true
End Select

Select Case e.DataCol.Name
    Case "结余成本单价","零售数量"
        e.DataRow("零售成本金额")=e.DataRow("零售数量")*e.DataRow("结余成本单价")
End Select

Select Case e.DataCol.Name
    Case "结余成本单价","结余数量"
systemready=false
        e.DataRow("结余成本金额")=e.DataRow("结余数量")*e.DataRow("结余成本单价")
systemready=true
End Select


--  作者:lgj716330
--  发布时间:2021/1/12 9:57:00
--  
但这样出来的结果显示结余成本单价是“非数字”
--  作者:有点蓝
--  发布时间:2021/1/12 9:58:00
--  
出现了除以0的操作,判断一下被除数为0,就直接给结余成本单价赋值0
--  作者:lgj716330
--  发布时间:2021/1/12 10:15:00
--  
不是这个原因
把这里的systemready去掉后,零售数量是空的结果都为0,其他可以计算
Select Case e.DataCol.Name
    Case "结余成本单价","结余数量"
        e.DataRow("结余成本金额")=e.DataRow("结余数量")*e.DataRow("结余成本单价")
End Select

然后改成下面这样,好象可以了,不明白其中道理
Select Case e.DataCol.Name
    Case "结余成本单价","结余数量",“零售数量”,“采购数量”
        e.DataRow("结余成本金额")=e.DataRow("结余数量")*e.DataRow("结余成本单价")
End Select
[此贴子已经被作者于2021/1/12 10:16:05编辑过]