comparison Chronosv2/source/Modules/Sample/ViewModels/EmpresaViewModel.cs @ 10:443821e55f06

Initial cleaned up add from Codeplex files
author stevenh7776 stevenhollidge@hotmail.com
date Tue, 21 Feb 2012 17:25:44 +0700
parents
children 09d18d6e5f40
comparison
equal deleted inserted replaced
9:904a9faadf8b 10:443821e55f06
1 /*
2 The MIT License
3
4 Copyright (c) 2009-2010. Carlos Guzmán Álvarez. http://chronoswpf.codeplex.com/
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24
25 using System.ComponentModel;
26 using Chronos.Modules.Navigation;
27 using Chronos.Modules.Sample.Models;
28 using Chronos.Presentation.Core.Windows;
29 using Chronos.Presentation.ViewModel;
30 using Chronos.Presentation.Core.Navigation;
31 using nRoute.Components;
32 using System.Collections.ObjectModel;
33
34 namespace Chronos.Modules.Sample.ViewModels
35 {
36 public sealed class EmpresaViewModel
37 : WorkspaceViewModel<EmpresaEntity>
38 {
39 #region · PropertyChangedEventArgs Cached Instances ·
40
41 private static readonly PropertyChangedEventArgs IdEmpresaChangedArgs = CreateArgs<EmpresaViewModel>(x => x.IdEmpresa);
42 private static readonly PropertyChangedEventArgs CifChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Cif);
43 private static readonly PropertyChangedEventArgs IdEpigrafeIaeChangedArgs = CreateArgs<EmpresaViewModel>(x => x.IdEpigrafeIae);
44 private static readonly PropertyChangedEventArgs IdCnaeChangedArgs = CreateArgs<EmpresaViewModel>(x => x.IdCnae);
45 private static readonly PropertyChangedEventArgs NombreChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Nombre);
46 private static readonly PropertyChangedEventArgs NombreComercialChangedArgs = CreateArgs<EmpresaViewModel>(x => x.NombreComercial);
47 private static readonly PropertyChangedEventArgs IdTipoViaChangedArgs = CreateArgs<EmpresaViewModel>(x => x.IdTipoVia);
48 private static readonly PropertyChangedEventArgs DireccionChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Direccion);
49 private static readonly PropertyChangedEventArgs NumeroBloqueChangedArgs = CreateArgs<EmpresaViewModel>(x => x.NumeroBloque);
50 private static readonly PropertyChangedEventArgs PisoChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Piso);
51 private static readonly PropertyChangedEventArgs PuertaChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Puerta);
52 private static readonly PropertyChangedEventArgs CodigoPostalChangedArgs = CreateArgs<EmpresaViewModel>(x => x.CodigoPostal);
53 private static readonly PropertyChangedEventArgs CiudadChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Ciudad);
54 private static readonly PropertyChangedEventArgs ProvinciaChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Provincia);
55 private static readonly PropertyChangedEventArgs PaisChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Pais);
56 private static readonly PropertyChangedEventArgs Telefono1ChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Telefono1);
57 private static readonly PropertyChangedEventArgs Telefono2ChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Telefono2);
58 private static readonly PropertyChangedEventArgs Fax1ChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Fax1);
59 private static readonly PropertyChangedEventArgs Fax2ChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Fax2);
60 private static readonly PropertyChangedEventArgs WwwChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Www);
61 private static readonly PropertyChangedEventArgs EmailChangedArgs = CreateArgs<EmpresaViewModel>(x => x.Email);
62
63 #endregion
64
65 #region · Model Data ·
66
67 public string IdEmpresa
68 {
69 get { return this.Entity.IdEmpresa; }
70 set
71 {
72 if (this.Entity.IdEmpresa != value)
73 {
74 this.Entity.IdEmpresa = value;
75 this.NotifyPropertyChanged(IdEmpresaChangedArgs);
76 }
77 }
78 }
79
80 public string Cif
81 {
82 get { return this.Entity.Cif; }
83 set
84 {
85 if (this.Entity.Cif != value)
86 {
87 this.Entity.Cif = value;
88 this.NotifyPropertyChanged(CifChangedArgs);
89 }
90 }
91 }
92
93 public string IdEpigrafeIae
94 {
95 get { return this.Entity.IdEpigrafeIae; }
96 set
97 {
98 if (this.Entity.IdEpigrafeIae != value)
99 {
100 this.Entity.IdEpigrafeIae = value;
101 this.NotifyPropertyChanged(IdEpigrafeIaeChangedArgs);
102 }
103 }
104 }
105
106 public string IdCnae
107 {
108 get { return this.Entity.IdCnae; }
109 set
110 {
111 if (this.Entity.IdCnae != value)
112 {
113 this.Entity.IdCnae = value;
114 this.NotifyPropertyChanged(IdCnaeChangedArgs);
115 }
116 }
117 }
118
119 public string Nombre
120 {
121 get { return this.Entity.Nombre; }
122 set
123 {
124 if (this.Entity.Nombre != value)
125 {
126 this.Entity.Nombre = value;
127 this.NotifyPropertyChanged(NombreChangedArgs);
128 }
129 }
130 }
131
132 public string NombreComercial
133 {
134 get { return this.Entity.NombreComercial; }
135 set
136 {
137 if (this.Entity.NombreComercial != value)
138 {
139 this.Entity.NombreComercial = value;
140 this.NotifyPropertyChanged(NombreComercialChangedArgs);
141 }
142 }
143 }
144
145 public string IdTipoVia
146 {
147 get { return this.Entity.IdTipoVia; }
148 set
149 {
150 if (this.Entity.IdTipoVia != value)
151 {
152 this.Entity.IdTipoVia = value;
153 this.NotifyPropertyChanged(IdTipoViaChangedArgs);
154 }
155 }
156 }
157
158 public string Direccion
159 {
160 get { return this.Entity.Direccion; }
161 set
162 {
163 if (this.Entity.Direccion != value)
164 {
165 this.Entity.Direccion = value;
166 this.NotifyPropertyChanged(DireccionChangedArgs);
167 }
168 }
169 }
170
171 public string NumeroBloque
172 {
173 get { return this.Entity.NumeroBloque; }
174 set
175 {
176 if (this.Entity.NumeroBloque != value)
177 {
178 this.Entity.NumeroBloque = value;
179 this.NotifyPropertyChanged(NumeroBloqueChangedArgs);
180 }
181 }
182 }
183
184 public string Piso
185 {
186 get { return this.Entity.Piso; }
187 set
188 {
189 if (this.Entity.Piso != value)
190 {
191 this.Entity.Piso = value;
192 this.NotifyPropertyChanged(PisoChangedArgs);
193 }
194 }
195 }
196
197 public string Puerta
198 {
199 get { return this.Entity.Puerta; }
200 set
201 {
202 if (this.Entity.Puerta != value)
203 {
204 this.Entity.Puerta = value;
205 this.NotifyPropertyChanged(PuertaChangedArgs);
206 }
207 }
208 }
209
210 public string CodigoPostal
211 {
212 get { return this.Entity.CodigoPostal; }
213 set
214 {
215 if (this.Entity.CodigoPostal != value)
216 {
217 this.Entity.CodigoPostal = value;
218 this.NotifyPropertyChanged(CodigoPostalChangedArgs);
219 }
220 }
221 }
222
223 public string Ciudad
224 {
225 get { return this.Entity.Ciudad; }
226 set
227 {
228 if (this.Entity.Ciudad != value)
229 {
230 this.Entity.Ciudad = value;
231 this.NotifyPropertyChanged(CiudadChangedArgs);
232 }
233 }
234 }
235
236 public string Provincia
237 {
238 get { return this.Entity.Provincia; }
239 set
240 {
241 if (this.Entity.Provincia != value)
242 {
243 this.Entity.Provincia = value;
244 this.NotifyPropertyChanged(ProvinciaChangedArgs);
245 }
246 }
247 }
248
249 public string Pais
250 {
251 get { return this.Entity.Pais; }
252 set
253 {
254 if (this.Entity.Pais != value)
255 {
256 this.Entity.Pais = value;
257 this.NotifyPropertyChanged(PaisChangedArgs);
258 }
259 }
260 }
261
262 public string Telefono1
263 {
264 get { return this.Entity.Telefono1; }
265 set
266 {
267 if (this.Entity.Telefono1 != value)
268 {
269 this.Entity.Telefono1 = value;
270 this.NotifyPropertyChanged(Telefono1ChangedArgs);
271 }
272 }
273 }
274
275 public string Telefono2
276 {
277 get { return this.Entity.Telefono2; }
278 set
279 {
280 if (this.Entity.Telefono2 != value)
281 {
282 this.Entity.Telefono2 = value;
283 this.NotifyPropertyChanged(Telefono2ChangedArgs);
284 }
285 }
286 }
287
288 public string Fax1
289 {
290 get { return this.Entity.Fax1; }
291 set
292 {
293 if (this.Entity.Fax1 != value)
294 {
295 this.Entity.Fax1 = value;
296 this.NotifyPropertyChanged(Fax1ChangedArgs);
297 }
298 }
299 }
300
301 public string Fax2
302 {
303 get { return this.Entity.Fax2; }
304 set
305 {
306 if (this.Entity.Fax2 != value)
307 {
308 this.Entity.Fax2 = value;
309 this.NotifyPropertyChanged(Fax2ChangedArgs);
310 }
311 }
312 }
313
314 public string Www
315 {
316 get { return this.Entity.Www; }
317 set
318 {
319 if (this.Entity.Www != value)
320 {
321 this.Entity.Www = value;
322 this.NotifyPropertyChanged(WwwChangedArgs);
323 }
324 }
325 }
326
327 public string Email
328 {
329 get { return this.Entity.Email; }
330 set
331 {
332 if (this.Entity.Email != value)
333 {
334 this.Entity.Email = value;
335 this.NotifyPropertyChanged(EmailChangedArgs);
336 }
337 }
338 }
339
340 #endregion
341
342 #region · Properties ·
343
344 /// <summary>
345 /// Gets the navigation URL
346 /// </summary>
347 /// <value></value>
348 public override string NavigationRoute
349 {
350 get { return NavigationRoutes.Companies; }
351 }
352
353 #endregion
354
355 #region · Constructors ·
356
357 public EmpresaViewModel()
358 : base()
359 {
360 }
361
362 #endregion
363
364 #region · Overriden Methods ·
365
366 protected override void OnInitialize(nRoute.Components.ParametersCollection requestParameters)
367 {
368 if (requestParameters.ContainsKey(NavigationParams.NavigationParamsKey))
369 {
370 object[] rparams = requestParameters.GetValueOrDefault<object[]>(NavigationParams.NavigationParamsKey, null);
371
372 if (rparams != null && rparams[0] is int)
373 {
374 int value = (int)rparams[0];
375 }
376 }
377 }
378
379 protected override void InitializePropertyStates()
380 {
381 this.PropertyStates.Add(e => e.IdEmpresa);
382 this.PropertyStates.Add(e => e.Nombre);
383 this.PropertyStates.Add(e => e.Cif);
384 this.PropertyStates.Add(e => e.IdEpigrafeIae);
385 this.PropertyStates.Add(e => e.IdCnae);
386 this.PropertyStates.Add(e => e.NombreComercial);
387 this.PropertyStates.Add(e => e.IdTipoVia);
388 this.PropertyStates.Add(e => e.Direccion);
389 this.PropertyStates.Add(e => e.NumeroBloque);
390 this.PropertyStates.Add(e => e.Piso);
391 this.PropertyStates.Add(e => e.Puerta);
392 this.PropertyStates.Add(e => e.CodigoPostal);
393 this.PropertyStates.Add(e => e.Ciudad);
394 this.PropertyStates.Add(e => e.Provincia);
395 this.PropertyStates.Add(e => e.Pais);
396 this.PropertyStates.Add(e => e.Telefono1);
397 this.PropertyStates.Add(e => e.Telefono2);
398 this.PropertyStates.Add(e => e.Fax1);
399 this.PropertyStates.Add(e => e.Fax2);
400 this.PropertyStates.Add(e => e.Www);
401 this.PropertyStates.Add(e => e.Email);
402 }
403
404 protected override void OnViewModeChanged()
405 {
406 base.OnViewModeChanged();
407
408 if (this.PropertyStates.Count > 0)
409 {
410 bool editing = this.ViewMode == Chronos.Presentation.Core.Windows.ViewModeType.Add ||
411 this.ViewMode == Chronos.Presentation.Core.Windows.ViewModeType.Edit;
412
413 this.PropertyStates[x => x.IdEmpresa].IsEditable = this.ViewMode == ViewModeType.ViewOnly;
414 this.PropertyStates[x => x.Nombre].IsEditable = editing;
415 this.PropertyStates[x => x.Cif].IsEditable = editing;
416 this.PropertyStates[x => x.NombreComercial].IsEditable = editing;
417 this.PropertyStates[x => x.IdEpigrafeIae].IsEditable = editing;
418 this.PropertyStates[x => x.IdCnae].IsEditable = editing;
419 this.PropertyStates[x => x.NombreComercial].IsEditable = editing;
420 this.PropertyStates[x => x.IdTipoVia].IsEditable = editing;
421 this.PropertyStates[x => x.Direccion].IsEditable = editing;
422 this.PropertyStates[x => x.NumeroBloque].IsEditable = editing;
423 this.PropertyStates[x => x.Piso].IsEditable = editing;
424 this.PropertyStates[x => x.Puerta].IsEditable = editing;
425 this.PropertyStates[x => x.CodigoPostal].IsEditable = editing;
426 this.PropertyStates[x => x.Ciudad].IsEditable = editing;
427 this.PropertyStates[x => x.Provincia].IsEditable = editing;
428 this.PropertyStates[x => x.Pais].IsEditable = editing;
429 this.PropertyStates[x => x.Telefono1].IsEditable = editing;
430 this.PropertyStates[x => x.Telefono2].IsEditable = editing;
431 this.PropertyStates[x => x.Fax1].IsEditable = editing;
432 this.PropertyStates[x => x.Fax2].IsEditable = editing;
433 this.PropertyStates[x => x.Www].IsEditable = editing;
434 this.PropertyStates[x => x.Email].IsEditable = editing;
435 }
436 }
437
438 #endregion
439
440 #region · Command Actions ·
441
442 protected override void OnInquiryAction(InquiryActionResult<EmpresaEntity> result)
443 {
444 }
445
446 #endregion
447 }
448 }