Acumatica SOOrder上未绑定的用户字段
我在SOOrder DAC扩展上有一个用户字段,它是文档中一些行的总和(基于SOLine扩展中的一个字段)。当我添加新行时,总数正在正确更新。但是,当我第一次加载文档时,屏幕显示为0.00。我创建了一个SOOrderEntry扩展,并将代码放入SOLine_RowSelecting事件处理程序中。当我加载文档时,它会进入代码,看起来它正在正确设置字段,但它们不会显示在屏幕上。从SOLine_CuryLineAmt_字段updated调用相同的方法,效果很好。以下是我正在使用的代码:Acumatica SOOrder上未绑定的用户字段,acumatica,Acumatica,我在SOOrder DAC扩展上有一个用户字段,它是文档中一些行的总和(基于SOLine扩展中的一个字段)。当我添加新行时,总数正在正确更新。但是,当我第一次加载文档时,屏幕显示为0.00。我创建了一个SOOrderEntry扩展,并将代码放入SOLine_RowSelecting事件处理程序中。当我加载文档时,它会进入代码,看起来它正在正确设置字段,但它们不会显示在屏幕上。从SOLine_CuryLineAmt_字段updated调用相同的方法,效果很好。以下是我正在使用的代码: public
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
//Used to prevent recursive calls in RowSelecting
bool _isCalculating = false;
protected virtual void SOLine_RowSelecting(PXCache cache, PXRowSelectingEventArgs e)
{
var row = e.Row as SOLine;
if (row == null) return;
using (new PXConnectionScope())
{
if (!_isCalculating)
CalcTotals();
}
}
protected virtual void SOLine_CuryLineAmt_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
if (!_isCalculating)
CalcTotals();
}
public void CalcTotals()
{
SOOrder order = Base.CurrentDocument.Select();
if (order == null) return;
_isCalculating = true;
var orderExt = order.GetExtension<SOOrderExt>();
orderExt.UsrMyCustomField = 0m;
//Get totals
foreach (SOLine lineSum in Base.Transactions.Select())
{
var lineSumExt = lineSum.GetExtension<SOLineExt>();
if (lineSumExt.UsrMyCondition)
orderExt.UsrMyCustomField += lineSum.CuryLineAmt;
}
_isCalculating = false;
}
}
公共类SOOrderEntryExt:PXGraphExtension
{
//用于防止行选择中的递归调用
bool _isCalculating=false;
受保护的虚拟void SOLine_行选择(PXCache缓存、PXRowSelectingEventArgs e)
{
var row=e.作为SOLine的行;
if(row==null)返回;
使用(新的PXConnectionScope())
{
如果(!\u正在计算)
CalcTotals();
}
}
受保护的虚拟void SOLine\u CuryLineAmt\u FieldUpdated(PXCache缓存,PXFieldUpdatedEventArgs e)
{
如果(!\u正在计算)
CalcTotals();
}
公共无效CalcTotals()
{
SOOrder order=Base.CurrentDocument.Select();
if(order==null)返回;
_正在计算=正确;
var orderExt=order.GetExtension();
orderExt.UsrMyCustomField=0m;
//得到总数
foreach(Base.Transactions.Select()中的SOLine lineSum)
{
var lineSumExt=lineSum.GetExtension();
if(lineSumExt.UsrMyCondition)
orderExt.UsrMyCustomField+=lineSum.CuryLineAmt;
}
_正在计算=错误;
}
}
- 在每次回调时调用RowSelected以选择数据。也不需要在FieldUpdated事件上重新计算,因为更新记录时将调用RowSelected。因此考虑去除SOLYN-CuryLeNAMTFieldfield更新
- 您已经为SOLine DAC声明了RowSelected事件。然后,事件选择所有SOLine以计算总数。这相当于当选择一个细节计算所有细节的总和时,缺少递归模式。因此,请考虑在主文档中声明行选择,在这种情况下是SOORD,并移除所有必须中断递归的解决方案。
- 计算中没有空的签入。Acumatica DAC字段可为空。在代码中,您可能会遇到这样的情况:将null添加到一个数字中,这将导致在运行时发生类型冲突。因此,在使用它的值来计算总数之前,请考虑检查CuryLineAmt是否为空。
- 您正在UsrMyCustomField DAC字段中累积总数
使用+=加法赋值运算符。这是可行的,但我会的
建议不要那样做。DAC字段并不表示为的寄存器
计算或临时值占位符。因此考虑
将总数累加到局部变量中,并仅指定最终值
DAC字段的计算值
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public void SOOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
SOOrder order = e.Row as SOOrder;
if (order != null)
{
SOOrderExt orderExt = order.GetExtension<SOOrderExt>();
if (orderExt != null)
{
decimal total = 0M;
foreach (SOLine line in Base.Transactions.Select())
{
total += line.CuryLineAmt.HasValue ? line.CuryLineAmt.Value : 0M;
}
orderExt.UsrMyCustomField = total;
}
}
}
}
公共类SOOrderEntryExt:PXGraphExtension
{
public void SOOrder_row selected(PXCache缓存,PXRowSelectedEventArgs e)
{
SOOrder order=e.行作为SOOrder;
如果(订单!=null)
{
soorderextorderext=order.GetExtension();
if(orderExt!=null)
{
小数总数=0米;
foreach(Base.Transactions.Select()中的SOLine行)
{
合计+=line.CuryLineAmt.HasValue?line.CuryLineAmt.Value:0M;
}
orderExt.UsrMyCustomField=总计;
}
}
}
}
谢谢@HB_Acumatica的帮助。我不想把它放在SOOrder_RowSelected中,因为RowSelected被命中的次数太多了。但是,将其放入行选择中不会加载Base.Transactions。所以我把它放在RowSelected中,它看起来仍然在快速计算。我还按照建议用局部变量替换了总数,因为缓存处理这些变量的方式是合理的。