Ricerca…


introduzione

In questo argomento imparerai come modificare gli attributi del campo ereditati dagli attributi PXStringList o PXIntList. L'approccio dimostrato farà in modo di non interrompere la funzionalità del prodotto base Acumatica ERP e richiederebbe una minima manutenzione, se esistente, durante l'aggiornamento delle personalizzazioni a una versione più recente di Acumatica.

Osservazioni

In tutti gli esempi precedenti, sono state apportate modifiche agli array _AllowedValues e _AllowedLabels . Se l'attività consiste nel modificare solo l'etichetta (valore esterno) di un elemento a discesa, prendere in considerazione l'uso dei dizionari di traduzione. Per ulteriori informazioni sui dizionari di traduzione, consultare la documentazione di ERP Acumatica

Modifica degli stati matrimoniali

In questo esempio si modificherà l'elenco a discesa Stato civile trovato nel modulo Contatti (CR302000): inserisci la descrizione dell'immagine qui

Per aggiungere nuovi elementi al successore PXStringListAttribute

Il modo migliore per estendere gli elementi a discesa codificati all'interno di un attributo ereditato dall'attributo PXStringList o PXIntList consiste nell'aumentare le dimensioni degli array _AllowedValues e _AllowedLabels nel costruttore dell'attributo del campo personalizzato:

[PXLocalizable(Messages.Prefix)]
public static class MaritalStatusesMessages
{
    public const string CommonLaw = "Living common law";
    public const string Separated = "Separated (not living common law)";
    public const string DivorcedNoCommonLaw = "Divorced (not living common law)";
    public const string NeverMarried = "Never Married";
}

public class MaritalStatusesCst1Attribute : MaritalStatusesAttribute
{
    public const string CommonLaw = "L";
    public const string Separated = "P";
    public const string NeverMarried = "N";

    public MaritalStatusesCst1Attribute()
    {
        Array.Resize(ref _AllowedValues, _AllowedValues.Length + 3);
        _AllowedValues[_AllowedValues.Length - 3] = CommonLaw;
        _AllowedValues[_AllowedValues.Length - 2] = Separated;
        _AllowedValues[_AllowedValues.Length - 1] = NeverMarried;
        Array.Resize(ref _AllowedLabels, _AllowedLabels.Length + 3);
        _AllowedLabels[_AllowedLabels.Length - 3] = MaritalStatusesMessages.CommonLaw;
        _AllowedLabels[_AllowedLabels.Length - 2] = MaritalStatusesMessages.Separated;
        _AllowedLabels[_AllowedLabels.Length - 1] = MaritalStatusesMessages.NeverMarried;
    }
}

Nell'esempio sopra riportato, hai aumentato le dimensioni degli array _AllowedValues e _AllowedLabels per aggiungere 3 elementi aggiuntivi all'elenco a discesa Stato _AllowedLabels . I valori interni, memorizzati nell'array _AllowedValues , verranno assegnati ai campi DAC e salvati nel database, mentre i valori esterni dall'array _AllowedValues rappresentano valori interni nell'interfaccia utente.

Per verificare i risultati, nell'estensione Contact DAC, decora il campo MaritalStatus con MaritalStatusesCst1Attribute :

public class ContactExt : PXCacheExtension<Contact>
{
    [PXRemoveBaseAttribute(typeof(MaritalStatusesAttribute))]
    [PXMergeAttributes(Method = MergeMethod.Append)]
    [MaritalStatusesCst1]
    public string MaritalStatus { get; set; }
}

Ora ci sono 7 voci nell'elenco a discesa Stato civile:

inserisci la descrizione dell'immagine qui

Per rimuovere elementi dichiarati nel successore PXStringListAttribute

Per rimuovere un elemento a discesa specifico, che era codificato in un attributo ereditato dall'attributo PXStringList o PXIntList, è necessario ridurre la dimensione degli array _AllowedValues e _AllowedLabels nel costruttore dell'attributo del campo personalizzato:

public class MaritalStatusesCst2Attribute : MaritalStatusesCst1Attribute
{
    public MaritalStatusesCst2Attribute()
    {
        string[] allowedValues = new string[_AllowedValues.Length - 1];
        string[] allowedLabels = new string[_AllowedLabels.Length - 1];
        Array.Copy(_AllowedValues, 1, allowedValues, 0, _AllowedValues.Length - 1);
        Array.Copy(_AllowedLabels, 1, allowedLabels, 0, _AllowedValues.Length - 1);
        _AllowedValues = allowedValues;
        _AllowedLabels = allowedLabels;
    }
}

Nell'esempio sopra riportato, hai ridotto le dimensioni degli array _AllowedValues e _AllowedLabels per rimuovere un singolo elemento dall'elenco a discesa Stato _AllowedLabels .

Per verificare i risultati, nell'estensione Contact DAC, decorare il campo MaritalStatus con MaritalStatusesCst2Attribute :

public class ContactExt : PXCacheExtension<Contact>
{
    [PXRemoveBaseAttribute(typeof(MaritalStatusesAttribute))]
    [PXMergeAttributes(Method = MergeMethod.Append)]
    [MaritalStatusesCst2]
    public string MaritalStatus { get; set; }
}

Ora ci sono solo 6 elementi: 3 originali e 3 personalizzati - nell'elenco a discesa Stato civile:

inserisci la descrizione dell'immagine qui

Per sostituire elementi dichiarati nel successore PXStringListAttribute

Per sostituire un elemento a discesa specifico, originariamente codificato all'interno di un attributo ereditato dall'attributo PXStringList o PXIntList, è necessario aggiornare il valore appropriato negli array _AllowedValues e _AllowedLabels nel costruttore dell'attributo del campo personalizzato:

public class MaritalStatusesCst3Attribute : MaritalStatusesCst2Attribute
{
    public const string DivorcedNoCommonLaw = "V";

    public MaritalStatusesCst3Attribute()
    {
        _AllowedValues[Array.IndexOf(_AllowedValues, Divorced)] = DivorcedNoCommonLaw;
        _AllowedLabels[Array.IndexOf(_AllowedLabels, Messages.Divorced)] = MaritalStatusesMessages.DivorcedNoCommonLaw;
    }
}

Nell'esempio sopra, hai sostituito D - Divorziato con V - Divorziato (non in vigore common law) rispettivamente _AllowedLabels array _AllowedValues e _AllowedLabels . In questo modo, sostituiamo sia i valori interni che quelli esterni di un elemento a discesa.

Per verificare i risultati, nell'estensione Contact DAC, decorare il campo MaritalStatus con MaritalStatusesCst3Attribute :

public class ContactExt : PXCacheExtension<Contact>
{
    [PXRemoveBaseAttribute(typeof(MaritalStatusesAttribute))]
    [PXMergeAttributes(Method = MergeMethod.Append)]
    [MaritalStatusesCst3]
    public string MaritalStatus { get; set; }
}

Ora ci sono solo 6 elementi: 2 originali, 3 personalizzati e 1 sostituito - nell'elenco a discesa Stato civile:

inserisci la descrizione dell'immagine qui



Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow