项目重新打开就出现 未将对象引用设置到对象的实例
'首先生成统计表
Dim dt As DataTable
Dim b As New GroupTableBuilder("统计表1",DataTables("涂胶检验"))
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 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
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
-----------------------------------------------------------------------------------
Dim Filter As String = ""
If e.node.Name <> "显示所有行" Then '要用Name属性,不能用Text属性
Dim d1 As Date
Dim d2 As Date
Dim d3 As Date
Dim Year As Integer = e.Node.DataRow("年")
Dim Month As Integer = e.Node.DataRow("月")
Dim day As Integer = e.Node.DataRow("日")
Dim Product As String = e.Node.DataRow("型号")
Select Case e.Node.Level
Case 0
d1 = New Date(Year,1,1) '取得该年的第一天
d2 = new Date(Year,12,31) '取得该年的最后一天
Filter = "日期 >= #" & d1 & "# And 日期 <= #" & d2 & "#"
Case 1
d1 = New Date(Year, Month, 1) '取得该月的第一天
d2 = new Date(Year, Month, Date.DaysInMonth(Year,Month)) '取得该月的最后一天
Filter = "日期 >= #" & d1 & "# And 日期 <= #" & d2 & "#"
Case 2
d1 = New Date(Year, Month, day)
Filter = "日期 >= #" & d1 & "# And 日期 < #" & d1.AddDays(1) & "#"
Case 3
d1 = New Date(Year, Month, day)
Filter = "日期 >= #" & d1 & "# And 日期 < #" & d1.AddDays(1) & "# And 型号 = '" & Product & "'"
End Select
End If
Tables("涂胶检验").Filter = Filter