Fonctions de sélection/déselection d'une colonne de type interrupteur
Ensemble de fonctions complémentaires pour faciliter la sélection/desélection d'une colonne de type interrupteur dans une champ table


Bonjour à tous

Dans une première contribution Nouvelles fonctions interrupteurs, je mettais à dispositions des fonctions complémentaires pour gérer la sélection/desélection des champs interrupteurs. Sur le même principe, j'ai développé des fonctions pour faciliter la sélection/deselection d'une colonne de type interrupteur.

TableSelectionne

Cette fonction permet de sélectionner plusieurs cases d'une colonnes de type interrupteur en passant les indices en paramètres

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
 
// Résumé : Active les options des lignes passées en paramètres
// Syntaxe :
//[ <Résultat> = ] TableSelectionne (<ps_champ> est chaîne, <pt_LstIndice> est tableau)
//
// Paramètres :
//	ps_champ (chaîne ANSI) : Nom de la colonne de type interrupteur
//	pt_LstIndice (tableau) : Liste des indices à sélectionner
// Valeur de retour :
// 	booléen : vrai si toutes les indices passé en paramètres ont été traité avec succès
//
// Exemple :
// TableSelectionne(Colonne3..nom,[1,5,8,20])
//
PROCEDURE TableSelectionne(ps_champ est un chaîne,pt_LstIndice est un tableau d'entiers)
 
//----->Declaration des variables
lb_retour est un booléen
ls_MessageErreur,ls_nomTable  est une chaîne
li_tableOccurrence est un entier
 
//----->Initialisation des variables
ls_MessageErreur="Vous avez appelé l'opérateur [] sur le champ %1."+RC+...
"L'indice spécifié [%2] est invalide. "+RC+...
"Les valeurs valides sont comprises entre 1 et %3 (inclus)."
 
//----->Initialisation des variables
lb_retour=Faux
 
SI ChampExiste(ps_champ) ALORS
	SI {ps_champ,indChamp}..Type = typInterr ALORS
 
		ls_nomTable={ps_champ,indChamp}..NomComplet
		ls_nomTable=ExtraitChaîne(ls_nomTable,2,".",DepuisDébut)
 
		SI {ls_nomTable,indChamp}..Type = typTable ALORS
			//----->Initialisation des variables
			li_tableOccurrence={ls_nomTable,indChamp}..Occurrence
 
			POUR li_i=1 _A_ pt_LstIndice..Occurrence
				SI pt_LstIndice[li_i] < li_tableOccurrence ALORS
					{ps_champ,indChamp}[pt_LstIndice[li_i]]=Vrai
				SINON
					ExceptionDéclenche(3,ChaîneConstruit(ls_MessageErreur,ps_champ,pt_LstIndice[li_i],li_tableOccurrence))
				FIN
			FIN
		SINON
			ExceptionDéclenche(2,"Le champ '"+ps_champ+"' n'est pas de type table ou colonne")
		FIN
 
		lb_retour=Vrai
	SINON SI {ps_champ,indChamp}..Type = typTable ALORS
 
		li_tableOccurrence={ps_champ,indChamp}..Occurrence
 
		POUR li_i=1 _A_ {ps_champ,indChamp}..NombreColonne
			SI {ps_champ,indChamp}[1,li_i]..Type = typInterr ALORS
				POUR li_j=1 _A_ pt_LstIndice..Occurrence
					SI pt_LstIndice[li_j] < li_tableOccurrence ALORS
						{ps_champ,indChamp}[pt_LstIndice[li_j],li_i]=Vrai
					SINON
						ExceptionDéclenche(3,ChaîneConstruit(ls_MessageErreur,ps_champ,pt_LstIndice[li_i],li_tableOccurrence))
					FIN
				FIN
				lb_retour=Vrai
				SORTIR
			FIN
		FIN
	SINON
		ExceptionDéclenche(2,"Le champ '"+ps_champ+"' n'est pas de type table ou colonne")
	FIN
SINON
	ExceptionDéclenche(1,"Le champ '"+ps_champ+"' n'existe pas")
FIN
 
RENVOYER lb_retour
TableSelectionneTout

Cette fonction permet de sélectionner toutes les cases d'une colonne de type interrupteur.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
// Résumé : Sélectionne toutes les cases d'une colonne interrupteur.
// Syntaxe :
//[ <Résultat> = ] TableSelectionneTout (<ps_champ> est chaîne)
//
// Paramètres :
//        ps_champ (chaîne ANSI) : Nom de la colonne ou nom de la table
// Valeur de retour :
//         booléen :  Vrai si toutes les lignes ont été sélectionnées
//
// Exemple :
// TableSelectionneTout(Col_activer..nom)
//
//        ps_nomColonne (chaîne ANSI - valeur par défaut="") : <indiquez ici le rôle de ps_nomColonne>
PROCEDURE TableSelectionneTout(ps_champ est un chaîne)
 
//----->Declaration des variables
lb_retour est un booléen
 
//----->Initialisation des variables
lb_retour=Faux
 
SI ChampExiste(ps_champ) ALORS
        SI {ps_champ,indChamp}..Type = typColonne ALORS
                POUR li_i=1 _A_ TableOccurrence(ps_champ)
                        {ps_champ,indChamp}[li_i]=1
                FIN        
                lb_retour=Vrai
        SINON SI {ps_champ,indChamp}..Type = typTable ALORS
                POUR li_i=1 _A_ {ps_champ,indChamp}..NombreColonne
                        SI {ps_champ,indChamp}[1,li_i]..Type = typInterr ALORS
                                POUR li_j=1  _A_ TableOccurrence(ps_champ)
                                        {ps_champ,indChamp}[li_j,li_i]=Vrai
                                FIN
                                lb_retour=Vrai
                                SORTIR
                        FIN
                FIN
        SINON
                ExceptionDéclenche(2,"Le champ '"+ps_champ+"' n'est pas de type table ou colonne")
        FIN
SINON
        ExceptionDéclenche(1,"Le champ '"+ps_champ+"' n'existe pas")
FIN
 
RENVOYER lb_retour
TableDeselectionne

Cette fonction permet de désélectionner plusieurs cases d'une colonne de type interrupteur en passant les indices en paramètres.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
 
 
// Résumé : Désélectionne les options des lignes passées en patamètres
// Syntaxe :
//[ <Résultat> = ] TableDeSelectionne (<ps_champ> est chaîne, <pt_LstIndice> est tableau)
//
// Paramètres :
//        ps_champ (chaîne ANSI) : niom de la colonne de type interrupteur
//        pt_LstIndice (tableau) : Liste des indices des lignes à désélectionner
// Valeur de retour :
//         booléen :  vrai si toutes les indices passé en paramètres ont été traité avec succès
//
// Exemple :
// Indiquez ici un exemple d'utilisation.
//
PROCEDURE TableDeSelectionne(ps_champ est un chaîne,pt_LstIndice est un tableau d'entiers)
 
//----->Declaration des variables
lb_retour est un booléen
ls_MessageErreur,ls_nomTable  est une chaîne
li_tableOccurrence est un entier
 
//----->Initialisation des variables
ls_MessageErreur="Vous avez appelé l'opérateur [] sur le champ %1."+RC+...
"L'indice spécifié [%2] est invalide. "+RC+...
"Les valeurs valides sont comprises entre 1 et %3 (inclus)."
 
//----->Initialisation des variables
lb_retour=Faux
 
SI ChampExiste(ps_champ) ALORS
        SI {ps_champ,indChamp}..Type = typInterr ALORS
 
                ls_nomTable={ps_champ,indChamp}..NomComplet
                ls_nomTable=ExtraitChaîne(ls_nomTable,2,".",DepuisDébut)
 
                SI {ls_nomTable,indChamp}..Type = typTable ALORS
                        //----->Initialisation des variables
                        li_tableOccurrence={ls_nomTable,indChamp}..Occurrence
 
                        POUR li_i=1 _A_ pt_LstIndice..Occurrence
                                SI pt_LstIndice[li_i] < li_tableOccurrence ALORS
                                        {ps_champ,indChamp}[pt_LstIndice[li_i]]=Faux
                                SINON
                                        ExceptionDéclenche(3,ChaîneConstruit(ls_MessageErreur,ps_champ,pt_LstIndice[li_i],li_tableOccurrence))
                                FIN
                        FIN
                SINON
                        ExceptionDéclenche(2,"Le champ '"+ps_champ+"' n'est pas de type table ou colonne")
                FIN
 
                lb_retour=Vrai
        SINON SI {ps_champ,indChamp}..Type = typTable ALORS
 
                li_tableOccurrence={ps_champ,indChamp}..Occurrence
 
                POUR li_i=1 _A_ {ps_champ,indChamp}..NombreColonne
                        SI {ps_champ,indChamp}[1,li_i]..Type = typInterr ALORS
                                POUR li_j=1 _A_ pt_LstIndice..Occurrence
                                        SI pt_LstIndice[li_j] < li_tableOccurrence ALORS
                                                {ps_champ,indChamp}[pt_LstIndice[li_j],li_i]=Faux
                                        SINON
                                                ExceptionDéclenche(3,ChaîneConstruit(ls_MessageErreur,ps_champ,pt_LstIndice[li_i],li_tableOccurrence))
                                        FIN
                                FIN
                                lb_retour=Vrai
                                SORTIR
                        FIN
                FIN
        SINON
                ExceptionDéclenche(2,"Le champ '"+ps_champ+"' n'est pas de type table ou colonne")
        FIN
SINON
        ExceptionDéclenche(1,"Le champ '"+ps_champ+"' n'existe pas")
FIN
 
RENVOYER lb_retour

TableDeselectionneTout

Cette fonction permet de désélectionner toutes les cases d'une colonne de type interrupteur.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
// Résumé : désélectionne toutes les options d'une colonne de type interrupteur
// Syntaxe :
//[ <Résultat> = ] TableDeselectionneTout (<ps_champ> est chaîne)
//
// Paramètres :
//        ps_champ (chaîne ANSI) : nom de la colonne ou nom de la table
// Valeur de retour :
//         booléen : vrai si toutes les options de la colonne interrupteur ont été désélectionnées
//
// Exemple :
// Indiquez ici un exemple d'utilisation.
// TableDeselectionneTout(Col_Export..nom)
//       
PROCEDURE TableDeselectionneTout(ps_champ est un chaîne)
 
//----->Declaration des variables
lb_retour est un booléen
 
//----->Initialisation des variables
lb_retour=Faux
 
SI ChampExiste(ps_champ) ALORS
        SI {ps_champ,indChamp}..Type = typColonne ALORS
                POUR li_i=1 _A_ TableOccurrence(ps_champ)
                        {ps_champ,indChamp}[li_i]=0
                FIN        
                lb_retour=Vrai
        SINON SI {ps_champ,indChamp}..Type = typTable ALORS
                POUR li_i=1 _A_ {ps_champ,indChamp}..NombreColonne
                        SI {ps_champ,indChamp}[1,li_i]..Type = typInterr ALORS
                                POUR li_j=1  _A_ TableOccurrence(ps_champ)
                                        {ps_champ,indChamp}[li_j,li_i]=0
                                FIN
                                lb_retour=Vrai
                                SORTIR
                        FIN
                FIN
        SINON
                ExceptionDéclenche(2,"Le champ '"+ps_champ+"' n'est pas de type table ou colonne")
        FIN
SINON
        ExceptionDéclenche(1,"Le champ '"+ps_champ+"' n'existe pas")
FIN
 
RENVOYER lb_retour
Vous trouver des exemples d'utilisations et des explications sur les exceptions : WinDev : fonctions de gestion des champs tables

N'hésitez pas à me faire part de vos retours pour améliorer, compléter la liste de ces fonctions.

Bon dev à tous