如下代码
Dim frm As WinForm.Form = Args(0)
Dim cmd As New SQLCommand
cmd.ConnectionName = erp1 ' "基础档案"
Dim tbnm As String = frm.TableName 'tb0.Name ' frm.Name ' & "_Table1" '
cmd.CommandText = "select * from {数据表} where 表名 = '" & tbnm & "'"
Dim dt1 As DataTable = cmd.ExecuteReader
Dim nm As String '筛选列
Dim nms As String()
If dt1.DataRows.Count = 0 Then ' Is Nothing Then
MessageBox.Show("无此""" & tbnm & """数据表")
Return Nothing
Else
Dim dr As DataRow = dt1.DataRows(0)
Dim spc As WinForm.SplitContainer = frm.Controls("SplitContainer1")
Dim btn As WinForm.Button = frm.Controls("Button筛选显示")
If dr("生成目录树的各列_显示") = False Then
spc.Panel1.Collapsed = True
Return Nothing
End If
spc.Panel1.Collapsed = False
Dim trv1 As WinForm.TreeView = frm.Controls("TreeView1")
If trv1.Nodes.Count > 0 Then
End If
nm = dr("生成目录树的各列_设置")
If nm > "" Then
nms = nm.Split("|")
For i As Integer = 0 To nms.Length - 1 ' Each nm1 As String In nms
If nms(i).EndsWith(" YM") Then
Dim nm1s As String() = nms(i).Split(" ")
If DataTables(frm.Name).DataCols.Contains(nm1s(0) & "年") = False Then
DataTables(frm.Name).DataCols.Add(nm1s(0) & "年",Gettype(String),"SubString(Convert([日期],'System.String'),1,4) + '年'") ',SubString([日期],1,4)) 'Year(nm1s(0)))
End If
If DataTables(frm.Name).DataCols.Contains(nm1s(0) & "月") = False Then
DataTables(frm.Name).DataCols.Add(nm1s(0) & "月",Gettype(String),"IIF(SubString(Convert([日期],'System.String'),6,IIF(SubString(Convert([日期],'System.String'),7,1) In ('-','/'),1,2)) > '09',SubString(Convert([日期],'System.String'),6,IIF(SubString(Convert([日期],'System.String'),7,1) In ('-','/'),1,2)),SubString(Convert([日期],'System.String'),7,IIF(SubString(Convert([日期],'System.String'),6,1) In ('-','/'),1,1))) + '月'") ' ,SubString([日期],6,2)) 'Month(nm1s(0)))
End If
Dim nmst As New List(Of String)
nmst.AddRange(nms)
nmst(i) = nm1s(0) & "年"
nmst.Insert(i + 1,nm1s(0) & "月")
nms = nmst.ToArray()
nm = nm.Replace(" YM","年|" & nm1s(0) & "月")
ElseIf nms(i).EndsWith(" YW") Then
Dim nm1s As String() = nms(i).Split(" ")
If DataTables(frm.Name).DataCols.Contains(nm1s(0) & "年") = False Then
DataTables(frm.Name).DataCols.Add(nm1s(0) & "年",Gettype(String),"SubString(Convert([日期],'System.String'),1,4) + '年'") ',SubString([日期],1,4)) 'Year(nm1s(0)))
End If
If DataTables(frm.Name).DataCols.Contains(nm1s(0) & "周") = False Then
MessageBox.Show("这里怎么写周的表达式?" & vbcrlf & "请修改内部函数treeview")
DataTables(frm.Name).DataCols.Add(nm1s(0) & "周",Gettype(String))
For Each mdr As DataRow In DataTables(frm.Name).DataRows
mdr(nm1s(0) & "周") = DatePart("ww", mdr("日期"))
Next
Else
For Each mdr As DataRow In DataTables(frm.Name).DataRows
mdr(nm1s(0) & "周") = Format(DatePart("ww", mdr("日期")), "00") & "周"
Next
End If
nm = nm.Replace(nms(i), nm1s(0) & "年|" & nm1s(0) & "周")
End If
Next
btn.Text = "关闭"
Else
MessageBox.Show("请设置筛选列")
Return Nothing
End If
End If
Dim txtsz As WinForm.TextBox = frm.Controls("TextBox设置")
txtsz.Value = nm
cmd.ConnectionName = erp2 ' "收发明细"
If frm.Opened = False Then
frm.Open
End If
Dim tbl As WinForm.Table = frm.Controls("Table1")
Dim tb As Table = tbl.Table
Dim dt As DataTable = tb.DataTable ' Tables(frm.Name & "_Table1").DataTable
Dim trv As WinForm.TreeView = frm.Controls("TreeView1")
trv.BuildTree(dt, nm) ' "年|月|材料名称|规格型号")
trv.StopRedraw
nms = nm.Split("|")
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属性nd.Level
Filter = nms(0) & " = '" & Value(0) & "'"
For i As Integer = 1 To nd.Level
Filter = Filter & " And " & nms(i) & " = '" & Value(i) & "'"
Next
nd.Text = nd.text & "(" & dt.Compute("Count(单号)",Filter) & "条)"
Next
If trv.AllNodes.Count > 0 Then
trv.Nodes.Insert("显示所有行",0)
trv.Nodes(0).Text = trv.Nodes(0).Text & "(" & dt.Compute("Count(单号)") & "条)"
trv.Nodes(0).Checked = True
tb.Filter = ""
End If
trv.ResumeRedraw
tbl.Select()