我在相应的AP Ref中具有AR发票和备忘录(屏幕ID AR301000)中的自定义字段。nbr。在类似的管理器中,AP帐单和调整(屏幕ID AP301000)中的另一个自定义字段(相应的AR Ref)。nbr。
我正在尝试更新AP Ref。nbr。在AR屏幕上,当用户更新AR Ref时。nbr。在AP屏幕中。
例如 -
我在AR屏幕发票0001上,我正在更新AP Ref。nbr。到ABC01。系统将使用相应的AR Ref自动更新AP Bill ABC01。nbr。用0001。
我有以下代码以实现此目的,但它陷入了无限循环,因为这两者都试图在其他屏幕中更新相应的字段。让我知道我是否缺少任何东西或有更好的方法。
在AR图扩展上
public class ARInvoiceEntryExtension : PXGraphExtension<ARInvoiceEntry>
{
protected virtual void ARInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
var row = (ARInvoice)e.Row;
if (row != null && sender.IsDirty)
{
ARRegisterExtension ext = PXCache<ARRegister>.GetExtension<ARRegisterExtension>(row);
if (ext != null && !string.IsNullOrEmpty(ext.UsrAPRefNbr))
{
APInvoiceEntry graph = PXGraph.CreateInstance<APInvoiceEntry>();
APInvoice apRow = PXSelect<APInvoice,
Where<APInvoice.refNbr, Equal<Required<APInvoice.refNbr>>>>.Select(graph, ext.UsrAPRefNbr);
if (apRow != null)
{
APRegisterExtension ext1 = PXCache<APRegister>.GetExtension<APRegisterExtension>(apRow);
if (ext1 != null && string.IsNullOrEmpty(ext1.UsrARRefNbr)) //Update only if it is empty
{
ext1.UsrARRefNbr = row.RefNbr;
graph.Document.Current = apRow;
graph.Caches[typeof(APRegister)].SetValue<APRegisterExtension.usrARRefNbr>(apRow, row.RefNbr);
graph.Caches[typeof(APRegister)].Update(apRow);
graph.Actions.PressSave();
}
}
}
}
}
}
在AP Graph Extension上
public class APInvoiceEntryExtension : PXGraphExtension<APInvoiceEntry>
{
protected virtual void APInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
var row = (APInvoice)e.Row;
if (row != null && sender.IsDirty)
{
APRegisterExtension ext = PXCache<APRegister>.GetExtension<APRegisterExtension>(row);
if (ext != null && !string.IsNullOrEmpty(ext.UsrARRefNbr))
{
ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();
ARInvoice arRow = PXSelect<ARInvoice,
Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>.Select(graph, ext.UsrARRefNbr);
if (arRow != null)
{
ARRegisterExtension ext1 = PXCache<ARRegister>.GetExtension<ARRegisterExtension>(arRow);
if (ext1 != null && string.IsNullOrEmpty(ext1.UsrAPRefNbr)) //Update only if it is empty
{
ext1.UsrAPRefNbr = row.RefNbr;
graph.Document.Current = arRow;
graph.Caches[typeof(ARRegister)].SetValue<ARRegisterExtension.usrAPRefNbr>(arRow, row.RefNbr);
graph.Caches[typeof(ARRegister)].Update(arRow);
graph.Actions.PressSave();
}
}
}
}
}
}
AR缓存扩展
public class ARRegisterExtension : PXCacheExtension<ARRegister>
{
public abstract class usrAPRefNbr : PX.Data.IBqlField
{
}
protected string _usrAPRefNbr;
[PXDBString(15)]
[PXUIField(DisplayName = "AP Ref Nbr.", Visibility = PXUIVisibility.SelectorVisible)]
[APInvoiceType.RefNbr(typeof(Search3<PX.Objects.AP.Standalone.APRegisterAlias.refNbr,
InnerJoinSingleTable<APInvoice, On<APInvoice.docType, Equal<PX.Objects.AP.Standalone.APRegisterAlias.docType>,
And<APInvoice.refNbr, Equal<PX.Objects.AP.Standalone.APRegisterAlias.refNbr>>>,
InnerJoinSingleTable<Vendor, On<PX.Objects.AP.Standalone.APRegisterAlias.vendorID, Equal<Vendor.bAccountID>>>>,
OrderBy<Desc<APRegister.refNbr>>>))]
public virtual string UsrAPRefNbr
{
get; set;
}
}
ap缓存扩展
public class APRegisterExtension : PXCacheExtension<APRegister>
{
public abstract class usrARRefNbr : PX.Data.IBqlField
{
}
protected string _usrARRefNbr;
[PXDBString(15)]
[PXUIField(DisplayName = "AR Ref Nbr.", Visibility = PXUIVisibility.SelectorVisible)]
[ARInvoiceType.RefNbr(typeof(Search3<PX.Objects.AR.Standalone.ARRegisterAlias.refNbr,
InnerJoinSingleTable<ARInvoice, On<ARInvoice.docType, Equal<PX.Objects.AR.Standalone.ARRegisterAlias.docType>,
And<ARInvoice.refNbr, Equal<PX.Objects.AR.Standalone.ARRegisterAlias.refNbr>>>,
InnerJoinSingleTable<Customer, On<PX.Objects.AR.Standalone.ARRegisterAlias.customerID, Equal<Customer.bAccountID>>>>,
OrderBy<Desc<ARRegister.refNbr>>>))]
public virtual string UsrARRefNbr
{
get; set;
}
}
保存时,apinvoice_rowupped修改了arinvoice,进而修改apinvoice,触发apinvoice_rowupped at taged apinvoe_rowupped产生了事件呼叫的无限环路。ARINVOICE_ROWUPED的倒数更新Apinvoice将导致类似的无限循环。
为了摆脱此功能,您可以在实例化图表后在运行时删除图形事件处理程序。首先使您的活动处理程序访问修饰符公开,因此您可以参考:
public virtual void APInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
创建图形后,获取扩展名并删除导致无限循环的处理程序:
APInvoiceEntry graph = PXGraph.CreateInstance<APInvoiceEntry>();
APInvoiceEntryExtension graphExt = graph.GetExtension<APInvoiceEntryExtension>();
graphExt.RowUpdated.RemoveHandler<APInvoice>(graphExt.APInvoice_RowUpdated);
必须对Arinvoice进行相同的修改,因为无限循环从AP到AR到AR到AP。