以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  合并不重复的数据  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=64076)

--  作者:信达
--  发布时间:2015/2/4 13:53:00
--  合并不重复的数据

老师,

 

我在合并“产品”表时,

 

Dim mg As New Merger
mg.SourcePath = "d:\\订单管理表.xls"
mg.Format = "excel" \'指定格式
mg.SourceTableName = "订单管理表$" \'指定要合并的表
mg.DataTableName = "产品" \'指定接收数据的表
mg.FieldMaps.Add("委托单位","客户简称")
mg.FieldMaps.Add("名称","部件名称")
mg.Merge() \'开始合并

为了防止重复写入客户简称和图号相同的数据时,在“产品”的DataColChanged里加上:

Select Case e.DataCol.name
    Case "客户简称","图号"
        Dim dr As DataRow = e.DataRow
        If dr.IsNull("客户简称") = False AndAlso dr.IsNull("图号") = False Then
            If e.DataTable.Compute("Count([_Identify])","客户简称 = \'" & dr("客户简称") & "\' And 图号 = \'" & dr("图号") & "\'") > 1 Then
                MessageBox.Show("已经存在相同客户和图号的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
            End If
        End If
End Select

 

不起作用。难度在合并表时,不运行DataColChanged吗?要怎样写呢?


--  作者:有点甜
--  发布时间:2015/2/4 14:21:00
--  

 合并不会触发DataCochanged事件。

 

 你可以编码导入 http://www.foxtable.com/help/topics/2334.htm

 


--  作者:信达
--  发布时间:2015/2/4 16:40:00
--  

那在菜单"产品导入"中这样写对吗?

 

Dim Book As New XLS.Book("d:\\订单管理表.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("产品").StopRedraw()
Dim Cols1() As String = {"委托单位","名称","图号","台车定额"}
Dim Cols2() As String = {"客户简称","部件名称","图号","台车定额"}
For dr1 As Integer = 1 To Sheet.Rows.Count -1
    Dim dr2 As DataRow = DataTables("产品").Find("客户简称 = \'" & dr2("客户简称") & "\' And 图号 = \'" & dr2("图号") & "\'")
    If dr2 Is Nothing Then \'如果不存在同客户名称和图号的订单
        dr2 =  DataTables("产品").AddNew()
    End If
    For i As Integer = 0 To Cols1.Length - 1
        dr2(Cols2(i)) = dr1(Cols1(i))
    Next
Next
Tables("产品").ResumeRedraw()

[此贴子已经被作者于2015-2-4 16:40:40编辑过]

--  作者:有点甜
--  发布时间:2015/2/4 16:44:00
--  
Dim Book As New XLS.Book("d:\\订单管理表.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("产品").StopRedraw()
Dim Cols1() As String = {"委托单位","名称","图号","台车定额"}
Dim Cols2() As String = {"客户简称","部件名称","图号","台车定额"}
For dr1 As Integer = 1 To Sheet.Rows.Count -1
    Dim dr2 As DataRow = DataTables("产品").Find("客户简称 = \'" & sheet(dr1,0).Text & "\' And 图号 = \'" & sheet(dr1,2).Text & "\'")
    If dr2 Is Nothing Then \'如果不存在同客户名称和图号的订单
        dr2 =  DataTables("产品").AddNew()
    End If
    For i As Integer = 0 To Cols1.Length - 1
        dr2(Cols2(i)) = sheet(dr1,i).Text
    Next
Next
Tables("产品").ResumeRedraw()