在自定义 BLC 中覆盖 Persist()
Overriding Persist() in Custom BLC
我找到了有关如何为开箱即用 BLC 的自定义扩展覆盖 Persist() 函数的信息,但我找不到有关自定义构建 BLC 的任何信息。我需要在 RowPersisting() 开始之前将一个项目插入到缓存中,但是使用 public void Persist(PersistDelegate baseMethod) 不起作用,因为我没有定义 PersistDelegate 对象。我收到的错误是:
PX.Data.PXException: An invalid type has been specified for the data source.
有没有办法在自定义 BLC 中覆盖 Persist()?如果可以,我该怎么做?
在自定义 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();
}
...
}
我找到了有关如何为开箱即用 BLC 的自定义扩展覆盖 Persist() 函数的信息,但我找不到有关自定义构建 BLC 的任何信息。我需要在 RowPersisting() 开始之前将一个项目插入到缓存中,但是使用 public void Persist(PersistDelegate baseMethod) 不起作用,因为我没有定义 PersistDelegate 对象。我收到的错误是:
PX.Data.PXException: An invalid type has been specified for the data source.
有没有办法在自定义 BLC 中覆盖 Persist()?如果可以,我该怎么做?
在自定义 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();
}
...
}