2017-04-20 93 views
0

我發現了有關如何覆蓋開箱即用BLC的自定義擴展的Persist()函數的信息,但找不到有關定製的BLC的任何信息。我需要在RowPersisting()開始之前將一個項目插入緩存中,但是使用public void Persist(PersistDelegate baseMethod)不起作用,因爲我沒有定義PersistDelegate對象。我收到的錯誤是:覆蓋自定義BLC中的Persist()

PX.Data.PXException:已爲數據源指定了無效類型。

有沒有辦法重寫自定義BLC中的Persist()?如果是這樣,我該怎麼做?

回答

1

重寫在自定義BLC沒有不同,那麼覆蓋在C#中的任何虛擬方法persist方法:

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(); 
    } 
    ... 
} 
+0

難道我只是需要讓.Persist();函數調用在我的邏輯結束,它繼續其正常的保存過程?我提出這個問題的原因是因爲我確實執行了覆蓋void Persist(),但它沒有執行實際的保存。 –

+0

正確的,你應該在你的邏輯之後調用'base.Persist();'來啓動實際的保存過程。 – RuslanDev