Dim cmd As New SQLCommand Dim dt As DataTable cmd.CommandText = "Select 所在园区, Year(盘点日期) As 年, Month(盘点日期) As 月, Count([_Identify]) As 订单数 FROM {盘点明细} Group By 所在园区, Year(盘点日期), Month(盘点日期) HAVING 所在园区 = '物流中心总部' " dt = cmd.ExecuteReader() Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1") trv.BuildTree(dt, "年|月") trv.StopRedraw For Each nd As WinForm.TreeNode In trv.AllNodes Dim Value()As String Dim Filter As String Dim d1 As Date Dim d2 As Date Value = nd.FullName.Split("\") '注意这里用FullName属性,不能用FullPath属性 Select Case nd.Level Case 0 nd.text = nd.text & "年" Filter = "年 = " & value(0) Case 1 nd.text = nd.text & "月" Filter = "年 = " & value(0) & " And 月 = " & value(1) End Select nd.Text = nd.text & "(" & dt.Compute("Sum(订单数)",Filter) & "条)" Next trv.Nodes.Insert("加载所有行","加载所有行(" & dt.Compute("Sum(订单数)") & "条)",0) trv.ResumeRedraw
|