以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何实现复制单据  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=7955)

--  作者:qtcks
--  发布时间:2010/8/24 9:31:00
--  [求助]如何实现复制单据
根据进销存模板要求,需要对一些单据进行复制新增。选中需要复制的有父表记录,还需复制关联表的内容。代码该如何写?
--  作者:blackzhu
--  发布时间:2010/8/24 9:49:00
--  

Select Case e.DataCol.Name
 Case "客户","产品"
    Dim kh As String = e.DataRow("客户")
    Dim cp As String = e.DataRow("产品")
    Dim tj = "客户 = \'" & kh & "\' And 产品 = \'" & cp & "\' "
    If kh >"" Andalso cp> "" Then
        If DataTables("表B").Find(tj) Is Nothing Then
            Dim dr As DataRow = DataTables("表B").AddNew()
            dr("客户") = kh
            dr("产品") = cp
        End If
    End If
End Select

 

 

   这个代码是在A表输入客户,产品的同时,在B表新增行输入客户,产品.


--  作者:狐狸爸爸
--  发布时间:2010/8/24 9:54:00
--  

假定表A是父表,表B是子表,代码大概如下,请自行理解调试:

 

Dim Childs As List(of DataRow) = Tables("表A").Current.DataRow.GetChildRows("表B")
Dim pr As Row = Tables("表A").AddNew
pr("关联列") = "aaa" \'如果通过_Identify列关联,则不需要此行
For Each cr As DataRow In Childs
    Dim nr As Row = Tables("表A.表B").AddNew
    For Each cl As Col In Tables("表B").Cols
      If cl.Name <> "关联列" Then
        nr(cl.name) = cr(cl.Name)
      End If
   Next
Next


--  作者:blackzhu
--  发布时间:2010/8/24 10:00:00
--  

Dim r1 As Row = Tables("父表").Current
Dim r2 As Row=  r1.Clone
For Each r3 As DataRow = r1.DataRow.GetChildRows("子表")
    Dim  r4 As Row = Tables("子表").AddNew 
    For c As Col In Tables("子表").Cols
        r4(c.Name) = r3(c.Name)
    Next
    r4("子表关联列") = r2("父表关联列")
Next

 

  试试这个,我以前保存下来的.


--  作者:qtcks
--  发布时间:2010/8/24 18:02:00
--  

谢谢大家的帮助,晚上搞定这个。再次谢谢大家。


--  作者:king
--  发布时间:2010/10/26 11:08:00
--  

希望给个示例看看,谢谢各位前辈。