以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]代码耗时问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=184607) |
-- 作者:lgj716330 -- 发布时间:2022/12/15 17:29:00 -- [求助]代码耗时问题 For Each dr As DataRow In DataTables("净进货核算差额调整").DataRows If dr("店铺性质") = "正价店" Then If dr("新季节属性") = "当季新款" Then Dim pr As DataRow Dim filter As String filter = "货品年份 = \'" & dr("款式年份") & "\' And 货品季节 = \'" & dr("款式季度") & "\' And 仓店编号 = \'" & dr("仓店编号") & "\' and 退货截止日期 is not null" pr = DataTables("客户当季货品退货核算标准").Find(filter) If pr IsNot Nothing Then If (pr("退货截止年份") = N1 And pr("退货截止月份") <= y1) Or pr("退货截止年份") < N1 Then dr("退货完成标记") = "完成退货" dr("核算年份") = pr("退货截止年份") dr("核算月份") = pr("退货截止月份") Else dr("退货完成标记") = "未完成退货" dr("核算年份") = Nothing dr("核算月份") = Nothing End If Else dr("退货完成标记") = "未完成退货" dr("核算年份") = Nothing dr("核算月份") = Nothing End If End If If dr("新季节属性") = "往年旧款" Then Dim pr1 As DataRow Dim filter1 As String filter1 = "款式季度 = \'" & dr("款式季度") & "\' And 仓店编号 = \'" & dr("仓店编号") & "\' and ((年份= \'" & dr("年份") & "\' and 月份>= " & dr("月份") & ") or 年份> \'" & dr("年份") & "\') and 退货完成标记=\'完成退货\' and 新季节属性=\'当季新款\'" pr1 = DataTables("净进货核算差额调整").Find(filter1) If pr1 IsNot Nothing Then dr("退货完成标记") = "完成退货" dr("核算年份") = pr1("核算年份") dr("核算月份") = pr1("核算月份") Else dr("退货完成标记") = "未完成退货" dr("核算年份") = Nothing dr("核算月份") = Nothing End If End If ElseIf dr("店铺性质") = "非正价店" Then Dim pr2 As DataRow Dim filter2 As String filter2 = "款式季度 = \'" & dr("款式季度") & "\' And 品牌名称 = \'" & dr("品牌名称") & "\' and ((调整退市年份= \'" & dr("年份") & "\' and 调整退市月份>= " & dr("月份") & ") or 调整退市年份> \'" & dr("年份") & "\')" pr2 = DataTables("商品上市退市时间档案").Find(filter2, "调整退货日期") If pr2 IsNot Nothing Then If (pr2("调整退市年份") = N1 And pr2("调整退市月份") <= y1) Or pr2("调整退市年份") < N1 Then dr("退货完成标记") = "完成退货" dr("核算年份") = pr2("调整退市年份") dr("核算月份") = pr2("调整退市月份") Else dr("退货完成标记") = "未完成退货" dr("核算年份") = Nothing dr("核算月份") = Nothing End If Else dr("退货完成标记") = "未完成退货" dr("核算年份") = Nothing dr("核算月份") = Nothing End If Else dr("退货完成标记") = "未完成退货" dr("核算年份") = Nothing dr("核算月份") = Nothing End If Next 两万来条记录,结果出来差不多个把小时,如何调整可以效率高一些
|
-- 作者:有点蓝 -- 发布时间:2022/12/15 17:39:00 -- 看看:http://www.foxtable.com/webhelp/topics/2225.htm |
-- 作者:lgj716330 -- 发布时间:2022/12/15 17:43:00 -- 帮助中要求是同一个表内查找赋值,不同表也可以这样处理吗 |
-- 作者:lgj716330 -- 发布时间:2022/12/15 18:58:00 -- Dim lst1 As New List(Of DataRow) Dim lst2 As New List(Of DataRow) Dim lst3 As New List(Of DataRow) Dim lst4 As New List(Of DataRow) Dim pr1 As DataRow Dim pr2 As DataRow Dim pr3 As DataRow For Each dr As DataRow In DataTables("净进货核算差额调整").DataRows If dr("店铺性质") = "正价店" Then If dr("新季节属性") = "当季新款" Then Dim filter As String filter = "货品年份 = \'" & dr("款式年份") & "\' And 货品季节 = \'" & dr("款式季度") & "\' And 仓店编号 = \'" & dr("仓店编号") & "\' and 退货截止日期 is not null" pr1 = DataTables("客户当季货品退货核算标准").Find(filter) If pr1 IsNot Nothing Then If (pr1("退货截止年份") = N1 And pr1("退货截止月份") <= y1) Or pr1("退货截止年份") < N1 Then lst1.Add(dr) Else lst4.Add(dr) End If Else lst4.Add(dr) End If End If If dr("新季节属性") = "往年旧款" Then Dim filter1 As String filter1 = "款式季度 = \'" & dr("款式季度") & "\' And 仓店编号 = \'" & dr("仓店编号") & "\' and ((年份= \'" & dr("年份") & "\' and 月份>= " & dr("月份") & ") or 年份> \'" & dr("年份") & "\') and 退货完成标记=\'完成退货\' and 新季节属性=\'当季新款\'" pr2 = DataTables("净进货核算差额调整").Find(filter1) If pr2 IsNot Nothing Then lst2.Add(dr) Else lst4.Add(dr) End If End If ElseIf dr("店铺性质") = "非正价店" Then Dim filter2 As String filter2 = "款式季度 = \'" & dr("款式季度") & "\' And 品牌名称 = \'" & dr("品牌名称") & "\' and ((调整退市年份= \'" & dr("年份") & "\' and 调整退市月份>= " & dr("月份") & ") or 调整退市年份> \'" & dr("年份") & "\')" pr3 = DataTables("商品上市退市时间档案").Find(filter2, "调整退货日期") If pr3 IsNot Nothing Then If (pr3("调整退市年份") = N1 And pr3("调整退市月份") <= y1) Or pr3("调整退市年份") < N1 Then lst3.Add(dr) Else lst4.Add(dr) End If Else lst4.Add(dr) End If Else lst4.Add(dr) End If Next For Each dr As DataRow In lst1 dr("退货完成标记") = "完成退货" dr("核算年份") = pr1("退货截止年份") dr("核算月份") = pr1("退货截止月份") Next For Each dr As DataRow In lst2 dr("退货完成标记") = "完成退货" dr("核算年份") = pr2("核算年份") dr("核算月份") = pr2("核算月份") Next For Each dr As DataRow In lst3 dr("退货完成标记") = "完成退货" dr("核算年份") = pr3("调整退市年份") dr("核算月份") = pr3("调整退市月份") Next For Each dr As DataRow In lst4 dr("退货完成标记") = "未完成退货" dr("核算年份") = Nothing dr("核算月份") = Nothing Next 调整成这样,快是快了很多,就是结果不对
|
-- 作者:有点蓝 -- 发布时间:2022/12/15 20:22:00 -- Dim dz1 As New Dictionary(Of DataRow, DataRow) Dim dz2 As New Dictionary(Of DataRow, DataRow) Dim dz3 As New Dictionary(Of DataRow, DataRow) Dim dznull As New List(Of DataRow) For Each dr As DataRow In DataTables("净进货核算差额调整").DataRows If dr("店铺性质") = "正价店" Then If dr("新季节属性") = "当季新款" Then Dim pr As DataRow Dim filter As String filter = "货品年份 = \'" & dr("款式年份") & "\' And 货品季节 = \'" & dr("款式季度") & "\' And 仓店编号 = \'" & dr("仓店编号") & "\' and 退货截止日期 is not null" pr = DataTables("客户当季货品退货核算标准").Find(filter) If pr IsNot Nothing Then If (pr("退货截止年份") = N1 And pr("退货截止月份") <= y1) Or pr("退货截止年份") < N1 Then dz1.Add(dr, pr) Else dznull.Add(dr) End If Else dznull.Add(dr) End If ElseIf dr("新季节属性") = "往年旧款" Then Dim pr1 As DataRow Dim filter1 As String filter1 = "款式季度 = \'" & dr("款式季度") & "\' And 仓店编号 = \'" & dr("仓店编号") & "\' and ((年份= \'" & dr("年份") & "\' and 月份>= " & dr("月份") & ") or 年份> \'" & dr("年份") & "\') and 退货完成标记=\'完成退货\' and 新季节属性=\'当季新款\'" pr1 = DataTables("净进货核算差额调整").Find(filter1) If pr1 IsNot Nothing Then dz2.Add(dr, pr1) Else dznull.Add(dr) End If End If ElseIf dr("店铺性质") = "非正价店" Then Dim pr2 As DataRow Dim filter2 As String filter2 = "款式季度 = \'" & dr("款式季度") & "\' And 品牌名称 = \'" & dr("品牌名称") & "\' and ((调整退市年份= \'" & dr("年份") & "\' and 调整退市月份>= " & dr("月份") & ") or 调整退市年份> \'" & dr("年份") & "\')" pr2 = DataTables("商品上市退市时间档案").Find(filter2, "调整退货日期") If pr2 IsNot Nothing Then If (pr2("调整退市年份") = N1 And pr2("调整退市月份") <= y1) Or pr2("调整退市年份") < N1 Then dz3.Add(dr, pr2) Else dznull.Add(dr) End If Else dznull.Add(dr) End If Else dznull.Add(dr) End If Next For Each dr As DataRow In dz1.Keys dr("退货完成标记") = "完成退货" dr("核算年份") = dz1(dr)("退货截止年份") dr("核算月份") = dz1(dr)("退货截止月份") Next For Each dr As DataRow In dz2.Keys dr("退货完成标记") = "完成退货" dr("核算年份") = dz2(dr)("核算年份") dr("核算月份") = dz2(dr)("核算月份") Next For Each dr As DataRow In dz3.Keys dr("退货完成标记") = "完成退货" dr("核算年份") = dz3(dr)("调整退市年份") dr("核算月份") = dz3(dr)("调整退市月份") Next For Each dr As DataRow In dznull dr("退货完成标记") = "未完成退货" dr("核算年份") = Nothing dr("核算月份") = Nothing Next
|