我在SOShipment和SOShipmentFilter中添加了一个新的自定义字段。我正在尝试使用它来过滤处理货件的网格,我遇到了代码问题。我已经做了其他自定义,我有扩展代码,但我能够先调用baseHandler,然后在返回时执行我的代码片段。但是当我覆盖委托函数时,它只是设置一个返回baseMethod的模板。当我将代码放入包含新的过滤器字段时,我得到未定义字段/引用的编译错误。我是否需要从原始委托中复制所有原始代码并将其包含在我的覆盖功能中?以下是我当前的覆盖代码:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.IN;
using PX.Objects.AR;
using PX.Objects.CM;
using POReceipt = PX.Objects.PO.POReceipt;
using POReceiptLine = PX.Objects.PO.POReceiptLine;
using POLineType = PX.Objects.PO.POLineType;
using PX.Objects;
using PX.Objects.SO;
namespace PX.Objects.SO
{
public class SOInvoiceShipment_Extension:PXGraphExtension<SOInvoiceShipment>
{
#region Event Handlers
public delegate IEnumerable ordersDelegate();
[PXOverride]
public IEnumerable orders(ordersDelegate baseMethod)
{
if (filter.usrTruckNbr != null)
{
((PXSelectBase<SOShipment>)cmd).WhereAnd<Where<SOShipment.usrTruckNbr, GreaterEqual<Current<SOShipmentFilter.usrTruckNbr>>>>();
}
return baseMethod();
}
protected virtual void SOShipmentFilter_UsrTruckNbr_CacheAttached(PXCache cache)
{
}
#endregion
}
}
答案 0 :(得分:2)
cmd
是位置变量,您无法通过扩展程序访问它。我看到两种方法可以达到你想要的结果:
在从原始委托返回但在屏幕上显示之前,在客户端上过滤数据。这不如过滤SQL有效,但至少不需要将太多代码复制到您的扩展。这是一个完整的样本,它将过滤货件清单,仅返回货件数量均匀的文件:
public class SOInvoiceShipment_Extension : PXGraphExtension<SOInvoiceShipment>
{
[PXFilterable]
public PXFilteredProcessing<SOShipment, SOShipmentFilter> Orders;
protected IEnumerable orders()
{
// Filter the list of shipments to return only documents where shipment quantity is even
foreach (SOShipment shipment in Base.Orders.Select())
{
if(shipment.ShipmentQty % 2 == 0)
{
yield return shipment;
}
}
}
public void SOShipmentFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
if (e.Row == null) return;
SOShipmentFilter filter = e.Row as SOShipmentFilter;
if (filter != null && !string.IsNullOrEmpty(filter.Action))
{
Dictionary<string, object> parameters = Base.Filter.Cache.ToDictionary(filter);
Orders.SetProcessTarget(null, null, null, filter.Action, parameters);
}
}
}
在所有情况下,您都不应该使用PXOverride来覆盖视图委托;遗憾的是,当您尝试覆盖委托时,自定义工具会生成错误的方法签名,这将得到改进。有关此类自定义的更多信息,请参阅可用的T300培训here(查找“声明或更改BLC数据视图委托”)。