c# - 如何确定更新 DAC 字段的正确方法?

标签 c# acumatica

在更新记录值时,我无法确定何时使用 e.Row 属性或 cache.SetValue/SetValueExt。在 T200 类(class)中,pdf 中有一部分是这样说的,

To update a field that is defined after the current field in the data access class, use the properties of the e.Row data record as follows.

ShipmentLine line = e.Row as ShipmentLine;
...
line.Description

To update a field that is defined before the current field in the data access class, use the SetValueExt<>() method:

sender.SetValueExt<ShipmentLine.ProductID>(e.Row, GiftCardID);

在这些情况下,当他们说“之前”和“之后”时,他们指的是什么?如果我的 DAC 字段声明按以下顺序:

Field1 {get;set;}
Field2 {get;set;}
Field3 {get;set;}

他们的字面意思是,如果我在“Field2.FieldUpdated()”中,我必须像这样更新 Field1 和 Field3 吗?

sender.SetValueExt<ShipmentLine.Field1>(e.Row, "X");
line.Field3 = "X";

此外,对于何时使用哪种方法是否有一些硬性规定? IE。如果在 RowUpdated 事件中,使用“X”,如果在 FieldUpdated 事件中,使用“Y”。

最佳答案

您将主要遇到三种类型的赋值:

 1. record.Field = "value"
 2. cache.SetValue<T>
 3. cache.SetValueExt<T>

方法一和方法二本质上是一样的。他们在不引发事件的情况下分配值。实际区别在于使用方法 2 可以避免转换。

// 1. With cast
ShipmentLine line = e.Row as ShipmentLine;

if (line != null)
{
    line.Description = "value";
}

// 2. Without cast
sender.SetValue<ShipmentLine.description>(e.Row, "value");

当您希望分配引发 FieldUpdated 事件时,应使用 SetValueExt。当用户更改其值时,UI 上的许多字段都会引发事件。如果用户更改销售订单的数量字段,它将引发 FieldUpdated 事件,该事件将重新计算总价。

如果您要通过代码以编程方式更改数量,您应该使用 SetValueExt,因为它将确保使用事件系统重新计算总成本。当您尝试复制用户在屏幕上的操作时,它特别有用,因为 UI 默认控制所有引发事件。

关于c# - 如何确定更新 DAC 字段的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56346424/

相关文章:

acumatica - 如何在 Acumatica 中使用推送通知?

c# - ASP.net 在服务引用之间重用类型

acumatica - 回发后如何继续关注 PXNumberEdit 字段?

c# - 在回调方法中模拟参数

c# - #nullable disable - 仅适用于特定的命名空间?

acumatica - 自定义选择器的挑战

erp - 刷新 Acumatica 中的 View

c# - 使用 51degrees.mobi 进行平板电脑与手机检测

c# - 自动重构为 string.Format

c# - linq 异常 : This function can only be invoked from LINQ to Entities