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
use crate::com::{SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;
/// ✅ IMPLÉMENTATION ENRICHIE - Version Phase 6
///
/// Wrapper pour unités de mesure (IBSCIALUnite3)
///
/// Les unités de mesure permettent de définir les unités de vente, d'achat
/// et de stock des articles :
/// - Pièce (PCE, U, etc.)
/// - Poids (kg, g, t, etc.)
/// - Longueur (m, cm, mm, etc.)
/// - Volume (L, mL, m³, etc.)
/// - Surface (m², etc.)
///
/// # Exemple
/// ```no_run
/// use objets_metier_rs::wrappers::cial::CialApplication;
///
/// let cial_app = CialApplication::new("Objets100c.CIAL")?;
/// let factory = cial_app.factory_unite()?;
///
/// let unite = factory.create()?;
/// unite.set_intitule("Kilogramme")?;
/// unite.set_abreviation("kg")?;
/// unite.set_coef_conversion(1.0)?;
/// unite.write()?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub struct Unite {
pub(crate) dispatch: IDispatch,
}
impl Unite {
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
// ═══════════════════════════════════════════════════════════════════════
// PROPRIÉTÉS DE BASE (2 propriétés)
// ═══════════════════════════════════════════════════════════════════════
/// Identifiant unique (cbMarq)
pub fn cbmarq(&self) -> SageResult<i32> {
self.dispatch().call_method_by_name("cbMarq", &[])?.to_i32()
}
/// Intitulé de l'unité
pub fn intitule(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("Intitule", &[])?
.to_string()
}
// ═══════════════════════════════════════════════════════════════════════
// PROPRIÉTÉS DE CONFIGURATION (5 propriétés)
// ═══════════════════════════════════════════════════════════════════════
/// Abréviation de l'unité (ex: "kg", "m", "L")
pub fn abreviation(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("Abreviation", &[])?
.to_string()
}
/// Coefficient de conversion (par rapport à l'unité de base)
pub fn coef_conversion(&self) -> SageResult<f64> {
self.dispatch()
.call_method_by_name("CoefConversion", &[])?
.to_f64()
}
/// Unité de base (pour conversions)
pub fn unite_base(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("UniteBase", &[])?
.to_string()
}
/// Nombre de décimales pour affichage
pub fn nb_decimales(&self) -> SageResult<i16> {
self.dispatch()
.call_method_by_name("NbDecimales", &[])?
.to_short()
}
/// Type d'unité (0=Standard, 1=Poids, 2=Volume, 3=Longueur, 4=Surface)
pub fn type_unite(&self) -> SageResult<i16> {
self.dispatch()
.call_method_by_name("TypeUnite", &[])?
.to_short()
}
// ═══════════════════════════════════════════════════════════════════════
// SETTERS (6 setters)
// ═══════════════════════════════════════════════════════════════════════
/// Modifie l'intitulé de l'unité
pub fn set_intitule(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("Intitule", &[param])?;
Ok(())
}
/// Modifie l'abréviation
pub fn set_abreviation(&self, abrev: &str) -> SageResult<()> {
let param = SafeVariant::from_string(abrev);
self.dispatch().call_property_put("Abreviation", &[param])?;
Ok(())
}
/// Modifie le coefficient de conversion
pub fn set_coef_conversion(&self, coef: f64) -> SageResult<()> {
let param = SafeVariant::from_f64(coef);
self.dispatch()
.call_property_put("CoefConversion", &[param])?;
Ok(())
}
/// Modifie l'unité de base
pub fn set_unite_base(&self, unite: &str) -> SageResult<()> {
let param = SafeVariant::from_string(unite);
self.dispatch().call_property_put("UniteBase", &[param])?;
Ok(())
}
/// Modifie le nombre de décimales
pub fn set_nb_decimales(&self, nb: i16) -> SageResult<()> {
let param = SafeVariant::from_i16(nb);
self.dispatch().call_property_put("NbDecimales", &[param])?;
Ok(())
}
/// Modifie le type d'unité
pub fn set_type_unite(&self, type_u: i16) -> SageResult<()> {
let param = SafeVariant::from_i16(type_u);
self.dispatch().call_property_put("TypeUnite", &[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(())
}
}