我正在尝试从标题中删除记录,在“Fabrication Stage = 6. Cancelled”字段然后按保存按钮的情况下,删除记录。
附件是我的代码,当我尝试删除记录时它给我一个错误。
提前感谢您的帮助。
protected void INKitRegister_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var row = (INKitRegister)e.Row;
if (row == null) return;
var extKit = row.GetExtension<INKitRegisterExt>();
if (extKit.UsrFabStage == "06")
{
if (Base.Document.Ask("Confirm Delete", "Are you sure?", MessageButtons.YesNo) == WebDialogResult.Yes)
{
PXTimeStampScope.SetRecordComesFirst(typeof(INKitRegister), true);
KitAssemblyEntry graph = PXGraph.CreateInstance<KitAssemblyEntry>();
INKitRegister dac = graph.Document.Current = graph.Document.Search<INKitRegister.refNbr>(row.RefNbr);
graph.Document.Delete(dac);
graph.Save.Press();
}
}
}
我不喜欢我的答案,当我仔细考虑这个问题并得到更优雅的东西时,很可能会提交另一个答案。
本质上我们将缓存中的记录标记为只要符合要求的条件就删除。我的示例确认缓存中的记录状态并且它没有描述。
保存后它将被删除,尽管此解决方案目前需要刷新屏幕才能从 UI 中删除记录。
public class KitAssemblyEntryExtension : PXGraphExtension<KitAssemblyEntry>
{
[PXOverride]
public void Persist(Action del)
{
INKitRegister document = Base.Document.Current;
//Confirm the cache status of the record is correct for deletion and that criteria is met for the record we want deleted.
if(Base.Document.Cache.GetStatus(document) == PXEntryStatus.Updated && string.IsNullOrEmpty(document.TranDesc))
{
//Marks the record as deleted in the Cache, when base persist is called this record is then deleted.
Base.Document.Cache.MarkDeleted(Base.Document.Current);
}
del?.Invoke();
}
}