从图形保存到其他表(DAC) [英] Save in other tables (DACs) from a Graph
问题描述
假设我有三个数据库表。表1,表2,表3。我已经为每个Graph1,Graph2和Graph3创建了它们的DAC及其对应的图形。
Let's say that I have three database tables. Table1, Table2, Table3. I have created their DACs and their corresponding graph for each Graph1, Graph2, and Graph3.
现在,我为Graph1创建了一个屏幕,其中显示了Table1中的数据。但是,当用户单击此屏幕上的特定操作按钮时,我想将数据保存在表2和3中。我想在每个表中插入多个记录。
Now I have created a screen for Graph1 which is showing data from Table1. But when a user clicks a particular Action Button in this screen, I want to save data in Tables 2 and 3. I want to insert multiple records in each table.
I不要认为在表1中将Tables2和Table 3添加为数据视图(PXSelect属性)是没有意义的,因为它们仅在用户触发操作时才使用。
I don't think it makes sense to add Tables2 and Table 3 as Data Views (PXSelect properties) in Graph 1 because they will only be used when the user triggers the Action.
在Acumatica中实现此目标的推荐方法是什么?例如,应该使用PXDatabase.Update还是创建Graph2和Graph3的实例,在它们的数据视图上调用update并调用PressSave?另外,是否可以将所有内容包装在PXTransactionScope中?
What's the recommended way to achieve this in Acumatica? For example, should I use PXDatabase.Update or should I create an instance of Graph2 and Graph3, call update on their Data Views and call PressSave? Also, would it be possible to wrap everything in a PXTransactionScope?
推荐答案
请在下面找到一个代码示例,该示例显示如何保存更改。来自多个BLC实例的单个交易:
Please find below a code sample showing how to save changes in a single transaction from multiple BLC instances:
public class MyGraph1 : PXGraph<MyGraph1>
{
public PXAction<MyDAC> MultiGraphAction;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "My Magic Action")]
protected virtual void multiGraphAction()
{
using (var ts = new PXTransactionScope())
{
// To save changes made in MyGraph1
Actions.PressSave();
// To save changes in MyGraph2
var myGraph2 = PXGraph.CreateInstance<MyGraph2>();
// Place here data manipulation logic for myGraph2
myGraph2.Actions.PressSave();
// To save changes in MyGraph2
var myGraph3 = PXGraph.CreateInstance<MyGraph3>();
// Place here data manipulation logic for myGraph3
myGraph3.Actions.PressSave();
ts.Complete();
}
}
}
这篇关于从图形保存到其他表(DAC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!