在库存查找中添加属性字段
Add Attributes fields on Inventory Lookup
我想在销售订单和采购订单上添加库存查询属性,有人知道怎么做吗?或者有什么想法?
请参考下面的代码示例,使用开箱即用的方式在选择器和网格控件中包含属性列 CRAttributesFieldAttribute
。
声明一个 class PXAddAtttributeColumns
继承自 CRAttributesFieldAttribute
。
public class PXAddAtttributeColumns : CRAttributesFieldAttribute
{
string[] _names;
bool _IsForSelector;
public PXAddAtttributeColumns(string[] names, Type entityType, Type entityIDField, Type classIDField, bool IsForSelector = true)
: base(entityType, entityIDField, classIDField)
{
_names = names;
_IsForSelector = IsForSelector;
}
public override void CacheAttached(PXCache sender)
{
this._IsActive = true;
base.CacheAttached(sender);
}
protected override void AttributeFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, PXFieldState state, string attributeName, int idx)
{
if (_names.Any(attributeName.Equals))
{
//Out-of-box DisplayName is prefixed with "$Attributes$-" - if you need to take that off.
state.DisplayName = (!String.IsNullOrEmpty(state.DisplayName)) ? (state.DisplayName.Replace("$Attributes$-", "")) : attributeName;
state.Visible = true;
//Requires AutoGenerateColumns="AppendDynamic" for PXGrid Control for dynamic Attribute columns creation
state.Visibility = (_IsForSelector) ? PXUIVisibility.SelectorVisible : PXUIVisibility.Dynamic;
}
base.AttributeFieldSelecting(sender, e, state, attributeName, idx);
}
public override void CommandPreparing(PXCache sender, PXCommandPreparingEventArgs e)
{
base.CommandPreparing(sender, e);
if (e.BqlTable == null && aggregateAttributes && sender.GetItemType().IsDefined(typeof(PXProjectionAttribute), true))
{
e.BqlTable = _BqlTable;
}
}
}
要将属性作为列包含在 Inventory Look up
中,请如下声明 DAC 扩展:
public class InventoryItemPXExt : PXCacheExtension<PX.Objects.IN.InventoryItem>
{
#region Attributes
public abstract class attributes : IBqlField { }
[PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
typeof(CSAnswerType.inventoryAnswerType),
typeof(InventoryItem.inventoryID),
typeof(InventoryItem.itemClassID))]
public virtual string[] Attributes { get; set; }
#endregion
}
字段将显示如下:
可以通过将 FilterByAllFields
设置为 True
来在属性列上启用搜索
要将属性作为列包含在 Sales Order Details Grid
中,请按如下方式声明 DAC 扩展:
public class SOLineExtension : PXCacheExtension<SOLine>
{
public abstract class itemAttributes : IBqlField { }
[PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
typeof(CSAnswerType.inventoryAnswerType),
typeof(SOLine.inventoryID),
typeof(InventoryItem.itemClassID), false)]
public virtual string[] ItemAttributes { get; set; }
}
确保为 PXGrid
控件动态属性列创建指定 AutoGenerateColumns="AppendDynamic"
字段将显示如下:
要将属性作为列包含在 Add Stock Item
对话框的网格中,请按如下方式声明 DAC 扩展:
public class SOSiteStatusSelectedExtension : PXCacheExtension<SOSiteStatusSelected>
{
public abstract class itemAttributes : IBqlField { }
[PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
typeof(CSAnswerType.inventoryAnswerType),
typeof(InventoryItem.inventoryID),
typeof(InventoryItem.itemClassID), false)]
public virtual string[] ItemAttributes { get; set; }
}
确保为 PXGrid
控件动态属性列创建指定 AutoGenerateColumns="AppendDynamic"
字段将显示如下:
注意:此示例适用于 5.3 系列 – Build 5.30.1367 及以上版本。
20R1以后的版本更新解决方案:
下面是将自定义属性添加到销售订单 (SO301000) 屏幕的 CustomerID
和 InventoryID
查找的示例场景。
- 从属性 (CS205000) 屏幕创建所需的属性。
- 将必要的属性添加到相应的客户 类 (AR201000) 屏幕以添加到
CustomerID
查找和相应的项目 类 (IN201000) 屏幕以添加到 InventoryID
查找。
- 创建一个新的属性 class
CustomerAttributeSetFieldsAttribute
扩展 CustomerActiveAttribute
(因为它在 CustomerID
中使用)并通过重写相同的内容来覆盖 SetColumns 以更改 FieldList和 HeaderList.
public class CustomerAttributeSetFieldsAttribute : CustomerActiveAttribute
{
public static void SetColumns(PXCache cache, string field, string[] fieldList, string[] headerList)
{
PXSelectorAttribute.SetColumns(cache, field, fieldList, headerList);
foreach (CustomerAttributeSetFieldsAttribute attr in cache.GetAttributes(field).OfType<CustomerAttributeSetFieldsAttribute>())
{
attr._FieldList = fieldList;
attr._HeaderList = headerList;
}
}
}
- 覆盖 Initialize 方法并调用 Activate 以通过传递适当的缓存来激活属性 - BAccountR - 对于
CustomerID
和 InventoryItem - InventoryID
。此外,从 CustomerID
CustomerAttributeSetFieldsAttribute
的自定义属性和 InventoryID
的 PXSelectorAttribute
调用 SetColumns 并传递缓存类型(存在查找的位置),字段(字段名称), fieldList(所有字段的名称列表,包括属性)和 headerList(所有 headers 的名称列表,包括属性)。
- 通过将
CustomerAttributeSetFields
添加到 SOOrder_CustomerID_CacheAttached 方法来覆盖属性以将新添加的属性合并到 CustomerID
。
public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
public override void Initialize()
{
base.Initialize();
//for InventoryID lookup
CR.CRAttributesFieldAttribute.Activate(Base.Caches[typeof(InventoryItem)]);
PXSelectorAttribute.SetColumns(Base.Caches[typeof(SOLine)],
"InventoryID", new string[] { "InventoryCD", "Descr", "itemClassID", "Color_ATTRIBUTES" },
new string[] { "InventoryCD", "Descr", "itemClassID", "$Attributes$-Color" });
//for CustomerID lookup
CR.CRAttributesFieldAttribute.Activate(Base.Caches[typeof(BAccountR)]);
CustomerAttributeSetFieldsAttribute.SetColumns(Base.Caches[typeof(SOOrder)],
"CustomerID", new string[] { "AcctCD", "acctName", "COMPREV_Attributes" },
new string[] { "AcctCD", "acctName", "$Attributes$-Company Revenue" });
}
[PXMergeAttributes(Method = MergeMethod.Merge)]
[CustomerAttributeSetFields]
protected virtual void SOOrder_CustomerID_CacheAttached(PXCache sender)
{
}
}
注意:由于Customer DAC是从BAccount派生的,CustomerActive属性是从Customer派生的,所以它的缓存类型是BAccountR,只有缓存类型相同的属性才会可用于添加到 CustomerID 弹出窗口。如果用户需要添加不同缓存类型的其他属性,最好创建一个新的属性并使用它而不是 CustomerActive。
我想在销售订单和采购订单上添加库存查询属性,有人知道怎么做吗?或者有什么想法?
请参考下面的代码示例,使用开箱即用的方式在选择器和网格控件中包含属性列 CRAttributesFieldAttribute
。
声明一个 class PXAddAtttributeColumns
继承自 CRAttributesFieldAttribute
。
public class PXAddAtttributeColumns : CRAttributesFieldAttribute
{
string[] _names;
bool _IsForSelector;
public PXAddAtttributeColumns(string[] names, Type entityType, Type entityIDField, Type classIDField, bool IsForSelector = true)
: base(entityType, entityIDField, classIDField)
{
_names = names;
_IsForSelector = IsForSelector;
}
public override void CacheAttached(PXCache sender)
{
this._IsActive = true;
base.CacheAttached(sender);
}
protected override void AttributeFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, PXFieldState state, string attributeName, int idx)
{
if (_names.Any(attributeName.Equals))
{
//Out-of-box DisplayName is prefixed with "$Attributes$-" - if you need to take that off.
state.DisplayName = (!String.IsNullOrEmpty(state.DisplayName)) ? (state.DisplayName.Replace("$Attributes$-", "")) : attributeName;
state.Visible = true;
//Requires AutoGenerateColumns="AppendDynamic" for PXGrid Control for dynamic Attribute columns creation
state.Visibility = (_IsForSelector) ? PXUIVisibility.SelectorVisible : PXUIVisibility.Dynamic;
}
base.AttributeFieldSelecting(sender, e, state, attributeName, idx);
}
public override void CommandPreparing(PXCache sender, PXCommandPreparingEventArgs e)
{
base.CommandPreparing(sender, e);
if (e.BqlTable == null && aggregateAttributes && sender.GetItemType().IsDefined(typeof(PXProjectionAttribute), true))
{
e.BqlTable = _BqlTable;
}
}
}
要将属性作为列包含在 Inventory Look up
中,请如下声明 DAC 扩展:
public class InventoryItemPXExt : PXCacheExtension<PX.Objects.IN.InventoryItem>
{
#region Attributes
public abstract class attributes : IBqlField { }
[PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
typeof(CSAnswerType.inventoryAnswerType),
typeof(InventoryItem.inventoryID),
typeof(InventoryItem.itemClassID))]
public virtual string[] Attributes { get; set; }
#endregion
}
字段将显示如下:
可以通过将 FilterByAllFields
设置为 True
要将属性作为列包含在 Sales Order Details Grid
中,请按如下方式声明 DAC 扩展:
public class SOLineExtension : PXCacheExtension<SOLine>
{
public abstract class itemAttributes : IBqlField { }
[PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
typeof(CSAnswerType.inventoryAnswerType),
typeof(SOLine.inventoryID),
typeof(InventoryItem.itemClassID), false)]
public virtual string[] ItemAttributes { get; set; }
}
确保为 PXGrid
控件动态属性列创建指定 AutoGenerateColumns="AppendDynamic"
字段将显示如下:
要将属性作为列包含在 Add Stock Item
对话框的网格中,请按如下方式声明 DAC 扩展:
public class SOSiteStatusSelectedExtension : PXCacheExtension<SOSiteStatusSelected>
{
public abstract class itemAttributes : IBqlField { }
[PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
typeof(CSAnswerType.inventoryAnswerType),
typeof(InventoryItem.inventoryID),
typeof(InventoryItem.itemClassID), false)]
public virtual string[] ItemAttributes { get; set; }
}
确保为 PXGrid
控件动态属性列创建指定 AutoGenerateColumns="AppendDynamic"
字段将显示如下:
注意:此示例适用于 5.3 系列 – Build 5.30.1367 及以上版本。
20R1以后的版本更新解决方案:
下面是将自定义属性添加到销售订单 (SO301000) 屏幕的 CustomerID
和 InventoryID
查找的示例场景。
- 从属性 (CS205000) 屏幕创建所需的属性。
- 将必要的属性添加到相应的客户 类 (AR201000) 屏幕以添加到
CustomerID
查找和相应的项目 类 (IN201000) 屏幕以添加到InventoryID
查找。 - 创建一个新的属性 class
CustomerAttributeSetFieldsAttribute
扩展CustomerActiveAttribute
(因为它在CustomerID
中使用)并通过重写相同的内容来覆盖 SetColumns 以更改 FieldList和 HeaderList.
public class CustomerAttributeSetFieldsAttribute : CustomerActiveAttribute
{
public static void SetColumns(PXCache cache, string field, string[] fieldList, string[] headerList)
{
PXSelectorAttribute.SetColumns(cache, field, fieldList, headerList);
foreach (CustomerAttributeSetFieldsAttribute attr in cache.GetAttributes(field).OfType<CustomerAttributeSetFieldsAttribute>())
{
attr._FieldList = fieldList;
attr._HeaderList = headerList;
}
}
}
- 覆盖 Initialize 方法并调用 Activate 以通过传递适当的缓存来激活属性 - BAccountR - 对于
CustomerID
和 InventoryItem -InventoryID
。此外,从CustomerID
CustomerAttributeSetFieldsAttribute
的自定义属性和InventoryID
的PXSelectorAttribute
调用 SetColumns 并传递缓存类型(存在查找的位置),字段(字段名称), fieldList(所有字段的名称列表,包括属性)和 headerList(所有 headers 的名称列表,包括属性)。 - 通过将
CustomerAttributeSetFields
添加到 SOOrder_CustomerID_CacheAttached 方法来覆盖属性以将新添加的属性合并到CustomerID
。
public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
public override void Initialize()
{
base.Initialize();
//for InventoryID lookup
CR.CRAttributesFieldAttribute.Activate(Base.Caches[typeof(InventoryItem)]);
PXSelectorAttribute.SetColumns(Base.Caches[typeof(SOLine)],
"InventoryID", new string[] { "InventoryCD", "Descr", "itemClassID", "Color_ATTRIBUTES" },
new string[] { "InventoryCD", "Descr", "itemClassID", "$Attributes$-Color" });
//for CustomerID lookup
CR.CRAttributesFieldAttribute.Activate(Base.Caches[typeof(BAccountR)]);
CustomerAttributeSetFieldsAttribute.SetColumns(Base.Caches[typeof(SOOrder)],
"CustomerID", new string[] { "AcctCD", "acctName", "COMPREV_Attributes" },
new string[] { "AcctCD", "acctName", "$Attributes$-Company Revenue" });
}
[PXMergeAttributes(Method = MergeMethod.Merge)]
[CustomerAttributeSetFields]
protected virtual void SOOrder_CustomerID_CacheAttached(PXCache sender)
{
}
}
注意:由于Customer DAC是从BAccount派生的,CustomerActive属性是从Customer派生的,所以它的缓存类型是BAccountR,只有缓存类型相同的属性才会可用于添加到 CustomerID 弹出窗口。如果用户需要添加不同缓存类型的其他属性,最好创建一个新的属性并使用它而不是 CustomerActive。