【问题标题】:Dynamically changing PXSelector by event in Acumatica在 Acumatica 中按事件动态更改 PXSelector
【发布时间】:2021-05-12 19:41:25
【问题描述】:

我在形成动态选择器时遇到了一些问题,下面我将想象一下已经完成了什么。 我需要根据所选 AssetId 动态生成选择器。 AssedInfo 选择器必须根据 AssetId 中选择的信息类型返回信息。我试过了,分步骤:

public class NSIAssetLinkInfo: IBqlTable
    {
        #region AssetId
        [PXDBString(500, IsUnicode = true, InputMask = "")]
        [PXUIField(DisplayName = "Asset Id")]
        [PXStringList(
            new string[]
            {
                "AssedInfo","GLTran"
            },
            new string[]
            {
                "AssedInfo","GLTran"
            })]
        public virtual string AssetId { get; set; }
        public new abstract class assetId : PX.Data.BQL.BqlString.Field<assetId> { }
        #endregion

        #region AssetInfo
        [PXUIField(DisplayName = "Asset Information")]
        [PXDBString(500, IsUnicode = true, InputMask = "")]
        public virtual string AssetInfo { get; set; }
        public abstract class assetInfo : PX.Data.BQL.BqlString.Field<assetInfo> { }
        #endregion
    }

在这里,我创建了一个按钮和一个应该动态形成我们的选择器的事件。 并且选择器将形成的事件还必须返回不是所有的列,而只返回必要的列,例如“AssetID - RecordType”,如果你是准确的,那么你只需要我将指出的那些列,而不是全部。 added button to panel

public class KNRWAPInvoiceEntryExt : PXGraphExtension<APInvoiceEntry>
    {

        public SelectFrom<GLTranR>.View GLTrans;
        public SelectFrom<FixedAsset>.View FXAsset;

        public SelectFrom<NSIAssetLinkInfo>.View NSIAssetLinkInfo;

      
        public PXAction<APInvoice> LinkInfo;
        [PXButton]
        [PXUIField(DisplayName = "LinkInfo", MapEnableRights = PXCacheRights.Delete, MapViewRights = PXCacheRights.Delete)]
        protected void linkInfo()
        {
            if (TagPanel.AskExt(true) != WebDialogResult.OK) return;

            //Do some useful Stuff
        }

        public PXFilter<NSIAssetLinkInfo> TagPanel;


        public virtual void _(Events.FieldSelecting<NSIAssetLinkInfo, NSIAssetLinkInfo.assetId> e)
        {
            if (e.Row == null)
            {
                return;
            }
            var assetId = e.Row.AssetId;
            

            if (assetId == "GLTran")
            {
                //gltran
                //saves TranID
                //Displays RefNbr - InventoryID
                //not all gltran, but gltran which has accountid
                var returnState = PXFieldState.CreateInstance(e.ReturnState, dataType: typeof(FixedAsset), isKey: false, nullable: null,
                    required: null, precision: null, length: null, defaultValue: null, fieldName: null);
                e.ReturnState = returnState;
                returnState.Visible = true;
                returnState.Visibility = PXUIVisibility.Visible;
                returnState.Enabled = true;
                returnState.DisplayName = "RefNbr";
                returnState.ViewName = "GLTrans";
                returnState.DescriptionName = "GLTranR";
                returnState.FieldList = new[] { nameof(FixedAsset.AssetID), nameof(FixedAsset.Description), nameof(FixedAsset.Depreciable) };
                returnState.HeaderList = new[]
                {
                    PXUIFieldAttribute.GetDisplayName<FixedAsset.assetID>(FXAsset.Cache),
                    PXUIFieldAttribute.GetDisplayName<FixedAsset.description>(FXAsset.Cache),
                    PXUIFieldAttribute.GetDisplayName<FixedAsset.depreciable>(FXAsset.Cache),
                };
            }
            if (assetId == "AssedInfo")
            {
                //Fixed Asset
                //saves InventoryID
                //InventoryID - Desc
                //not all fixed assets, but those, which has class 
                var returnState = PXFieldState.CreateInstance(e.ReturnState, dataType: typeof(GLTranR), isKey: false, nullable: null,
                    required: null, precision: null, length: null, defaultValue: null, fieldName: null);
                //descriptionName: null, displayName: null, error: null, errorLevel: PXErrorLevel.Undefined,
                //enabled: null, visible: null, readOnly: false, visibility: PXUIVisibility.Visible, viewName: null,
                //fieldList: null, headerList: null);
                e.ReturnState = returnState;
                returnState.Visible = true;
                returnState.Visibility = PXUIVisibility.Visible;
                returnState.Enabled = true;
                returnState.DisplayName = "RefNbr";
                returnState.ViewName = "GLTrans";
                returnState.DescriptionName = "GLTranR";
                returnState.FieldList = new[] { nameof(GLTranR.InventoryID), nameof(GLTranR.TranDesc), nameof(GLTranR.RefNbr), nameof(GLTranR.DebitAmt), nameof(GLTranR.CreditAmt) };
                returnState.HeaderList = new[]
                {
                    PXUIFieldAttribute.GetDisplayName<GLTranR.inventoryID>(GLTrans.Cache),
                    PXUIFieldAttribute.GetDisplayName<GLTranR.tranDesc>(GLTrans.Cache),
                    PXUIFieldAttribute.GetDisplayName<GLTranR.refNbr>(GLTrans.Cache),
                    PXUIFieldAttribute.GetDisplayName<GLTranR.debitAmt>(GLTrans.Cache),
                    PXUIFieldAttribute.GetDisplayName<GLTranR.creditAmt>(GLTrans.Cache)
                };
            }
        }
    }

视图中的按钮

<CallbackCommands>
    <px:PXDSCallbackCommand Name="LinkInfo" Visible="false" />
</CallbackCommands>

<px:PXToolBarButton>
           <AutoCallBack Command="LinkInfo" Target="ds" />
</px:PXToolBarButton>

<px:PXSmartPanel ID="pnlCopyCompany" runat="server" CaptionVisible="True" Caption="My Command" Style="position: static" LoadOnDemand="True" Key="TagPanel" AutoCallBack-Target="frmMyCommand" AutoCallBack-Command="Refresh" DesignView="Content">
<px:PXFormView ID="frmMyCommand" runat="server" SkinID="Transparent" DataMember="TagPanel"  DataSourceID="ds" EmailingGraph="">
           <Template>
<px:PXGrid runat="server" SyncPosition="true" KeepPosition="true" Height="150px" SkinID="Details" Width="865px" Caption="Caption"
              CaptionVisible="false" MatrixMode="True" RepaintColumns="true"
DataSourceID="ds" AllowPaging="True" AdjustPageSize="Auto" NoteIndicator="false" FilesIndicator="false" Style='left: 0px; top: 0px; height: 188px;'>
              <AutoSize Enabled="True" MinHeight="200" />
                    <ActionBar PagerVisible="False" />
                    <CallbackCommands>
                        <Refresh CommitChanges="True" />
                    </CallbackCommands>
                    <Levels>
<px:PXGridLevel DataMember="NSIAssetLinkInfo" DataKeyNames="TagInfoID">
                            <RowTemplate>
                                <px:PXDropDown runat="server" ID="edAssetId" CommitChanges="True" DataField="AssetId" AllowMultiSelect="True" />
<px:PXSelector runat="server" ID="edAssetInfo" DataField="AssetInfo" AutoRefresh="True" CommitChanges="True" />
                            </RowTemplate>
                            <Columns>
                                <px:PXGridColumn DataField="AssetId" CommitChanges="True" />
<px:PXGridColumn DataField="AssetInfo" CommitChanges="True" />
                            </Columns>
                        </px:PXGridLevel>
                    </Levels>
                </px:PXGrid>
            </Template>
        </px:PXFormView>
</px:PXSmartPanel>

I plan what would be like this

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    我正在努力遵循你的榜样与你所说的你需要做的事情。看起来您希望将 AssetID 中的允许值列表正确设置为预定义列表。如果您使用 RowSelected 事件并预定义您的允许列表,这将比您的示例简单得多。下面是一个非常精简的示例,显示了我如何使用 1 个示例列表完成此操作。您可以根据允许的组合定义多个列表,并根据您的条件为 listattr 指定所需的类型。

    protected void _(Events.RowSelected<XXMyDAC> e)
    {
        if(*condition*) // Substitute your conditional logic here
        {
            SelectableValues listattr = new SelectableValues();
            PXStringListAttribute.SetList<XXMyDAC.myField>
                (e.Cache, row, listattr.AllowedValues, listattr.AllowedLabels);
        }
    }
    
    public class SelectableValues : PXStringListAttribute
    {
    
        public string[] AllowedLabels = new string[]
        {
                Messages.MyLabel1,
                Messages.MyLabel2
        };
    
        public string[] AllowedValues = new string[]
        {
                MyValue1,
                MyValue2
        };
    }
    

    如果您需要限制从数据库而不是从预定义列表返回的值,您可以直接在 DAC 中或通过图中的 CacheAttached 对 DAC 字段使用 PXRestrictorAttribute。这是一个非常简单的示例,它使用一个名为 UsrXXMyCondition 的自定义字段添加到 INLocation(通过 DAC 扩展 INLocationExt)。

    [PXMergeAttributes(Method = MergeMethod.Append)]
    [PXRestrictor(typeof(
        Where<INLocationExt.usrXXMyCondition, NotEqual<ConditionType.condition1>>
        ), "")]
    protected virtual void INTran_ToLocationID_CacheAttached(PXCache sender) { }
    

    【讨论】:

      猜你喜欢
      • 2016-08-31
      • 1970-01-01
      • 2022-01-15
      • 2022-12-15
      • 2016-05-06
      • 2016-02-27
      • 2018-10-19
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多