如何覆盖属性内的事件处理程序?

时间:2019-07-12 21:40:24

标签: acumatica

我需要在采购订单收据期间验证是否选择了正确的位置,这可能意味着临时更改在“物料仓库”屏幕上定义的“默认”位置。我的挑战是字段默认事件处理程序是在POLocationAvailAttribute属性而不是POReceiptEntry图中定义的。

public class POLocationAvailAttribute : LocationAvailAttribute
{
    public POLocationAvailAttribute(Type InventoryType, Type SubItemType, Type SiteIDType, Type TranType, Type InvtMultType)
        : base(InventoryType, SubItemType, SiteIDType, TranType, InvtMultType)
    {
    }

    public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        POReceiptLine row = e.Row as POReceiptLine;
        if (row == null) return;

        if (POLineType.IsStock(row.LineType) && row.POType != null && row.PONbr != null && row.POLineNbr != null)
        {
            POLine poLine = PXSelect<POLine, Where<POLine.orderType, Equal<Required<POLine.orderType>>,
                    And<POLine.orderNbr, Equal<Required<POLine.orderNbr>>,
                    And<POLine.lineNbr, Equal<Required<POLine.lineNbr>>>>>>.Select(sender.Graph, row.POType, row.PONbr, row.POLineNbr);

            if (poLine != null && poLine.TaskID != null)
            {
                INLocation selectedLocation = PXSelect<INLocation, Where<INLocation.siteID, Equal<Required<INLocation.siteID>>,
                    And<INLocation.taskID, Equal<Required<INLocation.taskID>>>>>.Select(sender.Graph, row.SiteID, poLine.TaskID);

                if (selectedLocation != null )
                {
                    e.NewValue = selectedLocation.LocationID;
                    return;
                }
                else
                {
                    e.NewValue = null;
                    return;
                }
            }
        }

        base.FieldDefaulting(sender, e);
    }
}

如何覆盖图形扩展中的字段默认事件,以便调用基本方法来设置默认位置,但是当我将其替换为我的“备用默认位置”时,我可以检查一下满足特定条件?

1 个答案:

答案 0 :(得分:1)

简单

首先:您使用自己的属性来破坏POLocationAvailAttribute并覆盖FieldDefaulting方法。

public class CustomPOLocationAvailAttribute : POLocationAvailAttribute
{
    public CustomPOLocationAvailAttribute(Type InventoryType, Type SubItemType, Type SiteIDType, Type TranType, Type InvtMultType)
        : base(InventoryType, SubItemType, SiteIDType, TranType, InvtMultType)
    {
    }

    public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        base.FieldDefaulting(sender, e);
        //code you may wanna implement          
    }
}

第二:扩展POReceiptLine DAC,并用自定义属性替换现有属性。

public class POReceiptLineExt : PXCacheExtension<POReceiptLine>
{
        #region LocationID
        public abstract class locationID : PX.Data.IBqlField        {       }
        [PXMergeAttributes(Method = MergeMethod.Append)]
        [PXRemoveBaseAttribute(typeof(POLocationAvailAttribute))]
        [CustomPOLocationAvail(typeof(POReceiptLine.inventoryID), typeof(POReceiptLine.subItemID), typeof(POReceiptLine.siteID), typeof(POReceiptLine.tranType), typeof(POReceiptLine.invtMult), KeepEntry = false)]
        public virtual Int32? LocationID {get; set;}
        #endregion
}

注意: 您可以覆盖属性: -在具有CacheAttached事件的“图形级”上,仅将更改应用于该屏幕。 -或在DAC级别上将更改应用于使用POReceiptLine DAC对象的所有屏幕。

现在应该工作;)