写成红色代码报错,且没有了本年累计数据,改为下面黑字的代码直接报错不让保存,S已经定义了一次,重复定义了。
.NET Framework 版本:4.0.30319.17929
Foxtable 版本:2021.5.29.1
错误所在事件:窗口,多栏式明细账,Button1,Click
详细错误信息:
An item with the same key has already been added.
With Tables("多栏式明细账_Table1")
For i As Integer = .Rows.count - 1 To 0 Step -1
.Rows(i).Delete
Next
Dim g As Subtotalgroup
.SubtotalGroups.Clear()
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("combobox1").Value & "'"
dt = cmd.ExecuteReader()
Dim b As New CrossTableBuilder("统计表1",dt)
b.HGroups.AddDef("日期",DateGroupEnum.Year,"年")
b.HGroups.AddDef("日期",DateGroupEnum.Month,"月")
b.HGroups.AddDef("日期",DateGroupEnum.Day,"日")
b.HGroups.AddDef("字号")
b.HGroups.AddDef("凭证号")
b.HGroups.AddDef("摘要")
b.VGroups.AddDef("二级科目","{0}")
b.Totals.AddDef("借方金额","借方金额")
b.HorizontalTotal = True
b.OrderByTotal = True
b.Build(True)
.DataSource = b.BuildDataSource
Dim s As String = ""
For Each c As Col In .Cols
If c.Name Like "借方金额_*" Then
s = s & "," & c.name
End If
Next
g = New Subtotalgroup
g.GroupOn = "月"
g.TotalOn = s.Trim(",")
g.Caption = "本月发生额"
.SubtotalGroups.Add(g)
g = New Subtotalgroup
g.GroupOn = "月"
g.Caption = "{0}月"
.SubtotalGroups.Add(g)
.Sort = "年,月"
.Subtotal(True)
Dim r As Row
For i As Integer = 0 To .Rows.Count(True) - 1
r = .Rows(i,True)
If r.IsGroup AndAlso r("年") Like "*月" '如果是分组行
Dim f As String = "年 = " & .Rows(i-2,True)("年") & " And 月 <= " & r("年").trim("月")
r("年") = "本年累计"
For Each c As Col In .Cols
If c.name = c.Name Like "借方金额_*" Then
r(c.name) = .Compute("Sum(" & c.name & ")",f)
End If
Next
End If
Next
Dim sa As String = "年|35|月|30|日|30|字号|30|凭证号|35|摘要|300|[其它]|合计|60"
Dim ct As WinForm.Table = e.Form.Controls("Table1")
Dim t As Table = ct.Table
Dim str As String
Dim w2 As Integer = (ct.Width - 35 - 30 * 4 - 300 - 60) / (t .cols.Count-7)
If w2 > 0 Then
For Each c As Col In .Cols
str = str & "|" & c.name & "|" & w2
Next
sa = sa.replace("[其它]",str.trim("|"))
t.SetColVisibleWidth(sa)
End If
Dim s As String = "年|35|月|30|日|30|字号|30|凭证号|35|摘要|300|[其它]|合计|60"
Dim ct As WinForm.Table = e.Form.Controls("Table1")
Dim t As Table = ct.Table
Dim str As String
Dim w2 As Integer = (ct.Width - 35 - 30 * 4 - 300 - 60) / (t .cols.Count-7)
If w2 > 0 Then
For Each c As Col In .Cols
str = str & "|" & c.name & "|" & w2
Next
s = sa.replace("[其它]",str.trim("|"))
t.SetColVisibleWidth(s)
End If
End With
[此贴子已经被作者于2021/6/24 10:54:41编辑过]