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
|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Gestor.Model.Attributes;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using Gestor.Model.Helper;
using Gestor.Model.Resources;
using Gestor.Model.Validation;
using Newtonsoft.Json;
namespace Gestor.Model.Domain.Financeiro;
public class Fornecedor : EnderecoBase, IDomain
{
private string _nome;
private string _documento;
private string _email;
private string _observacao;
public new long Id { get; set; }
public long IdEmpresa { get; set; }
public long? IdConta { get; set; }
public long? IdCentro { get; set; }
public long? IdPlano { get; set; }
public TipoPagamento? TipoPagamento { get; set; }
[Log(true)]
[Name(true)]
public string Nome
{
get
{
return _nome?.ToUpper();
}
set
{
_nome = value;
NomeSocial = $"{value?.ToUpper()} - {Id}";
}
}
[Log(true)]
[Description("NOME SOCIAL")]
public string NomeSocial { get; set; }
[Log(true)]
public string Documento
{
get
{
return _documento?.ToUpper().Trim();
}
set
{
_documento = value;
}
}
[Log(true)]
[Description("TIPO TELEFONE")]
public TipoTelefone? TipoTelefone1 { get; set; }
[Log(true)]
[Description("PREFIXO 1")]
public string Prefixo1 { get; set; }
[Log(true)]
[Description("TELEFONE 1")]
public string Telefone1 { get; set; }
[Log(true)]
[Description("TIPO TELEFONE 2")]
public TipoTelefone? TipoTelefone2 { get; set; }
[Log(true)]
[Description("PREFIXO 2")]
public string Prefixo2 { get; set; }
[Log(true)]
[Description("TELEFONE 2")]
public string Telefone2 { get; set; }
[Log(true)]
[Description("E-MAIL")]
public string Email
{
get
{
return _email?.ToLower();
}
set
{
_email = value;
}
}
[Log(true)]
[Description("OBSERVAÇÃO")]
public string Observacao
{
get
{
return _observacao?.ToUpper();
}
set
{
_observacao = value;
}
}
[Log(true)]
[Description("ATIVO")]
public bool Ativo { get; set; }
[JsonIgnore]
public Func<List<KeyValuePair<string, string>>> ValidationEvent => Validate;
public List<KeyValuePair<string, string>> Validate()
{
List<KeyValuePair<string, string>> list = ValidationHelper.AddValue();
int? num = Nome?.Trim().Split(new char[1] { ' ' }).Length;
if (!num.HasValue)
{
list.AddValue("Nome", Messages.Obrigatorio);
}
else if (num <= 1)
{
list.AddValue("Nome", Messages.NomeInvalido);
}
if (!string.IsNullOrWhiteSpace(Nome) && Nome.Length > 60)
{
list.AddValue("Nome", string.Format(Messages.MaiorQueLimite, 60));
}
if (!string.IsNullOrWhiteSpace(Documento) && !Documento.ValidacaoDocumento())
{
list.AddValue("Documento", Messages.Invalido);
}
if (!string.IsNullOrWhiteSpace(Prefixo1) && !Prefixo1.ValidacaoPrefixo())
{
list.AddValue("Prefixo1", Messages.Obrigatorio);
}
if (!string.IsNullOrWhiteSpace(Telefone1) && !Telefone1.ValidacaoTelefone())
{
list.AddValue("Telefone1", Messages.Obrigatorio);
}
if (!string.IsNullOrWhiteSpace(Email) && !Email.ValidacaoEmail())
{
list.AddValue("Email", Messages.Obrigatorio);
}
if (!string.IsNullOrWhiteSpace(base.Cidade) && base.Cidade.Length > 30)
{
list.AddValue("Cidade", string.Format(Messages.MaiorQueLimite, 30));
}
if (!string.IsNullOrWhiteSpace(base.Bairro) && base.Bairro.Length > 60)
{
list.AddValue("Bairro", string.Format(Messages.MaiorQueLimite, 60));
}
if (!string.IsNullOrWhiteSpace(base.Complemento) && base.Complemento.Length > 40)
{
list.AddValue("Complemento", string.Format(Messages.MaiorQueLimite, 40));
}
return list;
}
public List<TupleList> Log()
{
List<TupleList> list = new List<TupleList>();
TupleList tupleList = new TupleList();
ObservableCollection<Tuple<string, string, string>> obj = new ObservableCollection<Tuple<string, string, string>>
{
new Tuple<string, string, string>("NOME DO FORNECEDOR", string.IsNullOrWhiteSpace(Nome) ? "" : Nome, ""),
new Tuple<string, string, string>("DOCUMENTO", string.IsNullOrWhiteSpace(Documento) ? "" : Documento, ""),
new Tuple<string, string, string>("CEP", string.IsNullOrWhiteSpace(base.Cep) ? "" : base.Cep, ""),
new Tuple<string, string, string>("ENDEREÇO", string.IsNullOrWhiteSpace(base.Endereco) ? "" : base.Endereco, ""),
new Tuple<string, string, string>("NÚMERO", string.IsNullOrWhiteSpace(base.Numero) ? "" : base.Numero, ""),
new Tuple<string, string, string>("COMPLEMENTO", string.IsNullOrWhiteSpace(base.Complemento) ? "" : base.Complemento, ""),
new Tuple<string, string, string>("BAIRRO", string.IsNullOrWhiteSpace(base.Bairro) ? "" : base.Bairro, ""),
new Tuple<string, string, string>("CIDADE", string.IsNullOrWhiteSpace(base.Cidade) ? "" : base.Cidade, ""),
new Tuple<string, string, string>("ESTADO", string.IsNullOrWhiteSpace(base.Estado) ? "" : base.Estado, "")
};
object item;
if (TipoTelefone1.HasValue)
{
TipoTelefone? tipoTelefone = TipoTelefone1;
item = (tipoTelefone.HasValue ? tipoTelefone.GetValueOrDefault().GetDescription() : null);
}
else
{
item = "";
}
obj.Add(new Tuple<string, string, string>("TIPO DO PRIMEIRO TELEFONE", (string)item, ""));
obj.Add(new Tuple<string, string, string>("PRIMEIRO PREFIXO", string.IsNullOrWhiteSpace(Prefixo1) ? "" : Prefixo1, ""));
obj.Add(new Tuple<string, string, string>("PRIMEIRO TELEFONE", string.IsNullOrWhiteSpace(Telefone1) ? "" : Telefone1, ""));
object item2;
if (TipoTelefone2.HasValue)
{
TipoTelefone? tipoTelefone = TipoTelefone2;
item2 = (tipoTelefone.HasValue ? tipoTelefone.GetValueOrDefault().GetDescription() : null);
}
else
{
item2 = "";
}
obj.Add(new Tuple<string, string, string>("TIPO DO SEGUNDO TELEFONE", (string)item2, ""));
obj.Add(new Tuple<string, string, string>("SEGUNDO PREFIXO", string.IsNullOrWhiteSpace(Prefixo2) ? "" : Prefixo2, ""));
obj.Add(new Tuple<string, string, string>("SEGUNDO TELEFONE", string.IsNullOrWhiteSpace(Telefone2) ? "" : Telefone2, ""));
obj.Add(new Tuple<string, string, string>("E-MAIL", string.IsNullOrWhiteSpace(Email) ? "" : Email, ""));
obj.Add(new Tuple<string, string, string>("PLANO DE CONTAS", (!IdPlano.HasValue) ? "" : IdPlano?.ToString(), ""));
obj.Add(new Tuple<string, string, string>("CENTRO DE CUSTO", (!IdCentro.HasValue) ? "" : IdCentro?.ToString(), ""));
obj.Add(new Tuple<string, string, string>("CONTA CORRENTE", (!IdConta.HasValue) ? "" : IdConta?.ToString(), ""));
object item3;
if (TipoPagamento.HasValue)
{
TipoPagamento? tipoPagamento = TipoPagamento;
item3 = (tipoPagamento.HasValue ? tipoPagamento.GetValueOrDefault().GetDescription() : null);
}
else
{
item3 = "";
}
obj.Add(new Tuple<string, string, string>("TIPO DE PAGAMENTO", (string)item3, ""));
obj.Add(new Tuple<string, string, string>("OBSERVAÇÕES", string.IsNullOrWhiteSpace(Observacao) ? "" : Observacao, ""));
tupleList.Tuples = obj;
list.Add(tupleList);
return list;
}
}
|