以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  关联表的导入  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=87323)

--  作者:zhangxl1964
--  发布时间:2016/7/8 10:30:00
--  关联表的导入
老师:你好!

         关联表导入是,怎样控制,当父表已存在(按条件),则禁止重新导入,同时禁止子表导入。
    If e.DataCol.Name = "客户编码" Then
    Dim Num As String \'客户编码
    Num=e.DataRow("客户编码")
    Dim Num1 As Date \'存货编码
    Num1=e.DataRow("日期")
    Dim dr As DataRow
    dr = e.DataTable.SQLFind("客户编码 = \'" & e.NewValue & "\' and  日期 = \'" & num1 & "\'")
    If dr IsNot Nothing Then
        MessageBox.Show("此客户已经存在!")
        e.Cancel = True
        \'子表页禁止导入代码
    End If
End If

--  作者:大红袍
--  发布时间:2016/7/8 10:41:00
--  
 你应该去控制导入的代码,而不是在这个事件控制。
--  作者:zhangxl1964
--  发布时间:2016/7/8 10:56:00
--  
请麻烦修改一下:
If e.Form.Controls("日期").Value Is Nothing  OrElse  e.Form.Controls("申购单号").Value Is Nothing Then
    MessageBox.Show("请检查条件是否全部输入!", "提示")
    Return
Else
    
    Dim Filter As String
    With e.Form.Controls("日期")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "日期 = \'" & .Value & "\'"
        End If
    End With
    With e.Form.Controls("申购单号")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "申购单号 = \'" & .Value & "\'"
        End If
    End With
    
    Dim jb1 As New SQLJoinTableBuilder("查询表1","申购主表")
    jb1.C
    Dim dt As DataTable
    jb1.AddCols("日期","客户编码","客户名称","仓库","保管员","录入员","申购单号")
    jb1.Filter = Filter
    dt = jb1.Build(True) \'生成一个DataTable
    
    Dim Cols1() As String = {"客户编码","客户名称","仓库","保管员","录入员","申购单号"}
    Dim Cols2() As String = {"客户编码","客户名称","仓库","保管员","录入员","申报单号"}
    For Each dr1 As DataRow In dt.Select("")
        \'For Each dr1 As DataRow In DataTables("原辅料明细").Select("")
        Dim dr2 As DataRow = DataTables("出库主表").AddNew()
        dr2("日期") = Forms("生成出库单").Controls("日期").value
        \'dr2("出库单号") = Tables("出库主表").Current("出库单号")
        \'dr2("客户编码") = Tables("出库主表").Current("客户编码")
        \'dr2("学校或单位") = Tables("出库主表").Current("客户名称")
        For i As Integer = 0 To Cols1.Length -1
            dr2(Cols2(i)) = dr1(Cols1(i))
        Next
    Next
    
    
    Dim jb2 As New SQLJoinTableBuilder("查询表1","申购明细")
    jb2.C
    Dim dt2 As DataTable
    jb2.AddCols("申购单号","存货编码","存货名称","存货单位","申购数量","客户编码","客户名称","大类","小类","采购品分类","拼音编码")
    jb2.Filter = Filter
    dt2 = jb2.Build(True) \'生成一个DataTable
    
    Dim Cols3() As String = {"申购单号","存货编码","存货名称","存货单位","申购数量","客户编码","客户名称","大类","小类","采购品分类","拼音编码"}
    Dim Cols4() As String = {"申报单号","存货编码","存货名称","存货单位","申购数量","客户编码","学校或单位","大类","小类","采购品分类","拼音编码"}
    For Each dr3 As DataRow In dt2.Select("")
        \'For Each dr1 As DataRow In DataTables("原辅料明细").Select("")
        Dim dr4 As DataRow = DataTables("出库明细").AddNew()
        dr4("日期") = Forms("生成出库单").Controls("日期").value
        dr4("出库单号") = Forms("生成出库单").Controls("出库单号").value
        \'dr2("学校或单位") = Tables("出库主表").Current("客户名称")
        For i As Integer = 0 To Cols3.Length -1
            dr4(Cols4(i)) = dr3(Cols3(i))
            \'dr4("出库数量") = dr4("申购数量") + dr4("增减数量")
        Next
    Next
End If

--  作者:大红袍
--  发布时间:2016/7/8 10:59:00
--  

AddNew之前,先find一下是否存在,如果存在,就不要AddNew就行了啊。

 

 


--  作者:zhangxl1964
--  发布时间:2016/7/8 11:01:00
--  
知道了