FoxPro 表单不更新表格

发布于 2024-11-17 03:51:18 字数 1119 浏览 1 评论 0原文

我创建了一个非常简单的表单,其中包含两个文本框和一个“更新位置”按钮,其输入的值应该更新到数据库中的两个链接表。我最终尝试将其放入独立的应用程序中,但现在我只希望表单本身能够工作。我对 FoxPro 非常陌生,所以我不知道是否可以只用一个表单来更新我的表格,或者工作中是否存在其他问题。

这是我的“更新位置”按钮的代码(OldLoc 是第一个文本框,NewLoc 第二个文本框):

SET DATABASE TO LOCATIONS
CLOSE ALL DATABASES
OPEN DATABASE locations\locations EXCLUSIVE

IF  this.parent.OldLoc.Value == "" then  
     MESSAGEBOX('Please fill in the old location.', 48, 'Missing Location Information')
this.parent.OldLoc.SetFocus

ELSE
INDEX ON table1.loc TAG loc
SET ORDER TO loc
SEEK this.parent.OldLoc.Value IN table1

IF FOUND()
    IF this.parent.NewLoc.Value == "" then
        MESSAGEBOX('Please fill in the new location.', 48, 
                                 'Missing  Location Information')       this.parent.NewLoc.SetFocus  

    UPDATE table1 SET loc = this.parent.NewLoc.Value ; 
                   WHERE loc = this.parent.OldLoc.value
    UPDATE table2 SET loc = this.parent.NewLoc.Value ;
                   WHERE loc = this.parent.OldLoc.value

    ENDIF
ENDIF
ENDIF

感谢您的任何输入!

我的基本形式

I've created a very simple form with two textboxes and an 'update locations' button, the inputted values of which should be updating to two linked tables in a database. I'm eventually trying to put this in a standalone application but for now I just want the form itself to work. I'm very new to FoxPro so I don't know if it's possible for just a form to update my tables, or if there's some other issue at work.

Here's the code for my 'update locations' button (OldLoc is the first textbox and NewLoc the second):

SET DATABASE TO LOCATIONS
CLOSE ALL DATABASES
OPEN DATABASE locations\locations EXCLUSIVE

IF  this.parent.OldLoc.Value == "" then  
     MESSAGEBOX('Please fill in the old location.', 48, 'Missing Location Information')
this.parent.OldLoc.SetFocus

ELSE
INDEX ON table1.loc TAG loc
SET ORDER TO loc
SEEK this.parent.OldLoc.Value IN table1

IF FOUND()
    IF this.parent.NewLoc.Value == "" then
        MESSAGEBOX('Please fill in the new location.', 48, 
                                 'Missing  Location Information')       this.parent.NewLoc.SetFocus  

    UPDATE table1 SET loc = this.parent.NewLoc.Value ; 
                   WHERE loc = this.parent.OldLoc.value
    UPDATE table2 SET loc = this.parent.NewLoc.Value ;
                   WHERE loc = this.parent.OldLoc.value

    ENDIF
ENDIF
ENDIF

Any input you have is appreciated!

my very basic form

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏花。依旧 2024-11-24 03:51:18

您在点击事件中做了多余的工作...关闭数据库,然后重新打开,然后打开独占。您尝试更新的表应该已经在您计划连接或搜索的关键列上有一个索引。完成后,您不需要一遍又一遍地显式创建索引标签...创建索引“TAG”后,您不需要再次执行...

因此,话虽这么说...

打开窗体,并打开“INIT”事件。在那里,您可以在使用表单时显式打开要使用的表...

IF NOT DBUSED( "Locations" )
   */ You only need exclusive if you will be modifying the database.
   */ The indexes should already exist before the form ever starts
   Open Database Locations\Locations SHARED
ENDIF

现在,更新按钮的“CLICK”事件...预先验证是否有值,不用担心尝试寻找或更新,除非两者都已填写...

IF    ALLTRIM( This.Parent.OldLoc.Value ) == "";
   OR ALLTRIM( This.Parent.NewLoc.Value ) == ""
   */ Simple one message about BOTH being required
   messagebox( "Please fill in both Old and New Locations.", 48, ;
      "Missing Location Information" )
ENDIF

*/ Then, update... if no entries match, no records will be updated.
*/ VFP sometimes chokes with multiple "." values such as form values 
*/ as SQL commands are expecting "alias.field" format... 
lcOldValue = This.Parent.OldLoc.Value
lcNewValue = This.Parent.NewLoc.Value


Update Locations!Table1;
   set Loc = lcNewLoc;
   where Loc = lcOldLoc

*/ Were there any updates?
llAnyUpdates = _Tally > 0

*/ Now, the OTHER table too...
Update Locations!Table1;
   set Loc = lcNewLoc;
   where Loc = lcOldLoc

*/ Were there any updates on THIS cycle...
llAnyUpdates = llAnyUpdates OR _Tally > 0

if llAnyUpdates
   messagebox( "Locations have been updated.", 0, "Update complete" )
else
   messagebox( "No such location found to be updated.", 0, "No Records Updated" )
endif

you are doing redundant work in your click event... Closing the database, then re-opening, then opening exclusive. The tables you are trying to update, should already have an index on the key columns you ever plan to join or search based on. Once that is done, you don't need to explicitly create the index tag over and over... Once an index "TAG" is created, you don't need to do again..

So, that being said...

Open the form, and open the "INIT" event. In there, that is where you can explicitly open the tables for use while the form is in use...

IF NOT DBUSED( "Locations" )
   */ You only need exclusive if you will be modifying the database.
   */ The indexes should already exist before the form ever starts
   Open Database Locations\Locations SHARED
ENDIF

Now, the "CLICK" event of your update button... Pre-validate that there are values, don't worry about trying to seek or update unless BOTH are filled in...

IF    ALLTRIM( This.Parent.OldLoc.Value ) == "";
   OR ALLTRIM( This.Parent.NewLoc.Value ) == ""
   */ Simple one message about BOTH being required
   messagebox( "Please fill in both Old and New Locations.", 48, ;
      "Missing Location Information" )
ENDIF

*/ Then, update... if no entries match, no records will be updated.
*/ VFP sometimes chokes with multiple "." values such as form values 
*/ as SQL commands are expecting "alias.field" format... 
lcOldValue = This.Parent.OldLoc.Value
lcNewValue = This.Parent.NewLoc.Value


Update Locations!Table1;
   set Loc = lcNewLoc;
   where Loc = lcOldLoc

*/ Were there any updates?
llAnyUpdates = _Tally > 0

*/ Now, the OTHER table too...
Update Locations!Table1;
   set Loc = lcNewLoc;
   where Loc = lcOldLoc

*/ Were there any updates on THIS cycle...
llAnyUpdates = llAnyUpdates OR _Tally > 0

if llAnyUpdates
   messagebox( "Locations have been updated.", 0, "Update complete" )
else
   messagebox( "No such location found to be updated.", 0, "No Records Updated" )
endif
情徒 2024-11-24 03:51:18

您可能还想查看表单的数据环境。
您可以选择表单加载时要打开的表,这样可以在表单加载事件或表单初始化事件中显式打开它们,

我对“更新位置”按钮的单击事件的简陋提供是:-

LOCAL lcOldLoc,lcNewLoc
WITH THISFORM
    lcOldLoc=.oldloc.VALUE
    lcNewLoc=newloc.VALUE
    DO CASE
        CASE EMPTY(lcOldLoc)
            MESSAGEBOX("PLEASE ENTER OLD LOCATION",16,"ERROR")
        CASE EMPTY(lcNewLoc)
            MESSAGEBOX("NEW LOCATION CAN'T BE EMPTY",16,"ERROR")
        OTHERWISE
            UPDATE table1 SET loc=lcNewLoc WHERE loc=lcOldLoc
            DO CASE
                CASE _TALLY=0
                    MESSAGEBOX("OLD LOCATION NOT FOUND",16,"ERROR")
                OTHERWISE
                    UPDATE tabel2 SET loc=lcNewLoc WHERE loc=lcOldLoc
            ENDCASE
    ENDCASE
ENDWITH

这应该是唯一需要的代码。显然,可以对上述内容进行许多改进,但本质上就可以完成这项工作。

如果您想查看从头开始构建的上述表单,请发送一封电子邮件至 [email protected ]我会给你一个直播示范。

You might also want to take a look at the data environment of the form.
You can select which tables the form is to open when the form loads, this saves explicitly opening them either in the forms load event or in the forms init event

My humble offering for the Click Event of the 'Update Locations' button is :-

LOCAL lcOldLoc,lcNewLoc
WITH THISFORM
    lcOldLoc=.oldloc.VALUE
    lcNewLoc=newloc.VALUE
    DO CASE
        CASE EMPTY(lcOldLoc)
            MESSAGEBOX("PLEASE ENTER OLD LOCATION",16,"ERROR")
        CASE EMPTY(lcNewLoc)
            MESSAGEBOX("NEW LOCATION CAN'T BE EMPTY",16,"ERROR")
        OTHERWISE
            UPDATE table1 SET loc=lcNewLoc WHERE loc=lcOldLoc
            DO CASE
                CASE _TALLY=0
                    MESSAGEBOX("OLD LOCATION NOT FOUND",16,"ERROR")
                OTHERWISE
                    UPDATE tabel2 SET loc=lcNewLoc WHERE loc=lcOldLoc
            ENDCASE
    ENDCASE
ENDWITH

This should be the only code required. Clearly there are many improvements that can be made to the above , but in essence that will do the job.

If you would like to see the above form built from scratch, pop an email to [email protected] and I will give you a live demonstration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文