c# - 如何通过扩展中的 PXActions 正确地将记录添加到 DAC
问题描述
概括
我为APInvoiceEntry
图形(AP301000 屏幕)创建了一个图形扩展,名为APInvoiceEntry_Extension
.
我创建了一个名为 的新数据库表APRegisterException
,其中存储了 SalesTax、Freight、Price 和 Qty 错误的异常信息。 和 之间存在一对多的关系APRegister
,APRegisterException
表明一个账单可以有许多不同类型的异常。对于这些异常中的每一个,我创建了一个按钮和一个操作,以在我的扩展图中将异常添加到 DAC。
问题
我只能向APRegisterExcetion
DAC 添加 1 条新记录。DAC 不会针对多次单击按钮进行更新。以下每个操作都应创建一个新APRegisterException
记录,并将它们添加到我的图表中的异常 DAC。
public PXAction<APInvoice> ApplyPriceException;
public PXAction<APInvoice> ApplyQtyException;
public PXAction<PX.Objects.AP.APInvoice> ApplyFreightException;
public PXAction<PX.Objects.AP.APInvoice> ApplySalesTaxException;
注意:动作正在执行,只是 DAC 没有更新。
代码
APRegisterException DAC
namespace BillsAndAdjustmentsExt
{
[Serializable]
public class APRegisterException : IBqlTable
{
#region APRegisterRefNbr
[PXDBString(15, IsKey = true, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Ref Nbr")]
public virtual string APRegisterRefNbr { get; set; }
public abstract class aPRegisterRefNbr : IBqlField { }
#endregion
#region APTranLineNbr
[PXDBInt()]
[PXUIField(DisplayName = "Line Nbr")]
public virtual int? APTranLineNbr { get; set; }
public abstract class aPTranLineNbr : IBqlField { }
#endregion
#region ExceptionDesc
[PXDBString(150, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Description")]
public virtual string ExceptionDesc { get; set; }
public abstract class exceptionDesc : IBqlField { }
#endregion
#region ExceptionType
[PXDBString(3, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Exc. Type")]
public virtual string ExceptionType { get; set; }
public abstract class exceptionType : IBqlField { }
#endregion
#region ApprovedByID
[PXDBString(15, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Approved By")]
public virtual string ApprovedByID { get; set; }
public abstract class approvedByID : IBqlField { }
#endregion
#region ApprovedDate
[PXDBDate()]
[PXUIField(DisplayName = "Approval Date")]
public virtual DateTime? ApprovedDate { get; set; }
public abstract class approvedDate : IBqlField { }
#endregion
}
}
扩展图:
namespace PX.Objects.AP
{
public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
#region properties
public APRegister _currentDoc
{
get
{
return Base.Document.Current;
}
}
#endregion
// note
#region selects
public PXSelectJoin<
APRegisterException,
LeftJoin<APInvoice,
On<APRegisterException.aPRegisterRefNbr, Equal<APInvoice.refNbr>>>,
Where<APRegisterException.aPRegisterRefNbr, Equal<Current<APInvoice.refNbr>>>> Exceptions;
#endregion
#region Event Handlers
#endregion
#region Actions
public PXAction<APRegisterException> AdjustSalesTax;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Adj. Sales Tax")]
protected void adjustSalesTax()
{
// put code here to adjust sales tax
}
public PXAction<APInvoice> ApplyPriceException;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Apply Price Exc.")]
protected void applyPriceException()
{
APTran row = Base.Transactions.Current;
if(row == null)
{
throw new PXException("No rows selected");
}
APRegisterException rException = new APRegisterException();
rException.APRegisterRefNbr = row.RefNbr;
rException.APTranLineNbr = row.LineNbr;
rException.ExceptionDesc = row.TranDesc;
rException.ExceptionType = "PRC";
Exceptions.Insert(rException);
}
public PXAction<APInvoice> ApplyQtyException;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Apply Qty Exc.")]
protected void applyQtyException()
{
APTran row = Base.Transactions.Current;
if(row == null)
{
throw new PXException("No rows selected");
}
APRegisterException rException = new APRegisterException();
rException.APRegisterRefNbr = row.RefNbr;
rException.APTranLineNbr = row.LineNbr;
rException.ExceptionDesc = row.TranDesc;
rException.ExceptionType = "QTY";
Exceptions.Insert(rException);
}
public PXAction<PX.Objects.AP.APInvoice> ApplyFreightException;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Apply Freight Exc.")]
protected void applyFreightException()
{
string exceptionMessage = string.Empty;
// insert freight exception code here
if(_currentDoc.DocType != "INV" ) { exceptionMessage += "Document type must be 'Bill' to apply a freight exception. \n"; }
if(!string.IsNullOrEmpty(exceptionMessage))
{
throw new PXException("One or more errors occured trying to save this record. \n" + exceptionMessage);
}
// set the current document to hold
_currentDoc.Hold = true;
// create the exception record and store it in cache
APRegisterException rException = new APRegisterException();
rException.APRegisterRefNbr = _currentDoc.RefNbr;
rException.ExceptionDesc = "FREIGHT";
rException.ExceptionType = "FRT";
Exceptions.Insert(rException);
// Base.Actions.PressSave();
}
public PXAction<PX.Objects.AP.APInvoice> ApplySalesTaxException;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Apply Sales Tax Exc.")]
protected void applySalesTaxException()
{
string exceptionMessage = string.Empty;
if(_currentDoc.RefNbr == "<NEW>") { exceptionMessage += "Please save the invoice before applying a sales tax exception. \n"; }
if(_currentDoc.DocType != "INV" ) { exceptionMessage += "Document type must be 'Bill' to apply a sales tax exception. \n"; }
//if(((APInvoice)_currentDoc).CuryTaxTotal == 0) { exceptionMessage += "Tax total must be greate than $0.00 to apply a sales tax exception. \n"; }
if(!string.IsNullOrEmpty(exceptionMessage))
{
throw new PXException("One or more errors occured trying to save this record. \n" + exceptionMessage);
}
// set the current document to hold
_currentDoc.Hold = true;
// create the exception record and store it in cache
APRegisterException rException = new APRegisterException();
rException.APRegisterRefNbr = _currentDoc.RefNbr;
rException.ExceptionDesc = "SALES TAX";
rException.ExceptionType = "TAX";
Exceptions.Insert(rException);
// Base.Actions.PressSave();
}
#endregion
}
}
解决方案
- 您似乎没有使用 APRegisterException 类上的 PXParent 和 PXDBDefault 属性为您的 DAC 定义父子关系,并且需要调整您的键来完成所描述的业务用例。
- 在声明的“异常”视图中包含对 DocType 的限制,否则不同的文档类型可能会拉取与其他文档关联的异常。
在 APRegisterException 上包括审计字段以及 tstamp 和 noteID。
[Serializable] public class APRegisterException : IBqlTable { #region APRegisterRefNbr [PXDBString(15, IsKey = true, IsUnicode = true, InputMask = "")] [PXUIField(DisplayName = "Ref Nbr")] [PXParent(typeof(Select<APInvoice, Where<APInvoice.refNbr, Equal<Current<APRegisterException.refNbr>>, And<APInvoice.docType, Equal<Current<APRegisterException.docType>>>>>))] [PXDBDefault(typeof(APInvoice.refNbr))] public virtual string APRegisterRefNbr { get; set; } public abstract class aPRegisterRefNbr : IBqlField { } #endregion #region APDocType [PXDBString(3, IsKey = true, IsUnicode = true, InputMask = "")] [PXUIField(DisplayName = "Doc Type")] [PXDBDefault(typeof(APInvoice.docType))] public virtual string APDocType { get; set; } public abstract class aPDocType: IBqlField { } #endregion #region ExceptionDesc [PXDBString(150, IsUnicode = true, InputMask = "")] [PXUIField(DisplayName = "Description")] public virtual string ExceptionDesc { get; set; } public abstract class exceptionDesc : IBqlField { } #endregion #region ExceptionType [PXDBString(3, IsUnicode = true, InputMask = "", IsKey = true)] [PXUIField(DisplayName = "Exc. Type")] public virtual string ExceptionType { get; set; } public abstract class exceptionType : IBqlField { } #endregion #region ApprovedByID [PXDBString(15, IsUnicode = true, InputMask = "")] [PXUIField(DisplayName = "Approved By")] public virtual string ApprovedByID { get; set; } public abstract class approvedByID : IBqlField { } #endregion #region ApprovedDate [PXDBDate()] [PXUIField(DisplayName = "Approval Date")] public virtual DateTime? ApprovedDate { get; set; } public abstract class approvedDate : IBqlField { } #endregion }
推荐阅读
- rxjs - RXJS switchmap + tap like 运算符
- sql - sql从egthe 5th记录到最后选择记录
- reactjs - react redux-thunk 中递归 api 调用的正确模式
- ios - pod update 导致错误 [致命:无法访问]
- javascript - 在模态组件中阻止焦点的最佳做法是什么?
- mysql - mysql加入不同的字段
- c++ - 我如何从文本文件中获取值然后用它们执行一些计算(例如相乘并显示它们)?
- python - 对 Python 请求的卷曲命令 - 不起作用
- android - 无论应用程序在后台还是前台,都未收到 FCM 通知
- c# - 是否可以使用登录用户的令牌连接到 SharePoint