红色标注错误
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 t As Table = Tables("三栏式账_Table1")
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
g = New Subtotalgroup
g.GroupOn = "月"
g.TotalOn = "借方金额,贷方金额"
g.upto = True '进行截止统计
t.SubtotalGroups.Add(g)
g = New Subtotalgroup
g.GroupOn = "年"
g.TotalOn = "借方金额,贷方金额"
g.upto = True '进行截止统计
t.SubtotalGroups.Add(g)
t.Subtotal()
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 '如果没有找到上一行,说明本行就是第一行
Tables("三栏式账_Table1").current("余额") = Tables("三栏式账_Table1").current("借方金额") - Tables("三栏式账_Table1").current("贷方金额")
dr("借或贷") = "借"
dr("余额") = current("借方金额")
ElseIf dr Is Nothing And (DataTables("负债").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing OrElse DataTables("所有者权益").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing OrElse DataTables("损益").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing) Then
Tables("三栏式账_Table1").current("余额") = Tables("三栏式账_Table1").current("贷方金额") - Tables("三栏式账_Table1").current("借方金额")
dr("借或贷") = "贷"
dr("余额") = current("贷方金额")
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)("借或贷") = "借"
drs(i)("余额") = drs(i-1)("余额") + drs(i)("借方金额") - drs(i)("贷方金额")
ElseIf DataTables("负债").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing OrElse DataTables("所有者权益").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing OrElse DataTables("损益").SQLFind("[科目名称] = '" & t & "'") IsNot Nothing Then
drs(i)("借或贷") = "贷"
drs(i)("余额") = drs(i-1)("余额") + drs(i)("贷方金额") - drs(i)("借方金额")
End If
Next
If Tables("三栏式账_Table1").Rows.Count < 15 Then
Tables("三栏式账_Table1").AddNew(15 - Tables("三栏式账_Table1").Rows.Count)
End If
End With