summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Seguros.Itens/AutoViewModel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
commit225aa1499e37faf9d38257caabbadc68d78b427e (patch)
tree102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.ViewModels.Seguros.Itens/AutoViewModel.cs
parent1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff)
downloadgestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz
gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Seguros.Itens/AutoViewModel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels.Seguros.Itens/AutoViewModel.cs1266
1 files changed, 1266 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Seguros.Itens/AutoViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Seguros.Itens/AutoViewModel.cs
new file mode 100644
index 0000000..5de8d10
--- /dev/null
+++ b/Decompiler/Gestor.Application.ViewModels.Seguros.Itens/AutoViewModel.cs
@@ -0,0 +1,1266 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Data;
+using System.Globalization;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Forms;
+using ClosedXML.Excel;
+using Gestor.Application.Actions;
+using Gestor.Application.Componentes;
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos.Seguros.Itens;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Configuracoes;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using Gestor.Model.Helper;
+using Microsoft.Office.Interop.Excel;
+
+namespace Gestor.Application.ViewModels.Seguros.Itens;
+
+public class AutoViewModel : ItemViewModel, IDisposable
+{
+ private new readonly ItemServico _itemServico;
+
+ private readonly AutoServico _servico;
+
+ private bool _allowAlterarExcluir = true;
+
+ private Visibility _isVisiblePorcentagemReferencia = (Visibility)2;
+
+ private Visibility _isVisibleValorDeterminado = (Visibility)2;
+
+ private object _cobertura;
+
+ private List<Combustivel> _combustivel = ((Combustivel[])Enum.GetValues(typeof(Combustivel))).OrderBy((Combustivel x) => ValidationHelper.GetCategory((Enum)(object)x)).ToList();
+
+ private Item _selectedItem = new Item();
+
+ private List<Fabricante> _fabricantes;
+
+ private Fabricante _selectedFabricante;
+
+ private string _codigoItem;
+
+ private Categoria? _categocia;
+
+ private UsoVeiculo? _usoVeiculo;
+
+ private Item ItemSelecionado { get; set; }
+
+ private Ramo Ramo { get; }
+
+ public bool Invoke { get; set; }
+
+ public bool AllowAlterarExcluir
+ {
+ get
+ {
+ return _allowAlterarExcluir;
+ }
+ set
+ {
+ _allowAlterarExcluir = value;
+ OnPropertyChanged("AllowAlterarExcluir");
+ }
+ }
+
+ public Visibility IsVisiblePorcentagemReferencia
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _isVisiblePorcentagemReferencia;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ _isVisiblePorcentagemReferencia = value;
+ OnPropertyChanged("IsVisiblePorcentagemReferencia");
+ }
+ }
+
+ public Visibility IsVisibleValorDeterminado
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _isVisibleValorDeterminado;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ _isVisibleValorDeterminado = value;
+ OnPropertyChanged("IsVisibleValorDeterminado");
+ }
+ }
+
+ public object Cobertura
+ {
+ get
+ {
+ return _cobertura;
+ }
+ set
+ {
+ _cobertura = value;
+ OnPropertyChanged("Cobertura");
+ }
+ }
+
+ public List<Combustivel> Combustivel
+ {
+ get
+ {
+ return _combustivel;
+ }
+ set
+ {
+ _combustivel = value;
+ OnPropertyChanged("Combustivel");
+ }
+ }
+
+ public Item SelectedItem
+ {
+ get
+ {
+ return _selectedItem;
+ }
+ set
+ {
+ _selectedItem = value;
+ VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null);
+ OnPropertyChanged("SelectedItem");
+ }
+ }
+
+ public List<Fabricante> Fabricantes
+ {
+ get
+ {
+ return _fabricantes;
+ }
+ set
+ {
+ _fabricantes = value;
+ OnPropertyChanged("Fabricantes");
+ }
+ }
+
+ public Fabricante SelectedFabricante
+ {
+ get
+ {
+ return _selectedFabricante;
+ }
+ set
+ {
+ _selectedFabricante = value;
+ OnPropertyChanged("SelectedFabricante");
+ }
+ }
+
+ public string CodigoItem
+ {
+ get
+ {
+ return _codigoItem;
+ }
+ set
+ {
+ _codigoItem = value;
+ OnPropertyChanged("CodigoItem");
+ }
+ }
+
+ public Categoria? Categoria
+ {
+ get
+ {
+ return _categocia;
+ }
+ set
+ {
+ _categocia = value;
+ Item selectedItem = SelectedItem;
+ if (((selectedItem != null) ? selectedItem.Auto : null) != null)
+ {
+ SelectedItem.Auto.Categoria = value;
+ }
+ OnPropertyChanged("Categoria");
+ }
+ }
+
+ public UsoVeiculo? UsoVeiculo
+ {
+ get
+ {
+ return _usoVeiculo;
+ }
+ set
+ {
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0008: Invalid comparison between Unknown and I4
+ //IL_000c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0012: Invalid comparison between Unknown and I4
+ if ((int)value.GetValueOrDefault() == 2 || (int)value.GetValueOrDefault() == 3)
+ {
+ SelectedItem.Auto.Categoria = (Categoria)3;
+ Categoria = (Categoria)3;
+ }
+ Item selectedItem = SelectedItem;
+ if (((selectedItem != null) ? selectedItem.Auto : null) != null && value.HasValue)
+ {
+ SelectedItem.Auto.UsoVeiculo = value;
+ }
+ _usoVeiculo = value;
+ OnPropertyChanged("UsoVeiculo");
+ }
+ }
+
+ public AutoViewModel(bool substituir = false, ManutencaoItem manutencao = null, Item itemSelecionado = null, Ramo ramo = null, bool endossoRenovacao = false)
+ {
+ //IL_0009: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0010: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0059: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0063: Expected O, but got Unknown
+ //IL_00b1: Unknown result type (might be due to invalid IL or missing references)
+ Invoke = itemSelecionado == null;
+ ItemSelecionado = itemSelecionado ?? ConsultaViewModel.ItemSelecionado;
+ Ramo = ramo ?? ConsultaViewModel.DocumentoSelecionado.Controle.Ramo;
+ if (Invoke)
+ {
+ ItemSelecionado = (Item)(((object)ItemSelecionado) ?? ((object)new Item()));
+ ItemSelecionado.Documento = ConsultaViewModel.DocumentoSelecionado;
+ }
+ _itemServico = new ItemServico();
+ _servico = new AutoServico();
+ Seleciona(ItemSelecionado);
+ if (substituir)
+ {
+ Substituir(ItemSelecionado);
+ }
+ if (manutencao != null)
+ {
+ Manter(ItemSelecionado, manutencao);
+ }
+ AllowAlterarExcluir = !endossoRenovacao;
+ CarregaCobertura();
+ }
+
+ public void CarregaCobertura()
+ {
+ CoberturaViewModel.Item = ItemSelecionado;
+ CoberturaViewModel.Ramo = Ramo;
+ Cobertura = new CoberturaView(CoberturaViewModel);
+ }
+
+ public void Descarregar()
+ {
+ Cobertura = null;
+ }
+
+ private void WorkOnSelectedAuto(Auto value)
+ {
+ if (value != null && ((DomainBase)value).Id != 0L)
+ {
+ SelectedFabricante = ((IEnumerable<Fabricante>)Fabricantes).FirstOrDefault((Func<Fabricante, bool>)delegate(Fabricante x)
+ {
+ int id = x.Id;
+ Fabricante fabricante = value.Fabricante;
+ return id == ((fabricante != null) ? new int?(fabricante.Id) : null);
+ });
+ }
+ }
+
+ public async void Seleciona(Item item)
+ {
+ Loading(isLoading: true);
+ await PermissaoTela((TipoTela)3);
+ await SelecionaItem(item);
+ Loading(isLoading: false);
+ }
+
+ public async void Substituir(Item item)
+ {
+ base.ItemSubstituido = item;
+ await Incluir(substituir: true);
+ }
+
+ public void Manter(Item item, ManutencaoItem manutencao)
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0007: Invalid comparison between Unknown and I4
+ if ((int)manutencao.Tipo == 1)
+ {
+ base.ItemSubstituido = item;
+ }
+ Manter(manutencao);
+ base.Mantido = true;
+ }
+
+ public async Task SelecionaItem(Item item, bool registrar = true)
+ {
+ if (item != null && LastAccessId == ((DomainBase)item).Id && (int)LastAccessTela == 9)
+ {
+ return;
+ }
+ base.Mantido = false;
+ Fabricantes = Recursos.Fabricantes;
+ if (!new List<long> { 5L, 37L }.Contains(((DomainBase)Ramo).Id))
+ {
+ return;
+ }
+ CoberturaViewModel.Ramo = Ramo;
+ if (CoberturaViewModel.CoberturasPadrao == null)
+ {
+ await CoberturaViewModel.SelectionaCoberturas();
+ }
+ if (item == null || ((DomainBase)item).Id == 0L)
+ {
+ SelectedItem = null;
+ CoberturaViewModel.Coberturas = null;
+ base.IsVisible = (Visibility)0;
+ return;
+ }
+ Loading(isLoading: true);
+ item = await _itemServico.BuscarItemPorIdAsync(((DomainBase)item).Id);
+ Item val = item;
+ val.Auto = await _itemServico.BuscaAuto(((DomainBase)item).Id);
+ SelectedItem = item;
+ ((DomainBase)SelectedItem).Initialize();
+ Initialized = true;
+ WorkOnSelectedAuto(SelectedItem.Auto);
+ CoberturaViewModel.Item = item;
+ await CoberturaViewModel.CancelarAlteracao();
+ if (registrar)
+ {
+ RegistrarAcao("ACESSOU ITEM DE DESCRIÇÃO \"" + SelectedItem.Descricao + "\"", ((DomainBase)SelectedItem).Id, (TipoTela)3, $"ID ITEM: {((DomainBase)SelectedItem).Id}\nID DOCUMENTO: {((DomainBase)SelectedItem.Documento).Id}\nRAMO: {SelectedItem.Documento.Controle.Ramo.Nome}\nCLIENTE: {SelectedItem.Documento.Controle.Cliente.Nome}\nID CLIENTE: {((DomainBase)SelectedItem.Documento.Controle.Cliente).Id}");
+ }
+ LastAccessId = ((DomainBase)SelectedItem).Id;
+ LastAccessTela = (TipoTela)3;
+ CodigoItem = ((DomainBase)SelectedItem).Id.ToString();
+ UsoVeiculo = SelectedItem.Auto.UsoVeiculo;
+ Categoria = SelectedItem.Auto.Categoria;
+ Loading(isLoading: false);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>();
+ if (string.IsNullOrEmpty(SelectedItem.Auto.Chassi))
+ {
+ return errors;
+ }
+ if (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 26))
+ {
+ return errors;
+ }
+ Documento val = await new AutoServico().BuscarAuto(SelectedItem.Auto.Chassi, ((DomainBase)SelectedItem.Auto).Id, SelectedItem.Documento.Vigencia1, SelectedItem.Documento.Vigencia2, ((DomainBase)SelectedItem.Documento.Controle.Seguradora).Id);
+ if (val == null)
+ {
+ return errors;
+ }
+ if (!AllowAlterarExcluir && ((DomainBase)SelectedItem.Documento.Controle).Id == ((DomainBase)val.Controle).Id)
+ {
+ return errors;
+ }
+ errors.Add(new KeyValuePair<string, string>("Chassi", "CHASSI JÁ CADASTRADO NA APÓLICE " + val.Apolice + " DO CLIENTE " + val.Controle.Cliente.Nome + "."));
+ return errors;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Validate(Item item)
+ {
+ List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>();
+ if (string.IsNullOrEmpty(item.Auto.Chassi))
+ {
+ return errors;
+ }
+ if (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 26))
+ {
+ return errors;
+ }
+ Documento val = await new AutoServico().BuscarAuto(item.Auto.Chassi, ((DomainBase)item.Auto).Id, item.Documento.Vigencia1, item.Documento.Vigencia2, ((DomainBase)item.Documento.Controle.Seguradora).Id);
+ if (val == null)
+ {
+ return errors;
+ }
+ if (!AllowAlterarExcluir && ((DomainBase)item.Documento.Controle).Id == ((DomainBase)val.Controle).Id)
+ {
+ return errors;
+ }
+ errors.Add(new KeyValuePair<string, string>("Chassi", "CHASSI JÁ CADASTRADO NA APÓLICE " + val.Apolice + " DO CLIENTE " + val.Controle.Cliente.Nome + "."));
+ return errors;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ SelectedItem.Auto.Placa = ((!string.IsNullOrEmpty(SelectedItem.Auto.Placa)) ? ValidationHelper.FormataPlaca(SelectedItem.Auto.Placa) : string.Empty);
+ Item selectedItem = SelectedItem;
+ string[] array = new string[7];
+ Fabricante fabricante = SelectedItem.Auto.Fabricante;
+ array[0] = ((fabricante != null) ? fabricante.Descricao : null);
+ array[1] = " ";
+ array[2] = SelectedItem.Auto.Modelo;
+ array[3] = " / ";
+ array[4] = SelectedItem.Auto.Chassi;
+ array[5] = " / ";
+ array[6] = SelectedItem.Auto.Placa;
+ selectedItem.Descricao = string.Concat(array);
+ List<KeyValuePair<string, string>> errorMessages = SelectedItem.Validate(Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 18), Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 27));
+ List<KeyValuePair<string, string>> list = errorMessages;
+ list.AddRange(await Validate());
+ if (errorMessages.Count > 0)
+ {
+ return errorMessages;
+ }
+ Item selectedItem2 = SelectedItem;
+ selectedItem2.Coberturas = await CoberturaViewModel.LimpaCoberturas();
+ string acao = ((((DomainBase)SelectedItem).Id == 0L) ? "INCLUIU" : "ALTEROU");
+ string status = ((SelectedItem.Documento.Ordem <= 0) ? "" : (base.Mantido ? $"ITEM ALTERADO NO ENDOSSO ORDEM {SelectedItem.Documento.Ordem}" : ((base.ItemSubstituido != null) ? $"SUBSTITUIÇÃO DO ITEM {base.ItemSubstituido.Ordem} NO ENDOSSO ORDEM {SelectedItem.Documento.Ordem}" : $"ITEM INCLUÍDO NO ENDOSSO ORDEM {SelectedItem.Documento.Ordem}")));
+ if (((DomainBase)SelectedItem).Id == 0L)
+ {
+ SelectedItem.Status = status;
+ }
+ SelectedItem = await _itemServico.Save(SelectedItem);
+ if (!_itemServico.Sucesso)
+ {
+ return null;
+ }
+ if (base.ItemSubstituido != null)
+ {
+ string descricao = (base.Mantido ? $"ITEM ALTERADO NO ENDOSSO ORDEM {SelectedItem.Documento.Ordem}" : $"ITEM SUBSTITUIDO NO ENDOSSO ORDEM {SelectedItem.Documento.Ordem}");
+ await _itemServico.Substituir(base.ItemSubstituido, ((DomainBase)SelectedItem).Id, descricao);
+ }
+ base.Mantido = false;
+ await SelecionaItem(SelectedItem, registrar: false);
+ ItemSelecionado = SelectedItem;
+ if (Invoke)
+ {
+ ConsultaViewModel.ItemSelecionado = SelectedItem;
+ }
+ ToggleSnackBar(Ramo.Nome + " SALVO COM SUCESSO");
+ RegistrarAcao(acao + " ITEM DE DESCRIÇÃO \"" + SelectedItem.Descricao + "\"", ((DomainBase)SelectedItem).Id, (TipoTela)3, $"ID ITEM: {((DomainBase)SelectedItem).Id}\nID DOCUMENTO: {((DomainBase)SelectedItem.Documento).Id}\nRAMO: {SelectedItem.Documento.Controle.Ramo.Nome}\nCLIENTE: {SelectedItem.Documento.Controle.Cliente.Nome}\nID CLIENTE: {((DomainBase)SelectedItem.Documento.Controle.Cliente).Id}");
+ Alterar(alterar: false);
+ return null;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> SalvarRange(IEnumerable<Item> list)
+ {
+ Item ultimoItem = new Item();
+ List<KeyValuePair<string, string>> erros = new List<KeyValuePair<string, string>>();
+ int ordeminicial = await QuantidadeDeItens(((DomainBase)list.First().Documento.Controle).Id);
+ foreach (Item item in list)
+ {
+ if (!item.Auto.Isencao.HasValue)
+ {
+ item.Auto.Isencao = (Isencao)0;
+ }
+ if (!item.Auto.ZeroKm.HasValue)
+ {
+ item.Auto.ZeroKm = false;
+ }
+ if (!item.Auto.Financiado.HasValue)
+ {
+ item.Auto.Financiado = false;
+ }
+ if (!item.Auto.UsoVeiculo.HasValue)
+ {
+ item.Auto.UsoVeiculo = (UsoVeiculo)0;
+ }
+ item.Ordem = ordeminicial;
+ ordeminicial++;
+ item.Auto.Item = item;
+ item.Auto.Placa = ((!string.IsNullOrEmpty(item.Auto.Placa)) ? ValidationHelper.FormataPlaca(item.Auto.Placa) : string.Empty);
+ Item obj = item;
+ string[] array = new string[7];
+ Fabricante fabricante = item.Auto.Fabricante;
+ array[0] = ((fabricante != null) ? fabricante.Descricao : null);
+ array[1] = " ";
+ array[2] = item.Auto.Modelo;
+ array[3] = " / ";
+ array[4] = item.Auto.Chassi;
+ array[5] = " / ";
+ array[6] = item.Auto.Placa;
+ obj.Descricao = string.Concat(array);
+ List<KeyValuePair<string, string>> errorMessages = item.Validate(Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 18), false);
+ List<KeyValuePair<string, string>> list2 = errorMessages;
+ list2.AddRange(await Validate(item));
+ item.Status = ((item.Documento.Ordem > 0) ? $"ITEM INCLUÍDO NO ENDOSSO ORDEM {item.Documento.Ordem}" : "");
+ if (errorMessages.Count > 0)
+ {
+ erros.Add(new KeyValuePair<string, string>("", item.Descricao));
+ erros.AddRange(errorMessages);
+ }
+ }
+ if (erros.Count > 0)
+ {
+ return erros;
+ }
+ foreach (Item item in list)
+ {
+ string acao = ((((DomainBase)item).Id == 0L) ? "INCLUIU" : "ALTEROU");
+ ultimoItem = await _itemServico.Save(item);
+ RegistrarAcao(acao + " ITEM DE DESCRIÇÃO \"" + item.Descricao + "\"", ((DomainBase)item).Id, (TipoTela)3, $"ID ITEM: {((DomainBase)item).Id}\nID DOCUMENTO: {((DomainBase)item.Documento).Id}\nRAMO: {item.Documento.Controle.Ramo.Nome}\nCLIENTE: {item.Documento.Controle.Cliente.Nome}\nID CLIENTE: {((DomainBase)item.Documento.Controle.Cliente).Id}");
+ }
+ SelectedItem = ultimoItem;
+ await SelecionaItem(SelectedItem, registrar: false);
+ ItemSelecionado = SelectedItem;
+ if (Invoke)
+ {
+ ConsultaViewModel.ItemSelecionado = SelectedItem;
+ }
+ ToggleSnackBar("ITENS SALVOS COM SUCESSO");
+ Alterar(alterar: false);
+ return null;
+ }
+
+ public async Task<bool> Excluir()
+ {
+ if (SelectedItem == null || ((DomainBase)SelectedItem).Id == 0L)
+ {
+ return false;
+ }
+ if (!(await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO")))
+ {
+ return false;
+ }
+ Loading(isLoading: true);
+ bool num = await _servico.Delete(SelectedItem);
+ Loading(isLoading: false);
+ if (!num)
+ {
+ await ShowMessage("NÃO POSSÍVEL EXCLUIR O ITEM");
+ return false;
+ }
+ RegistrarAcao("EXCLUIU ITEM DE DESCRIÇÃO \"" + SelectedItem.Descricao + "\"", ((DomainBase)SelectedItem).Id, (TipoTela)3, $"ID ITEM: {((DomainBase)SelectedItem).Id}\nID DOCUMENTO: {((DomainBase)SelectedItem.Documento).Id}\nRAMO: {SelectedItem.Documento.Controle.Ramo.Nome}\nCLIENTE: {SelectedItem.Documento.Controle.Cliente.Nome}\nID CLIENTE: {((DomainBase)SelectedItem.Documento.Controle.Cliente).Id}");
+ ToggleSnackBar(Ramo.Nome + " EXCLUÍDO COM SUCESSO");
+ return true;
+ }
+
+ public async Task<Fipe> BuscaModelo(string fipe)
+ {
+ return await _itemServico.BuscarModelo(fipe);
+ }
+
+ public async Task Incluir(bool substituir = false)
+ {
+ List<Cobertura> coberturas = ((CoberturaViewModel.Coberturas == null) ? CoberturaViewModel.CarregaCoberturaPadrao().ToList() : CoberturaViewModel.Coberturas.ToList());
+ Item val = new Item();
+ val.Documento = ItemSelecionado.Documento;
+ Item val2 = val;
+ int? ordem = (substituir ? base.ItemSubstituido.Ordem : new int?(await QuantidadeDeItens(((DomainBase)ItemSelecionado.Documento.Controle).Id)));
+ val2.Ordem = ordem;
+ val.Auto = new Auto
+ {
+ Isencao = (Isencao)0,
+ ZeroKm = false,
+ Financiado = false,
+ UsoVeiculo = (UsoVeiculo)0,
+ Categoria = (Categoria)3
+ };
+ val.Substituicao = (substituir ? new long?(((DomainBase)base.ItemSubstituido).Id) : null);
+ Item item = val;
+ bool flag = substituir;
+ if (flag)
+ {
+ flag = await ShowMessage("DESEJA COPIAR OS DADOS DO ITEM?", "SIM", "NÃO");
+ }
+ if (flag)
+ {
+ ((DomainBase)SelectedItem).Id = 0L;
+ ((DomainBase)SelectedItem.Auto).Id = 0L;
+ Item selectedItem = SelectedItem;
+ Item itemSubstituido = base.ItemSubstituido;
+ selectedItem.Substituicao = ((itemSubstituido != null) ? new long?(((DomainBase)itemSubstituido).Id) : null);
+ SelectedItem.Documento = ItemSelecionado.Documento;
+ }
+ else
+ {
+ SelectedItem = item;
+ SelectedItem.Auto.Item = item;
+ UsoVeiculo = SelectedItem.Auto.UsoVeiculo;
+ Categoria = SelectedItem.Auto.Categoria;
+ }
+ if (item.Ordem.GetValueOrDefault() == 2 && !substituir && !(await ShowMessage("ESTA APÓLICE SERÁ UMA FROTA, DESEJA CONTINUAR?", "SIM", "NÃO")))
+ {
+ return;
+ }
+ flag = item.Ordem > 1;
+ if (flag)
+ {
+ flag = await ShowMessage("DESEJA REPLICAR AS COBERTURAS DO ITEM SELECIONADO?", "SIM", "NÃO");
+ }
+ if (flag)
+ {
+ CoberturaViewModel.Coberturas = new ObservableCollection<Cobertura>();
+ coberturas.ForEach(delegate(Cobertura x)
+ {
+ x.Item = SelectedItem;
+ CoberturaViewModel.Coberturas.Add(x);
+ });
+ }
+ else
+ {
+ CoberturaViewModel.CarregaPadrao();
+ }
+ if (substituir)
+ {
+ CoberturaViewModel.Coberturas = new ObservableCollection<Cobertura>();
+ coberturas.ForEach(delegate(Cobertura x)
+ {
+ x.Item = SelectedItem;
+ CoberturaViewModel.Coberturas.Add(x);
+ });
+ }
+ Alterar(alterar: true);
+ }
+
+ public void Manter(ManutencaoItem manutencao)
+ {
+ //IL_0077: Unknown result type (might be due to invalid IL or missing references)
+ List<Cobertura> obj = CoberturaViewModel.Coberturas?.ToList();
+ ((DomainBase)SelectedItem).Id = 0L;
+ ((DomainBase)SelectedItem.Auto).Id = 0L;
+ Item selectedItem = SelectedItem;
+ Item itemSubstituido = base.ItemSubstituido;
+ selectedItem.Substituicao = ((itemSubstituido != null) ? new long?(((DomainBase)itemSubstituido).Id) : null);
+ SelectedItem.Documento = ItemSelecionado.Documento;
+ if ((int)manutencao.Tipo == 0)
+ {
+ SelectedItem.Sinistrado = false;
+ SelectedItem.Status = "";
+ SelectedItem.Sinistro = null;
+ SelectedItem.Sinistros = null;
+ }
+ CoberturaViewModel.CarregaPadrao();
+ CoberturaViewModel.Coberturas = new ObservableCollection<Cobertura>();
+ obj?.ForEach(delegate(Cobertura x)
+ {
+ x.Item = SelectedItem;
+ CoberturaViewModel.Coberturas.Add(x);
+ });
+ Alterar(alterar: true);
+ }
+
+ public async void CancelarAlteracao()
+ {
+ Loading(isLoading: true);
+ await SelecionaItem(ItemSelecionado, registrar: false);
+ await CoberturaViewModel.CancelarAlteracao();
+ Alterar(alterar: false);
+ Loading(isLoading: false);
+ }
+
+ public void Dispose()
+ {
+ Gestor.Application.Actions.Actions.UpdateItem = (Action<Item>)Delegate.Remove(Gestor.Application.Actions.Actions.UpdateItem, new Action<Item>(Seleciona));
+ Gestor.Application.Actions.Actions.SubstituirItem = (Action<Item>)Delegate.Remove(Gestor.Application.Actions.Actions.SubstituirItem, new Action<Item>(Substituir));
+ Gestor.Application.Actions.Actions.ManterItem = (Action<Item, ManutencaoItem>)Delegate.Remove(Gestor.Application.Actions.Actions.ManterItem, new Action<Item, ManutencaoItem>(Manter));
+ }
+
+ public void Atualiza(string valorSelecionado)
+ {
+ if (valorSelecionado == "MERCADO")
+ {
+ IsVisiblePorcentagemReferencia = (Visibility)0;
+ IsVisibleValorDeterminado = (Visibility)2;
+ }
+ else
+ {
+ IsVisiblePorcentagemReferencia = (Visibility)2;
+ IsVisibleValorDeterminado = (Visibility)0;
+ }
+ }
+
+ public async void BaixarXls()
+ {
+ FolderBrowserDialog fbd = new FolderBrowserDialog();
+ try
+ {
+ fbd.SelectedPath = Environment.SpecialFolder.Desktop.ToString();
+ if ((int)((CommonDialog)fbd).ShowDialog() == 1 && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
+ {
+ XLWorkbook val = new XLWorkbook();
+ DataTable dataTable = new DataTable();
+ List<string> list = new List<string>
+ {
+ "placa", "fabricante", "modelo", "fipe", "chassi", "anofabricacao", "anomodelo", "cor", "categoria", "combustivel",
+ "zerokm", "renavam", "capacidade", "portas", "bonus", "ceppernoite", "ci", "financiado", "correcao", "isencao",
+ "pcd", "cepcirculacao", "tipocobertura", "porcentagemreferencia", "tabelareferencia", "valordeterminado", "observacao", "pr casco", "fr casco", "lmi casco",
+ "obs casco", "pr dm", "fr dm", "lmi dm", "obs dm", "pr dc", "fr dc", "lmi dc", "obs dc", "pr morte",
+ "fr morte", "lmi morte", "obs morte", "pr invalidez", "fr invalidez", "lmi invalidez", "obs invalidez", "pr carro reserva", "fr carro reserva", "lmi carro reserva",
+ "obs carro reserva", "pr vidros", "fr vidros", "lmi vidros", "obs vidros", "pr carroceria", "fr carroceria", "lmi carroceria", "obs carroceria", "pr Ass 24Horas",
+ "fr Ass 24Horas", "lmi Ass 24Horas", "obs Ass 24Horas", "pr Danos Morais", "fr Danos Morais", "lmi Danos Morais", "obs Danos Morais", "pr app", "fr app", "lmi app",
+ "obs app", "pr equipamentos", "fr equipamentos", "lmi equipamentos", "obs equipamentos"
+ };
+ List<List<string>> list2 = new List<List<string>>
+ {
+ new List<string>
+ {
+ "XXX0X00", "FORD", "MODELO", "000000-0", "75F 8C33MP Y2 W12900", "2000", "2001", "PRETO", "PASSEIO", "FLEX",
+ "SIM", "00000000000", "5", "5", "100", "00.000-000", "000000", "NÃO", "MERCADO", "SEM",
+ "NÃO", "00.000-000", "COMPREENSIVA", "100", "FIPE", "", "OBSERVAÇÕES", "1000", "2000", "3000",
+ "teste obs", "", "", "", "", "2000", "3000", "4000", "teste obs", "100000",
+ "200000", "300000", "teste obs", "2000", "3000", "4000", "teste obs", "", "", "",
+ "", "1000", "2000", "3000", "teste obs", "2000", "3000", "4000", "teste obs", "",
+ "", "", "", "1000", "2000", "3000", "teste obs", "", "", "",
+ "", "2000", "3000", "4000", "teste obs", "1000", "2000", "3000", "teste obs"
+ },
+ new List<string>
+ {
+ "XXX0X01", "CHEVROLET", "MODELO", "000000-1", "4EL ZBE75H B5 A65693", "2000", "2001", "VERDE", "PICKUP", "GASOLINA/ÁLCOOL/GNV",
+ "NÃO", "00000000000", "5", "2", "100", "00.000-000", "000000", "SIM", "DETERMINADO", "IPI E ICMS",
+ "NÃO", "00.000-000", "INCÊNDIO E ROUBO/FURTO", "100", "MOLICAR", "19767,34", "OBSERVAÇÕES", "1000", "2000", "3000",
+ "teste obs", "", "", "", "", "2000", "3000", "4000", "teste obs", "100000",
+ "200000", "300000", "teste obs", "2000", "3000", "4000", "teste obs", "", "", "",
+ "", "1000", "2000", "3000", "teste obs", "2000", "3000", "4000", "teste obs", "",
+ "", "", "", "1000", "2000", "3000", "teste obs", "", "", "",
+ "", "2000", "3000", "4000", "teste obs", "1000", "2000", "3000", "teste obs"
+ }
+ };
+ List<string> list3 = new List<string>
+ {
+ "BRANCO", "CINZA", "PRATA", "VERMELHO", "AMARELO", "OURO", "LARANJA", "ROSA", "VERDE", "AZUL",
+ "VINHO", "MARROM", "BEGE", "DOURADO", "OUTROS"
+ };
+ List<string> list4 = new List<string>
+ {
+ "PICKUP", "OUTROS", "PASSEIO", "CAMINHÃO", "CAMINHONETE", "ÔNIBUS", "UTILITÁRIO", "CARGA", "MOTOCICLETA", "TAXI",
+ "UBER", "REBOCADOR", "REBOQUE/SEMI REBOQUE"
+ };
+ List<string> list5 = new List<string>
+ {
+ "ÁLCOOL", "GASOLINA", "DIESEL", "FLEX", "GNV", "OUTROS", "GASOLINA/GNV", "GASOLINA/ÁLCOOL/GNV", "GASOLINA/ELÉTRICO", "HÍBRIDO",
+ "ELÉTRICO", "GASOLINA/ÁLCOOL/ELÉTRICO"
+ };
+ List<string> list6 = new List<string> { "MERCADO", "DETERMINADO" };
+ List<string> list7 = new List<string> { "SEM ISENÇÃO", "ICMS", "IPI", "IPI E ICMS" };
+ List<string> list8 = new List<string> { "COMPREENSIVA", "INCÊNDIO E ROUBO/FURTO", "DANOS A TERCEIROS", "PASSAGEIROS", "ROUBO/FURTO" };
+ List<string> list9 = new List<string> { "MOLICAR", "FIPE" };
+ List<string> list10 = new List<string> { "SIM", "NÃO" };
+ foreach (string item in list)
+ {
+ DataColumn column = new DataColumn
+ {
+ DataType = Type.GetType("System.String"),
+ ColumnName = item
+ };
+ dataTable.Columns.Add(column);
+ }
+ foreach (List<string> item2 in list2)
+ {
+ DataRow dataRow = dataTable.NewRow();
+ foreach (string item3 in list)
+ {
+ dataRow[item3] = item2[list.IndexOf(item3)];
+ }
+ dataTable.Rows.Add(dataRow);
+ }
+ val.Worksheets.Add(dataTable, "EXEMPLO AUTO EXCEL");
+ val.SaveAs(fbd.SelectedPath + "\\EXEMPLO AUTO EXCEL.xlsx");
+ val = new XLWorkbook();
+ dataTable = new DataTable();
+ foreach (string item4 in list)
+ {
+ DataColumn column2 = new DataColumn
+ {
+ DataType = Type.GetType("System.String"),
+ ColumnName = item4
+ };
+ dataTable.Columns.Add(column2);
+ }
+ foreach (string item5 in list3)
+ {
+ DataRow dataRow2 = dataTable.NewRow();
+ foreach (string item6 in list)
+ {
+ int num = list3.IndexOf(item5);
+ switch (item6)
+ {
+ case "cor":
+ dataRow2[item6] = ((list3.Count >= num + 1) ? list3[num] : "");
+ break;
+ case "categoria":
+ dataRow2[item6] = ((list4.Count >= num + 1) ? list4[num] : "");
+ break;
+ case "combustivel":
+ dataRow2[item6] = ((list5.Count >= num + 1) ? list5[num] : "");
+ break;
+ case "correcao":
+ dataRow2[item6] = ((list6.Count >= num + 1) ? list6[num] : "");
+ break;
+ case "isencao":
+ dataRow2[item6] = ((list7.Count >= num + 1) ? list7[num] : "");
+ break;
+ case "tipocobertura":
+ dataRow2[item6] = ((list8.Count >= num + 1) ? list8[num] : "");
+ break;
+ case "tabelareferencia":
+ dataRow2[item6] = ((list9.Count >= num + 1) ? list9[num] : "");
+ break;
+ case "pcd":
+ case "zerokm":
+ case "financiado":
+ dataRow2[item6] = ((list10.Count >= num + 1) ? list10[num] : "");
+ break;
+ case "placa":
+ dataRow2[item6] = ((num == 0) ? "XXX0X00" : "");
+ break;
+ case "fabricante":
+ dataRow2[item6] = ((num == 0) ? "FABRICANTE" : "");
+ break;
+ case "modelo":
+ dataRow2[item6] = ((num == 0) ? "MODELO" : "");
+ break;
+ case "fipe":
+ dataRow2[item6] = ((num == 0) ? "000000-0" : "");
+ break;
+ case "chassi":
+ dataRow2[item6] = ((num == 0) ? "XXX XXXXXX XX XXXXXX" : "");
+ break;
+ case "anofabricacao":
+ dataRow2[item6] = ((num == 0) ? "0000" : "");
+ break;
+ case "anomodelo":
+ dataRow2[item6] = ((num == 0) ? "0000" : "");
+ break;
+ case "renavam":
+ dataRow2[item6] = ((num == 0) ? "00000000000" : "");
+ break;
+ case "capacidade":
+ dataRow2[item6] = ((num == 0) ? "000" : "");
+ break;
+ case "portas":
+ dataRow2[item6] = ((num == 0) ? "00" : "");
+ break;
+ case "bonus":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "ceppernoite":
+ dataRow2[item6] = ((num == 0) ? "00.000-000" : "");
+ break;
+ case "ci":
+ dataRow2[item6] = ((num == 0) ? "000000" : "");
+ break;
+ case "cepcirculacao":
+ dataRow2[item6] = ((num == 0) ? "00.000-000" : "");
+ break;
+ case "porcentagemreferencia":
+ dataRow2[item6] = ((num == 0) ? "000" : "");
+ break;
+ case "valordeterminado":
+ dataRow2[item6] = ((num == 0) ? "000000" : "");
+ break;
+ case "observacao":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÕES" : "");
+ break;
+ case "pr casco":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr casco":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi casco":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs casco":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr dm":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr dm":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi dm":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs dm":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr dc":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr dc":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi dc":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs dc":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr morte":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr morte":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi morte":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs morte":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr invalidez":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr invalidez":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi invalidez":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs invalidez":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr carro reserva":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr carro reserva":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi carro reserva":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs carro reserva":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr vidros":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr vidros":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi vidros":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs vidros":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr carroceria":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr carroceria":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi carroceria":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs carroceria":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr Ass 24Horas":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr Ass 24Horas":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi Ass 24Horas":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs Ass 24Horas":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr Danos Morais":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr Danos Morais":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi Danos Morais":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs Danos Morais":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr app":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr app":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi app":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs app":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ case "pr equipamentos":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "fr equipamentos":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "lmi equipamentos":
+ dataRow2[item6] = ((num == 0) ? "0" : "");
+ break;
+ case "obs equipamentos":
+ dataRow2[item6] = ((num == 0) ? "OBSERVAÇÃO" : "");
+ break;
+ }
+ }
+ dataTable.Rows.Add(dataRow2);
+ }
+ val.Worksheets.Add(dataTable, "VALORES PERMITIDOS AUTO EXCEL");
+ val.SaveAs(fbd.SelectedPath + "\\VALORES PERMITIDOS AUTO EXCEL.xlsx");
+ }
+ await ShowMessage("\"EXEMPLO AUTO EXCEL.xlsx\" E \"VALORES PERMITIDOS AUTO EXCEL.xlsx\"\nFORAM SALVOS EM \"" + fbd.SelectedPath + "\"");
+ }
+ finally
+ {
+ ((IDisposable)fbd)?.Dispose();
+ }
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> ImportarXls()
+ {
+ List<KeyValuePair<string, string>> erros = new List<KeyValuePair<string, string>>();
+ OpenFileDialog val = new OpenFileDialog();
+ string path;
+ try
+ {
+ ((FileDialog)val).Filter = "Excel|*.xls;*.xlsx";
+ ((FileDialog)val).InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
+ if (1 != (int)((CommonDialog)val).ShowDialog())
+ {
+ erros.Add(new KeyValuePair<string, string>("EXCEL", "ERRO AO SELECIONAR DOCUMENTO"));
+ return erros;
+ }
+ path = ((FileDialog)val).FileName;
+ }
+ finally
+ {
+ ((IDisposable)val)?.Dispose();
+ }
+ try
+ {
+ List<Task<Item>> list = await Task.Run(delegate
+ {
+ Microsoft.Office.Interop.Excel.Application application = (Microsoft.Office.Interop.Excel.Application)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("00024500-0000-0000-C000-000000000046")));
+ Workbook workbook = application.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
+ new List<string>
+ {
+ "placa", "fabricante", "modelo", "fipe", "chassi", "anofabricacao", "anomodelo", "cor", "categoria", "combustivel",
+ "zerokm", "renavam", "capacidade", "portas", "bonus", "ceppernoite", "ci", "financiado", "correcao", "isencao",
+ "pcd", "cepcirculacao", "tipocobertura", "porcentagemreferencia", "tabelareferencia", "valordeterminado", "observacao", "usoveiculos"
+ };
+ List<DataTable> list2 = new List<DataTable>();
+ foreach (object worksheet in workbook.Worksheets)
+ {
+ DataTable dataTable = new DataTable();
+ Microsoft.Office.Interop.Excel.Range usedRange = ((Worksheet)worksheet).UsedRange;
+ object[,] array = (dynamic)usedRange.Value2;
+ int num = 0;
+ for (int i = 0; i <= usedRange.Columns.Count - 1; i++)
+ {
+ if (array[1, i + 1] == null)
+ {
+ num--;
+ }
+ else
+ {
+ DataColumn column = new DataColumn
+ {
+ DataType = Type.GetType("System.String"),
+ ColumnName = Funcoes.RemoverAcentos(array[1, i + 1].ToString().ToLower())
+ };
+ dataTable.Columns.Add(column);
+ for (int j = 0; j <= usedRange.Rows.Count - 2; j++)
+ {
+ object obj = array[j + 2, i + 1];
+ string value = ((obj is string text) ? Funcoes.RemoverAcentos(text).ToUpper() : ((!(obj is double num2)) ? ((!(obj is bool)) ? "" : (((bool)obj) ? "1" : "0")) : ((!num2.ToString(CultureInfo.InvariantCulture).Contains("+")) ? num2.ToString(CultureInfo.InvariantCulture) : ".")));
+ if (i + num == 0)
+ {
+ dataTable.Rows.Add(dataTable.NewRow());
+ dataTable.Rows[j][i + num] = value;
+ }
+ else
+ {
+ dataTable.Rows[j][i + num] = value;
+ }
+ }
+ }
+ }
+ list2.Add(dataTable);
+ }
+ application.Quit();
+ List<Task<Item>> list3 = new List<Task<Item>>();
+ foreach (DataTable dt in list2)
+ {
+ for (int num3 = dt.Rows.Count - 1; num3 >= 0; num3--)
+ {
+ if (dt.Rows[num3].ItemArray.All((object item) => string.IsNullOrEmpty(item?.ToString())))
+ {
+ dt.Rows.RemoveAt(num3);
+ }
+ }
+ list3.AddRange(((IEnumerable<DataRow>)dt.AsEnumerable().ToList()).Select((Func<DataRow, Task<Item>>)async delegate(DataRow x)
+ {
+ Item val2 = new Item();
+ Item val3 = val2;
+ Auto val4 = new Auto();
+ val4.Placa = ((!dt.Columns.Contains("placa") || string.IsNullOrWhiteSpace(x.Field<object>("placa").ToString())) ? null : x.Field<object>("placa").ToString().ToUpper());
+ val4.AnoFabricacao = ((!dt.Columns.Contains("anofabricacao") || string.IsNullOrWhiteSpace(x.Field<object>("anofabricacao").ToString())) ? null : new Regex("[^0-9]").Replace(x.Field<object>("anofabricacao").ToString(), ""));
+ val4.AnoModelo = ((!dt.Columns.Contains("anomodelo") || string.IsNullOrWhiteSpace(x.Field<object>("anomodelo").ToString())) ? null : new Regex("[^0-9]").Replace(x.Field<object>("anomodelo").ToString(), ""));
+ val4.Bonus = ((!dt.Columns.Contains("bonus") || string.IsNullOrWhiteSpace(x.Field<object>("bonus").ToString())) ? null : new int?(int.Parse(new Regex("[^0-9]").Replace(x.Field<object>("bonus").ToString(), ""))));
+ val4.Capacidade = ((!dt.Columns.Contains("capacidade") || string.IsNullOrWhiteSpace(x.Field<object>("capacidade").ToString())) ? null : new Regex("[^0-9]").Replace(x.Field<object>("capacidade").ToString(), ""));
+ val4.CepPernoite = ((!dt.Columns.Contains("ceppernoite") || string.IsNullOrWhiteSpace(x.Field<object>("ceppernoite").ToString())) ? ValidationHelper.FormatPostCode(new Regex("[^0-9]").Replace(x.Field<object>("cepcirculacao").ToString(), "")) : ValidationHelper.FormatPostCode(new Regex("[^0-9]").Replace(x.Field<object>("ceppernoite").ToString(), "")));
+ val4.Chassi = ((!dt.Columns.Contains("chassi") || string.IsNullOrWhiteSpace(x.Field<object>("chassi").ToString())) ? null : x.Field<object>("chassi").ToString());
+ val4.Ci = ((!dt.Columns.Contains("ci") || string.IsNullOrWhiteSpace(x.Field<object>("ci").ToString())) ? null : new Regex("[^0-9]").Replace(x.Field<object>("ci").ToString(), ""));
+ val4.Observacao = ((!dt.Columns.Contains("observacao") || string.IsNullOrWhiteSpace(x.Field<object>("observacao").ToString())) ? null : x.Field<object>("observacao").ToString());
+ val4.Cor = ((!dt.Columns.Contains("cor") || string.IsNullOrWhiteSpace(x.Field<object>("cor").ToString())) ? null : Funcoes.GetCor(x.Field<object>("cor").ToString().ToLower()));
+ val4.Financiado = ((!dt.Columns.Contains("financiado") || string.IsNullOrWhiteSpace(x.Field<object>("financiado").ToString())) ? null : new bool?(x.Field<object>("financiado").ToString().ToLower() == "sim"));
+ val4.ZeroKm = ((!dt.Columns.Contains("zerokm") || string.IsNullOrWhiteSpace(x.Field<object>("zerokm").ToString())) ? null : new bool?(x.Field<object>("zerokm").ToString().ToLower() == "sim"));
+ val4.Combustivel = ((!dt.Columns.Contains("combustivel") || string.IsNullOrWhiteSpace(x.Field<object>("combustivel").ToString())) ? null : Funcoes.GetCombustivel(x.Field<object>("combustivel").ToString().ToLower()));
+ val4.Correcao = ((!dt.Columns.Contains("correcao") || string.IsNullOrWhiteSpace(x.Field<object>("correcao").ToString())) ? null : Funcoes.GetCorrecao(x.Field<object>("correcao").ToString().ToLower()));
+ Auto val5 = val4;
+ Fabricante fabricante = ((dt.Columns.Contains("fabricante") && !string.IsNullOrWhiteSpace(x.Field<object>("fabricante").ToString())) ? (await Funcoes.GetFabricante(x.Field<object>("fabricante").ToString().ToLower())) : null);
+ val5.Fabricante = fabricante;
+ val4.Fipe = ((!dt.Columns.Contains("fipe") || string.IsNullOrWhiteSpace(x.Field<object>("fipe").ToString())) ? null : ValidationHelper.FormataFipe(new Regex("[^0-9]").Replace(x.Field<object>("fipe").ToString(), "")));
+ val4.Isencao = ((!dt.Columns.Contains("isencao") || string.IsNullOrWhiteSpace(x.Field<object>("isencao").ToString())) ? null : Funcoes.GetIsencao(x.Field<object>("isencao").ToString().ToLower()));
+ val4.Modelo = ((!dt.Columns.Contains("modelo") || string.IsNullOrWhiteSpace(x.Field<object>("modelo").ToString())) ? null : x.Field<object>("modelo").ToString());
+ val4.Pcd = ((!dt.Columns.Contains("pcd") || string.IsNullOrWhiteSpace(x.Field<object>("pcd").ToString())) ? null : new bool?(x.Field<object>("pcd").ToString().ToLower() == "sim"));
+ val4.PorcentagemReferencia = ((!dt.Columns.Contains("porcentagemreferencia") || string.IsNullOrWhiteSpace(x.Field<object>("porcentagemreferencia").ToString())) ? 0m : (decimal.TryParse(x.Field<object>("porcentagemreferencia").ToString(), out var _) ? decimal.Parse(x.Field<object>("porcentagemreferencia").ToString()) : 0m));
+ val4.Portas = ((!dt.Columns.Contains("portas") || string.IsNullOrWhiteSpace(x.Field<object>("portas").ToString())) ? null : new Regex("[^0-9]").Replace(x.Field<object>("portas").ToString(), ""));
+ val4.RegiaoCirculacao = ((!dt.Columns.Contains("cepcirculacao") || string.IsNullOrWhiteSpace(x.Field<object>("cepcirculacao").ToString())) ? null : ValidationHelper.FormatPostCode(new Regex("[^0-9]").Replace(x.Field<object>("cepcirculacao").ToString(), "")));
+ val4.Renavam = ((!dt.Columns.Contains("renavam") || string.IsNullOrWhiteSpace(x.Field<object>("renavam").ToString())) ? null : new Regex("[^0-9]").Replace(x.Field<object>("renavam").ToString(), ""));
+ val4.TabelaReferencia = ((!dt.Columns.Contains("tabelareferencia") || string.IsNullOrWhiteSpace(x.Field<object>("tabelareferencia").ToString())) ? null : Funcoes.GetTabelaReferencia(x.Field<object>("tabelareferencia").ToString().ToLower()));
+ val4.TipoCobertura = ((!dt.Columns.Contains("tipocobertura") || string.IsNullOrWhiteSpace(x.Field<object>("tipocobertura").ToString())) ? null : Funcoes.GetTipoCobertura(x.Field<object>("tipocobertura").ToString().ToLower()));
+ val4.ValorDeterminado = ((!dt.Columns.Contains("valordeterminado") || string.IsNullOrWhiteSpace(x.Field<object>("valordeterminado").ToString()) || !ValidationHelper.ValidateValor(x.Field<object>("valordeterminado").ToString())) ? 0m : decimal.Parse(x.Field<object>("valordeterminado").ToString()));
+ val4.Categoria = ((!dt.Columns.Contains("categoria") || string.IsNullOrWhiteSpace(x.Field<object>("categoria").ToString())) ? null : Funcoes.GetCategoria(x.Field<object>("categoria").ToString().ToLower()));
+ val4.UsoVeiculo = ((!dt.Columns.Contains("usoveiculo") || string.IsNullOrWhiteSpace(x.Field<object>("usoveiculo").ToString())) ? null : Funcoes.GetUsoveiculo(x.Field<object>("usoveiculo").ToString().ToUpper()));
+ val4.KitGas = ((!dt.Columns.Contains("KitGas") || string.IsNullOrWhiteSpace(x.Field<object>("KitGas").ToString())) ? null : new bool?(x.Field<object>("KitGas").ToString().ToLower() == "sim"));
+ val3.Auto = val4;
+ val2.Coberturas = Coberturas(x);
+ val2.Documento = ItemSelecionado.Documento;
+ val2.Substituicao = null;
+ return val2;
+ }).ToList());
+ }
+ return list3;
+ });
+ if (list.Count == 0)
+ {
+ erros.Add(new KeyValuePair<string, string>("EXCEL", "NENHUMA COLUNA FOI ENCONTRADA"));
+ return erros;
+ }
+ erros = await SalvarRange(await Task.WhenAll(list));
+ }
+ catch (Exception)
+ {
+ erros.Add(new KeyValuePair<string, string>("EXCEL", "FALHA AO IMPORTAR O EXCEL,\nVERIFIQUE SE O ARQUIVO POSSUI ALGUM ERRO"));
+ }
+ return erros;
+ }
+
+ public List<Cobertura> Coberturas(DataRow row)
+ {
+ //IL_0478: Unknown result type (might be due to invalid IL or missing references)
+ //IL_047d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_047e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0483: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0491: Expected O, but got Unknown
+ //IL_0491: Unknown result type (might be due to invalid IL or missing references)
+ //IL_04a5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_04ad: Unknown result type (might be due to invalid IL or missing references)
+ //IL_04b5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_04c2: Expected O, but got Unknown
+ List<Cobertura> list = new List<Cobertura>();
+ foreach (DataColumn column in row.Table.Columns)
+ {
+ if (!Regex.IsMatch(column.ColumnName, "pr .+"))
+ {
+ continue;
+ }
+ string value = Regex.Match(column.ColumnName, "pr (.+)").Groups[1].Value;
+ if (!(value != "casco") || !(value != "dm") || !(value != "dc") || !(value != "morte") || !(value != "invalidez") || !(value != "carro reserva") || !(value != "vidros") || !(value != "carroceria") || !(value != "ass 24horas") || !(value != "danos morais") || !(value != "app") || !(value != "equipamentos"))
+ {
+ int num = 0;
+ string text = "";
+ switch (value)
+ {
+ case "casco":
+ num = 1;
+ text = "Veiculo (Casco)";
+ break;
+ case "dm":
+ num = 2;
+ text = "Danos Materiais";
+ break;
+ case "dc":
+ num = 3;
+ text = "Danos Corporais";
+ break;
+ case "morte":
+ num = 4;
+ text = "Morte";
+ break;
+ case "invalidez":
+ num = 5;
+ text = "Invalidez";
+ break;
+ case "carro reserva":
+ num = 7;
+ text = "Carro Reserva";
+ break;
+ case "vidros":
+ num = 6;
+ text = "Vidros";
+ break;
+ case "carroceria":
+ num = 25;
+ text = "Carroceria";
+ break;
+ case "ass 24horas":
+ num = 19;
+ text = "Assistência (Guincho)";
+ break;
+ case "danos morais":
+ num = 17;
+ text = "Danos Morais";
+ break;
+ case "app":
+ num = 53;
+ text = "Acidentes Pessoais";
+ break;
+ case "equipamentos":
+ num = 54;
+ text = "Equipamentos";
+ break;
+ }
+ decimal num2 = (string.IsNullOrWhiteSpace(row.Field<object>("pr " + value).ToString()) ? 0m : ValidationHelper.ToDecimal(row.Field<object>("pr " + value).ToString(), "pt-BR"));
+ decimal num3 = (string.IsNullOrWhiteSpace(row.Field<object>("lmi " + value).ToString()) ? 0m : ValidationHelper.ToDecimal(row.Field<object>("lmi " + value).ToString(), "pt-BR"));
+ decimal num4 = (string.IsNullOrWhiteSpace(row.Field<object>("fr " + value).ToString()) ? 0m : ValidationHelper.ToDecimal(row.Field<object>("fr " + value).ToString(), "pt-BR"));
+ string text2 = (string.IsNullOrWhiteSpace(row.Field<object>("obs " + value).ToString()) ? "" : row.Field<object>("obs " + value).ToString());
+ if (num3 > 0m || num4 > 0m || num2 > 0m)
+ {
+ list.Add(new Cobertura
+ {
+ CoberturaPadrao = new CoberturaPadrao
+ {
+ Id = num
+ },
+ Observacao = text + " - " + text2,
+ Premio = num2,
+ Lmi = num3,
+ Franquia = num4
+ });
+ }
+ }
+ }
+ return list;
+ }
+}