1、数据表总行数近1500万行,实际参与统计的(Filter 以后)不到1万行,窗口表的样式描绘已关。如图,点击统计按钮后,方框中的控件信息都空了,代码运行完毕后,又重新显示:
此主题相关图片如下:gif.gif
2、统计按钮代码:
'添加分析表
Dim b As New SQLCrossTableBuilder("统计表1","分析数据")
b.C
'添加多表-关联列
b.AddTable("分析数据","阳历日期","股piao日线","日期") '添加统计表
'横向分组(竖向-行标题)
For Each s As String In e.Form.Controls("CheckedComboBox16").text.Split("|")
If s = "日期" Then
b.HGroups.AddDef("日期",DateGroupEnum.none)
Else
b.HGroups.AddDef(s) '添加列用于垂直分组
End If
Next
'竖向分组(横向-列标题)
For Each s As String In e.Form.Controls("CheckedComboBox17").text.Split("|")
If s = "日期" Then
b.VGroups.AddDef("日期",DateGroupEnum.none)
ElseIf s = "阳历日期" Then
b.VGroups.AddDef("阳历日期",DateGroupEnum.none)
Else
b.VGroups.AddDef(s) '添加列用于水平分组
End If
Next
'计算列
For Each s As String In e.Form.Controls("CheckedComboBox18").text.Split("|")
If e.Form.Controls("CheckBox5").checked = True Then
b.Decimals = 2 '保留两位小数
b.Totals.AddDef(s,AggregateEnum.Sum) '累计数统计
ElseIf e.Form.Controls("CheckBox8").checked = True Then
b.Decimals = 2 '保留两位小数
b.Totals.AddDef(s,AggregateEnum.Average) '平均数统计
End If
Next
'设置统计条件
b.Filter = e.form.controls("TextBox1").Text
'生成汇总模式
If e.Form.Controls("CheckBox1").checked = True Then '水平方向生成汇总
b.HorizontalTotal = True
End If
If e.Form.Controls("CheckBox2").checked = True Then '垂直方向生成汇总
b.VerticalTotal = True
End If
If e.Form.Controls("CheckBox3").checked = True Then '自动生成汇总模式
b.Subtotal = True
End If
b.Decimals = 2 '保留两位小数
b.Build '生成统计表
Tables("统计分析_Table1").DataSource = b.BuildDataSource()
'窗口表样式
Tables("统计分析_Table1").grid.styles.Normal.Border.Color = Color.Red
Tables("统计分析_Table1").grid.styles.Normal.Border.Style = 1
Tables("统计分析_Table1").grid.styles.Normal.Border.width = 1
Tables("统计分析_Table1").grid.styles.Normal.Border.Direction = 0 '0-2
Tables("统计分析_Table1").DefaultRowHeight = 30
'Tables("统计分析_Table1").AutoSizeRows
'单元格水平居中
If e.Form.Controls("CheckBox4").checked = True Then
For Each c As Col In Tables("统计分析_Table1").cols
c.TextAlign = TextAlignEnum.Center
Next
End If
'平均列宽
If e.Form.Controls("CheckBox6").checked = True Then
Dim wid As Integer=(e.Form.controls("Table1").Width-50)/Tables("统计分析_Table1").Cols.Count
Dim cls As String
For Each c As Col In Tables("统计分析_Table1").Cols
cls = cls & c.Name & "|" & wid & "|"
Next
Tables("统计分析_Table1").SetColVisibleWidth(cls.Trim("|"))
End If
'自动列宽
If e.Form.Controls("CheckBox7").checked = True Then
Tables("统计分析_Table1").AutoSizeCols()
End If
'合并单元格
If e.Form.Controls("CheckBox12").checked = True Then
With Tables("统计分析_Table1") '合并
.MergeMode = MergeModeEnum.Standard '标准合并模式
.MergeCols.Clear() '清除原来的合并列
Dim Names As String() = e.Form.Controls("CheckedComboBox16").text.Split("|")
For i As Integer = 0 To Names.Length -2
.MergeCols.Add(Names(i))
Next
.AllowMerge = True '启用合并模式
End With
End If
Dim dt As Table = Tables("统计分析_Table1") '居中
For Each c As Col In dt.Cols
c.TextAlign = TextAlignEnum.Center
Next
'补齐日期
If Tables("统计分析_Table1").Cols.Contains("日期") Or Tables("统计分析_Table1").Cols.Contains("阳历日期") Then
Dim drs As List(of DataRow) = DataTables("分析数据").SQLSelect("年份 = '2020'")
For Each dr As DataRow In drs
Dim dr1 As DataRow = Tables("统计分析_Table1").DataTable.Find("日期 = '" & dr("阳历日期") & "'")
If dr1 Is Nothing Then
dr1 = Tables("统计分析_Table1").DataTable.Addnew()
dr1("日期") = dr("阳历日期")
Dim Names As String() = e.Form.Controls("CheckedComboBox16").text.Split("|")
For i As Integer = 0 To Names.Length -2
dr1(Names(i)) = dr(Names(i))
Next
Else
End If
Next
End If
'汇总显示目录树
If e.Form.Controls("CheckBox9").checked = True Then
Dim t As Table = Tables("统计分析_Table1")
t.GroupAboveData = True '分组行位于数据行之上
t.TreeVisible = True '显示目录树
End If
[此贴子已经被作者于2020/5/27 18:45:49编辑过]