【问题标题】:Overriding Persist() in Custom BLC在自定义 BLC 中覆盖 Persist()
【发布时间】:2017-04-20 18:55:03
【问题描述】:

我找到了有关如何为开箱即用的 BLC 的自定义扩展覆盖 Persist() 函数的信息,但我找不到任何关于自定义构建的 BLC 的信息。我需要在 RowPersisting() 开始之前将一个项目插入缓存,但是使用 public void Persist(PersistDelegate baseMethod) 不起作用,因为我没有定义 PersistDelegate 对象。我收到的错误是:

PX.Data.PXException: 为数据源指定了无效类型。

有没有办法在自定义 BLC 中覆盖 Persist()?如果是这样,我该怎么做?

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    在自定义 BLC 中覆盖 Persist 方法与在 C# 中覆盖任何虚拟方法没有什么不同:

    public class ARSalesPriceMaint : PXGraph<ARSalesPriceMaint>
    {
        ...
        public override void Persist()
        {
            foreach (ARSalesPrice price in Records.Cache.Inserted)
            {
                ARSalesPrice lastPrice = FindLastPrice(this, price);
                if (lastPrice?.EffectiveDate > price.EffectiveDate && price.ExpirationDate == null)
                {
                    Records.Cache.RaiseExceptionHandling<ARSalesPrice.expirationDate>(price, price.ExpirationDate, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName<ARSalesPrice.expirationDate>(Records.Cache)));
                    throw new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName<ARSalesPrice.expirationDate>(Records.Cache));
                }
                ValidateDuplicate(this, Records.Cache, price);
            }
            foreach (ARSalesPrice price in Records.Cache.Updated)
            {
                ARSalesPrice lastPrice = FindLastPrice(this, price);
                if (lastPrice?.EffectiveDate > price.EffectiveDate && price.ExpirationDate == null)
                {
                    Records.Cache.RaiseExceptionHandling<ARSalesPrice.expirationDate>(price, price.ExpirationDate, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName<ARSalesPrice.expirationDate>(Records.Cache)));
                    throw new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName<ARSalesPrice.expirationDate>(Records.Cache));
                }
                ValidateDuplicate(this, Records.Cache, price);
            }
            base.Persist();
        }
        ...
    }
    

    【讨论】:

    • 我只需要制作 .Persist();在我的逻辑结束时调用函数以继续其正常的保存过程?我提出这个的原因是因为我确实做了覆盖 void Persist(),但它不再执行实际的保存了。
    • 正确,你应该在你的逻辑之后调用base.Persist();来启动实际的保存过程。
    猜你喜欢
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2015-02-12
    • 2019-02-12
    • 2013-05-05
    • 1970-01-01
    相关资源
    最近更新 更多