用注识的代码可以保存,但没有数据生成,用你的代码红色标注代码报错,不让保存,就算改为统计表1也一样报错,会计账格式是统一规定的,统计本年度累计数也是报税时取数规定的,不允许变,只能想办法解决统计问题。
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 CrossTableBuilder("三栏式账_Table1",dt)
'b.VGroups.AddDef("日期",DateGroupEnum.Year,"年")
'b.VGroups.AddDef("日期",DateGroupEnum.Month,"月")
'b.HGroups.AddDef("字号")
'b.HGroups.AddDef("凭证号")
'b.HGroups.AddDef("摘要")
'b.HGroups.AddDef("借方金额")
'b.HGroups.AddDef("贷方金额")
'b.Totals.AddDef("借方金额","本月发生额")
'b.Totals.AddExp("借方金额","本月止累计",True) '这里应是本年累计
'b.Totals.AddDef("贷方金额","本月发生额")
'b.Totals.AddExp("贷方金额","本月止累计",True) '这里应是本年累计
'b.Build()
Dim b As New GroupTableBuilder("三栏式账_Table1",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
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()
'MainTable = Tables("三栏式账_Table1")
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("借或贷") = "借"
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("借或贷") = "贷"
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-1)("余额") + drs(i)("借方金额") - 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-1)("余额") + drs(i)("贷方金额") - 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
[此贴子已经被作者于2021/5/12 21:19:23编辑过]