在用户退出之前以编程方式保存的正确方法是什么? [英] What is the proper way to programmatically save before a user exits?

查看:75
本文介绍了在用户退出之前以编程方式保存的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为,类似于此的代码都是保存的正确方法:

I see code similar to this all over as the proper way to save:

myapp.applyChanges().then(screen.LineItemsByQuote.load(), function fail(e) {
    msls.showMessageBox(e.message, { title: e.title }).then(function () {
        myapp.discardChanges();
        throw e;
    });
});


我在纯粹用代码创建和保存实体时遇到了一些麻烦.事实证明,该问题与此无关.但是在尝试找出问题的过程中,我将以下代码直接添加到先前的保存代码下面,以尝试强制执行 之所以要保存,是因为它一直命中DiscardChanges:

I was having some trouble with creating and saving an entity purely in code. The problem turned out not to be related to this. But in the course of trying to figure it out, I added the following code directly below the previous save code to try and force the save because it kept hitting discardChanges:

myapp.activeDataWorkspace.aris_dbData.saveChanges().then(function () {
    screen.LineItemsByQuote.load();
});

这和其他一些事情起作用了.第一次运行时,它将添加两个实体.此后只有一个. 

This and a few other things got it to work, sort of. The first time it would run, it would add two entities. Thereafter only one. Removing one or the other of the above snippets got rid of the double entry problem. But when I try to exit the program, it tells me I have unsaved changes.

然后我被旁白了一位同事,必须将C ++模板安装到Visual Studio中.当然,这首先失败了 时间.修复并返回我的项目后,我注意到现在throwChanges不再是myapp中的有效函数,如果被击中,它将导致异常.

I then got sidetracked by a colleague and had to install the C++ templates into Visual Studio. This, of course, failed the first time. After the repair and getting back to my project, I noticed that now discardChanges is no longer a valid function in myapp and if it was ever hit, it caused an exception.

所以我现在有两个需要解决的问题.首先,displacedChanges去了哪里?我需要它,因为我不想向后导航 到带有cancelChanges的上一个屏幕.

So now I have two problems that need solving. The first, where did discardChanges go? I need it because I don't want to navigate back to the previous screen with cancelChanges.

第二,我如何最终确定保存所做的更改,以便用户无需退出即可轻松退出丢失数据而没有提示保存?

推荐答案

您尝试使用.refresh( )而不是.load()?

Did you try using .refresh() instead of .load()? 

如果表与同一屏幕上的另一个父/子表有关系,并且该表的数据也有变化,则在activeDataWorkspace中的特定表上使用saveChanges()可能会导致部分问题.使用myapp.applyChanges()或myapp.commitChanges() (以便在完成操作后再返回),以确保正确保存更改.因此,当两个表位于完全不同的数据源中(例如ApplicationData和 另一个SQL Server上),您必须重写save方法以将两个数据源的Promise加入,以便两个Promise必须先完成,然后才能被视为已解决.

Using saveChanges() on a specific table in the activeDataWorkspace may be causing part of the problem, if the table has a relation to another parent/child table on the same screen that also has a change in its data. Using myapp.applyChanges() or myapp.commitChanges() (to navigate back upon completion) is preferred in order to make sure that the changes are saved appropriately. There used to be an issue when two tables are in completely different datasources (like one in ApplicationData and the other on another SQL Server) where you had to override the save method to join the promises for both datasources so that both promises must complete before they are considered resolved.


这篇关于在用户退出之前以编程方式保存的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆