在Acumatica中动态更改PXSelector [英] Dynamically changing PXSelector in Acumatica

查看:79
本文介绍了在Acumatica中动态更改PXSelector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用例:

Acumatica组合框/下拉列表,可以有8个左右的值,其选择确定了用于表/ DAC的值

Acumatica combo box / dropdown, which can have 8 or so values, the selection of which determines the table / DAC used to present in a PXSelector.

例如:

-如果用户选择选项a,则需要在PXSelector中显示表A的值

-If user select option a, I need to show in PXSelector values from Table A

-如果用户选择选项b,则需要在PXSelector中显示表B的值

-If user select option b, I need to show in PXSelector values from Table B

-如果用户选择选项c,则需要在表C中显示PXSelector值

-If user select option c, I need to show in PXSelector value from Table C

我知道我必须使用自定义选择器属性,但是详细信息

I understand that I'd have to use a Custom Selector Attribute, but the details of how to do this are not clear.

推荐答案

如您所说,您需要实现一个从<$继承的属性c $ c> PXCustomSelectorAttribute 类。

As you said, you need to implement an attribute that inherits from the PXCustomSelectorAttribute class.

1-创建一个类 PromptType ID Description 来保存每个表的类型。

1- Create a class PromptType that will have an ID and Description that will hold the types of each table.

public class PromptType
{
    public Type Id { get; set;}
    public Type Description { get; set; }
}





2-实现customSelectorAttribute,如下所示:

2- Implement the customSelectorAttribute, like this:

public class MyCustomSelector : PXCustomSelectorAttribute
{
    //Class used to display the data into the selector
    [Serializable]
    public class TableDummy : IBqlTable
    {
        #region Id

        [PXInt(IsKey = true)]
        [PXUIField(DisplayName = "Id")]
        public int? Id { get; set; }

        public class id : IBqlField { }

        #endregion


        #region Description

        [PXString(60, IsUnicode = true, InputMask = "")]
        [PXUIField(DisplayName = "Description", Visibility = PXUIVisibility.SelectorVisible)]
        public string Description { get; set; }

        public class description : IBqlField { }

        #endregion
    }

    //Selected table
    private Type _TableSelection;

    //Tables Ids. You can add as much field ID as you want
    private Type _TableFieldA;
    private Type _TableFieldB;
    private Type _TableFieldC;

    //Tables description fields
    private Type _TableAFieldDesc;
    private Type _TableBFieldDesc;
    private Type _TableCFieldDesc;


    public MyCustomSelector(Type tableSelection, Type tableFieldA, Type tableAFieldDesc, Type tableFieldB, Type tableBFieldDesc, Type tableFieldC, Type tableCFieldDesc) : base(typeof(TableDummy.id))
    {
        _TableSelection = tableSelection;
        _TableFieldA = tableFieldA;
        _TableFieldB = tableFieldB;
        _TableFieldC = tableFieldC;
        _TableAFieldDesc = tableAFieldDesc;
        _TableBFieldDesc = tableBFieldDesc;
        _TableCFieldDesc = tableCFieldDesc;
    }

    //Get the name of the selected table by using the private field _TableSelection.
    private string GetSelection()
    {
        var cache = _Graph.Caches[_BqlTable];
        return cache.GetValue(cache.Current, _TableSelection.Name)?.ToString();
    }

    //Return a pompt instance based on the selected table in the dropdown.
    private PromptType GetSelectedTableField(string selectedTable)
    {
        switch (selectedTable)
        {
            case "A":
                return new PromptType() { Id = _TableFieldA, Description = _TableAFieldDesc };
            case "B":
                return new PromptType() { Id = _TableFieldB, Description = _TableBFieldDesc };
            case "C":
                return new PromptType() { Id = _TableFieldC, Description = _TableCFieldDesc };
            default:
                return new PromptType() { Id = _TableFieldA, Description = _TableAFieldDesc };
        }
    }

    //Return the records
    public IEnumerable GetRecords()
    {
        var selectedField = GetSelectedTableField(GetSelection());
        var selectedTable = BqlCommand.GetItemType(selectedField.Id);

        var select = BqlCommand.Compose(
                        typeof(Select<>),
                            selectedTable
                        );

        var cmd = BqlCommand.CreateInstance(select);
        PXView view = new PXView(_Graph, true, cmd);

        foreach (var row in view.SelectMulti())
        {
            var id = (int?)view.Cache.GetValue(row, selectedField.Id.Name);
            var description = view.Cache.GetValue(row, selectedField.Description.Name)?.ToString();
            yield return new TableDummy { Id = id, Description = description };
        }
    }
}

您可以更改

3-实现自定义属性后,您就可以在您的字段中像这样使用它:

3- Once you have implemented your custom attribute, you can use it in your field like this:

#region DropDown to select a table
[PXDBString(1)]
[PXUIField(DisplayName = "Table Selection")]
[PXStringList(
    new string[]
    {
        "A",
        "B",
        "C"
    },
    new string[]
    {
            "Table A",
            "Table B",
            "Table C"
    })]
public virtual string UsrTableSelection { get; set; }
public abstract class usrTableSelection : IBqlField
{
}
#endregion

#region Selector
[PXDBInt]
[PXUIField(DisplayName = "Table Selector")]
[MyCustomSelector(
    typeof(APRegisterExt.usrTableSelection), 
    typeof(TableA.id),typeof(TableA.description),
    typeof(TableB.id), typeof(TableB.description),
    typeof(PX.Objects.AR.Customer.bAccountID), 
    typeof(PX.Objects.AR.Customer.acctName))]
public virtual int? UsrTableSelector { get; set; }

public abstract class usrTableSelector : IBqlField
{
}
#endregion





4-同样,您也不要忘记在表字段中设置可见性。我指的是您要在选择器中显示的表( DAC )。假设您要显示 TableA TableB TableC 根据您的下拉菜单,需要在选择器中要使用的字段上设置可见性。

4- Also, you should not forget to set the visibility on your tables fields. I'm referring to the tables (DACs) that you want to display in the selector. Let say that you want to display TableA, TableB or TableC depending on your drop down, you need to set the visibility on the fields that you are going to use in the selector.

这是其中一个表的实现我在测试中使用过:

Here's the implementation of one of the tables that I used during my tests:

[Serializable]
public class TableA : IBqlTable
{
    #region Id

    [PXDBInt(IsKey = true)]
    [PXUIField(DisplayName = "Id")]
    public int? Id { get; set; }

    public class id : IBqlField { }

    #endregion


    #region Description

    [PXDBString(60, IsUnicode = true, InputMask = "")]
    [PXUIField(DisplayName = "Description", Visibility = PXUIVisibility.SelectorVisible)]
    public string Description { get; set; }

    public class description : IBqlField { }

    #endregion


    #region InfoA

    [PXDBString(60, IsUnicode = true, InputMask = "")]
    [PXUIField(DisplayName = "Info A", Visibility = PXUIVisibility.SelectorVisible)]
    public string InfoA { get; set; }

    public class infoA : IBqlField { }

    #endregion
}

通过将可见性设置为 SelectorVisible ,该字段将自动显示在PXSelector中。

By setting the visibility to SelectorVisible, the field will be displayed automatically in the PXSelector.

5-最后,您需要将 CommitChanges 设置为 True 上的下拉菜单,然后在表单字段上将 AutoRefresh 设置为 True 。例如:

5- Finally, you need to set CommitChanges to True on your dropdown and set AutoRefresh to True on your form field. Here's an example:

<px:PXDropDown runat="server" ID="CstPXDropDown1" DataField="UsrTableSelection" CommitChanges="True" />
<px:PXSelector runat="server" ID="CstPXSelector2" DataField="UsrTableSelector" AutoRefresh="True" />

这篇关于在Acumatica中动态更改PXSelector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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