Foxtable(狐表)用户栏目专家坐堂 → 这段通用代码有什么问题


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

主题:这段通用代码有什么问题

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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57584 威望:0 精华:15 注册:2008/9/1 9:45:00
这段通用代码有什么问题  发帖心情 Post By:2011/12/2 8:53:00 [只看该作者]

 

   是这样,我的表单有的有表控件,有的没有.


   原来这段代码我是遍历控件,判断table1控件是否存在?代码如下:

   If e.Sender.Text = "保存单据" Then
    If Tables(e.form.Name).Rows.Count>0 Then
        Tables(e.form.Name).Current("修改人") = _UserName
        Tables(e.form.Name).Current("修改时间") = Date.Now()
        Tables(e.form.Name).DataTable.Save()
    End If
    For Each c As Winform.Control In e.Form.Controls
        If Typeof c Is WinForm.Table Then
            If e.form.ExistControl("Table1") =True Then
                If DataTables(e.form.Name & "_Table1").DataRows.Count>0 Then
                    DataTables(e.form.Name & "_Table1").Save
                End If
                Dim t As Table = Tables(e.form.Name & "_Table1")
                With Tables(e.form.Name)
                    If .Current Is Nothing Then
                        t.Filter = "False"
                    Else
                        t.Filter = "系统单号 = '" & .Current("系统单号") & "'"
                    End If
                End With
            End If
        End If
    Next
End If
  但是提示,找不到Table1的控件.后来改成这样:

If e.Sender.Text = "保存单据" Then
    If Tables(e.form.Name).Rows.Count>0 Then
        Tables(e.form.Name).Current("修改人") = _UserName
        Tables(e.form.Name).Current("修改时间") = Date.Now()
        Tables(e.form.Name).DataTable.Save()
        If e.form.ExistControl(e.form.Name & "_Table1") =True Then
            If DataTables(e.form.Name & "_Table1").DataRows.Count>0 Then
                DataTables(e.form.Name & "_Table1").Save
            End If
            Dim t As Table = Tables(e.form.Name & "_Table1")
            With Tables(e.form.Name)
                If .Current Is Nothing Then
                    t.Filter = "False"
                Else
                    t.Filter = "系统单号 = '" & .Current("系统单号") & "'"
                End If
            End With
        End If
    End If
End If
  这样是不提示了,但是窗口表不保存,是什么问题?

 


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


加好友 发短信
等级:管理员 帖子:47448 积分:251054 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/12/2 9:13:00 [只看该作者]

你先追踪一下,看看问题出在哪一行代码吧。

 

另外,不可以更简单吗:

For Each t As Table In Tables

   If t.Name = e.form.Name & "_Table1" Then

          '.....

   End if

Next

 

 


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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57584 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 9:18:00 [只看该作者]

按你的方法可行.

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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57584 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 9:21:00 [只看该作者]

不对,我改了一下,还是提示.新增以后,保存还会出现提示.保存后在保存就没有问题了.我把代码改了这样

 

If e.Sender.Text = "保存单据" Then
    If Tables(e.form.Name).Rows.Count>0 Then
        Tables(e.form.Name).Current("修改人") = _UserName
        Tables(e.form.Name).Current("修改时间") = Date.Now()
        Tables(e.form.Name).DataTable.Save()
        For Each t1 As Table In Tables
            If t1.Name = e.form.Name & "_Table1" Then
                If DataTables(e.form.Name & "_Table1").DataRows.Count>0 Then
                    DataTables(e.form.Name & "_Table1").Save
                End If
                Dim t As Table = Tables(e.form.Name & "_Table1")
                With Tables(e.form.Name)
                    If .Current Is Nothing Then
                        t.Filter = "False"
                    Else
                        t.Filter = "系统单号 = '" & .Current("系统单号") & "'"
                    End If
                End With
            End If
        Next
    End If
End If


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251054 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/12/2 9:27:00 [只看该作者]

提示什么啊?

 

可以在后面加两行,要主动去跟踪关键代码:

 

If e.Sender.Text = "保存单据" Then
    If Tables(e.form.Name).Rows.Count>0 Then
        Tables(e.form.Name).Current("修改人") = _UserName
        Tables(e.form.Name).Current("修改时间") = Date.Now()
        Tables(e.form.Name).DataTable.Save()

        Messagebox.Show(“保存1”)
        For Each t1 As Table In Tables
            If t1.Name = e.form.Name & "_Table1" Then
                If DataTables(e.form.Name & "_Table1").DataRows.Count>0 Then
                    DataTables(e.form.Name & "_Table1").Save

                     Messagebox.Show(“保存2”) 
                End If
                Dim t As Table = Tables(e.form.Name & "_Table1")
                With Tables(e.form.Name)
                    If .Current Is Nothing Then
                        t.Filter = "False"
                    Else
                        t.Filter = "系统单号 = '" & .Current("系统单号") & "'"
                    End If
                End With
            End If
        Next
    End If
End If

MessageBox.show(Tables(e.form.Name).DataTable.HasChanges)
MessageBox.show(Tables(e.form.Name & "_Table1")).DataTable.HasChanges)


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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57584 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 9:28:00 [只看该作者]

我看看!

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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57584 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 9:37:00 [只看该作者]

我用三个测试:第一个窗口表用的SQLTable   提示是连续的两个false.没有一点问题.保存1和保存2显示.我用fill加载,

 

                  第二个窗口表用的普通的表,是副本表,提示是连续的两个个ture,保存1和保存2没有显示.然后提示是找不到"付款单_Table1"的提示.这个是直接绑定的.

 

                 第三个是没有窗口表的,出来的情况跟第二个窗口一样.提示是找不到"预付款_Table1"的提示.


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251054 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/12/2 9:44:00 [只看该作者]

保存1和保存2没有显示,说明你的代码根本没有执行。

代码是机械的,从来不会偏离轨道,条件成立就一定会执行。

 

既然没有执行,说明下面两个条件不成立:

 

If e.Sender.Text = "保存单据" Then
    If Tables(e.form.Name).Rows.Count>0 Then

 

我想你自己可以知道原因了,前面来两行:

 

messagebox.show(e.Sender.Text)

messageBook.Show(Tables(e.form.Name).Rows.Count)

 

就知道到底是那个条件不成立的了。

 

要搞清楚不同状态下Table的表名:

http://www.foxtable.com/help/topics/1788.htm

 

[此贴子已经被作者于2011-12-2 9:44:29编辑过]

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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57584 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 9:59:00 [只看该作者]

messagebox.show(e.Sender.Text)

messageBook.Show(Tables(e.form.Name).Rows.Count)

  判断是对的呀控件是对的,行数也是对的.
[此贴子已经被作者于2011-12-2 9:59:02编辑过]

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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57584 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 10:03:00 [只看该作者]


    If Tables(e.form.Name).Rows.Count>0 Then
        Tables(e.form.Name).Current("修改人") = _UserName
        Tables(e.form.Name).Current("修改时间") = Date.Now()
        Tables(e.form.Name).DataTable.Save()
       
        Messagebox.Show("保存1")
        For Each t1 As Table In Tables

            If t1.Name = e.form.Name & "_Table1" Then
Messagebox.Show("存在")
Else
Messagebox.Show("不存在")

 

 

 我这样跟踪后,第一步保存,第二步显示不存在.


 回到顶部
总数 32 1 2 3 4 下一页