首页 > 解决方案 > 如何覆盖属性内的事件处理程序?

问题描述

我需要在采购订单接收期间验证选择的正确位置,这可能意味着临时更改项目仓库屏幕上定义的“默认”位置。我的挑战是字段默认事件处理程序是在 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);
    }
}

如何在我的图形扩展中覆盖字段默认事件,以便调用基本方法来设置默认位置,但是当我的特定条件是时,我可以检查它是否需要切换到我的“备用默认位置”见过?

标签: acumatica

解决方案


简单的

首先:您使用自己的属性从 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 对象的所有屏幕。

现在应该工作;)


推荐阅读