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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
use crate::com::{SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;
/// ✅ IMPLÉMENTATION ENRICHIE - Version Phase 6
///
/// Wrapper pour gammes de produits (IBSCIALGamme3)
///
/// Les gammes permettent de décliner un article selon différentes caractéristiques
/// (couleurs, tailles, finitions, etc.). Chaque gamme contient des énumérés qui
/// représentent les valeurs possibles.
///
/// # Exemple
/// ```no_run
/// use objets_metier_rs::wrappers::cial::CialApplication;
///
/// let cial_app = CialApplication::new("Objets100c.CIAL")?;
/// let factory = cial_app.factory_gamme()?;
///
/// let gamme = factory.create()?;
/// gamme.set_intitule("Couleurs")?;
/// gamme.set_type_gamme(1)?; // Gamme enumérée
/// gamme.set_longueur_enumere(20)?;
/// gamme.set_n_numero(1)?;
/// gamme.write()?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub struct Gamme {
pub(crate) dispatch: IDispatch,
}
impl Gamme {
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
// ═══════════════════════════════════════════════════════════════════════
// PROPRIÉTÉS DE BASE (3 propriétés)
// ═══════════════════════════════════════════════════════════════════════
/// Identifiant unique (cbMarq)
pub fn cbmarq(&self) -> SageResult<i32> {
self.dispatch().call_method_by_name("cbMarq", &[])?.to_i32()
}
/// Intitulé de la gamme
pub fn intitule(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("Intitule", &[])?
.to_string()
}
/// Numéro de la gamme (1 ou 2)
pub fn n_numero(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("nNumero", &[])?
.to_i32()
}
// ═══════════════════════════════════════════════════════════════════════
// PROPRIÉTÉS DE CONFIGURATION (5 propriétés)
// ═══════════════════════════════════════════════════════════════════════
/// Type de gamme (0=Champ libre, 1=Enuméré)
pub fn type_gamme(&self) -> SageResult<i16> {
self.dispatch()
.call_method_by_name("TypeGamme", &[])?
.to_short()
}
/// Longueur de l'énuméré (si type enuméré)
pub fn longueur_enumere(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("LongueurEnumere", &[])?
.to_i32()
}
/// Nombre d'énumérés dans la gamme
pub fn nb_enumeres(&self) -> SageResult<i32> {
let enums = self.gamme_enumeres()?;
let dispatch = enums.to_dispatch()?;
let safe_dispatch = SafeDispatch::new(&dispatch);
safe_dispatch.call_method_by_name("Count", &[])?.to_i32()
}
/// Actif (gamme utilisable)
pub fn actif(&self) -> SageResult<bool> {
self.dispatch().call_method_by_name("Actif", &[])?.to_bool()
}
/// Obligatoire (gamme requise pour l'article)
pub fn obligatoire(&self) -> SageResult<bool> {
self.dispatch()
.call_method_by_name("Obligatoire", &[])?
.to_bool()
}
// ═══════════════════════════════════════════════════════════════════════
// COLLECTIONS (1 collection)
// ═══════════════════════════════════════════════════════════════════════
/// Collection des énumérés de la gamme
pub fn gamme_enumeres(&self) -> SageResult<SafeVariant> {
self.dispatch().call_method_by_name("GammeEnumeres", &[])
}
// ═══════════════════════════════════════════════════════════════════════
// SETTERS (7 setters)
// ═══════════════════════════════════════════════════════════════════════
/// Modifie l'intitulé de la gamme
pub fn set_intitule(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("Intitule", &[param])?;
Ok(())
}
/// Modifie le numéro de la gamme (1 ou 2)
pub fn set_n_numero(&self, value: i32) -> SageResult<()> {
let param = SafeVariant::I4(value);
self.dispatch().call_property_put("nNumero", &[param])?;
Ok(())
}
/// Modifie le type de gamme (0=Champ libre, 1=Enuméré)
pub fn set_type_gamme(&self, type_gamme: i16) -> SageResult<()> {
let param = SafeVariant::from_i16(type_gamme);
self.dispatch().call_property_put("TypeGamme", &[param])?;
Ok(())
}
/// Modifie la longueur de l'énuméré
pub fn set_longueur_enumere(&self, longueur: i32) -> SageResult<()> {
let param = SafeVariant::I4(longueur);
self.dispatch()
.call_property_put("LongueurEnumere", &[param])?;
Ok(())
}
/// Active/désactive la gamme
pub fn set_actif(&self, actif: bool) -> SageResult<()> {
let param = SafeVariant::from_bool(actif);
self.dispatch().call_property_put("Actif", &[param])?;
Ok(())
}
/// Rend la gamme obligatoire ou optionnelle
pub fn set_obligatoire(&self, obligatoire: bool) -> SageResult<()> {
let param = SafeVariant::from_bool(obligatoire);
self.dispatch().call_property_put("Obligatoire", &[param])?;
Ok(())
}
// ═══════════════════════════════════════════════════════════════════════
// MÉTHODES STANDARD (3 méthodes)
// ═══════════════════════════════════════════════════════════════════════
/// Enregistre les modifications
pub fn write(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Write", &[])?;
Ok(())
}
/// Enregistre avec valeurs par défaut
pub fn write_default(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("WriteDefault", &[])?;
Ok(())
}
/// Supprime l'objet
pub fn remove(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Remove", &[])?;
Ok(())
}
}