Bonjour à toutes et tous.
J'essaie de mettre en place dans mon application un des post de thomas
Je rencontre quelques petits soucis, j'espère que thomas passera jetter un petit coup d'oeil:
Voilà l'architecture de mon projet :
Une solution nommée ProjetCreative avec :
3 projets :
_ 1 nommé BL qui contient mais classe métier et où j'ai mis ma règle de validation ci dessus.
_ 1 nommé DAL qui contient toutes mes classes d'accès aux données
_ 1 nommé GUI pour l'interface graphique
1/ Code de Thomas Lebrun :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <Canvas.BindingGroup> <BindingGroup Name="CustomerValidationBindingGroup"> <BindingGroup.ValidationRules> <local:StringIsEmptyValidationRule ErrorMessage="Le champ ne peut pas être vide !" /> </BindingGroup.ValidationRules> </BindingGroup> </Canvas.BindingGroup>
Ma question est de savoir si StringIsEmptyValidationRule est bien une classe heritant de ValidationRule ?
Moi j'ai fais une classe RegleValidationClient heritant de ValidationRule comme suit :
Cette classe est située dans dans la couche BL.
Code C# : 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 namespace BLCreative { public class RegleValidationClient:ValidationRule { #region Properties public string ErrorMessage { get; set; } #endregion #region ValidationRule public override ValidationResult Validate(object value, CultureInfo cultureInfo) { var result = new ValidationResult(true, null); BindingGroup bindingGroup = (BindingGroup)value; Client client = (Client)bindingGroup.Items[0]; var raisonSociale = Convert.ToString(bindingGroup.GetValue(client, "RaisonSocialeClient")); var nom = Convert.ToString(bindingGroup.GetValue(client, "NomClient")); var prenom = Convert.ToString(bindingGroup.GetValue(client, "PrenomClient")); if (string.IsNullOrEmpty(raisonSociale) || string.IsNullOrEmpty(nom) || string.IsNullOrEmpty(prenom)) { result = new ValidationResult(false, this.ErrorMessage); } return result; } #endregion } }
Client est ma classe métier permettant de créer mon objet client, voici le code :
Code C# : 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 namespace BLCreative { public class Client { private decimal _idClient; public decimal IdClient { get { return _idClient; } set { _idClient = value; } } private string _nomClient; public string NomClient { get { return _nomClient; } set { _nomClient = value; if (String.IsNullOrEmpty(value)) { throw new ApplicationException("Champs obligatoire."); } } } private string _prenomClient; public string PrenomClient { get { return _prenomClient; } set { _prenomClient = value; if (String.IsNullOrEmpty(value)) { throw new ApplicationException("Champs obligatoire."); } } } private string _raisonSocialeClient; public string RaisonSocialeClient { get { return _raisonSocialeClient; } set { _raisonSocialeClient = value; if (String.IsNullOrEmpty(value)) { throw new ApplicationException("Champs obligatoire."); } } } private string _adresseClient; public string AdresseClient { get { return _adresseClient; } set { _adresseClient = value; } } private string _cpClient; public string CpClient { get { return _cpClient; } set { _cpClient = value; } } private string _villeClient; public string VilleClient { get { return _villeClient; } set { _villeClient = value; } } private string _telFixeClient; public string TelFixeClient { get { return _telFixeClient; } set { _telFixeClient = value; } } private string _telPortableClient; public string TelPortableClient { get { return _telPortableClient; } set { _telPortableClient = value; } } private string _faxClient; public string FaxClient { get { return _faxClient; } set { _faxClient = value; } } private string _emailClient; public string EmailClient { get { return _emailClient; } set { _emailClient = value; } } //Constructeur de la classe métier CLIENT public Client() { } public Client(decimal idClient,string nom, string prenom) { IdClient = idClient; NomClient = nom; PrenomClient = prenom; } public Client(string nomClient, string prenomClient, string raisonSocialeClient, string adresseClient, string cpClient, string villeClient, string telFixeClient, string telPortableClient, string faxClient, string emailclient) { NomClient = nomClient; PrenomClient = prenomClient; RaisonSocialeClient = raisonSocialeClient; AdresseClient = adresseClient; CpClient = cpClient; VilleClient = villeClient; TelFixeClient = telFixeClient; TelPortableClient = telPortableClient; FaxClient = faxClient; EmailClient = emailclient; } //Override de toString() public override string ToString() { return string.Format("{0} {1}", NomClient, PrenomClient); } } }
Volia le code XAML pour la creation de mon BindingGroup situé dans ma couche GUI :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 <Canvas.BindingGroup> <BindingGroup Name="FicheClientBindingGroup"> <BindingGroup.ValidationRules> <local:RegleValidationClient ErrorMessage="Ce champs ne doit pas être vide" /> </BindingGroup.ValidationRules> </BindingGroup> </Canvas.BindingGroup>
Cela vous semble t'il correct ?
La où ça pèche c'est que je ne sais pas comment faire pour appeler la validation de ses données en cliquant sur mon bouton suivant :
Ce bouton verifie les données entrées si pas d'erreurs je passe à l'étape suivante la saisie de l'adresse du client sinon j'affiche les erreurs de saisies.
En vous remerciant par avance et espérant que quelqu'un puisse m'aider pour avancer.
Si vous avez besoin d'autres info n'hesitez pas.
Bonne soirée, Thomas D.
Partager