覆盖自定义BLC中的Persist()

时间:2017-04-20 18:55:03

标签: acumatica

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

  

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

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

1 个答案:

答案 0 :(得分: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();
    }
    ...
}