以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  能否根据目录树复选框的选中状态进行数据筛选?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=6122)

--  作者:czy
--  发布时间:2010/3/9 13:13:00
--  

这个问题有点大了,Nodes是根据目录树的层数级增加的,我不知道动态遍历n层目录树的代码应该怎么写,这是一个难点。
另外如果象上图所示,勾选了pd03再直接跳开Cs01而选择下一层,要动态组合成筛选语句估计这也是个难点。


--  作者:狐狸爸爸
--  发布时间:2010/3/9 13:41:00
--  

如果层级固定,还是好办的,否则要定义函数,使用递归。


--  作者:exonjee
--  发布时间:2010/3/9 13:50:00
--  

楼主提出的的目录树复选框筛选数据很实用,

老大代码怎样实现?请贴个示例


--  作者:czy
--  发布时间:2010/3/9 14:19:00
--  
以下是引用狐狸爸爸在2010-3-9 13:41:00的发言:

如果层级固定,还是好办的,否则要定义函数,使用递归。


嗯,固定层级能实现,不过代码好象比较烦琐,这是我写的遍历三层的测试代码(中间还未判断哪些层级重复,哪些层级缺失)

For i As integer = 0 to tv.Nodes.Count -1
    if tv.Nodes(i).Checked Then
        tvname = tvname & ",\'" & tv.Nodes(i).name & "\'"
    End If
    For n As integer = 0 to tv.Nodes(i).Nodes.Count -1
        if tv.Nodes(i).Nodes(n).Checked Then
            tvname1 = tvname1 & ",\'" & tv.Nodes(i).Nodes(n).name & "\'"
        End If
        For x As integer = 0 to tv.Nodes(i).Nodes(n).Nodes.Count -1
            if tv.Nodes(i).Nodes(n).Nodes(x).Checked Then
                tvname2 = tvname2 & ",\'" & tv.Nodes(i).Nodes(n).Nodes(x).name & "\'"
            End If
        Next
    Next
Next


--  作者:czy
--  发布时间:2010/3/9 14:20:00
--  
老六空时给我们来个示例,或者将你所说的方法写入程序可否?
--  作者:狐狸爸爸
--  发布时间:2010/3/9 14:37:00
--  
呵呵,有空我再试试。
--  作者:mr725
--  发布时间:2010/3/10 18:05:00
--  有条件的筛选合计,再线求高手教我,

借C版5楼代码加工了一下,在命令窗口测试基本可用,还不完善。不分级次,只要打勾了的就筛选(如一级勾选后,下面级次无论是否勾选,都对一级进行筛选)。实例见系统自带例子【目录树.table 自己加复选框】,如有狐友改进或更好的代码,恳请贴上来学习,谢谢!~
Dim tr As WinForm.TreeView
dim f0 as string
dim n1,n11,n10,n01,n222,n220,n202,n200,n002,n022,n020 as string
tr = Forms("主窗口").Controls("TreeView1")
for i as integer = 0 to tr.Nodes.count-1    \'第一级的个数
    Dim l1 As string = tr.Nodes(i).text
    if tr.Nodes(i).checked then
        n1 = n1 & "[产品] = " & "\'" & l1 & "\'" & "§"
        n1 = n1.trim("§") &  " or "
    end if  
   
    for ii as integer = 0 to tr.Nodes(i).Nodes.count-1
        Dim l11 As string = tr.Nodes(i).Nodes(ii).text
        if  tr.Nodes(i).checked and tr.Nodes(i).Nodes(ii).checked = true  then
            n11 = n11 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] = " &  "\'" & l11 & "\'" & "§"
            n11 = n11.trim("§") &  " or "
        end if
        if  tr.Nodes(i).checked and tr.Nodes(i).Nodes(ii).checked = false then
            n10 = n10 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] <> " &  "\'" & l11 & "\'" & "§"
            n10 = n10.trim("§") & " or "
        end if
        if tr.Nodes(i).checked = false and tr.Nodes(i).Nodes(ii).checked = true then
            n01 = n01 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] = " & "\'" & l11 & "\'" & "§"
            n01 = n01.trim("§") &  " or "
        end if
       
        for iii as integer = 0 to tr.Nodes(i).Nodes(ii).Nodes.count-1
            Dim l111 As string = tr.Nodes(i).Nodes(ii).Nodes(iii).text
            if tr.Nodes(i).checked = true and tr.Nodes(i).Nodes(ii).checked = true and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true then
                n222 = n222 & "[产品] = " &  "\'" & l1 & "\'" & " and [客户] = " & "\'" & l11 & "\'" & " and [雇员] = " & "\'" & l111 & "\'" & "§"
                n222 = n222.trim("§") &  " or "
            end if     \'===
            if tr.Nodes(i).checked = true and tr.Nodes(i).Nodes(ii).checked = true and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = false then
                n220 = n220 & "[产品] = " &  "\'" & l1 & "\'" & " and [客户] = " & "\'" & l11 & "\'" & " and [雇员] <> " & "\'" & l111 & "\'" & "§"
                n220 = n220.trim("§") &  " or "
            end if     \'==0
            if tr.Nodes(i).checked and tr.Nodes(i).Nodes(ii).checked = false and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true  then
                n202 = n202 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] <> " & "\'" & l11 & "\'" & " and [雇员] = " & "\'" & l111 & "\'" & "§"
                n202 = n202.trim("§") &  " or "
            end if     \'=0=
            if tr.Nodes(i).checked = true and tr.Nodes(i).Nodes(ii).checked = false and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = false then
                n200 = n200 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] <> " & "\'" & l11 & "\'" & " and [雇员] <> " & "\'" & l111 & "\'" & "§"
                n200 = n200.trim("§") &  " or "
            end if     \'=00
            if tr.Nodes(i).checked = false and tr.Nodes(i).Nodes(ii).checked = false and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true  then
                n002 = n002 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] = " & "\'" & l11 & "\'" & " and [雇员] = " & "\'" & l111 & "\'" & "§"
                n002 = n002.trim("§") &  " or "
            end if   \'===
            if tr.Nodes(i).checked = false and tr.Nodes(i).Nodes(ii).checked = true and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = false then
                n020 = n020 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] = " & "\'" & l11 & "\'" & " and [雇员] <> " & "\'" & l111 & "\'" & "§"
                n020 = n020.trim("§") &  " or "
            end if   \'==0
            if tr.Nodes(i).checked = false and tr.Nodes(i).Nodes(ii).checked = true and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true then
                n022 = n022 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] = " & "\'" & l11 & "\'" & " and [雇员] = " & "\'" & l111 & "\'" & "§"
                n022 = n022.trim("§") &  " or "
            end if     \'===
        next
    next
next
f0 = n1 & n11 & n10 & n01 & n222 & n220 & n202 & n200 & n002 & n020 & n022
if len(f0) >=3   \'其实大于空就行了.
    f0 = left(f0,len(f0)-3)
    Tables("订单").Filter = f0
else
    Tables("订单").Filter = "产品 = \'^_^\'"   \'什么也不显示.
end if

[此贴子已经被作者于2010-3-10 18:19:59编辑过]

--  作者:czy
--  发布时间:2010/3/10 18:29:00
--  
呵呵,这种筛选应该用 In 好一点。
[此贴子已经被作者于2010-3-10 18:29:36编辑过]

--  作者:mr725
--  发布时间:2010/3/10 18:35:00
--  
以下是引用czy在2010-3-10 18:29:00的发言:
呵呵,这种筛选应该用 In 好一点。
[此贴子已经被作者于2010-3-10 18:29:36编辑过]

从没有过,不知道如果表达,只能死板的套用学过的。 呵呵~


--  作者:mr725
--  发布时间:2010/3/10 18:48:00
--  
简化一下: 前面代码很多重复或多余了!~
Dim tr As WinForm.TreeView
dim f0 as string
dim n1,n11,n222 as string
tr = Forms("主窗口").Controls("TreeView1")
for i as integer = 0 to tr.Nodes.count-1    \'第一级的个数
    Dim l1 As string = tr.Nodes(i).text
    if tr.Nodes(i).checked then
        n1 = n1 & "[产品] = " & "\'" & l1 & "\'" & "§"
        n1 = n1.trim("§") &  " or "
    end if  

    for ii as integer = 0 to tr.Nodes(i).Nodes.count-1
        Dim l11 As string = tr.Nodes(i).Nodes(ii).text
        if  tr.Nodes(i).Nodes(ii).checked = true  then
            n11 = n11 & "[产品] = " & "\'" & l1 & "\'" & " and [客户] = " &  "\'" & l11 & "\'" & "§"
            n11 = n11.trim("§") &  " or "
        end if
       
        for iii as integer = 0 to tr.Nodes(i).Nodes(ii).Nodes.count-1
            Dim l111 As string = tr.Nodes(i).Nodes(ii).Nodes(iii).text
            if tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true then
                n222 = n222 & "[产品] = " &  "\'" & l1 & "\'" & " and [客户] = " & "\'" & l11 & "\'" & _
                " and [雇员] = " & "\'" & l111 & "\'" & "§"
                n222 = n222.trim("§") &  " or "
            end if     \'===
        next

    next

next
f0 = n1 & n11 & n222
if len(f0) >=3   \'其实大于空就行了.
    f0 = left(f0,len(f0)-3)
    Tables("订单").Filter = f0
else
    Tables("订单").Filter = "产品 = \'^_^\'"   \'什么也不显示.
end if
[此贴子已经被作者于2010-3-10 18:52:40编辑过]