'首先生成统计表 Dim dt As DataTable Dim b As New GroupTableBuilder("统计表1",DataTables("涂胶检验")) b.Groups.AddDef("日期",DateGroupEnum.none,"日期") b.Groups.AddDef("日期",DateGroupEnum.Year,"年") b.Groups.AddDef("日期",DateGroupEnum.Month,"月") b.Groups.AddDef("日期",DateGroupEnum.day,"日") b.Groups.AddDef("型号") b.Totals.AddDef("投入",AggregateEnum.sum,"投入") b.Totals.AddDef("不良率",AggregateEnum.sum,"不良率") dt = b.Build(False) '参数设置为False,生成一个临时表,不在主界面显示 Dim fdr As DataRow = dt.Find("日期 <= #" & Date.Today & "#", "日期 desc") '然后根据统计表生成目录树 Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1") trv.BuildTree(dt, "年|月|日|型号") trv.StopRedraw For Each nd As WinForm.TreeNode In trv.AllNodes Dim Year As Integer = nd.DataRow("年") Dim Month As Integer = nd.DataRow("月") Dim day As Integer = nd.DataRow("日") Dim Product As String = nd.DataRow("型号") Select Case nd.Level Case 0 nd.Text = nd.text & "年(投入" & dt.Compute("Sum(投入)","年 = " & Year) & "m,不良率" & Format(dt.Compute("AVG(不良率)","年 = " & Year),"#0.00") & "%)" Case 1 nd.Text = nd.text & "月(投入" & dt.Compute("Sum(投入)","年 = " & Year & " And 月 = " & Month) & "m,不良率" & Format(dt.Compute("AVG(不良率)","年 = " & Year & " And 月 = " & Month),"#0.00") & "%)" Case 2 If nd.DataRow("日期") = fdr("日期") Then trv.SelectedNode = nd nd.ExpandAll End If nd.Text = nd.text & "日(投入" & dt.Compute("Sum(投入)","年 = " & Year & " And 月 = " & Month & " And 日 = " & day) & "m, 不良率" & Format(dt.Compute("AVG(不良率)","年 = " & Year & " And 月 = " & Month & " And 日 = " & day),"#0.00") & "%)" Case 3 nd.Text = nd.text & "(" & nd.DataRow("投入") & "m)" End Select Next trv.Nodes.Insert("显示所有行","显示所有行(" & dt.Compute("Sum(投入)") & "m)",0) trv.ResumeRedraw
|