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.Globalization; using System.Runtime.CompilerServices; namespace Gestor.Model.Domain.Ferramentas { public class Recibo : DomainBase, IDomain { [Description("DATA DO RECIBO")] [Log(true)] public DateTime? DataRecibo { get; set; } [Description("DOCUMENTO PAGANTE")] [Log(true)] public string DocumentoPagante { get; set; } [Description("DOCUMENTO RECEBEDOR")] [Log(true)] public string DocumentoRecebedor { get; set; } [Log(true)] public TipoPagamento? Pagamento { get; set; } [Log(true)] public string Pagante { get; set; } [Log(true)] public string Recebedor { get; set; } [Log(true)] public string Referente { get; set; } [Log(true)] public TipoRecibo? Tipo { get; set; } [JsonIgnore] public Func>> ValidationEvent { get { Recibo recibo = this; return new Func>>(recibo.Validate); } } [Log(true)] public decimal Valor { get; set; } public Recibo() { } public List Log() { string description; string shortDateString; List tupleLists = new List(); TupleList tupleList = new TupleList(); ObservableCollection> observableCollection = new ObservableCollection>() { new Tuple("PAGANTE", (string.IsNullOrWhiteSpace(this.Pagante) ? "" : this.Pagante), ""), new Tuple("DOCUMENTO PAGANTE", (string.IsNullOrWhiteSpace(this.DocumentoPagante) ? "" : this.DocumentoPagante), ""), new Tuple("RECEBEDOR", (string.IsNullOrWhiteSpace(this.Recebedor) ? "" : this.Recebedor), ""), new Tuple("DOCUMENTO", (string.IsNullOrWhiteSpace(this.DocumentoRecebedor) ? "" : this.DocumentoRecebedor), ""), new Tuple("TIPO DO RECIBO", this.Tipo.GetDescription(), "") }; TipoPagamento? pagamento = this.Pagamento; if (!pagamento.HasValue) { description = ""; } else { pagamento = this.Pagamento; if (pagamento.HasValue) { description = pagamento.GetValueOrDefault().GetDescription(); } else { description = null; } } observableCollection.Add(new Tuple("PAGAMENTO", description, "")); decimal valor = this.Valor; observableCollection.Add(new Tuple("VALOR", valor.ToString(new CultureInfo("pt-BR")), "")); DateTime? dataRecibo = this.DataRecibo; if (dataRecibo.HasValue) { shortDateString = dataRecibo.GetValueOrDefault().ToShortDateString(); } else { shortDateString = null; } observableCollection.Add(new Tuple("DATA DO RECIBO", shortDateString, "")); observableCollection.Add(new Tuple("PAGANTE", (string.IsNullOrWhiteSpace(this.Pagante) ? "" : this.Pagante), "")); observableCollection.Add(new Tuple("RECEBEDOR", (string.IsNullOrWhiteSpace(this.Recebedor) ? "" : this.Recebedor), "")); observableCollection.Add(new Tuple("REFERENTE", (string.IsNullOrWhiteSpace(this.Referente) ? "" : this.Referente), "")); tupleList.Tuples = observableCollection; tupleLists.Add(tupleList); return tupleLists; } public List> Validate() { List> keyValuePairs = ValidationHelper.AddValue(); if (string.IsNullOrWhiteSpace(this.Referente)) { keyValuePairs.AddValue("Referente|REFERENTE À(AO)", Messages.Obrigatorio, true); } if (this.DataRecibo.HasValue && (DateTime.Compare(this.DataRecibo.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(this.DataRecibo.Value, new DateTime(9999, 12, 31)) > 0)) { keyValuePairs.AddValue("DataRecibo|DATA DO RECIBO", Messages.Obrigatorio, true); } if (!this.DataRecibo.HasValue) { keyValuePairs.AddValue("DataRecibo|DATA DO RECIBO", Messages.Obrigatorio, true); } if (string.IsNullOrWhiteSpace(this.DocumentoPagante)) { keyValuePairs.AddValue("DocumentoPagante|DOCUMENTO DO PAGANTE", Messages.Obrigatorio, true); } else if (!this.DocumentoPagante.ValidacaoDocumento()) { keyValuePairs.AddValue("DocumentoPagante|DOCUMENTO DO PAGANTE", Messages.Invalido, true); } if (string.IsNullOrWhiteSpace(this.DocumentoRecebedor)) { keyValuePairs.AddValue("DocumentoRecebedor|DOCUMENTO DO RECEBEDOR", Messages.Obrigatorio, true); } else if (!this.DocumentoRecebedor.ValidacaoDocumento()) { keyValuePairs.AddValue("DocumentoRecebedor|DOCUMENTO DO RECEBEDOR", Messages.Invalido, true); } if (string.IsNullOrWhiteSpace(this.Recebedor)) { keyValuePairs.AddValue("Recebedor", Messages.Obrigatorio, true); } if (string.IsNullOrWhiteSpace(this.Pagante)) { keyValuePairs.AddValue("Pagante", Messages.Obrigatorio, true); } if (!this.Pagamento.HasValue) { keyValuePairs.AddValue("Pagamento|FORMA DE PAGAMENTO", Messages.Obrigatorio, true); } if (!string.IsNullOrWhiteSpace(this.Referente) && this.Referente.Length >= 255) { keyValuePairs.AddValue("Referente|REFERENTE À(AO)", string.Format(Messages.MaiorQueLimite, 255), true); } return keyValuePairs; } } }