-- 作者:leizhizhilun
-- 发布时间:2012/8/21 17:21:00
-- [求助]按窗口控件内容统计或汇总
此项目基础数据表中的报表管理器窗口中,有姓名、类型和日期,类型是按照不同的时间跨度汇总或统计,日期是查询时间范围,想要根据这些项目中填写的内容,汇总或统计(按天就是汇总,按周、月、季度、年都是统计)各项数值呢?研究了半天还是不会写代码。
我研究的内容如下:但好像不对……请大神帮忙!
Dim g As New GroupTableBuilder("统计表1", DataTables("基础数据")) Dim Val As String = Forms("报表管理器").Controls("ComboBox1").Value Dim name As String = Forms("报表管理器").Controls("TextBox1").Value Dim Date1 As Date = Forms("报表管理器").Controls("datetimepicker1").Value Dim Date2 As Date = Forms("报表管理器").Controls("datetimepicker2").Value If g.filter = "[姓名] = name and [日期] >= Date1 and [日期] <= Date2 " Then g.Groups.AddDef("姓名") If Val Is Nothing Then MessageBox.Show("对不起,请先输入查询类型!", "提示") ElseIf Val = "按月" Then g.Groups.AddDef("日期",DateGroupEnum.month,"月") ElseIf Val = "按天" Then g.Groups.AddDef("日期",DateGroupEnum.day,"天,dddd") ElseIf Val = "按周" Then g.Groups.AddDef("日期",DateGroupEnum.week,"周") ElseIf Val = "按季度" Then g.Groups.AddDef("日期",DateGroupEnum.quarter,"季度") ElseIf Val = "按年" Then g.Groups.AddDef("日期",DateGroupEnum.year,"年") End If g.Totals.AddDef("呼叫次数") g.Totals.AddDef("总单量") g.VerticalTotal = True g.Build() End If
[此贴子已经被作者于2012-8-21 17:24:03编辑过]
|
-- 作者:狐狸爸爸
-- 发布时间:2012/8/21 17:40:00
--
大概如此:
Dim Filter As String If e.form.Controls("TextBox1").Value IsNot Nothing Then Filter = "姓名 = \'" & e.form.Controls("TextBox1").Value & "\'" End If If e.form.Controls("DateTimePicker1").Value IsNot Nothing Then If filter > "" Then Filter = Filter & " And " End If Filter = Filter & "日期 >= #" & e.form.Controls("DateTimePicker1").Value & "#" End If If e.form.Controls("DateTimePicker2").Value IsNot Nothing Then If filter > "" Then Filter = Filter & " And " End If Filter = Filter & "日期 <= #" & e.form.Controls("DateTimePicker2").Value & "#" End If Dim g As New GroupTableBuilder("统计表1", DataTables("基础数据")) Dim Val As String = Forms("报表管理器").Controls("ComboBox1").Value g.Filter = filter g.Groups.AddDef("姓名") If Val Is Nothing Then MessageBox.Show("对不起,请先输入查询类型!", "提示") ElseIf Val = "按月" Then g.Groups.AddDef("日期",DateGroupEnum.month,"月") ElseIf Val = "按天" Then g.Groups.AddDef("日期",DateGroupEnum.day,"日") ElseIf Val = "按周" Then g.Groups.AddDef("日期",DateGroupEnum.week,"周") ElseIf Val = "按季度" Then g.Groups.AddDef("日期",DateGroupEnum.quarter,"季度") ElseIf Val = "按年" Then g.Groups.AddDef("日期",DateGroupEnum.year,"年") End If g.Totals.AddDef("呼叫次数") g.Totals.AddDef("总单量") g.VerticalTotal = True g.Build()
MainTable = Tables("统计表1")
[此贴子已经被作者于2012-8-21 17:41:17编辑过]
|