With Tables("主表")
For i As Integer = .BottomRow To .TopRow Step -1
Dim r1 As Row = .Rows(i)
Dim r2 As Row = Tables("主表").AddNew
For Each c As Col In .Cols
r2(c.name) = r1(c.name)
Next
r2.Save
Next
End With
Dim r As Row = Tables("主表").Current
If r Is Nothing Then
Return
End If
Dim cnt As Integer
Dim drs As List(Of DataRow)
drs = Tables(e.form.Name & "_Table1").DataTable.Select("工作单号='" & e.Form.Controls("TextBox2").Text & "' And 拆piao = True")
For Each dr As DataRow In drs
Dim dx As Row = Tables("主表明细").AddNew
dx("工作单号") = r("工作单号")
dx("录入日期")=Date.Now
dx("录入人")=_UserName
cnt = drs.Count
dx("二十尺集卡") = dr("二十尺集卡")
dx("四十尺集卡")=dr("四十尺集卡")
dx("箱号")=dr("箱号")
dx("封号")=dr("封号")
dx("船名航次")=dr("船名航次")
dx("船公司")=dr("船公司")
dx("运单号")=dr("运单号")
dr.Delete
Next
MessageBox.Show(cnt)
Dim cmd As new SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "Select * from{费用明细} Where 工作单号='" & e.Form.Controls("TextBox2").Text & "'"
dt = cmd.ExecuteReader(True) '记得将参数设置为True
For Each dr1 As DataRow In dt.DataRows
Dim dh As Row = Tables("费用明细").AddNew
dh("工作单号") = r("工作单号")
dh("录入日期")=Date.Now
dh("录入人")=_UserName
dh("费用项") = dr1("费用项")
dh("应收付")=dr1("应收付")
dh("结算日期")=dr1("结算日期")
dh("单价")=dr1("单价")
dh("结算单位")=dr1("结算单位")
dh("船名航次")=dr1("船名航次")
dh("船公司")=dr1("船公司")
dh("运单号")=dr1("运单号")
dh("数量")= cnt
dr1("数量")=dr1("数量") - cnt
Next
Tables("主表.费用明细").DataTable.Save
Tables(e.form.Name & "_Table1").DataTable.Save
Tables("费用明细").DataTable.Save
Tables("主表明细").DataTable.Save
Dim ids As String
If DataTables("主表").DataRows.Count = 0 Then '如果订单表没有数据
DataTables("主表明细").LoadFilter = "工作单号 Is Null" '不加载订单明细
Else
For Each dr As DataRow In DataTables("主表").DataRows
If ids="" Then
ids="'" & dr("工作单号") & "'"
Else
ids=ids & ",'" & dr("工作单号") & "'"
End If
Next
ids="(" & ids & ")"
DataTables("主表明细").LoadFilter = "工作单号 In " & ids
DataTables("主表明细").Load()
DataTables("费用明细").LoadFilter = "工作单号 In " & ids
DataTables("费用明细").Load()
End If
这个代码有啥问题,发现窗口表1 以及 费用明细 的工作单号会全部改成 新增的 工作单号 我的愿意是 勾选的 新增,新增后工作单号是新增的号码, 费用明细全部复制一遍 新增的工作单号也是新增的号码