我有50多个自定义的配对字段“英寸”和“厘米”,每个字段均已启用且可编辑。如果用户更改了“厘米”和Visa诗句的值,则需要更新“英寸”。在“字段更新事件”期间,我能够在配对字段之一上使用SetValuePending,在另一个字段上使用SetValueExt来执行此操作。我的问题是,有没有一种方法可以在更高级别上执行此操作,而不必对所有100多个字段都执行Field_Updated事件。我知道公式会创建一个循环引用,因此无法使用。谢谢
您可以使用RowUpdated
事件并将旧行与新行进行比较,以检测更改了哪个字段。我同意将所有逻辑都保存在一个方法中是更好的选择。
public virtual void DAC_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
DAC row = e.Row as DAC;
DAC oldRow = e.OldRow as DAC;
if (row == null || oldRow == null) return;
// Compare old row with new row to determine which field changed
if (row.Inches != oldRow.Inches)
{
// Inches field changed, update CM value
row.CM = row.Inches * INCHES_TO_CM_CONSTANT;
}
// Add more conditions for the other fields
[..]
}
我知道公式会创建一个循环引用,所以不能使用。
是的,我也不会推荐它,但是您可以使用DAC属性设置器。
public string _Inches
public virtual string Inches
{
get
{
return this._Inches;
}
set
{
this._Inches = value;
this.CM = value * INCHES_TO_CM_CONSTANT;
}
}
对于所有解决方案(Formula / DAC属性除外),如果绝对必要,我认为应该有可能停止递归:
if (this.CM != value * INCHES_TO_CM_CONSTANT)
this.CM = value * INCHES_TO_CM_CONSTANT;
理想情况下,正确使用SetValueExt
足以停止无限循环。