以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  明细表汇总数据到汇总表编码问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=92635)

--  作者:feixianzhi
--  发布时间:2016/11/9 10:28:00
--  明细表汇总数据到汇总表编码问题

\'按发票录入自动汇总到发票录入汇总表中
Select Case e.DataCol.Name
    Case "无税金额","供应商名称","会计年月","发票号","开票日期"
        
        If e.DataRow.IsNull("供应商名称") OrElse e.DataRow.IsNull("会计年月") OrElse e.DataRow.IsNull("发票号") OrElse e.DataRow.IsNull("开票日期")  Then
        Else
            Dim filter As String = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.DataRow("供应商名称"),e.DataRow("会计年月"),e.DataRow("发票号"),e.DataRow("开票日期"))
            Dim dr2 As DataRow = DataTables("发票录入汇总").Find(filter)
            If dr2 Is Nothing Then
                dr2 = DataTables("发票录入汇总").AddNew()
                dr2("供应商名称") = e.DataRow("供应商名称")
                dr2("会计年月") = e.DataRow("会计年月")
                dr2("发票号") = e.DataRow("发票号")
                dr2("开票日期") = e.DataRow("开票日期")
            End If
            dr2("发票金额") = e.DataTable.Compute("sum(合计金额)",filter)
        End If
End Select

以上代码能实现,在发票录入表录入一条数据,能够汇总到发票汇总中。
但我想实现,如果发票录入表某个数据或全部数据清空,则发票汇总表中的相关数据也同时清空,编码怎么改。请各位老师帮忙。




--  作者:feixianzhi
--  发布时间:2016/11/9 10:59:00
--  
请有点蓝老师帮忙呀。
--  作者:有点蓝
--  发布时间:2016/11/9 11:21:00
--  
多个列关联的比较麻烦

Select Case e.DataCol.Name
    Case "无税金额","供应商名称","会计年月","发票号","开票日期"
        
        Dim filter As String
        If e.DataRow.IsNull("供应商名称") OrElse e.DataRow.IsNull("会计年月") OrElse e.DataRow.IsNull("发票号") OrElse e.DataRow.IsNull("开票日期")  Then
            Select Case e.DataCol.Name
                Case "供应商名称"
                    filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.OldValue ,e.DataRow("会计年月"),e.DataRow("发票号"),e.DataRow("开票日期"))
                Case "会计年月"
                    filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.DataRow("供应商名称"),e.OldValue ,e.DataRow("发票号"),e.DataRow("开票日期"))
                    
                Case "发票号"
                    其它列自己仿照改改
                Case "开票日期"
                    其它列自己仿照改改

            End Select
            Dim dr As DataRow = DataTables("发票录入汇总").Find(filter)
            If dr IsNot Nothing Then dr.Delete
            Else
                filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.DataRow("供应商名称"),e.DataRow("会计年月"),e.DataRow("发票号"),e.DataRow("开票日期"))
                Dim dr2 As DataRow = DataTables("发票录入汇总").Find(filter)
                If dr2 Is Nothing Then
                    dr2 = DataTables("发票录入汇总").AddNew()
                    dr2("供应商名称") = e.DataRow("供应商名称")
                    dr2("会计年月") = e.DataRow("会计年月")
                    dr2("发票号") = e.DataRow("发票号")
                    dr2("开票日期") = e.DataRow("开票日期")
                End If
                dr2("发票金额") = e.DataTable.Compute("sum(合计金额)",filter)
            End If
    End Select

--  作者:feixianzhi
--  发布时间:2016/11/9 13:56:00
--  
\'按发票录入自动汇总到发票录入汇总表中
Select Case e.DataCol.Name
    Case "无税金额","供应商名称","会计年月","发票号","开票日期"
        
        Dim filter As String
        If e.DataRow.IsNull("供应商名称") OrElse e.DataRow.IsNull("会计年月") OrElse e.DataRow.IsNull("发票号") OrElse e.DataRow.IsNull("开票日期")  Then
            Select Case e.DataCol.Name
                Case "供应商名称"
                    filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.OldValue ,e.DataRow("会计年月"),e.DataRow("发票号"),e.DataRow("开票日期"))
                Case "会计年月"
                    filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.DataRow("供应商名称"),e.OldValue ,e.DataRow("发票号"),e.DataRow("开票日期"))
                    
                Case "发票号"
                    filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.DataRow("供应商名称") ,e.DataRow("发票号"),e.OldValue,e.DataRow("开票日期"))
                    
                Case "开票日期"
                    filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.DataRow("供应商名称") ,e.DataRow("发票号"),e.DataRow("开票日期"),e.OldValue)
                    
            End Select
            Dim dr2 As DataRow = DataTables("发票录入汇总").Find(filter)
            If dr2 IsNot Nothing Then dr.Delete
        Else
            filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.DataRow("供应商名称"),e.DataRow("会计年月"),e.DataRow("发票号"),e.DataRow("开票日期"))
            Dim dr2 As DataRow = DataTables("发票录入汇总").Find(filter)
            If dr2 Is Nothing Then
                dr2 = DataTables("发票录入汇总").AddNew()
                dr2("供应商名称") = e.DataRow("供应商名称")
                dr2("会计年月") = e.DataRow("会计年月")
                dr2("发票号") = e.DataRow("发票号")
                dr2("开票日期") = e.DataRow("开票日期")
            End If
            dr2("发票金额") = e.DataTable.Compute("sum(合计金额)",filter)
        End If
End Select

有点蓝老师,代码我改了,但还是实现不了,删除明细表的行,汇总表里相对应的也删除。我不知道是哪出了问题。


--  作者:有点蓝
--  发布时间:2016/11/9 14:16:00
--  
你是要删除还是不要删除?
--  作者:feixianzhi
--  发布时间:2016/11/9 15:27:00
--  
有点蓝老师,您好。我的想法是:明细表录入的时候,汇总表按要求汇总。明细表删除的时候,汇总表里的相对应数据一并删除。
--  作者:有点蓝
--  发布时间:2016/11/9 15:32:00
--  
DataRowDeleting事件

dim filter = CExp("供应商名称 =\'{0}\' and 会计年月=\'{1}\' and 发票号=\'{2}\' and 开票日期=\'{3}\'",e.DataRow("供应商名称"),e.DataRow("会计年月"),e.DataRow("发票号"),e.DataRow("开票日期"))
            Dim dr2 As DataRow = DataTables("发票录入汇总").Find(filter)
If dr2 IsNot Nothing Then dr2.Delete

--  作者:feixianzhi
--  发布时间:2016/11/9 22:28:00
--  
非常感谢有点蓝老师。
--  作者:feixianzhi
--  发布时间:2016/11/10 7:50:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:发票录入2.rar

有点蓝老师,还是不行,我上传了附件,帮忙看一下。

--  作者:feixianzhi
--  发布时间:2016/11/10 8:46:00
--  
请有点蓝老师帮忙。