以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  删除行记录更新表数据  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=125889)

--  作者:yetle
--  发布时间:2018/10/9 11:12:00
--  删除行记录更新表数据
保存按钮更新了dr的可申领数:

If Forms("领料申请").opened
For Each dr2 As DataRow In DataTables("领料申请明细").Select("[领料申请单号] = \'" & Tables("领料申请_table1").current("领料申请单号")  & "\'")
    For Each dr As DataRow In DataTables("物检入库明细表").Select("[物料ID] = \'" & dr2("物料ID")  & "\'")
        dr("可申领数") = dr("需求数") - DataTables("领料申请明细").Compute("Sum(申请数)", "[物料ID] = \'" & dr2("物料ID")  & "\' and [审核] = \'true\'")
        dr.save()
    Next
Next
End If

删除按钮代码:(在删除行记录的时候,因为申请数会删掉,当前行对应的物检入库明细表的可申领数也需要更新,代码怎么写?)
If Tables("领料申请_table2").Current IsNot Nothing Then
        If Tables("领料申请_table2").TopPosition>-1 Then
            For  i As Integer=Tables("领料申请_table2").BottomPosition To Tables("领料申请_table2").TopPosition Step -1
                Tables("领料申请_table2").Rows(i).Delete()
            Next
        End If
End If


领料申请_table2绑定的是领料申请明细表



--  作者:有点甜
--  发布时间:2018/10/9 11:40:00
--  

重新计算一次不就好了?

 

If Tables("领料申请_table2").Current IsNot Nothing Then
    If Tables("领料申请_table2").TopPosition>-1 Then
        For  i As Integer=Tables("领料申请_table2").BottomPosition To Tables("领料申请_table2").TopPosition Step -1
            Dim dr2 = Tables("领料申请_table2").Rows(i)
           
            For Each dr As DataRow In DataTables("物检入库明细表").Select("[物料ID] = \'" & dr2("物料ID")  & "\'")
                dr("可申领数") = dr("需求数") - DataTables("领料申请明细").Compute("Sum(申请数)", "[物料ID] = \'" & dr2("物料ID")  & "\' and [审核] = \'true\'") + dr2("申请数")
                dr.save()
            Next
            dr2.delete
        Next
    End If
End If