Event handling 字段值的开关语句

Event handling 字段值的开关语句,event-handling,switch-statement,acumatica,Event Handling,Switch Statement,Acumatica,我正在尝试设置一个自定义项,该自定义项将使用switch语句在一系列字段中动态显示值 如果我们关注一个领域,我有一个字符串列表 public static class SMSPlans { public const string A = "A"; public const string B = "B"; public const string C = "C"; public const string Z = "Z"; } [PXDBString(2, IsUnicode = true)

我正在尝试设置一个自定义项,该自定义项将使用switch语句在一系列字段中动态显示值

如果我们关注一个领域,我有一个字符串列表

public static class SMSPlans
{
 public const string A = "A";
 public const string B = "B";
 public const string C = "C";
 public const string Z = "Z";
}

[PXDBString(2, IsUnicode = true)]
[PXDefault(SMSPlans.Z)]
[PXUIField(DisplayName = "SMS Plan Selected")]
[PXStringList(
 new string[]
 {
 SMSPlans.A,
 SMSPlans.B,
 SMSPlans.C,
 SMSPlans.Z
 },
 new string[]
 {
 "Plan A",
 "Plan B",
 "Plan C",
 "No Text Plan"
 })]
我想在将此字段设置为任何一个允许值时,使用下图所示的相应固定值填充一系列字段(0是默认值,如果选择了任何计划,当前将显示)

我计划使用公式函数和switch语句来设置我想要的值

[PXFormula(null,typeof(Switch<Case<Where<Current<UsrMPSMSPlanSelected, Equal<SMSPlans.A>>,0>))]

[PXFormula(null,typeof)(Switch)我可以告诉您一些处理方法

1) 使用PXFormula属性标记-在上面的示例中,您的开关定义基本上是正确的,但根据您的位置,PXFormula定义本身是不正确的。我要做的是将PXFormula标记放在需要更新的字段上

例如,如果字段为UsrMinText,请使用以下命令:

[PXFormula(typeof(Switch<Case<Where<UsrMPSMSPlanSelected,Equal<SMSPlans.A>>,{value if true},{value if false or more case statements}))]
在任何一种方法中,将存储在数据库中的值都是在PXFormula的{True}/{False}值中指定的值或在实际开关方法中指定的值

需要记住的一点是,DAC中的字段顺序很重要。我已经通读了培训信息和帮助指南,以了解更多有关这方面的信息

protected void Batch_ManualStatus_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
    Batch batch = (Batch)e.Row;
    if (batch != null && e.NewValue != null)
    {
        switch ((string)e.NewValue)
        {
        case "H":
            batch.Hold = true;
            batch.Released = false;
            batch.Posted = false;
            break;
        case "B":
            batch.Hold = false;
            batch.Released = false;
            batch.Posted = false;
            break;
        case "U":
            batch.Hold = false;
            batch.Released = true;
            batch.Posted = false;
            break;
        case "P":
            batch.Hold = false;
            batch.Released = true;
            batch.Posted = true;
            break;
        }
   }
}