扩展现有事件 [英] Extend existing event

查看:29
本文介绍了扩展现有事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行现有操作后,我需要执行更多操作.例如,在分销 > 销售订单 > 发货 > 操作 > 确认发货后,我需要将所有跟踪编号填充到另一个文本框中.请提出建议.

I need to perform more action after the existing action is performed. For example, After Distribution > Sales Orders > Shipment > Action > Confirm Shipment, I need to populate all tracking numbers into another text box. Please suggest.

推荐答案

在我看来,这里最好的事情是覆盖 stock 方法的逻辑.这将允许您在不接触基本方法的情况下添加所需的代码,并且您可以在调用基本方法之前和之后验证信息.

The best thing here in my opinion would be to override the logic of the stock method. That will allow you to add your needed code without touching the base method as well as you being able to validate information before and after the base method is called.

在您的示例中,Confirm Shipment"操作最终执行方法ConfirmShipment",其定义如下:

In the case of your example, "Confirm Shipment" action ultimately executes the method "ConfirmShipment" which is defined as below:

public virtual void ConfirmShipment(SOOrderEntry docgraph, SOShipment shiporder)
{
.....
}

为了自定义此处的逻辑,您有几个选项.

In order to customize the logic in here you have a few options.

  • 创建一个覆盖方法(添加到方法队列中,首先调用基类,然后调用所有覆盖"方法)
  • 创建一个先调用股票的方法,然后再调用您的代码.- 这实质上将替换"库存逻辑,但仍允许您调用基本方法.这样做时,您可以在调用 base 之前运行一些检查.

要进行第二个,您将执行以下操作

To do the second you would do the following

首先在您的代码中创建委托:

Create first the delegate in your code:

public delegate void ConfirmShipmentDelegate(SOOrderEntry docgraph, SOShipment shiporder)

然后定义您的覆盖方法:

Then define your override method:

[PXOverride]
public virtual void ConfirmShipment(SOOrderEntry docgraph, SOShipment shiporder, ConfirmShipmentDelegate baseMethod = null)
{
    // Call our base method first if it exists
    if (baseMethod != null) 
    {
        baseMethod(docgraph,shiporder);
    }
    // Do my stuff here
}

这里需要注意几个项目.

Couple items to note here.

  • 定义有第三个参数给我们的委托,这允许我们调用股票方法,然后做进一步的工作.它还告诉 Acumatica 框架我们的方法应该优先于库存方法.

  • The definition has a third param to our delegate, this allows us to call the stock method and then do further work. It also tells the Acumatica framework our method should take priority over the stock method.

stock 方法是从实际代码中的 baseMethod 调用中调用的.

The stock method is called from the baseMethod call in the actual code.

以这种方式创建扩展允许进行升级,而无需每次都完全重新定义您的方法.

Creating the extension this way allows for upgrades to occur without you having to totally redefine your method every time.

第二种方法只是覆盖股票代码.这是通过以下语法完成的

The second method would be just be an override of the stockcode. That is done with the following syntax

[PXOverride]
public virtual void ConfirmShipment(SOOrderEntry docgraph, SOShipment shiporder)
{}

采用这种方法时,首先调用 stock 方法,然后调用您的覆盖方法.

When taking this approach, the stock method is first called, then your override method is called.

这两个都将在定义为的图形扩展中处理:

both of these would be handled in a graph extension defined as:

public class SOShipmentEntryExt  : PXGraphExtension<SOShipmentEntry>

在尝试之前,我会查看 Wiki 中关于 PXOverride 的文章,因为它们提供了进一步的示例/情况

Before attempting either, I would look at the articles in the Wiki on PXOverride as they give further examples/situations for these

这篇关于扩展现有事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆