从 BAccountMaint 扩展更新客户(错误 #91 另一个进程已更新..)

Update Customer from BAccountMaint extension (Error #91 Another process has updated..)

我已经使用新的 UsrAccountType 字段扩展了企业帐户 DAC。当该字段通过业务帐户维护图更新时,我还需要更新相关客户记录中的各个字段。但是,当坚持 "Error #91: Another process has updated 'BAccount' record. Your changes will be lost." 发生时。

首先,我只是尝试将 Customer.customerClassID 字段设置为与帐户类型相同的值,帐户类型是客户 类 的子集,并更改与更改相关的其他字段客户class无需申请。

public class BusinessAccountMaint_Extension : PXGraphExtension<BusinessAccountMaint>
{
    public PXSelect<Customer, Where<Customer.bAccountID, Equal<Current<BAccount.bAccountID>>>> ARCustomer;

    public virtual void BAccount_UsrAccountType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
    {
        BAccount row = (BAccount)e.Row;
        if (row == null) return;
        BAccount_Extension rowExt = row.GetExtension<BAccount_Extension>();

        Customer customer = ARCustomer.Current;
        if (customer == null) return;

        customer.CustomerClassID = rowExt.UsrAccountType;
        // additional changes to Customer record
        this.Base.Caches<Customer>().Update(customer);
    }
}

如何在更新 BAccount 的同时更新客户?我是否需要创建 CustomerMaint 图并通过它更新记录——这不会导致同时更新两条记录的相同问题吗?或者可以在 BAccount 更改已保留并在那里完成对客户的更改后在 BAccount_RowPersisted 中完成某些操作吗?

此行为的根本原因是 customer 派生自 BAccount。

[PXCacheName(Messages.Customer)]
[PXEMailSource]
public partial class Customer : BAccount, PX.SM.IIncludable
{

因此,如果您更新客户记录,BAccount 记录也会更新。

要绕过它,您必须创建自己的客户 DAC,而不是从 BAccount 派生并更新它。

namespace  SomeNamespce
{
     [Serializable]
    public partial class Customer : IBqlTable
    {
        public abstract class bAccountID : PX.Data.IBqlField
        {
        }
        [PXDBIdentity((IsKey = true))]
        public virtual int? BAccountID
        {
            get;
            set;
        }
        public abstract class customerClassID : PX.Data.IBqlField
        {
        }
        [PXDBString(10, IsUnicode = true)]
        //[PXDefault(typeof(Search<ARSetup.dfltCustomerClassID>))]
        //[PXSelector(typeof(CustomerClass.customerClassID), DescriptionField = typeof(CustomerClass.descr), CacheGlobal = true)]
        public virtual String CustomerClassID
        {
            get;
            set;
        }
    }
}
namespace  YourNamespace
{ 
    public class BusinessAccountMaint_Extension : PXGraphExtension<BusinessAccountMaint>
    {
        public PXSelect<SomeNamespce.Customer , Where<SomeNamespce.Customer.bAccountID, Equal<Current<BAccount.bAccountID>>>> ARCustomer;

        public virtual void BAccount_UsrAccountType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            BAccount row = (BAccount)e.Row;
            if (row == null) return;
            BAccount_Extension rowExt = row.GetExtension<BAccount_Extension>();

            SomeNamespce.Customer customer = ARCustomer.Current;
            if (customer == null) return;

            customer.CustomerClassID = rowExt.UsrAccountType;
            // additional changes to Customer record
            ARCustomer.Update(customer);
        }
    }
}