错误#90:另一个进程更新了“BAccount”记录。您的更改将会丢失

时间:2015-07-30 02:11:21

标签: acumatica

我正在尝试两次更新BAccount记录,但是第二次它会抛出上述异常。

当我向下钻取异常时,我也看到了PXLockViolationException。我猜这里有一些交易事情。

基本上我是使用CustomerMaint图添加客户记录

使用graph.Actions.Save()

保存记录

然后在同一个过程中,我使用VendorMaint图添加同一客户(Baccount)的供应商记录,当我坚持更改时,它会抛出该错误。

任何帮助都将不胜感激。

欢呼声

2 个答案:

答案 0 :(得分:1)

问题来自于您尝试坚持过时的DAC这一事实。原因是您在内存中有多个相同DAC的实例。一旦你坚持更新的实例,如果你试图坚持过时的实例,你会得到一个例外。要理解为什么要使用多个实例,我们需要了解您正在使用的不同类之间的关系。

AR.Customer和AP​​.Vendor类直接从CR.BAccount继承。

客户声明:

public partial class Customer : BAccount, PX.SM.IIncludable

供应商声明

public partial class Vendor : CR.BAccount, PX.SM.IIncludable

CR.BAccount的不同可能状态是

  • 展望
  • 客户
  • 供应商
  • 客户和供应商(合并)

要从Prospect转换为Vendor或从Customer或Vendor转换,请参阅BusinessAccountMaint中的ConvertToVendor函数:

public PXAction<BAccount> converToVendor;
[PXUIField(DisplayName = Messages.ConvertToVendor, MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.Process)]
public virtual IEnumerable ConverToVendor(PXAdapter adapter)
{
    BAccount bacct = this.BAccount.Current;
    if (bacct != null && (bacct.Type == BAccountType.ProspectType || bacct.Type == BAccountType.CustomerType))
    {
        Save.Press();
        AP.VendorMaint editingBO = PXGraph.CreateInstance<AP.VendorMaint>();
        AP.VendorR vendor = (AP.VendorR)editingBO.BAccount.Cache.Extend<BAccount>(bacct);
        editingBO.BAccount.Current = vendor;
        vendor.Type = (bacct.Type == BAccountType.ProspectType) ? BAccountType.VendorType : BAccountType.CombinedType;
        LocationExtAddress defLocation = editingBO.DefLocation.Select();
        editingBO.DefLocation.Cache.RaiseRowSelected(defLocation);
        string locationType = (bacct.Type == BAccountType.ProspectType) ? LocTypeList.VendorLoc : LocTypeList.CombinedLoc;
        editingBO.InitVendorLocation(defLocation, locationType);
        defLocation = editingBO.DefLocation.Update(defLocation);
        foreach (Location iLoc in editingBO.IntLocations.Select())
        {
            if (iLoc.LocationID != defLocation.LocationID)
            {
                editingBO.InitVendorLocation(iLoc, locationType);
                editingBO.IntLocations.Update(iLoc);
            }
        }
        editingBO.Answers.CopyAttributes(vendor, bacct);
        throw new PXRedirectRequiredException(editingBO, Messages.EditVendor);
    }
    return adapter.Get();
}

要在同一进程上调用ConverToCustomer和ConverToVendor,您需要保留BAccount类的相同实例:

    public PXAction<BAccount> converToCustomerThenVendor;
    [PXUIField(DisplayName = "Convert To Customer Then Vendor No Redirection", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
    [PXButton(ImageKey = PX.Web.UI.Sprite.Main.Process)]
    public virtual IEnumerable ConverToCustomerThenVendor(PXAdapter adapter)
    {
        //Convert to Customer
        try
        {
            Base.converToCustomer.Press();
        }
        catch (PXRedirectRequiredException ex)
        {
            var customerGraph = ex.Graph as CustomerMaint;
            //Add your own extended logic here. 


            //Save the new Customer to the database
            customerGraph.Actions.PressSave();
            //Set the current instance of BAccount as the one you just saved in the customer graph
            Base.BAccount.Current = customerGraph.BAccount.Current;
        }

        //Convert to vendor
        try
        {
            Base.converToVendor.Press();
        }
        catch(PXRedirectRequiredException ex)
        {
            var vendorGraph = ex.Graph as VendorMaint;
            //Add your own extended logic here. 


            //Save the new Vendor to the database
            vendorGraph.Actions.PressSave();
            //Set the current instance of BAccount as the one you just saved in the vendor graph
            Base.BAccount.Current = vendorGraph.BAccount.Current;
        }

        //Refresh the page with the new data
        Base.Actions.PressCancel();
        return adapter.Get();

    }

答案 1 :(得分:0)

添加客户后

  1. 清除图表,
  2. 通过设置当前
  3. 将客户记录加载到图表中
  4. 然后添加其他详细信息
  5. 保存