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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
use crate::com::{FromDispatch, FromDispatchNew, SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;
/// Wrapper pour l'objet Depot de Sage 100c (IBODepot)
///
/// Représente un dépôt de stockage avec ses propriétés et informations.
/// Un dépôt est un lieu physique ou logique où sont stockés les articles.
///
/// # Exemples
///
/// ```no_run
/// # use objets_metier_rs::wrappers::cial::CialApplication;
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let cial = CialApplication::new("Objets100c.CIAL")?;
/// # cial.set_name("D:\\Sage\\BIJOU.MAE")?;
/// # cial.open()?;
/// let factory_depot = cial.factory_depot()?;
/// let depot = factory_depot.read_intitule("Principal")?;
/// println!("Dépôt : {}", depot.de_intitule()?);
/// println!("Code : {}", depot.de_code()?);
/// # Ok(())
/// # }
/// ```
pub struct Depot {
pub(crate) dispatch: IDispatch,
}
impl Depot {
/// Crée un SafeDispatch temporaire pour les appels
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
// ==================== IDENTIFICATION ====================
/// Obtient l'intitulé du dépôt
///
/// # Exemples
///
/// ```no_run
/// # use objets_metier_rs::wrappers::cial::objects::Depot;
/// # fn example(depot: &Depot) -> Result<(), Box<dyn std::error::Error>> {
/// let intitule = depot.de_intitule()?;
/// println!("Intitulé : {}", intitule);
/// # Ok(())
/// # }
/// ```
pub fn de_intitule(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Intitule", &[])?
.to_string()
}
/// Définit l'intitulé du dépôt
pub fn set_de_intitule(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Intitule", &[param])?;
Ok(())
}
/// Obtient le code du dépôt
pub fn de_code(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Code", &[])?
.to_string()
}
/// Définit le code du dépôt
pub fn set_de_code(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Code", &[param])?;
Ok(())
}
/// Obtient le compteur interne du dépôt
pub fn de_no(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("DE_No", &[])?
.to_i32()
}
// ==================== ADRESSE ====================
/// Obtient l'adresse du dépôt
pub fn de_adresse(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Adresse", &[])?
.to_string()
}
/// Définit l'adresse du dépôt
pub fn set_de_adresse(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Adresse", &[param])?;
Ok(())
}
/// Obtient le complément d'adresse du dépôt
pub fn de_complement(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Complement", &[])?
.to_string()
}
/// Définit le complément d'adresse du dépôt
pub fn set_de_complement(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Complement", &[param])?;
Ok(())
}
/// Obtient le code postal du dépôt
pub fn de_code_postal(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_CodePostal", &[])?
.to_string()
}
/// Définit le code postal du dépôt
pub fn set_de_code_postal(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_CodePostal", &[param])?;
Ok(())
}
/// Obtient la ville du dépôt
pub fn de_ville(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Ville", &[])?
.to_string()
}
/// Définit la ville du dépôt
pub fn set_de_ville(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Ville", &[param])?;
Ok(())
}
/// Obtient le pays du dépôt
pub fn de_pays(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Pays", &[])?
.to_string()
}
/// Définit le pays du dépôt
pub fn set_de_pays(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Pays", &[param])?;
Ok(())
}
// ==================== CONTACT ====================
/// Obtient le contact du dépôt
pub fn de_contact(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Contact", &[])?
.to_string()
}
/// Définit le contact du dépôt
pub fn set_de_contact(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Contact", &[param])?;
Ok(())
}
/// Obtient le téléphone du dépôt
pub fn de_telephone(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Telephone", &[])?
.to_string()
}
/// Définit le téléphone du dépôt
pub fn set_de_telephone(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Telephone", &[param])?;
Ok(())
}
// ==================== OPTIONS ====================
/// Obtient le type de dépôt (0=Normal, 1=Principal, etc.)
pub fn de_type(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("DE_Type", &[])?
.to_i32()
}
/// Définit le type de dépôt
pub fn set_de_type(&self, value: i32) -> SageResult<()> {
let param = SafeVariant::from_i32(value);
self.dispatch().call_property_put("DE_Type", &[param])?;
Ok(())
}
// ==================== MÉTHODES D'ÉCRITURE ====================
/// Enregistre les modifications du dépôt dans la base de données
///
/// # Exemples
///
/// ```no_run
/// # use objets_metier_rs::wrappers::cial::objects::Depot;
/// # fn example(depot: &Depot) -> Result<(), Box<dyn std::error::Error>> {
/// depot.set_de_intitule("Dépôt Sud")?;
/// depot.set_de_ville("Lyon")?;
/// depot.write()?;
/// # Ok(())
/// # }
/// ```
pub fn write(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Write", &[])?;
Ok(())
}
/// Supprime le dépôt de la base de données
///
/// ⚠️ Attention : Cette opération est irréversible
pub fn remove(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Remove", &[])?;
Ok(())
}
}
impl FromDispatch for Depot {
fn from_dispatch(dispatch: IDispatch) -> SageResult<Self> {
Ok(Depot { dispatch })
}
}
impl FromDispatchNew for Depot {
fn from_dispatch_new(dispatch: IDispatch) -> SageResult<Self> {
Ok(Depot { dispatch })
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_depot_structure() {
// Test de documentation vérifiant que la structure compile
// Ne s'exécute pas réellement car nécessite une connexion Sage
}
}