以文本方式查看主题

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

--  作者:zhuxinhui
--  发布时间:2020/7/12 16:41:00
--  批量导入关联表
现在把EXCEL数据导入到临时表,想把临时表数据根据单号不同导入到关联表销售订单明细表里,销售订单主表增加行时自动增加日期及订单单号,不知哪出了问题
DataTables("销售订单导入").Save()
Dim Cols1() As String = {"货物编码","货物名称","规格","单位","数量","单价","金额"}
Dim Cols2() As String = {"货物编码","货物名称","规格","单位","数量","单价","金额"}
Dim s As Table = Tables("销售订单导入")
For i As Integer = 0 To s.Rows.count-1
    If s.Rows(i)("单据编码") <> s.Rows(i-1)("单据编码") Then
        DataTables("销售订单明细").Save()
        DataTables("销售订单").Save()
        DataTables("销售订单").AddNew()
        If s.Rows(i)("选择")=True Then
            Dim dr2 As DataRow = DataTables("销售订单明细").AddNew()
            dr2("单据编码")=Forms("销售订单").Controls("TextBox2").text
            dr2("日期")=Forms("销售订单").Controls("DateTimePicker1").text
            dr2("单据类别")=Forms("销售订单").Controls("DropBox2").text
            dr2("往来名称")=Forms("销售订单").Controls("TextBox4").text
            dr2("往来编码")=Forms("销售订单").Controls("DropBox3").text
            For b As Integer = 0 To Cols1.Length -1
                dr2(Cols2(b)) = s.Rows(i)(Cols1(b))
            Next
        End If
    End If
Next
DataTables("销售订单导入").Save()
DataTables("销售订单导入").deletefor("[货物编码] Is not null")


--  作者:zhuxinhui
--  发布时间:2020/7/12 18:32:00
--  
在窗口在操作,还是导入同一张单,不会增加单据,是什么问题?想不通

DataTables("销售订单导入").Save()
Dim Cols1() As String = {"货物编码","货物名称","规格","单位","数量","单价","金额"}
Dim Cols2() As String = {"货物编码","货物名称","规格","单位","数量","单价","金额"}
Dim s As Table = Tables("销售订单导入")
For i As Integer = 0 To s.Rows.count-1
    If s.Rows(i)("单据编码") <> s.Rows(i-1)("单据编码") Then
        DataTables("销售订单明细").Save()
        DataTables("销售订单").Save()
        DataTables("销售订单").AddNew()
        Dim dr2 As DataRow = DataTables("销售订单明细").AddNew()
        dr2("单据编码")=Forms("销售订单").Controls("TextBox2").text
        dr2("日期")=Forms("销售订单").Controls("DateTimePicker1").text
        dr2("单据类别")=Forms("销售订单").Controls("DropBox2").text
        dr2("往来名称")=Forms("销售订单").Controls("TextBox4").text
        dr2("往来编码")=Forms("销售订单").Controls("DropBox3").text
        For b As Integer = 0 To Cols1.Length -1
            dr2(Cols2(b)) = s.Rows(i)(Cols1(b))
        Next       
    ElseIf s.Rows(i)("选择")=True Then
        Dim dr2 As DataRow = DataTables("销售订单明细").AddNew()
        dr2("单据编码")=Forms("销售订单").Controls("TextBox2").text
        dr2("日期")=Forms("销售订单").Controls("DateTimePicker1").text
        dr2("单据类别")=Forms("销售订单").Controls("DropBox2").text
        dr2("往来名称")=Forms("销售订单").Controls("TextBox4").text
        dr2("往来编码")=Forms("销售订单").Controls("DropBox3").text
        For b As Integer = 0 To Cols1.Length -1
            dr2(Cols2(b)) = s.Rows(i)(Cols1(b))
        Next
    End If
Next
DataTables("销售订单导入").Save()
DataTables("销售订单导入").deletefor("[货物编码] Is not null")

--  作者:zhuxinhui
--  发布时间:2020/7/12 18:36:00
--  
DataTables("销售订单导入").Save()
Dim Cols1() As String = {"货物编码","货物名称","规格","单位","数量","单价","金额"}
Dim Cols2() As String = {"货物编码","货物名称","规格","单位","数量","单价","金额"}
Dim s As Table = Tables("销售订单导入")
For i As Integer = 0 To s.Rows.count-1
    If s.Rows(i)("单据编码") <> s.Rows(i-1)("单据编码") And s.Rows(i)("选择")=True Then
        DataTables("销售订单明细").Save()
        DataTables("销售订单").Save()
        DataTables("销售订单").AddNew()
        Dim dr2 As DataRow = DataTables("销售订单明细").AddNew()
        dr2("单据编码")=Forms("销售订单").Controls("TextBox2").text
        dr2("日期")=Forms("销售订单").Controls("DateTimePicker1").text
        dr2("单据类别")=Forms("销售订单").Controls("DropBox2").text
        dr2("往来名称")=Forms("销售订单").Controls("TextBox4").text
        dr2("往来编码")=Forms("销售订单").Controls("DropBox3").text
        For b As Integer = 0 To Cols1.Length -1
            dr2(Cols2(b)) = s.Rows(i)(Cols1(b))
        Next       
    ElseIf s.Rows(i)("单据编码") = s.Rows(i-1)("单据编码") And s.Rows(i)("选择")=True Then
        Dim dr2 As DataRow = DataTables("销售订单明细").AddNew()
        dr2("单据编码")=Forms("销售订单").Controls("TextBox2").text
        dr2("日期")=Forms("销售订单").Controls("DateTimePicker1").text
        dr2("单据类别")=Forms("销售订单").Controls("DropBox2").text
        dr2("往来名称")=Forms("销售订单").Controls("TextBox4").text
        dr2("往来编码")=Forms("销售订单").Controls("DropBox3").text
        For b As Integer = 0 To Cols1.Length -1
            dr2(Cols2(b)) = s.Rows(i)(Cols1(b))
        Next
    End If
Next
DataTables("销售订单导入").Save()
DataTables("销售订单导入").deletefor("[货物编码] Is not null")

--  作者:zhuxinhui
--  发布时间:2020/7/12 19:12:00
--  
已解决了
--  作者:有点蓝
--  发布时间:2020/7/12 21:05:00
--  
这2句放到循环外面,最后保存一下即可。没有必要在循环里每一行保存一次吧

        DataTables("销售订单明细").Save()
        DataTables("销售订单").Save()

--  作者:zhuxinhui
--  发布时间:2020/7/19 11:41:00
--  
这个是,已删除了,多谢