Dim cmd As new SQLCommand
cmd.CommandText = "Select Masseur_Name As 姓名,Date①_Date As 日期, year(Date①_Date) As 年, month(Date①_Date) As 月, day(Date①_Date) As 日, 1 As 开单 from {Information} where Masseur_Name Is not null " _
& " union Select Masseur_Name,Date②_Date, year(Date②_Date), month(Date②_Date) As 月, day(Date②_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date③_Date, year(Date③_Date), month(Date③_Date) As 月, day(Date③_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date④_Date, year(Date④_Date), month(Date④_Date) As 月, day(Date④_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑤_Date, year(Date⑤_Date), month(Date⑤_Date) As 月, day(Date⑤_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑥_Date, year(Date⑥_Date), month(Date⑥_Date) As 月, day(Date⑥_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑦_Date, year(Date⑦_Date), month(Date⑦_Date) As 月, day(Date⑦_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑧_Date, year(Date⑧_Date), month(Date⑧_Date) As 月, day(Date⑧_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑨_Date, year(Date⑨_Date), month(Date⑨_Date) As 月, day(Date⑨_Date), 1 from {Information} where Masseur_Name Is not null" _
& " union Select Masseur_Name,Date⑩_Date, year(Date⑩_Date), month(Date⑩_Date) As 月, day(Date⑩_Date), 1 from {Information} where Masseur_Name Is not null"
Dim dt As DataTable = cmd.ExecuteReader
For Each ary As String() In dt.GetValues("姓名|年", "年 is not null")
For i As Integer = 1 To 12
For j As Integer = 1 To Date.DaysInMonth(ary(1),i)
Dim d As Date = new Date(ary(1), i, j)
Dim fdr As DataRow = dt.Find("姓名 = '" & ary(0) & "' and 日期 = #" & d & "#")
If fdr Is Nothing Then
fdr = dt.AddNew
fdr("姓名") = ary(0)
fdr("日期") = d
fdr("年") = ary(1)
fdr("月") = i
fdr("日") = j
fdr("开单") = 0
End If
Next
Next
Next
Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
tv.BuildTree(dt, "姓名|年|月|日")
For Each nd As WinForm.TreeNode In tv.AllNodes
Select Case nd.Level
Case 0
nd.Text = nd.Text & "(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1") & "张)"
Case 1
nd.Text = nd.Text & "年(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "'") & "张)"
Case 2
nd.Text = nd.Text & "月(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "'") & "张)"
Case 3
nd.Text = nd.DataRow("月") & "月" & nd.Text & "日(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "' and 日 = '" & nd.DataRow("日") & "'") & "张)"
End Select
Next