-- 作者:sf020cf
-- 发布时间:2015/11/15 11:32:00
-- 加载很慢
把当前表的数据加载到另外的表 (5千多条)花了好多分钟 代码如下:
Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } Dim Cols2() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } Dim count As Integer = 0 systemready = False For Each r As Row In Tables("配载订单").GetCheckedRows Dim filter As String = "1=1" For Each dc As String In Cols1 If r.IsNull(dc) Then filter &= " and " & dc & " is null" Else Dim c As Col = Tables("客服跟单").Cols(dc) If c.IsNumeric Then filter &= " and " & dc & " = " & r(dc) ElseIf c.IsBoolean Then If r(dc) = True Then filter &= " and " & dc & " = true" Else filter &= " and " & dc & " = false" End If ElseIf c.IsDate Then filter &= " and " & dc & " = #" & r(dc) & "#" Else filter &= " and " & dc & " = \'" & r(dc) & "\'" End If End If Next Dim dr As DataRow = DataTables("客服跟单").find(filter) If dr Is Nothing Then dr = DataTables("客服跟单").AddNew count += 1 End If For i As Integer = 0 To Cols1.Length -1 If r.IsNull(Cols1(i)) Then dr(Cols2(i)) = Nothing Else dr(Cols2(i)) = r(Cols1(i)) End If Next Next systemready = True msgbox("共有 "& count &" 条数据提交" ) Tables("配载订单").save Tables("配载订单").ClearCheckedRows
需要如何改进
|
-- 作者:大红袍
-- 发布时间:2015/11/15 11:39:00
--
Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } Dim Cols2() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","收货时间","是否采购订单","车型","司机","车牌","车数","出车日期" } Dim count As Integer = 0 Dim ls As new List(of Row) Dim dic As new Dictionary (Of DataRow, Row) systemready = False For Each r As Row In Tables("配载订单").GetCheckedRows Dim filter As String = "1=1" For Each dc As String In Cols1 If r.IsNull(dc) Then filter &= " and " & dc & " is null" Else Dim c As Col = Tables("客服跟单").Cols(dc) If c.IsNumeric Then filter &= " and " & dc & " = " & r(dc) ElseIf c.IsBoolean Then If r(dc) = True Then filter &= " and " & dc & " = true" Else filter &= " and " & dc & " = false" End If ElseIf c.IsDate Then filter &= " and " & dc & " = #" & r(dc) & "#" Else filter &= " and " & dc & " = \'" & r(dc) & "\'" End If End If Next Dim dr As DataRow = DataTables("客服跟单").find(filter) If dr Is Nothing Then ls.Add(r) count += 1 Else dic.add(dr, r) End If Next For Each r As Row In ls Dim dr As DataRow = DataTables("客服跟单").AddNew For i As Integer = 0 To Cols1.Length -1 If r.IsNull(Cols1(i)) Then dr(Cols2(i)) = Nothing Else dr(Cols2(i)) = r(Cols1(i)) End If Next Next For Each key As DataRow In dic.Keys Dim r As Row = dic(key) Dim dr As DataRow = key For i As Integer = 0 To Cols1.Length -1 If r.IsNull(Cols1(i)) Then dr(Cols2(i)) = Nothing Else dr(Cols2(i)) = r(Cols1(i)) End If Next Next
systemready = True msgbox("共有 "& count &" 条数据提交" ) Tables("配载订单").save Tables("配载订单").ClearCheckedRows
|