自定义属性构造函数 - PXCustomSelectorAttribute
Custom attribute constructor - PXCustomSelectorAttribute
美好的一天
我已经为销售订单上的客户 ID 属性创建了一个自定义属性。
使用客户 ID 的当前属性,处于信用保留状态的客户不会显示在列表中。
我的想法是动态更改列表,这样如果订单类型为 QT,处于信用暂停状态的客户仍会显示在列表中。
我的问题是我不知道是否有办法 send/get 当前 SOOrder.OrderType
这是我所在的地方
namespace PX.Objects.SO
{
[PXNonInstantiatedExtension]
public class SO_SOOrder_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOOrder>
{
#region CustomerID
[PXMergeAttributes(Method = MergeMethod.Append)]
// [CustomercustomersAttribute(Current<SOOrder.orderType>))]
[CustomercustomersAttribute()]
public int? CustomerID { get; set; }
#endregion
}
public class CustomercustomersAttribute : PXCustomSelectorAttribute
{
public string orderType { get; set; }
public Type orderType2 { get; set; }
public CustomercustomersAttribute(Type OrderType) : base(typeof(Customer.acctCD))
{
this.orderType2 = OrderType;
this.DescriptionField = typeof(Customer.acctName);
}
public CustomercustomersAttribute(string OrderType) : base(typeof(Customer.acctCD))
{
this.orderType = OrderType;
this.DescriptionField = typeof(Customer.acctName);
}
public CustomercustomersAttribute() : base(typeof(Customer.acctCD))
{
this.DescriptionField = typeof(Customer.acctName);
}
protected virtual IEnumerable GetRecords()
{
foreach (Customer pc in PXSelect<Customer>.Select(this._Graph))
{
if (pc.Status != "A")
{
// Here I want to do the check if
if (orderType.ToString() == "QT")
{
yield return pc;
}
}
else
{
yield return pc;
}
}
}
}
}
尝试从GraphCaches
集合中获取当前缓存对象:
Type fieldType = [...];
var cache = _Graph.Caches[BqlCommand.GetItemType(fieldType)];
var currentCacheObject = cache.Current;
尽可能使用现有属性总是一个好主意。
在您的情况下,您似乎可以使用 PXRestrictorAttribute
获得所需的行为。它向为查找控件选择数据的 BQL 命令添加限制,并在输入的值不符合限制时显示错误消息。
Here is a nice article from Sergey Marenich from Acumatica about PXRestrictor.
这就是您编写限流器的方式。请注意,我们使用 ReplaceInherited
属性 覆盖活跃客户的现有限制器:
using System;
using PX.Data;
using PX.Objects.Common;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.SO;
namespace PX.Objects.SO
{
#region CustomerID
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRestrictor(typeof(Where<Customer.status, IsNull,
Or<Customer.status, Equal<BAccount.status.active>,
Or<Customer.status, Equal<BAccount.status.oneTime>,
Or2<Where<Customer.status, Equal<BAccount.status.Hold>, And<Current<SOOrder.orderType>,Equal<SOOrderTypeConstants.quoteOrder>>>>
>>>), "Customer status is {0} and this is not a quote", typeof(Customer.status), ReplaceInherited = true)]
public virtual int? CustomerID { get; set; }
#endregion
}
奖励:如果这是您唯一需要的定制,您可以直接将其添加到 UI 的定制项目中,而无需实际编译扩展库。
美好的一天
我已经为销售订单上的客户 ID 属性创建了一个自定义属性。 使用客户 ID 的当前属性,处于信用保留状态的客户不会显示在列表中。
我的想法是动态更改列表,这样如果订单类型为 QT,处于信用暂停状态的客户仍会显示在列表中。
我的问题是我不知道是否有办法 send/get 当前 SOOrder.OrderType
这是我所在的地方
namespace PX.Objects.SO
{
[PXNonInstantiatedExtension]
public class SO_SOOrder_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOOrder>
{
#region CustomerID
[PXMergeAttributes(Method = MergeMethod.Append)]
// [CustomercustomersAttribute(Current<SOOrder.orderType>))]
[CustomercustomersAttribute()]
public int? CustomerID { get; set; }
#endregion
}
public class CustomercustomersAttribute : PXCustomSelectorAttribute
{
public string orderType { get; set; }
public Type orderType2 { get; set; }
public CustomercustomersAttribute(Type OrderType) : base(typeof(Customer.acctCD))
{
this.orderType2 = OrderType;
this.DescriptionField = typeof(Customer.acctName);
}
public CustomercustomersAttribute(string OrderType) : base(typeof(Customer.acctCD))
{
this.orderType = OrderType;
this.DescriptionField = typeof(Customer.acctName);
}
public CustomercustomersAttribute() : base(typeof(Customer.acctCD))
{
this.DescriptionField = typeof(Customer.acctName);
}
protected virtual IEnumerable GetRecords()
{
foreach (Customer pc in PXSelect<Customer>.Select(this._Graph))
{
if (pc.Status != "A")
{
// Here I want to do the check if
if (orderType.ToString() == "QT")
{
yield return pc;
}
}
else
{
yield return pc;
}
}
}
}
}
尝试从GraphCaches
集合中获取当前缓存对象:
Type fieldType = [...];
var cache = _Graph.Caches[BqlCommand.GetItemType(fieldType)];
var currentCacheObject = cache.Current;
尽可能使用现有属性总是一个好主意。
在您的情况下,您似乎可以使用 PXRestrictorAttribute
获得所需的行为。它向为查找控件选择数据的 BQL 命令添加限制,并在输入的值不符合限制时显示错误消息。
Here is a nice article from Sergey Marenich from Acumatica about PXRestrictor.
这就是您编写限流器的方式。请注意,我们使用 ReplaceInherited
属性 覆盖活跃客户的现有限制器:
using System;
using PX.Data;
using PX.Objects.Common;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.SO;
namespace PX.Objects.SO
{
#region CustomerID
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRestrictor(typeof(Where<Customer.status, IsNull,
Or<Customer.status, Equal<BAccount.status.active>,
Or<Customer.status, Equal<BAccount.status.oneTime>,
Or2<Where<Customer.status, Equal<BAccount.status.Hold>, And<Current<SOOrder.orderType>,Equal<SOOrderTypeConstants.quoteOrder>>>>
>>>), "Customer status is {0} and this is not a quote", typeof(Customer.status), ReplaceInherited = true)]
public virtual int? CustomerID { get; set; }
#endregion
}
奖励:如果这是您唯一需要的定制,您可以直接将其添加到 UI 的定制项目中,而无需实际编译扩展库。