以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]这个要怎么实现  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=68570)

--  作者:linswcfr
--  发布时间:2015/5/20 15:58:00
--  [求助]这个要怎么实现

第一个表格是通过交叉统计表得到的,但是要进一步得到下面表格要代码要怎么写了


图片点击可在新窗口打开查看此主题相关图片如下:例图.png
图片点击可在新窗口打开查看

--  作者:大红袍
--  发布时间:2015/5/20 16:00:00
--  
 上传具体例子。
--  作者:linswcfr
--  发布时间:2015/5/20 16:30:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目4.table


--  作者:linswcfr
--  发布时间:2015/5/20 16:43:00
--  
在线等,求老师帮忙!!
--  作者:大红袍
--  发布时间:2015/5/20 16:45:00
--  
Dim t As Table = Tables("临时表")
For Each r As Row In t.Rows
    For i As Integer = 6 To 1 Step -1
        If r("余额_" & i) < 0 Then
            Dim ye As Double = 0
            Dim fe As Double = 0
            For j As Integer = i To 1 Step -1
                ye += r("余额_" & j)
                fe += r("余额_" & j & "hp")
                If ye >= 0 Then
                    r("余额_" & j) = ye
                    r("余额_" & j & "hp") = fe
                    For k As Integer = j+1 To i
                        r("余额_" & k) = Nothing
                        r("余额_" & k & "hp") = Nothing
                    Next
                    i = j
                    Exit For
                End If
            Next
        End If
    Next
Next

--  作者:linswcfr
--  发布时间:2015/5/20 16:56:00
--  

谢谢老师!

 


--  作者:linswcfr
--  发布时间:2015/5/20 17:09:00
--  
去掉客户C的数据,问题又出来了....
--  作者:大红袍
--  发布时间:2015/5/20 17:15:00
--  

什么意思。

 

Dim t As Table = Tables("临时表")
For y As Integer = t.Rows.Count - 1 To 0 Step -1
    Dim r As Row = t.Rows(y)
    Dim flag As Boolean = True
    For i As Integer = 6 To 1 Step -1
        If r("余额_" & i) < 0 Then
            flag = False
            Dim ye As Double = 0
            Dim fe As Double = 0
            For j As Integer = i To 1 Step -1
                ye += r("余额_" & j)
                fe += r("余额_" & j & "hp")
                If ye >= 0 Then
                    r("余额_" & j) = ye
                    r("余额_" & j & "hp") = fe
                    For k As Integer = j+1 To i
                        r("余额_" & k) = Nothing
                        r("余额_" & k & "hp") = Nothing
                    Next
                    i = j
                    Exit For
                End If
            Next
        End If
    Next
    If flag Then
        r.delete
    End If
Next


--  作者:linswcfr
--  发布时间:2015/5/20 17:16:00
--  
明细表中,删除客户C的数据后,执行以上代码结果又不对了..
--  作者:大红袍
--  发布时间:2015/5/20 17:22:00
--  
Dim t As Table = Tables("临时表")
Dim mqj As Integer = DataTables("明细表").Compute("max(区间)")
For Each r As Row In t.Rows
    For i As Integer = mqj To 1 Step -1
        If t.Cols.Contains("余额_" & i) Then
            If r("余额_" & i) < 0 Then
                Dim ye As Double = 0
                Dim fe As Double = 0
                For j As Integer = i To 1 Step -1
                    If t.Cols.Contains("余额_" & j) Then
                        ye += r("余额_" & j)
                        fe += r("余额_" & j & "hp")
                        If ye >= 0 Then
                            r("余额_" & j) = ye
                            r("余额_" & j & "hp") = fe
                            For k As Integer = j+1 To i
                                If t.Cols.Contains("余额_" & k) Then
                                    r("余额_" & k) = Nothing
                                    r("余额_" & k & "hp") = Nothing
                                End If
                            Next
                            i = j
                            Exit For
                        End If
                    End If
                Next
            End If
        End If
    Next
Next