保存记录时插入网格线 [英] Insert a grid line when the record gets saved

查看:81
本文介绍了保存记录时插入网格线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在持久逻辑期间向网格添加新记录.但是,即使确实将记录添加到UI的网格中,刷新页面时,新行也会消失.它并没有持久保存在数据库中.

I am trying to add a new record to a grid during the persist logic. However, even though the record does get added to the grid in the UI, when the page gets refreshed, the new line disappears. It is not getting persisted in the DB.

我正在使用账单页面作为参考.

I am using the Bills page as reference.

代码示例

protected virtual void APTran_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
    if (e.Row == null)
    {
        return;
    }

    APInvoice invoiceRow = this.Base.Document.Current;

    if (invoiceRow != null)
    {

        APTran tranRow = new APTran();
        tranRow = this.Base.Transactions.Insert(tranRow);

        tranRow.InventoryID = 10043;
        this.Base.Transactions.Update(tranRow);

        tranRow.Qty = 3;
        this.Base.Transactions.Update(tranRow);
    }
}

保存后的结果-记录显示在网格中:

Result after saving - Record is shown in the grid:

取消后的结果-记录从网格中消失:

Result after cancelling - Record disappears from the grid:

推荐答案

像这样的事情我倾向于在调用base持久化之前重写Persist方法并插入或更新相关记录.这是您的图形扩展中的一个可能示例:

Something like this I tend to override the Persist method and insert or update related records before calling base persist. Here is a possible example which goes inside your graph extension:

[PXOverride]
public virtual void Persist(Action del)
{
    foreach(APInvoice invoiceRow in Base.Document.Cache.Inserted)
    {
        APTran tranRow = this.Base.Transactions.Insert();

        tranRow.InventoryID = 10043;
        tranRow = this.Base.Transactions.Update(tranRow);

        tranRow.Qty = 3;
        this.Base.Transactions.Update(tranRow);
    }

    del?.Invoke();
}

这篇关于保存记录时插入网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆