动态更改字段属性的字符串长度或小数精度

Change String length or decimal precision of field attribute dynamically

我正在尝试使用一个 table 中的设置数据来允许我即时/动态地设置字段格式。我知道我可以根据 PXUIFieldAttribute class 更改字段名称和可见性,但显然更改精度或字符串长度有点棘手。根据我所做的研究,我想出了以下示例代码,它似乎应该可以工作 - 但我收到错误:

“无法将类型 'PX.Data.PXUIFieldAttribute' 的对象转换为类型 'PX.Data.PXDBDecimalAttribute'。

我不明白为什么会这样...

    protected virtual void xTACOpenSourceDetail_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
    {
        var osd = (PXCache)sender;

        foreach (PXDBDecimalAttribute attribute in this.Caches<xTACOpenSourceDetail>().GetAttributes("Number1"))
        {

            PXDBDecimalAttribute someAttribute = attribute as PXDBDecimalAttribute;
            if (someAttribute != null)
            {
                someAttribute.DBProperties._precision = 4;
            }
        }

    }

我刚刚在销售订单屏幕中尝试了以下代码,它似乎有效!

        var props = typeof(SOOrder).GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PXDecimalAttribute)));
        foreach (System.Reflection.PropertyInfo item in props)
        {
            PXDecimalAttribute.SetPrecision(this.Base.Caches[typeof(SOOrder)], item.Name, 1);
        }

您可能需要更改它以匹配您的 DAC。