Foxtable(狐表)用户栏目专家坐堂 → [已解决]怎样把表1中最后一次生成的余额加到表2中


  共有5438人关注过本帖树形打印复制链接

主题:[已解决]怎样把表1中最后一次生成的余额加到表2中

帅哥哟,离线,有人找我吗?
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/5/6 8:41:00 [显示全部帖子]

Select Case e.DataCol.Name
    Case "账户", "借", "贷"
        Dim drs As List(Of DataRow)
        Dim Filter As String
        Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [账户] = '" & e.DataRow("账户") & "'"
        drs = e.DataTable.Select(Filter)
        For Each dr As DataRow In drs
            Filter = "[_SortKey] <= " & dr("_SortKey") & " And [账户] = '" & dr("账户") & "'"
            Dim Val1 As Double = e.DataTable.Compute("Sum(借)", Filter)
            Dim Val2 As Double = e.DataTable.Compute("Sum(贷)", Filter)
            dt = DataTables("各种账户的名称").AddNew()
            dr("余额") = Val1 - Val2
        Next
        Dim dt As DataRow = DataTables("各种账户的名称").Find("账户= '" & e.DataRow("账户") & "'")
        If dt Is Nothing Then
            dt = DataTables("各种账户的名称").AddNew()
            dt("账户") = e.DataRow("账户")
        End If 
        Dim dr2 As DataRow = e.DataTable.find("账户= '" & e.DataRow("账户") & "'", "[_SortKey] desc")
        dt("余额") = dr2("余额") 
        If e.DataCol.Name = "账户" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [账户] = '" & e.OldValue & "'"
            drs = e.DataTable.Select(Filter)
            For Each dr As DataRow In drs
                Filter = "[_SortKey] <= " & dr("_SortKey") & " And [账户] = '" & dr("账户借") & "'"
                Dim Val1 As Double = e.DataTable.Compute("Sum(借)", Filter)
                Dim Val2 As Double = e.DataTable.Compute("Sum(贷)", Filter)
                dt = DataTables("各种账户的名称").AddNew()
                
                dr("余额") = Val1 - Val2
                dt("余额") = dr("余额") 
            Next
            dt = DataTables("各种账户的名称").Find("账户= '" & e.OldValue & "'")
            If dt Is Nothing Then
                dt = DataTables("各种账户的名称").AddNew()
                dt("账户") = e.OldValue
            End If 
            dr2 = e.DataTable.find("账户= '" & e.OldValue & "'", "[_SortKey] desc")
            dt("余额") = dr2("余额") 
        End If
        
End Select

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/5/6 11:26:00 [显示全部帖子]

Select Case e.DataCol.Name
    Case "账户", "借", "贷"
        Dim drs As List(Of DataRow)
        Dim Filter As String
        Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [账户] = '" & e.DataRow("账户") & "'"
        drs = e.DataTable.Select(Filter)
        For Each dr As DataRow In drs
            Filter = "[_SortKey] <= " & dr("_SortKey") & " And [账户] = '" & dr("账户") & "'"
            Dim Val1 As Double = e.DataTable.Compute("Sum(借)", Filter)
            Dim Val2 As Double = e.DataTable.Compute("Sum(贷)", Filter)
            dr("余额") = Val1 - Val2
        Next
        Dim dt As DataRow = DataTables("各种账户的名称").Find("账户= '" & e.DataRow("账户") & "'")
        If dt Is Nothing Then
            dt = DataTables("各种账户的名称").AddNew()
            dt("账户") = e.DataRow("账户")
        End If 
        Dim dr2 As DataRow = e.DataTable.find("账户= '" & e.DataRow("账户") & "'", "[_SortKey] desc")
        dt("余额") = dr2("余额") 
        If e.DataCol.Name = "账户" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [账户] = '" & e.OldValue & "'"
            drs = e.DataTable.Select(Filter)
            For Each dr As DataRow In drs
                Filter = "[_SortKey] <= " & dr("_SortKey") & " And [账户] = '" & dr("账户借") & "'"
                Dim Val1 As Double = e.DataTable.Compute("Sum(借)", Filter)
                Dim Val2 As Double = e.DataTable.Compute("Sum(贷)", Filter)
                dr("余额") = Val1 - Val2
            Next
            dt = DataTables("各种账户的名称").Find("账户= '" & e.OldValue & "'")
            If dt Is Nothing Then
                dt = DataTables("各种账户的名称").AddNew()
                dt("账户") = e.OldValue
            End If 
            dr2 = e.DataTable.find("账户= '" & e.OldValue & "'", "[_SortKey] desc")
            dt("余额") = dr2("余额") 
        End If
        
End Select


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/5/6 12:04:00 [显示全部帖子]

变成啥样?

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/5/6 13:33:00 [显示全部帖子]

删除行到datarowdeleteing事件处理

 回到顶部