以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]子表计算  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=96539)

--  作者:yupeng
--  发布时间:2017/2/22 22:19:00
--  [求助]子表计算

老师 您好

 

   我想达到以下效果,请问要怎样弄,是在表事件还是在窗口保存时写代码。

 

  当子表的“日期”列有值时,判断所有的子表行“日期”列是否都有值,如果有找出最晚的日期,把此日期赋值给父表当前行的“日期”列。

 

子表的日期是代码生成的,并非手工输入。

 

谢谢了

[此贴子已经被作者于2017/2/23 0:06:36编辑过]

--  作者:有点色
--  发布时间:2017/2/23 1:55: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
        Dim maxDate As Date
        For Each cr As DataRow In crs
            If cr.IsNull("日期") Then
                Exit For
            End If
            If maxDate < cr("日期") Then maxDate = cr("日期")
            cnt = cnt + 1
           
        Next
        If crs.Count = cnt Then
            pr("日期") = maxDate
        Else
            pr("日期") = Nothing
        End If
    End If
End If