Foxtable(狐表)用户栏目专家坐堂 → [求助] 代码优化


  共有2688人关注过本帖树形打印复制链接

主题:[求助] 代码优化

美女呀,离线,留言给我吧!
susanhe
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:312 积分:2477 威望:0 精华:0 注册:2018/11/22 20:30:00
[求助] 代码优化  发帖心情 Post By:2019/10/12 11:37:00 [只看该作者]

你好,以下代码觉得太慢了,可以优化吗?

 

 

'ETD变更
Dim q  As new QueryBuilder
 q.TableName = "MPSDiff1"
q.Se lectString = "Se lect  OrderDate,批号,EndCustomer,CustomerPO,Pos,PartNo,OrderQty,ETD,ShippingTerms,ID,产品,数量,发货日期,发货方式,订单日期,{Orderlist}.Remark From {Orderlist} Inner JOIN {myOrderlistBackup} ON {myOrderlistBackup}.[ID] = {Orderlist}.[批号] Where {Orderlist}.ETD <> {myOrderlistBackup}.发货日期"
q.Build
 MainTable = Tables("MPSDiff1")


'批号新增
Dim qq  As new QueryBuilder
qq.TableName = "MPSDiff2"
qq.Sel ectString = "Se lect  OrderDate,批号,EndCustomer,CustomerPO,Pos,PartNo,OrderQty,ETD,ShippingTerms,ID,产品,数量,发货日期,发货方式,订单日期,{Orderlist}.Remark From {Orderlist} Left JOIN {myOrderlistBackup} ON {myOrderlistBackup}.[ID] = {Orderlist}.[批号] Where {myOrderlistBackup}.ID is null"
qq.Build
MainTable = Tables("MPSDiff2")

'批号删除
Dim qqq  As new QueryBuilder
qqq.TableName = "MPSDiff3"
qqq.Se lectString = "Sel ect  OrderDate,批号,EndCustomer,CustomerPO,Pos,PartNo,OrderQty,ETD,ShippingTerms,ID,产品,数量,发货日期,发货方式,订单日期,{Orderlist}.Remark From {Orderlist} Right JOIN {myOrderlistBackup} ON {myOrderlistBackup}.[ID] = {Orderlist}.[批号] Where {orderlist}.批号 is null"
qqq.Build
MainTable = Tables("MPSDiff3")

'Qty变更
Dim qqqq  As new QueryBuilder
qqqq.TableName = "MPSDiff4"
qqqq.Se ectString = "Se lect  OrderDate,批号,EndCustomer,CustomerPO,Pos,PartNo,OrderQty,ETD,ShippingTerms,ID,产品,数量,发货日期,发货方式,订单日期,{Orderlist}.Remark From {Orderlist} Inner JOIN {myOrderlistBackup} ON {myOrderlistBackup}.[ID] = {Orderlist}.[批号] Where {Orderlist}.orderQty <> {myOrderlistBackup}.数量"
qqqq.Build
MainTable = Tables("MPSDiff4")

'Shippingterms变更
Dim qqqqq  As new QueryBuilder
qqqqq.TableName = "MPSDiff5"
qqqqq.Se lectString = "Se lect  OrderDate,批号,EndCustomer,CustomerPO,Pos,PartNo,OrderQty,ETD,ShippingTerms,ID,产品,数量,发货日期,发货方式,订单日期,{Orderlist}.Remark From {Orderlist} Inner JOIN {myOrderlistBackup} ON {myOrderlistBackup}.[ID] = {Orderlist}.[批号] Where {Orderlist}.ShippingTerms <> {myOrderlistBackup}.发货方式"
qqqqq.Build
MainTable = Tables("MPSDiff5")


'Part No变更
Dim qqqqqq  As new QueryBuilder
qqqqqq.TableName = "MPSDiff6"
qqqqqq.Se  lectString = "Se lect  OrderDate,批号,EndCustomer,CustomerPO,Pos,PartNo,OrderQty,ETD,ShippingTerms,ID,产品,数量,发货日期,发货方式,订单日期,{Orderlist}.Remark From {Orderlist} Inner JOIN {myOrderlistBackup} ON {myOrderlistBackup}.[ID] = {Orderlist}.[批号] Where {Orderlist}.partno <> {myOrderlistBackup}.产品"
qqqqqq.Build
MainTable = Tables("MPSDiff6")


'DataTables("MPSDiff").datarows.clear

'Dim dr2 As DataRow = DataTables("MyplanningDiff").AddNew()

DataTables("MyplanningDiff").datarows.clear


Dim f11 As New  Filler
f11.SourceTable = DataTables("MPSDiff1") '指定数据来源
f11.DataTable = DataTables("MyplanningDiff") '指定数据接收表
f11.Fill() '填充数据

For Each ar As Row In Tables("MyplanningDiff").Rows
If ar("变更内容") = Nothing
ar("变更内容")  = "ETD变更"
End If
Next


Dim f2 As New  Filler
f2.SourceTable = DataTables("MPSDiff2") '指定数据来源
f2.DataTable = DataTables("MyplanningDiff") '指定数据接收表
f2.Fill() '填充数据

For Each ar As Row In Tables("MyplanningDiff").Rows
If ar("变更内容") = Nothing
ar("变更内容") = "批号新增"
End If
Next

 

Dim f3 As New  Filler
f3.SourceTable = DataTables("MPSDiff3") '指定数据来源
f3.DataTable = DataTables("MyplanningDiff") '指定数据接收表
f3.Fill() '填充数据

For Each ar As Row In Tables("MyplanningDiff").Rows
If ar("变更内容") = Nothing
ar("变更内容") = "批号删除"
End If
Next


Dim f4 As New  Filler
f4.SourceTable = DataTables("MPSDiff4") '指定数据来源
f4.DataTable = DataTables("MyplanningDiff") '指定数据接收表
f4.Fill() '填充数据

For Each ar As Row In Tables("MyplanningDiff").Rows
If ar("变更内容") = Nothing
ar("变更内容") = "Qty变更"
End If
Next


Dim f5 As New  Filler
f5.SourceTable = DataTables("MPSDiff5") '指定数据来源
f5.DataTable = DataTables("MyplanningDiff") '指定数据接收表
f5.Fill() '填充数据

For Each ar As Row In Tables("MyplanningDiff").Rows
If ar("变更内容") = Nothing
ar("变更内容") = "发货方式变更"
End If
Next


Dim f6 As New  Filler
f6.SourceTable = DataTables("MPSDiff6") '指定数据来源
f6.DataTable = DataTables("MyplanningDiff") '指定数据接收表
f6.Fill() '填充数据

For Each ar As Row In Tables("MyplanningDiff").Rows
If ar("变更内容") = Nothing
ar("变更内容") = "Part No变更"
End If
Next

DataTables("MyplanningDiff").save
Tables("MyplanningDiff").sort ="变更内容 desc"


If Tables("MyplanningDiff").value IsNot Nothing
Dim flg As New  SaveExcelFlags
 flg.RowNumber = True
 flg.CellStyle = True
 'Tables("MyplanningDiff").SaveExcel("d:\myPlanningDiff\myPlanningDiff  " &format(Date.now,"yyyyMMddHHmmss")  & ".xlsx","Diff",flg)
ShowAppWindow("myPlanningDiff.xls",5)
 Tables("MyplanningDiff").SaveExcel(ProjectPath & "Attachments\myPlanningDiff.xls",format(Date.now,"yyyyMMddHHmmss") ,flg)

If  ShowAppWindow("myPlanningDiff.xls",1) = False Then
     Dim  Proc As New Process
msgbox ("有变更内容产生!!!")
     Proc.File = ProjectPath & "Attachments\myPlanningDiff.xls"
     Proc.Start
 End If

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110813 积分:564003 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/10/12 11:46:00 [只看该作者]

Se lect  'ETD变更' as 变更内容,OrderDate,批号,EndCustomer,CustomerPO,Pos,PartNo,OrderQty,ETD,ShippingTerms,ID,产品,数量,发货日期,发货方式,订单日期,{Orderlist}.Remark From {Orderlist} Inner JOIN {myOrderlistBackup} ON {myOrderlistBackup}.[ID] = {Orderlist}.[批号] Where {Orderlist}.ETD <> {myOrderlistBackup}.发货日期
union all
Se lect  '批号新增' as 变更内容,OrderDate,批号,EndCustomer,CustomerPO,Pos,PartNo,OrderQty,ETD,ShippingTerms,ID,产品,数量,发货日期,发货方式,订单日期,{Orderlist}.Remark From {Orderlist} Left JOIN {myOrderlistBackup} ON {myOrderlistBackup}.[ID] = {Orderlist}.[批号] Where {myOrderlistBackup}.ID is null
union all
其它表数据自己补充

把上面SQL放到数据库建一个视图,如果是内部表,建一个查询表:http://www.foxtable.com/webhelp/topics/2329.htm

然后全部代码改为:

Tables("MyplanningDiff").Fill("select * from {视图名称或者查询表名称}",True)

Dim flg As New  SaveExcelFlags
 flg.RowNumber = True
 flg.CellStyle = True
 'Tables("MyplanningDiff").SaveExcel("d:\myPlanningDiff\myPlanningDiff  " &format(Date.now,"yyyyMMddHHmmss")  & ".xlsx","Diff",flg)
ShowAppWindow("myPlanningDiff.xls",5)
 Tables("MyplanningDiff").SaveExcel(ProjectPath & "Attachments\myPlanningDiff.xls",format(Date.now,"yyyyMMddHHmmss") ,flg)

If  ShowAppWindow("myPlanningDiff.xls",1) = False Then
     Dim  Proc As New Process
msgbox ("有变更内容产生!!!")
     Proc.File = ProjectPath & "Attachments\myPlanningDiff.xls"
     Proc.Start
 End If


 回到顶部