以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  求助代码简写  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=61938)

--  作者:xjc620
--  发布时间:2014/12/22 19:58:00
--  求助代码简写
甜版这个代码是在AfterOpenProject,能不能简写为定位到所有表最后一行,刚才看了下全局表,好像没有合适的事件
Dim idx As Integer = Tables("收入").FindRow(Tables("收入").DataTable.Find("车号 Is not null", "_Identify desc"))
If idx > -1 Then
    Tables("收入").Position = idx
Else
    Tables("收入").Position = Tables("收入").Rows.Count - 1
End If

Dim id As Integer = Tables("支出").FindRow(Tables("支出").DataTable.Find("车号 Is not null", "_Identify desc"))
If id > -1 Then
    Tables("支出").Position = id
Else
    Tables("支出").Position = Tables("支出").Rows.Count - 1
End If

Dim ixd As Integer = Tables("北斗安装").FindRow(Tables("北斗安装").DataTable.Find("车号 Is not null", "_Identify desc"))
If ixd > -1 Then
    Tables("北斗安装").Position = ixd
Else
    Tables("北斗安装").Position = Tables("北斗安装").Rows.Count - 1
End If

Dim id2 As Integer = Tables("北斗续费").FindRow(Tables("北斗续费").DataTable.Find("车号 Is not null", "_Identify desc"))
If id2 > -1 Then
    Tables("北斗续费").Position = id2
Else
    Tables("北斗续费").Position = Tables("北斗续费").Rows.Count - 1
End If

Dim id1 As Integer = Tables("日新车队").FindRow(Tables("日新车队").DataTable.Find("车号 Is not null", "_Sortkey desc"))
If id1 > -1 Then
    Tables("日新车队").Position = id1
Else
    Tables("日新车队").Position = Tables("日新车队").Rows.Count - 1
End If

--  作者:有点甜
--  发布时间:2014/12/22 20:15:00
--  

 不需要在afteropenproject里面写啊。你在currentTableChanged时间写就行了啊。


--  作者:有点甜
--  发布时间:2014/12/22 20:18:00
--  
Dim tns() As String = {"日新车队", "收入"}
For Each tn As String In tns
Dim id1 As Integer = Tables(tn).FindRow(Tables(tn).DataTable.Find("车号 Is not null", "_Sortkey desc"))
If id1 > -1 Then
    Tables(tn).Position = id1
Else
    Tables(tn).Position = Tables(tn).Rows.Count - 1
End If
Next

--  作者:xjc620
--  发布时间:2014/12/22 20:19:00
--  
CurrentTableChanged事件的话,如果两个表做对比时切换回去就到最后一行,那样还要重新查找刚才那条记录
--  作者:xjc620
--  发布时间:2014/12/22 20:23:00
--  
.NET Framework 版本:2.0.50727.6421
Foxtable 版本:2014.11.11.1
错误所在事件:项目,AfterOpenProject
详细错误信息:
无法找到列 _Sortkey。


--  作者:有点甜
--  发布时间:2014/12/22 20:26:00
--  

Dim tns() As String = {"日新车队", "收入"}
For Each tn As String In tns
    Dim cname As String
    If Tables(tn).Cols.Contains("_Sortkey") Then
        cname = "_Sortkey"
    Else
        cname = "_Identify"
    End If
    Dim id1 As Integer = Tables(tn).FindRow(Tables(tn).DataTable.Find("车号 Is not null", cname &" desc"))
    If id1 > -1 Then
        Tables(tn).Position = id1
    Else
        Tables(tn).Position = Tables(tn).Rows.Count - 1
    End If
Next