以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  这段通用代码有什么问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=14785)

--  作者:blackzhu
--  发布时间: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
  这样是不提示了,但是窗口表不保存,是什么问题?

 


--  作者:狐狸爸爸
--  发布时间: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
--  发布时间:2011/12/2 9:18:00
--  
按你的方法可行.
--  作者:blackzhu
--  发布时间: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


--  作者:狐狸爸爸
--  发布时间: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
--  发布时间:2011/12/2 9:28:00
--  
我看看!
--  作者:blackzhu
--  发布时间:2011/12/2 9:37:00
--  

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

 

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

 

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


--  作者:狐狸爸爸
--  发布时间: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
--  发布时间: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
--  发布时间: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("不存在")

 

 

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