我正在寻找一种解决方案,将注释添加到我在自定义表中创建的数据库行。我从 Ruslan 找到了下面用于访问 noteid 的解决方案,但我不明白如何使用它来向行添加注释。我拥有创建该行的所有代码,我只需要属性或函数调用即可将注释文本实际附加到该行。
=================================================== ===============
要在保存新父记录时自动创建注释记录,应在将父记录插入到缓存中时调用静态 PXNoteAttribute.GetNoteID(PXCache cache, object data) 方法。
例如,要在保存新库存商品时自动创建注释记录,您应该订阅 InventoryItem DAC 的 RowInserted 处理程序并调用 PXNoteAttribute.GetNoteID(...):
public class InventoryItemMaintExt : PXGraphExtension<InventoryItemMaint>
{
public void InventoryItem_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
{
var noteCache = Base.Caches[typeof(Note)];
var oldDirty = noteCache.IsDirty;
PXNoteAttribute.GetNoteID<InventoryItem.noteID>(sender, e.Row);
noteCache.IsDirty = oldDirty;
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码片段可以合并到几乎任何自定义 BLC 中,只需进行一些简单的更改即可用自定义 DAC 替换 InventoryItem。
实施加布里埃尔的建议后:
我似乎没有在数据库中得到任何注释。代码编译并运行良好,但据我所知,注释并未生成。我的表中设置了注释id,但是注释表中没有出现任何数据。请查看我的代码并让我知道需要更改哪些内容。另外,如何将注释列放入网格中,或者正确完成后它是否会自动变得可用?
数据库字段定义:
[NoteID] [uniqueidentifier] NULL
Run Code Online (Sandbox Code Playgroud)
DAC领域:
#region NoteID
public abstract class noteID : PX.Data.IBqlField
{
}
protected Guid? _NoteID;
[PXNote()]
public virtual Guid? NoteID
{
get
{
return this._NoteID;
}
set
{
this._NoteID = value;
}
}
#endregion
Run Code Online (Sandbox Code Playgroud)
创建记录的代码:
private static bool acumaticaException(Exception e, EDImportExceptionMaint excpMaint, LingoRet850 res850)
{
excpMaint.Clear();
var except = new EDImportExcept();
except.ExceptReason = "U";
except.Active = true;
<...field assignments...>
except.OrderNbr = "";
PXNoteAttribute.SetNote(excpMaint.Exception.Cache, excpMaint.Exception.Current,
((PX.Data.PXOuterException)e).InnerMessages[0] + "-" + e.Message);
excpMaint.Exception.Insert(except);
excpMaint.Actions.PressSave();
return true;
}
Run Code Online (Sandbox Code Playgroud)
要设置记录的注释,请使用以下SetNote()静态函数PXNoteAttribute
PXNoteAttribute.SetNote(Base.Item.Cache, Base.Item.Current, "Hello, World!");
Run Code Online (Sandbox Code Playgroud)
如果注释记录不存在,调用SetNote还将负责添加注释记录,因此您不必GetNoteID像问题中那样在设置注释值之前调用。
PS 还有一个GetNote函数可以让你检索票据的当前值:
string note = PXNoteAttribute.GetNote(Base.Item.Cache, Base.Item.Current);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1090 次 |
| 最近记录: |