簡體   English   中英

需要攜帶銷售訂單用戶字段的幫助才能創建采購訂單屏幕

[英]Need help carrying Sales Order user fields to Create Purchase order screen

我有一個自定義項,在其中我向銷售訂單(SO301000)屏幕交易網格中添加了三個用戶字段。 我想在“創建采購訂單”屏幕(PO505000)上設置字段。 我使用了POFixedDemand的'RowSelected'事件,該事件運行良好-但是,當任何人嘗試連續修改任何內容時,都會引起問題-重新觸發該事件-而不是期望的結果。

我已經嘗試了'RowInserting'和'RowInserted'事件-但它們從未觸發過。 我假設此時,我將不得不在“ POCreate” BLC中截取一些代碼,以在“創建采購訂單”屏幕中創建POFixedDemand記錄-但我真的不知道從哪里開始。 我可以將它放在EnumerateAndPrepareFixedDemands方法中的某個地方嗎?

這是我創建的代碼,該代碼適用於RowSelected事件,但不適用於用戶修改行的情況。 任何幫助表示贊賞。 謝謝。

    protected virtual void POFixedDemand_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
    {
        var pofd = (POFixedDemand)e.Row;
        if (pofd == null) return;

        var filter = Base.Filter.Current;
        var ordernbr = filter.OrderNbr;
        var ordertype = filter.OrderType;

        var solinesplit = (SOLineSplit)PXSelect<SOLineSplit, Where<SOLineSplit.planID, Equal<Required<SOLineSplit.planID>>>>.Select(Base, pofd.PlanID);
        if (solinesplit != null)
        {
            var soline = (SOLine)PXSelect<SOLine,
                                 Where<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
                                 And<SOLine.orderType, Equal<Required<SOLine.orderType>>,
                                 And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>.Select(Base, solinesplit.OrderNbr, solinesplit.OrderType, solinesplit.LineNbr);

            if (soline != null)
            {
                var solineext = PXCache<SOLine>.GetExtension<SOLineExt>(soline);
                pofd.VendorID = solineext.UsrVendor;
                pofd.EffPrice = solineext.UsrVendorUnitCost;
                pofd.ExtCost = solineext.UsrVendorExtendedCost;

                //Now set the Vendor location...
                var location = (Location)PXSelect<Location,
                                         Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>.Select(Base, pofd.VendorID);

                if (location != null)
                {
                    pofd.LocationID = location.LocationID;
                }

            }
        }
    }

我假設此時我必須在“ POCreate” BLC中攔截一些代碼

是的,您需要按照這些原則進行操作。 對於初始化POLine而不是POFixedDemand,這里有類似的答案: https ://stackoverflow.com/a/372​​55340/7376238

經過一些小的調整,一般模式將是:

public class POCreateExt : PXGraphExtension<POCreate>
{
    public override void Initialize()
    {
        PXGraph.InstanceCreated.AddHandler<POOrderEntry>((graph) =>
        {
            graph.RowInserting.AddHandler<POFixedDemand>((sender, e) =>
            {
                // Initialize fields when row is inserted
                POFixedDemand demand = e.Row as POFixedDemand;
                demand.DACField = [initialization value];
            });

            graph.RowUpdating.AddHandler<POFixedDemand>((sender, e) =>
            {
                // Sometimes fields are updated so you need to 
                // hook RowUpdating too and re-initialize
                POFixedDemand demand = e.NewRow as POFixedDemand;
                demand.DACField = [initialization value];
            });
        });
    }
}

經過一番調查后,我想到的是重寫“ EnumerateAndPrepareFixedDemands”方法來設置值。 代碼如下:

    public delegate IEnumerable EnumerateAndPrepareFixedDemandsDelegate(PXResultset<POFixedDemand> fixedDemands);
    [PXOverride]
    public IEnumerable EnumerateAndPrepareFixedDemands(PXResultset<POFixedDemand> fixedDemands, EnumerateAndPrepareFixedDemandsDelegate baseMethod)
    {
        foreach (PXResult<POFixedDemand> rec in fixedDemands)
        {
            POFixedDemand demand = rec;

            var solinesplit = (SOLineSplit)PXSelect<SOLineSplit, Where<SOLineSplit.planID, Equal<Required<SOLineSplit.planID>>>>.Select(Base, demand.PlanID);
            if (solinesplit != null)
            {
                var soline = (SOLine)PXSelect<SOLine,
                             Where<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
                             And<SOLine.orderType, Equal<Required<SOLine.orderType>>,
                             And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>.Select(Base, solinesplit.OrderNbr, solinesplit.OrderType, solinesplit.LineNbr);
                if (soline != null)
                {
                    var solineext = PXCache<SOLine>.GetExtension<SOLineExt>(soline);
                    demand.VendorID = solineext.UsrVendor;
                    demand.EffPrice = solineext.UsrVendorUnitCost;
                    demand.ExtCost = solineext.UsrVendorExtendedCost;

                    //Now set the Vendor location...
                    var location = (Location)PXSelect<Location,
                                             Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>.Select(Base, solineext.UsrVendor);

                    if (location != null)
                    {
                        demand.VendorLocationID = location.LocationID;
                    }

                }
            }
        }

        return baseMethod(fixedDemands);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM