Acumatica 中动态变化的 PXSelector

2024-01-06

我有以下用例:

Acumatica 组合框/下拉列表,可以有 8 个左右的值,其选择决定了用于在 PXSelector 中呈现的表/DAC。

e.g.:

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

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

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

我知道我必须使用自定义选择器属性,但如何执行此操作的详细信息尚不清楚。


正如你所说,你需要实现一个继承自PXCustomSelectorAttribute class.

1-创建一个类PromptType将会有一个ID and Description这将保存每个表的类型。

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

2- 实现 customSelectorAttribute,如下所示:

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- 实现自定义属性后,您可以在您的字段中使用它,如下所示:

#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-此外,您不应该忘记设置表字段的可见性。我指的是表格(DACs)您想要在选择器中显示的内容。假设您要显示TableA, TableB or TableC根据您的下拉列表,您需要设置要在选择器中使用的字段的可见性。

这是我在测试期间使用的表之一的实现:

[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 中。


5-最后,你需要设置CommitChanges to True在你的下拉菜单中并设置AutoRefresh to True在您的表单字段上。这是一个例子:

<px:PXDropDown runat="server" ID="CstPXDropDown1" DataField="UsrTableSelection" CommitChanges="True" />
<px:PXSelector runat="server" ID="CstPXSelector2" DataField="UsrTableSelector" AutoRefresh="True" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Acumatica 中动态变化的 PXSelector 的相关文章

随机推荐

  • 构建 cassandra 数据库

    我对卡桑德拉一无所知 比如说 我有一个类似于 Facebook 的网站 人们可以在那里分享 点赞 评论 上传图片等等 现在 假设我想要得到我朋友所做的所有事情 用户名1 喜欢你的评论 用户名 2 更新了他的个人资料图片 等等 因此 经过大量
  • Java ArrayList 删除对象 - IndexOutOfBoundsException

    我试图从 ArrayList 中删除一个对象 但不断收到 IndexOutOfBounds 错误 现在有大量可用信息 为什么会发生这种情况迭代在 ArrayList 上去除时 但是我不会那样做 例子 ArrayList
  • 在 python 中定义组合函数时卡住了

    输入 两个函数 f 和 g 表示为字典 使得 g f 存在 输出 表示函数 g f 的字典 示例 给定 f 0 a 1 b 和 g a apple b banana 返回 0 apple 1 香蕉 最接近正确答案的是 i g j for i
  • PHP 变量和 MySQL LIKE 查询不起作用

    我有以下代码 surname POST surname sql2 SELECT FROM andriana WHERE surname LIKE surname if mysql query sql2 con die Error mysql
  • excel vba dir函数查找doc而不是docx

    我在 excel 中使用此 vba 代码从特定文件夹中获取文件名 Sub getfilelistfromfolder Dim varDirectory As Variant Dim flag As Boolean Dim i As Inte
  • 如何从 Go 1.18 二进制文件中读取调试 VCS 版本信息?

    我正在尝试从 Go 二进制文件中读取版本控制信息 但构建信息似乎不包含任何 VCS 信息 从Go 1 18开始发行说明 https tip golang org doc go1 18 go 命令现在将版本控制信息嵌入到二进制文件中 它包括当
  • AES 加密 Java -> PHP -> Java

    在我的 Android 应用程序中 我正在与 Web 服务通信 发送和响应的数据均使用 AES 加密进行加密 所以我所做的如下 我正在发送一个 base64 编码的 AES 加密 JSON 字符串到 share php 然后 Share p
  • 令牌索引序列长度比使用拥抱面部情感分类器的该模型指定的最大序列长度 (651 > 512) 长

    我试图借助拥抱面部情绪分析预训练模型来获取评论的情绪 它返回错误 例如Token indices sequence length is longer than the specified maximum sequence length fo
  • C++ 以二进制模式读取文件。文件结尾问题

    我正在学习 C 我必须以二进制模式读取文件 我的做法如下 遵循 C 参考 unsigned values 255 unsigned total ifstream in test txt ifstream binary while in go
  • 四边形网格划分库

    我试图找到一个用 C 编写的网格划分库 仅使用四边形网格对自定义形状进行网格划分 这是我正在寻找的算法 代码的示例 但这不是免费的并且是用 ANSI C 编写的 http members ozemail com au comecau qua
  • RxJS5 TypeScript 打字失败

    I run tsc在我的项目中 我收到与 RxJS5 库相关的这些错误 tsc node modules rxjs observable FromEventObservable d ts 11 39 error TS2304 Cannot
  • PHP/HTML/CSS - 如果是 FireFox,是 Chrome,还是 Safari

    是否有简单的条件语句 css命令 html jquery javascript或简单的PHP动态方法来检测当前浏览器 element top 4px element top 6px element top 8px element top 1
  • 访问 ASM Java 库中的局部变量

    我试图在插入方法时调用局部变量 到目前为止 我能够获取节点中的局部变量 但在实际访问任何内容时遇到困难 这是我的插入内容 非常杂乱 我已经这样做了一段时间 设计不再是我的首要任务 不久前 final ClassReader reader n
  • Spring防止ajax调用成为身份验证时的目标url

    我有一个正在运行的 Spring Java Web 应用程序 在某些页面上 当我注销时 最后发出的请求是 AJAX 调用 因此 当我重新登录时 Spring 将我重定向到 ajax 调用 给我一个充满 json 的浏览器 我的登录成功处理程
  • 包含敏感数据的私有和公共 Git 存储库

    我当前正在运行一个服务Heroku https www heroku com Heroku 的部署方式是将代码推送到 git 存储库 这会触发构建并随后触发新代码的部署 由于这是将服务部署到 Heroku 的唯一方法 因此该 git 存储库
  • Windows 8 XAML 多列文本

    Is there a way to make columns in a text I have one big string with the text i have to display and i have a fixed height
  • 如何在 Jetpack Compose 中添加边距?

    您究竟如何添加保证金Jetpack Compose 我可以看到有一个Modifier用于填充Modifier padding 但我似乎找不到一个利润 还是我瞎了 请有人指导我 非常感谢 您可以将填充和边距视为同一件事 将其想象为 间距 填充
  • 重叠部分透明元素的不透明度

    如果你有 div 不透明度为 0 5 的元素和另一个 div 元素以相等的不透明度覆盖第一个元素 那么两个元素加在一起的不透明度是多少 它不是 5 5 也不是 5 5 遇到这样的问题我该如何计算呢 我相信您正在寻找的公式是 1 x y di
  • 当文件名大小写改变时如何切换分支?

    我有一个分行development有一个文件Config json 我正在创建一个新分支new development 我重命名的地方Config json to config json并承诺 我切换回development看看那个分支中的
  • Acumatica 中动态变化的 PXSelector

    我有以下用例 Acumatica 组合框 下拉列表 可以有 8 个左右的值 其选择决定了用于在 PXSelector 中呈现的表 DAC e g 如果用户选择选项 a 我需要在表 A 中的 PXSelector 值中显示 如果用户选择选项