Dim d1 As Date = CDate(e.Form.controls("TextBox1").text & "-1-1")
Dim d2 As Date = CDate(e.Form.controls("TextBox1").text & "-12-31")
Dim dt As DataTable
Dim b As New SQLGroupTableBuilder("统计表1", "EI")
b.Groups.AddDef("人员类别")
b.Groups.AddDef("人员状态")
b.Totals.AddDef("_Identify", AggregateEnum.Count, "人数")
b.filter = "离开单位日期>=#" & d1 & "# and 进入单位日期<=#" & d2 & "#"
dt = b.Build()
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dt, "人员类别|人员状态")
trv.StopRedraw
For Each nd As WinForm.TreeNode In trv.AllNodes
Dim lb1 As String = nd.DataRow("人员类别")
Dim zt As String = nd.DataRow("人员状态")
Select Case nd.Level
Case 0
nd.Text = nd.text & "(" & dt.Compute("Sum(人数)", "人员类别 = '" & lb1 & "'") & "人)"
Case 1
nd.Text = nd.text & "(" & dt.Compute("Sum(人数)", "人员类别 = '" & lb1 & "' And 人员状态 = '" & zt & "'") & "人)"
Case 2
nd.Text = nd.text & "(" & nd.DataRow("人数") & ")"
End Select
Next
trv.Nodes.Insert("加载所有行", "加载所有行(" & dt.Compute("Sum(人数)") & "人)", 0)
trv.ResumeRedraw
Dim lvw As WinForm.ListView
lvw = e.Form.CreateControl("ListView1", ControlTypeEnum.ListView)
lvw.StopRedraw()
lvw.Groups.Clear()
lvw.Columns.Clear()
lvw.Rows.Clear()
lvw.Images.Clear()
lvw.Dock = System.Windows.Forms.DockStyle.Fill
lvw.View = ViewMode.Details
lvw.TitleSize = New Size(130, 80)
lvw.GridLines = True
lvw.AllowDrag = True
lvw.Images.AddImage("Man", "Man.ico", "Man48.ico")
lvw.Images.AddImage("Woman", "Woman.ico", "Woman48.ico")
e.Form.Controls("SplitContainer1").Panel2.AddControl(lvw)
Dim cls() As String = {"姓名", "人员类别", "进入单位日期", "离开单位日期", "人员状态"}
For i As Integer = 0 To cls.Length - 1
Dim c As WinForm.ListViewColumn = lvw.Columns.Add()
c.Name = cls(i)
c.Text = cls(i)
c.TextAlign = HorizontalAlignment.Center
Next
For Each lb As String In DataTables("EI").GetValues("人员类别")
Dim grp As WinForm.ListViewGroup = lvw.Groups.Add()
grp.Name = lb
grp.Text = lb
Next
For Each dr As DataRow In DataTables("EI").DataRows
Dim r As WinForm.ListViewRow = lvw.Rows.Add()
r.Group = dr("人员类别")
For Each cl As String In cls
r(cl) = dr(cl)
Next
If dr("性别") = "男" Then
r.ImageKey = "Man"
Else
r.ImageKey = "Woman"
End If
r.Tag = dr
Next
For Each c As WinForm.ListViewColumn In lvw.Columns
c.AutoResize
Next
lvw.ShowGroups = False
lvw.ResumeRedraw()