我想使用PXUnboundFormula,但字段保持为0。
dac定义:
public abstract class usrTotalLignes : IBqlField { }
[PXDecimal]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Total des lignes")]
public virtual Decimal? UsrTotalLignes { get; set; }
这似乎管用。
protected virtual void POLine_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
{
POLine orderLine = (POLine)e.Row;
POOrder order = Base.Document.Current;
POOrderExt orderExt = order.GetExtension<POOrderExt>();
bool isLineUpdated = false;
if (orderLine != null)
{
orderExt.UsrTotalLignes += orderLine.OrderQty;
isLineUpdated = true;
}
if (isLineUpdated)
{
Base.Document.Update(order);
}
}
protected virtual void POLine_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
POLine newOrderLine = (POLine)e.Row;
POLine oldOrderLine = (POLine)e.OldRow;
POOrder order = Base.Document.Current;
POOrderExt orderExt = order.GetExtension<POOrderExt>();
bool isLineUpdated = false;
if (!sender.ObjectsEqual<POLine.orderQty>(newOrderLine, oldOrderLine))
{
if (oldOrderLine.OrderQty != null)
{
orderExt.UsrTotalLignes -= oldOrderLine.OrderQty;
}
if (newOrderLine.OrderQty != null)
{
orderExt.UsrTotalLignes += newOrderLine.OrderQty;
}
isLineUpdated = true;
}
if (isLineUpdated)
{
Base.Document.Update(order);
}
}
protected virtual void POLine_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
{
POLine orderLine = (POLine)e.Row;
POOrder order = Base.Document.Current;
POOrderExt orderExt = order.GetExtension<POOrderExt>();
bool isLineUpdated = false;
if (orderLine != null)
{
orderExt.UsrTotalLignes -= orderLine.OrderQty;
isLineUpdated = true;
}
if (isLineUpdated)
{
Base.Document.Update(order);
}
}
当我添加、编辑或删除一行时,它起作用。
现在我的问题是,当我想在加载页面时设置此未绑定字段的值时,我尝试了以下方法:
[PXDecimal]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Total des lignes")]
[PXUnboundFormula(typeof(POLine.orderQty), typeof(SumCalc<POOrderExt.usrTotalLignes>))]
public virtual void POOrder_UsrTotalLignes_CacheAttached(PXCache sender)
{
}
我试着:
[PXDecimal]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Total des lignes")]
[PXUnboundFormula(typeof(Sum<POLine.orderQty>), typeof(SumCalc<POOrderExt.usrTotalLignes>))]
public virtual void POOrder_UsrTotalLignes_CacheAttached(PXCache sender)
{
}
我还试图补充:
[PXParent(typeof(Select<POOrder, Where<POOrder.orderNbr, Equal<Current<POLine.orderNbr>>,
And<POOrder.orderType, Equal<Current<POLine.orderType>>>>>))]
但它只是内环和崩溃。
protected void POOrder_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
{
POOrder order = (POOrder)e.Row;
if (order == null) return;
var extension = PXCache<POOrder>.GetExtension<POOrderExt>(order);
using (PXConnectionScope cs = new PXConnectionScope())
{
extension.UsrTotalLignes = 0;
foreach(POLine line in PXSelectReadonly<POLine,
Where<POLine.orderNbr, Equal<Required<POOrder.orderNbr>>,
And<POLine.orderType, Equal<Required<POOrder.orderType>>>>>.Select(Base, order.OrderNbr, order.OrderType))
{
extension.UsrTotalLignes += line.OrderQty;
}
}
}
如果我修改了一个字段(如果我加载了一个旧的记录,在我修改它之前它不会工作,然后它会写入值),那么我如何要求UI刷新缓存的值呢?
我的错误在哪里?
编辑:
我设法让它与这个一起工作:
protected void POOrder_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
{
POOrder order = (POOrder)sender.Current;
if (order == null) return;
var extension = PXCache<POOrder>.GetExtension<POOrderExt>(order);
using (PXConnectionScope cs = new PXConnectionScope())
{
extension.UsrTotalLignes = 0;
foreach(POLine line in PXSelectReadonly<POLine,
Where<POLine.orderNbr, Equal<Required<POOrder.orderNbr>>,
And<POLine.orderType, Equal<Required<POOrder.orderType>>>>>.Select(Base, order.OrderNbr, order.OrderType))
{
extension.UsrTotalLignes += line.OrderQty;
}
}
Base.Document.Current.GetExtension<POOrderExt>().UsrTotalLignes = extension.UsrTotalLignes;
}
我不得不使用:
POOrder order = (POOrder)sender.Current;
POOrder order = (POOrder)e.Row
另外,由于某些原因,我不明白,当第一次加载的记录,它工作得很好。然后,当我更改了任何包含“commit”的字段时,它再次调用了rowSelectingEvent,这次e.row是列表中的下一个差的字段。
知道为什么会这样吗?