客户位置的建筑物处理屏幕

时间:2019-06-07 13:50:38

标签: acumatica

我需要为客户位置建立一个处理屏幕,以确定并更新位置上的居民标志。

此代码正确处理每个选定的记录,并显示为更新相应的字段。但是我遇到的问题是我对Location所做的更改未保存回数据库。

“客户位置”图需要先指定企业帐户,然后才能输入“位置ID”,我怀疑因此不能简单地更新图上的“位置”视图。但是我找不到任何文档或代码示例来说明我应该在此处使用哪种方法。

这是我的处理屏幕图形上的代码:

public class ProcessCustomerLocations : PXGraph<ProcessCustomerLocations>
{
    public PXCancel<Location> Cancel;
    public PXProcessing<Location, Where<Location.isActive, Equal<True>>> Locations;

    public static void Process(List<Location> locations)
    {
        var graph = PXGraph.CreateInstance<CustomerLocationMaint>();
        CustomerLocationMaint_Extension graphExt = graph.GetExtension<CustomerLocationMaint_Extension>();

        foreach (var location in locations)
        {
            graphExt.UpdateLocation(location, true);
        }
    }

    public ProcessCustomerLocations()
    {
        Locations.SetProcessDelegate(Process);
    }

}

这是我在CustomerLocationMaint_Extension图上的代码:

public class CustomerLocationMaint_Extension : PXGraphExtension<CustomerLocationMaint>
{
  public void UpdateLocation(Location location, bool isMassProcess = false)
    {
        bool isRes = false;

        Base.Location.Current = Base.Location.Search<Location.locationID>(location.LocationID, location.BAccountID);
        LocationExt locationExt = location.GetExtension<LocationExt>();

        // INSERT CODE TO DETERMINE VALUE OF isRes
        locationExt.UsrResidentialValidated = true;
        location.CResedential = isRes;

        Base.Location.Update(location);
        Base.Actions.PressSave();
    }
}

我要在“位置”上更新的一个字段是一个名为UsrResidentialValidated的自定义字段。这是该字段的代码。

namespace PX.Objects.CR
{
  public class LocationExt : PXCacheExtension<PX.Objects.CR.Location>
  {          
    #region UsrResidentialValidated
    [PXDBBool]
    [PXUIField(DisplayName="Residential Validated")]

    public virtual bool? UsrResidentialValidated { get; set; }
    public abstract class usrResidentialValidated : IBqlField { }
    #endregion
  }
}

更新

感谢@Samvel的帮助,我对UpdateLocation代码进行了如下修改。以下代码确实将更改保存到数据库(在自定义字段和非自定义字段上),这很棒。但是,为此,我必须创建一个新的Location对象“ myLocation”,并且不再使用PXProcessing图形传递给UpdateLocation的“ location”对象。这意味着在处理之后,当处理屏幕显示带有已修改数据的处理记录时(处理完成之后和刷新屏幕之前),它不会显示更新的值。有什么办法可以使处理屏幕显示更新的值并将更改保存到数据库吗?

    public void UpdateLocation(PX.Objects.CR.Location location, bool isMassProcess = false)
    {
        bool isRes = true;

        Location myLocation = PXSelect<Location,
              Where<Location.bAccountID, Equal<Required<Location.bAccountID>>, And<Location.locationID, Equal<Required<Location.locationID>>>>>
              .Select(this.Base, location.BAccountID, location.LocationID);

        this.Base.Location.Current = myLocation;

        LocationExt locationExt = myLocation.GetExtension<LocationExt>();
        locationExt.UsrResidentialValidated = true;

        myLocation.CResedential = isRes;
        Base.Location.Current = Base.Location.Update(myLocation);

        this.Base.Save.Press();
    }

1 个答案:

答案 0 :(得分:1)

已更新

我已更新代码以适合您的情况。处理完所有记录后,将更新网格中的记录并显示已修改的记录。 您可以通过this link

下载此代码的自定义程序包

要创建用于更新位置的处理页面,您应该执行以下步骤:

  1. 将“选定”字段添加到位置DAC

    public sealed class LocationExt: PXCacheExtension<Location>
    {
        #region Selected
        public abstract class selected : IBqlField
        { }
        [PXBool()]
        [PXDefault(true,PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "Selected")]
        public bool? Selected { get; set; }
        #endregion
        #region UsrResidentialValidated
        [PXDBBool]
        [PXUIField(DisplayName = "Residential Validated")]
        public bool? UsrResidentialValidated { get; set; }
        public abstract class usrResidentialValidated : IBqlField { }
        #endregion
    }
    

    此步骤是必需的,因为否则将永远不会调用您的SetProcessDelegate的代表。 Acumatica正在检查是否有至少一条选定的记录,然后再调用Process Delegate。

  2. 创建如下所示的处理图:

    using PX.Data;
    using PX.Objects.CR;
    using System.Collections.Generic;
    
    namespace CustomerLocationUpdate
    {
        public class ProcessCustomerLocations : PXGraph<ProcessCustomerLocations>
        {
            public PXCancel<Location> Cancel;
            public PXProcessingJoin<Location,InnerJoin<BAccountR,On<Location.bAccountID,Equal<BAccountR.bAccountID>>>, 
        Where<Location.isActive, Equal<True>,And<Location.locType, Equal<PX.Objects.CR.LocTypeList.customerLoc>>>> Locations;
    
            public static void Process(List<Location> locations)
            {
                var graph = PXGraph.CreateInstance<PX.Objects.AR.CustomerLocationMaint>();
                CustomerLocationMaint_Extension graphExt = graph.GetExtension<CustomerLocationMaint_Extension>();
    
                foreach (var location in locations)
                {
                    graphExt.UpdateLocation(location, true);
                    graph.Clear();
                }
            }
    
            public ProcessCustomerLocations()
            {
                Locations.SetProcessDelegate(Process);
            }
        }
    }   
    

    您可以看到,由于某种原因,我隐式指定了PX.Objects.AR和PX.Objects.CR。

  3. 在GraphExtension中创建UpdateLocation方法:

    using PX.Data;
    
    namespace CustomerLocationUpdate
    {
        public class CustomerLocationMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerLocationMaint>
        {
            public void UpdateLocation(PX.Objects.CR.Location location, bool isMassProcess = false)
            {
                bool isRes = false;
                this.Base.Location.Current = PXSelect<PX.Objects.CR.Location,Where<PX.Objects.CR.Location.bAccountID,Equal<Required<PX.Objects.CR.Location.bAccountID>>,And<PX.Objects.CR.Location.locationID,Equal<Required<PX.Objects.CR.Location.locationID>>>>>.Select(this.Base,location.BAccountID,location.LocationID);
                this.Base.Location.Current.CResedential = isRes;
                LocationExt locationExt = PXCache<PX.Objects.CR.Location>.GetExtension<LocationExt>(this.Base.Location.Current);
                locationExt.UsrResidentialValidated = false;
                this.Base.Location.Current = this.Base.Location.Update(this.Base.Location.Current);
                this.Base.Save.Press();
            }
        }
    }
    

    如您所见,我正在使用PXSelect而不是Location.Current来设置Location.Current.Search。 由于某些原因,Location.Current.Search总是返回null。 可能是由于应用了PXProjectionAttribute引起的,我不确定确切的原因是什么。