Foxtable(狐表)用户栏目专家坐堂 → [求助]当流水账借方金额去贷方金额余额为负数时,在“借贷方向”列自动填入“”贷“”


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

主题:[求助]当流水账借方金额去贷方金额余额为负数时,在“借贷方向”列自动填入“”贷“”

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


加好友 发短信
等级:幼狐 帖子:142 积分:1649 威望:0 精华:0 注册:2014/5/3 14:52:00
[求助]当流水账借方金额去贷方金额余额为负数时,在“借贷方向”列自动填入“”贷“”  发帖心情 Post By:2019/3/11 19:33:00 [显示全部帖子]

    请教:当流水账借方金额减去贷方金额余额为负数时,在“借贷方向”列自动填入“贷”;当流水账借方金额减去贷方金额余额为正数时,在“借贷方向”列自动填入“借”;当流水账借方金额减去贷方金额余额为“0”时,在“借贷方向”列自动填入“平”;

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


加好友 发短信
等级:幼狐 帖子:142 积分:1649 威望:0 精华:0 注册:2014/5/3 14:52:00
  发帖心情 Post By:2019/3/11 21:23:00 [显示全部帖子]

请问:以下代码错在哪里?



Select Case e.DataCol.Name
    Case "借方发生额","贷方发生额"
        For Each dr As DataRow In e.DataTable.Select("[_SortKey] >= " & e.DataRow("_SortKey"))
            Dim Val1 As Double = e.DataTable.Compute("Sum(借方发生额)","[_SortKey] <= " & dr("_SortKey"))
            Dim Val2 As Double = e.DataTable.Compute("Sum(贷方发生额)","[_SortKey] <= " & dr("_SortKey"))
            dr("余额") = Val1 - Val2
        Next
End Select



'明细余额列数据DataColChanged事件代码改为:

 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("贷方发生额")
            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)("贷方发生额")
        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("贷方发生额")
                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)("贷方发生额")
                Next
            End If
        End If
End Select





'科目余额列数据DataColChanged事件代码改为:

 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("贷方发生额")
            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)("贷方发生额")
        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("贷方发生额")
                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)("贷方发生额")
                Next
            End If
        End If
End Select





'例如

Select Case e.DataCol.Name
    Case "借方发生额","贷方发生额"
        For Each dr As DataRow In e.DataTable.Select("[_SortKey] >= " & e.DataRow("_SortKey"))
            Dim Val1 As Double = e.DataTable.Compute("Sum(借方发生额)","[_SortKey] <= " & dr("_SortKey"))
            Dim Val2 As Double = e.DataTable.Compute("Sum(贷方发生额)","[_SortKey] <= " & dr("_SortKey"))
            dr("明细余额") = Val1 - Val2
        Next
    Case "明细余额"
        If e.newvalue = 0 Then
            e.DataRow("余额方向") = "平"
        ElseIf e.newvalue > 0 Then
            e.DataRow("余额方向") = "借"
        Else
            e.DataRow("余额方向") = "贷"
        End If
End Select






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


加好友 发短信
等级:幼狐 帖子:142 积分:1649 威望:0 精华:0 注册:2014/5/3 14:52:00
  发帖心情 Post By:2019/3/11 22:07:00 [显示全部帖子]

我把您提供的代码,放在原来的代码后面,能实现自动显示借贷方向,但是明细余额数据变得不按照原来的“明细余额”运算,也就是某一客户的余额不正确。


请教:能不能这样判断:当指定的列比如“明细余额”数据大于0时,借贷方向列自动显示借,当小于0时,“明细余额”自动显示贷,当“明细余额”等于0时,自动显示平。

请教代码怎么写?谢谢!!!

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


加好友 发短信
等级:幼狐 帖子:142 积分:1649 威望:0 精华:0 注册:2014/5/3 14:52:00
  发帖心情 Post By:2019/3/11 22:18:00 [显示全部帖子]

衷心感谢您的指导!

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


加好友 发短信
等级:幼狐 帖子:142 积分:1649 威望:0 精华:0 注册:2014/5/3 14:52:00
  发帖心情 Post By:2019/3/12 20:12:00 [显示全部帖子]

好了,可以实现了,只是调整了一下顺序,就正常了,谢谢老大的提示!


Select Case e.DataCol.Name
    Case "借方发生额","贷方发生额"
        For Each dr As DataRow In e.DataTable.Select("[_SortKey] >= " & e.DataRow("_SortKey"))
            Dim Val1 As Double = e.DataTable.Compute("Sum(借方发生额)","[_SortKey] <= " & dr("_SortKey"))
            Dim Val2 As Double = e.DataTable.Compute("Sum(贷方发生额)","[_SortKey] <= " & dr("_SortKey"))
            dr("余额") = Val1 - Val2
        Next
End Select



Select Case e.DataCol.Name
    Case "借方发生额","贷方发生额"
        For Each dr As DataRow In e.DataTable.Select("[_SortKey] >= " & e.DataRow("_SortKey"))
            Dim Val1 As Double = e.DataTable.Compute("Sum(借方发生额)","[_SortKey] <= " & dr("_SortKey"))
            Dim Val2 As Double = e.DataTable.Compute("Sum(贷方发生额)","[_SortKey] <= " & dr("_SortKey"))
            dr("明细余额") = Val1 - Val2
        Next
    Case "明细余额"
        If e.newvalue = 0 Then
            e.DataRow("余额方向") = "平"
        ElseIf e.newvalue > 0 Then
            e.DataRow("余额方向") = "借"
        Else
            e.DataRow("余额方向") = "贷"
        End If
End Select








'明细余额列数据DataColChanged事件代码改为:

 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("贷方发生额")
            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)("贷方发生额")
        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("贷方发生额")
                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)("贷方发生额")
                Next
            End If
        End If
End Select






'科目余额列数据DataColChanged事件代码改为:

 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("贷方发生额")
            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)("贷方发生额")
        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("贷方发生额")
                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)("贷方发生额")
                Next
            End If
        End If
End Select







'例如
'Select Case e.DataCol.Name
'    Case "借方发生额","贷方发生额"
'        For Each dr As DataRow In e.DataTable.Select("[_SortKey] >= " & e.DataRow("_SortKey"))
'            Dim Val1 As Double = e.DataTable.Compute("Sum(借方发生额)","[_SortKey] <= " & dr("_SortKey"))
'            Dim Val2 As Double = e.DataTable.Compute("Sum(贷方发生额)","[_SortKey] <= " & dr("_SortKey"))
'            dr("明细余额") = Val1 - Val2
'        Next
'    Case "明细余额"

'        If e.newvalue = 0 Then
'            e.DataRow("余额方向") = "平"
'        ElseIf e.newvalue > 0 Then
'            e.DataRow("余额方向") = "借"
'        Else
'            e.DataRow("余额方向") = "贷"
'        End If
'End Select

 回到顶部