还是提示它错误,另会计有用红字表示负数,我用红色标注代码就是让负数文本显示红色,问题来了,会计上用红色就已经表示负数,不用再带负号,但软件上用红色只是显示,与计算无关,如不要负号就表示正数,如何使账面上的红色数量或金额就表示负数,不带负号。
此主题相关图片如下:qq图片20210513165510.png
With Tables("三栏式账_Table1")
For i As Integer = .Rows.count - 1 To 0 Step -1
.Rows(i).Delete
Next
End With
Dim t As String
Dim Parts() As String = e.Form.Controls("DropBox1").Value.Split("-")
If Parts.length > 0 Then
t = Parts(0)
End If
Dim Filter As String
With e.Form.Controls("DropBox1")
If .Value IsNot Nothing Then
Filter = "会计科目辅助列 = '" & .Value & "'"
End If
End With
With e.Form.Controls("StartDate")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 <= #" & .Value & "#"
End If
End With
With e.Form.Controls("EndDate")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 >= #" & .Value & "#"
End If
End With
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "Select 日期,字号,凭证号,摘要,借方金额,贷方金额 fro m {财务数据源} Where Filter"
dt = cmd.ExecuteReader()
'对临时进行分组统计
Dim b As New GroupTableBuilder("统计表",dt)
b.Groups.AddDef("日期",DateGroupEnum.Year,"年")
b.Groups.AddDef("日期",DateGroupEnum.Month,"月")
b.Groups.AddDef("字号")
b.Groups.AddDef("凭证号")
b.Groups.AddDef("摘要")
b.Totals.AddDef("借方金额")
b.Totals.AddDef("贷方金额")
b.Build
Tables("三栏式账_Table1").DataSource = b.BuildDataSource
Dim a As Table = Tables("三栏式账_Table1")
Dim g As Subtotalgroup
a.SubtotalGroups.Clear()
g = New Subtotalgroup
g.GroupOn = "月"
g.TotalOn = "借方金额,贷方金额"
g.Caption = "本月发生额"
a.SubtotalGroups.Add(g)
'g = New Subtotalgroup
'g.GroupOn = "年"
'g.TotalOn = "借方金额,贷方金额"
'g.Caption = "本年累计"
'a.SubtotalGroups.Add(g)
'a.Subtotal()
Dim groups As List(of String) = DataTables("三栏式账_Table1").GetValues("年")
For Each grp As String In groups
g = New Subtotalgroup
g.GroupOn = "*"
g.Caption = "本年累计"
a.SubtotalGroups.Add(g)
Next
a.Subtotal()
Dim cnt As Integer = Tables("三栏式账_Table1").Rows.Count(True) - groups.count
For Each group As String In groups
Tables("三栏式账_Table1").Rows(cnt,True)("年") = group
Tables("三栏式账_Table1").Rows(cnt,True)("借方金额") = DataTables("财务数据源").Compute("Sum(借方金额)","年 = #" & group & "#")
Tables("三栏式账_Table1").Rows(cnt,True)("贷方金额") = DataTables("财务数据源").Compute("Sum(借方金额)","年 = #" & group & "#")
cnt = cnt + 1
Next
Tables("三栏式账_Table1").SetColVisibleWidth("日期|60|字号|40|凭证号|50|摘要|300|借方金额|60|贷方金额|60")
Dim ckb As DataTable = e.Form.Controls("Table1").Table.DataTable
If ckb.DataCols.Contains("借或贷") = False And ckb.DataCols.Contains("余额") = False Then
ckb.DataCols.add("借或贷", Gettype(String))
ckb.DataCols.add("余额", Gettype(Double))
End If
With DataTables("三栏式账_Table1")
Dim dr As DataRow
Dim drs As List(of DataRow)
dr = .Find("[_SortKey] < " & Tables("三栏式账_Table1").current("_SortKey"), "[_SortKey] Desc") '找出上一行
If dr Is Nothing And DataTables("资产").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing Then '如果没有找到上一行,说明本行就是第一行
dr("借或贷") = "借"
If Tables("三栏式账_Table1").Current IsNot Nothing Then
dr("余额") = current("借方金额")
If dr("余额") = current("贷方金额") Then
dr("余额").Style.TextColor = Color.Red
End If
End If
ElseIf dr Is Nothing And (DataTables("负债").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing OrElse DataTables("所有者权益").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing OrElse DataTables("损益").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing) Then
dr("借或贷") = "贷"
If Tables("三栏式账_Table1").Current IsNot Nothing Then
dr("余额") = current("贷方金额")
If dr("余额") = current("借方金额") Then
dr("余额").Style.TextColor = Color.Red
End If
End If
End If
drs = .Select("[_SortKey] >= " & dr("_SortKey"), "[_SortKey]")
For i As Integer = 1 To drs.Count - 1 '重算余下行的余额
If DataTables("资产").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing Then
drs(i)("借或贷") = "借"
If Tables("三栏式账_Table1").Current IsNot Nothing Then
drs(i)("余额") = drs(i-1)("余额") + drs(i)("借方金额") - drs(i)("贷方金额")
If drs(i-1)("余额") + drs(i)("借方金额") - drs(i)("贷方金额") < 0 Then
drs(i)("余额").Style.TextColor = Color.Red
End If
End If
ElseIf DataTables("负债").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing OrElse DataTables("所有者权益").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing OrElse DataTables("损益").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing Then
drs(i)("借或贷") = "贷"
If Tables("三栏式账_Table1").Current IsNot Nothing Then
drs(i)("余额") = drs(i-1)("余额") + drs(i)("贷方金额") - drs(i)("借方金额")
If drs(i-1)("余额") + drs(i)("贷方金额") - drs(i)("借方金额") < 0 Then
drs(i)("余额").Style.TextColor = Color.Red
End If
End If
End If
Next
If Tables("三栏式账_Table1").Rows.Count < 15 Then
Tables("三栏式账_Table1").AddNew(15 - Tables("三栏式账_Table1").Rows.Count)
End If
End With