以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  程序理解问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=190353)

--  作者:侠客1985
--  发布时间:2024/2/2 18:45:00
--  程序理解问题
老师在帮助文档“事件中的父表与子表”实例4

If e.DataCol.name = "审核" Then
    Dim pr As DataRow = e.DataRow.GetParentRow("
订单")
    If pr IsNot Nothing Then
        Dim crs As List(of DataRow) = pr.GetChildRows("
订单明细")
        Dim cnt As Integer
        For Each cr As DataRow In crs
            If cr("
审核") = True
                cnt = cnt + 1
            End If
        Next
        pr("
审核") = (crs.Count = cnt)
    End If
End
If

例子中: pr("审核") = (crs.Count = cnt) 表示什么意思啊,程序看得不太懂?

--  作者:有点蓝
--  发布时间:2024/2/3 8:41:00
--  
crs来自【Dim crs As List(of DataRow) = pr.GetChildRows("订单明细")】,GetChildRows表示子表的关联行,那么【crs.Count】就是所有子表关联行的行数,cnt来自【 If cr("审核") = True cnt = cnt + 1】,表示勾选了审核的行数,如果【crs.Count = cnt】,那么结果就是true,就表示所有子表关联行都已经审核,那么父表的审核也应该勾选

换种方式写代码,可能会清晰一点

dim 全部审核 as boolean
if crs.Count = cnt then
全部审核=true
else
全部审核=false
end if
pr("审核") = 全部审核

[此贴子已经被作者于2024/2/3 8:40:54编辑过]