Foxtable(狐表)用户栏目专家坐堂 → [求助]代码优化问题,请求指教


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

主题:[求助]代码优化问题,请求指教

帅哥哟,离线,有人找我吗?
有点色
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/12/5 15:02:00 [显示全部帖子]

 Dim time1 As Date = Functions.Execute("SQLTIME")
e.Form.Controls("Label1").Text = "正在增加行,请稍后..."
Application.DoEvents()
Dim tb As Table = e.Form.Controls("Table1").Table
Dim tbltaizhang As Table = e.Form.Controls("Table2").Table
tb.StopRedraw
Dim cmb年度 As WinForm.ComboBox = e.Form.Controls("cmb年度")
Dim mydate As  Date = Functions.Execute("SQLTIME")
Dim nlist As new List(Of Row)
Dim dic As new Dictionary(Of Row, Integer)
For Each ydr As  Row In tbltaizhang.Rows
    Dim wz As Integer = tb.FindRow("[台账号] = '" & ydr("台账号") & "' And [春检年度] = '" & cmb年度.Text & "'")
    If wz >= 0 Then
        dic.add(ydr, wz)
    Else
        nlist.Add(ydr)
    End If
Next
For Each ydr As Row In nlist
    Dim nr As Row = tb.AddNew
    nr("部门编号")= ydr("部门编号")
    nr("部门")= ydr("部门")
    nr("春检年度")= e.Form.Controls("cmb年度").text
    nr("台账号")= ydr("台账号")
    nr("台账号old")= ydr("台账号old")
    nr("地点")= ydr("地点")
    nr("台账名称")= ydr("台账名称")
    nr("录入人")= _UserTag
    nr("录入终端")= _UserPCip
    nr("录入日期")= mydate
next
For Each ydr As Row In dic.Keys
    Dim nr As Row = tb.rows(dic(ydr))
    nr("部门编号")= ydr("部门编号")
    nr("部门")= ydr("部门")
    nr("春检年度")= e.Form.Controls("cmb年度").text
    nr("台账号")= ydr("台账号")
    nr("台账号old")= ydr("台账号old")
    nr("地点")= ydr("地点")
    nr("台账名称")= ydr("台账名称")
    nr("录入人")= _UserTag
    nr("录入终端")= _UserPCip
    nr("录入日期")= mydate
next
tb.ResumeRedraw
Dim time2 As Date = Functions.Execute("SQLTIME")
e.Form.Controls("Label1").Text = "耗时:" & Format((time2-time1).TotalSeconds,"0.0000") & "秒"

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/12/5 15:03:00 [显示全部帖子]

不要一边插一遍赋值。

 

http://www.foxtable.com/webhelp/scr/2225.htm

 


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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/12/8 10:19:00 [显示全部帖子]

Dim time1 As Date = Functions.Execute("SQLTIME")
e.Form.Controls("Label1").Text = "正在增加行,请稍后..."
Application.DoEvents()
Dim tb As DataTable = e.Form.Controls("Table1").Table.DataTable
Dim tbltaizhang As DataTable = e.Form.Controls("Table2").Table.DataTable
tb.StopRedraw
Dim cmb年度 As WinForm.ComboBox = e.Form.Controls("cmb年度")
Dim mydate As  Date = Functions.Execute("SQLTIME")
Dim nlist As new List(Of DataRow)
Dim dic As new Dictionary(Of DataRow, DataRow)
For Each ydr As DataRow In tbltaizhang.dataRows
    Dim wz As DataRow = tb.Find("[台账号] = '" & ydr("台账号") & "' And [春检年度] = '" & cmb年度.Text & "'")
    If wz IsNot Nothing Then
        dic.add(ydr, wz)
    Else
        nlist.Add(ydr)
    End If
Next
For Each ydr As DataRow In nlist
    Dim nr As DataRow = tb.AddNew
    nr("部门编号")= ydr("部门编号")
    nr("部门")= ydr("部门")
    nr("春检年度")= e.Form.Controls("cmb年度").text
    nr("台账号")= ydr("台账号")
    nr("台账号old")= ydr("台账号old")
    nr("地点")= ydr("地点")
    nr("台账名称")= ydr("台账名称")
    nr("录入人")= _UserTag
    nr("录入终端")= _UserPCip
    nr("录入日期")= mydate
next
For Each ydr As DataRow In dic.Keys
    Dim nr As dataRow = dic(ydr)
    nr("部门编号")= ydr("部门编号")
    nr("部门")= ydr("部门")
    nr("春检年度")= e.Form.Controls("cmb年度").text
    nr("台账号")= ydr("台账号")
    nr("台账号old")= ydr("台账号old")
    nr("地点")= ydr("地点")
    nr("台账名称")= ydr("台账名称")
    nr("录入人")= _UserTag
    nr("录入终端")= _UserPCip
    nr("录入日期")= mydate
Next
tb.ResumeRedraw
Dim time2 As Date = Functions.Execute("SQLTIME")
e.Form.Controls("Label1").Text = "耗时:" & Format((time2-time1).TotalSeconds,"0.0000") & "秒"

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/12/8 11:20:00 [显示全部帖子]


 回到顶部