上一个问题Make a Field Mandatory on the Graph Level中的后续问题。
通过从我的TableColumn中删除下划线(_
)来应用上一个问题的答案后,很明显客户位置屏幕正在进行代码自定义,所以我在那里接受了答案,因为我的新问题肯定需要一个不同的解决方案。
加载客户位置(AR303020)屏幕后,我现在收到此错误:
无法在图形PX.Objects.AR.CustomerLocationMaint中订阅事件PX.Objects.AR.CustomerLocationMaint_Extension :: SelectedCustomerLocation_UsrDCLID_CacheAttached。方法签名看起来像一个事件处理程序,但是在自动初始化的缓存列表中找不到缓存SelectedCustomerLocation。从代码中删除未使用的事件处理程序。
我使用布局编辑器中的 OVERRIDE ON SCREEN LEVEL 按钮来生成我认为正确的代码存根。
这是产生的股票代码:
using System;
using PX.Data;
using PX.Objects.CR;
using System.Collections.Generic;
using PX.Objects;
using PX.Objects.AR;
namespace PX.Objects.AR
{
public class CustomerLocationMaint_Extension : PXGraphExtension<CustomerLocationMaint>
{
#region Event Handlers
protected virtual void SelectedCustomerLocation_UsrDCLID_CacheAttached(PXCache cache)
{
}
#endregion
}
}
这是在我简单的必要修改之后:
using System;
using PX.Data;
using PX.Objects.CR;
using System.Collections.Generic;
using PX.Objects;
using PX.Objects.AR;
namespace PX.Objects.AR
{
public class CustomerLocationMaint_Extension : PXGraphExtension<CustomerLocationMaint>
{
#region Event Handlers
[PXDefault]
[PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), "Required", true)]
protected virtual void SelectedCustomerLocation_UsrDCLID_CacheAttached(PXCache cache)
{
}
#endregion
}
}
从此处保存我的代码更改并发布自定义项目。然后,当我刷新客户位置屏幕时,我收到上述错误。
您可以在此处看到此表单的数据类为PX.Objects.AR.SelectedCustomerLocation
但是当我检查页面上的字段时,它会显示数据类为Location
,我发现它与PX.Objects.CR.Location
相关联。我相信AR.SelectedCustomerLocation
延伸CR.Location
我不确定从哪里开始。鉴于系统生成了SelectedCustomerLocation_UsrDCLID_CacheAttached
方法,我不得不相信这是需要的事件处理程序。我已经尝试将其更改为Location_UsrDCLID_CacheAttached
,这会导致错误消失,但字段的必要性不存在,所以我不相信这是正确的方法签名。
如何在此页面上存在SelectedCustomerLocation缓存?我需要它存在吗?它应该只是位置吗?
答案 0 :(得分:1)
当您使用要扩展的基本DAC名称时,Location_UsrDCLID_CacheAttached将是正确的名称。 SelectedCustomerLocation继承自SelectedLocation,它继承自Location。
试试这个......
[PXDBInt]
[PXUIField(DisplayName="DCL Account ID", Required = true)]
protected virtual void Location_UsrDCLID_CacheAttached(PXCache cache)
{
}
如果您需要条件要求,可以添加PXUIRequiredAttribute
。例如:
[PXUIRequired(typeof(Where<INItemSite.overrideInvtAcctSub, Equal<True>>))]
您可以使用PXUIFieldAttribute在DAC上设置所需属性,附加图形缓存,或者在RowSelected事件或图形扩展初始化等逻辑中设置。
示例:
protected virtual void Location_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
PXUIFieldAttribute.SetRequired<LocationExt.usrDCLID>(cache, true);
}
为了获得更大的灵活性,您可以检查rowpersisting事件中的条件,如此...
protected virtual void Location_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
var row = (Location)e.Row;
if(row == null)
{
return;
}
var rowExt = row.GetExtension<LocationExt>();
if (rowExt != null && rowExt.UsrDCLID == null)
{
if (sender.RaiseExceptionHandling<LocationExt.usrDCLID>(e.Row, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(LocationExt.usrDCLID).Name)))
{
throw new PXRowPersistingException(typeof(LocationExt.usrDCLID).Name, null, ErrorMessages.FieldIsEmpty, typeof(LocationExt.usrDCLID).Name);
}
}
}