diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs | 769 |
1 files changed, 769 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs new file mode 100644 index 0000000..e00947c --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs @@ -0,0 +1,769 @@ +using Gestor.Application.Helpers;
+using Gestor.Application.Servicos;
+using Gestor.Application.Servicos.Ferramentas;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Ferramentas;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Drawing;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.ViewModels.Ferramentas
+{
+ public class ReciboViewModel : BaseSegurosViewModel
+ {
+ private readonly ReciboServico _servico;
+
+ public Recibo CancelRecibo;
+
+ private Recibo _selectedRecibo = new Recibo();
+
+ private DateTime? _horaRecibo;
+
+ private ObservableCollection<Recibo> _recibosFiltrados = new ObservableCollection<Recibo>();
+
+ private bool _isExpanded;
+
+ private Cliente _pagante;
+
+ private Cliente _recebedor;
+
+ public DateTime? HoraRecibo
+ {
+ get
+ {
+ return this._horaRecibo;
+ }
+ set
+ {
+ DateTime? nullable;
+ this._horaRecibo = value;
+ if (!value.HasValue)
+ {
+ return;
+ }
+ Recibo selectedRecibo = this.SelectedRecibo;
+ DateTime? dataRecibo = this.SelectedRecibo.get_DataRecibo();
+ if (dataRecibo.HasValue)
+ {
+ dataRecibo = this.SelectedRecibo.get_DataRecibo();
+ nullable = new DateTime?(DateTime.Parse(string.Format("{0:d} {1:T}", dataRecibo.Value, value)));
+ }
+ else
+ {
+ dataRecibo = null;
+ nullable = dataRecibo;
+ }
+ selectedRecibo.set_DataRecibo(nullable);
+ base.OnPropertyChanged("HoraRecibo");
+ }
+ }
+
+ public bool IsExpanded
+ {
+ get
+ {
+ return this._isExpanded;
+ }
+ set
+ {
+ this._isExpanded = value;
+ base.OnPropertyChanged("IsExpanded");
+ }
+ }
+
+ public Cliente Pagante
+ {
+ get
+ {
+ return this._pagante;
+ }
+ set
+ {
+ this._pagante = value;
+ this.WorkOnSelectedPagante(value);
+ base.OnPropertyChanged("Pagante");
+ }
+ }
+
+ public Cliente Recebedor
+ {
+ get
+ {
+ return this._recebedor;
+ }
+ set
+ {
+ this._recebedor = value;
+ this.WorkOnSelectedRecebedor(value);
+ base.OnPropertyChanged("Recebedor");
+ }
+ }
+
+ public List<Recibo> Recibos
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Recibo> RecibosFiltrados
+ {
+ get
+ {
+ return this._recibosFiltrados;
+ }
+ set
+ {
+ this._recibosFiltrados = value;
+ this.IsExpanded = (value != null ? value.Count > 0 : false);
+ base.OnPropertyChanged("RecibosFiltrados");
+ }
+ }
+
+ public Recibo SelectedRecibo
+ {
+ get
+ {
+ return this._selectedRecibo;
+ }
+ set
+ {
+ long? nullable;
+ this._selectedRecibo = value;
+ this.WorkOnSelectedRecibo(value, true);
+ if (value != null)
+ {
+ nullable = new long?(value.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ base.VerificarEnables(nullable);
+ if (!value.get_DataRecibo().HasValue)
+ {
+ value.set_DataRecibo(new DateTime?(DateTime.Now));
+ }
+ if (value != null)
+ {
+ this.HoraRecibo = value.get_DataRecibo();
+ }
+ base.OnPropertyChanged("SelectedRecibo");
+ }
+ }
+
+ public ReciboViewModel()
+ {
+ this._servico = new ReciboServico();
+ base.EnableMenu = true;
+ this.Seleciona();
+ }
+
+ public void CancelarAlteracao()
+ {
+ if (this.CancelRecibo == null || !this.Recibos.Any<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Recibo, Recibo>(this.Recibos.First<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()), this.CancelRecibo);
+ if (this.RecibosFiltrados.Count <= 0 || !this.RecibosFiltrados.Any<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()))
+ {
+ this.RecibosFiltrados.Add(this.CancelRecibo);
+ }
+ else
+ {
+ DomainBase.Copy<Recibo, Recibo>(this.RecibosFiltrados.First<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()), this.CancelRecibo);
+ }
+ this.RecibosFiltrados = new ObservableCollection<Recibo>(this.RecibosFiltrados);
+ this.SelectedRecibo = this.RecibosFiltrados.First<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id());
+ }
+ base.Alterar(false);
+ }
+
+ public async void Excluir()
+ {
+ string description;
+ object obj;
+ if (this.SelectedRecibo != null && this.SelectedRecibo.get_Id() != 0)
+ {
+ if (await base.ShowMessage("DESEJA REALMENTE EXCLUIR O RECIBO PERMANENTEMENTE?", "SIM", "NÃO", false))
+ {
+ base.Loading(true);
+ if (await this._servico.Delete(this.SelectedRecibo))
+ {
+ ReciboViewModel reciboViewModel = this;
+ string str = string.Format("EXCLUIU RECIBO DE NÚMERO \"{0}\"", this.SelectedRecibo.get_Id());
+ long id = this.SelectedRecibo.get_Id();
+ TipoTela? nullable = new TipoTela?(42);
+ object[] valor = new object[9];
+ if (this.SelectedRecibo.get_Tipo().HasValue)
+ {
+ TipoRecibo? tipo = this.SelectedRecibo.get_Tipo();
+ description = ValidationHelper.GetDescription(tipo.Value);
+ if (description == null)
+ {
+ description = "";
+ }
+ }
+ else
+ {
+ description = "-";
+ }
+ valor[0] = description;
+ TipoPagamento? pagamento = this.SelectedRecibo.get_Pagamento();
+ if (pagamento.HasValue)
+ {
+ obj = ValidationHelper.GetDescription(pagamento.GetValueOrDefault());
+ }
+ else
+ {
+ obj = null;
+ }
+ valor[1] = obj;
+ valor[2] = this.SelectedRecibo.get_Valor();
+ valor[3] = this.SelectedRecibo.get_DataRecibo();
+ valor[4] = this.SelectedRecibo.get_Pagante();
+ valor[5] = this.SelectedRecibo.get_DocumentoPagante();
+ valor[6] = this.SelectedRecibo.get_Recebedor();
+ valor[7] = this.SelectedRecibo.get_DocumentoRecebedor();
+ valor[8] = this.SelectedRecibo.get_Referente();
+ reciboViewModel.RegistrarAcao(str, id, nullable, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", valor));
+ await this.SelecionaRecibo();
+ base.Loading(false);
+ base.ToggleSnackBar("RECIBO EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ internal async Task<List<Recibo>> Filtrar(string value)
+ {
+ List<Recibo> recibos = await Task.Run<List<Recibo>>(() => this.FiltrarRecibo(value));
+ return recibos;
+ }
+
+ public List<Recibo> FiltrarRecibo(string filter)
+ {
+ this.RecibosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Recibo>(this.Recibos) : new ObservableCollection<Recibo>(this.Recibos.Where<Recibo>((Recibo x) => {
+ if (ValidationHelper.RemoveDiacritics(x.get_Pagante().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)))
+ {
+ return true;
+ }
+ return ValidationHelper.RemoveDiacritics(x.get_Recebedor()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter));
+ })));
+ return this.RecibosFiltrados.ToList<Recibo>();
+ }
+
+ private static string GetImage(byte[] bytes, string extensao)
+ {
+ string str;
+ try
+ {
+ Image image = Image.FromStream(new MemoryStream(bytes));
+ string str1 = (extensao.ToUpper().Contains("JPG") ? string.Concat("data:image/jpeg;base64,", Convert.ToBase64String(bytes, Base64FormattingOptions.None)) : string.Concat("data:image/png;base64,", Convert.ToBase64String(bytes, Base64FormattingOptions.None)));
+ string[] strArrays = new string[] { "<img style=\"WIDTH=", null, null, null, null, null, null };
+ int width = image.Width;
+ strArrays[1] = width.ToString();
+ strArrays[2] = "; HEIGHT=";
+ width = image.Height;
+ strArrays[3] = width.ToString();
+ strArrays[4] = "; max-height: 250px; max-width: 250px; margin-bottom: 0px; margin-left: 100px; margin-top: 0px;\" src=\"";
+ strArrays[5] = str1;
+ strArrays[6] = "\"/>";
+ str = string.Concat(strArrays);
+ }
+ catch (Exception exception)
+ {
+ str = "";
+ }
+ return str;
+ }
+
+ public void Incluir()
+ {
+ this.SelectedRecibo = new Recibo();
+ base.Alterar(true);
+ }
+
+ private bool IsImage(string extensao)
+ {
+ if (extensao == null)
+ {
+ return false;
+ }
+ if (extensao.ToLower().Contains("jpg"))
+ {
+ return true;
+ }
+ if (extensao.ToLower().Contains("jpeg"))
+ {
+ return true;
+ }
+ if (extensao.ToLower().Contains("png"))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public async void Print()
+ {
+ bool referente;
+ byte[] arquivo;
+ string str;
+ string str1;
+ string str2;
+ string upper;
+ string str3;
+ string str4;
+ string upper1;
+ string description;
+ object obj;
+ string extensao;
+ string extensao1;
+ long? nullable;
+ string bd;
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital;
+ string image;
+ string str5;
+ Recibo selectedRecibo = this.SelectedRecibo;
+ if (selectedRecibo != null)
+ {
+ referente = selectedRecibo.get_Referente();
+ }
+ else
+ {
+ referente = false;
+ }
+ if (referente && this.SelectedRecibo.get_Recebedor() != null)
+ {
+ arquivoDigital = null;
+ List<IndiceArquivoDigital> indiceArquivoDigitals = await this.ArquivoDigitalServico.BuscarPorTipo(13, Recursos.Empresa.get_Id());
+ if (indiceArquivoDigitals != null)
+ {
+ List<IndiceArquivoDigital> indiceArquivoDigitals1 = indiceArquivoDigitals;
+ if (indiceArquivoDigitals1.Any<IndiceArquivoDigital>((IndiceArquivoDigital x) => x.get_Descricao() == "LOGO"))
+ {
+ List<IndiceArquivoDigital> indiceArquivoDigitals2 = indiceArquivoDigitals;
+ IndiceArquivoDigital indiceArquivoDigital = indiceArquivoDigitals2.FirstOrDefault<IndiceArquivoDigital>((IndiceArquivoDigital x) => x.get_Descricao() == "LOGO");
+ if (indiceArquivoDigital != null)
+ {
+ nullable = new long?(indiceArquivoDigital.get_IdArquivoDigital());
+ }
+ else
+ {
+ nullable = null;
+ }
+ long? nullable1 = nullable;
+ List<IndiceArquivoDigital> indiceArquivoDigitals3 = indiceArquivoDigitals;
+ IndiceArquivoDigital indiceArquivoDigital1 = indiceArquivoDigitals3.FirstOrDefault<IndiceArquivoDigital>((IndiceArquivoDigital x) => x.get_Descricao() == "LOGO");
+ if (indiceArquivoDigital1 != null)
+ {
+ bd = indiceArquivoDigital1.get_Bd();
+ }
+ else
+ {
+ bd = null;
+ }
+ string str6 = bd;
+ if (nullable1.HasValue)
+ {
+ arquivoDigital = await this.ArquivoDigitalServico.BuscarPorId(nullable1.Value, str6);
+ }
+ }
+ }
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital1 = arquivoDigital;
+ if (arquivoDigital1 != null)
+ {
+ arquivo = arquivoDigital1.get_Arquivo();
+ }
+ else
+ {
+ arquivo = null;
+ }
+ byte[] numArray = arquivo;
+ image = "";
+ if (numArray != null && numArray.Length != 0)
+ {
+ ReciboViewModel reciboViewModel = this;
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital2 = arquivoDigital;
+ if (arquivoDigital2 != null)
+ {
+ extensao = arquivoDigital2.get_Extensao();
+ }
+ else
+ {
+ extensao = null;
+ }
+ if (reciboViewModel.IsImage(extensao))
+ {
+ byte[] numArray1 = numArray;
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital3 = arquivoDigital;
+ if (arquivoDigital3 != null)
+ {
+ extensao1 = arquivoDigital3.get_Extensao();
+ }
+ else
+ {
+ extensao1 = null;
+ }
+ image = ReciboViewModel.GetImage(numArray1, extensao1);
+ }
+ }
+ string longDatePattern = (new CultureInfo("pt-PT", false)).DateTimeFormat.LongDatePattern;
+ DateTime? dataRecibo = this.SelectedRecibo.get_DataRecibo();
+ if (dataRecibo.HasValue)
+ {
+ DateTime valueOrDefault = dataRecibo.GetValueOrDefault();
+ str = valueOrDefault.ToString(longDatePattern, new CultureInfo("pt-PT"));
+ }
+ else
+ {
+ str = null;
+ }
+ str5 = str;
+ bool flag = await base.ShowMessage("DESEJA IMPRIMIR DUAS VIAS DO RECIBO?", "SIM", "NÃO", false);
+ int num = (!flag ? 1 : 2);
+ flag = !string.IsNullOrEmpty(image);
+ if (flag)
+ {
+ flag = await base.ShowMessage("DESEJA IMPRIMIR O LOGO DA CORRETORA NO RECIBO?\nPARA ADICIONAR UM LOGO, É NECESSÁRIO COLOCÁ-LO NO ARQUIVO\nDIGITAL NA TELA DE EMPRESA E FILIAIS COM DESCRIÇÃO \"LOGO\"", "SIM", "NÃO", false);
+ }
+ bool flag1 = flag;
+ string str7 = "<html><head><style type='text/css'>@page{size: A4; margin: 0cm}</style><title>RECIBO</title><link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css' integrity='sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh' crossorigin='anonymous'></head><body>";
+ for (int i = 0; i < num; i++)
+ {
+ if (!flag1)
+ {
+ str7 = string.Concat(str7, "<div style='margin: 50px 100px 50px 100px; font-size: 20px;'>");
+ }
+ else
+ {
+ str7 = string.Concat(str7, "<div>", image, "</div>");
+ str7 = string.Concat(str7, "<div style='margin: 0px 100px 0px 100px; font-size: 20px;'>");
+ }
+ str7 = string.Concat(str7, string.Format("<div style='text-align: right'><strong>N° {0}</strong></div><br>", this.SelectedRecibo.get_Id()));
+ str7 = string.Concat(str7, "<strong>R E C I B O</strong><br><br>");
+ if (this.SelectedRecibo.get_Tipo().GetValueOrDefault() != 1)
+ {
+ str1 = (this.SelectedRecibo.get_DocumentoPagante() == null || this.SelectedRecibo.get_DocumentoPagante().Clear().Length < 12 ? "EU" : "A");
+ string str8 = str1;
+ str2 = (this.SelectedRecibo.get_DocumentoPagante() == null || this.SelectedRecibo.get_DocumentoPagante().Clear().Length < 12 ? "CPF" : "CNPJ");
+ string str9 = str2;
+ string str10 = (str8 == "EU" ? "O" : "A");
+ string str11 = (str8 == "EU" ? "PAGUEI" : "PAGOU");
+ object[] pagante = new object[] { str8, this.SelectedRecibo.get_Pagante(), str10, str9, this.SelectedRecibo.get_DocumentoPagante(), str10, str11, this.SelectedRecibo.get_DataRecibo(), this.SelectedRecibo.get_Valor(), ValidationHelper.GetDescription(this.SelectedRecibo.get_Pagamento()), this.SelectedRecibo.get_Recebedor(), this.SelectedRecibo.get_DocumentoRecebedor(), this.SelectedRecibo.get_Referente().ToUpper() };
+ str7 = string.Concat(str7, string.Format("PELO PRESENTE, {0}, <strong>{1}</strong>, INSCRIT{2} NO {3} SOB Nº <strong>{4}</strong>, DECLAR{5} QUE {6}, NA DATA DE HOJE, <strong>{7:dd/MM/yyyy HH:mm}</strong>, O VALOR DE <strong>R$ {8:0.00}</strong> POR MEIO DE <strong>{9}</strong>, PARA <strong>{10}</strong>, INSCRITO NO CPF/CNPJ SOB Nº <strong>{11}</strong>, REFERENTE À(AO) <strong>{12}</strong>. DANDO-LHE POR ESTE RECIBO A DEVIDA QUITAÇÃO.<br>", pagante));
+ string[] cidade = new string[] { str7, "<br><strong>", Recursos.Empresa.get_Cidade(), ", ", null, null };
+ string str12 = str5;
+ if (str12 != null)
+ {
+ upper = str12.ToUpper();
+ }
+ else
+ {
+ upper = null;
+ }
+ cidade[4] = upper;
+ cidade[5] = ".</strong><br><br>";
+ str7 = string.Concat(cidade);
+ string[] recebedor = new string[] { str7, "_________________________________<br><strong>ASSINATURA </strong>", this.SelectedRecibo.get_Recebedor(), "<br>", this.SelectedRecibo.get_DocumentoRecebedor() };
+ str7 = string.Concat(recebedor);
+ }
+ else
+ {
+ str3 = (this.SelectedRecibo.get_DocumentoRecebedor() == null || this.SelectedRecibo.get_DocumentoRecebedor().Clear().Length < 12 ? "EU" : "A");
+ string str13 = str3;
+ str4 = (this.SelectedRecibo.get_DocumentoRecebedor() == null || this.SelectedRecibo.get_DocumentoRecebedor().Clear().Length < 12 ? "CPF" : "CNPJ");
+ string str14 = str4;
+ string str15 = (str13 == "EU" ? "O" : "A");
+ string str16 = (str13 == "EU" ? "RECEBI" : "RECEBEU");
+ object[] objArray = new object[] { str13, this.SelectedRecibo.get_Recebedor(), str15, str14, this.SelectedRecibo.get_DocumentoRecebedor(), str15, str16, this.SelectedRecibo.get_DataRecibo(), this.SelectedRecibo.get_Valor(), ValidationHelper.GetDescription(this.SelectedRecibo.get_Pagamento()), this.SelectedRecibo.get_Pagante(), this.SelectedRecibo.get_DocumentoPagante(), this.SelectedRecibo.get_Referente().ToUpper() };
+ str7 = string.Concat(str7, string.Format("PELO PRESENTE, {0}, <strong>{1}</strong>, INSCRIT{2} NO {3} SOB Nº <strong>{4}</strong>, DECLAR{5} QUE {6}, NA DATA DE HOJE, <strong>{7:dd/MM/yyyy HH:mm}</strong>, O VALOR DE <strong>R$ {8:0.00}</strong> POR MEIO DE <strong>{9}</strong>, DE <strong>{10}</strong>, INSCRITO NO CPF/CNPJ SOB Nº <strong>{11}</strong>, REFERENTE À(AO) <strong>{12}</strong>. DANDO-LHE POR ESTE RECIBO A DEVIDA QUITAÇÃO.<br>", objArray));
+ string[] strArrays = new string[] { str7, "<strong>", Recursos.Empresa.get_Cidade(), ", ", null, null };
+ string str17 = str5;
+ if (str17 != null)
+ {
+ upper1 = str17.ToUpper();
+ }
+ else
+ {
+ upper1 = null;
+ }
+ strArrays[4] = upper1;
+ strArrays[5] = ".</strong><br><br>";
+ str7 = string.Concat(strArrays);
+ string[] recebedor1 = new string[] { str7, "_________________________________<br><strong>ASSINATURA </strong>", this.SelectedRecibo.get_Recebedor(), "<br>", this.SelectedRecibo.get_DocumentoRecebedor() };
+ str7 = string.Concat(recebedor1);
+ }
+ str7 = string.Concat(str7, "<hr /></div>");
+ }
+ str7 = string.Concat(str7, "<script src='https://code.jquery.com/jquery-3.4.1.slim.min.js' integrity='sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n' crossorigin='anonymous'></script> <script src = 'https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js' integrity = 'sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo' crossorigin = 'anonymous' ></script><script src = 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js' integrity = 'sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6' crossorigin = 'anonymous' ></script> </body></html>");
+ string tempPath = Path.GetTempPath();
+ string str18 = string.Format("{0}_{1:ddMMyyyyhhmmss}.html", tempPath, Funcoes.GetNetworkTime());
+ StreamWriter streamWriter = new StreamWriter(str18, true, Encoding.UTF8);
+ streamWriter.Write(str7);
+ streamWriter.Close();
+ Process.Start(str18);
+ ReciboViewModel reciboViewModel1 = this;
+ string str19 = string.Format("IMPRIMIU O RECIBO DE NÚMERO \"{0}\"", this.SelectedRecibo.get_Id());
+ long id = this.SelectedRecibo.get_Id();
+ TipoTela? nullable2 = new TipoTela?(42);
+ object[] valor = new object[9];
+ if (this.SelectedRecibo.get_Tipo().HasValue)
+ {
+ TipoRecibo? tipo = this.SelectedRecibo.get_Tipo();
+ description = ValidationHelper.GetDescription(tipo.Value);
+ if (description == null)
+ {
+ description = "";
+ }
+ }
+ else
+ {
+ description = "-";
+ }
+ valor[0] = description;
+ TipoPagamento? pagamento = this.SelectedRecibo.get_Pagamento();
+ if (pagamento.HasValue)
+ {
+ obj = ValidationHelper.GetDescription(pagamento.GetValueOrDefault());
+ }
+ else
+ {
+ obj = null;
+ }
+ valor[1] = obj;
+ valor[2] = this.SelectedRecibo.get_Valor();
+ valor[3] = this.SelectedRecibo.get_DataRecibo();
+ valor[4] = this.SelectedRecibo.get_Pagante();
+ valor[5] = this.SelectedRecibo.get_DocumentoPagante();
+ valor[6] = this.SelectedRecibo.get_Recebedor();
+ valor[7] = this.SelectedRecibo.get_DocumentoRecebedor();
+ valor[8] = this.SelectedRecibo.get_Referente();
+ reciboViewModel1.RegistrarAcao(str19, id, nullable2, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", valor));
+ }
+ arquivoDigital = null;
+ image = null;
+ str5 = null;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string description;
+ object obj;
+ string str1;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedRecibo.Validate();
+ if (keyValuePairs1.Count <= 0)
+ {
+ str = (this.SelectedRecibo.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
+ str1 = str;
+ Recibo recibo = await this._servico.Save(this.SelectedRecibo);
+ if (this._servico.Sucesso)
+ {
+ ReciboViewModel reciboViewModel = this;
+ string str2 = string.Format("{0} RECIBO DE NÚMERO \"{1}\"", str1, recibo.get_Id());
+ long id = recibo.get_Id();
+ TipoTela? nullable = new TipoTela?(42);
+ object[] valor = new object[9];
+ if (recibo.get_Tipo().HasValue)
+ {
+ TipoRecibo? tipo = recibo.get_Tipo();
+ description = ValidationHelper.GetDescription(tipo.Value);
+ if (description == null)
+ {
+ description = "";
+ }
+ }
+ else
+ {
+ description = "-";
+ }
+ valor[0] = description;
+ TipoPagamento? pagamento = recibo.get_Pagamento();
+ if (pagamento.HasValue)
+ {
+ obj = ValidationHelper.GetDescription(pagamento.GetValueOrDefault());
+ }
+ else
+ {
+ obj = null;
+ }
+ valor[1] = obj;
+ valor[2] = recibo.get_Valor();
+ valor[3] = recibo.get_DataRecibo();
+ valor[4] = recibo.get_Pagante();
+ valor[5] = recibo.get_DocumentoPagante();
+ valor[6] = recibo.get_Recebedor();
+ valor[7] = recibo.get_DocumentoRecebedor();
+ valor[8] = recibo.get_Referente();
+ reciboViewModel.RegistrarAcao(str2, id, nullable, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", valor));
+ if (!this.Recibos.Any<Recibo>((Recibo x) => x.get_Id() == recibo.get_Id()))
+ {
+ this.Recibos.Add(recibo);
+ }
+ else
+ {
+ DomainBase.Copy<Recibo, Recibo>(this.Recibos.First<Recibo>((Recibo x) => x.get_Id() == recibo.get_Id()), recibo);
+ }
+ if (!this.RecibosFiltrados.Any<Recibo>((Recibo x) => x.get_Id() == recibo.get_Id()))
+ {
+ this.RecibosFiltrados.Add(recibo);
+ }
+ else
+ {
+ DomainBase.Copy<Recibo, Recibo>(this.RecibosFiltrados.First<Recibo>((Recibo x) => x.get_Id() == recibo.get_Id()), recibo);
+ }
+ this.RecibosFiltrados = new ObservableCollection<Recibo>(this.RecibosFiltrados);
+ this.WorkOnSelectedRecibo(recibo, false);
+ base.Alterar(false);
+ base.ToggleSnackBar("RECIBO SALVO COM SUCESSO", true);
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = null;
+ }
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ str1 = null;
+ return keyValuePairs;
+ }
+
+ private async void Seleciona()
+ {
+ base.Loading(true);
+ await base.PermissaoTela(42);
+ await this.SelecionaRecibo();
+ base.Loading(false);
+ }
+
+ private async Task SelecionaRecibo()
+ {
+ base.Loading(true);
+ List<Recibo> recibos = await this._servico.BuscarRecibos();
+ this.Recibos = recibos.ToList<Recibo>();
+ this.RecibosFiltrados = new ObservableCollection<Recibo>(this.Recibos);
+ if (this.RecibosFiltrados.Count <= 0)
+ {
+ this.SelectedRecibo = new Recibo();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelectedRecibo = this.RecibosFiltrados.First<Recibo>();
+ }
+ base.Loading(false);
+ }
+
+ private void WorkOnSelectedPagante(Cliente value)
+ {
+ if (value != null)
+ {
+ this.SelectedRecibo.set_Pagante(Regex.Replace(value.get_NomeSocial(), "\\-\\s\\d.*", "").Trim());
+ this.SelectedRecibo.set_DocumentoPagante(value.get_Documento());
+ this.SelectedRecibo = this.SelectedRecibo;
+ }
+ }
+
+ private void WorkOnSelectedRecebedor(Cliente value)
+ {
+ if (value != null)
+ {
+ this.SelectedRecibo.set_Recebedor(Regex.Replace(value.get_NomeSocial(), "\\-\\s\\d.*", "").Trim());
+ this.SelectedRecibo.set_DocumentoRecebedor(value.get_Documento());
+ this.SelectedRecibo = this.SelectedRecibo;
+ }
+ }
+
+ private void WorkOnSelectedRecibo(Recibo value, bool registrar = true)
+ {
+ long? nullable;
+ string description;
+ object obj;
+ this.CancelRecibo = (value == null || value.get_Id() == 0 ? this.CancelRecibo : (Recibo)value.Clone());
+ if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 42)
+ {
+ return;
+ }
+ if (registrar)
+ {
+ string str = string.Format("ACESSOU RECIBO DE NÚMERO \"{0}\"", value.get_Id());
+ long id = value.get_Id();
+ TipoTela? nullable1 = new TipoTela?(42);
+ object[] valor = new object[9];
+ if (value.get_Tipo().HasValue)
+ {
+ TipoRecibo? tipo = value.get_Tipo();
+ description = ValidationHelper.GetDescription(tipo.Value) ?? "";
+ }
+ else
+ {
+ description = "-";
+ }
+ valor[0] = description;
+ TipoPagamento? pagamento = value.get_Pagamento();
+ if (pagamento.HasValue)
+ {
+ obj = ValidationHelper.GetDescription(pagamento.GetValueOrDefault());
+ }
+ else
+ {
+ obj = null;
+ }
+ valor[1] = obj;
+ valor[2] = value.get_Valor();
+ valor[3] = value.get_DataRecibo();
+ valor[4] = value.get_Pagante();
+ valor[5] = value.get_DocumentoPagante();
+ valor[6] = value.get_Recebedor();
+ valor[7] = value.get_DocumentoRecebedor();
+ valor[8] = value.get_Referente();
+ base.RegistrarAcao(str, id, nullable1, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", valor));
+ }
+ this.LastAccessId = value.get_Id();
+ this.LastAccessTela = 42;
+ Recibo selectedRecibo = this.SelectedRecibo;
+ if (selectedRecibo != null)
+ {
+ nullable = new long?(selectedRecibo.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ long? nullable2 = nullable;
+ long num = value.get_Id();
+ if (nullable2.GetValueOrDefault() != num | !nullable2.HasValue)
+ {
+ this.SelectedRecibo = this.RecibosFiltrados.FirstOrDefault<Recibo>((Recibo x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+}
\ No newline at end of file |