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