diff options
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Ferramentas/EtiquetaViewModel.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.ViewModels.Ferramentas/EtiquetaViewModel.cs | 792 |
1 files changed, 792 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Ferramentas/EtiquetaViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Ferramentas/EtiquetaViewModel.cs new file mode 100644 index 0000000..a541f8f --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Ferramentas/EtiquetaViewModel.cs @@ -0,0 +1,792 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Seguros; +using Gestor.Application.Servicos.Seguros.Itens; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; + +namespace Gestor.Application.ViewModels.Ferramentas; + +public class EtiquetaViewModel : BaseSegurosViewModel +{ + private bool _allSelectedChanging; + + private List<string> _tiposEtiqueta = new List<string> { "CLIENTE", "APÓLICE" }; + + private string _tipoEtiqueta = "CLIENTE"; + + private bool? _allSelected; + + private ObservableCollection<Documento> _apolicesFiltrados = new ObservableCollection<Documento>(); + + private bool _duasColunas = true; + + private bool _tresColunas; + + private bool _umaPagina; + + private bool _mostrarNascimento; + + private int _pular; + + private object _visibilityColunas; + + private bool _mostrarApolice = true; + + private bool _mostrarVendedor = true; + + private bool _mostrarItem = true; + + public List<string> TiposEtiqueta + { + get + { + return _tiposEtiqueta; + } + set + { + _tiposEtiqueta = value; + OnPropertyChanged("TiposEtiqueta"); + } + } + + public string TipoEtiqueta + { + get + { + return _tipoEtiqueta; + } + set + { + _tipoEtiqueta = value; + OnPropertyChanged("TipoEtiqueta"); + OnPropertyChanged("ExibirControlesEtiquetaApolice"); + OnPropertyChanged("ExibirControlesEtiquetaCliente"); + } + } + + public Visibility ExibirControlesEtiquetaApolice + { + get + { + if (TipoEtiqueta == "APÓLICE") + { + return (Visibility)0; + } + return (Visibility)2; + } + } + + public Visibility ExibirControlesEtiquetaCliente + { + get + { + if (TipoEtiqueta == "CLIENTE") + { + return (Visibility)0; + } + return (Visibility)2; + } + } + + public bool? AllSelected + { + get + { + return _allSelected; + } + set + { + if (value != _allSelected) + { + _allSelected = value; + AllSelectedChanged(); + Apolices = new List<Documento>(Apolices); + OnPropertyChanged("AllSelected"); + } + } + } + + public List<Documento> Apolices { get; set; } + + public ObservableCollection<Documento> ApolicesFiltrados + { + get + { + return _apolicesFiltrados; + } + set + { + _apolicesFiltrados = value; + foreach (Documento apolicesFiltrado in ApolicesFiltrados) + { + apolicesFiltrado.PropertyChanged += EntryOnPropertyChanged; + } + OnPropertyChanged("ApolicesFiltrados"); + } + } + + public bool DuasColunas + { + get + { + return _duasColunas; + } + set + { + _duasColunas = value; + OnPropertyChanged("DuasColunas"); + } + } + + public bool TresColunas + { + get + { + return _tresColunas; + } + set + { + _tresColunas = value; + OnPropertyChanged("TresColunas"); + } + } + + public bool UmaPagina + { + get + { + return _umaPagina; + } + set + { + _umaPagina = value; + VisibilityColunas = (object)(Visibility)(value ? 2 : 0); + OnPropertyChanged("UmaPagina"); + } + } + + public bool MostrarNascimento + { + get + { + return _mostrarNascimento; + } + set + { + _mostrarNascimento = value; + OnPropertyChanged("MostrarNascimento"); + } + } + + public int Pular + { + get + { + return _pular; + } + set + { + _pular = value; + OnPropertyChanged("Pular"); + } + } + + public object VisibilityColunas + { + get + { + return _visibilityColunas; + } + set + { + _visibilityColunas = value; + OnPropertyChanged("VisibilityColunas"); + } + } + + public bool MostrarApolice + { + get + { + return _mostrarApolice; + } + set + { + _mostrarApolice = value; + OnPropertyChanged("MostrarApolice"); + } + } + + public bool MostrarVendedor + { + get + { + return _mostrarVendedor; + } + set + { + _mostrarVendedor = value; + OnPropertyChanged("MostrarVendedor"); + } + } + + public bool MostrarItem + { + get + { + return _mostrarItem; + } + set + { + _mostrarItem = value; + OnPropertyChanged("MostrarItem"); + } + } + + private void EntryOnPropertyChanged(object sender, PropertyChangedEventArgs args) + { + if (args.PropertyName == "Selecionado") + { + RecheckAllSelected(); + } + } + + private void RecheckAllSelected() + { + if (_allSelectedChanging) + { + return; + } + try + { + _allSelectedChanging = true; + if (Apolices.All((Documento e) => e.Selecionado)) + { + AllSelected = true; + } + else if (Apolices.All((Documento e) => !e.Selecionado)) + { + AllSelected = false; + } + else + { + AllSelected = null; + } + } + finally + { + _allSelectedChanging = false; + } + } + + private void AllSelectedChanged() + { + if (_allSelectedChanging) + { + return; + } + try + { + _allSelectedChanging = true; + if (!AllSelected.HasValue) + { + return; + } + foreach (Documento apolice in Apolices) + { + apolice.Selecionado = AllSelected.Value; + } + } + finally + { + _allSelectedChanging = false; + } + } + + public async Task CarregarDados(List<Documento> list, bool apenasCliente) + { + List<Cliente> source = ((IEnumerable<Documento>)list.ToList()).Select((Func<Documento, Cliente>)((Documento x) => new Cliente + { + Id = ((DomainBase)x.Controle.Cliente).Id + })).ToList(); + ClienteServico clienteServico = new ClienteServico(); + ItemServico itemServico = new ItemServico(); + List<ClienteEndereco> enderecos = await clienteServico.BuscarEnderecosPorCliente(source.Where((Cliente x) => ((DomainBase)x).Id > 0).ToList()); + ObservableCollection<Item> observableCollection = ((!apenasCliente) ? (await itemServico.BuscarItens(list.ToList())) : null); + ObservableCollection<Item> source2 = observableCollection; + foreach (Documento x2 in list) + { + if (enderecos.Where((ClienteEndereco y) => ((DomainBase)y.Cliente).Id == ((DomainBase)x2.Controle.Cliente).Id).Count() == 0) + { + continue; + } + if (((DomainBase)x2.Controle.Cliente).Id > 0) + { + x2.Controle.Cliente.Enderecos = new ObservableCollection<ClienteEndereco>(from y in enderecos.Where((ClienteEndereco y) => ((DomainBase)y.Cliente).Id == ((DomainBase)x2.Controle.Cliente).Id).ToList() + orderby y.Ordem + select y); + } + if (!apenasCliente) + { + x2.ItensAtivo = source2.Where((Item y) => ((DomainBase)y.Documento).Id == ((DomainBase)x2).Id).ToList(); + } + } + TipoEtiqueta = (apenasCliente ? "CLIENTE" : "APÓLICE"); + Apolices = (from x in list.Where(delegate(Documento x) + { + Cliente cliente = x.Controle.Cliente; + if (((cliente != null) ? cliente.Enderecos : null) != null) + { + Cliente cliente2 = x.Controle.Cliente; + if (cliente2 == null) + { + return false; + } + return cliente2.Enderecos.Count() > 0; + } + return false; + }) + orderby x.Controle.Cliente.Nome + select x).ToList(); + ApolicesFiltrados = new ObservableCollection<Documento>(Apolices); + AllSelected = true; + RecheckAllSelected(); + } + + public void EmitirEtiquetas() + { + string text = ""; + List<Documento> list = Apolices.Where((Documento x) => x.Selecionado).ToList(); + string tipoEtiqueta = TipoEtiqueta; + if (!(tipoEtiqueta == "CLIENTE")) + { + if (tipoEtiqueta == "APÓLICE") + { + if (UmaPagina) + { + text = "<html><head><style type='text/css'>@page{size: landscape}</style><title>ETIQUETAS</title></head><body>"; + for (int i = 0; i < list.Count; i++) + { + text += "<div style='clear: both; page-break-after:always; margin-top:"; + text += ((i == 0) ? "25%'>" : "30%'>"); + text += "<div align='center'>"; + text += "<table style='text-align: center;'>"; + text += "<tr style='height: 2.5cm;'>"; + text = text + "<td style='width: " + 10.7.ToString(CultureInfo.InvariantCulture) + "cm;'><font size='1px' face='Arial'>"; + Documento val = list[i]; + string[] obj = new string[7] + { + text, + val.Controle.Cliente.Nome.Trim(), + " <br>", + null, + null, + null, + null + }; + object obj2; + if (!MostrarItem) + { + obj2 = null; + } + else + { + if (val.ItensAtivo.Count <= 1) + { + Item? obj3 = val.ItensAtivo.FirstOrDefault(); + obj2 = ((obj3 != null) ? obj3.Descricao.ToUpper() : null) + "<br>"; + } + else + { + obj2 = "APÓLICE COLETIVA <br>"; + } + if (obj2 == null) + { + obj2 = ""; + } + } + obj[3] = (string)obj2; + obj[4] = (MostrarApolice ? (((val.Apolice == "PROSPECÇÃO") ? $"{val.Vigencia2:d} - APÓLICE: {val.Apolice} <br>" : ($"{val.Vigencia1:d} - {val.Vigencia2:d} - APÓLICE: {val.Apolice}" + (string.IsNullOrEmpty(val.Endosso) ? "<br>" : (" /" + val.Endosso + " <br>")))) ?? "") : null); + obj[5] = ((val.Apolice == "PROSPECÇÃO") ? "" : (val.Controle.Seguradora.Nome + " - " + val.Controle.Ramo.Nome + " <br>")); + obj[6] = (MostrarVendedor ? (((val.VendedorPrincipal == null) ? "" : ("VENDEDOR: " + val.VendedorPrincipal.Nome)) ?? "") : null); + text = string.Concat(obj); + text += "</font></td>"; + text += "</tr>"; + text += "</table>"; + text += "</div>"; + text += "</div>"; + } + } + else + { + int num = 0; + int num2 = 0; + double num3 = 0.0; + if (DuasColunas) + { + num = 10; + num2 = 2; + num3 = 10.52; + } + else if (TresColunas) + { + num = 10; + num2 = 3; + num3 = 6.87; + } + Pular %= num * num2; + int pular = Pular; + text = "<html><head><style type='text/css'>@page{size: Letter; margin: 0cm}</style><title>ETIQUETAS</title></head><body><div align='center'>"; + int num4 = 0; + while (num4 < list.Count) + { + text += "<div style='clear: both; page-break-after:always;'>"; + text = text + "<table><tr style='height: " + ((num4 == 0) ? "0.55" : "0.8") + "cm;'></tr>"; + for (int j = 0; j < num * num2; j += num2) + { + text += "<tr style='height: 2.6cm;'>"; + for (int k = 0; k < num2; k++) + { + text = text + "<td style='width: " + num3.ToString(CultureInfo.InvariantCulture) + "cm; padding: 10px;'><font size='1px' face='Arial'>"; + if (j + k >= Pular) + { + if (num4 < list.Count) + { + Documento val2 = list[num4]; + string[] obj4 = new string[7] + { + text, + val2.Controle.Cliente.Nome.Trim(), + " <br>", + null, + null, + null, + null + }; + object obj5; + if (!MostrarItem) + { + obj5 = null; + } + else + { + if (val2.ItensAtivo.Count <= 1) + { + Item? obj6 = val2.ItensAtivo.FirstOrDefault(); + obj5 = ((obj6 != null) ? obj6.Descricao.ToUpper() : null) + "<br>"; + } + else + { + obj5 = "APÓLICE COLETIVA <br>"; + } + if (obj5 == null) + { + obj5 = ""; + } + } + obj4[3] = (string)obj5; + obj4[4] = ((!MostrarApolice) ? null : (((val2.Apolice == "PROSPECÇÃO") ? $"{val2.Vigencia2:d} - APÓLICE: {val2.Apolice} <br>" : ($"{val2.Vigencia1:d} - {val2.Vigencia2:d} - APÓLICE: {val2.Apolice}" + (string.IsNullOrEmpty(val2.Endosso) ? "<br>" : (" /" + val2.Endosso + " <br>")))) ?? "")); + obj4[5] = ((val2.Apolice == "PROSPECÇÃO") ? "" : (val2.Controle.Seguradora.Nome + " - " + val2.Controle.Ramo.Nome + " <br>")); + obj4[6] = ((!MostrarVendedor) ? null : (((val2.VendedorPrincipal == null) ? "" : ("VENDEDOR: " + val2.VendedorPrincipal.Nome)) ?? "")); + text = string.Concat(obj4); + num4++; + } + Pular = 0; + } + text += "</font></td>"; + } + } + text += "</table>"; + text += "</div>"; + } + Pular = (pular + list.Count) % (num * num2); + } + RegistrarAcao(string.Format("EMITIU ETIQUETA DE {0} DOCUMENTO{1}", list.Count, (list.Count == 1) ? "" : "S"), 0L, (TipoTela)59, "IDS DOS DOCUMENTOS:\n" + string.Join(", ", list.Select((Documento x) => ((DomainBase)x).Id))); + } + } + else + { + list = Apolices.Where((Documento x) => x.Selecionado && x.Controle.Cliente.Enderecos != null).ToList(); + if (UmaPagina) + { + text = "<html><head><style type='text/css'>@page{size: landscape}</style><title>ETIQUETAS</title></head><body>"; + for (int l = 0; l < list.Count; l++) + { + text += "<div style='clear: both; page-break-after:always; margin-top:"; + text += ((l == 0) ? "25%'>" : "30%'>"); + text += "<div align='center'>"; + text += "<table style='text-align: center;'>"; + text += "<tr style='height: 2.48cm;'>"; + text = text + "<td style='width: " + 10.7.ToString(CultureInfo.InvariantCulture) + "cm;'><font size='3px' face='Arial'>"; + Documento val3 = list[l]; + if (MostrarNascimento) + { + val3.Controle.Cliente.Nascimento = new ClienteServico().BuscarNascimento(((DomainBase)val3.Controle.Cliente).Id); + } + string[] obj7 = new string[9] + { + text, + val3.Controle.Cliente.Nome.Trim(), + " ", + (!val3.Controle.Cliente.Nascimento.HasValue || !MostrarNascimento) ? "" : val3.Controle.Cliente.Nascimento?.ToString("dd/MM"), + " <br>", + null, + null, + null, + null + }; + object obj16; + if (((DomainBase)val3.Controle.Cliente).Id != 0L) + { + string[] array = new string[10]; + ClienteEndereco? obj8 = val3.Controle.Cliente.Enderecos.OrderBy((ClienteEndereco x) => x.Ordem).FirstOrDefault(); + array[0] = ((obj8 == null) ? null : ((EnderecoBase)obj8).Endereco?.Trim()); + array[1] = ", "; + ClienteEndereco? obj9 = val3.Controle.Cliente.Enderecos.FirstOrDefault(); + array[2] = ((obj9 == null) ? null : ((EnderecoBase)obj9).Numero?.Trim()); + ClienteEndereco? obj10 = val3.Controle.Cliente.Enderecos.FirstOrDefault(); + object obj11; + if (string.IsNullOrWhiteSpace((obj10 != null) ? ((EnderecoBase)obj10).Complemento : null)) + { + obj11 = ""; + } + else + { + ClienteEndereco? obj12 = val3.Controle.Cliente.Enderecos.FirstOrDefault(); + obj11 = "<br>" + ((obj12 == null) ? null : ((EnderecoBase)obj12).Complemento?.Trim()); + } + array[3] = (string)obj11; + array[4] = "<br>"; + ClienteEndereco? obj13 = val3.Controle.Cliente.Enderecos.FirstOrDefault(); + array[5] = ((obj13 == null) ? null : ((EnderecoBase)obj13).Bairro?.Trim()); + array[6] = " - "; + ClienteEndereco? obj14 = val3.Controle.Cliente.Enderecos.FirstOrDefault(); + array[7] = ((obj14 == null) ? null : ((EnderecoBase)obj14).Cidade?.Trim()); + array[8] = "/"; + ClienteEndereco? obj15 = val3.Controle.Cliente.Enderecos.FirstOrDefault(); + array[9] = ((obj15 == null) ? null : ((EnderecoBase)obj15).Estado?.Trim()); + obj16 = string.Concat(array); + } + else + { + obj16 = ""; + } + obj7[5] = (string)obj16; + obj7[6] = " <br>"; + object obj18; + if (((DomainBase)val3.Controle.Cliente).Id != 0L) + { + ClienteEndereco? obj17 = val3.Controle.Cliente.Enderecos.OrderBy((ClienteEndereco x) => x.Ordem).FirstOrDefault(); + obj18 = ((obj17 != null) ? ((EnderecoBase)obj17).Cep.Trim() : null) ?? ""; + } + else + { + obj18 = ""; + } + obj7[7] = (string)obj18; + obj7[8] = " <br>"; + text = string.Concat(obj7); + text += "</font></td>"; + text += "</tr>"; + text += "</table>"; + text += "</div>"; + text += "</div>"; + } + } + else + { + int num5 = 0; + int num6 = 0; + double num7 = 0.0; + if (DuasColunas) + { + num5 = 10; + num6 = 2; + num7 = 10.52; + } + else if (TresColunas) + { + num5 = 10; + num6 = 3; + num7 = 6.82; + } + Pular %= num5 * num6; + int pular2 = Pular; + text = "<html><head><style type='text/css'>@page{size: Letter; margin: 0cm}</style><title>ETIQUETAS</title></head><body><div align='center'>"; + int num8 = 0; + while (num8 < list.Count) + { + text += "<div style='clear: both; page-break-after:always;'>"; + bool flag = num8 == 0 || num8 == num5 * num6; + text = text + "<table><tr style='height: " + (flag ? "0.55" : "0.85") + "cm;'></tr>"; + for (int m = 0; m < num5 * num6; m += num6) + { + text += "<tr style='height: 2.60cm;'>"; + if (DuasColunas) + { + text += "<td style='width: 0.4cm;'>"; + } + else if (TresColunas) + { + text += "<td style='width: 0.05cm;'>"; + } + text += "</td>"; + for (int n = 0; n < num6; n++) + { + text = text + "<td style='width: " + num7.ToString(CultureInfo.InvariantCulture) + "cm;'><font size='1px' face='Arial'>"; + if (m + n >= Pular) + { + if (num8 < list.Count) + { + Documento val4 = list[num8]; + if (MostrarNascimento) + { + val4.Controle.Cliente.Nascimento = new ClienteServico().BuscarNascimento(((DomainBase)val4.Controle.Cliente).Id); + } + if (val4.Controle.Cliente.Enderecos.Count() > 0) + { + string[] obj19 = new string[8] + { + text, + val4.Controle.Cliente.Nome.Trim(), + " ", + (!val4.Controle.Cliente.Nascimento.HasValue || !MostrarNascimento) ? "" : val4.Controle.Cliente.Nascimento?.ToString("dd/MM"), + " <br>", + null, + null, + null + }; + object obj32; + if (((DomainBase)val4.Controle.Cliente).Id != 0L) + { + string[] array2 = new string[10]; + ClienteEndereco? obj20 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + array2[0] = ((obj20 == null) ? null : ((EnderecoBase)obj20).Endereco?.Trim()); + array2[1] = ", "; + ClienteEndereco? obj21 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + array2[2] = ((obj21 == null) ? null : ((EnderecoBase)obj21).Numero?.Trim()); + ClienteEndereco? obj22 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + object obj23; + if (string.IsNullOrWhiteSpace((obj22 != null) ? ((EnderecoBase)obj22).Complemento : null)) + { + obj23 = ""; + } + else + { + ClienteEndereco? obj24 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + obj23 = "<br>" + ((obj24 != null) ? ((EnderecoBase)obj24).Complemento.Trim() : null); + } + array2[3] = (string)obj23; + array2[4] = "<br>"; + ClienteEndereco? obj25 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + array2[5] = ((obj25 == null) ? null : ((EnderecoBase)obj25).Bairro?.Trim()); + array2[6] = " - "; + ClienteEndereco? obj26 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + object obj27; + if (string.IsNullOrEmpty((obj26 != null) ? ((EnderecoBase)obj26).Cidade : null)) + { + obj27 = ""; + } + else + { + ClienteEndereco? obj28 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + obj27 = ((obj28 != null) ? ((EnderecoBase)obj28).Cidade.Trim() : null); + } + array2[7] = (string)obj27; + array2[8] = "/"; + ClienteEndereco? obj29 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + object obj30; + if (string.IsNullOrEmpty((obj29 != null) ? ((EnderecoBase)obj29).Estado : null)) + { + obj30 = ""; + } + else + { + ClienteEndereco? obj31 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + obj30 = ((obj31 != null) ? ((EnderecoBase)obj31).Estado.Trim() : null); + } + array2[9] = (string)obj30; + obj32 = string.Concat(array2); + } + else + { + obj32 = ""; + } + obj19[5] = (string)obj32; + obj19[6] = " <br>"; + object obj34; + if (((DomainBase)val4.Controle.Cliente).Id != 0L) + { + ClienteEndereco? obj33 = val4.Controle.Cliente.Enderecos.FirstOrDefault(); + obj34 = ((obj33 != null) ? ((EnderecoBase)obj33).Cep.Trim() : null) ?? ""; + } + else + { + obj34 = ""; + } + obj19[7] = (string)obj34; + text = string.Concat(obj19); + } + num8++; + } + Pular = 0; + } + text += "</font></td>"; + if (n < num6 - 1) + { + if (DuasColunas) + { + text += "<td style='width: 0.5cm;'>"; + } + else if (TresColunas) + { + text += "<td style='width: 0.3cm;'>"; + } + } + text += "</td>"; + } + } + text += "</table>"; + text += "</div>"; + } + Pular = (pular2 + list.Count) % (num5 * num6); + } + RegistrarAcao(string.Format("EMITIU ETIQUETA DE {0} CLIENTE{1}", list.Count, (list.Count == 1) ? "" : "S"), 0L, (TipoTela)59, "IDS E NOMES DOS CLIENTES:\n" + string.Join("\n", list.Select((Documento x) => ((DomainBase)x.Controle.Cliente).Id + ": \"" + x.Controle.Cliente.Nome + "\""))); + } + text += "</body></html>"; + string tempPath = Path.GetTempPath(); + string text2 = $"{tempPath}{(object)(TipoExtrato)0}_{Funcoes.GetNetworkTime():ddMMyyyyhhmmss}.html"; + StreamWriter streamWriter = new StreamWriter(text2, append: true, Encoding.UTF8); + streamWriter.Write(text); + streamWriter.Close(); + Process.Start(text2); + } + + internal async Task<List<Documento>> Filtrar(string value) + { + return await Task.Run(() => FiltrarApolice(value)); + } + + public List<Documento> FiltrarApolice(string filter) + { + ApolicesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Documento>(Apolices) : new ObservableCollection<Documento>(from x in Apolices + where ValidationHelper.RemoveDiacritics(x.Controle.Cliente.Nome.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) + orderby x.Controle.Cliente.Nome descending, ((DomainBase)x).Id + select x)); + return ApolicesFiltrados.ToList(); + } +} |