Acumatica 标识字段作为自定义表的键
我有两个自定义表(Header/Detail),它们都有多个字段作为键。我已经在从标题选择的细节中创建了所有PXParent和PXDefault属性,如T200课程所示 问题是,当我在标题部分有关键字段并且我尝试创建新记录时,表单不会清除我为这些关键字段选择的值 我继续创建了一个自动递增的int-identity字段作为键,其他以前的键字段组合成一个唯一的索引。我在DAC中使用PXDBIdentity(IsKey=true)属性,除了一个问题外,它工作得很好:当我创建一个新记录时,字段显示-2147483647,直到我保存,然后显示新创建的标识值 所以我想我的问题是:Acumatica 标识字段作为自定义表的键,acumatica,Acumatica,我有两个自定义表(Header/Detail),它们都有多个字段作为键。我已经在从标题选择的细节中创建了所有PXParent和PXDefault属性,如T200课程所示 问题是,当我在标题部分有关键字段并且我尝试创建新记录时,表单不会清除我为这些关键字段选择的值 我继续创建了一个自动递增的int-identity字段作为键,其他以前的键字段组合成一个唯一的索引。我在DAC中使用PXDBIdentity(IsKey=true)属性,除了一个问题外,它工作得很好:当我创建一个新记录时,字段显示-21
当自定义表的唯一标识由6个字段组成时,为该表创建键字段的标准协议/最佳实践是什么?如果操作正确,如何消除ID字段中显示的-2147483647?标识字段的问题是,该数字是由数据库生成的,而不是由ORM生成的,ORM通常在记录持续存在之前在缓存中保存新插入的行。我的建议是要么从UI中完全删除标识,要么找出一个不同的键。标识字段的问题是,该数字是由数据库生成的,而不是由ORM生成的,ORM通常在记录持续存在之前在缓存中保存新插入的行。我的建议是要么从UI中完全删除标识,要么找出一个不同的键。在DAC中定义键字段时,只有一条主要规则:
- 只有绑定到标识列的字段才能是DAC中的唯一键字段
- 您可以在DAC中定义多个关键字段,只要定义的关键字段中没有一个绑定到标识列
PXInsert
类继承并清除搜索数组:
public class MyGraph : PXGraph<MyGraph>
{
public class PXInsertCst<TNode> : PXInsert<TNode>
where TNode : class, IBqlTable, new()
{
public PXInsertCst(PXGraph graph, string name)
: base(graph, name)
{
}
public PXInsertCst(PXGraph graph, Delegate handler)
: base(graph, handler)
{
}
[PXUIField(DisplayName = ActionsMessages.Insert,
MapEnableRights = PXCacheRights.Insert,
MapViewRights = PXCacheRights.Insert)]
[PXInsertButton]
protected override IEnumerable Handler(PXAdapter adapter)
{
adapter.Searches = null;
return base.Handler(adapter);
}
}
public PXSave<MyPrimaryDAC> Save;
public PXCancel<MyPrimaryDAC> Cancel;
// The standard PXInsert type was replaced with the custom PXInsertCst type
public PXInsertCst<MyPrimaryDAC> Insert;
public PXDelete<MyPrimaryDAC> Delete;
public PXCopyPasteAction<MyPrimaryDAC> CopyPaste;
public PXFirst<MyPrimaryDAC> First;
public PXPrevious<MyPrimaryDAC> Previous;
public PXNext<MyPrimaryDAC> Next;
public PXLast<MyPrimaryDAC> Last;
}
在DAC中定义关键字段时,只有一条主要规则:
- 只有绑定到标识列的字段才能是DAC中的唯一键字段
- 您可以在DAC中定义多个关键字段,只要定义的关键字段中没有一个绑定到标识列
PXInsert
类继承并清除搜索数组:
public class MyGraph : PXGraph<MyGraph>
{
public class PXInsertCst<TNode> : PXInsert<TNode>
where TNode : class, IBqlTable, new()
{
public PXInsertCst(PXGraph graph, string name)
: base(graph, name)
{
}
public PXInsertCst(PXGraph graph, Delegate handler)
: base(graph, handler)
{
}
[PXUIField(DisplayName = ActionsMessages.Insert,
MapEnableRights = PXCacheRights.Insert,
MapViewRights = PXCacheRights.Insert)]
[PXInsertButton]
protected override IEnumerable Handler(PXAdapter adapter)
{
adapter.Searches = null;
return base.Handler(adapter);
}
}
public PXSave<MyPrimaryDAC> Save;
public PXCancel<MyPrimaryDAC> Cancel;
// The standard PXInsert type was replaced with the custom PXInsertCst type
public PXInsertCst<MyPrimaryDAC> Insert;
public PXDelete<MyPrimaryDAC> Delete;
public PXCopyPasteAction<MyPrimaryDAC> CopyPaste;
public PXFirst<MyPrimaryDAC> First;
public PXPrevious<MyPrimaryDAC> Previous;
public PXNext<MyPrimaryDAC> Next;
public PXLast<MyPrimaryDAC> Last;
}
那么,Acumatica是如何通过这种方式逃脱惩罚的呢?其实,它没有缺点,它不是一个有意义的键。那么,Acumatica是如何通过这种方式逃脱惩罚的呢?嗯,没有缺点,它不是一个有意义的键。太棒了!非常感谢,罗斯兰;真讨厌!非常感谢,罗斯兰;D
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter |
AttributeTargets.Class | AttributeTargets.Method)]
public class PXDBNewIdentityAttribute : PXDBIdentityAttribute
{
public override void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
base.FieldSelecting(sender, e);
if (e.Row != null && e.ReturnValue is int?)
{
if ((e.ReturnValue as int?).GetValueOrDefault() < 0)
{
e.ReturnValue = null;
}
}
}
public override void FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
if (e.Row != null && e.NewValue == null && sender.Inserted.Count() == 1)
{
var defaultValue = sender.GetValue(sender.Inserted.FirstOrDefault_(), FieldOrdinal);
if (defaultValue != null)
{
e.NewValue = defaultValue;
}
}
base.FieldUpdating(sender, e);
}
}