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


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

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

帅哥,在线噢!
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110569 积分:562735 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/12/5 14:57:00 [显示全部帖子]

效率的问题可以参考:http://www.foxtable.com/webhelp/scr/2225.htm

具体上例子测试

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110569 积分:562735 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/12/8 9:38:00 [显示全部帖子]

Dim tb As dataTable = e.Form.Controls("Table1").Table.datatable
......
Dim nlist As new List(Of dataRow)
......
Dim dic As new Dictionary(Of dataRow, 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.datarow, wz)
    Else
        nlist.Add(ydr.datarow)
    End If
Next

 回到顶部
帅哥,在线噢!
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110569 积分:562735 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/12/8 10:17: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, 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.DataRow, wz)
    Else
        nlist.Add(ydr.DataRow)
    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 = tb.rows(dic(ydr)).DataRow
    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") & "秒"

 回到顶部