我想在三栏式账窗口的Table1中加入第一行,如果资产或负债或所有者权益或损益表的科目名称列中科目名称等于e.Form.Controls("DropBox1").Value,其余额等于查找到的对应表对应期初余额,我这样写红色代码报错,另即使添加了第一行并引用了期初余额,下面的统计表生成的数据亦会把它覆盖吧?
Dim a As Table = Tables("三栏式账_Table1")
Dim g As Subtotalgroup
a.SubtotalGroups.Clear()
CurrentTable.AddNew()
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 cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "Select 日期,字号,凭证号,摘要,借方金额,贷方金额 fr om {财务数据源} Where [日期] >= #" & e.Form.Controls("StartDate").Value & "# And [日期] <= #" & e.Form.Controls("EndDate").Value & "# And [会计科目辅助列] ='" & e.Form.Controls("DropBox1").Value & "'"
dt = cmd.ExecuteReader()
'对临时进行分组统计
Dim b As New GroupTableBuilder("统计表1",dt)
b.Groups.AddDef("日期",DateGroupEnum.Year,"年")
b.Groups.AddDef("日期","月")
b.Groups.AddDef("字号")
b.Groups.AddDef("凭证号")
b.Groups.AddDef("摘要")
b.Totals.AddDef("借方金额")
b.Totals.AddDef("贷方金额")
b.Build(True)
Tables("三栏式账_Table1").DataSource = b.BuildDataSource
g = New Subtotalgroup
g.GroupOn = "月"
g.TotalOn = "借方金额,贷方金额"
g.Caption = "本月发生额"
a.SubtotalGroups.Add(g)
g = New Subtotalgroup
g.GroupOn = "月"
g.Caption = "{0}月"
a.SubtotalGroups.Add(g)
a.Sort = "年,月"
a.Subtotal(True)
Dim r As Row
For i As Integer = 0 To a.Rows.Count(True) - 1
r = a.Rows(i,True)
If r.IsGroup AndAlso r("年") Like "*月" '如果是分组行
Dim f As String = "年 = " & a.Rows(i-2,True)("年") & " And 月 <= " & r("年").trim("月")
r("年") = "本年累计"
r("借方金额") = a.Compute("Sum(借方金额)",f)
r("贷方金额") = a.Compute("Sum(贷方金额)",f)
End If
Next
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
If e.Form.Controls("DropBox1").Value = DataTables("资产").Find("[科目名称] ='" & e.Form.Controls("DropBox1").Value & "'") Then
DataTables("三栏式账_Table1").DataRows(0)("借或贷") = "借"
DataTables("三栏式账_Table1").DataRows(0)("余额") = DataTables("资产").Compute("Sum(期初余额)","[科目名称] = '" & Right(e.Form.Controls("DropBox1").Value,len(科目代码)) & "' And [期初余额] Is Not Null")
ElseIf e.Form.Controls("DropBox1").Value = DataTables("负债").Find("[科目名称] ='" & e.Form.Controls("DropBox1").Value & "'") Then
DataTables("三栏式账_Table1").DataRows(0)("借或贷") = "贷"
DataTables("三栏式账_Table1").DataRows(0)("余额") = DataTables("负债").Compute("Sum(期初余额)","[科目名称] = '" & Right(e.Form.Controls("DropBox1").Value,len(科目代码)) & "' And [期初余额] Is Not Null")
ElseIf e.Form.Controls("DropBox1").Value = DataTables("所有者权益").Find("[科目名称] ='" & e.Form.Controls("DropBox1").Value & "'") Then
DataTables("三栏式账_Table1").DataRows(0)("借或贷") = "贷"
DataTables("三栏式账_Table1").DataRows(0)("余额") = DataTables("所有者权益").Compute("Sum(期初余额)","[科目名称] = '" & Right(e.Form.Controls("DropBox1").Value,len(科目代码)) & "' And [期初余额] Is Not Null")
ElseIf e.Form.Controls("DropBox1").Value = DataTables("损益").Find("[科目名称] ='" & e.Form.Controls("DropBox1").Value & "'") Then
DataTables("三栏式账_Table1").DataRows(0)("借或贷") = "贷"
DataTables("三栏式账_Table1").DataRows(0)("余额") = DataTables("损益").Compute("Sum(期初余额)","[科目名称] = '" & Right(e.Form.Controls("DropBox1").Value,len(科目代码)) & "' And [期初余额] Is Not Null")
End If
DataTables("三栏式账_Table1").DataCols("借方金额").SetFormat("#,###.##")
DataTables("三栏式账_Table1").DataCols("贷方金额").SetFormat("#,###.##")
DataTables("三栏式账_Table1").DataCols("余额").SetFormat("#,###.##")
Tables("三栏式账_Table1").SetColVisibleWidth("年|40|月|25|字号|35|凭证号|45|摘要|380|借方金额|70|贷方金额|70|借或贷|45|余额|70")