我必须根据配置屏幕中的字母设置在口罩中显示价格。
我正在尝试为DAC字段编写自定义属性,以便可以在报表中使用该属性。
我在下面给出了现有代码。函数调用工作正常,我正在使用它来获取价值,但是我无法将其用作DAC属性
#region PXPriceMaskAttribute
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.Class)]
public class PXPriceMaskAttribute : PXStringAttribute
{
#region Ctor
public PXPriceMaskAttribute()
: base()
{
}
#endregion
#region Implementation
/// <exclude/>
///
public static string GetPriceMask(PXGraph grp , decimal? val)
{
string _maskedstring = string.Empty;
decimal value = val ?? 0m;
int ivalue = Convert.ToInt32(Math.Floor(value));
if (ivalue > 0)
{
MemoSetUp setUp = PXSelect<MemoSetUp>.Select(grp);
char[] arr = ivalue.ToString().ToCharArray();
char prevvalue = ' ';
foreach (char cval in arr)
{
if (prevvalue != cval)
{
prevvalue = cval;
switch (cval)
{
case '1': _maskedstring += setUp.N1; break;
case '2': _maskedstring += setUp.N2; break;
case '3': _maskedstring += setUp.N3; break;
case '4': _maskedstring += setUp.N4; break;
case '5': _maskedstring += setUp.N5; break;
case '6': _maskedstring += setUp.N6; break;
case '7': _maskedstring += setUp.N7; break;
case '8': _maskedstring += setUp.N8; break;
case '9': _maskedstring += setUp.N9; break;
case '0': _maskedstring += setUp.N0; break;
default: break;
}
}
else
{
_maskedstring += setUp.Repeate;
}
}
}
return _maskedstring;
}
public static string GetPriceMask(MemoSetUp setUp, decimal? val)
{
string _maskedstring = string.Empty;
decimal value = val ?? 0m;
int ivalue = Convert.ToInt32(Math.Floor(value));
if (ivalue > 0)
{
char[] arr = ivalue.ToString().ToCharArray();
char prevvalue = ' ';
foreach (char cval in arr)
{
if (prevvalue != cval)
{
prevvalue = cval;
switch (cval)
{
case '1': _maskedstring += setUp.N1; break;
case '2': _maskedstring += setUp.N2; break;
case '3': _maskedstring += setUp.N3; break;
case '4': _maskedstring += setUp.N4; break;
case '5': _maskedstring += setUp.N5; break;
case '6': _maskedstring += setUp.N6; break;
case '7': _maskedstring += setUp.N7; break;
case '8': _maskedstring += setUp.N8; break;
case '9': _maskedstring += setUp.N9; break;
case '0': _maskedstring += setUp.N0; break;
default: break;
}
}
else
{
_maskedstring += setUp.Repeate;
}
}
}
return _maskedstring;
}
public override void FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
if (e.NewValue != null && !e.Cancel)
{
decimal? value = Convert.ToDecimal(e.NewValue);
e.NewValue = GetPriceMask(sender.Graph, value);
}
}
/// <exclude/>
public override void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
if (_AttributeLevel == PXAttributeLevel.Item || e.IsAltered)
{
e.ReturnState = PXStringState.CreateInstance(e.ReturnState, _Length, _IsUnicode, _FieldName, _IsKey, null, _InputMask, null, null, null, null);
}
}
/// <exclude/>
#endregion
}
#endregion
上面的代码不起作用。解决此问题的最佳方法是什么。
更新
我创建了一个BQL评估器并附加到DAC,它始终返回零。
public class PriceRounding<PriceField> : BqlFormulaEvaluator<PriceField>, IBqlOperand
where PriceField : IBqlField
{
public override object Evaluate(PXCache cache, object item,
Dictionary<Type, object> pars)
{
PXFieldState fState = cache.GetStateExt<PriceField>(item) as PXFieldState;
return GetSortOrderValueExt(Convert.ToDecimal(fState.Value));
}
public decimal GetSortOrderValueExt(decimal dVal)
{
dVal = Math.Round(dVal, 0);
decimal divider = (dVal <= 5000) ? 25m : (dVal <= 10000) ? 50m : (dVal <= 100000) ? 100m : 500m;
decimal reminder = dVal % divider;
if (reminder > 0)
{
decimal diff = divider - reminder;
dVal = dVal + diff;
}
return dVal;
}
}
DAC字段
#region RetailPrice
public abstract class retailPrice : PX.Data.IBqlField
{
}
protected decimal? _RetailPrice;
[PXDBDecimal(2)]
[PXUIField(DisplayName = "Retail Price")]
[PXFormula(typeof(PriceRounding<InfoInventoryItemAttributeExtNV.retailPrice>))]
public virtual decimal? RetailPrice
{
get
{
return this._RetailPrice;
}
set
{
this._RetailPrice = value;
}
}
#endregion
答案 0 :(得分:1)
考虑使用自定义BQL函数(源自BqlFormulaEvaluator
)–您可以引用PX.Objects
源代码的公式子文件夹中提供的现成的自定义BQL函数。或者,您可以参考KB article,其中使用了此类自定义BQL函数HierarchySorting
。
答案 1 :(得分:0)
与使用BQL公式评估程序相比,以下代码对我来说自定义四舍五入效果很好
.datepicker({...})
在DAC中使用
$(...).datepicker is not a function