以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请教老师帮助代码修改  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=110182)

--  作者:wakai
--  发布时间:2017/11/28 14:30:00
--  请教老师帮助代码修改
子表与父表

示例四

假定订单和订单明细表都有一个名为“审核”的列,逻辑型。
当某个订单的所有订单明细全部通过审核后,此订单也自动审核通过,当某订单的任何一个订单明细取消审核后,此订单也自动取消审核。
为此可以将订单明细表的DataColChanged事件代码设置为:

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


上面帮助代码是做了子父表关联的,

请教老师如果两个表不做关联,子表和父表分别如何写


--  作者:有点甜
--  发布时间:2017/11/28 15:07:00
--  
If e.DataCol.name = "审核" Then
    Dim pr As DataRow = DataTables("订单").Find("订单编号 = \'" & e.DataRow("订单编号") & "\'")
    If pr IsNot Nothing Then
        Dim crs As List(of DataRow) = DataTables("订单明细").Select("订单编号 = \'" & e.DataRow("订单编号") & "\'")
        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

--  作者:wakai
--  发布时间:2017/11/29 17:20:00
--  
再请教老师,实现另个功能,订单表的审核列由逻辑改为字符,
如果订单明细全部为ture,订单表审核列显示为“全部审核”
订单明细部分ture,订单表审核列显示为“部分审核”
订单明细全部为flase,订单表审核列显示为“未审核”
要怎么写

--  作者:有点甜
--  发布时间:2017/11/29 17:29:00
--  
If e.DataCol.name = "审核" Then
    Dim pr As DataRow = DataTables("订单").Find("订单编号 = \'" & e.DataRow("订单编号") & "\'")
    If pr IsNot Nothing Then
        Dim crs As List(of DataRow) = DataTables("订单明细").Select("订单编号 = \'" & e.DataRow("订单编号") & "\'")
        Dim cnt As Integer
        For Each cr As DataRow In crs
            If cr("审核") = True
                cnt = cnt + 1
            End If
        Next
        pr("审核") = iif(crs.Count=cnt, "全部审核", iif(cnt=0, "未审核", "部分审核"))
    End If
End If