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


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

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

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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望: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
  这样是不提示了,但是窗口表不保存,是什么问题?

 


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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 9:18:00 [显示全部帖子]

按你的方法可行.

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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望: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


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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 9:28:00 [显示全部帖子]

我看看!

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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望: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"的提示.


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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望: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
  7楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望: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("不存在")

 

 

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


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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 10:13:00 [显示全部帖子]

For Each t1 As Table In Tables

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

  

 

老大,这个是遍历表以后,然后判断  表名=本窗口表名 的时候判断存在,否则不存在,判断对的呀.前提是这样判断的呀.


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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 10:15:00 [显示全部帖子]

即使存在,会显示一个“存在”,同时会显示很多个“不存在”。

你想一下,如果10个Table,有一个名称相符的,那么肯定还有9个名称不相符的,所以会显示1个“存在”,9个“不存在”。

如果名称全部不相符,就会显示10个“不存在”。

 

 

 而且每一个表名肯定是不一样的,如果是窗口虽说是"Table1"有很多,但是前提也是  e.form.Name & "-Table1",这样一来,表名不可能相同的呀.


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


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57590 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2011/12/2 10:33: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.Contains(e.form.Name & "_Table1")=True Then
            ElseIf DataTables(e.form.Name & "_Table1").DataRows.Count>0 Then
                DataTables(e.form.Name & "_Table1").Save
                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

 

老大,我改成这样还是提示不存在窗口表,你帮我改一下,我怎么想也不明白,按钮对的,主表肯定保存了,就是提示不存在窗口表.


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