类似代码
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "SELECT DISTINCT 合同年月,客户简称,合同ID,生产ID,作业ID,工piao编号 From {工piao信息}"
dt = cmd.ExecuteReader()
Dim trv As WinForm.TreeView = Forms("工piao管理").Controls("TreeView1")
trv.BuildTree(dt,"合同年月|客户简称|合同ID|生产ID|作业ID|工piao编号","","")
trv.Nodes.Insert("作业计划合计",0)
For Each nd As WinForm.TreeNode In trv.AllNodes
Select Case nd.Level
Case 0
If nd.Name = "作业计划合计" Then
Dim n0 As Integer = DataTables("工piao信息").GetValues("作业ID").Count
Dim n1 As Integer = DataTables("工piao信息").Compute("Count(工piaoID)") '工piao数
Dim n2 As Integer = DataTables("工piao信息").Compute("Count(工piao编号)","Len(工piaoID) = 8") '绑定数
Dim n3 As Integer = DataTables("工piao信息").Compute("Count(工piao编号)","iif(len(工piaoID) > 3, Substring(工piaoID, Len(工piaoID)-2, 3) = '已回收', false)") '回收数
nd.text = nd.Name & "("& n0 &"/"& n1 &"/"& n2 &"/"& n3 &")"
Else
Dim filter As String = "合同年月 = '" & nd.Name & "'"
Dim n0 As Integer = DataTables("工piao信息").GetValues("作业ID", filter).Count
Dim n1 As Integer = DataTables("工piao信息").Compute("Count(工piaoID)", filter) '工piao数
Dim n2 As Integer = DataTables("工piao信息").Compute("Count(工piao编号)","Len(工piaoID) = 8 and " & filter) '绑定数
Dim n3 As Integer = DataTables("工piao信息").Compute("Count(工piao编号)","iif(len(工piaoID) > 3, Substring(工piaoID, Len(工piaoID)-2, 3) = '已回收', false) and " & filter) '回收数
nd.text = nd.Name & "("& n0 &"/"& n1 &"/"& n2 &"/"& n3 &")"
End If
Case 1
Dim ary() As String = nd.FullName.Split("\")
Dim filter As String = "合同年月 = '" & ary(0) & "' and 客户简称 = '" & ary(1) & "'"
Dim n0 As Integer = DataTables("工piao信息").GetValues("作业ID", filter).Count
Dim n1 As Integer = DataTables("工piao信息").Compute("Count(工piaoID)", filter) '工piao数
Dim n2 As Integer = DataTables("工piao信息").Compute("Count(工piao编号)","Len(工piaoID) = 8 and " & filter) '绑定数
Dim n3 As Integer = DataTables("工piao信息").Compute("Count(工piao编号)","iif(len(工piaoID) > 3, Substring(工piaoID, Len(工piaoID)-2, 3) = '已回收', false) and " & filter) '回收数
nd.text = nd.Name & "("& n0 &"/"& n1 &"/"& n2 &"/"& n3 &")"
End Select
Next