以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- 如 id=1 就去找foid中等于1的数据 然后对应获取到id=2,3,4 然后又以id=2,3,4去找foid=5,6,7 然后又以foid=5,6,7去找id=……一直循环 怎么操作呢? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=179787)
|
-- 作者:cnsjroom
-- 发布时间:2022/9/8 19:36:00
-- 如 id=1 就去找foid中等于1的数据 然后对应获取到id=2,3,4 然后又以id=2,3,4去找foid=5,6,7 然后又以foid=5,6,7去找id=……一直循环 怎么操作呢?
b如何实现先根据sys_Navigation表中的不重复值id来去依次在id foid两个字段中去实现顺序遍历呢?
实现数据的节点依次找到末尾
如 id=1 就去找foid中等于1的数据 然后对应获取到id=2,3,4 然后又以id=2,3,4去找foid=5,6,7 然后又以foid=5,6,7去找id=……一直循环 每找到一次就作为一个节点 并将对应的name依次显示为第一节 第二节 第三节 第四节
此主题相关图片如下:123.png
当前代码如下:【没有完整达到预期】
If DataTables.Contains("测试表") Then \'如果表C已经加载 DataTables.Unload("测试表") \'卸载表C End If Dim cmd As New SQLCommand Dim dt As DataTable cmd.C cmd.CommandText = "Sele ct * From sys_Navigation" dt = cmd.ExecuteReader() Dim id1,id2,id3,id4 As String Dim dtb As New DataTableBuilder("测试表") dtb.AddDef("第一节", Gettype(String), 32) dtb.AddDef("第二节", Gettype(String), 32) dtb.AddDef("第三节", Gettype(String), 32) dtb.AddDef("第四节", Gettype(String), 32) dtb.AddDef("窗体id", Gettype(String), 32) dtb.AddDef("导航名", Gettype(String), 32) dtb.Build() Dim Products As List(Of String()) Products = dt.sqlGetValues("ID|Name","FaID is null") \'获取第一级节点 For Each Product As String() In Products Dim Products1 As List(Of String()) Products1 = dt.sqlGetValues("ID|Name","FaID =\'" & Product(0) & "\'") \'获取第二级节点 For Each Product1 As String() In Products1 Dim Products11 As List(Of String()) Products11 = dt.sqlGetValues("ID|Name","FaID =\'" & Product1(0) & "\'") \'获取第三级节点 For Each Product11 As String() In Products11 Dim Products12 As List(Of String()) Products12 = dt.sqlGetValues("ID|Name|formid","ID =\'" & Product11(0) & "\'") \'获取第四级节点 For Each Product12 As String() In Products12 Dim Products13 As List(Of String()) Products13 = dt.sqlGetValues("ID|Name|formid","faID =\'" & Product12(0) & "\'") For Each Product13 As String() In Products13 Dim dr1 As DataRow = DataTables("测试表").AddNew() dr1("第一节") = Product(1) dr1("第二节") = Product1(1) dr1("第三节") = Product11(1) If Product12(1).Contains("谈话通知书") Or Product12(1).Contains("询问通知书") Or Product12(1).Contains("讯问通知书") Then dr1("第四节") = Product13(1) output.show(Product13(1) & Product13(0)) Else dr1("第四节") = Product12(1) End If dr1("窗体id") = Product13(2) dr1("导航名") = Product1(1) Next Next Next Next Next MainTable=Tables("测试表")
[此贴子已经被作者于2022/9/8 19:42:12编辑过]
|
-- 作者:z769036165
-- 发布时间:2022/9/8 19:47:00
--
用自定义函数,做递归查询,帮助有递归的案列
|
-- 作者:有点蓝
-- 发布时间:2022/9/8 20:29:00
--
参考:http://www.foxtable.com/webhelp/topics/2416.htm
|
-- 作者:cnsjroom
-- 发布时间:2022/9/8 21:18:00
-- 回复:(有点蓝)参考:http://www.foxtable.com/webh...
还是不得要领 老师可以帮忙具体指导一下不呢 谢谢!
我这里不需要生成目录树 主要是生成表
|
-- 作者:cnsjroom
-- 发布时间:2022/9/8 21:18:00
-- 回复:(z769036165)用自定义函数,做递归查询,帮助...
没有看明白帮助列子 只看明白了函数自己调用自己 叫递归函数
还是不得要领 老师可以帮忙具体指导一下不呢 谢谢!
我这里不需要生成目录树 主要是生成表
|
-- 作者:有点蓝
-- 发布时间:2022/9/8 21:55:00
--
设计步骤: 1、在内部函数中新建一个函数,名为AddChildren,代码为: Dim dr1 as datarow = args(0) Dim faIDpath As string = args(1) Dim dt As DataTable = args(2) Dim drs As List(of DataRow) drs = dt.Select("faID =\'" & dr1("ID") & "\'") if drs.count = 0 then Dim dr2 As DataRow = DataTables("测试表").AddNew() dim sr() as string = faIDpath.split(".") for i as integer = 0 to sr.length - 1 dr2("第" & (i+1) & "节") = sr(i) dr2("窗体id") = dr2("id") dr2("导航名") = dr2("name")next else For Each dr As DataRow In drs Functions.Execute("AddChildren",dr("ID"),faIDpath & "." & dr("ID"),dt) Next end if
按钮 If DataTables.Contains("测试表") Then \'如果表C已经加载 DataTables.Unload("测试表") \'卸载表C End If Dim cmd As New SQLCommand Dim dt As DataTable cmd.C cmd.CommandText = "Sele ct * From sys_Navigation" dt = cmd.ExecuteReader()
Dim dtb As New DataTableBuilder("测试表") dtb.AddDef("第1节", Gettype(String), 32) dtb.AddDef("第2节", Gettype(String), 32) dtb.AddDef("第3节", Gettype(String), 32) dtb.AddDef("第4节", Gettype(String), 32) dtb.AddDef("窗体id", Gettype(String), 32) dtb.AddDef("导航名", Gettype(String), 32) dtb.Build() Dim drs As List(of DataRow) drs = dt.Select("faID is null") For Each dr As DataRow In drs Functions.Execute("AddChildren",dr("ID"),dr("ID"),dt) Next
|
-- 作者:cnsjroom
-- 发布时间:2022/9/8 23:40:00
-- 回复:(有点蓝)设计步骤:1、在内部函数中新建一个函...
谢谢老师的耐心指导
当前已经实现如下测试表数据,但还有几个问题需要老师指导下!
1、怎么实现在当前第1、2、3、4、5节中有值的情况下,同步完成第1、2、3、4、5节名称字段的值得填充
(根据第1、2、3、4、5节中的值 去sys navigation中id=第1、23、4、5节值符合条件的数据行 获取name的值)
2、第2、3、4、5节不一定有值,如果没有值 那窗口id就等于上一节的值对应到sys navgation中去查找id符合条件的值 中的formid
3、第2、3、4、5节不一定有值,如果没有值 那导航名就等于上一节的值对应到sys navgation中去查找id符合条件的值 中的name
效果图:
此主题相关图片如下:222.png
按钮执行代码:
If DataTables.Contains("测试表") Then \'如果表已经加载 DataTables.Unload("测试表") \'卸载表 End If Dim cmd As New SQLCommand Dim dt As DataTable cmd.Conne cti cmd.CommandText = "Se le ct * From sys_Navigation" dt = cmd.ExecuteReader()
Dim dtb As New DataTableBuilder("测试表") dtb.AddDef("第1节", Gettype(String), 64) dtb.AddDef("第1节名称", Gettype(String), 64) dtb.AddDef("第2节", Gettype(String), 64) dtb.AddDef("第2节名称", Gettype(String), 64) dtb.AddDef("第3节", Gettype(String), 64) dtb.AddDef("第3节名称", Gettype(String), 64) dtb.AddDef("第4节", Gettype(String), 64) dtb.AddDef("第4节名称", Gettype(String), 64) dtb.AddDef("第5节", Gettype(String), 64) dtb.AddDef("第5节名称", Gettype(String), 64) dtb.AddDef("窗体id", Gettype(String), 64) dtb.AddDef("导航名", Gettype(String), 64) dtb.Build()
Dim drs As List(of DataRow) drs = dt.Select("faID is null")
For Each dr As DataRow In drs Functions.Execute("AddChildren",dr("ID"),dr("ID"),dt)
Next
MainTable=Tables("测试表")
内部函数代码如下:【红色部分代码怎么修正才能实现上述123功能点呢?】
Dim dr1 As String = args(0) Dim faIDpath As String = args(1) Dim dt As DataTable = args(2)
Dim dt1 As DataTable Dim cmd As New SQ LCommand cmd.Conn ectionN ame = "主数据源"
cmd.Comma ndText = "Sel ect * Fr om sys_Navigation" dt1 = cmd.ExecuteReader() Dim drs As List(of DataRow) drs = dt.S elect("faID =\'" & dr1 & "\'")
If drs.count = 0 Then Dim dr2 As DataRow = DataTables("测试表").AddNew() Dim sr() As String = faIDpath.split(".") For i As Integer = 0 To sr.length - 1 dr2("第" & (i+1) & "节") = sr(i) If sr(i)<>"" Then Dim Products As List(Of String()) Products = dt.sqlGetValues("formID|Name","FaID =\'" & sr(i) & "\'") For Each Product As String() In Products \'dr2("窗体id") = dr2("窗体id") \'dr2("导航名") = dr2("name") dr2("窗体id") = Products(0) dr2("导航名") = Products(1) Next End If Next Else For Each dr As DataRow In drs Functions.Execute("AddChildren",dr("ID"),faIDpath & "." & dr("ID"),dt) Next End If
[此贴子已经被作者于2022/9/9 1:47:43编辑过]
|
-- 作者:有点蓝
-- 发布时间:2022/9/9 8:43:00
--
dtb.Build() Dim drs As List(of DataRow) drs = dt.Select("faID is null") For Each dr As DataRow In drs Functions.Execute("AddChildren",dr ,dr("ID"),dt) Next MainTable=Tables("测试表")
内部函数代码如下: Dim dr1 As DataRow = args(0) Dim faIDpath As String = args(1) Dim dt As DataTable = args(2)
Dim drs As List(of DataRow) drs = dt.S elect("faID =\'" & dr1("ID") & "\'") If drs.count = 0 Then Dim dr2 As DataRow = DataTables("测试表").AddNew() Dim sr() As String = faIDpath.split(".") For i As Integer = 0 To sr.length - 1 dr2("第" & (i+1) & "节") = sr(i) Next dr2("窗体id") = dr1("窗体id") dr2("导航名") = dr1("name") Else For Each dr As DataRow In drs Functions.Execute("AddChildren",dr,faIDpath & "." & dr("ID"),dt) Next End If
|
|
-- 作者:cnsjroom
-- 发布时间:2022/9/9 9:17:00
-- 回复:(有点蓝)dtb.Build()Dim drs As List(of Data...
老师在你的指导下 现在是"第" & (i+1) & "节名称") 无法根据第" & (i+1) & "节")的内容获取列名,下述红色部分代码怎么修正呢?
当前代码如下:
Dim dr1 As DataRow = args(0) Dim faIDpath As String = args(1) Dim dt As DataTable = args(2)
Dim dt1 As DataTable Dim cmd As New SQLCommand cmd.C cmd.CommandText = "Se lect * From sys_Navigation" dt1 = cmd.ExecuteReader()
Dim drs As List(of DataRow) drs = dt.Select("faID =\'" & dr1("ID") & "\'")
If drs.count = 0 Then Dim dr2 As DataRow = DataTables("测试表").AddNew() Dim sr() As String = faIDpath.split(".") For i As Integer = 0 To sr.length - 1 dr2("第" & (i+1) & "节") = sr(i) \'Dim Products As List(Of String()) \'Products = dt1.sqlGetValues("Name","ID =\'" & sr(i) & "\'") \'For Each Product As String() In Products \'dr2("第" & (i+1) & "节名称") = Product \'Next Next dr2("窗体id") = dr1("formid") dr2("导航名") = dr1("name") Else For Each dr As DataRow In drs Functions.Execute("AddChildren",dr,faIDpath & "." & dr("ID"),dt) Next End If
|
-- 作者:有点蓝
-- 发布时间:2022/9/9 9:37:00
--
第一段红色代码去掉,不需要多次一举,在函数里有又查一次表格,表格已经在按钮里查询,然后传入函数就可以使用了,不然调用函数100次,要查100次数据库?是觉得程序太快了,要减慢速度运行吗!!
名称和faIDpath参数用法一样,合并传入函数使用即可
|