c# - 无法获取 Events.CacheAttached 以识别 Acuamtica 中的自定义属性
问题描述
这是我在此处发布的问题的后续行动 Override action on curyOrigDiscAmt
按照那里的建议,我正在尝试:
基于原始的 TermsAttribute 类创建自定义属性。
覆盖字段 APInvoice.TermsID
使用自定义属性装饰字段 APInvoice.TermsID 并使用它来替换原始条款。
最后改变 CalcDisc() 方法的逻辑
这是我所做的:
1.自定义属性:
public class CTERMSIDAttribute : PX.Objects.CS.TermsAttribute
{
public CTERMSIDAttribute(Type DocDate, Type DueDate, Type DiscDate, Type CuryDocBal, Type CuryDiscBal) : base(DocDate, DueDate, DiscDate, CuryDocBal, CuryDiscBal)
{
var cBalance = _CuryDocBal;
var cDiscount = _CuryDiscBal;
int i = 0;
}
protected override void CalcDisc(PXCache sender, PXFieldUpdatedEventArgs e)
{
base.CalcDisc(sender, e);
int i2 = 0;
}
}
注意:目前没有任何事情要做。我只是在 int i = 0 上放了一个断点,以确保我的代码在运行时被执行。
我还创建了一个用新创建的属性装饰的类:
public class CTermID : Vendor.termsID
{
[PXDBString(10, IsUnicode = true)]
[PXDefault(typeof(Search<Vendor.termsID,
Where<Vendor.bAccountID, Equal<Current<APInvoice.vendorID>>,
And<Current<APInvoice.docType>, NotEqual<APDocType.debitAdj>>>>),
PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Terms", Visibility = PXUIVisibility.Visible)]
[APTermsSelector]
[CTERMSIDAttribute(typeof(APInvoice.docDate), typeof(APInvoice.dueDate), typeof(APInvoice.discDate),
typeof(APInvoice.curyOrigDocAmt), typeof(APInvoice.curyOrigDiscAmt))]
public string termsID { get; set; }
}
我不确定这是否需要或使用,但我在一个片段中看到它,所以我实现了它。
2 & 3. 覆盖和装饰
[PXMergeAttributes(Method = MergeMethod.Append)] // add to other properties
[PXRemoveBaseAttribute(typeof(Vendor.termsID))] // remove existing property
[CTERMSIDAttribute(typeof(APInvoice.docDate), typeof(APInvoice.dueDate), typeof(APInvoice.discDate),
typeof(APInvoice.curyOrigDocAmt), typeof(APInvoice.curyOrigDiscAmt))]
public CTermID termsID { get; set; } // redefine termsID to use custom attribute
protected virtual void _(Events.CacheAttached<APInvoice.termsID> e)
{
int i3 = 0;
}
4. CalcDisc() 的重写方法
这是在新属性中(之前在步骤 1 中显示):
protected override void CalcDisc(PXCache sender, PXFieldUpdatedEventArgs e)
{
base.CalcDisc(sender, e);
int i2 = 0;
}
同样,它现在什么也不做,我只是在 int i2 = 0 处放置一个断点来检查它是否在运行时命中。事实并非如此。
发生的情况是第一个断点(i = 0)命中......实际上它命中了好几次......但其他断点都没有,这告诉我覆盖工作不正常。
我错过了什么?
[编辑] 根据 Patrick Chen 的建议,我将其更改为:
[PXMergeAttributes(Method = MergeMethod.Replace)]
[CTERMSIDAttribute(typeof(APInvoice.docDate), typeof(APInvoice.dueDate), typeof(APInvoice.discDate), typeof(APInvoice.curyOrigDocAmt), typeof(APInvoice.curyOrigDiscAmt))]
public CTermID termsID { get; set; } // redefine termsID to use custom attribute
protected virtual void _(Events.CacheAttached<APInvoice.termsID> e)
{
int i = 0;
}
而且我的 DoCalc() 版本仍然没有被解雇。
解决方案
推荐阅读
- python-3.x - 如何缩短我的代码而不是编写相同的重复命令?(discord.py)
- javascript - 用于列表的 youtube player api 总是播放初始视频
- r - R Keras - 模型是用形状 (1, 16, 1) 构建的,但它是在形状不兼容的输入上调用的 (1, 1, 1)
- c - Scanf 在运行时崩溃
- c# - 在 ToString 中使用“{0} of {1}”
- python - python中的一个初学者任务,带有txt数据处理,一列中的数字总和
- sql - 将列设置为等于 postgres 中子查询的值
- python - 不允许使用 aiocoap 获取方法
- r - 如何在 R Shiny 中上传 3 个 bamfile,然后合并为一个?
- ios - 在 Flutter 2.0.4 上构建 iOS 应用程序错误:找不到“Flutter/Flutter.h”文件