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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Helper;
using Gestor.Model.Resources;
using Gestor.Model.Validation;
using Newtonsoft.Json;
namespace Gestor.Model.Domain.Seguros;
public class Aeronautico : DomainBase, IDomain
{
private string _fabricante;
private string _modelo;
private string _serie;
private string _prefixo;
private string _marinaAero;
private string _certificado;
private string _casco;
private string _navegacao;
private string _observacao;
public Item Item { get; set; }
public TipoAeronautico Tipo { get; set; }
public string Fabricante
{
get
{
return _fabricante?.ToUpper();
}
set
{
_fabricante = value;
}
}
public string Modelo
{
get
{
return _modelo?.ToUpper();
}
set
{
_modelo = value;
}
}
public string Serie
{
get
{
return _serie?.ToUpper();
}
set
{
_serie = value;
}
}
public string Prefixo
{
get
{
return _prefixo?.ToUpper();
}
set
{
_prefixo = value;
}
}
public int? Fabricacao { get; set; }
public int? Tripulantes { get; set; }
public int? Passageiros { get; set; }
public string MarinaAero
{
get
{
return _marinaAero?.ToUpper();
}
set
{
_marinaAero = value;
}
}
public long? Peso { get; set; }
public string Certificado
{
get
{
return _certificado?.ToUpper();
}
set
{
_certificado = value;
}
}
public DateTime? Vistoria { get; set; }
public string Casco
{
get
{
return _casco?.ToUpper();
}
set
{
_casco = value;
}
}
public string Navegacao
{
get
{
return _navegacao?.ToUpper();
}
set
{
_navegacao = value;
}
}
public string Observacao
{
get
{
return _observacao?.ToUpper();
}
set
{
_observacao = value;
}
}
[JsonIgnore]
public Func<List<KeyValuePair<string, string>>> ValidationEvent => Validate;
public List<KeyValuePair<string, string>> Validate()
{
List<KeyValuePair<string, string>> list = ValidationHelper.AddValue();
if (string.IsNullOrWhiteSpace(Fabricante))
{
list.AddValue("Fabricante", Messages.Obrigatorio);
}
else if (Fabricante != null && Fabricante.Length > 60)
{
list.AddValue("Fabricante", string.Format(Messages.MaiorQueLimite, 60));
}
if (Tipo == (TipoAeronautico)0)
{
list.AddValue("Tipo", Messages.Obrigatorio);
}
if (string.IsNullOrWhiteSpace(Modelo))
{
list.AddValue("Modelo", Messages.Obrigatorio);
}
else if (Modelo.Length > 60)
{
list.AddValue("Modelo", string.Format(Messages.MaiorQueLimite, 60));
}
if (Vistoria.HasValue && (DateTime.Compare(Vistoria.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(Vistoria.Value, new DateTime(9999, 12, 31)) > 0))
{
list.AddValue("Vistoria", string.Format(Messages.DataInvalida));
}
if (string.IsNullOrWhiteSpace(Serie))
{
list.AddValue("Serie", Messages.Obrigatorio);
}
else if (Serie.Length > 30)
{
list.AddValue("Serie", string.Format(Messages.MaiorQueLimite, 30));
}
if (string.IsNullOrWhiteSpace(Prefixo))
{
list.AddValue("Prefixo", Messages.Obrigatorio);
}
else if (Prefixo.Length > 30)
{
list.AddValue("Prefixo", string.Format(Messages.MaiorQueLimite, 30));
}
if (!Fabricacao.HasValue)
{
list.AddValue("Fabricacao", Messages.Obrigatorio);
}
else if (!Fabricacao.Value.ToString().ValidacaoFabricacao())
{
list.AddValue("Fabricacao", Messages.Invalido);
}
if (!Tripulantes.HasValue)
{
list.AddValue("Tripulantes", Messages.Obrigatorio);
}
if (!Passageiros.HasValue)
{
list.AddValue("Passageiros", Messages.Obrigatorio);
}
if (string.IsNullOrWhiteSpace(MarinaAero))
{
list.AddValue("MarinaAero", Messages.Obrigatorio);
}
else if (MarinaAero.Length > 60)
{
list.AddValue("MarinaAero", string.Format(Messages.MaiorQueLimite, 60));
}
if (!string.IsNullOrWhiteSpace(Certificado) && Certificado.Length > 60)
{
list.AddValue("Certificado", string.Format(Messages.MaiorQueLimite, 60));
}
if (string.IsNullOrWhiteSpace(Casco) && Tipo.Categoria() == "Aero")
{
list.AddValue("Casco", Messages.Obrigatorio);
}
else if (Tipo.Categoria() != "Aero" && Casco != null && Casco.Length > 60)
{
list.AddValue("Casco", string.Format(Messages.MaiorQueLimite, 60));
}
if (!string.IsNullOrWhiteSpace(Navegacao) && Tipo.Categoria() != "Aero" && Navegacao.Length > 60)
{
list.AddValue("Navegacao", string.Format(Messages.MaiorQueLimite, 60));
}
if (!Vistoria.HasValue && Tipo.Categoria() == "Aero")
{
list.AddValue("Vistoria", Messages.Obrigatorio);
}
if (!Peso.HasValue && Tipo.Categoria() == "Aero")
{
list.AddValue("Peso", Messages.Obrigatorio);
}
return list;
}
public static List<TupleList> Log(Item item)
{
List<TupleList> list = new List<TupleList>
{
new TupleList
{
Tuples = new ObservableCollection<Tuple<string, string, string>>
{
new Tuple<string, string, string>("TIPO DE AERONAVE", item.Aeronautico.Tipo.GetDescription(), ""),
new Tuple<string, string, string>("FABRICANTE", string.IsNullOrWhiteSpace(item.Aeronautico.Fabricante) ? "" : item.Aeronautico.Fabricante.ToUpper(), ""),
new Tuple<string, string, string>("MODELO", string.IsNullOrWhiteSpace(item.Aeronautico.Modelo) ? "" : item.Aeronautico.Modelo.ToUpper(), ""),
new Tuple<string, string, string>("REGISTRO", string.IsNullOrWhiteSpace(item.Aeronautico.Serie) ? "" : item.Aeronautico.Serie.ToUpper(), ""),
new Tuple<string, string, string>("PREFIXO", string.IsNullOrWhiteSpace(item.Aeronautico.Prefixo) ? "" : item.Aeronautico.Prefixo.ToUpper(), ""),
new Tuple<string, string, string>("ANO DE FABRICAÇÃO", (!item.Aeronautico.Fabricacao.HasValue) ? "" : item.Aeronautico.Fabricacao?.ToString(), ""),
new Tuple<string, string, string>("TRIPULANTES", (!item.Aeronautico.Tripulantes.HasValue) ? "" : item.Aeronautico.Tripulantes?.ToString(), ""),
new Tuple<string, string, string>("PASSAGEIROS", (!item.Aeronautico.Passageiros.HasValue) ? "" : item.Aeronautico.Passageiros?.ToString(), ""),
new Tuple<string, string, string>("AERÓDROMO", string.IsNullOrWhiteSpace(item.Aeronautico.MarinaAero) ? "" : item.Aeronautico.MarinaAero.ToUpper(), ""),
new Tuple<string, string, string>("PESO", (!item.Aeronautico.Peso.HasValue) ? "" : item.Aeronautico.Peso?.ToString(), ""),
new Tuple<string, string, string>("NAVEGAÇÃO", string.IsNullOrWhiteSpace(item.Aeronautico.Navegacao) ? "" : item.Aeronautico.Navegacao.ToUpper(), ""),
new Tuple<string, string, string>("CERTIFICADO", string.IsNullOrWhiteSpace(item.Aeronautico.Certificado) ? "" : item.Aeronautico.Certificado.ToUpper(), ""),
new Tuple<string, string, string>("MATERIAL DO CASCO", string.IsNullOrWhiteSpace(item.Aeronautico.Casco) ? "" : item.Aeronautico.Casco.ToUpper(), ""),
new Tuple<string, string, string>("VALIDADE DA VISTORIA", (!item.Aeronautico.Vistoria.HasValue) ? "" : item.Aeronautico.Vistoria?.ToShortDateString(), ""),
new Tuple<string, string, string>("OBSERVAÇÃO", string.IsNullOrWhiteSpace(item.Aeronautico.Observacao) ? "" : item.Aeronautico.Observacao.ToUpper(), "")
}
}
};
ObservableCollection<Tuple<string, string, string>> observableCollection = new ObservableCollection<Tuple<string, string, string>>
{
new Tuple<string, string, string>("COBERTURAS$", "", "")
};
foreach (Cobertura cobertura in item.Coberturas)
{
observableCollection.Add(new Tuple<string, string, string>($" COBERTURA {item.Coberturas.IndexOf(cobertura) + 1}$", "", ""));
observableCollection.Add(new Tuple<string, string, string>(" OBSERVAÇÃO", string.IsNullOrWhiteSpace(cobertura.Observacao) ? "" : cobertura.Observacao.ToUpper(), ""));
observableCollection.Add(new Tuple<string, string, string>(" PRÊMIO", cobertura.Premio.ToString("C", new CultureInfo("pt-BR", useUserOverride: false)), ""));
observableCollection.Add(new Tuple<string, string, string>(" FRANQUIA", cobertura.Franquia.ToString("C", new CultureInfo("pt-BR", useUserOverride: false)), ""));
observableCollection.Add(new Tuple<string, string, string>(" L.M.I.", cobertura.Lmi.ToString("C", new CultureInfo("pt-BR", useUserOverride: false)), ""));
}
list.Add(new TupleList
{
Tuples = observableCollection
});
return list;
}
}
|