且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Acumatica框架的操作中添加自定义业务逻辑?

更新时间:2022-12-11 17:17:04

为SOOrderEntry创建图形扩展并添加如下所示的Action方法:

Create a graph extension for SOOrderEntry and add an Action method like this :

using PX.Data;
using System.Collections;

namespace PX.Objects.SO
{

    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {
        public PXAction<SOOrder> action;
        [PXUIField(DisplayName = "Actions", MapEnableRights = PXCacheRights.Select)]
        [PXButton]
        protected virtual IEnumerable Action(PXAdapter adapter,
            [PXInt]
            [PXIntList(new int[] { 1, 2, 3, 4, 5 }, new string[] { "Create Shipment", "Apply Assignment Rules", "Create Invoice", "Post Invoice to IN", "Create Purchase Order" })]
            int? actionID,
            [PXDate]
            DateTime? shipDate,
            [PXSelector(typeof(INSite.siteCD))]         
            string siteCD,
            [SOOperation.List]
            string operation,
            [PXString()]
            string ActionName)
        {
            //actionID = 1 means the CreateShipment action was the one invoked
            if (actionID == 1)
            {
                PXGraph.InstanceCreated.AddHandler<SOShipmentEntry>((graph) =>
                {
                    graph.RowInserting.AddHandler<SOShipment>((sender, e) =>
                    {
                        //Custom logic goes here
                        var shipment = (SOShipment)e.Row;
                        var shipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(shipment);
                        if (Base.Document.Current != null && shipmentExt != null)
                        {
                            shipmentExt.UsrPriority = Base.Document.Current.Priority;
                        }
                    });
                });
            }

            //calls the basic action that was invoked
            return Base.action.Press(adapter);
        }
    }
}

任何SOOrderEntry的动作是运行(甚至通过流程订单屏幕),将调用此方法。我们验证操作确实是带有 actionID == 1 的CreateShipment,并添加事件处理程序以用于SOShipmentEntry图形创建和SOShipment RowInserting。我们的自定义逻辑已添加到RowInserting事件中。

When any of SOOrderEntry's actions is run (even through the Process Orders screen), this method is invoked. We verify that the action really is CreateShipment with the actionID == 1 and add events handler for SOShipmentEntry graph creation and SOShipment RowInserting. Our custom logic is added inside the RowInserting event.