Acumatica:在另一个自定义按钮上触发保存验证
你好 单击自定义按钮时,如何触发视图的验证?例如,我在DAC中有一个必需的金额字段,它具有PXDefault属性,如果我保存记录而不填充它,它自然会触发“错误:'Amount'不能为空”错误。现在,我想从这里复制这个行为,当另一个按钮除了保存按钮被触发 如何触发验证?我已经尝试在字段本身上添加PXUIVerify属性,但是它在页面加载期间已经被触发,我尝试通过添加属性CheckOnRowSelected=false来禁用它,但是没有效果,它仍然会触发验证 如有任何建议和答案,我们将不胜感激。非常感谢你 附加问题:Acumatica:在另一个自定义按钮上触发保存验证,acumatica,Acumatica,你好 单击自定义按钮时,如何触发视图的验证?例如,我在DAC中有一个必需的金额字段,它具有PXDefault属性,如果我保存记录而不填充它,它自然会触发“错误:'Amount'不能为空”错误。现在,我想从这里复制这个行为,当另一个按钮除了保存按钮被触发 如何触发验证?我已经尝试在字段本身上添加PXUIVerify属性,但是它在页面加载期间已经被触发,我尝试通过添加属性CheckOnRowSelected=false来禁用它,但是没有效果,它仍然会触发验证 如有任何建议和答案,我们将不胜感激。非常
验证表单的正确方法是什么?您可以调用RaiseFieldVerification事件。检查ARDocumentEnq图形,CreateInvoice(输入新发票)按钮调用FieldVerification和FieldUpdate事件,触发这些事件。您可以捕获异常,如在INTransferEntry图中:
protected virtual void INRegister_TransferType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
INRegister row = (INRegister)e.Row;
{
object toSiteID = row.ToSiteID;
try
{
sender.RaiseFieldVerifying<INRegister.toSiteID>(row, ref toSiteID);
sender.RaiseExceptionHandling<INRegister.toSiteID>(row, toSiteID, null);
}
catch (PXSetPropertyException ex)
{
sender.RaiseExceptionHandling<INRegister.toSiteID>(row, toSiteID, new PXSetPropertyException(ex, PXErrorLevel.Error, Messages.WarehouseNotAllowed, Messages.OneStep));
}
}
}
注册表中受保护的虚拟无效\u传输类型\u字段已更新(PXCache发送方,PXFieldUpdatedEventArgs e)
{
INRegister行=(INRegister)e.row;
{
object-toSiteID=row.toSiteID;
尝试
{
sender.RaiseFieldVerification(行,引用到站点ID);
sender.RaiseExceptionHandling(行,toSiteID,null);
}
捕获(PXSetPropertyException ex)
{
sender.RaiseExceptionHandling(行、toSiteID、新PXSetPropertyException(例如,PXErrorLevel.Error、Messages.WarehouseNotAllowed、Messages.OneStep));
}
}
}
您可以调用RaiseFieldVerification事件。检查ARDocumentEnq图形,CreateInvoice(输入新发票)按钮调用FieldVerification和FieldUpdate事件,触发这些事件。您可以捕获异常,如在INTransferEntry图中:
protected virtual void INRegister_TransferType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
INRegister row = (INRegister)e.Row;
{
object toSiteID = row.ToSiteID;
try
{
sender.RaiseFieldVerifying<INRegister.toSiteID>(row, ref toSiteID);
sender.RaiseExceptionHandling<INRegister.toSiteID>(row, toSiteID, null);
}
catch (PXSetPropertyException ex)
{
sender.RaiseExceptionHandling<INRegister.toSiteID>(row, toSiteID, new PXSetPropertyException(ex, PXErrorLevel.Error, Messages.WarehouseNotAllowed, Messages.OneStep));
}
}
}
注册表中受保护的虚拟无效\u传输类型\u字段已更新(PXCache发送方,PXFieldUpdatedEventArgs e)
{
INRegister行=(INRegister)e.row;
{
object-toSiteID=row.toSiteID;
尝试
{
sender.RaiseFieldVerification(行,引用到站点ID);
sender.RaiseExceptionHandling(行,toSiteID,null);
}
捕获(PXSetPropertyException ex)
{
sender.RaiseExceptionHandling(行、toSiteID、新PXSetPropertyException(例如,PXErrorLevel.Error、Messages.WarehouseNotAllowed、Messages.OneStep));
}
}
}
在PXDefaultAttribute中的行持久化事件中验证字段是否为空。在PXUIFieldAttribute中的CommandPreparing事件中验证屏幕上是否存在任何错误
因为您实际上并没有保存,所以复制验证比尝试“触发”验证更容易。下面的代码段尝试通过验证图上每个视图的缓存中的每个记录来复制验证
public static void Validate(PXGraph graph)
{
for (int k = 0; k < graph.Views.Caches.Count; ++k)
{
PXCache cache = graph.Caches[graph.Views.Caches[k]];
PXEntryStatus status;
foreach (object rec in cache.Cached)
{
status = cache.GetStatus(rec);
if (cache.GetStatus(rec) == PXEntryStatus.Updated || cache.GetStatus(rec) == PXEntryStatus.Inserted)
{
cache.Current = rec;
foreach (PXDefaultAttribute attribute in cache.GetAttributesReadonly(rec, null).OfType<PXDefaultAttribute>())
{
CheckDefaultAttribute(attribute.PersistingCheck, attribute.FieldName, rec, cache);
}
foreach (PXDBDefaultAttribute attribute in cache.GetAttributesReadonly(rec, null).OfType<PXDBDefaultAttribute>())
{
CheckDefaultAttribute(attribute.PersistingCheck, attribute.FieldName, rec, cache);
}
// Verifies that there are no errors on the page.
foreach (IPXInterfaceField field in cache.GetAttributesReadonly(rec, null).OfType<IPXInterfaceField>())
{
if (!string.IsNullOrEmpty(field.ErrorText) && (field.ErrorLevel == PXErrorLevel.Error || field.ErrorLevel == PXErrorLevel.RowError))
{
throw new PXException(field.ErrorText);
}
}
}
}
}
}
// Verifies that the field has a value if the PersistingCheck is not PXPersistingCheck.Nothing
protected static void CheckDefaultAttribute(PXPersistingCheck persistingCheck, string fieldName, object row, PXCache cache)
{
if (persistingCheck != PXPersistingCheck.Nothing)
{
object value = cache.GetValue(row, fieldName);
if (value == null || (persistingCheck == PXPersistingCheck.NullOrBlank && value is string && ((string)value).Trim() == string.Empty))
{
throw new PXException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName(cache, fieldName));
}
}
}
公共静态无效验证(PXGraph)
{
对于(int k=0;k
作为免责声明,此方法将错过在自定义行持久化事件中发生的任何验证。在PXDefaultAttribute中的行持久化事件中验证字段是否为空。在PXUIFieldAttribute中的CommandPreparing事件中验证屏幕上是否存在任何错误 因为您实际上并没有保存,所以复制验证比尝试“触发”验证更容易。下面的代码段尝试通过验证图上每个视图的缓存中的每个记录来复制验证
public static void Validate(PXGraph graph)
{
for (int k = 0; k < graph.Views.Caches.Count; ++k)
{
PXCache cache = graph.Caches[graph.Views.Caches[k]];
PXEntryStatus status;
foreach (object rec in cache.Cached)
{
status = cache.GetStatus(rec);
if (cache.GetStatus(rec) == PXEntryStatus.Updated || cache.GetStatus(rec) == PXEntryStatus.Inserted)
{
cache.Current = rec;
foreach (PXDefaultAttribute attribute in cache.GetAttributesReadonly(rec, null).OfType<PXDefaultAttribute>())
{
CheckDefaultAttribute(attribute.PersistingCheck, attribute.FieldName, rec, cache);
}
foreach (PXDBDefaultAttribute attribute in cache.GetAttributesReadonly(rec, null).OfType<PXDBDefaultAttribute>())
{
CheckDefaultAttribute(attribute.PersistingCheck, attribute.FieldName, rec, cache);
}
// Verifies that there are no errors on the page.
foreach (IPXInterfaceField field in cache.GetAttributesReadonly(rec, null).OfType<IPXInterfaceField>())
{
if (!string.IsNullOrEmpty(field.ErrorText) && (field.ErrorLevel == PXErrorLevel.Error || field.ErrorLevel == PXErrorLevel.RowError))
{
throw new PXException(field.ErrorText);
}
}
}
}
}
}
// Verifies that the field has a value if the PersistingCheck is not PXPersistingCheck.Nothing
protected static void CheckDefaultAttribute(PXPersistingCheck persistingCheck, string fieldName, object row, PXCache cache)
{
if (persistingCheck != PXPersistingCheck.Nothing)
{
object value = cache.GetValue(row, fieldName);
if (value == null || (persistingCheck == PXPersistingCheck.NullOrBlank && value is string && ((string)value).Trim() == string.Empty))
{
throw new PXException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName(cache, fieldName));
}
}
}
公共静态无效验证(PXGraph)
{
对于(int k=0;k