From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../Ferramentas/CadastroEmailViewModel.cs | 362 ------ .../Ferramentas/CadastroParceiroViewModel.cs | 413 ------- .../ViewModels/Ferramentas/ComboModelo.cs | 43 - .../ViewModels/Ferramentas/ComboVariavel.cs | 45 - .../ViewModels/Ferramentas/DownloadViewModel.cs | 550 --------- .../ViewModels/Ferramentas/EmpresaViewModel.cs | 512 --------- .../ViewModels/Ferramentas/EstipulanteViewModel.cs | 380 ------- .../ViewModels/Ferramentas/EtiquetaViewModel.cs | 1163 -------------------- .../ViewModels/Ferramentas/IncluirRamoViewModel.cs | 110 -- .../Ferramentas/IncluirSeguradoraViewModel.cs | 110 -- .../ViewModels/Ferramentas/MalaDiretaViewModel.cs | 821 -------------- .../Ferramentas/ManutencaoPagamentosViewModel.cs | 821 -------------- .../ViewModels/Ferramentas/NotaFiscalViewModel.cs | 482 -------- .../ViewModels/Ferramentas/ProdutoViewModel.cs | 303 ----- .../Ferramentas/ProtocoloDocumentosViewModel.cs | 399 ------- .../ViewModels/Ferramentas/ProtocoloEtiqueta.cs | 26 - .../Ferramentas/QualificacaoViewModel.cs | 122 -- .../ViewModels/Ferramentas/RamoViewModel.cs | 332 ------ .../ViewModels/Ferramentas/ReciboViewModel.cs | 769 ------------- .../ViewModels/Ferramentas/SeguradoraViewModel.cs | 621 ----------- .../ViewModels/Ferramentas/SocioViewModel.cs | 358 ------ .../Ferramentas/StatusProspeccaoViewModel.cs | 326 ------ .../ViewModels/Ferramentas/StatusViewModel.cs | 367 ------ .../ViewModels/Ferramentas/TipoTarefaViewModel.cs | 325 ------ .../Ferramentas/TipoVendedorViewModel.cs | 338 ------ .../ViewModels/Ferramentas/UsuarioViewModel.cs | 826 -------------- .../ViewModels/Ferramentas/VendedorViewModel.cs | 913 --------------- 27 files changed, 11837 deletions(-) delete mode 100644 Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/CadastroParceiroViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/ComboModelo.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/ComboVariavel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/DownloadViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/EtiquetaViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/MalaDiretaViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/ManutencaoPagamentosViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/NotaFiscalViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/ProdutoViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/ProtocoloDocumentosViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/ProtocoloEtiqueta.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/QualificacaoViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/StatusProspeccaoViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/StatusViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/TipoTarefaViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/TipoVendedorViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs delete mode 100644 Gestor.Application/ViewModels/Ferramentas/VendedorViewModel.cs (limited to 'Gestor.Application/ViewModels/Ferramentas') diff --git a/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs deleted file mode 100644 index 2294490..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs +++ /dev/null @@ -1,362 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.Servicos.Ferramentas; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.ViewModels.Generic; -using Gestor.Common.Helpers; -using Gestor.Common.Validation; -using Gestor.Model.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.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class CadastroEmailViewModel : BaseSegurosViewModel - { - private readonly EmailServico _servico; - - public Credencial CancelCredencial; - - private Credencial _selectedCredencial; - - private ObservableCollection _credenciaisFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - public List Credenciais - { - get; - set; - } - - public ObservableCollection CredenciaisFiltrados - { - get - { - return this._credenciaisFiltrados; - } - set - { - this._credenciaisFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("CredenciaisFiltrados"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public Credencial SelectedCredencial - { - get - { - return this._selectedCredencial; - } - set - { - long? nullable; - this._selectedCredencial = value; - this.WorkOnSelectedCredencial(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedCredencial"); - } - } - - public CadastroEmailViewModel() - { - this._servico = new EmailServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public async Task CancelarAlteracao() - { - long id; - await this.CarregarCredenciais(); - if (!this.CredenciaisFiltrados.Any()) - { - this.SelectedCredencial = new Credencial(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - Credencial cancelCredencial = this.CancelCredencial; - if (cancelCredencial != null) - { - id = cancelCredencial.get_Id(); - } - else - { - id = (long)0; - } - long num = id; - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault((Credencial x) => x.get_Id() == num); - } - base.Alterar(false); - } - - private async Task CarregarCredenciais() - { - List credencials = await (new BaseServico()).BuscarCredenciais(); - foreach (Credencial credencial in credencials) - { - if (credencial.get_Email().Contains("@gmail.com")) - { - credencial.set_Tipo(1); - } - credencial.set_Senha(EncryptionHelper.Decrypt(credencial.get_Senha())); - } - CadastroEmailViewModel list = this; - List credencials1 = credencials; - list.Credenciais = ( - from x in credencials1 - orderby x.get_Descricao() - select x).ToList(); - this.CredenciaisFiltrados = new ObservableCollection(this.Credenciais); - } - - public async Task EnviarTesteEmail() - { - bool flag; - if (this.SelectedCredencial != null) - { - TipoEmail tipo = this.SelectedCredencial.get_Tipo(); - if (tipo != null) - { - if (tipo - 1 <= 1) - { - if (string.IsNullOrWhiteSpace(this.SelectedCredencial.get_Email())) - { - await base.ShowMessage("NECESSÁRIO PREENCHER O E-MAIL PARA ENVIAR UM E-MAIL DE TESTE", "OK", "", false); - flag = false; - return flag; - } - } - } - else if (string.IsNullOrWhiteSpace(this.SelectedCredencial.get_Email()) || !this.SelectedCredencial.get_Porta().HasValue || string.IsNullOrWhiteSpace(this.SelectedCredencial.get_Dominio())) - { - await base.ShowMessage("NECESSÁRIO PREENCHER O E-MAIL, PORTA E DOMÍNIO PARA ENVIAR UM E-MAIL DE TESTE", "OK", "", false); - flag = false; - return flag; - } - MailHelper mailHelper = new MailHelper(); - Destinatario destinatario = new Destinatario(); - destinatario.set_Assunto("TESTE ENVIO E-MAIL"); - destinatario.set_Corpo("TESTE DE ENVIO DE E-MAIL"); - destinatario.set_Email(this.SelectedCredencial.get_Email()); - destinatario.set_Nome(this.SelectedCredencial.get_Descricao()); - Destinatario destinatario1 = destinatario; - LogEnvio logEnvio = await mailHelper.SendAsync(this.SelectedCredencial, destinatario1, null, null, 0, false); - if (logEnvio.get_Enviado()) - { - flag = true; - } - else - { - await base.ShowMessage(logEnvio.get_Erro(), "OK", "", false); - flag = false; - } - } - else - { - await base.ShowMessage("NECESSÁRIO CRIAR UM E-MAIL DE ENVIO PARA PROSSEGUIR.", "OK", "", false); - flag = false; - } - return flag; - } - - public async Task Excluir() - { - if (this.SelectedCredencial != null && this.SelectedCredencial.get_Id() != 0) - { - if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR O E-MAIL ", this.SelectedCredencial.get_Email(), " PERMANENTEMENTE?"), "SIM", "NÃO", false)) - { - base.Loading(true); - if (await this._servico.Delete(this.SelectedCredencial)) - { - base.RegistrarAcao(string.Concat("EXCLUIU E-MAIL \"", this.SelectedCredencial.get_Email(), "\""), this.SelectedCredencial.get_Id(), new TipoTela?(17), string.Format("E-MAIL: {0}\nID: {1}", this.SelectedCredencial.get_Email(), this.SelectedCredencial.get_Id())); - await this.CarregarCredenciais(); - if (!this.CredenciaisFiltrados.Any()) - { - this.SelectedCredencial = new Credencial(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault(); - } - base.Loading(false); - base.ToggleSnackBar("E-MAIL EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - internal async Task> Filtrar(string value) - { - List credencials = await Task.Run>(() => this.FiltrarCredenciais(value)); - return credencials; - } - - public List FiltrarCredenciais(string filter) - { - this.CredenciaisFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Credenciais) : new ObservableCollection( - from x in this.Credenciais - where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - select x)); - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault(); - return this.CredenciaisFiltrados.ToList(); - } - - public void Incluir() - { - Credencial credencial = new Credencial(); - credencial.set_IdEmpresa(Recursos.Usuario.get_IdEmpresa()); - credencial.set_IdUsuario(Recursos.Usuario.get_Id()); - this.SelectedCredencial = credencial; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string str1; - List> keyValuePairs1 = this.SelectedCredencial.Validate(); - keyValuePairs1.AddRange(this.Validate()); - if (keyValuePairs1.Count <= 0) - { - this.SelectedCredencial.set_Assinatura(this.SelectedCredencial.get_Assinatura().GetBody()); - this.SelectedCredencial.set_Cabecalho(this.SelectedCredencial.get_Cabecalho().GetBody()); - if (this.SelectedCredencial.get_Senha() == null) - { - this.SelectedCredencial.set_Senha(""); - } - str = (this.SelectedCredencial.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Credencial credencial = await this._servico.Save(this.SelectedCredencial); - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str1, " E-MAIL \"", credencial.get_Email(), "\""), credencial.get_Id(), new TipoTela?(17), string.Format("E-MAIL: {0}\nID: {1}", credencial.get_Email(), credencial.get_Id())); - await this.CarregarCredenciais(); - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault((Credencial x) => x.get_Id() == credencial.get_Id()); - base.Alterar(false); - base.ToggleSnackBar("E-MAIL 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(17); - base.Loading(false); - } - - public async Task SelecionaCredenciais() - { - base.Loading(true); - await this.CarregarCredenciais(); - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault(); - base.Loading(false); - } - - public void SelecionaCredencial(Credencial credencial) - { - this.SelectedCredencial = this.CredenciaisFiltrados.First((Credencial x) => x.get_Id() == credencial.get_Id()); - } - - public List> Validate() - { - List> keyValuePairs = new List>(); - if (this.Credenciais.Any((Credencial x) => { - if (x.get_Id() == this.SelectedCredencial.get_Id()) - { - return false; - } - return x.get_Descricao() == this.SelectedCredencial.get_Descricao(); - })) - { - keyValuePairs.Add(new KeyValuePair("Descricao", "UM E-MAIL COM A MESMA DESCRIÇÃO/NOME JÁ EXISTE.")); - } - return keyValuePairs; - } - - private void WorkOnSelectedCredencial(Credencial value, bool registrar = true) - { - long? nullable; - this.CancelCredencial = (value == null || value.get_Id() == 0 ? this.CancelCredencial : (Credencial)value.Clone()); - if (value == null || value.get_Id() == 0) - { - return; - } - if (this.LastAccessId == value.get_Id() && this.LastAccessTela == 17) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU E-MAIL \"", value.get_Email(), "\""), value.get_Id(), new TipoTela?(17), string.Format("ID E-MAIL: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 17; - Credencial selectedCredencial = this.SelectedCredencial; - if (selectedCredencial != null) - { - nullable = new long?(selectedCredencial.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault((Credencial x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/CadastroParceiroViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/CadastroParceiroViewModel.cs deleted file mode 100644 index 9b8f08c..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/CadastroParceiroViewModel.cs +++ /dev/null @@ -1,413 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.Servicos; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.ViewModels.Generic; -using Gestor.Common.Validation; -using Gestor.Model.Common; -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.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class CadastroParceiroViewModel : BaseSegurosViewModel - { - private readonly ParceiroServico _servico; - - private Parceiro _selectedParceiro; - - private ObservableCollection _parceirosFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - public Parceiro CancelParceiro; - - private Item _selectedItem = new Item(); - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public List Parceiros - { - get; - set; - } - - public ObservableCollection ParceirosFiltrados - { - get - { - return this._parceirosFiltrados; - } - set - { - this._parceirosFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("ParceirosFiltrados"); - } - } - - public Item SelectedItem - { - get - { - return this._selectedItem; - } - set - { - this._selectedItem = value; - base.OnPropertyChanged("SelectedItem"); - } - } - - public Parceiro SelectedParceiro - { - get - { - return this._selectedParceiro; - } - set - { - long? nullable; - this._selectedParceiro = value; - this.WorkOnSelectedParceiro(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedParceiro"); - } - } - - public CadastroParceiroViewModel(Parceiro parceiro) - { - this._servico = new ParceiroServico(); - base.EnableMenu = true; - this.Seleciona(parceiro); - } - - public void CancelarAlteracao() - { - if (this.CancelParceiro == null || !this.Parceiros.Any((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Parceiros.First((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id()), this.CancelParceiro); - if (this.ParceirosFiltrados.Count <= 0 || !this.ParceirosFiltrados.Any((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id())) - { - this.ParceirosFiltrados.Add(this.CancelParceiro); - } - else - { - DomainBase.Copy(this.ParceirosFiltrados.First((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id()), this.CancelParceiro); - } - this.ParceirosFiltrados = new ObservableCollection(this.ParceirosFiltrados); - this.SelecionarParceiro(this.ParceirosFiltrados.First((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id())); - } - base.Alterar(false); - } - - public async void Excluir() - { - string complemento; - Parceiro parceiro; - if (this.SelectedParceiro != null && this.SelectedParceiro.get_Id() != 0) - { - if (await (new BaseServico()).ParceiroUtilizado(this.SelectedParceiro.get_Id())) - { - await base.ShowMessage("PARCEIRO NÃO PODE SER EXCLUÍDO POIS ESTÁ SENDO UTILIZADO.", "OK", "", false); - } - else if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false)) - { - base.Loading(true); - if (await this._servico.Delete(this.SelectedParceiro)) - { - CadastroParceiroViewModel cadastroParceiroViewModel = this; - string str = string.Concat("EXCLUIU O PARCEIRO \"", this.SelectedParceiro.get_Nome(), "\""); - long id = this.SelectedParceiro.get_Id(); - TipoTela? nullable = new TipoTela?(22); - string[] cgccpf = new string[] { "DOCUMENTO: ", this.SelectedParceiro.get_Cgccpf(), "\nTELEFONE 1: (", this.SelectedParceiro.get_Ddd1(), ") ", this.SelectedParceiro.get_Telefone1(), "\nTELEFONE 2: (", this.SelectedParceiro.get_Ddd2(), ") ", this.SelectedParceiro.get_Telefone2(), "\nTELEFONE 3: (", this.SelectedParceiro.get_Ddd3(), ") ", this.SelectedParceiro.get_Telefone3(), "\nE-MAIL: ", this.SelectedParceiro.get_Email(), "\n\nENDEREÇO: ", this.SelectedParceiro.get_Endereco(), ", ", this.SelectedParceiro.get_Numero(), ", ", null, null, null, null, null, null, null, null, null }; - if (string.IsNullOrWhiteSpace(this.SelectedParceiro.get_Complemento())) - { - complemento = "-"; - } - else - { - complemento = this.SelectedParceiro.get_Complemento(); - if (complemento == null) - { - complemento = ""; - } - } - cgccpf[21] = complemento; - cgccpf[22] = ", "; - cgccpf[23] = this.SelectedParceiro.get_Bairro(); - cgccpf[24] = ", "; - cgccpf[25] = this.SelectedParceiro.get_Cidade(); - cgccpf[26] = "/"; - cgccpf[27] = this.SelectedParceiro.get_Uf(); - cgccpf[28] = " - "; - cgccpf[29] = this.SelectedParceiro.get_Cep(); - cadastroParceiroViewModel.RegistrarAcao(str, id, nullable, string.Concat(cgccpf)); - int num = this.ParceirosFiltrados.IndexOf(this.SelectedParceiro); - this.Parceiros.Remove(this.SelectedParceiro); - this.ParceirosFiltrados.Remove(this.SelectedParceiro); - this.ParceirosFiltrados = new ObservableCollection(this.ParceirosFiltrados); - if (this.ParceirosFiltrados.Count <= 0) - { - this.Incluir(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - CadastroParceiroViewModel cadastroParceiroViewModel1 = this; - parceiro = (num < this.ParceirosFiltrados.Count ? this.ParceirosFiltrados.ElementAt(num) : this.ParceirosFiltrados.Last()); - cadastroParceiroViewModel1.SelecionarParceiro(parceiro); - } - base.Loading(false); - base.ToggleSnackBar("PARCEIRO EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - internal async Task> Filtrar(string value) - { - List parceiros = await Task.Run>(() => this.FiltrarParceiro(value)); - return parceiros; - } - - public List FiltrarParceiro(string filter) - { - this.ParceirosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Parceiros) : new ObservableCollection( - from x in this.Parceiros - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - select x)); - return this.ParceirosFiltrados.ToList(); - } - - public void Incluir() - { - this.SelectedParceiro = new Parceiro(); - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string complemento; - string str1; - List> keyValuePairs1 = this.SelectedParceiro.Validate(); - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedParceiro.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Parceiro parceiro = await this._servico.Save(this.SelectedParceiro); - if (this._servico.Sucesso) - { - CadastroParceiroViewModel cadastroParceiroViewModel = this; - string str2 = string.Concat(str1, " PARCEIRO \"", parceiro.get_Nome(), "\""); - long id = parceiro.get_Id(); - TipoTela? nullable = new TipoTela?(22); - string[] cgccpf = new string[] { "DOCUMENTO: ", parceiro.get_Cgccpf(), "\nTELEFONE 1: (", parceiro.get_Ddd1(), ") ", parceiro.get_Telefone1(), "\nTELEFONE 2: (", parceiro.get_Ddd2(), ") ", parceiro.get_Telefone2(), "\nTELEFONE 3: (", parceiro.get_Ddd3(), ") ", parceiro.get_Telefone3(), "\nE-MAIL: ", parceiro.get_Email(), "\n\nENDEREÇO: ", parceiro.get_Endereco(), ", ", parceiro.get_Numero(), ", ", null, null, null, null, null, null, null, null, null }; - if (string.IsNullOrWhiteSpace(parceiro.get_Complemento())) - { - complemento = "-"; - } - else - { - complemento = parceiro.get_Complemento(); - if (complemento == null) - { - complemento = ""; - } - } - cgccpf[21] = complemento; - cgccpf[22] = ", "; - cgccpf[23] = parceiro.get_Bairro(); - cgccpf[24] = ", "; - cgccpf[25] = parceiro.get_Cidade(); - cgccpf[26] = "/"; - cgccpf[27] = parceiro.get_Uf(); - cgccpf[28] = " - "; - cgccpf[29] = parceiro.get_Cep(); - cadastroParceiroViewModel.RegistrarAcao(str2, id, nullable, string.Concat(cgccpf)); - if (!this.Parceiros.Any((Parceiro x) => x.get_Id() == parceiro.get_Id())) - { - this.Parceiros.Add(parceiro); - } - else - { - DomainBase.Copy(this.Parceiros.First((Parceiro x) => x.get_Id() == parceiro.get_Id()), parceiro); - } - if (!this.ParceirosFiltrados.Any((Parceiro x) => x.get_Id() == parceiro.get_Id())) - { - this.ParceirosFiltrados.Add(parceiro); - } - else - { - DomainBase.Copy(this.ParceirosFiltrados.First((Parceiro x) => x.get_Id() == parceiro.get_Id()), parceiro); - } - this.ParceirosFiltrados = new ObservableCollection(this.ParceirosFiltrados); - Recursos.Parceiros = this.Parceiros; - this.WorkOnSelectedParceiro(parceiro, false); - base.Alterar(false); - base.ToggleSnackBar("PARCEIRO SALVO COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - str1 = null; - return keyValuePairs; - } - - private async void Seleciona(Parceiro parceiro) - { - base.Loading(true); - await base.PermissaoTela(22); - await this.SelecionaParceiro(parceiro); - base.Loading(false); - } - - private async Task SelecionaParceiro(Parceiro parceiro = null) - { - base.Loading(true); - List parceiros = await (new BaseServico()).BuscarParceirosAsync(); - CadastroParceiroViewModel list = this; - List parceiros1 = parceiros; - list.Parceiros = ( - from x in parceiros1 - orderby x.get_Nome() - select x).ToList(); - this.ParceirosFiltrados = new ObservableCollection(this.Parceiros); - CadastroParceiroViewModel cadastroParceiroViewModel = this; - Parceiro parceiro1 = parceiro; - if (parceiro1 == null) - { - parceiro1 = this.ParceirosFiltrados.FirstOrDefault(); - } - cadastroParceiroViewModel.SelecionarParceiro(parceiro1); - base.Loading(false); - } - - public async void SelecionarParceiro(Parceiro parceiro) - { - if (parceiro != null) - { - Parceiro parceiro1 = await this._servico.BuscarParceiro(parceiro.get_Id()); - DomainBase.Copy(this.ParceirosFiltrados.First((Parceiro x) => x.get_Id() == parceiro.get_Id()), parceiro1); - this.SelectedParceiro = this.ParceirosFiltrados.First((Parceiro x) => x.get_Id() == parceiro.get_Id()); - } - else - { - this.SelectedParceiro = null; - } - } - - private async void WorkOnSelectedParceiro(Parceiro value, bool registrar = true) - { - Parceiro parceiro; - long? nullable; - string complemento; - CadastroParceiroViewModel cadastroParceiroViewModel = this; - parceiro = (value == null || value.get_Id() == 0 ? this.CancelParceiro : (Parceiro)value.Clone()); - cadastroParceiroViewModel.CancelParceiro = parceiro; - if (value != null && value.get_Id() != 0 && (this.LastAccessId != value.get_Id() || this.LastAccessTela != 22)) - { - if (registrar) - { - CadastroParceiroViewModel cadastroParceiroViewModel1 = this; - string str = string.Concat("ACESSOU PARCEIRO \"", value.get_Nome(), "\""); - long id = value.get_Id(); - TipoTela? nullable1 = new TipoTela?(22); - string[] cgccpf = new string[] { "DOCUMENTO: ", value.get_Cgccpf(), "\nTELEFONE 1: (", value.get_Ddd1(), ") ", value.get_Telefone1(), "\nTELEFONE 2: (", value.get_Ddd2(), ") ", value.get_Telefone2(), "\nTELEFONE 3: (", value.get_Ddd3(), ") ", value.get_Telefone3(), "\nE-MAIL: ", value.get_Email(), "\n\nENDEREÇO: ", value.get_Endereco(), ", ", value.get_Numero(), ", ", null, null, null, null, null, null, null, null, null }; - if (string.IsNullOrWhiteSpace(value.get_Complemento())) - { - complemento = "-"; - } - else - { - complemento = value.get_Complemento(); - if (complemento == null) - { - complemento = ""; - } - } - cgccpf[21] = complemento; - cgccpf[22] = ", "; - cgccpf[23] = value.get_Bairro(); - cgccpf[24] = ", "; - cgccpf[25] = value.get_Cidade(); - cgccpf[26] = "/"; - cgccpf[27] = value.get_Uf(); - cgccpf[28] = " - "; - cgccpf[29] = value.get_Cep(); - cadastroParceiroViewModel1.RegistrarAcao(str, id, nullable1, string.Concat(cgccpf)); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 22; - Parceiro selectedParceiro = this.SelectedParceiro; - if (selectedParceiro != null) - { - nullable = new long?(selectedParceiro.get_Id()); - } - else - { - nullable = null; - } - long? nullable2 = nullable; - long num = value.get_Id(); - if (nullable2.GetValueOrDefault() != num | !nullable2.HasValue) - { - Parceiro parceiro1 = await this._servico.BuscarParceiro(value.get_Id()); - DomainBase.Copy(this.SelectedParceiro, parceiro1); - Parceiro selectedParceiro1 = this.SelectedParceiro; - if (selectedParceiro1 != null) - { - selectedParceiro1.Initialize(); - } - else - { - } - this.Initialized = true; - } - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/ComboModelo.cs b/Gestor.Application/ViewModels/Ferramentas/ComboModelo.cs deleted file mode 100644 index 97b1ae0..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/ComboModelo.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Gestor.Application.ViewModels.Generic; -using Gestor.Model.Domain.MalaDireta; -using System; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class ComboModelo : BaseViewModel - { - private Gestor.Model.Domain.MalaDireta.ModeloMalaDireta _modeloMalaDireta = new Gestor.Model.Domain.MalaDireta.ModeloMalaDireta(); - - private bool _indisponivel; - - public bool Indisponivel - { - get - { - return this._indisponivel; - } - set - { - this._indisponivel = value; - base.OnPropertyChanged("Indisponivel"); - } - } - - public Gestor.Model.Domain.MalaDireta.ModeloMalaDireta ModeloMalaDireta - { - get - { - return this._modeloMalaDireta; - } - set - { - this._modeloMalaDireta = value; - base.OnPropertyChanged("ModeloMalaDireta"); - } - } - - public ComboModelo() - { - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/ComboVariavel.cs b/Gestor.Application/ViewModels/Ferramentas/ComboVariavel.cs deleted file mode 100644 index 6fd4392..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/ComboVariavel.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Gestor.Application.ViewModels.Generic; -using Gestor.Model.Domain.MalaDireta; -using System; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class ComboVariavel : BaseViewModel - { - private Gestor.Model.Domain.MalaDireta.VariaveisMalaDireta _variaveisMalaDireta; - - private bool _indisponivel; - - public bool Indisponivel - { - get - { - return this._indisponivel; - } - set - { - this._indisponivel = value; - base.OnPropertyChanged("Indisponivel"); - } - } - - public Gestor.Model.Domain.MalaDireta.VariaveisMalaDireta VariaveisMalaDireta - { - get - { - return this._variaveisMalaDireta; - } - set - { - this._variaveisMalaDireta = value; - base.OnPropertyChanged("VariaveisMalaDireta"); - } - } - - public ComboVariavel(Gestor.Model.Domain.MalaDireta.VariaveisMalaDireta variaveisMalaDireta, bool indisponivel) - { - this.VariaveisMalaDireta = variaveisMalaDireta; - this.Indisponivel = indisponivel; - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/DownloadViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/DownloadViewModel.cs deleted file mode 100644 index 66da49e..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/DownloadViewModel.cs +++ /dev/null @@ -1,550 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.ViewModels.Generic; -using Gestor.Common.Validation; -using Gestor.Model.API; -using Gestor.Model.Domain.Common; -using Gestor.Model.Domain.Generic; -using Gestor.Model.Domain.Seguros; -using IWshRuntimeLibrary; -using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Net; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class DownloadViewModel : BaseSegurosViewModel - { - private const string _path = "c:\\AggerSeguros\\"; - - private string _head; - - private string _total; - - private string _progresso; - - private decimal _porcentagem; - - private bool _processando = true; - - private Geometry _maximizeRestore = Geometry.Parse((string)System.Windows.Application.Current.Resources["Maximize"]); - - private string CurrentVersion - { - get; - set; - } - - public string Head - { - get - { - return this._head; - } - set - { - this._head = value; - base.OnPropertyChanged("Head"); - } - } - - public Geometry MaximizeRestore - { - get - { - return this._maximizeRestore; - } - set - { - this._maximizeRestore = value; - base.OnPropertyChanged("MaximizeRestore"); - } - } - - private Gestor.Model.API.Parameters Parameters - { - get; - set; - } - - public decimal Porcentagem - { - get - { - return this._porcentagem; - } - set - { - this._porcentagem = value; - this.Progresso = string.Format("{0}% de {1} MB", value, this.Total); - base.OnPropertyChanged("Porcentagem"); - } - } - - public bool Processando - { - get - { - return this._processando; - } - set - { - this._processando = value; - base.OnPropertyChanged("Processando"); - } - } - - public string Progresso - { - get - { - return this._progresso; - } - set - { - this._progresso = value; - base.OnPropertyChanged("Progresso"); - } - } - - public string Total - { - get - { - return this._total; - } - set - { - this._total = value; - base.OnPropertyChanged("Total"); - } - } - - public DownloadViewModel(Gestor.Model.API.Parameters parameters) - { - this.Parameters = parameters; - base.IsEnabled = false; - this.Head = string.Concat("ATUALIZAÇÃO ", this.Parameters.get_Directory().ToUpper()); - } - - public async Task Atualizar() - { - System.Version version; - string str; - FileVersionInfo versionInfo; - str = (this.Parameters.get_Beta() ? "Beta" : "Released"); - string str1 = str; - int type = this.Parameters.get_Type(); - if (type == 7) - { - try - { - Gestor.Model.API.Version version1 = await Gestor.Application.Helpers.Connection.Get(string.Format("Update/{0}/{1}", str1, this.Parameters.get_Type()), true, false); - if (File.Exists("c:\\AggerSeguros\\Agger.Gestor.exe")) - { - versionInfo = FileVersionInfo.GetVersionInfo("c:\\AggerSeguros\\Agger.Gestor.exe"); - } - else - { - versionInfo = null; - } - FileVersionInfo fileVersionInfo = versionInfo; - if (fileVersionInfo == null || !System.Version.TryParse(fileVersionInfo.FileVersion, out version) || !(version >= System.Version.Parse(version1.get_VersaoAplicacao()))) - { - await this.AtualizarGestor(version1, true); - } - else - { - Funcoes.Destroy(); - str1 = null; - return; - } - } - catch (Exception exception) - { - Funcoes.Destroy(); - } - } - else if (type != 88) - { - if (type == 99) - { - Gestor.Model.API.Version version2 = await Gestor.Application.Helpers.Connection.Get(string.Format("Update/Released/{0}", this.Parameters.get_Type()), true, false); - await this.Atualizar(version2); - } - else - { - this.CurrentVersion = await this.GetCurrentVersion(this.Parameters.get_Directory()); - Gestor.Model.API.Version version3 = await Gestor.Application.Helpers.Connection.Get(string.Format("Update/{0}/{1}", str1, this.Parameters.get_Type()), true, false); - if (!this.VerificarVersao(version3)) - { - await this.Atualizar(version3); - } - else - { - this.Open(); - } - } - } - else if (File.Exists("c:\\AggerSeguros\\Aggilizador.Application.exe")) - { - this.Parameters.set_Application("Aggilizador.Application.exe"); - this.Open(); - } - else - { - this.Parameters.set_Arguments(""); - await this.AtualizarAggilizador(); - } - str1 = null; - } - - public async Task Atualizar(Gestor.Model.API.Version version) - { - string str; - string str1; - if (this.CheckFreeSpace()) - { - string str2 = string.Concat("c:\\AggerSeguros\\", version.get_Name()); - if (Directory.Exists(str2)) - { - Directory.Delete(str2, true); - } - while (Directory.Exists(str2)) - { - Thread.Sleep(500); - } - Directory.CreateDirectory(str2); - using (WebClient webClient = new WebClient()) - { - webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(this.DownloadFileComplete); - webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.DownloadProgressCallback); - this.CurrentVersion = version.get_Name(); - str = (this.Parameters.get_Type() == 99 ? string.Concat(version.get_Uri(), "/", version.get_Name(), ".exe") : string.Concat(version.get_Uri(), "/", version.get_Name(), ".zip")); - string str3 = str; - str1 = (this.Parameters.get_Type() == 99 ? string.Concat(str2, ".exe") : string.Concat(str2, "//", version.get_Name(), ".zip")); - string str4 = str1; - Stream stream = webClient.OpenRead(str3); - double num = Math.Round((double)((float)long.Parse(webClient.ResponseHeaders["Content-Length"]) / 1024f / 1024f), 2); - this.Total = num.ToString(CultureInfo.InvariantCulture); - if (stream != null) - { - stream.Dispose(); - } - else - { - } - await webClient.DownloadFileTaskAsync(str3, str4); - webClient.Dispose(); - } - webClient = null; - } - else - { - LogError logError = new LogError(); - logError.set_IdFornecedor(ApplicationHelper.IdFornecedor); - logError.set_Fornecedor(Recursos.Empresa.get_Nome()); - logError.set_UsuarioLogado(Recursos.Usuario.get_Nome()); - logError.set_IdUsuarioLogado(Recursos.Usuario.get_Id()); - logError.set_Versao(ApplicationHelper.Versao.ToString()); - logError.set_Data(Funcoes.GetNetworkTime()); - logError.set_IdErro(1001); - logError.set_Erro(string.Concat(Gestor.Common.Validation.ValidationHelper.GetDescription((TipoErro)1001), " - ", version.get_Name())); - logError.set_HResult(0); - logError.set_HelpLink(""); - logError.set_Message(""); - logError.set_Source(""); - logError.set_StackTrace(""); - logError.set_Maquina(Environment.MachineName); - logError.set_UsuarioMaquina(Environment.UserName); - Erro.RegistrarErro(logError, true); - } - } - - public async Task AtualizarAggilizador() - { - if (this.CheckFreeSpace()) - { - using (WebClient webClient = new WebClient()) - { - webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(this.DownloadFileComplete); - webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.DownloadProgressCallback); - string str = "https://update.aggilizador.com.br/stable/Instalador.exe"; - string str1 = string.Concat("c:\\AggerSeguros\\", this.Parameters.get_Application()); - Stream stream = webClient.OpenRead(str); - double num = Math.Round((double)((float)long.Parse(webClient.ResponseHeaders["Content-Length"]) / 1024f / 1024f), 2); - this.Total = num.ToString(CultureInfo.InvariantCulture); - if (stream != null) - { - stream.Dispose(); - } - else - { - } - await webClient.DownloadFileTaskAsync(str, str1); - webClient.Dispose(); - } - webClient = null; - } - else - { - LogError logError = new LogError(); - logError.set_IdFornecedor(ApplicationHelper.IdFornecedor); - logError.set_Fornecedor(Recursos.Empresa.get_Nome()); - logError.set_UsuarioLogado(Recursos.Usuario.get_Nome()); - logError.set_IdUsuarioLogado(Recursos.Usuario.get_Id()); - logError.set_Versao(ApplicationHelper.Versao.ToString()); - logError.set_Data(Funcoes.GetNetworkTime()); - logError.set_IdErro(1001); - logError.set_Erro(string.Concat(Gestor.Common.Validation.ValidationHelper.GetDescription((TipoErro)1001), " - AGGILIZADOR")); - logError.set_HResult(0); - logError.set_HelpLink(""); - logError.set_Message(""); - logError.set_Source(""); - logError.set_StackTrace(""); - logError.set_Maquina(Environment.MachineName); - logError.set_UsuarioMaquina(Environment.UserName); - Erro.RegistrarErro(logError, true); - } - } - - public async Task AtualizarGestor(Gestor.Model.API.Version version, bool criarAtalho = false) - { - string str = "c:\\AggerSeguros\\"; - using (WebClient webClient = new WebClient()) - { - webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(this.DownloadFileCompleteGestor); - webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.DownloadProgressCallback); - this.CurrentVersion = version.get_Name(); - string str1 = string.Concat(version.get_Uri(), "/", version.get_Name(), ".zip"); - string str2 = string.Concat(str, version.get_Name(), ".zip"); - Stream stream = webClient.OpenRead(str1); - double num = Math.Round((double)((float)long.Parse(webClient.ResponseHeaders["Content-Length"]) / 1024f / 1024f), 2); - this.Total = num.ToString(CultureInfo.InvariantCulture); - if (stream != null) - { - stream.Dispose(); - } - else - { - } - await webClient.DownloadFileTaskAsync(str1, str2); - webClient.Dispose(); - } - webClient = null; - if (criarAtalho) - { - this.CriarAtalho(); - } - } - - private bool CheckFreeSpace() - { - DriveInfo driveInfo = new DriveInfo("C"); - if (!driveInfo.IsReady) - { - return false; - } - return driveInfo.AvailableFreeSpace > (long)314572800; - } - - private void CriarAtalho() - { - WshShell variable = (WshShell)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8"))); - string str = "c:\\AggerSeguros\\"; - string str1 = "Agger.Gestor.exe"; - string str2 = "Agger Gestor"; - try - { - IWshShortcut variable1 = variable.CreateShortcut(string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "\\Agger Gestor.lnk")) as IWshShortcut; - if (variable1 != null) - { - variable1.TargetPath = string.Concat(str, str1); - variable1.WindowStyle = 1; - variable1.Description = str2; - variable1.WorkingDirectory = str; - variable1.IconLocation = string.Concat(str, str1, ",0"); - variable1.Save(); - } - } - catch (Exception exception) - { - } - try - { - IWshShortcut variable2 = variable.CreateShortcut(string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "\\Agger Gestor.lnk")) as IWshShortcut; - if (variable2 != null) - { - variable2.TargetPath = string.Concat(str, str1); - variable2.WindowStyle = 1; - variable2.Description = str2; - variable2.WorkingDirectory = str; - variable2.IconLocation = string.Concat(str, str1, ",0"); - variable2.Save(); - } - } - catch (Exception exception1) - { - } - try - { - IWshShortcut variable3 = variable.CreateShortcut(string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "\\Agger Gestor.lnk")) as IWshShortcut; - if (variable3 != null) - { - variable3.TargetPath = string.Concat(str, str1); - variable3.WindowStyle = 1; - variable3.Description = str2; - variable3.WorkingDirectory = str; - variable3.IconLocation = string.Concat(str, str1, ",0"); - variable3.Save(); - } - } - catch (Exception exception2) - { - } - try - { - IWshShortcut variable4 = variable.CreateShortcut(string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "\\Agger Gestor.lnk")) as IWshShortcut; - if (variable4 != null) - { - variable4.TargetPath = string.Concat(str, str1); - variable4.WindowStyle = 1; - variable4.Description = str2; - variable4.WorkingDirectory = str; - variable4.IconLocation = string.Concat(str, str1, ",0"); - variable4.Save(); - } - } - catch (Exception exception3) - { - } - } - - private void DownloadFileComplete(object sender, AsyncCompletedEventArgs e) - { - this.Processando = true; - this.Porcentagem = decimal.Zero; - this.Extract(); - this.Open(); - } - - private void DownloadFileCompleteGestor(object sender, AsyncCompletedEventArgs e) - { - this.Processando = true; - this.Porcentagem = decimal.Zero; - this.ExtractGestor(); - Funcoes.Destroy(); - } - - private void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e) - { - this.Processando = false; - this.Porcentagem = e.ProgressPercentage; - } - - public void Extract() - { - if (this.Parameters.get_Type() == 99 || this.Parameters.get_Type() == 88) - { - return; - } - string str = string.Concat("c:\\AggerSeguros\\", this.CurrentVersion); - string str1 = string.Concat(str, "\\", this.CurrentVersion, ".zip"); - string.Concat(str, "\\", this.Parameters.get_Application()); - ZipFile.ExtractToDirectory(str1, str); - File.Delete(str1); - } - - public void ExtractGestor() - { - string str = string.Concat("c:\\AggerSeguros\\", this.CurrentVersion, ".zip"); - ZipArchive zipArchive = ZipFile.OpenRead(str); - try - { - foreach (ZipArchiveEntry entry in zipArchive.get_Entries()) - { - string fullPath = Path.GetFullPath(Path.Combine("c:\\AggerSeguros\\", entry.get_FullName())); - fullPath.StartsWith("c:\\AggerSeguros\\", StringComparison.OrdinalIgnoreCase); - if (entry.get_Name() != "") - { - entry.ExtractToFile(fullPath, true); - } - else - { - Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); - } - } - zipArchive.Dispose(); - File.Delete(str); - } - catch (Exception exception) - { - } - } - - private async Task GetCurrentVersion(string name) - { - string str1 = await Task.Run(() => { - string[] directories = Directory.GetDirectories("c:\\AggerSeguros\\"); - List nums = new List(); - string[] strArrays = directories; - for (int i = 0; i < (int)strArrays.Length; i++) - { - string str = strArrays[i]; - if (str.IndexOf(name, StringComparison.Ordinal) > -1) - { - System.Text.RegularExpressions.Match match = (new Regex("(^[A-Za-z]+)(.)([A-Za-z]+)(\\d+)", RegexOptions.IgnoreCase)).Match(str.Replace("c:\\AggerSeguros\\", "")); - if (match.Success) - { - nums.Add(long.Parse(match.Groups[4].Value)); - } - } - } - nums.Reverse(); - if (nums.Count == 0) - { - return ""; - } - return string.Format("{0}{1}", name, nums.First()); - }); - return str1; - } - - public void Open() - { - if (!this.Parameters.get_Run()) - { - Funcoes.Destroy(); - return; - } - string str = Path.Combine((this.Parameters.get_Type() == 99 || this.Parameters.get_Type() == 88 ? "c:\\AggerSeguros\\" : string.Concat("c:\\AggerSeguros\\", this.CurrentVersion)), this.Parameters.get_Application()); - try - { - Process.Start(str, this.Parameters.get_Arguments()); - } - catch - { - } - Funcoes.Destroy(); - } - - private bool VerificarVersao(Gestor.Model.API.Version versao) - { - bool flag = File.Exists(string.Concat("c:\\AggerSeguros\\\\", this.CurrentVersion, "\\", this.Parameters.get_Application())); - return (versao.get_Name() == this.CurrentVersion) & flag; - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs deleted file mode 100644 index 6f528ac..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs +++ /dev/null @@ -1,512 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.Servicos.Ferramentas; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.ViewModels.Command; -using Gestor.Application.ViewModels.Generic; -using Gestor.Common.Helpers; -using Gestor.Common.Validation; -using Gestor.Model.API; -using Gestor.Model.Common; -using Gestor.Model.Domain.Common; -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.IO; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Forms; -using System.Windows.Input; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class EmpresaViewModel : BaseSegurosViewModel - { - private readonly EmpresaServico _servico; - - public Empresa CancelEmpresa; - - private Empresa _selectedEmpresa = new Empresa(); - - private string _logoLabel = "ANEXAR LOGOTIPO"; - - private bool _passWordReadOnly; - - private bool _enableConsultaEspaco = true; - - private double _espaco; - - private string _senha; - - private string _confirmaSenha; - - private ObservableCollection _empresasFiltradas = new ObservableCollection(); - - private bool _isExpanded; - - private Visibility _confirmacaoSenha { get; set; } = Visibility.Collapsed; - - private Visibility _visualizacaoMatriz { get; set; } = Visibility.Collapsed; - - public Visibility ConfirmacaoSenha - { - get - { - return this._confirmacaoSenha; - } - set - { - this._confirmacaoSenha = value; - base.OnPropertyChanged("ConfirmacaoSenha"); - } - } - - public string ConfirmaSenha - { - get - { - return this._confirmaSenha; - } - set - { - this._confirmaSenha = value; - base.OnPropertyChanged("ConfirmaSenha"); - } - } - - public ICommand ConsultarEspacoCommand - { - get; - set; - } - - public List Empresas - { - get; - set; - } - - public ObservableCollection EmpresasFiltradas - { - get - { - return this._empresasFiltradas; - } - set - { - this._empresasFiltradas = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("EmpresasFiltradas"); - } - } - - public bool EnableConsultaEspaco - { - get - { - return this._enableConsultaEspaco; - } - set - { - this._enableConsultaEspaco = value; - base.OnPropertyChanged("EnableConsultaEspaco"); - } - } - - public double Espaco - { - get - { - return this._espaco; - } - set - { - this._espaco = value; - base.OnPropertyChanged("Espaco"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public string LogoLabel - { - get - { - return this._logoLabel; - } - set - { - this._logoLabel = value; - base.OnPropertyChanged("LogoLabel"); - } - } - - public bool PassWordReadOnly - { - get - { - return this._passWordReadOnly; - } - set - { - bool flag; - if (!value) - { - flag = false; - } - else - { - flag = (Recursos.Usuario.get_Administrador() ? true : Recursos.Usuario.get_Id() == (long)0); - } - this._passWordReadOnly = flag; - base.OnPropertyChanged("PassWordReadOnly"); - } - } - - public Empresa SelectedEmpresa - { - get - { - return this._selectedEmpresa; - } - set - { - string str; - long? nullable; - this._selectedEmpresa = value; - if (value != null) - { - string senhaAdmin = value.get_SenhaAdmin(); - if (senhaAdmin != null) - { - str = EncryptionHelper.Decrypt(senhaAdmin); - } - else - { - str = null; - } - } - else - { - str = null; - } - this.Senha = str; - this.ConfirmaSenha = string.Empty; - this.WorkOnSelectedEmpresa(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedEmpresa"); - } - } - - public string Senha - { - get - { - return this._senha; - } - set - { - this._senha = value; - base.OnPropertyChanged("Senha"); - } - } - - public Visibility VisualizacaoMatriz - { - get - { - return this._visualizacaoMatriz; - } - set - { - this._visualizacaoMatriz = value; - base.OnPropertyChanged("VisualizacaoMatriz"); - } - } - - public EmpresaViewModel() - { - this.ConsultarEspacoCommand = new RelayCommand(async () => await this.ConsultaEspacoUsadoClienteInGb()); - this._servico = new EmpresaServico(); - base.EnableMenu = true; - this.PassWordReadOnly = (!Recursos.Usuario.get_Administrador() ? false : base.EnableFields); - this.Seleciona(); - } - - public async Task AnexarLogo() - { - string fileName = ""; - using (OpenFileDialog openFileDialog = new OpenFileDialog()) - { - openFileDialog.Multiselect = false; - openFileDialog.Filter = "Imagens|*.jpg;*.jpeg;*.png;"; - openFileDialog.InitialDirectory = Environment.SpecialFolder.Desktop.ToString(); - if (DialogResult.OK == openFileDialog.ShowDialog()) - { - fileName = openFileDialog.FileName; - } - else - { - return; - } - } - int num = 0; - try - { - using (MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(fileName))) - { - byte[] numArray = new byte[checked((IntPtr)memoryStream.Length)]; - memoryStream.Position = (long)0; - memoryStream.Read(numArray, 0, (int)numArray.Length); - this.SelectedEmpresa.set_Logo(numArray); - } - } - catch (Exception exception) - { - num = 1; - } - if (num == 1) - { - string[] newLine = new string[] { "NÃO FOI POSSÍVEL CARREGAR O ARQUIVO ", fileName, ".", Environment.NewLine, "O ARQUIVO ESTÁ INACESSÍVEL OU SENDO UTILIZADO POR OUTRO PROCESSO." }; - await base.ShowMessage(string.Concat(newLine), "OK", "", false); - } - } - - public void CancelarAlteracao() - { - if (this.CancelEmpresa == null || !this.Empresas.Any((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Empresas.First((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()), this.CancelEmpresa); - if (this.EmpresasFiltradas.Count <= 0 || !this.EmpresasFiltradas.Any((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id())) - { - this.EmpresasFiltradas.Add(this.CancelEmpresa); - } - else - { - DomainBase.Copy(this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()), this.CancelEmpresa); - } - this.EmpresasFiltradas = new ObservableCollection(this.EmpresasFiltradas); - this.SelectedEmpresa = this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()); - } - base.Alterar(false); - } - - public async Task ConsultaEspacoUsadoClienteInGb() - { - this.EnableConsultaEspaco = false; - base.Loading(true); - double num = await this._servico.ConsultaEspacoBancoInGb(); - double num1 = 0; - if (Connection.ConnectionAddress.get_UsaAzureStorage()) - { - double num2 = await Connection.EspacoUsadoAzureInBytes(""); - if (num2 > 0) - { - num1 = num2 / 1024 / 1024 / 1024; - } - } - this.Espaco = num + num1; - if (this.Espaco == 0) - { - this.EnableConsultaEspaco = true; - } - base.Loading(false); - } - - internal async Task> Filtrar(string value) - { - List empresas = await Task.Run>(() => this.FiltrarEmpresa(value)); - return empresas; - } - - public List FiltrarEmpresa(string filter) - { - this.EmpresasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Empresas) : new ObservableCollection( - from x in this.Empresas - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Nome() - select x)); - return this.EmpresasFiltradas.ToList(); - } - - public void Incluir() - { - this.SelectedEmpresa = new Empresa(); - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string str1; - List> keyValuePairs1 = this.SelectedEmpresa.Validate(); - if (this.VisualizacaoMatriz != Visibility.Collapsed && this.ConfirmaSenha != this.Senha) - { - keyValuePairs1.Add(new KeyValuePair("SenhaAdmin|SENHA ADM", "A SENHA E A CONFIRMAÇÃO DA SENHA DEVEM SER IGUAIS.")); - } - if (keyValuePairs1.Count <= 0) - { - if (this.SelectedEmpresa.get_Id() == (long)1) - { - this.SelectedEmpresa.set_SenhaAdmin(EncryptionHelper.Encrypt(this.Senha)); - } - str = (this.SelectedEmpresa.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Empresa empresa = await this._servico.Save(this.SelectedEmpresa); - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str1, " EMPRESA \"", empresa.get_Nome(), "\""), empresa.get_Id(), new TipoTela?(18), string.Format("EMPRESA \"{0}\", ID: {1}", empresa.get_Nome(), empresa.get_Id())); - if (!this.Empresas.Any((Empresa x) => x.get_Id() == empresa.get_Id())) - { - this.Empresas.Add(empresa); - } - else - { - DomainBase.Copy(this.Empresas.First((Empresa x) => x.get_Id() == empresa.get_Id()), empresa); - } - if (!this.EmpresasFiltradas.Any((Empresa x) => x.get_Id() == empresa.get_Id())) - { - this.EmpresasFiltradas.Add(empresa); - } - else - { - DomainBase.Copy(this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == empresa.get_Id()), empresa); - } - this.EmpresasFiltradas = new ObservableCollection(this.EmpresasFiltradas); - Recursos.Empresas = this.Empresas; - this.WorkOnSelectedEmpresa(empresa, false); - base.Alterar(false); - base.ToggleSnackBar("EMPRESA SALVA 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(18); - await this.SelecionaEmpresas(); - base.Loading(false); - } - - public async void SelecionaEmpresa(Empresa empresa) - { - Empresa empresa1 = await this._servico.BuscarEmpresaPorId(empresa.get_Id()); - DomainBase.Copy(this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == empresa.get_Id()), empresa1); - this.SelectedEmpresa = this.EmpresasFiltradas.First((Empresa x) => x.get_Id() == empresa.get_Id()); - } - - private async Task SelecionaEmpresas() - { - base.Loading(true); - List empresas = await (new BaseServico()).BuscarEmpresasAsync(); - EmpresaViewModel list = this; - List empresas1 = empresas; - IEnumerable empresas2 = empresas1.Where((Empresa x) => { - if (Recursos.Usuario.get_IdEmpresa() == (long)1) - { - return true; - } - return x.get_Id() == Recursos.Usuario.get_IdEmpresa(); - }); - list.Empresas = ( - from x in empresas2 - orderby x.get_Nome() - select x).ToList(); - this.EmpresasFiltradas = new ObservableCollection(this.Empresas); - if (this.EmpresasFiltradas.Count <= 0) - { - this.SelectedEmpresa = new Empresa(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelecionaEmpresa(this.EmpresasFiltradas.First()); - } - base.Loading(false); - } - - private void WorkOnSelectedEmpresa(Empresa value, bool registrar = true) - { - long? nullable; - bool logo; - this.CancelEmpresa = (value == null || value.get_Id() == 0 ? this.CancelEmpresa : (Empresa)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 18) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU EMPRESA \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(18), string.Format("ID EMPRESA: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 18; - Empresa selectedEmpresa = this.SelectedEmpresa; - if (selectedEmpresa != null) - { - nullable = new long?(selectedEmpresa.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedEmpresa = this.EmpresasFiltradas.FirstOrDefault((Empresa x) => x.get_Id() == value.get_Id()); - } - Empresa empresa = this.SelectedEmpresa; - if (empresa != null) - { - logo = empresa.get_Logo(); - } - else - { - logo = false; - } - this.LogoLabel = (!logo ? "ANEXAR LOGOTIPO" : "ALTERAR LOGOTIPO"); - this.VisualizacaoMatriz = (this.SelectedEmpresa.get_Id() == (long)1 ? Visibility.Visible : Visibility.Collapsed); - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs deleted file mode 100644 index a084abd..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs +++ /dev/null @@ -1,380 +0,0 @@ -using Gestor.Application.Helpers; -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.Generic; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class EstipulanteViewModel : BaseSegurosViewModel - { - private readonly EstipulanteServico _servico; - - public Estipulante CancelEstipulante; - - private Estipulante _selectedEstipulante = new Estipulante(); - - private ObservableCollection _estipulantesFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - public List Estipulantes - { - get; - set; - } - - public ObservableCollection EstipulantesFiltrados - { - get - { - return this._estipulantesFiltrados; - } - set - { - this._estipulantesFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("EstipulantesFiltrados"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public Estipulante SelectedEstipulante - { - get - { - return this._selectedEstipulante; - } - set - { - long? nullable; - this._selectedEstipulante = value; - this.WorkOnSelectedEstipulante(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedEstipulante"); - if (value == null) - { - return; - } - this.SelectedEstipulante.Initialize(); - } - } - - public EstipulanteViewModel() - { - this._servico = new EstipulanteServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelEstipulante == null || !this.Estipulantes.Any((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Estipulantes.First((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()), this.CancelEstipulante); - if (this.EstipulantesFiltrados.Count <= 0 || !this.EstipulantesFiltrados.Any((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id())) - { - this.EstipulantesFiltrados.Add(this.CancelEstipulante); - } - else - { - DomainBase.Copy(this.EstipulantesFiltrados.First((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()), this.CancelEstipulante); - } - this.EstipulantesFiltrados = new ObservableCollection(this.EstipulantesFiltrados); - this.SelectedEstipulante = this.EstipulantesFiltrados.First((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()); - } - base.Alterar(false); - } - - public async void Excluir() - { - Estipulante estipulante; - if (this.SelectedEstipulante != null && this.SelectedEstipulante.get_Id() != 0) - { - base.Loading(true); - List documentos = await (new BaseServico()).BuscarDocumentosPorEstipulante(this.SelectedEstipulante.get_Id()); - base.Loading(false); - if (documentos.Count > 0) - { - string str = "ESTIPULANTE NÃO PODE SER EXCLUÍDO POIS ESTÁ VINCULADO AOS SEGUINTES DOCUMENTOS:"; - foreach (Documento documento in documentos) - { - if (!string.IsNullOrWhiteSpace(documento.get_Apolice())) - { - object[] newLine = new object[] { Environment.NewLine, documentos.IndexOf(documento) + 1, documento.get_Proposta(), documento.get_Apolice() }; - str = string.Concat(str, string.Format("{0}DOCUMENTO {1} (NÚMERO DA PROPOSTA: {2}, NÚMERO DA APÓLICE: {3})", newLine)); - } - else - { - str = string.Concat(str, string.Format("{0}DOCUMENTO {1} (NÚMERO DA PROPOSTA: {2})", Environment.NewLine, documentos.IndexOf(documento) + 1, documento.get_Proposta())); - } - } - await base.ShowMessage(str, "OK", "", false); - } - else if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false)) - { - base.Loading(true); - if (await this._servico.Delete(this.SelectedEstipulante)) - { - base.RegistrarAcao(string.Concat("EXCLUIU ESTIPULANTE \"", this.SelectedEstipulante.get_Nome(), "\""), this.SelectedEstipulante.get_Id(), new TipoTela?(9), string.Format("ESTIPULANTE \"{0}\", ID: {1}", this.SelectedEstipulante.get_Nome(), this.SelectedEstipulante.get_Id())); - int num = this.EstipulantesFiltrados.IndexOf(this.SelectedEstipulante); - this.Estipulantes.Remove(this.SelectedEstipulante); - this.EstipulantesFiltrados.Remove(this.SelectedEstipulante); - this.EstipulantesFiltrados = new ObservableCollection(this.EstipulantesFiltrados); - if (this.EstipulantesFiltrados.Count <= 0) - { - this.SelectedEstipulante = new Estipulante(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - EstipulanteViewModel estipulanteViewModel = this; - estipulante = (num < this.EstipulantesFiltrados.Count ? this.EstipulantesFiltrados.ElementAt(num) : this.EstipulantesFiltrados.Last()); - estipulanteViewModel.SelectedEstipulante = estipulante; - } - Recursos.Estipulantes = await (new BaseServico()).BuscarEstipulantesAsync(); - base.Loading(false); - base.ToggleSnackBar("ESTIPULANTE EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - internal async Task> Filtrar(string value) - { - List estipulantes = await Task.Run>(() => this.FiltrarEstipulante(value)); - return estipulantes; - } - - public List FiltrarEstipulante(string filter) - { - this.EstipulantesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Estipulantes) : new ObservableCollection( - from x in this.Estipulantes - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Ativo() descending, x.get_Nome() - select x)); - this.SelectedEstipulante = this.EstipulantesFiltrados.FirstOrDefault(); - return this.EstipulantesFiltrados.ToList(); - } - - public void Incluir() - { - Estipulante estipulante = new Estipulante(); - estipulante.set_IdEmpresa(Recursos.Usuario.get_IdEmpresa()); - estipulante.set_Ativo(true); - this.SelectedEstipulante = estipulante; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string str1; - List> keyValuePairs1 = this.SelectedEstipulante.Validate(); - List> keyValuePairs2 = keyValuePairs1; - keyValuePairs2.AddRange(await this.Validate()); - keyValuePairs2 = null; - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedEstipulante.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Estipulante estipulante = await this._servico.Save(this.SelectedEstipulante); - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str1, " ESTIPULANTE \"", estipulante.get_Nome(), "\""), estipulante.get_Id(), new TipoTela?(9), string.Format("ESTIPULANTE \"{0}\", ID: {1}", estipulante.get_Nome(), estipulante.get_Id())); - if (!this.Estipulantes.Any((Estipulante x) => x.get_Id() == estipulante.get_Id())) - { - this.Estipulantes.Add(estipulante); - } - else - { - DomainBase.Copy(this.Estipulantes.First((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante); - } - if (!this.EstipulantesFiltrados.Any((Estipulante x) => x.get_Id() == estipulante.get_Id())) - { - this.EstipulantesFiltrados.Add(estipulante); - } - else - { - DomainBase.Copy(this.EstipulantesFiltrados.First((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante); - } - this.EstipulantesFiltrados = new ObservableCollection(this.EstipulantesFiltrados); - Recursos.Estipulantes = this.Estipulantes; - this.WorkOnSelectedEstipulante(estipulante, false); - base.Alterar(false); - this.SelectedEstipulante.Initialize(); - base.ToggleSnackBar("ESTIPULANTE SALVO COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - keyValuePairs1 = null; - str1 = null; - return keyValuePairs; - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(9); - await this.SelecionaEstipulantes(); - base.Loading(false); - } - - public async void SelecionaEstipulante(Estipulante estipulante) - { - Estipulante estipulante1 = await this._servico.BuscarEstipulantePorId(estipulante.get_Id()); - DomainBase.Copy(this.EstipulantesFiltrados.First((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante1); - this.SelectedEstipulante = this.EstipulantesFiltrados.First((Estipulante x) => x.get_Id() == estipulante.get_Id()); - } - - private async Task SelecionaEstipulantes() - { - base.Loading(true); - List estipulantes = await (new BaseServico()).BuscarEstipulantesAsync(); - EstipulanteViewModel list = this; - List estipulantes1 = estipulantes; - IEnumerable estipulantes2 = estipulantes1.Where((Estipulante x) => { - if (Recursos.Usuario.get_IdEmpresa() == (long)1) - { - return true; - } - return Recursos.Usuario.get_IdEmpresa() == x.get_IdEmpresa(); - }); - IOrderedEnumerable ativo = - from x in estipulantes2 - orderby x.get_Ativo() descending - select x; - list.Estipulantes = ativo.ThenBy((Estipulante x) => x.get_Nome()).ToList(); - this.EstipulantesFiltrados = new ObservableCollection(this.Estipulantes); - if (this.EstipulantesFiltrados.Count <= 0) - { - this.SelectedEstipulante = new Estipulante(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelecionaEstipulante(this.EstipulantesFiltrados.First()); - } - Recursos.Estipulantes = estipulantes; - base.Loading(false); - } - - public async Task>> Validate() - { - List estipulantes; - List> keyValuePairs = new List>(); - bool flag = !string.IsNullOrEmpty(this.SelectedEstipulante.get_Nome()); - if (!ValidationHelper.ValidateDocument(this.SelectedEstipulante.get_Documento())) - { - estipulantes = new List(); - } - else - { - estipulantes = await (new BaseServico()).BuscarEstipulante(this.SelectedEstipulante.get_Documento()); - } - List estipulantes1 = estipulantes; - string nome = ""; - if (estipulantes1.Count > 0) - { - estipulantes1.ForEach((Estipulante x) => { - if (x.get_Id() == this.SelectedEstipulante.get_Id()) - { - return; - } - if (!string.IsNullOrEmpty(this.SelectedEstipulante.get_Documento()) && x.get_Documento() == this.SelectedEstipulante.get_Documento()) - { - flag = false; - nome = x.get_Nome(); - } - }); - } - if (!flag) - { - keyValuePairs.Add(new KeyValuePair("Documento", string.Concat("O DOCUMENTO ESTÁ CADASTRADO PARA O ESTIPULANTE ", nome, "."))); - } - List> keyValuePairs1 = keyValuePairs; - keyValuePairs = null; - return keyValuePairs1; - } - - private void WorkOnSelectedEstipulante(Estipulante value, bool registrar = true) - { - long? nullable; - this.CancelEstipulante = (value == null || value.get_Id() == 0 ? this.CancelEstipulante : (Estipulante)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 9) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU ESTIPULANTE \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(9), string.Format("ID ESTIPULANTE: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 9; - Estipulante selectedEstipulante = this.SelectedEstipulante; - if (selectedEstipulante != null) - { - nullable = new long?(selectedEstipulante.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedEstipulante = this.EstipulantesFiltrados.FirstOrDefault((Estipulante x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/EtiquetaViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/EtiquetaViewModel.cs deleted file mode 100644 index c19b97e..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/EtiquetaViewModel.cs +++ /dev/null @@ -1,1163 +0,0 @@ -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; -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.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class EtiquetaViewModel : BaseSegurosViewModel - { - private bool _allSelectedChanging; - - private List _tiposEtiqueta = new List() - { - "CLIENTE", - "APÓLICE" - }; - - private string _tipoEtiqueta = "CLIENTE"; - - private bool? _allSelected; - - private ObservableCollection _apolicesFiltrados = new ObservableCollection(); - - 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 bool? AllSelected - { - get - { - return this._allSelected; - } - set - { - bool? nullable = value; - bool? nullable1 = this._allSelected; - if (nullable.GetValueOrDefault() == nullable1.GetValueOrDefault() & nullable.HasValue == nullable1.HasValue) - { - return; - } - this._allSelected = value; - this.AllSelectedChanged(); - this.Apolices = new List(this.Apolices); - base.OnPropertyChanged("AllSelected"); - } - } - - public List Apolices - { - get; - set; - } - - public ObservableCollection ApolicesFiltrados - { - get - { - return this._apolicesFiltrados; - } - set - { - this._apolicesFiltrados = value; - foreach (Documento apolicesFiltrado in this.ApolicesFiltrados) - { - apolicesFiltrado.add_PropertyChanged(new PropertyChangedEventHandler(this.EntryOnPropertyChanged)); - } - base.OnPropertyChanged("ApolicesFiltrados"); - } - } - - public bool DuasColunas - { - get - { - return this._duasColunas; - } - set - { - this._duasColunas = value; - base.OnPropertyChanged("DuasColunas"); - } - } - - public Visibility ExibirControlesEtiquetaApolice - { - get - { - if (this.TipoEtiqueta != "APÓLICE") - { - return Visibility.Collapsed; - } - return Visibility.Visible; - } - } - - public Visibility ExibirControlesEtiquetaCliente - { - get - { - if (this.TipoEtiqueta != "CLIENTE") - { - return Visibility.Collapsed; - } - return Visibility.Visible; - } - } - - public bool MostrarApolice - { - get - { - return this._mostrarApolice; - } - set - { - this._mostrarApolice = value; - base.OnPropertyChanged("MostrarApolice"); - } - } - - public bool MostrarItem - { - get - { - return this._mostrarItem; - } - set - { - this._mostrarItem = value; - base.OnPropertyChanged("MostrarItem"); - } - } - - public bool MostrarNascimento - { - get - { - return this._mostrarNascimento; - } - set - { - this._mostrarNascimento = value; - base.OnPropertyChanged("MostrarNascimento"); - } - } - - public bool MostrarVendedor - { - get - { - return this._mostrarVendedor; - } - set - { - this._mostrarVendedor = value; - base.OnPropertyChanged("MostrarVendedor"); - } - } - - public int Pular - { - get - { - return this._pular; - } - set - { - this._pular = value; - base.OnPropertyChanged("Pular"); - } - } - - public string TipoEtiqueta - { - get - { - return this._tipoEtiqueta; - } - set - { - this._tipoEtiqueta = value; - base.OnPropertyChanged("TipoEtiqueta"); - base.OnPropertyChanged("ExibirControlesEtiquetaApolice"); - base.OnPropertyChanged("ExibirControlesEtiquetaCliente"); - } - } - - public List TiposEtiqueta - { - get - { - return this._tiposEtiqueta; - } - set - { - this._tiposEtiqueta = value; - base.OnPropertyChanged("TiposEtiqueta"); - } - } - - public bool TresColunas - { - get - { - return this._tresColunas; - } - set - { - this._tresColunas = value; - base.OnPropertyChanged("TresColunas"); - } - } - - public bool UmaPagina - { - get - { - return this._umaPagina; - } - set - { - this._umaPagina = value; - this.VisibilityColunas = (value ? Visibility.Collapsed : Visibility.Visible); - base.OnPropertyChanged("UmaPagina"); - } - } - - public object VisibilityColunas - { - get - { - return this._visibilityColunas; - } - set - { - this._visibilityColunas = value; - base.OnPropertyChanged("VisibilityColunas"); - } - } - - public EtiquetaViewModel() - { - } - - private void AllSelectedChanged() - { - if (this._allSelectedChanging) - { - return; - } - try - { - this._allSelectedChanging = true; - if (this.AllSelected.HasValue) - { - foreach (Documento apolice in this.Apolices) - { - apolice.set_Selecionado(this.AllSelected.Value); - } - } - } - finally - { - this._allSelectedChanging = false; - } - } - - public async Task CarregarDados(List list, bool apenasCliente) - { - ObservableCollection observableCollection; - List documentos = list.ToList(); - List clientes = documentos.Select((Documento x) => { - Cliente cliente = new Cliente(); - cliente.set_Id(x.get_Controle().get_Cliente().get_Id()); - return cliente; - }).ToList(); - ClienteServico clienteServico = new ClienteServico(); - ItemServico itemServico = new ItemServico(); - List clientes1 = clientes; - List clienteEnderecos = await clienteServico.BuscarEnderecosPorCliente(( - from x in clientes1 - where x.get_Id() > (long)0 - select x).ToList()); - if (!apenasCliente) - { - observableCollection = await itemServico.BuscarItens(list.ToList()); - } - else - { - observableCollection = null; - } - ObservableCollection observableCollection1 = observableCollection; - foreach (Documento documento in list) - { - if (( - from y in clienteEnderecos - where y.get_Cliente().get_Id() == documento.get_Controle().get_Cliente().get_Id() - select y).Count() == 0) - { - continue; - } - if (documento.get_Controle().get_Cliente().get_Id() > (long)0) - { - Cliente cliente2 = documento.get_Controle().get_Cliente(); - List clienteEnderecos1 = ( - from y in clienteEnderecos - where y.get_Cliente().get_Id() == documento.get_Controle().get_Cliente().get_Id() - select y).ToList(); - cliente2.set_Enderecos(new ObservableCollection( - from y in clienteEnderecos1 - orderby y.get_Ordem() - select y)); - } - if (apenasCliente) - { - continue; - } - documento.set_ItensAtivo(( - from y in observableCollection1 - where y.get_Documento().get_Id() == documento.get_Id() - select y).ToList()); - } - this.TipoEtiqueta = (apenasCliente ? "CLIENTE" : "APÓLICE"); - EtiquetaViewModel etiquetaViewModel = this; - List documentos1 = list; - IEnumerable documentos2 = documentos1.Where((Documento x) => { - bool enderecos; - Cliente cliente = x.get_Controle().get_Cliente(); - if (cliente != null) - { - enderecos = cliente.get_Enderecos(); - } - else - { - enderecos = false; - } - if (!enderecos) - { - return false; - } - Cliente cliente1 = x.get_Controle().get_Cliente(); - if (cliente1 == null) - { - return false; - } - return cliente1.get_Enderecos().Count() > 0; - }); - etiquetaViewModel.Apolices = ( - from x in documentos2 - orderby x.get_Controle().get_Cliente().get_Nome() - select x).ToList(); - this.ApolicesFiltrados = new ObservableCollection(this.Apolices); - this.AllSelected = new bool?(true); - this.RecheckAllSelected(); - itemServico = null; - clienteEnderecos = null; - } - - public void EmitirEtiquetas() - { - double num; - DateTime? nascimento; - DateTime valueOrDefault; - string str; - string str1; - object obj; - string str2; - string str3; - string complemento; - string str4; - string str5; - string str6; - string cidade; - string str7; - string estado; - string str8; - string str9; - string str10; - object obj1; - string str11; - string str12; - string complemento1; - string str13; - string str14; - string str15; - string str16; - string str17; - object obj2; - object obj3; - object obj4; - string upper; - object obj5; - object obj6; - object obj7; - string upper1; - string str18 = ""; - List list = ( - from x in this.Apolices - where x.get_Selecionado() - select x).ToList(); - string tipoEtiqueta = this.TipoEtiqueta; - if (tipoEtiqueta == "CLIENTE") - { - list = this.Apolices.Where((Documento x) => { - if (!x.get_Selecionado()) - { - return false; - } - return x.get_Controle().get_Cliente().get_Enderecos() != null; - }).ToList(); - if (!this.UmaPagina) - { - int num1 = 0; - int num2 = 0; - double num3 = 0; - if (this.DuasColunas) - { - num1 = 10; - num2 = 2; - num3 = 10.52; - } - else if (this.TresColunas) - { - num1 = 10; - num2 = 3; - num3 = 6.82; - } - this.Pular = this.Pular % (num1 * num2); - int pular = this.Pular; - str18 = "ETIQUETAS
"; - int num4 = 0; - while (num4 < list.Count) - { - str18 = string.Concat(str18, "
"); - bool flag = (num4 == 0 ? true : num4 == num1 * num2); - str18 = string.Concat(str18, ""); - for (int i = 0; i < num1 * num2; i += num2) - { - str18 = string.Concat(str18, ""); - if (this.DuasColunas) - { - str18 = string.Concat(str18, ""); - for (int j = 0; j < num2; j++) - { - str18 = string.Concat(str18, ""); - if (j < num2 - 1) - { - if (this.DuasColunas) - { - str18 = string.Concat(str18, ""); - } - } - str18 = string.Concat(str18, "
"); - } - else if (this.TresColunas) - { - str18 = string.Concat(str18, ""); - } - str18 = string.Concat(str18, ""); - if (i + j >= this.Pular) - { - if (num4 < list.Count) - { - Documento item = list[num4]; - if (this.MostrarNascimento) - { - item.get_Controle().get_Cliente().set_Nascimento((new ClienteServico()).BuscarNascimento(item.get_Controle().get_Cliente().get_Id())); - } - if (item.get_Controle().get_Cliente().get_Enderecos().Count() > 0) - { - string[] strArrays = new string[] { str18, item.get_Controle().get_Cliente().get_Nome().Trim(), " ", null, null, null, null, null }; - nascimento = item.get_Controle().get_Cliente().get_Nascimento(); - if (!nascimento.HasValue || !this.MostrarNascimento) - { - str = ""; - } - else - { - nascimento = item.get_Controle().get_Cliente().get_Nascimento(); - if (nascimento.HasValue) - { - valueOrDefault = nascimento.GetValueOrDefault(); - str = valueOrDefault.ToString("dd/MM"); - } - else - { - str = null; - } - } - strArrays[3] = str; - strArrays[4] = "
"; - if (item.get_Controle().get_Cliente().get_Id() == 0) - { - str1 = ""; - } - else - { - string[] strArrays1 = new string[10]; - ClienteEndereco clienteEndereco = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco != null) - { - string endereco = clienteEndereco.get_Endereco(); - if (endereco != null) - { - str2 = endereco.Trim(); - } - else - { - str2 = null; - } - } - else - { - str2 = null; - } - strArrays1[0] = str2; - strArrays1[1] = ", "; - ClienteEndereco clienteEndereco1 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco1 != null) - { - string numero = clienteEndereco1.get_Numero(); - if (numero != null) - { - str3 = numero.Trim(); - } - else - { - str3 = null; - } - } - else - { - str3 = null; - } - strArrays1[2] = str3; - ClienteEndereco clienteEndereco2 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco2 != null) - { - complemento = clienteEndereco2.get_Complemento(); - } - else - { - complemento = null; - } - if (!string.IsNullOrWhiteSpace(complemento)) - { - ClienteEndereco clienteEndereco3 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco3 != null) - { - str4 = clienteEndereco3.get_Complemento().Trim(); - } - else - { - str4 = null; - } - str5 = string.Concat("
", str4); - } - else - { - str5 = ""; - } - strArrays1[3] = str5; - strArrays1[4] = "
"; - ClienteEndereco clienteEndereco4 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco4 != null) - { - string bairro = clienteEndereco4.get_Bairro(); - if (bairro != null) - { - str6 = bairro.Trim(); - } - else - { - str6 = null; - } - } - else - { - str6 = null; - } - strArrays1[5] = str6; - strArrays1[6] = " - "; - ClienteEndereco clienteEndereco5 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco5 != null) - { - cidade = clienteEndereco5.get_Cidade(); - } - else - { - cidade = null; - } - if (!string.IsNullOrEmpty(cidade)) - { - ClienteEndereco clienteEndereco6 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco6 != null) - { - str7 = clienteEndereco6.get_Cidade().Trim(); - } - else - { - str7 = null; - } - } - else - { - str7 = ""; - } - strArrays1[7] = str7; - strArrays1[8] = "/"; - ClienteEndereco clienteEndereco7 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco7 != null) - { - estado = clienteEndereco7.get_Estado(); - } - else - { - estado = null; - } - if (!string.IsNullOrEmpty(estado)) - { - ClienteEndereco clienteEndereco8 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco8 != null) - { - str8 = clienteEndereco8.get_Estado().Trim(); - } - else - { - str8 = null; - } - } - else - { - str8 = ""; - } - strArrays1[9] = str8; - str1 = string.Concat(strArrays1); - } - strArrays[5] = str1; - strArrays[6] = "
"; - if (item.get_Controle().get_Cliente().get_Id() == 0) - { - obj = ""; - } - else - { - ClienteEndereco clienteEndereco9 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco9 != null) - { - obj = clienteEndereco9.get_Cep().Trim(); - } - else - { - obj = null; - } - if (obj == null) - { - obj = ""; - } - } - strArrays[7] = (string)obj; - str18 = string.Concat(strArrays); - } - num4++; - } - this.Pular = 0; - } - str18 = string.Concat(str18, "
"); - } - else if (this.TresColunas) - { - str18 = string.Concat(str18, ""); - } - } - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, "
"); - } - this.Pular = (pular + list.Count) % (num1 * num2); - } - else - { - str18 = "ETIQUETAS"; - for (int k = 0; k < list.Count; k++) - { - str18 = string.Concat(str18, "
" : "30%'>")); - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, ""); - str18 = string.Concat(str18, ""); - num = 10.7; - str18 = string.Concat(str18, ""); - str18 = string.Concat(str18, ""); - str18 = string.Concat(str18, "
"); - Documento documento = list[k]; - if (this.MostrarNascimento) - { - documento.get_Controle().get_Cliente().set_Nascimento((new ClienteServico()).BuscarNascimento(documento.get_Controle().get_Cliente().get_Id())); - } - string[] strArrays2 = new string[] { str18, documento.get_Controle().get_Cliente().get_Nome().Trim(), " ", null, null, null, null, null, null }; - nascimento = documento.get_Controle().get_Cliente().get_Nascimento(); - if (!nascimento.HasValue || !this.MostrarNascimento) - { - str9 = ""; - } - else - { - nascimento = documento.get_Controle().get_Cliente().get_Nascimento(); - if (nascimento.HasValue) - { - valueOrDefault = nascimento.GetValueOrDefault(); - str9 = valueOrDefault.ToString("dd/MM"); - } - else - { - str9 = null; - } - } - strArrays2[3] = str9; - strArrays2[4] = "
"; - if (documento.get_Controle().get_Cliente().get_Id() == 0) - { - str10 = ""; - } - else - { - string[] strArrays3 = new string[10]; - ClienteEndereco clienteEndereco10 = ( - from x in documento.get_Controle().get_Cliente().get_Enderecos() - orderby x.get_Ordem() - select x).FirstOrDefault(); - if (clienteEndereco10 != null) - { - string endereco1 = clienteEndereco10.get_Endereco(); - if (endereco1 != null) - { - str11 = endereco1.Trim(); - } - else - { - str11 = null; - } - } - else - { - str11 = null; - } - strArrays3[0] = str11; - strArrays3[1] = ", "; - ClienteEndereco clienteEndereco11 = documento.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco11 != null) - { - string numero1 = clienteEndereco11.get_Numero(); - if (numero1 != null) - { - str12 = numero1.Trim(); - } - else - { - str12 = null; - } - } - else - { - str12 = null; - } - strArrays3[2] = str12; - ClienteEndereco clienteEndereco12 = documento.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco12 != null) - { - complemento1 = clienteEndereco12.get_Complemento(); - } - else - { - complemento1 = null; - } - if (!string.IsNullOrWhiteSpace(complemento1)) - { - ClienteEndereco clienteEndereco13 = documento.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco13 != null) - { - string complemento2 = clienteEndereco13.get_Complemento(); - if (complemento2 != null) - { - str13 = complemento2.Trim(); - } - else - { - str13 = null; - } - } - else - { - str13 = null; - } - str14 = string.Concat("
", str13); - } - else - { - str14 = ""; - } - strArrays3[3] = str14; - strArrays3[4] = "
"; - ClienteEndereco clienteEndereco14 = documento.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco14 != null) - { - string bairro1 = clienteEndereco14.get_Bairro(); - if (bairro1 != null) - { - str15 = bairro1.Trim(); - } - else - { - str15 = null; - } - } - else - { - str15 = null; - } - strArrays3[5] = str15; - strArrays3[6] = " - "; - ClienteEndereco clienteEndereco15 = documento.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco15 != null) - { - string cidade1 = clienteEndereco15.get_Cidade(); - if (cidade1 != null) - { - str16 = cidade1.Trim(); - } - else - { - str16 = null; - } - } - else - { - str16 = null; - } - strArrays3[7] = str16; - strArrays3[8] = "/"; - ClienteEndereco clienteEndereco16 = documento.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault(); - if (clienteEndereco16 != null) - { - string estado1 = clienteEndereco16.get_Estado(); - if (estado1 != null) - { - str17 = estado1.Trim(); - } - else - { - str17 = null; - } - } - else - { - str17 = null; - } - strArrays3[9] = str17; - str10 = string.Concat(strArrays3); - } - strArrays2[5] = str10; - strArrays2[6] = "
"; - if (documento.get_Controle().get_Cliente().get_Id() == 0) - { - obj1 = ""; - } - else - { - ClienteEndereco clienteEndereco17 = ( - from x in documento.get_Controle().get_Cliente().get_Enderecos() - orderby x.get_Ordem() - select x).FirstOrDefault(); - if (clienteEndereco17 != null) - { - obj1 = clienteEndereco17.get_Cep().Trim(); - } - else - { - obj1 = null; - } - if (obj1 == null) - { - obj1 = ""; - } - } - strArrays2[7] = (string)obj1; - strArrays2[8] = "
"; - str18 = string.Concat(strArrays2); - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, "
"); - } - } - base.RegistrarAcao(string.Format("EMITIU ETIQUETA DE {0} CLIENTE{1}", list.Count, (list.Count == 1 ? "" : "S")), (long)0, new TipoTela?(59), string.Concat("IDS E NOMES DOS CLIENTES:\n", string.Join("\n", - from x in list - select string.Concat(x.get_Controle().get_Cliente().get_Id().ToString(), ": \"", x.get_Controle().get_Cliente().get_Nome(), "\"")))); - } - else if (tipoEtiqueta == "APÓLICE") - { - if (!this.UmaPagina) - { - int num5 = 0; - int num6 = 0; - double num7 = 0; - if (this.DuasColunas) - { - num5 = 10; - num6 = 2; - num7 = 10.52; - } - else if (this.TresColunas) - { - num5 = 10; - num6 = 3; - num7 = 6.87; - } - this.Pular = this.Pular % (num5 * num6); - int pular1 = this.Pular; - str18 = "ETIQUETAS
"; - int num8 = 0; - while (num8 < list.Count) - { - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, ""); - for (int l = 0; l < num5 * num6; l += num6) - { - str18 = string.Concat(str18, ""); - for (int m = 0; m < num6; m++) - { - str18 = string.Concat(str18, ""); - } - } - str18 = string.Concat(str18, "
"); - if (l + m >= this.Pular) - { - if (num8 < list.Count) - { - Documento item1 = list[num8]; - string[] strArrays4 = new string[] { str18, item1.get_Controle().get_Cliente().get_Nome().Trim(), "
", null, null, null, null }; - if (this.MostrarItem) - { - if (item1.get_ItensAtivo().Count > 1) - { - obj2 = "APÓLICE COLETIVA
"; - } - else - { - Item item2 = item1.get_ItensAtivo().FirstOrDefault(); - if (item2 != null) - { - upper = item2.get_Descricao().ToUpper(); - } - else - { - upper = null; - } - obj2 = string.Concat(upper, "
"); - } - if (obj2 == null) - { - obj2 = ""; - } - } - else - { - obj2 = null; - } - strArrays4[3] = (string)obj2; - if (this.MostrarApolice) - { - obj3 = (item1.get_Apolice() == "PROSPECÇÃO" ? string.Format("{0:d} - APÓLICE: {1}
", item1.get_Vigencia2(), item1.get_Apolice()) : string.Concat(string.Format("{0:d} - {1:d} - APÓLICE: {2}", item1.get_Vigencia1(), item1.get_Vigencia2(), item1.get_Apolice()), (string.IsNullOrEmpty(item1.get_Endosso()) ? "
" : string.Concat(" /", item1.get_Endosso(), "
")))) ?? ""; - } - else - { - obj3 = null; - } - strArrays4[4] = (string)obj3; - strArrays4[5] = (item1.get_Apolice() == "PROSPECÇÃO" ? "" : string.Concat(item1.get_Controle().get_Seguradora().get_Nome(), " - ", item1.get_Controle().get_Ramo().get_Nome(), "
")); - if (this.MostrarVendedor) - { - obj4 = (item1.get_VendedorPrincipal() == null ? "" : string.Concat("VENDEDOR: ", item1.get_VendedorPrincipal().get_Nome())) ?? ""; - } - else - { - obj4 = null; - } - strArrays4[6] = (string)obj4; - str18 = string.Concat(strArrays4); - num8++; - } - this.Pular = 0; - } - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, "
"); - } - this.Pular = (pular1 + list.Count) % (num5 * num6); - } - else - { - str18 = "ETIQUETAS"; - for (int n = 0; n < list.Count; n++) - { - str18 = string.Concat(str18, "
" : "30%'>")); - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, ""); - str18 = string.Concat(str18, ""); - num = 10.7; - str18 = string.Concat(str18, ""); - str18 = string.Concat(str18, ""); - str18 = string.Concat(str18, "
"); - Documento documento1 = list[n]; - string[] strArrays5 = new string[] { str18, documento1.get_Controle().get_Cliente().get_Nome().Trim(), "
", null, null, null, null }; - if (this.MostrarItem) - { - if (documento1.get_ItensAtivo().Count > 1) - { - obj5 = "APÓLICE COLETIVA
"; - } - else - { - Item item3 = documento1.get_ItensAtivo().FirstOrDefault(); - if (item3 != null) - { - upper1 = item3.get_Descricao().ToUpper(); - } - else - { - upper1 = null; - } - obj5 = string.Concat(upper1, "
"); - } - if (obj5 == null) - { - obj5 = ""; - } - } - else - { - obj5 = null; - } - strArrays5[3] = (string)obj5; - if (this.MostrarApolice) - { - obj6 = (documento1.get_Apolice() == "PROSPECÇÃO" ? string.Format("{0:d} - APÓLICE: {1}
", documento1.get_Vigencia2(), documento1.get_Apolice()) : string.Concat(string.Format("{0:d} - {1:d} - APÓLICE: {2}", documento1.get_Vigencia1(), documento1.get_Vigencia2(), documento1.get_Apolice()), (string.IsNullOrEmpty(documento1.get_Endosso()) ? "
" : string.Concat(" /", documento1.get_Endosso(), "
")))) ?? ""; - } - else - { - obj6 = null; - } - strArrays5[4] = (string)obj6; - strArrays5[5] = (documento1.get_Apolice() == "PROSPECÇÃO" ? "" : string.Concat(documento1.get_Controle().get_Seguradora().get_Nome(), " - ", documento1.get_Controle().get_Ramo().get_Nome(), "
")); - if (this.MostrarVendedor) - { - obj7 = (documento1.get_VendedorPrincipal() == null ? "" : string.Concat("VENDEDOR: ", documento1.get_VendedorPrincipal().get_Nome())) ?? ""; - } - else - { - obj7 = null; - } - strArrays5[6] = (string)obj7; - str18 = string.Concat(strArrays5); - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, "
"); - str18 = string.Concat(str18, "
"); - } - } - base.RegistrarAcao(string.Format("EMITIU ETIQUETA DE {0} DOCUMENTO{1}", list.Count, (list.Count == 1 ? "" : "S")), (long)0, new TipoTela?(59), string.Concat("IDS DOS DOCUMENTOS:\n", string.Join(", ", - from x in list - select x.get_Id()))); - } - str18 = string.Concat(str18, ""); - string tempPath = Path.GetTempPath(); - string str19 = string.Format("{0}{1}_{2:ddMMyyyyhhmmss}.html", tempPath, (TipoExtrato)0, Funcoes.GetNetworkTime()); - StreamWriter streamWriter = new StreamWriter(str19, true, Encoding.UTF8); - streamWriter.Write(str18); - streamWriter.Close(); - Process.Start(str19); - } - - private void EntryOnPropertyChanged(object sender, PropertyChangedEventArgs args) - { - if (args.PropertyName == "Selecionado") - { - this.RecheckAllSelected(); - } - } - - internal async Task> Filtrar(string value) - { - List documentos = await Task.Run>(() => this.FiltrarApolice(value)); - return documentos; - } - - public List FiltrarApolice(string filter) - { - this.ApolicesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Apolices) : new ObservableCollection( - from x in this.Apolices - where ValidationHelper.RemoveDiacritics(x.get_Controle().get_Cliente().get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Controle().get_Cliente().get_Nome() descending, x.get_Id() - select x)); - return this.ApolicesFiltrados.ToList(); - } - - private void RecheckAllSelected() - { - if (this._allSelectedChanging) - { - return; - } - try - { - this._allSelectedChanging = true; - if (this.Apolices.All((Documento e) => e.get_Selecionado())) - { - this.AllSelected = new bool?(true); - } - else if (!this.Apolices.All((Documento e) => !e.get_Selecionado())) - { - this.AllSelected = null; - } - else - { - this.AllSelected = new bool?(false); - } - } - finally - { - this._allSelectedChanging = false; - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs deleted file mode 100644 index 89f3758..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs +++ /dev/null @@ -1,110 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.ViewModels.Generic; -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.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class IncluirRamoViewModel : BaseSegurosViewModel - { - private Ramo _selectedRamo; - - private Ramo _adicionarRamo; - - private List _ramosAdicionadas; - - private ObservableCollection _ramos; - - private string _filtro; - - public Ramo AdicionarRamo - { - get - { - return this._adicionarRamo; - } - set - { - this._adicionarRamo = value; - base.OnPropertyChanged("AdicionarRamo"); - } - } - - public string Filtro - { - get - { - return this._filtro; - } - set - { - this._filtro = value; - base.OnPropertyChanged("Filtro"); - } - } - - public ObservableCollection Ramos - { - get - { - return this._ramos; - } - set - { - this._ramos = value; - base.OnPropertyChanged("Ramos"); - } - } - - public List RamosAdicionadas - { - get - { - return this._ramosAdicionadas; - } - set - { - this._ramosAdicionadas = value; - base.OnPropertyChanged("RamosAdicionadas"); - } - } - - public Ramo SelectedRamo - { - get - { - return this._selectedRamo; - } - set - { - this._selectedRamo = value; - base.OnPropertyChanged("SelectedRamo"); - } - } - - public IncluirRamoViewModel(List ramos) - { - this.RamosAdicionadas = ramos; - } - - public async void Pesquisar() - { - if (!string.IsNullOrWhiteSpace(this.Filtro) && this.Filtro.Length >= 3) - { - string str = Uri.EscapeDataString(this.Filtro); - List ramos = await Connection.Get>(string.Concat("Ramos/search?ramo=", str), true, false); - this.Ramos = new ObservableCollection( - from x in ramos - where this.RamosAdicionadas.All((Ramo y) => y.get_Id() != x.get_Id()) - select x); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs deleted file mode 100644 index ebeed40..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs +++ /dev/null @@ -1,110 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.ViewModels.Generic; -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.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class IncluirSeguradoraViewModel : BaseSegurosViewModel - { - private Seguradora _selectedSeguradora; - - private Seguradora _adicionarSeguradora; - - private List _seguradorasAdicionadas; - - private ObservableCollection _seguradoras; - - private string _filtro; - - public Seguradora AdicionarSeguradora - { - get - { - return this._adicionarSeguradora; - } - set - { - this._adicionarSeguradora = value; - base.OnPropertyChanged("AdicionarSeguradora"); - } - } - - public string Filtro - { - get - { - return this._filtro; - } - set - { - this._filtro = value; - base.OnPropertyChanged("Filtro"); - } - } - - public ObservableCollection Seguradoras - { - get - { - return this._seguradoras; - } - set - { - this._seguradoras = value; - base.OnPropertyChanged("Seguradoras"); - } - } - - public List SeguradorasAdicionadas - { - get - { - return this._seguradorasAdicionadas; - } - set - { - this._seguradorasAdicionadas = value; - base.OnPropertyChanged("SeguradorasAdicionadas"); - } - } - - public Seguradora SelectedSeguradora - { - get - { - return this._selectedSeguradora; - } - set - { - this._selectedSeguradora = value; - base.OnPropertyChanged("SelectedSeguradora"); - } - } - - public IncluirSeguradoraViewModel(List seguradoras) - { - this.SeguradorasAdicionadas = seguradoras; - } - - public async void Pesquisar() - { - if (!string.IsNullOrWhiteSpace(this.Filtro) && this.Filtro.Length >= 3) - { - string str = Uri.EscapeDataString(this.Filtro); - List seguradoras = await Connection.Get>(string.Concat("Seguradoras/search?cia=", str), true, false); - this.Seguradoras = new ObservableCollection( - from x in seguradoras - where this.SeguradorasAdicionadas.All((Seguradora y) => y.get_Id() != x.get_Id()) - select x); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/MalaDiretaViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/MalaDiretaViewModel.cs deleted file mode 100644 index 0009fb4..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/MalaDiretaViewModel.cs +++ /dev/null @@ -1,821 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.Servicos; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.Servicos.Seguros; -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.MalaDireta; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class MalaDiretaViewModel : BaseSegurosViewModel - { - private readonly MalaDiretaServico _servico; - - private readonly FiltroArquivoDigital _filtro; - - private ObservableCollection _malaDireta = new ObservableCollection(); - - private ObservableCollection _variaveis = new ObservableCollection(); - - private bool _enableCredencial; - - private ObservableCollection _modelos = new ObservableCollection(); - - private ComboModelo _selectedModelo = new ComboModelo(); - - private ComboVariavel _selectedVariavel; - - private string _assunto; - - private string _corpo; - - private ObservableCollection _credenciais = new ObservableCollection(); - - private Credencial _selectedCredencial = new Credencial(); - - private ObservableCollection _arquivos = new ObservableCollection(); - - private ObservableCollection _arquivosAnexados = new ObservableCollection(); - - private Gestor.Model.Domain.Common.ArquivoDigital _selectedAnexado = new Gestor.Model.Domain.Common.ArquivoDigital(); - - private Visibility _visibilitySalvarAnexos = Visibility.Hidden; - - private bool _enviarOriginal; - - private bool _salvarArquivoDigital; - - private bool _assinatura; - - public bool _confirmarLeitura; - - public ObservableCollection Arquivos - { - get - { - return this._arquivos; - } - set - { - this._arquivos = value; - base.OnPropertyChanged("Arquivos"); - } - } - - public ObservableCollection ArquivosAnexados - { - get - { - return this._arquivosAnexados; - } - set - { - this._arquivosAnexados = value; - base.OnPropertyChanged("ArquivosAnexados"); - } - } - - public bool Assinatura - { - get - { - return this._assinatura; - } - set - { - this._assinatura = value; - base.OnPropertyChanged("Assinatura"); - } - } - - public string Assunto - { - get - { - return this._assunto; - } - set - { - this._assunto = value; - base.OnPropertyChanged("Assunto"); - } - } - - public bool ConfirmarLeitura - { - get - { - return this._confirmarLeitura; - } - set - { - this._confirmarLeitura = value; - } - } - - public string Corpo - { - get - { - return this._corpo; - } - set - { - this._corpo = value; - base.OnPropertyChanged("Corpo"); - } - } - - public ObservableCollection Credenciais - { - get - { - return this._credenciais; - } - set - { - this._credenciais = value; - base.OnPropertyChanged("Credenciais"); - } - } - - public bool EnableCredencial - { - get - { - return this._enableCredencial; - } - set - { - this._enableCredencial = value; - base.OnPropertyChanged("EnableCredencial"); - } - } - - public bool Enviado - { - get; - set; - } - - public bool EnviarOriginal - { - get - { - return this._enviarOriginal; - } - set - { - this._enviarOriginal = value; - base.OnPropertyChanged("EnviarOriginal"); - } - } - - public ObservableCollection MalaDireta - { - get - { - return this._malaDireta; - } - set - { - this._malaDireta = value; - base.OnPropertyChanged("MalaDireta"); - } - } - - public ObservableCollection Modelos - { - get - { - return this._modelos; - } - set - { - Func func = null; - List list = ( - from variavel in (VariaveisMalaDireta[])Enum.GetValues(typeof(VariaveisMalaDireta)) - select ValidationHelper.GetEntity(variavel)).ToList(); - List strs = ( - from x in this.Variaveis - where !x.Indisponivel - select x into v - select ValidationHelper.GetEntity(v.VariaveisMalaDireta)).ToList(); - List comboModelos = new List(); - foreach (ComboModelo comboModelo in value) - { - IEnumerable strs1 = list.Where(new Func(comboModelo.ModeloMalaDireta.get_Corpo().Contains)); - Func func1 = func; - if (func1 == null) - { - Func func2 = (string s) => strs.Contains(s); - Func func3 = func2; - func = func2; - func1 = func3; - } - if (!strs1.All(func1)) - { - comboModelos.Add(new ComboModelo() - { - ModeloMalaDireta = comboModelo.ModeloMalaDireta, - Indisponivel = true - }); - } - else - { - comboModelos.Add(comboModelo); - } - } - this._modelos = new ObservableCollection( - from x in comboModelos - orderby x.Indisponivel, x.ModeloMalaDireta.get_Assunto() - select x); - base.OnPropertyChanged("Modelos"); - } - } - - public bool SalvarArquivoDigital - { - get - { - return this._salvarArquivoDigital; - } - set - { - this._salvarArquivoDigital = value; - base.OnPropertyChanged("SalvarArquivoDigital"); - } - } - - public Gestor.Model.Domain.Common.ArquivoDigital SelectedAnexado - { - get - { - return this._selectedAnexado; - } - set - { - this._selectedAnexado = value; - base.OnPropertyChanged("SelectedAnexado"); - } - } - - public Credencial SelectedCredencial - { - get - { - return this._selectedCredencial; - } - set - { - this._selectedCredencial = value; - base.OnPropertyChanged("SelectedCredencial"); - } - } - - public ComboModelo SelectedModelo - { - get - { - return this._selectedModelo; - } - set - { - long? nullable; - ModeloMalaDireta modeloMalaDireta; - this._selectedModelo = value; - if (value != null) - { - nullable = new long?(value.ModeloMalaDireta.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - if (value != null) - { - modeloMalaDireta = value.ModeloMalaDireta; - } - else - { - modeloMalaDireta = null; - } - this.WorkOnSelectedModelo(modeloMalaDireta); - base.OnPropertyChanged("SelectedModelo"); - } - } - - public ComboVariavel SelectedVariavel - { - get - { - return this._selectedVariavel; - } - set - { - this._selectedVariavel = value; - base.OnPropertyChanged("SelectedVariavel"); - } - } - - public ObservableCollection Variaveis - { - get - { - return this._variaveis; - } - set - { - this._variaveis = new ObservableCollection( - from x in value - orderby x.Indisponivel, x.VariaveisMalaDireta.ToString() - select x); - base.OnPropertyChanged("Variaveis"); - } - } - - public Visibility VisibilitySalvarAnexos - { - get - { - return this._visibilitySalvarAnexos; - } - set - { - this._visibilitySalvarAnexos = value; - base.OnPropertyChanged("VisibilitySalvarAnexos"); - } - } - - public MalaDiretaViewModel(FiltroArquivoDigital filtro = null) - { - this._servico = new MalaDiretaServico(); - this._filtro = filtro; - this.BuscarCredenciais(); - } - - public async void Anexar() - { - ObservableCollection arquivos = this.Arquivos; - List list = arquivos.Select((IndiceArquivoDigital x) => { - Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = new Gestor.Model.Domain.Common.ArquivoDigital(); - arquivoDigital.set_Descricao(x.get_Descricao()); - arquivoDigital.set_Extensao(x.get_Extensao()); - return arquivoDigital; - }).ToList(); - List arquivoDigitals = await base.AddAttachments(this.ArquivosAnexados.ToList(), list); - if (arquivoDigitals != null) - { - arquivoDigitals.AddRange(this.ArquivosAnexados); - this.ArquivosAnexados = new ObservableCollection(arquivoDigitals); - } - } - - private async void BuscarCredenciais() - { - Credencial credencial; - await base.PermissaoTela(39); - base.VerificarEnables(null); - List credencials = await (new BaseServico()).BuscarCredenciais(); - MalaDiretaViewModel observableCollection = this; - List credencials1 = credencials; - observableCollection.Credenciais = new ObservableCollection( - from x in credencials1 - orderby x.get_Descricao() - select x); - this.EnableCredencial = !base.Restricao(110); - MalaDiretaViewModel malaDiretaViewModel = this; - if (this.EnableCredencial) - { - ObservableCollection credenciais = this.Credenciais; - credencial = credenciais.FirstOrDefault((Credencial x) => x.get_IdUsuario() == Recursos.Usuario.get_Id()); - if (credencial == null) - { - credencial = this.Credenciais.FirstOrDefault(); - } - } - else - { - ObservableCollection credenciais1 = this.Credenciais; - credencial = credenciais1.FirstOrDefault((Credencial x) => x.get_IdUsuario() == Recursos.Usuario.get_Id()); - } - malaDiretaViewModel.SelectedCredencial = credencial; - } - - public void CancelarAlteracao() - { - base.Alterar(false); - this.SelectedModelo = null; - } - - public async Task CarregarEmails(List maladireta, string assunto = null, string corpo = null) - { - Visibility visibility; - ComboVariavel comboVariavel; - ComboVariavel comboVariavel1; - ComboVariavel comboVariavel2; - ComboVariavel comboVariavel3; - ComboVariavel comboVariavel4; - ComboVariavel comboVariavel5; - ComboVariavel comboVariavel6; - ComboVariavel comboVariavel7; - ClienteServico clienteServico = new ClienteServico(); - List malaDiretas = maladireta; - IEnumerable malaDiretas1 = - from x in malaDiretas - where x.get_Cliente() != null - select x; - List nums = ( - from x in malaDiretas1 - select x.get_Cliente().get_Id()).ToList(); - MalaDiretaViewModel malaDiretaViewModel = this; - visibility = (nums.Count > 1 ? Visibility.Hidden : Visibility.Visible); - malaDiretaViewModel.VisibilitySalvarAnexos = visibility; - List clienteEmails = await clienteServico.BuscarEmailsPorCliente(nums); - List malaDiretas2 = new List(); - maladireta.ForEach((Gestor.Model.Domain.MalaDireta.MalaDireta x) => { - bool flag; - if (x.get_Cliente() != null) - { - MalaDiretaViewModel u003cu003e4_this = this; - if (this.Assinatura) - { - flag = true; - } - else if (x.get_ArquivoDigital() == null) - { - flag = false; - } - else - { - List arquivoDigital = x.get_ArquivoDigital(); - Func u003cu003e9_8417 = MalaDiretaViewModel.u003cu003ec.u003cu003e9__84_17; - if (u003cu003e9_8417 == null) - { - u003cu003e9_8417 = (IndiceArquivoDigital a) => { - if (string.IsNullOrEmpty(a.get_UrlAssinatura())) - { - return false; - } - return !a.get_Assinado(); - }; - MalaDiretaViewModel.u003cu003ec.u003cu003e9__84_17 = u003cu003e9_8417; - } - flag = arquivoDigital.Any(u003cu003e9_8417); - } - u003cu003e4_this.Assinatura = flag; - List list = ( - from e in clienteEmails - where e.get_Cliente().get_Id() == this.x.get_Cliente().get_Id() - select e).ToList(); - int num = 0; - Func u003cu003e9_8419 = MalaDiretaViewModel.u003cu003ec.u003cu003e9__84_19; - if (u003cu003e9_8419 == null) - { - u003cu003e9_8419 = (ClienteEmail o) => o.get_Ordem().GetValueOrDefault(); - MalaDiretaViewModel.u003cu003ec.u003cu003e9__84_19 = u003cu003e9_8419; - } - list.OrderBy(u003cu003e9_8419).ToList().ForEach((ClienteEmail e) => { - x.set_Selecionado((!string.IsNullOrWhiteSpace(x.get_Email()) ? false : x.get_Cliente().get_MalaDireta().GetValueOrDefault(true))); - if (num <= 0) - { - x.set_Email(e.get_Email()); - x.set_Ordem(e.get_Ordem().GetValueOrDefault()); - Gestor.Model.Domain.MalaDireta.MalaDireta malaDiretum = new Gestor.Model.Domain.MalaDireta.MalaDireta(); - DomainBase.Copy(malaDiretum, x); - malaDiretas2.Add(malaDiretum); - } - else - { - Gestor.Model.Domain.MalaDireta.MalaDireta malaDiretum1 = new Gestor.Model.Domain.MalaDireta.MalaDireta(); - DomainBase.Copy(malaDiretum1, x); - malaDiretum1.set_Email(e.get_Email()); - malaDiretum1.set_Selecionado(false); - malaDiretas2.Add(malaDiretum1); - } - num++; - }); - } - if (x.get_Prospeccao() == null) - { - return; - } - Gestor.Model.Domain.MalaDireta.MalaDireta malaDiretum2 = new Gestor.Model.Domain.MalaDireta.MalaDireta(); - Gestor.Model.Domain.MalaDireta.MalaDireta malaDiretum3 = x; - Cliente cliente = x.get_Cliente(); - if (cliente == null) - { - cliente = new Cliente(); - cliente.set_Nome(x.get_Prospeccao().get_Nome()); - cliente.set_Documento(x.get_Prospeccao().get_Documento()); - } - malaDiretum3.set_Cliente(cliente); - if (string.IsNullOrEmpty(x.get_Cliente().get_Documento())) - { - x.get_Cliente().set_Documento(x.get_Prospeccao().get_Documento()); - } - x.set_Email(x.get_Prospeccao().get_Email()); - x.set_Ordem(0); - x.set_Selecionado(true); - DomainBase.Copy(malaDiretum2, x); - malaDiretas2.Add(malaDiretum2); - }); - MalaDiretaViewModel observableCollection = this; - List malaDiretas3 = malaDiretas2; - IOrderedEnumerable nome = - from x in malaDiretas3 - orderby x.get_Cliente().get_Nome() - select x; - observableCollection.MalaDireta = new ObservableCollection(nome.ThenBy((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Ordem())); - this.Variaveis.Add(new ComboVariavel(18, false)); - this.Variaveis.Add(new ComboVariavel(0, false)); - this.Variaveis.Add(new ComboVariavel(1, false)); - this.Variaveis.Add(new ComboVariavel(2, false)); - ObservableCollection variaveis = this.Variaveis; - ObservableCollection malaDireta = this.MalaDireta; - comboVariavel = (malaDireta.Any((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Cliente().get_VencimentoHabilitacao().HasValue) ? new ComboVariavel(16, false) : new ComboVariavel(16, true)); - variaveis.Add(comboVariavel); - ObservableCollection malaDireta1 = this.MalaDireta; - if (!malaDireta1.Any((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Cliente().get_Nascimento().HasValue)) - { - this.Variaveis.Add(new ComboVariavel(14, true)); - this.Variaveis.Add(new ComboVariavel(15, true)); - } - else - { - this.Variaveis.Add(new ComboVariavel(14, false)); - this.Variaveis.Add(new ComboVariavel(15, false)); - } - ObservableCollection variaveis1 = this.Variaveis; - ObservableCollection observableCollection1 = this.MalaDireta; - comboVariavel1 = (observableCollection1.Any((Gestor.Model.Domain.MalaDireta.MalaDireta x) => { - if (x.get_ArquivoDigital() == null) - { - return false; - } - return x.get_ArquivoDigital().Any((IndiceArquivoDigital z) => !string.IsNullOrWhiteSpace(z.get_UrlAssinatura())); - }) ? new ComboVariavel(17, false) : new ComboVariavel(17, true)); - variaveis1.Add(comboVariavel1); - ObservableCollection malaDireta2 = this.MalaDireta; - if (!malaDireta2.All((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Apolice() != null)) - { - this.Variaveis.Add(new ComboVariavel(19, true)); - this.Variaveis.Add(new ComboVariavel(3, true)); - this.Variaveis.Add(new ComboVariavel(4, true)); - this.Variaveis.Add(new ComboVariavel(7, true)); - this.Variaveis.Add(new ComboVariavel(8, true)); - this.Variaveis.Add(new ComboVariavel(5, true)); - this.Variaveis.Add(new ComboVariavel(6, true)); - } - else - { - this.Variaveis.Add(new ComboVariavel(3, false)); - this.Variaveis.Add(new ComboVariavel(4, false)); - this.Variaveis.Add(new ComboVariavel(7, false)); - ObservableCollection variaveis2 = this.Variaveis; - ObservableCollection observableCollection2 = this.MalaDireta; - comboVariavel7 = (observableCollection2.Any((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Apolice().get_Vigencia2().HasValue) ? new ComboVariavel(8, false) : new ComboVariavel(8, true)); - variaveis2.Add(comboVariavel7); - this.Variaveis.Add(new ComboVariavel(19, false)); - this.Variaveis.Add(new ComboVariavel(23, false)); - this.Variaveis.Add(new ComboVariavel(24, false)); - ObservableCollection malaDireta3 = this.MalaDireta; - if (!malaDireta3.Any((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Apolice().get_Controle() != null)) - { - this.Variaveis.Add(new ComboVariavel(5, true)); - this.Variaveis.Add(new ComboVariavel(6, true)); - } - else - { - this.Variaveis.Add(new ComboVariavel(5, false)); - this.Variaveis.Add(new ComboVariavel(6, false)); - } - } - ObservableCollection observableCollection3 = this.MalaDireta; - if (!observableCollection3.All((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Parcela() != null)) - { - this.Variaveis.Add(new ComboVariavel(9, true)); - this.Variaveis.Add(new ComboVariavel(10, true)); - this.Variaveis.Add(new ComboVariavel(13, true)); - } - else - { - this.Variaveis.Add(new ComboVariavel(9, false)); - this.Variaveis.Add(new ComboVariavel(10, false)); - this.Variaveis.Add(new ComboVariavel(13, false)); - } - ObservableCollection variaveis3 = this.Variaveis; - ObservableCollection malaDireta4 = this.MalaDireta; - comboVariavel2 = (malaDireta4.All((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Item() != null) ? new ComboVariavel(11, false) : new ComboVariavel(11, true)); - variaveis3.Add(comboVariavel2); - ObservableCollection variaveis4 = this.Variaveis; - ObservableCollection observableCollection4 = this.MalaDireta; - comboVariavel3 = (observableCollection4.All((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Sinistro() != null) ? new ComboVariavel(12, false) : new ComboVariavel(12, true)); - variaveis4.Add(comboVariavel3); - this.Variaveis = new ObservableCollection(this.Variaveis); - ObservableCollection variaveis5 = this.Variaveis; - ObservableCollection malaDireta5 = this.MalaDireta; - comboVariavel4 = (malaDireta5.Any((Gestor.Model.Domain.MalaDireta.MalaDireta x) => { - Documento apolice = x.get_Apolice(); - if (apolice == null) - { - return false; - } - apolice.get_PremioLiquido(); - return true; - }) ? new ComboVariavel(20, false) : new ComboVariavel(20, true)); - variaveis5.Add(comboVariavel4); - ObservableCollection observableCollection5 = this.Variaveis; - ObservableCollection malaDireta6 = this.MalaDireta; - comboVariavel5 = (malaDireta6.Any((Gestor.Model.Domain.MalaDireta.MalaDireta x) => { - Documento apolice = x.get_Apolice(); - if (apolice == null) - { - return false; - } - apolice.get_PremioTotal(); - return true; - }) ? new ComboVariavel(21, false) : new ComboVariavel(21, true)); - observableCollection5.Add(comboVariavel5); - ObservableCollection variaveis6 = this.Variaveis; - ObservableCollection observableCollection6 = this.MalaDireta; - comboVariavel6 = (observableCollection6.Any((Gestor.Model.Domain.MalaDireta.MalaDireta x) => { - Documento apolice = x.get_Apolice(); - if (apolice == null) - { - return false; - } - return apolice.get_FormaPagamento().HasValue; - }) ? new ComboVariavel(22, false) : new ComboVariavel(22, true)); - variaveis6.Add(comboVariavel6); - await this.CarregarModelos(null); - if (assunto != null) - { - this.Assunto = assunto; - } - if (corpo != null) - { - this.Corpo = corpo; - } - } - - private async Task CarregarModelos(ModeloMalaDireta modelo = null) - { - List modeloMalaDiretas = await this._servico.BuscarModelos(); - List comboModelos = new List(); - foreach (ModeloMalaDireta modeloMalaDiretum in modeloMalaDiretas) - { - comboModelos.Add(new ComboModelo() - { - ModeloMalaDireta = modeloMalaDiretum - }); - } - this.Modelos = new ObservableCollection(comboModelos); - if (modelo != null) - { - this.SelectedModelo = this.Modelos.FirstOrDefault((ComboModelo x) => x.ModeloMalaDireta.get_Id() == modelo.get_Id()); - } - } - - public void Delete(Gestor.Model.Domain.Common.ArquivoDigital arquivo) - { - if (this.SelectedAnexado == null) - { - return; - } - Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = this.ArquivosAnexados.First((Gestor.Model.Domain.Common.ArquivoDigital x) => x.get_Descricao() == arquivo.get_Descricao()); - this.ArquivosAnexados.Remove(arquivoDigital); - this.ArquivosAnexados = new ObservableCollection(this.ArquivosAnexados); - } - - public async Task Enviar() - { - bool flag; - if (string.IsNullOrWhiteSpace(this.Corpo) || string.IsNullOrWhiteSpace(this.Assunto)) - { - await base.ShowMessage("NECESSÁRIO CONTER ASSUNTO E MENSAGEM PARA PROSSEGUIR.", "OK", "", false); - flag = false; - } - else if (this.SelectedCredencial == null || this.SelectedCredencial.get_Id() == 0) - { - await base.ShowMessage("NECESSÁRIO SELECIONAR O E-MAIL DE ENVIO PARA PROSSEGUIR.", "OK", "", false); - flag = false; - } - else - { - ObservableCollection malaDireta = this.MalaDireta; - List list = ( - from x in malaDireta - where x.get_Selecionado() - select x).ToList(); - if (list.Count != 0) - { - await base.ShowEnviarEmailsDialog(list, this.Assinatura, this.EnviarOriginal, this.ArquivosAnexados.ToList(), this.Assunto, this.Corpo, this.SelectedCredencial, this._filtro, this.SalvarArquivoDigital, this.ConfirmarLeitura); - this.Enviado = true; - flag = true; - } - else - { - await base.ShowMessage("NECESSÁRIO SELECIONAR AO MENOS UM DESTINATÁRIO PARA PROSSEGUIR.", "OK", "", false); - flag = false; - } - } - return flag; - } - - public async void Excluir() - { - if (this.SelectedModelo != null && this.SelectedModelo.ModeloMalaDireta.get_Id() != 0) - { - if (await base.ShowMessage("DESEJA REALMENTE EXCLUIR O MODELO?", "SIM", "NÃO", false)) - { - if (await this._servico.Delete(this.SelectedModelo.ModeloMalaDireta)) - { - base.RegistrarAcao(string.Concat("EXCLUIU MODELO ", this.SelectedModelo.ModeloMalaDireta.get_Assunto()), this.SelectedModelo.ModeloMalaDireta.get_Id(), new TipoTela?(39), null); - await this.CarregarModelos(null); - this.SelectedModelo = null; - base.ToggleSnackBar("MODELO EXCLUÍDO COM SUCESSO", true); - } - } - } - } - - public void Incluir() - { - this.SelectedModelo = new ComboModelo(); - this.Corpo = string.Empty; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - if (this.SelectedModelo != null) - { - this.SelectedModelo.ModeloMalaDireta.set_Assunto(this.Assunto); - this.SelectedModelo.ModeloMalaDireta.set_Corpo(this.Corpo); - } - else - { - ComboModelo comboModelo = new ComboModelo(); - ModeloMalaDireta modeloMalaDiretum = new ModeloMalaDireta(); - modeloMalaDiretum.set_Assunto(this.Assunto); - modeloMalaDiretum.set_Corpo(this.Corpo); - comboModelo.ModeloMalaDireta = modeloMalaDiretum; - this.SelectedModelo = comboModelo; - } - List> keyValuePairs1 = this.SelectedModelo.ModeloMalaDireta.Validate(); - if (keyValuePairs1.Count <= 0) - { - ModeloMalaDireta modeloMalaDiretum1 = await this._servico.Save(this.SelectedModelo.ModeloMalaDireta); - if (this._servico.Sucesso) - { - base.Alterar(false); - await this.CarregarModelos(modeloMalaDiretum1); - base.ToggleSnackBar("MODELO SALVO COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - return keyValuePairs; - } - - public void Selecionar() - { - this.MalaDireta.ToList().ForEach((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.set_Selecionado(!x.get_Selecionado())); - this.MalaDireta = new ObservableCollection(this.MalaDireta); - } - - private void WorkOnSelectedModelo(ModeloMalaDireta value) - { - if (value == null) - { - return; - } - this.Corpo = this.SelectedModelo.ModeloMalaDireta.get_Corpo(); - this.Assunto = this.SelectedModelo.ModeloMalaDireta.get_Assunto(); - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/ManutencaoPagamentosViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/ManutencaoPagamentosViewModel.cs deleted file mode 100644 index 5270c3f..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/ManutencaoPagamentosViewModel.cs +++ /dev/null @@ -1,821 +0,0 @@ -using CsQuery.ExtensionMethods; -using Gestor.Application.Helpers; -using Gestor.Application.Servicos; -using Gestor.Application.Servicos.Ferramentas; -using Gestor.Application.ViewModels.Generic; -using Gestor.Model.Common; -using Gestor.Model.Domain.Ferramentas; -using Gestor.Model.Domain.Generic; -using Gestor.Model.Domain.Relatorios; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Data; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class ManutencaoPagamentosViewModel : BaseSegurosViewModel - { - private Visibility _filtrosPersonalizados = Visibility.Collapsed; - - private Visibility _visibilityFiltroPersonalizado = Visibility.Collapsed; - - private List _filtroRelatorioPersonalizado; - - private Gestor.Model.Domain.Relatorios.FiltroPersonalizado _filtroPersonalizado; - - private Type _tipoString = typeof(string); - - private Type _tipoEnum = typeof(Enum); - - private Type _tipoDateTime = typeof(DateTime); - - private Type _tipoDecimal = typeof(decimal); - - private Type _tipoInt = typeof(int); - - private Type _tipoLong = typeof(long); - - private string _valorIncial = ""; - - private string _valorFinal = ""; - - private bool _semValor; - - private Visibility _visibilitySemValor = Visibility.Collapsed; - - private ObservableCollection _filtroPersonalizadoSelecionado; - - private ObservableCollection _filtroRelatorioSelecionado = new ObservableCollection(); - - private ObservableCollection _vendedores = new ObservableCollection(); - - private Vendedor _selectedVendedor; - - private bool _enableExcluirManutPagamento; - - private ObservableCollection _pagamentos; - - private ListCollectionView _view; - - private bool _allSelected; - - private string _selectedFiltro; - - private ObservableCollection _filtros; - - private DateTime? _inicio; - - private DateTime? _fim; - - private List _todosPagamentos; - - public bool AllSelected - { - get - { - return this._allSelected; - } - set - { - this._allSelected = value; - base.OnPropertyChanged("AllSelected"); - this.Selecionar(value); - } - } - - public bool EnableExcluirManutPagamento - { - get - { - return this._enableExcluirManutPagamento; - } - set - { - this._enableExcluirManutPagamento = value; - base.OnPropertyChanged("EnableExcluirManutPagamento"); - } - } - - public Gestor.Model.Domain.Relatorios.FiltroPersonalizado FiltroPersonalizado - { - get - { - return this._filtroPersonalizado; - } - set - { - char chr; - this._filtroPersonalizado = value; - this.VisibilitySemValor = (value != null ? Visibility.Visible : Visibility.Collapsed); - base.OnPropertyChanged("FiltroPersonalizado"); - if (value == null) - { - return; - } - string name = value.get_Tipo().Name; - if (name != null) - { - switch (name.Length) - { - case 3: - { - if (name == "int") - { - break; - } - return; - } - case 4: - { - chr = name[0]; - if (chr == 'E') - { - if (name == "Enum") - { - this.ValorInicial = null; - this.ValorFinal = null; - return; - } - return; - } - else - { - if (chr != 'l') - { - return; - } - if (name == "long") - { - break; - } - return; - } - } - case 5: - { - chr = name[3]; - if (chr == '3') - { - if (name == "int32") - { - break; - } - return; - } - else - { - if (chr != '6') - { - return; - } - if (name == "int64") - { - break; - } - return; - } - } - case 6: - { - if (name != "String") - { - return; - } - this.ValorInicial = ""; - this.ValorFinal = ""; - return; - } - case 7: - { - if (name != "Decimal") - { - return; - } - this.ValorInicial = "0,00"; - this.ValorFinal = "0,00"; - return; - } - case 8: - { - if (name == "DateTime") - { - this.ValorInicial = null; - this.ValorFinal = null; - return; - } - return; - } - default: - { - return; - } - } - this.ValorInicial = "0"; - this.ValorFinal = "0"; - } - } - } - - public ObservableCollection FiltroPersonalizadoSelecionado - { - get - { - return this._filtroPersonalizadoSelecionado; - } - set - { - this._filtroPersonalizadoSelecionado = value; - base.OnPropertyChanged("FiltroPersonalizadoSelecionado"); - } - } - - public ObservableCollection FiltroRelatorioSelecionado - { - get - { - return this._filtroRelatorioSelecionado; - } - set - { - this._filtroRelatorioSelecionado = value; - base.OnPropertyChanged("FiltroRelatorioSelecionado"); - } - } - - public ObservableCollection Filtros - { - get - { - return this._filtros; - } - set - { - this._filtros = value; - base.OnPropertyChanged("Filtros"); - } - } - - public Visibility FiltrosPersonalizados - { - get - { - return this._filtrosPersonalizados; - } - set - { - this._filtrosPersonalizados = value; - base.OnPropertyChanged("FiltrosPersonalizados"); - } - } - - public DateTime? Fim - { - get - { - return this._fim; - } - set - { - if (value.HasValue && value.Value < new DateTime(1754, 1, 1)) - { - value = new DateTime?(new DateTime(1754, 1, 1)); - } - if (value.HasValue && value.Value > new DateTime(9999, 12, 31)) - { - value = new DateTime?(new DateTime(9999, 12, 31)); - } - this._fim = value; - base.OnPropertyChanged("Fim"); - } - } - - public DateTime? Inicio - { - get - { - return this._inicio; - } - set - { - if (value.HasValue && value.Value < new DateTime(1754, 1, 1)) - { - value = new DateTime?(new DateTime(1754, 1, 1)); - } - if (value.HasValue && value.Value > new DateTime(9999, 12, 31)) - { - value = new DateTime?(new DateTime(9999, 12, 31)); - } - this._inicio = value; - base.OnPropertyChanged("Inicio"); - } - } - - public ObservableCollection Pagamentos - { - get - { - return this._pagamentos; - } - set - { - this._pagamentos = value; - this.View = new ListCollectionView(value); - this.View.GroupDescriptions.Add(new PropertyGroupDescription("Pagamento")); - this.View.GroupDescriptions.Add(new PropertyGroupDescription("Vendedor")); - base.OnPropertyChanged("Pagamentos"); - } - } - - public List RelatorioFiltroPersonalizado - { - get - { - return this._filtroRelatorioPersonalizado; - } - set - { - this._filtroRelatorioPersonalizado = value; - base.OnPropertyChanged("RelatorioFiltroPersonalizado"); - } - } - - public string SelectedFiltro - { - get - { - return this._selectedFiltro; - } - set - { - this._selectedFiltro = value; - base.OnPropertyChanged("SelectedFiltro"); - } - } - - public Vendedor SelectedVendedor - { - get - { - return this._selectedVendedor; - } - set - { - this._selectedVendedor = value; - base.OnPropertyChanged("SelectedVendedor"); - } - } - - public bool SemValor - { - get - { - return this._semValor; - } - set - { - this._semValor = value; - if (value) - { - this.ValorInicial = null; - this.ValorFinal = null; - } - base.OnPropertyChanged("SemValor"); - } - } - - public Type TipoDateTime - { - get - { - return this._tipoDateTime; - } - set - { - this._tipoDateTime = value; - base.OnPropertyChanged("TipoDateTime"); - } - } - - public Type TipoDecimal - { - get - { - return this._tipoDecimal; - } - set - { - this._tipoDecimal = value; - base.OnPropertyChanged("TipoDecimal"); - } - } - - public Type TipoEnum - { - get - { - return this._tipoEnum; - } - set - { - this._tipoEnum = value; - base.OnPropertyChanged("TipoEnum"); - } - } - - public Type TipoInt - { - get - { - return this._tipoInt; - } - set - { - this._tipoInt = value; - base.OnPropertyChanged("TipoInt"); - } - } - - public Type TipoLong - { - get - { - return this._tipoLong; - } - set - { - this._tipoLong = value; - base.OnPropertyChanged("TipoLong"); - } - } - - public Type TipoString - { - get - { - return this._tipoString; - } - set - { - this._tipoString = value; - base.OnPropertyChanged("TipoString"); - } - } - - private List TodosPagamentos - { - get - { - return this._todosPagamentos; - } - set - { - this.FiltrosPersonalizados = (value == null || !value.Any() ? Visibility.Collapsed : Visibility.Visible); - this._todosPagamentos = value; - } - } - - public string ValorFinal - { - get - { - return this._valorFinal; - } - set - { - this._valorFinal = value; - base.OnPropertyChanged("ValorFinal"); - } - } - - public string ValorInicial - { - get - { - return this._valorIncial; - } - set - { - this._valorIncial = value; - base.OnPropertyChanged("ValorInicial"); - } - } - - public ObservableCollection Vendedores - { - get - { - return this._vendedores; - } - set - { - this._vendedores = value; - this.SelectedVendedor = this.SelectedVendedor ?? value.FirstOrDefault(); - base.OnPropertyChanged("Vendedores"); - } - } - - public ListCollectionView View - { - get - { - return this._view; - } - set - { - this._view = value; - base.OnPropertyChanged("View"); - } - } - - public Visibility VisibilityFiltroPersonalizado - { - get - { - return this._visibilityFiltroPersonalizado; - } - set - { - this._visibilityFiltroPersonalizado = value; - base.OnPropertyChanged("VisibilityFiltroPersonalizado"); - } - } - - public Visibility VisibilitySemValor - { - get - { - return this._visibilitySemValor; - } - set - { - this._visibilitySemValor = value; - base.OnPropertyChanged("VisibilitySemValor"); - } - } - - public ManutencaoPagamentosViewModel() - { - this._filtrosPersonalizados = Visibility.Collapsed; - this._visibilityFiltroPersonalizado = Visibility.Collapsed; - this._tipoString = typeof(string); - this._tipoEnum = typeof(Enum); - this._tipoDateTime = typeof(DateTime); - this._tipoDecimal = typeof(decimal); - this._tipoInt = typeof(int); - this._tipoLong = typeof(long); - this._valorIncial = ""; - this._valorFinal = ""; - this._visibilitySemValor = Visibility.Collapsed; - this._filtroRelatorioSelecionado = new ObservableCollection(); - this._vendedores = new ObservableCollection(); - Usuario usuario = Recursos.Usuario; - if (usuario != null) - { - id = usuario.get_Id() > (long)0; - } - else - { - id = false; - } - this._enableExcluirManutPagamento = id; - this._inicio = new DateTime?(Funcoes.GetNetworkTime()); - DateTime networkTime = Funcoes.GetNetworkTime(); - this._fim = new DateTime?(networkTime.AddDays(7)); - base(); - bool id; - this.Filtros = new ObservableCollection() - { - "DATA DE EMISSÃO DO RECEBIMENTO", - "DATA DE EMISSÃO DO RECIBO DE PAGAMENTO" - }; - this.SelectedFiltro = this.Filtros.First(); - List list = ( - from x in Recursos.Vendedores - where x.get_Ativo() - orderby x.get_Nome() - select x).ToList(); - Vendedor vendedor = new Vendedor(); - vendedor.set_Id((long)0); - vendedor.set_Nome("TODAS OS VENDEDORES"); - list.Insert(0, vendedor); - this.Vendedores = new ObservableCollection(list); - this.RelatorioFiltroPersonalizado = Funcoes.PopularFiltroPersonalizado(); - } - - public async void AdcionarFiltroPersonalizado() - { - string str; - DateTime dateTime; - decimal num; - int num1; - long num2; - List filtroPersonalizados; - List filtroPersonalizados1; - if (this.FiltroPersonalizado != null) - { - if (this.SemValor) - { - filtroPersonalizados = (this.FiltroPersonalizadoSelecionado == null ? new List() : ( - from x in this.FiltroPersonalizadoSelecionado - where x.get_Propriedade() == this.FiltroPersonalizado.get_Propriedade() - select x).ToList()); - List filtroPersonalizados2 = filtroPersonalizados; - if (filtroPersonalizados2.Count > 0) - { - filtroPersonalizados2.ForEach((Gestor.Model.Domain.Relatorios.FiltroPersonalizado x) => this.FiltroPersonalizadoSelecionado.Remove(x)); - } - str = string.Concat(this.FiltroPersonalizado.get_Nome(), ": EM BRANCO"); - } - else - { - filtroPersonalizados1 = (this.FiltroPersonalizadoSelecionado == null ? new List() : this.FiltroPersonalizadoSelecionado.Where((Gestor.Model.Domain.Relatorios.FiltroPersonalizado x) => { - if (x.get_Propriedade() != this.FiltroPersonalizado.get_Propriedade()) - { - return false; - } - return x.get_SemValor(); - }).ToList()); - List filtroPersonalizados3 = filtroPersonalizados1; - if (filtroPersonalizados3.Count > 0) - { - filtroPersonalizados3.ForEach((Gestor.Model.Domain.Relatorios.FiltroPersonalizado x) => this.FiltroPersonalizadoSelecionado.Remove(x)); - } - string name = this.FiltroPersonalizado.get_Tipo().Name; - if (name == "DateTime") - { - if (!DateTime.TryParse(this.ValorInicial, out dateTime) || !DateTime.TryParse(this.ValorFinal, out dateTime) || DateTime.Parse(this.ValorInicial) > DateTime.Parse(this.ValorFinal)) - { - await base.ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); - return; - } - else - { - str = string.Format("{0}: {1:d} até {2:d}", this.FiltroPersonalizado.get_Nome(), DateTime.Parse(this.ValorInicial), DateTime.Parse(this.ValorFinal)); - } - } - else if (name == "Decimal") - { - if (!decimal.TryParse(this.ValorInicial, out num) || !decimal.TryParse(this.ValorFinal, out num) || Math.Abs(decimal.Parse(this.ValorInicial)) > Math.Abs(decimal.Parse(this.ValorFinal))) - { - await base.ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); - return; - } - else - { - str = string.Format("{0}: {1:n2} até {2:n2}", this.FiltroPersonalizado.get_Nome(), decimal.Parse(this.ValorInicial), decimal.Parse(this.ValorFinal)); - } - } - else if (name == "Int32") - { - if (!int.TryParse(this.ValorInicial, out num1) || !int.TryParse(this.ValorFinal, out num1) || int.Parse(this.ValorInicial) > int.Parse(this.ValorFinal)) - { - await base.ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); - return; - } - else - { - str = string.Format("{0}: {1:n0} até {2:n0}", this.FiltroPersonalizado.get_Nome(), int.Parse(this.ValorInicial), int.Parse(this.ValorFinal)); - } - } - else if (name != "Int64") - { - if (!string.IsNullOrEmpty(this.ValorInicial)) - { - str = string.Concat(this.FiltroPersonalizado.get_Nome(), " = ", this.ValorInicial); - } - else - { - await base.ShowMessage("O VALOR DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); - return; - } - } - else if (!long.TryParse(this.ValorInicial, out num2) || !long.TryParse(this.ValorFinal, out num2) || long.Parse(this.ValorInicial) > (long)int.Parse(this.ValorFinal)) - { - await base.ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); - return; - } - else - { - str = string.Format("{0}: {1:n0} até {2:n0}", this.FiltroPersonalizado.get_Nome(), long.Parse(this.ValorInicial), long.Parse(this.ValorFinal)); - } - } - if (this.FiltroPersonalizadoSelecionado == null) - { - this.FiltroPersonalizadoSelecionado = new ObservableCollection(); - } - ObservableCollection filtroPersonalizadoSelecionado = this.FiltroPersonalizadoSelecionado; - Gestor.Model.Domain.Relatorios.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Relatorios.FiltroPersonalizado(); - filtroPersonalizado.set_Nome(this.FiltroPersonalizado.get_Nome()); - filtroPersonalizado.set_Propriedade(this.FiltroPersonalizado.get_Propriedade()); - filtroPersonalizado.set_Tipo(this.FiltroPersonalizado.get_Tipo()); - filtroPersonalizado.set_ValorIncial(this.ValorInicial); - filtroPersonalizado.set_ValorFinal(this.ValorFinal); - filtroPersonalizado.set_SemValor(this.SemValor); - filtroPersonalizado.set_Descricao(str); - filtroPersonalizadoSelecionado.Add(filtroPersonalizado); - this.FiltroPersonalizado = null; - this.ValorInicial = string.Empty; - this.ValorFinal = string.Empty; - this.PesquisaPersonalizada(); - } - } - - public async Task Buscar() - { - if (this.Inicio.HasValue && this.Fim.HasValue) - { - this.FiltroPersonalizadoSelecionado = null; - this.VisibilityFiltroPersonalizado = Visibility.Visible; - Gestor.Model.Domain.Relatorios.Filtros filtro = new Gestor.Model.Domain.Relatorios.Filtros(); - filtro.set_Inicio(this.Inicio.Value); - filtro.set_Fim(this.Fim.Value); - Gestor.Model.Domain.Relatorios.Filtros filtro1 = filtro; - if (this.SelectedVendedor.get_Id() > (long)0) - { - filtro1.set_Vendedores(new List() - { - this.SelectedVendedor.get_Id() - }); - } - if (this.SelectedFiltro == "DATA DE EMISSÃO DO RECEBIMENTO") - { - filtro1.set_Referencia("DATA PREVISÃO"); - } - else - { - filtro1.set_Referencia("DATA PAGAMENTO"); - } - this.TodosPagamentos = await (new VendedorServico()).BuscarPagos(filtro1); - this.Pagamentos = new ObservableCollection(this.TodosPagamentos); - string[] shortDateString = new string[] { "CONSULTOU OS PAGAMENTOS DE \"", null, null, null, null, null }; - DateTime value = this.Inicio.Value; - shortDateString[1] = value.ToShortDateString(); - shortDateString[2] = "\" A \""; - value = this.Fim.Value; - shortDateString[3] = value.ToShortDateString(); - shortDateString[4] = "\" POR "; - shortDateString[5] = this.SelectedFiltro; - base.RegistrarAcao(string.Concat(shortDateString), (long)0, new TipoTela?(58), null); - } - } - - public async Task Excluir() - { - object obj; - string str; - ObservableCollection pagamentos = this.Pagamentos; - List list = ( - from x in pagamentos - where x.get_Selecionado() - select x).ToList(); - if (list.Count != 0) - { - str = "PAGAMENTOS EXCLUÍDOS:"; - foreach (ManutencaoPagamentos manutencaoPagamento in list) - { - str = string.Concat(str, string.Format("\nID: {0}, NÚMERO: {1}, ID DOCUMENTO: {2}", manutencaoPagamento.get_Id(), manutencaoPagamento.get_Parcela(), manutencaoPagamento.get_IdDocumento())); - VendedorParcela vendedorParcela = await (new VendedorServico()).BuscarVendedorParcelaCompleto(manutencaoPagamento.get_Id()); - vendedorParcela.set_DataPagamento(null); - await (new ParcelaServico()).Save(vendedorParcela); - } - ManutencaoPagamentosViewModel manutencaoPagamentosViewModel = this; - object count = list.Count; - obj = (list.Count > 1 ? "S" : ""); - manutencaoPagamentosViewModel.RegistrarAcao(string.Format("EXCLUIU {0} PAGAMENTO{1}", count, obj), (long)0, new TipoTela?(58), str); - for (int i = this.Pagamentos.Count - 1; i >= 0; i--) - { - if (this.Pagamentos[i].get_Selecionado()) - { - this.Pagamentos.RemoveAt(i); - } - } - base.ToggleSnackBar("PAGAMENTOS EXCLUÍDOS COM SUCESSO.", true); - } - list = null; - str = null; - } - - public void PesquisaPersonalizada() - { - this.Pagamentos = new ObservableCollection(this.TodosPagamentos.CustomWhere(this.FiltroPersonalizadoSelecionado.ToList(), false)); - } - - public void Selecionar(bool value) - { - if (this.Pagamentos == null || this.Pagamentos.Count == 0) - { - return; - } - ExtensionMethods.ForEach(this.Pagamentos, (ManutencaoPagamentos x) => x.set_Selecionado(value)); - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/NotaFiscalViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/NotaFiscalViewModel.cs deleted file mode 100644 index 61ee285..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/NotaFiscalViewModel.cs +++ /dev/null @@ -1,482 +0,0 @@ -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.Configuracoes; -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.Globalization; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class NotaFiscalViewModel : BaseSegurosViewModel - { - private readonly NotaFiscalServico _servico; - - private readonly ServicoExtrato _servicoExtrato; - - private bool _apelido; - - private List _estipulantes; - - private List _seguradoras; - - private ObservableCollection _notasFiscaisFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - private string _numExtrato; - - private NotaFiscal _selectedNotaFiscal; - - public NotaFiscal CancelNotaFiscal; - - public bool Apelido - { - get - { - return this._apelido; - } - set - { - this._apelido = value; - base.OnPropertyChanged("Apelido"); - } - } - - public List Estipulantes - { - get - { - return this._estipulantes; - } - set - { - this._estipulantes = value; - base.OnPropertyChanged("Estipulantes"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public List NotasFiscais - { - get; - set; - } - - public ObservableCollection NotasFiscaisFiltrados - { - get - { - return this._notasFiscaisFiltrados; - } - set - { - this._notasFiscaisFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("NotasFiscaisFiltrados"); - } - } - - public string NumExtrato - { - get - { - return this._numExtrato; - } - set - { - this._numExtrato = value; - base.OnPropertyChanged("NumExtrato"); - } - } - - public List Seguradoras - { - get - { - return this._seguradoras; - } - set - { - this._seguradoras = value; - base.OnPropertyChanged("Seguradoras"); - } - } - - public NotaFiscal SelectedNotaFiscal - { - get - { - return this._selectedNotaFiscal; - } - set - { - long? nullable; - this._selectedNotaFiscal = value; - this.WorkOnSelectedNotaFiscal(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedNotaFiscal"); - } - } - - public NotaFiscalViewModel() - { - this._servicoExtrato = new ServicoExtrato(); - this._servico = new NotaFiscalServico(); - this.Seguradoras = ( - from x in Recursos.Seguradoras - where x.get_Ativo() - select x).ToList(); - this.Estipulantes = ( - from e in Recursos.Estipulantes - where e.get_Ativo() - select e).ToList(); - this.Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 6); - base.EnableMenu = true; - this.Seleciona(); - } - - public async Task BuscarImposto() - { - decimal iss; - List impostos = await (new ImpostoServico()).Buscar(new bool?(true)); - Imposto imposto = impostos.FirstOrDefault((Imposto x) => { - if (x.get_Seguradora() == null || x.get_Seguradora().get_Id() != this.SelectedNotaFiscal.get_Seguradora().get_Id()) - { - return false; - } - return x.get_Ramo() == null; - }); - if (imposto == null) - { - List impostos1 = impostos; - imposto = impostos1.FirstOrDefault((Imposto x) => { - if (x.get_Seguradora() != null) - { - return false; - } - return x.get_Ramo() == null; - }); - } - if (imposto != null) - { - iss = imposto.get_Iss(); - } - else - { - iss = decimal.Zero; - } - return iss; - } - - public void CancelarAlteracao() - { - if (this.CancelNotaFiscal == null || !this.NotasFiscais.Any((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.NotasFiscais.First((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id()), this.CancelNotaFiscal); - if (this.NotasFiscaisFiltrados.Count <= 0 || !this.NotasFiscaisFiltrados.Any((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id())) - { - this.NotasFiscaisFiltrados.Add(this.CancelNotaFiscal); - } - else - { - DomainBase.Copy(this.NotasFiscaisFiltrados.First((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id()), this.CancelNotaFiscal); - } - this.NotasFiscaisFiltrados = new ObservableCollection(this.NotasFiscaisFiltrados); - this.SelectedNotaFiscal = this.NotasFiscaisFiltrados.First((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id()); - } - base.Alterar(false); - } - - public async void Excluir() - { - object obj; - if (this.SelectedNotaFiscal != null && this.SelectedNotaFiscal.get_Id() != 0) - { - if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR A NOTA FISCAL DA ", this.SelectedNotaFiscal.get_Seguradora().get_Nome(), "?"), "SIM", "NÃO", false)) - { - base.Loading(true); - if (await this._servico.Delete(this.SelectedNotaFiscal)) - { - NotaFiscalViewModel notaFiscalViewModel = this; - string str = string.Format("EXCLUIU NOTA FISCAL DE ID \"{0}\"", this.SelectedNotaFiscal.get_Id()); - long id = this.SelectedNotaFiscal.get_Id(); - TipoTela? nullable = new TipoTela?(55); - object[] nome = new object[] { this.SelectedNotaFiscal.get_Seguradora().get_Nome(), null, null, null, null }; - obj = (!this.SelectedNotaFiscal.get_Data().HasValue ? "-" : string.Format("{0:d}", this.SelectedNotaFiscal.get_Data())); - nome[1] = obj; - nome[2] = this.SelectedNotaFiscal.get_ValorBruto(); - nome[3] = this.SelectedNotaFiscal.get_Iss(); - nome[4] = this.SelectedNotaFiscal.get_ValorLiquido(); - notaFiscalViewModel.RegistrarAcao(str, id, nullable, string.Format("SEGURADORA: {0}\nDATA: {1}\nBRUTO: {2:c}\nISS: {3:c}\nLÍQUIDO: {4:c}", nome)); - await this.SelecionaNotaFiscal(); - base.Loading(false); - base.ToggleSnackBar("RECIBO EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - public async Task> Filtrar(string value) - { - List notaFiscals = await Task.Run>(() => this.FiltrarNotaFiscal(value)); - return notaFiscals; - } - - public List FiltrarNotaFiscal(string filter) - { - this.NotasFiscaisFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.NotasFiscais) : new ObservableCollection(this.NotasFiscais.Where((NotaFiscal x) => { - if (ValidationHelper.RemoveDiacritics(x.get_Seguradora().get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) || ValidationHelper.RemoveDiacritics(x.get_ValorBruto().ToString(CultureInfo.InvariantCulture).Trim()).Contains(ValidationHelper.RemoveDiacritics(filter))) - { - return true; - } - return ValidationHelper.RemoveDiacritics(x.get_Data().ToString().Trim()).Contains(ValidationHelper.RemoveDiacritics(filter)); - }).OrderBy((NotaFiscal x) => x.get_Seguradora().get_Nome()))); - return this.NotasFiscaisFiltrados.ToList(); - } - - public void Incluir() - { - NotaFiscal notaFiscal = new NotaFiscal(); - notaFiscal.set_Seguradora(new Seguradora()); - notaFiscal.set_Estipulante(new Estipulante()); - notaFiscal.set_Iss(decimal.Zero); - notaFiscal.set_ValorLiquido(decimal.Zero); - notaFiscal.set_ValorBruto(decimal.Zero); - notaFiscal.set_Extrato(""); - this.SelectedNotaFiscal = notaFiscal; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - long? nullable; - bool valueOrDefault; - object obj; - string str1; - List> keyValuePairs1 = this.SelectedNotaFiscal.Validate(); - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedNotaFiscal.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - NotaFiscal selectedNotaFiscal = this.SelectedNotaFiscal; - if (selectedNotaFiscal != null) - { - Estipulante estipulante = selectedNotaFiscal.get_Estipulante(); - if (estipulante != null) - { - nullable = new long?(estipulante.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long num = (long)0; - valueOrDefault = nullable1.GetValueOrDefault() <= num & nullable1.HasValue; - } - else - { - valueOrDefault = false; - } - if (valueOrDefault) - { - this.SelectedNotaFiscal.set_Estipulante(null); - } - NotaFiscal notaFiscal = await this._servico.Save(this.SelectedNotaFiscal); - if (this._servico.Sucesso) - { - NotaFiscalViewModel notaFiscalViewModel = this; - string str2 = string.Format("{0} NOTA FISCAL DE ID \"{1}\"", str1, notaFiscal.get_Id()); - long id = notaFiscal.get_Id(); - TipoTela? nullable2 = new TipoTela?(55); - object[] nome = new object[] { notaFiscal.get_Seguradora().get_Nome(), null, null, null, null }; - obj = (!notaFiscal.get_Data().HasValue ? "-" : string.Format("{0:d}", notaFiscal.get_Data())); - nome[1] = obj; - nome[2] = notaFiscal.get_ValorBruto(); - nome[3] = notaFiscal.get_Iss(); - nome[4] = notaFiscal.get_ValorLiquido(); - notaFiscalViewModel.RegistrarAcao(str2, id, nullable2, string.Format("SEGURADORA: {0}\nDATA: {1}\nBRUTO: {2:c}\nISS: {3:c}\nLÍQUIDO: {4:c}", nome)); - if (!this.NotasFiscais.Any((NotaFiscal x) => x.get_Id() == notaFiscal.get_Id())) - { - this.NotasFiscais.Add(notaFiscal); - } - else - { - DomainBase.Copy(this.NotasFiscais.First((NotaFiscal x) => x.get_Id() == notaFiscal.get_Id()), notaFiscal); - } - if (!this.NotasFiscaisFiltrados.Any((NotaFiscal x) => x.get_Id() == notaFiscal.get_Id())) - { - this.NotasFiscaisFiltrados.Add(notaFiscal); - } - else - { - DomainBase.Copy(this.NotasFiscaisFiltrados.First((NotaFiscal x) => x.get_Id() == notaFiscal.get_Id()), notaFiscal); - } - this.NotasFiscaisFiltrados = new ObservableCollection(this.NotasFiscaisFiltrados); - this.WorkOnSelectedNotaFiscal(notaFiscal, false); - base.Alterar(false); - base.ToggleSnackBar("NOTA FISCAL SALVA COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - str1 = null; - return keyValuePairs; - } - - public async Task SalvarLote(List notas) - { - foreach (NotaFiscal nota in notas) - { - bool hasValue = nota.get_IdExtrato().HasValue; - if (hasValue) - { - NotaFiscalServico notaFiscalServico = this._servico; - long? idExtrato = nota.get_IdExtrato(); - hasValue = await notaFiscalServico.Cadatrada(idExtrato.Value); - } - if (hasValue) - { - continue; - } - this.SelectedNotaFiscal = nota; - await this.Salvar(); - } - base.ToggleSnackBar("NOTAS FISCAIS SALVAS COM SUCESSO", true); - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(55); - await this.SelecionaNotaFiscal(); - base.Loading(false); - } - - public async Task SelecionaNotaFiscal() - { - base.Loading(true); - List notaFiscals = await this._servico.BuscarNotasFiscais(); - NotaFiscalViewModel list = this; - List notaFiscals1 = notaFiscals; - list.NotasFiscais = ( - from x in notaFiscals1 - orderby x.get_Seguradora().get_Nome() - select x).ToList(); - this.NotasFiscaisFiltrados = new ObservableCollection(this.NotasFiscais); - this.SelectedNotaFiscal = this.NotasFiscaisFiltrados.FirstOrDefault(); - base.Loading(false); - } - - private async Task WorkOnSelectedNotaFiscal(NotaFiscal value, bool registrar = true) - { - string str; - long? idExtrato; - NotaFiscal notaFiscal; - long? nullable; - object obj; - NotaFiscalViewModel notaFiscalViewModel = this; - notaFiscal = (value == null || value.get_Id() == 0 ? this.CancelNotaFiscal : (NotaFiscal)value.Clone()); - notaFiscalViewModel.CancelNotaFiscal = notaFiscal; - if (value != null && value.get_Id() != 0 && (this.LastAccessId != value.get_Id() || this.LastAccessTela != 55)) - { - if (registrar) - { - NotaFiscalViewModel notaFiscalViewModel1 = this; - string str1 = string.Format("ACESSOU NOTA FISCAL DE ID \"{0}\"", value.get_Id()); - long id = value.get_Id(); - TipoTela? nullable1 = new TipoTela?(55); - object[] nome = new object[] { value.get_Seguradora().get_Nome(), null, null, null, null }; - obj = (!value.get_Data().HasValue ? "-" : string.Format("{0:d}", value.get_Data())); - nome[1] = obj; - nome[2] = value.get_ValorBruto(); - nome[3] = value.get_Iss(); - nome[4] = value.get_ValorLiquido(); - notaFiscalViewModel1.RegistrarAcao(str1, id, nullable1, string.Format("SEGURADORA: {0}\nDATA: {1}\nBRUTO: {2:c}\nISS: {3:c}\nLÍQUIDO: {4:c}", nome)); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 55; - if (string.IsNullOrEmpty(this.SelectedNotaFiscal.get_Extrato())) - { - NotaFiscal selectedNotaFiscal = this.SelectedNotaFiscal; - idExtrato = this.SelectedNotaFiscal.get_IdExtrato(); - if (!idExtrato.HasValue) - { - str = ""; - } - else - { - str = await this._servicoExtrato.BuscarNumExtrato(this.SelectedNotaFiscal.get_IdExtrato()); - } - selectedNotaFiscal.set_Extrato(str); - selectedNotaFiscal = null; - } - NotaFiscal selectedNotaFiscal1 = this.SelectedNotaFiscal; - if (selectedNotaFiscal1 != null) - { - nullable = new long?(selectedNotaFiscal1.get_Id()); - } - else - { - nullable = null; - } - idExtrato = nullable; - long num = value.get_Id(); - if (idExtrato.GetValueOrDefault() != num | !idExtrato.HasValue) - { - this.SelectedNotaFiscal = this.NotasFiscaisFiltrados.FirstOrDefault((NotaFiscal x) => x.get_Id() == value.get_Id()); - } - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/ProdutoViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/ProdutoViewModel.cs deleted file mode 100644 index 40f14ae..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/ProdutoViewModel.cs +++ /dev/null @@ -1,303 +0,0 @@ -using Gestor.Application.Helpers; -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.Generic; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class ProdutoViewModel : BaseSegurosViewModel - { - private readonly ProdutoServico _servico; - - private Produto _selectedProduto; - - public Produto CancelProduto; - - private ObservableCollection _produtosFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public List Produtos - { - get; - set; - } - - public ObservableCollection ProdutosFiltrados - { - get - { - return this._produtosFiltrados; - } - set - { - this._produtosFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("ProdutosFiltrados"); - } - } - - public Produto SelectedProduto - { - get - { - return this._selectedProduto; - } - set - { - long? nullable; - this._selectedProduto = value; - this.WorkOnSelectedProduto(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedProduto"); - } - } - - public ProdutoViewModel() - { - this._servico = new ProdutoServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelProduto == null || !this.Produtos.Any((Produto x) => x.get_Id() == this.CancelProduto.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Produtos.First((Produto x) => x.get_Id() == this.CancelProduto.get_Id()), this.CancelProduto); - if (this.ProdutosFiltrados.Count <= 0 || !this.ProdutosFiltrados.Any((Produto x) => x.get_Id() == this.CancelProduto.get_Id())) - { - this.ProdutosFiltrados.Add(this.CancelProduto); - } - else - { - DomainBase.Copy(this.ProdutosFiltrados.First((Produto x) => x.get_Id() == this.CancelProduto.get_Id()), this.CancelProduto); - } - this.ProdutosFiltrados = new ObservableCollection(this.ProdutosFiltrados); - this.SelectedProduto = this.ProdutosFiltrados.First((Produto x) => x.get_Id() == this.CancelProduto.get_Id()); - } - base.Alterar(false); - } - - internal async Task> Filtrar(string value) - { - List produtos = await Task.Run>(() => this.FiltrarProduto(value)); - return produtos; - } - - public List FiltrarProduto(string filter) - { - this.ProdutosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Produtos) : new ObservableCollection( - from x in this.Produtos - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Ativo() descending, x.get_Nome() - select x)); - this.SelectedProduto = this.ProdutosFiltrados.FirstOrDefault(); - return this.ProdutosFiltrados.ToList(); - } - - public void Incluir() - { - Produto produto = new Produto(); - produto.set_Ativo(true); - this.SelectedProduto = produto; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string str1; - List> keyValuePairs1 = this.SelectedProduto.Validate(); - List> keyValuePairs2 = keyValuePairs1; - keyValuePairs2.AddRange(await this.Validate()); - keyValuePairs2 = null; - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedProduto.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Produto produto = await this._servico.Save(this.SelectedProduto); - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str1, " PRODUTO \"", produto.get_Nome(), "\""), produto.get_Id(), new TipoTela?(10), string.Format("PRODUTO \"{0}\", ID: {1}", produto.get_Nome(), produto.get_Id())); - if (!this.Produtos.Any((Produto x) => x.get_Id() == produto.get_Id())) - { - this.Produtos.Add(produto); - } - else - { - DomainBase.Copy(this.Produtos.First((Produto x) => x.get_Id() == produto.get_Id()), produto); - } - if (!this.ProdutosFiltrados.Any((Produto x) => x.get_Id() == produto.get_Id())) - { - this.ProdutosFiltrados.Add(produto); - } - else - { - DomainBase.Copy(this.ProdutosFiltrados.First((Produto x) => x.get_Id() == produto.get_Id()), produto); - } - this.ProdutosFiltrados = new ObservableCollection(this.ProdutosFiltrados); - List produtos = this.Produtos; - Recursos.Produtos = ( - from x in produtos - orderby x.get_Nome() - select x).ToList(); - this.WorkOnSelectedProduto(produto, false); - base.Alterar(false); - base.ToggleSnackBar("PRODUTO SALVO COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - keyValuePairs1 = null; - str1 = null; - return keyValuePairs; - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(10); - await this.SelecionaProdutos(); - base.Loading(false); - } - - public void SelecionaProduto(Produto produto) - { - this.SelectedProduto = produto; - } - - private async Task SelecionaProdutos() - { - base.Loading(true); - List produtos = await (new BaseServico()).BuscarProdutosAsync(); - ProdutoViewModel list = this; - List produtos1 = produtos; - IOrderedEnumerable ativo = - from x in produtos1 - orderby x.get_Ativo() descending - select x; - list.Produtos = ativo.ThenBy((Produto x) => x.get_Nome()).ToList(); - this.ProdutosFiltrados = new ObservableCollection(this.Produtos); - this.SelectedProduto = this.ProdutosFiltrados.FirstOrDefault(); - List produtos2 = this.Produtos; - Recursos.Produtos = ( - from x in produtos2 - orderby x.get_Nome() - select x).ToList(); - base.Loading(false); - base.Loading(true); - } - - public async Task>> Validate() - { - List> keyValuePairs; - List> keyValuePairs1; - if (!string.IsNullOrWhiteSpace(this.SelectedProduto.get_Nome())) - { - keyValuePairs1 = new List>(); - bool flag = true; - List produtos = await (new BaseServico()).BuscarProduto(this.SelectedProduto.get_Nome()); - if (produtos.Count > 0) - { - produtos.ForEach((Produto x) => { - if (x.get_Id() == this.SelectedProduto.get_Id()) - { - return; - } - if (x.get_Nome() == this.SelectedProduto.get_Nome()) - { - flag = false; - } - }); - } - if (!flag) - { - keyValuePairs1.Add(new KeyValuePair("Nome", "UM PRODUTO COM O MESMO NOME JÁ EXISTE.")); - } - keyValuePairs = keyValuePairs1; - } - else - { - keyValuePairs = new List>(); - } - keyValuePairs1 = null; - return keyValuePairs; - } - - private void WorkOnSelectedProduto(Produto value, bool registrar = true) - { - long? nullable; - this.CancelProduto = (value == null || value.get_Id() == 0 ? this.CancelProduto : (Produto)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 10) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU PRODUTO \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(10), string.Format("ID PRODUTO: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 10; - Produto selectedProduto = this.SelectedProduto; - if (selectedProduto != null) - { - nullable = new long?(selectedProduto.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedProduto = this.ProdutosFiltrados.FirstOrDefault((Produto x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/ProtocoloDocumentosViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/ProtocoloDocumentosViewModel.cs deleted file mode 100644 index 027f344..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/ProtocoloDocumentosViewModel.cs +++ /dev/null @@ -1,399 +0,0 @@ -using Assinador.Infrastructure.Helpers; -using Gestor.Application.Helpers; -using Gestor.Application.Servicos.Seguros; -using Gestor.Application.ViewModels.Generic; -using Gestor.Application.Views.Ferramentas; -using Gestor.Application.Views.Generic; -using Gestor.Model.Common; -using Gestor.Model.Domain.Common; -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.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class ProtocoloDocumentosViewModel : BaseSegurosViewModel - { - private Cliente _selectedCliente = new Cliente(); - - private ObservableCollection _apolicesFiltradas = new ObservableCollection(); - - private ObservableCollection _apolicesAdicionadas = new ObservableCollection(); - - private FiltroStatusDocumento _selectedStatus; - - public ObservableCollection ApolicesAdicionadas - { - get - { - return this._apolicesAdicionadas; - } - set - { - this._apolicesAdicionadas = value; - base.OnPropertyChanged("ApolicesAdicionadas"); - } - } - - public ObservableCollection ApolicesFiltradas - { - get - { - return this._apolicesFiltradas; - } - set - { - this._apolicesFiltradas = value; - base.OnPropertyChanged("ApolicesFiltradas"); - } - } - - public Cliente SelectedCliente - { - get - { - return this._selectedCliente; - } - set - { - this._selectedCliente = value; - if (this.SelectedCliente != null && this.SelectedCliente.get_Id() != 0 && (this.LastAccessId != this.SelectedCliente.get_Id() || this.LastAccessTela != 59)) - { - this.SelecionarDocumentos(); - this.LastAccessId = this.SelectedCliente.get_Id(); - this.LastAccessTela = 59; - } - base.OnPropertyChanged("SelectedCliente"); - } - } - - public FiltroStatusDocumento SelectedStatus - { - get - { - return this._selectedStatus; - } - set - { - this._selectedStatus = value; - this.SelectedCliente = this.SelectedCliente; - this.SelecionarDocumentos(); - base.OnPropertyChanged("SelectedStatus"); - } - } - - public ProtocoloDocumentosViewModel() - { - } - - public async void AdicionarEtiqueta(Documento documento) - { - ObservableCollection apolicesAdicionadas = this.ApolicesAdicionadas; - ProtocoloEtiqueta protocoloEtiquetum = new ProtocoloEtiqueta(); - ProtocoloEtiqueta protocoloEtiquetum1 = protocoloEtiquetum; - Documento documento1 = await (new ApoliceServico()).BuscarApoliceAsync(documento.get_Id(), false, false); - protocoloEtiquetum1.Documento = documento1; - protocoloEtiquetum.Tipo = 1; - apolicesAdicionadas.Add(protocoloEtiquetum); - apolicesAdicionadas = null; - protocoloEtiquetum1 = null; - protocoloEtiquetum = null; - ProtocoloDocumentosViewModel observableCollection = this; - ObservableCollection apolicesAdicionadas1 = this.ApolicesAdicionadas; - observableCollection.ApolicesAdicionadas = new ObservableCollection( - from x in apolicesAdicionadas1 - orderby x.Documento.get_Id() - select x); - } - - public async void AdicionarEtiquetaCliente() - { - if (this.SelectedCliente != null && this.SelectedCliente.get_Id() != 0) - { - bool flag = this.ApolicesAdicionadas.Any((ProtocoloEtiqueta x) => { - if (x.Documento.get_Controle().get_Cliente().get_Id() != this.SelectedCliente.get_Id()) - { - return false; - } - return x.Tipo == 1; - }); - if (flag) - { - flag = !await base.ShowMessage("JÁ EXISTE UMA ETIQUETA ADICIONADA PARA O CLIENTE SELECIONADO, DESEJA ADICIONAR NOVAMENTE?", "SIM", "NÃO", false); - } - if (!flag) - { - ObservableCollection apolicesAdicionadas = this.ApolicesAdicionadas; - ProtocoloEtiqueta protocoloEtiquetum = new ProtocoloEtiqueta(); - Documento documento = new Documento(); - Controle controle = new Controle(); - controle.set_Cliente(this.SelectedCliente); - documento.set_Controle(controle); - protocoloEtiquetum.Documento = documento; - protocoloEtiquetum.Tipo = 1; - apolicesAdicionadas.Add(protocoloEtiquetum); - ProtocoloDocumentosViewModel observableCollection = this; - ObservableCollection apolicesAdicionadas1 = this.ApolicesAdicionadas; - IOrderedEnumerable tipo = - from x in apolicesAdicionadas1 - orderby x.Tipo - select x; - observableCollection.ApolicesAdicionadas = new ObservableCollection(tipo.ThenBy((ProtocoloEtiqueta x) => x.Documento.get_Controle().get_Cliente().get_Id())); - } - } - } - - public async void AdicionarEtiquetaCorretora() - { - ProtocoloDocumentosViewModel protocoloDocumentosViewModel = this; - ClienteEndereco clienteEndereco = new ClienteEndereco(); - clienteEndereco.set_Endereco(Recursos.Empresa.get_Endereco()); - clienteEndereco.set_Bairro(Recursos.Empresa.get_Bairro()); - clienteEndereco.set_Numero(Recursos.Empresa.get_Numero()); - clienteEndereco.set_Complemento(Recursos.Empresa.get_Complemento()); - clienteEndereco.set_Cidade(Recursos.Empresa.get_Cidade()); - clienteEndereco.set_Estado(Recursos.Empresa.get_Estado()); - clienteEndereco.set_Cep(Recursos.Empresa.get_Cep()); - ObservableCollection observableCollection = new ObservableCollection() - { - clienteEndereco - }; - ObservableCollection apolicesAdicionadas = protocoloDocumentosViewModel.ApolicesAdicionadas; - ProtocoloEtiqueta protocoloEtiquetum = new ProtocoloEtiqueta(); - Documento documento = new Documento(); - Controle controle = new Controle(); - Cliente cliente = new Cliente(); - cliente.set_Nome(Recursos.Empresa.get_Nome()); - cliente.set_Id((long)-1); - cliente.set_Enderecos(observableCollection); - controle.set_Cliente(cliente); - documento.set_Controle(controle); - protocoloEtiquetum.Documento = documento; - protocoloEtiquetum.Tipo = 1; - apolicesAdicionadas.Add(protocoloEtiquetum); - ProtocoloDocumentosViewModel observableCollection1 = protocoloDocumentosViewModel; - ObservableCollection apolicesAdicionadas1 = protocoloDocumentosViewModel.ApolicesAdicionadas; - IOrderedEnumerable tipo = - from x in apolicesAdicionadas1 - orderby x.Tipo - select x; - observableCollection1.ApolicesAdicionadas = new ObservableCollection(tipo.ThenBy((ProtocoloEtiqueta x) => x.Documento.get_Controle().get_Cliente().get_Id())); - } - - public async void AdicionarProtocolo(Documento documento) - { - bool flag = this.ApolicesAdicionadas.Any((ProtocoloEtiqueta x) => { - if (x.Documento.get_Id() != documento.get_Id()) - { - return false; - } - return x.Tipo == 0; - }); - if (flag) - { - flag = !await base.ShowMessage("JÁ EXISTE UM PROTOCOLO ADICIONADO PARA O DOCUMENTO SELECIONADO, DESEJA ADICIONAR NOVAMENTE?", "SIM", "NÃO", false); - } - if (!flag) - { - ObservableCollection apolicesAdicionadas = this.ApolicesAdicionadas; - ProtocoloEtiqueta protocoloEtiquetum = new ProtocoloEtiqueta(); - ProtocoloEtiqueta protocoloEtiquetum1 = protocoloEtiquetum; - Documento documento1 = await (new ApoliceServico()).BuscarApoliceAsync(documento.get_Id(), false, false); - protocoloEtiquetum1.Documento = documento1; - protocoloEtiquetum.Tipo = 0; - apolicesAdicionadas.Add(protocoloEtiquetum); - apolicesAdicionadas = null; - protocoloEtiquetum1 = null; - protocoloEtiquetum = null; - ProtocoloDocumentosViewModel observableCollection = this; - ObservableCollection apolicesAdicionadas1 = this.ApolicesAdicionadas; - observableCollection.ApolicesAdicionadas = new ObservableCollection( - from x in apolicesAdicionadas1 - orderby x.Documento.get_Id() - select x); - } - } - - public async void Imprimir(TipoProtocoloEtiqueta tipo) - { - if (this.ApolicesAdicionadas.Count != 0) - { - TipoProtocoloEtiqueta tipoProtocoloEtiquetum = tipo; - if (tipoProtocoloEtiquetum == null) - { - ObservableCollection apolicesAdicionadas = this.ApolicesAdicionadas; - if (!apolicesAdicionadas.All((ProtocoloEtiqueta x) => x.Tipo != 0)) - { - ObservableCollection observableCollection = this.ApolicesAdicionadas; - if (observableCollection.Any((ProtocoloEtiqueta x) => x.Tipo == 0)) - { - ProtocoloDocumentosViewModel protocoloDocumentosViewModel = this; - ObservableCollection apolicesAdicionadas1 = this.ApolicesAdicionadas; - IEnumerable protocoloEtiquetas = - from x in apolicesAdicionadas1 - where x.Tipo == 0 - select x; - List documentos = await protocoloDocumentosViewModel.ShowProtocoloDialog(( - from x in protocoloEtiquetas - select x.Documento).ToList()); - if (documentos != null) - { - bool flag = await base.ShowMessage(string.Concat("DESEJA EMITIR DOIS PROTOCOLOS POR PÁGINA?", Environment.NewLine, "A QUANTIDADE DE INFORMÃÇÕES PODE IMPEDIR QUE ESSA FUNÇÃO FUNCIONE CORRETAMENTE"), "SIM", "NÃO", false); - this.PrepararProtocolo(documentos, flag); - documentos = null; - } - else - { - return; - } - } - } - else - { - await base.ShowMessage(string.Concat("NECESSÁRIO ADICIONAR DOCUMENTOS PARA EMISSÃO DE ", Functions.GetDescription(tipo)), "OK", "", false); - return; - } - } - else if (tipoProtocoloEtiquetum == 1) - { - ObservableCollection observableCollection1 = this.ApolicesAdicionadas; - if (!observableCollection1.All((ProtocoloEtiqueta x) => x.Tipo != 1)) - { - ObservableCollection apolicesAdicionadas2 = this.ApolicesAdicionadas; - if (apolicesAdicionadas2.Any((ProtocoloEtiqueta x) => { - if (x.Tipo != 1) - { - return false; - } - return x.Documento.get_Id() == (long)0; - })) - { - ObservableCollection observableCollection2 = this.ApolicesAdicionadas; - if (observableCollection2.Any((ProtocoloEtiqueta x) => { - if (x.Tipo != 1) - { - return false; - } - return x.Documento.get_Id() != (long)0; - })) - { - await base.ShowMessage("COMO EXISTEM ETIQUETAS DE CLIENTES E DOCUMENTOS,\nPRIMEIRO CONFIGURE AS DE SOMENTE CLIENTE.\nDEPOIS DE GERAR AS ETIQUETAS DE CLIENTE, CONFIGURAR AS DE DOCUMENTOS", "OK", "", false); - } - ObservableCollection apolicesAdicionadas3 = this.ApolicesAdicionadas; - IEnumerable protocoloEtiquetas1 = apolicesAdicionadas3.Where((ProtocoloEtiqueta x) => { - if (x.Tipo != 1) - { - return false; - } - return x.Documento.get_Id() == (long)0; - }); - (new HosterWindow(new EtiquetaView(( - from x in protocoloEtiquetas1 - select x.Documento).ToList(), true), "ETIQUETAS", new double?((double)900), new double?((double)600), false)).Show(); - } - ObservableCollection observableCollection3 = this.ApolicesAdicionadas; - if (observableCollection3.Any((ProtocoloEtiqueta x) => { - if (x.Tipo != 1) - { - return false; - } - return x.Documento.get_Id() != (long)0; - })) - { - ObservableCollection apolicesAdicionadas4 = this.ApolicesAdicionadas; - IEnumerable protocoloEtiquetas2 = apolicesAdicionadas4.Where((ProtocoloEtiqueta x) => { - if (x.Tipo != 1) - { - return false; - } - return x.Documento.get_Id() != (long)0; - }); - (new HosterWindow(new EtiquetaView(( - from x in protocoloEtiquetas2 - select x.Documento).ToList(), false), "ETIQUETAS", new double?((double)900), new double?((double)600), false)).Show(); - } - } - else - { - await base.ShowMessage(string.Concat("NECESSÁRIO ADICIONAR DOCUMENTOS PARA EMISSÃO DE ", Functions.GetDescription(tipo)), "OK", "", false); - return; - } - } - } - else - { - await base.ShowMessage(string.Concat("NECESSÁRIO ADICIONAR DOCUMENTOS PARA EMISSÃO DE ", Functions.GetDescription(tipo)), "OK", "", false); - } - } - - public async void PrepararProtocolo(List documentos, bool doisPorPagina) - { - if (await base.ShowMessage("DESEJA EMITIR O CHECKLIST?", "SIM", "NÃO", false)) - { - await base.EmitirCheckList(documentos); - } - if (documentos != null) - { - List documentos1 = documentos; - List> list = ( - from x in documentos1 - select new Tuple(x.get_Id(), x.get_ObsProtocolo())).ToList>(); - await base.EmitirProtocolos(list, doisPorPagina, documentos); - } - } - - public void Remover(ProtocoloEtiqueta documento) - { - this.ApolicesAdicionadas.Remove(documento); - this.SelecionarDocumentos(); - } - - public async void SelecionarDocumentos() - { - long? nullable; - object obj; - object nome; - long num; - base.Loading(true); - if (this.SelectedCliente != null) - { - this.ApolicesFiltradas = await (new ApoliceServico()).BuscarApolicesComissao(this.SelectedCliente.get_Id(), this.SelectedStatus); - ProtocoloDocumentosViewModel protocoloDocumentosViewModel = this; - obj = (this.SelectedStatus == 4 ? "TODOS OS DOCUMENTOS" : string.Concat("OS ", Functions.GetDescription(this.SelectedStatus))); - Cliente selectedCliente = this.SelectedCliente; - if (selectedCliente != null) - { - nome = selectedCliente.get_Nome(); - } - else - { - nome = null; - } - Cliente cliente = this.SelectedCliente; - if (cliente != null) - { - nullable = new long?(cliente.get_Id()); - } - else - { - nullable = null; - } - string str = string.Format("CONSULTOU {0} DO CLIENTE {1} ({2})", obj, nome, nullable); - num = (this.SelectedCliente == null ? (long)0 : this.SelectedCliente.get_Id()); - protocoloDocumentosViewModel.RegistrarAcao(str, num, new TipoTela?(59), null); - base.Loading(false); - } - else - { - base.Loading(false); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/ProtocoloEtiqueta.cs b/Gestor.Application/ViewModels/Ferramentas/ProtocoloEtiqueta.cs deleted file mode 100644 index 7e46a89..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/ProtocoloEtiqueta.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Gestor.Model.Common; -using Gestor.Model.Domain.Seguros; -using System; -using System.Runtime.CompilerServices; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class ProtocoloEtiqueta - { - public Gestor.Model.Domain.Seguros.Documento Documento - { - get; - set; - } - - public TipoProtocoloEtiqueta Tipo - { - get; - set; - } - - public ProtocoloEtiqueta() - { - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/QualificacaoViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/QualificacaoViewModel.cs deleted file mode 100644 index c259f93..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/QualificacaoViewModel.cs +++ /dev/null @@ -1,122 +0,0 @@ -using Gestor.Application.Servicos.Ferramentas; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.ViewModels.Generic; -using Gestor.Model.Common; -using Gestor.Model.Domain.Generic; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class QualificacaoViewModel : BaseSegurosViewModel - { - private readonly QualificacaoServico _servico; - - private Qualificacao _selectedQualificacao; - - public Qualificacao CancelQualificacao; - - public Qualificacao SelectedQualificacao - { - get - { - return this._selectedQualificacao; - } - set - { - if (value == null || value.get_Id() == 0) - { - Qualificacao qualificacao = new Qualificacao(); - qualificacao.set_Liquido1(decimal.Zero); - qualificacao.set_Liquido2(new decimal(1000)); - qualificacao.set_Liquido3(new decimal(5000)); - qualificacao.set_Comissao1(new decimal(10)); - qualificacao.set_Comissao2(new decimal(15)); - qualificacao.set_Comissao3(new decimal(20)); - qualificacao.set_Resultado1(new decimal(100)); - qualificacao.set_Resultado2(new decimal(200)); - qualificacao.set_Resultado3(new decimal(300)); - qualificacao.set_Id((long)1); - value = qualificacao; - } - this._selectedQualificacao = value; - base.VerificarEnables(new long?(value.get_Id())); - base.OnPropertyChanged("SelectedQualificacao"); - } - } - - public QualificacaoViewModel() - { - this._servico = new QualificacaoServico(); - this.Seleciona(); - } - - public void CancelarAlteracao() - { - base.Loading(true); - if (this.SelectedQualificacao.get_Id() != 0) - { - this.SelectedQualificacao = this.CancelQualificacao; - } - else - { - this.SelectedQualificacao = null; - base.Alterar(false); - base.EnableMenu = false; - base.Loading(false); - } - base.Alterar(false); - base.Loading(false); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - if (await this._servico.BuscarQualificacaoAsync().get_Id() == 0) - { - this.SelectedQualificacao.set_Id((long)0); - } - List> keyValuePairs1 = this.SelectedQualificacao.Validate(); - if (keyValuePairs1.Count <= 0) - { - this.SelectedQualificacao = await this._servico.Save(this.SelectedQualificacao); - if (this._servico.Sucesso) - { - base.RegistrarAcao("ALTEROU QUALIFICAÇÃO", (long)0, new TipoTela?(48), null); - base.Alterar(false); - base.ToggleSnackBar("QUALIFICACAO SALVA COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - return keyValuePairs; - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(48); - await this.SelecionaQualificacao(); - base.Loading(false); - } - - private async Task SelecionaQualificacao() - { - base.Loading(true); - this.SelectedQualificacao = await this._servico.BuscarQualificacaoAsync(); - base.RegistrarAcao("ACESSOU QUALIFICAÇÃO", (long)0, new TipoTela?(48), null); - base.Loading(false); - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs deleted file mode 100644 index 09ab1ea..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs +++ /dev/null @@ -1,332 +0,0 @@ -using Gestor.Application.Helpers; -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.Generic; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class RamoViewModel : BaseSegurosViewModel - { - private readonly RamoServico _servico; - - private Ramo _selectedRamo = new Ramo(); - - private decimal _iof; - - private ObservableCollection _ramosFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - private List _coberturas = new List(); - - private ObservableCollection _coberturasFiltradas = new ObservableCollection(); - - public Ramo CancelRamo; - - public List Coberturas - { - get - { - return this._coberturas; - } - set - { - this._coberturas = value; - base.OnPropertyChanged("Coberturas"); - } - } - - public ObservableCollection CoberturasFiltradas - { - get - { - return this._coberturasFiltradas; - } - set - { - this._coberturasFiltradas = value; - base.OnPropertyChanged("CoberturasFiltradas"); - } - } - - public decimal Iof - { - get - { - return this._iof; - } - set - { - this._iof = value; - base.OnPropertyChanged("Iof"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public List Ramos - { - get; - set; - } - - public ObservableCollection RamosFiltrados - { - get - { - return this._ramosFiltrados; - } - set - { - this._ramosFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("RamosFiltrados"); - } - } - - public Ramo SelectedRamo - { - get - { - return this._selectedRamo; - } - set - { - long? nullable; - this._selectedRamo = value; - this.WorkOnSelectedRamo(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedRamo"); - } - } - - public RamoViewModel() - { - this._servico = new RamoServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelRamo != null && this.Ramos.Any((Ramo x) => x.get_Id() == this.CancelRamo.get_Id())) - { - DomainBase.Copy(this.Ramos.First((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()), this.CancelRamo); - if (this.RamosFiltrados.Count <= 0 || !this.RamosFiltrados.Any((Ramo x) => x.get_Id() == this.CancelRamo.get_Id())) - { - this.RamosFiltrados.Add(this.CancelRamo); - } - else - { - DomainBase.Copy(this.RamosFiltrados.First((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()), this.CancelRamo); - } - this.RamosFiltrados = new ObservableCollection(this.RamosFiltrados); - this.SelectedRamo = this.RamosFiltrados.First((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()); - } - base.Alterar(false); - } - - internal async Task> Filtrar(string value) - { - List ramos = await Task.Run>(() => this.FiltrarRamo(value)); - return ramos; - } - - internal async Task> FiltrarCobertura(string value) - { - List coberturaPadraos = await Task.Run>(() => this.FiltrarCoberturaRamo(value)); - return coberturaPadraos; - } - - public List FiltrarCoberturaRamo(string filter) - { - this.CoberturasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Coberturas) : new ObservableCollection( - from x in this.Coberturas - where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - select x)); - return this.CoberturasFiltradas.ToList(); - } - - public List FiltrarRamo(string filter) - { - this.RamosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Ramos) : new ObservableCollection( - from x in this.Ramos - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Ativo() descending, x.get_Nome() - select x)); - return this.RamosFiltrados.ToList(); - } - - public async void Incluir(Ramo ramo) - { - ramo.set_Ativo(true); - await this._servico.Insert(ramo); - if (this._servico.Sucesso) - { - await this.SelecionaRamos(ramo); - } - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string str1; - this.SelectedRamo.set_Iof(this.Iof); - List> keyValuePairs1 = this.SelectedRamo.Validate(); - if (keyValuePairs1.Count <= 0) - { - Ramo selectedRamo = this.SelectedRamo; - selectedRamo.set_Iof(selectedRamo.get_Iof() * new decimal(100)); - str = (this.SelectedRamo.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Ramo ramo = await this._servico.Save(this.SelectedRamo, this.Coberturas); - Ramo ramo1 = ramo; - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str1, " RAMO \"", ramo1.get_Nome(), "\""), ramo1.get_Id(), new TipoTela?(12), string.Format("RAMO \"{0}\", ID: {1}", ramo1.get_Nome(), ramo1.get_Id())); - if (!this.Ramos.Any((Ramo x) => x.get_Id() == ramo1.get_Id())) - { - this.Ramos.Add(ramo1); - } - else - { - DomainBase.Copy(this.Ramos.First((Ramo x) => x.get_Id() == ramo1.get_Id()), ramo1); - } - if (!this.RamosFiltrados.Any((Ramo x) => x.get_Id() == ramo1.get_Id())) - { - this.RamosFiltrados.Add(ramo1); - } - else - { - DomainBase.Copy(this.RamosFiltrados.First((Ramo x) => x.get_Id() == ramo1.get_Id()), ramo1); - } - this.RamosFiltrados = new ObservableCollection(this.RamosFiltrados); - Recursos.Ramos = this.Ramos; - await RamoViewModel.SelecionaCoberturas(); - this.WorkOnSelectedRamo(ramo1, false); - base.Alterar(false); - base.ToggleSnackBar("RAMO SALVO COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - str1 = null; - return keyValuePairs; - } - - public async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(12); - await this.SelecionaRamos(null); - base.Loading(false); - } - - private static async Task SelecionaCoberturas() - { - Recursos.Coberturas = await (new BaseServico()).BuscaCoberturas(); - } - - public void SelecionaRamo(Ramo ramo) - { - this.SelectedRamo = ramo; - } - - private async Task SelecionaRamos(Ramo ramo = null) - { - Ramo ramo1; - base.Loading(true); - await RamoViewModel.SelecionaCoberturas(); - List ramos = await (new BaseServico()).BuscarRamosAsync(); - RamoViewModel list = this; - List ramos1 = ramos; - IOrderedEnumerable ativo = - from x in ramos1 - orderby x.get_Ativo() descending - select x; - list.Ramos = ativo.ThenBy((Ramo x) => x.get_Nome()).ToList(); - this.RamosFiltrados = new ObservableCollection(this.Ramos); - RamoViewModel ramoViewModel = this; - ramo1 = (ramo == null ? this.RamosFiltrados.First() : this.RamosFiltrados.FirstOrDefault((Ramo x) => x.get_Id() == ramo.get_Id())); - ramoViewModel.SelectedRamo = ramo1; - Recursos.Ramos = ramos; - base.Loading(false); - } - - private void WorkOnSelectedRamo(Ramo value, bool registrar = true) - { - long? nullable; - this.CancelRamo = (value == null || value.get_Id() == 0 ? this.CancelRamo : (Ramo)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 12) - { - return; - } - this.Coberturas = ( - from x in Recursos.Coberturas - where x.get_IdRamo() == value.get_Id() - orderby x.get_Padrao() descending, x.get_Descricao() - select x).ToList(); - this.CoberturasFiltradas = new ObservableCollection(this.Coberturas); - this.Iof = value.get_Iof() * new decimal(1, 0, 0, false, 2); - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU RAMO \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(12), string.Format("ID RAMO: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 12; - Ramo selectedRamo = this.SelectedRamo; - if (selectedRamo != null) - { - nullable = new long?(selectedRamo.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedRamo = this.RamosFiltrados.FirstOrDefault((Ramo x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs deleted file mode 100644 index e00947c..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs +++ /dev/null @@ -1,769 +0,0 @@ -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 _recibosFiltrados = new ObservableCollection(); - - 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 Recibos - { - get; - set; - } - - public ObservableCollection 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 x) => x.get_Id() == this.CancelRecibo.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Recibos.First((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()), this.CancelRecibo); - if (this.RecibosFiltrados.Count <= 0 || !this.RecibosFiltrados.Any((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id())) - { - this.RecibosFiltrados.Add(this.CancelRecibo); - } - else - { - DomainBase.Copy(this.RecibosFiltrados.First((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()), this.CancelRecibo); - } - this.RecibosFiltrados = new ObservableCollection(this.RecibosFiltrados); - this.SelectedRecibo = this.RecibosFiltrados.First((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> Filtrar(string value) - { - List recibos = await Task.Run>(() => this.FiltrarRecibo(value)); - return recibos; - } - - public List FiltrarRecibo(string filter) - { - this.RecibosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Recibos) : new ObservableCollection(this.Recibos.Where((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(); - } - - 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[] { ""; - 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 indiceArquivoDigitals = await this.ArquivoDigitalServico.BuscarPorTipo(13, Recursos.Empresa.get_Id()); - if (indiceArquivoDigitals != null) - { - List indiceArquivoDigitals1 = indiceArquivoDigitals; - if (indiceArquivoDigitals1.Any((IndiceArquivoDigital x) => x.get_Descricao() == "LOGO")) - { - List indiceArquivoDigitals2 = indiceArquivoDigitals; - IndiceArquivoDigital indiceArquivoDigital = indiceArquivoDigitals2.FirstOrDefault((IndiceArquivoDigital x) => x.get_Descricao() == "LOGO"); - if (indiceArquivoDigital != null) - { - nullable = new long?(indiceArquivoDigital.get_IdArquivoDigital()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - List indiceArquivoDigitals3 = indiceArquivoDigitals; - IndiceArquivoDigital indiceArquivoDigital1 = indiceArquivoDigitals3.FirstOrDefault((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 = "RECIBO"; - for (int i = 0; i < num; i++) - { - if (!flag1) - { - str7 = string.Concat(str7, "
"); - } - else - { - str7 = string.Concat(str7, "
", image, "
"); - str7 = string.Concat(str7, "
"); - } - str7 = string.Concat(str7, string.Format("
N° {0}

", this.SelectedRecibo.get_Id())); - str7 = string.Concat(str7, "R E C I B O

"); - 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}, {1}, INSCRIT{2} NO {3} SOB Nº {4}, DECLAR{5} QUE {6}, NA DATA DE HOJE, {7:dd/MM/yyyy HH:mm}, O VALOR DE R$ {8:0.00} POR MEIO DE {9}, PARA {10}, INSCRITO NO CPF/CNPJ SOB Nº {11}, REFERENTE À(AO) {12}. DANDO-LHE POR ESTE RECIBO A DEVIDA QUITAÇÃO.
", pagante)); - string[] cidade = new string[] { str7, "
", Recursos.Empresa.get_Cidade(), ", ", null, null }; - string str12 = str5; - if (str12 != null) - { - upper = str12.ToUpper(); - } - else - { - upper = null; - } - cidade[4] = upper; - cidade[5] = ".

"; - str7 = string.Concat(cidade); - string[] recebedor = new string[] { str7, "_________________________________
ASSINATURA ", this.SelectedRecibo.get_Recebedor(), "
", 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}, {1}, INSCRIT{2} NO {3} SOB Nº {4}, DECLAR{5} QUE {6}, NA DATA DE HOJE, {7:dd/MM/yyyy HH:mm}, O VALOR DE R$ {8:0.00} POR MEIO DE {9}, DE {10}, INSCRITO NO CPF/CNPJ SOB Nº {11}, REFERENTE À(AO) {12}. DANDO-LHE POR ESTE RECIBO A DEVIDA QUITAÇÃO.
", objArray)); - string[] strArrays = new string[] { str7, "", Recursos.Empresa.get_Cidade(), ", ", null, null }; - string str17 = str5; - if (str17 != null) - { - upper1 = str17.ToUpper(); - } - else - { - upper1 = null; - } - strArrays[4] = upper1; - strArrays[5] = ".

"; - str7 = string.Concat(strArrays); - string[] recebedor1 = new string[] { str7, "_________________________________
ASSINATURA ", this.SelectedRecibo.get_Recebedor(), "
", this.SelectedRecibo.get_DocumentoRecebedor() }; - str7 = string.Concat(recebedor1); - } - str7 = string.Concat(str7, "
"); - } - str7 = string.Concat(str7, " "); - 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>> Salvar() - { - List> keyValuePairs; - string str; - string description; - object obj; - string str1; - List> 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 x) => x.get_Id() == recibo.get_Id())) - { - this.Recibos.Add(recibo); - } - else - { - DomainBase.Copy(this.Recibos.First((Recibo x) => x.get_Id() == recibo.get_Id()), recibo); - } - if (!this.RecibosFiltrados.Any((Recibo x) => x.get_Id() == recibo.get_Id())) - { - this.RecibosFiltrados.Add(recibo); - } - else - { - DomainBase.Copy(this.RecibosFiltrados.First((Recibo x) => x.get_Id() == recibo.get_Id()), recibo); - } - this.RecibosFiltrados = new ObservableCollection(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 recibos = await this._servico.BuscarRecibos(); - this.Recibos = recibos.ToList(); - this.RecibosFiltrados = new ObservableCollection(this.Recibos); - if (this.RecibosFiltrados.Count <= 0) - { - this.SelectedRecibo = new Recibo(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelectedRecibo = this.RecibosFiltrados.First(); - } - 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 x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs deleted file mode 100644 index f7daced..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs +++ /dev/null @@ -1,621 +0,0 @@ -using Gestor.Application.Helpers; -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.Configuracoes; -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.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class SeguradoraViewModel : BaseSegurosViewModel - { - private readonly SeguradoraServico _servico; - - private bool _apelido; - - private Seguradora _selectedSeguradora; - - private SeguradoraEndereco _selectedEndereco = new SeguradoraEndereco(); - - private ObservableCollection _contatos = new ObservableCollection(); - - private ObservableCollection _enderecos = new ObservableCollection(); - - private SeguradoraContato _selectedTelefone = new SeguradoraContato(); - - private Visibility _tipoTelefone; - - private Visibility _telefone; - - private Visibility _prefixo; - - private ObservableCollection _configFiltrados = new ObservableCollection(); - - public Seguradora CancelSeguradora; - - public ObservableCollection CancelEnderecos; - - public ObservableCollection CancelContatos; - - private ObservableCollection _seguradorasFiltradas = new ObservableCollection(); - - private bool _isExpanded; - - public bool Apelido - { - get - { - return this._apelido; - } - set - { - this._apelido = value; - base.OnPropertyChanged("Apelido"); - } - } - - public List Config - { - get; - set; - } - - public ObservableCollection ConfigFiltrados - { - get - { - return this._configFiltrados; - } - set - { - this._configFiltrados = value; - base.OnPropertyChanged("ConfigFiltrados"); - } - } - - public ObservableCollection Contatos - { - get - { - return this._contatos; - } - set - { - this._contatos = value; - base.OnPropertyChanged("Contatos"); - } - } - - public ObservableCollection Enderecos - { - get - { - return this._enderecos; - } - set - { - this._enderecos = value; - base.OnPropertyChanged("Enderecos"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public string Pesquisa - { - get; - set; - } - - public Visibility PrefixoVisibility - { - get - { - return this._prefixo; - } - set - { - if (this.SelectedTelefone.get_TipoContato() != 2) - { - this._prefixo = Visibility.Visible; - } - else - { - this._prefixo = Visibility.Collapsed; - } - base.OnPropertyChanged("PrefixoVisibility"); - } - } - - public List Seguradoras - { - get; - set; - } - - public ObservableCollection SeguradorasFiltradas - { - get - { - return this._seguradorasFiltradas; - } - set - { - this._seguradorasFiltradas = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("SeguradorasFiltradas"); - } - } - - public SeguradoraEndereco SelectedEndereco - { - get - { - return this._selectedEndereco; - } - set - { - this._selectedEndereco = value; - base.OnPropertyChanged("SelectedEndereco"); - } - } - - public Seguradora SelectedSeguradora - { - get - { - return this._selectedSeguradora; - } - set - { - long? nullable; - this._selectedSeguradora = value; - this.WorkOnSelectedSeguradora(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedSeguradora"); - } - } - - public SeguradoraContato SelectedTelefone - { - get - { - return this._selectedTelefone; - } - set - { - this._selectedTelefone = value; - base.OnPropertyChanged("SelectedTelefone"); - } - } - - public Visibility TelefoneVisibility - { - get - { - return this._telefone; - } - set - { - if (this.SelectedTelefone.get_TipoContato() != 2) - { - this._telefone = Visibility.Visible; - } - else - { - this._telefone = Visibility.Collapsed; - } - base.OnPropertyChanged("TelefoneVisibility"); - } - } - - public Visibility TipoTelefoneVisibility - { - get - { - return this._tipoTelefone; - } - set - { - if (this.SelectedTelefone.get_TipoContato() != 2) - { - this._tipoTelefone = Visibility.Visible; - } - else - { - this._tipoTelefone = Visibility.Collapsed; - } - base.OnPropertyChanged("TipoTelefoneVisibility"); - } - } - - public decimal Tolerancia - { - get; - set; - } - - public SeguradoraViewModel() - { - this._servico = new SeguradoraServico(); - this.Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 6); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelSeguradora != null && this.Seguradoras.Any((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id())) - { - DomainBase.Copy(this.Seguradoras.First((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()), this.CancelSeguradora); - if (this.SeguradorasFiltradas.Count <= 0 || !this.SeguradorasFiltradas.Any((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id())) - { - this.SeguradorasFiltradas.Add(this.CancelSeguradora); - } - else - { - DomainBase.Copy(this.SeguradorasFiltradas.First((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()), this.CancelSeguradora); - } - this.SeguradorasFiltradas = new ObservableCollection(this.SeguradorasFiltradas); - this.ConfigFiltrados = new ObservableCollection(this.ConfigFiltrados); - this.SelectedSeguradora = this.SeguradorasFiltradas.First((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()); - this.Enderecos = this.CancelEnderecos; - this.Contatos = this.CancelContatos; - } - base.Alterar(false); - } - - public void Clonar() - { - this.CancelSeguradora = (Seguradora)this.SelectedSeguradora.Clone(); - this.CancelEnderecos = new ObservableCollection(this.Enderecos); - this.CancelContatos = new ObservableCollection(this.Contatos); - } - - public void ExcluirEndereco(SeguradoraEndereco endereco) - { - this.Enderecos.Remove(endereco); - } - - public void ExcluirTelefone(SeguradoraContato contato) - { - this.Contatos.Remove(contato); - } - - internal async Task> Filtrar(string value) - { - List seguradoras = await Task.Run>(() => this.FiltrarSeguradora(value)); - return seguradoras; - } - - internal async Task> FiltrarConfig(string value) - { - List configExtratoImports = await Task.Run>(() => this.FiltrarDescricao(value)); - return configExtratoImports; - } - - public List FiltrarDescricao(string filter) - { - this.ConfigFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Config) : new ObservableCollection( - from x in this.Config - where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Descricao() - select x)); - return this.ConfigFiltrados.ToList(); - } - - public List FiltrarSeguradora(string filter) - { - this.Pesquisa = filter; - this.SeguradorasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Seguradoras) : new ObservableCollection(this.Seguradoras.Where((Seguradora x) => { - if (ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))) - { - return true; - } - return ValidationHelper.RemoveDiacritics(x.get_NomeSocial()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)); - }).OrderByDescending((Seguradora x) => x.get_Ativo()).ThenBy((Seguradora x) => x.get_Nome()))); - return this.SeguradorasFiltradas.ToList(); - } - - public async void Incluir(Seguradora seguradora) - { - seguradora.set_Tolerancia(new decimal?(2)); - seguradora.set_ToleranciaPremio(new decimal?(2)); - seguradora.set_Ativo(true); - await this._servico.Insert(seguradora); - if (this._servico.Sucesso) - { - await this.SelecionaSeguradoras(seguradora); - } - } - - public void IncluirEndereco() - { - if (this.SelectedSeguradora == null) - { - return; - } - if (this.Enderecos == null) - { - this.Enderecos = new ObservableCollection(); - } - SeguradoraEndereco seguradoraEndereco = new SeguradoraEndereco(); - seguradoraEndereco.set_Empresa(Recursos.Empresa); - seguradoraEndereco.set_Seguradora(this.SelectedSeguradora); - seguradoraEndereco.set_Tipo(4); - SeguradoraEndereco seguradoraEndereco1 = seguradoraEndereco; - this.Enderecos.Add(seguradoraEndereco1); - this.SelectedEndereco = seguradoraEndereco1; - } - - public void IncluirTelefone() - { - if (this.SelectedSeguradora == null) - { - return; - } - if (this.Contatos == null) - { - this.Contatos = new ObservableCollection(); - } - SeguradoraContato seguradoraContato = new SeguradoraContato(); - seguradoraContato.set_Empresa(Recursos.Empresa); - seguradoraContato.set_Seguradora(this.SelectedSeguradora); - seguradoraContato.set_Tipo(new TipoTelefone?(2)); - SeguradoraContato seguradoraContato1 = seguradoraContato; - this.Contatos.Add(seguradoraContato1); - this.SelectedTelefone = seguradoraContato1; - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - List> keyValuePairs1 = this.SelectedSeguradora.Validate(); - keyValuePairs1.AddRange(this.Validate(this.Contatos.ToList())); - keyValuePairs1.AddRange(this.Validate(this.Enderecos.ToList())); - if (keyValuePairs1.Count <= 0) - { - Seguradora selectedSeguradora = this.SelectedSeguradora; - ObservableCollection contatos = this.Contatos; - selectedSeguradora.set_Contatos(contatos.Where((SeguradoraContato x) => { - if (!string.IsNullOrEmpty(x.get_NomeContato())) - { - return true; - } - return x.get_TipoContato() == 1; - }).ToList()); - Seguradora seguradora = this.SelectedSeguradora; - ObservableCollection enderecos = this.Enderecos; - seguradora.set_Enderecos(( - from x in enderecos - where !string.IsNullOrEmpty(x.get_Bairro()) - select x).ToList()); - Seguradora seguradora1 = await this._servico.Save(this.SelectedSeguradora, this.Config, false); - Seguradora seguradora2 = seguradora1; - str = (this.SelectedSeguradora.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - string str1 = str; - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str1, " SEGURADORA \"", seguradora2.get_Nome(), "\""), seguradora2.get_Id(), new TipoTela?(13), string.Format("SEGURADORA \"{0}\", ID: {1}", seguradora2.get_Nome(), seguradora2.get_Id())); - await this.SelecionaSeguradoras(null); - this.FiltrarSeguradora(this.Pesquisa); - SeguradoraViewModel seguradoraViewModel = this; - Seguradora seguradora3 = this.SeguradorasFiltradas.FirstOrDefault((Seguradora x) => x.get_Id() == seguradora2.get_Id()); - if (seguradora3 == null) - { - seguradora3 = this.SeguradorasFiltradas.FirstOrDefault(); - } - seguradoraViewModel.SelectedSeguradora = seguradora3; - base.Alterar(false); - base.ToggleSnackBar("SEGURADORA SALVA COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - return keyValuePairs; - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(13); - await this.SelecionaSeguradoras(null); - base.Loading(false); - } - - public async void SelecionaSeguradora(Seguradora seguradora) - { - base.Loading(true); - this.SelectedSeguradora = seguradora; - this.Contatos = await this._servico.BuscarContatos(this.SelectedSeguradora.get_Id()); - this.Enderecos = await this._servico.BuscarEnderecos(this.SelectedSeguradora.get_Id()); - this.Config = await this._servico.BuscarConfig(this.SelectedSeguradora.get_Id()); - this.ConfigFiltrados = new ObservableCollection(this.Config); - base.Loading(false); - } - - private async Task SelecionaSeguradoras(Seguradora seguradora = null) - { - base.Loading(true); - List seguradoras = await (new BaseServico()).BuscarSeguradorasAsync(); - SeguradoraViewModel list = this; - List seguradoras1 = seguradoras; - IOrderedEnumerable ativo = - from x in seguradoras1 - orderby x.get_Ativo() descending - select x; - list.Seguradoras = ativo.ThenBy((Seguradora x) => x.get_Nome()).ToList(); - this.SeguradorasFiltradas = new ObservableCollection(this.Seguradoras); - if (seguradora != null) - { - this.SelecionaSeguradora(this.SeguradorasFiltradas.FirstOrDefault((Seguradora x) => x.get_Id() == seguradora.get_Id())); - } - else if (this.SeguradorasFiltradas.Count <= 0) - { - this.SelectedSeguradora = new Seguradora(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelecionaSeguradora(this.SeguradorasFiltradas.First()); - } - Recursos.Seguradoras = seguradoras; - base.Loading(false); - } - - public List> Validate(List endereco) - { - List> keyValuePairs = new List>(); - if (endereco != null) - { - endereco.ForEach((SeguradoraEndereco x) => keyValuePairs.AddRange(x.Validate())); - } - return keyValuePairs.Distinct>().ToList>(); - } - - public List> Validate(List contatos) - { - List list; - List> keyValuePairs = new List>(); - if (contatos != null) - { - contatos.ForEach((SeguradoraContato x) => keyValuePairs.AddRange(x.Validate())); - } - if (contatos != null) - { - list = ( - from x in contatos - where x.get_TipoContato() == 1 - select x).ToList(); - } - else - { - list = null; - } - List seguradoraContatos = list; - if (seguradoraContatos == null) - { - return keyValuePairs; - } - if (seguradoraContatos.Count > 4) - { - keyValuePairs.Add(new KeyValuePair("ASSISTÊNCIAS 24 HORAS", "NÃO É POSSÍVEL ADICIONAR MAIS QUE 4 NUMEROS DE ASSISTÊNCIA 24 HORAS")); - } - return keyValuePairs.Distinct>().ToList>(); - } - - private void WorkOnSelectedSeguradora(Seguradora value, bool registrar = true) - { - decimal? nullable; - bool contatos; - bool enderecos; - long? nullable1; - decimal? tolerancia; - this.CancelSeguradora = (value == null || value.get_Id() == 0 ? this.CancelSeguradora : (Seguradora)value.Clone()); - this.CancelEnderecos = new ObservableCollection(this.Enderecos); - this.CancelContatos = new ObservableCollection(this.Contatos); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 13) - { - return; - } - Seguradora selectedSeguradora = this.SelectedSeguradora; - if (selectedSeguradora != null) - { - contatos = selectedSeguradora.get_Contatos(); - } - else - { - contatos = false; - } - if (contatos) - { - this.Contatos = new ObservableCollection(this.SelectedSeguradora.get_Contatos()); - } - Seguradora seguradora = this.SelectedSeguradora; - if (seguradora != null) - { - enderecos = seguradora.get_Enderecos(); - } - else - { - enderecos = false; - } - if (enderecos) - { - this.Enderecos = new ObservableCollection(this.SelectedSeguradora.get_Enderecos()); - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU SEGURADORA \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(13), string.Format("ID SEGURADORA: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 13; - Seguradora selectedSeguradora1 = this.SelectedSeguradora; - if (selectedSeguradora1 != null) - { - nullable1 = new long?(selectedSeguradora1.get_Id()); - } - else - { - nullable1 = null; - } - long? nullable2 = nullable1; - long id = value.get_Id(); - if (nullable2.GetValueOrDefault() != id | !nullable2.HasValue) - { - this.SelectedSeguradora = this.SeguradorasFiltradas.FirstOrDefault((Seguradora x) => x.get_Id() == value.get_Id()); - } - Seguradora seguradora1 = this.SelectedSeguradora; - if (seguradora1 != null) - { - tolerancia = seguradora1.get_Tolerancia(); - } - else - { - nullable = null; - tolerancia = nullable; - } - nullable = tolerancia; - this.Tolerancia = nullable.GetValueOrDefault(); - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs deleted file mode 100644 index d946d89..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs +++ /dev/null @@ -1,358 +0,0 @@ -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.Generic; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class SocioViewModel : BaseSegurosViewModel - { - private readonly SocioServico _servico; - - public Socio CancelSocio; - - private ObservableCollection _empresas = new ObservableCollection(); - - private Empresa _selectedEmpresa; - - private Socio _selectedSocio = new Socio(); - - private ObservableCollection _sociosFiltradas = new ObservableCollection(); - - private bool _isExpanded; - - private bool _isLoading; - - public ObservableCollection Empresas - { - get - { - return this._empresas; - } - set - { - this._empresas = value; - base.OnPropertyChanged("Empresas"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public bool IsLoading - { - get - { - return this._isLoading; - } - set - { - this._isLoading = value; - base.OnPropertyChanged("IsLoading"); - } - } - - public Empresa SelectedEmpresa - { - get - { - return this._selectedEmpresa; - } - set - { - this._selectedEmpresa = value; - this.WorkOnSelectedEmpresa(value); - base.OnPropertyChanged("SelectedEmpresa"); - } - } - - public Socio SelectedSocio - { - get - { - return this._selectedSocio; - } - set - { - long? nullable; - this._selectedSocio = value; - this.WorkOnSelectedSocio(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedSocio"); - } - } - - public List Socios - { - get; - set; - } - - public ObservableCollection SociosFiltradas - { - get - { - return this._sociosFiltradas; - } - set - { - this._sociosFiltradas = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("SociosFiltradas"); - } - } - - public SocioViewModel() - { - this._servico = new SocioServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelSocio == null || !this.Socios.Any((Socio x) => x.get_Id() == this.CancelSocio.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Socios.First((Socio x) => x.get_Id() == this.CancelSocio.get_Id()), this.CancelSocio); - if (this.SociosFiltradas.Count <= 0 || !this.SociosFiltradas.Any((Socio x) => x.get_Id() == this.CancelSocio.get_Id())) - { - this.SociosFiltradas.Add(this.CancelSocio); - } - else - { - DomainBase.Copy(this.SociosFiltradas.First((Socio x) => x.get_Id() == this.CancelSocio.get_Id()), this.CancelSocio); - } - this.SociosFiltradas = new ObservableCollection(this.SociosFiltradas); - this.SelectedSocio = this.SociosFiltradas.First((Socio x) => x.get_Id() == this.CancelSocio.get_Id()); - } - base.Alterar(false); - } - - public async void Excluir() - { - Socio socio; - if (this.SelectedSocio != null && this.SelectedSocio.get_Id() != 0) - { - if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false)) - { - base.Loading(true); - this.IsLoading = true; - if (await this._servico.Delete(this.SelectedSocio)) - { - string str = string.Concat("EXCLUIU SÓCIO \"", this.SelectedSocio.get_Nome(), "\""); - long id = this.SelectedSocio.get_Id(); - TipoTela? nullable = new TipoTela?(19); - object[] objArray = new object[] { this.SelectedSocio.get_Id(), this.SelectedSocio.get_Prefixo(), this.SelectedSocio.get_Telefone(), this.SelectedSocio.get_Email() }; - base.RegistrarAcao(str, id, nullable, string.Format("ID: {0}\nTELEFONE: ({1}) {2}\nE-MAIL: {3}", objArray)); - int num = this.SociosFiltradas.IndexOf(this.SelectedSocio); - this.Socios.Remove(this.SelectedSocio); - this.SociosFiltradas.Remove(this.SelectedSocio); - this.SociosFiltradas = new ObservableCollection(this.SociosFiltradas); - if (this.SociosFiltradas.Count <= 0) - { - this.SelectedSocio = new Socio(); - base.Alterar(false); - } - else - { - SocioViewModel socioViewModel = this; - socio = (num < this.SociosFiltradas.Count ? this.SociosFiltradas.ElementAt(num) : this.SociosFiltradas.Last()); - socioViewModel.SelectedSocio = socio; - } - base.Loading(false); - this.IsLoading = false; - base.ToggleSnackBar("SÓCIO EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - this.IsLoading = false; - } - } - } - } - - internal async Task> Filtrar(string value) - { - List socios = await Task.Run>(() => this.FiltrarSocio(value)); - return socios; - } - - public List FiltrarSocio(string filter) - { - this.SociosFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Socios) : new ObservableCollection( - from x in this.Socios - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Nome() - select x)); - return this.SociosFiltradas.ToList(); - } - - public void Incluir() - { - Socio socio = new Socio(); - socio.set_IdEmpresa(this.SelectedEmpresa.get_Id()); - this.SelectedSocio = socio; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string str1; - List> keyValuePairs1 = this.SelectedSocio.Validate(); - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedSocio.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Socio socio = await this._servico.Save(this.SelectedSocio); - if (this._servico.Sucesso) - { - string str2 = string.Concat(str1, " SÓCIO \"", socio.get_Nome(), "\""); - long id = socio.get_Id(); - TipoTela? nullable = new TipoTela?(19); - object[] objArray = new object[] { socio.get_Id(), socio.get_Prefixo(), socio.get_Telefone(), socio.get_Email() }; - base.RegistrarAcao(str2, id, nullable, string.Format("ID: {0}\nTELEFONE: ({1}) {2}\nE-MAIL: {3}", objArray)); - if (!this.Socios.Any((Socio x) => x.get_Id() == socio.get_Id())) - { - this.Socios.Add(socio); - } - else - { - DomainBase.Copy(this.Socios.First((Socio x) => x.get_Id() == socio.get_Id()), socio); - } - if (!this.SociosFiltradas.Any((Socio x) => x.get_Id() == socio.get_Id())) - { - this.SociosFiltradas.Add(socio); - } - else - { - DomainBase.Copy(this.SociosFiltradas.First((Socio x) => x.get_Id() == socio.get_Id()), socio); - } - this.SociosFiltradas = new ObservableCollection(this.SociosFiltradas); - this.WorkOnSelectedSocio(socio, false); - base.Alterar(false); - base.ToggleSnackBar("SÓCIO 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(19); - this.Empresas = new ObservableCollection(await (new EmpresaServico()).BuscarEmpresas()); - base.Loading(false); - this.SelectedEmpresa = this.Empresas.FirstOrDefault(); - } - - private async Task SelecionaSocios(long? id) - { - this.Socios = null; - this.SociosFiltradas = null; - if (id.HasValue) - { - long? nullable = id; - long num = (long)0; - if (!(nullable.GetValueOrDefault() == num & nullable.HasValue)) - { - base.Loading(true); - List socios = await (new BaseServico()).BuscarSociosAsync(id.Value); - SocioViewModel list = this; - List socios1 = socios; - list.Socios = ( - from x in socios1 - orderby x.get_Nome() - select x).ToList(); - this.SociosFiltradas = new ObservableCollection(this.Socios); - this.SelectedSocio = this.SociosFiltradas.FirstOrDefault(); - base.Loading(false); - return; - } - } - } - - private async void WorkOnSelectedEmpresa(Empresa value) - { - if (value != null && value.get_Id() != 0) - { - await this.SelecionaSocios(new long?(value.get_Id())); - } - } - - private void WorkOnSelectedSocio(Socio value, bool registrar = true) - { - long? nullable; - this.CancelSocio = (value == null || value.get_Id() == 0 ? this.CancelSocio : (Socio)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 19) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU SÓCIO \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(19), string.Format("ID: {0}\nTELEFONE: ({1}) {2}\nE-MAIL: {3}", new object[] { value.get_Id(), value.get_Prefixo(), value.get_Telefone(), value.get_Email() })); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 19; - Socio selectedSocio = this.SelectedSocio; - if (selectedSocio != null) - { - nullable = new long?(selectedSocio.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedSocio = this.SociosFiltradas.FirstOrDefault((Socio x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/StatusProspeccaoViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/StatusProspeccaoViewModel.cs deleted file mode 100644 index 4643cd1..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/StatusProspeccaoViewModel.cs +++ /dev/null @@ -1,326 +0,0 @@ -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.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.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class StatusProspeccaoViewModel : BaseSegurosViewModel - { - private readonly StatusProspeccaoServico _servico; - - private readonly ProspeccaoServico _servicoProspeccao; - - public StatusDeProspeccao CancelStatusProspeccao; - - private ObservableCollection _statusProspeccaoFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - private StatusDeProspeccao _selectedStatusProspeccao; - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public StatusDeProspeccao SelectedStatusProspeccao - { - get - { - return this._selectedStatusProspeccao; - } - set - { - long? nullable; - this._selectedStatusProspeccao = value; - this.WorkOnSelectedStatusProspeccao(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedStatusProspeccao"); - } - } - - public List StatusProspeccao - { - get; - set; - } - - public ObservableCollection StatusProspeccaoFiltrados - { - get - { - return this._statusProspeccaoFiltrados; - } - set - { - this._statusProspeccaoFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("StatusProspeccaoFiltrados"); - } - } - - public StatusProspeccaoViewModel() - { - this._servico = new StatusProspeccaoServico(); - this._servicoProspeccao = new ProspeccaoServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelStatusProspeccao == null || !this.StatusProspeccao.Any((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.StatusProspeccao.First((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id()), this.CancelStatusProspeccao); - if (this.StatusProspeccaoFiltrados.Count <= 0 || !this.StatusProspeccaoFiltrados.Any((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id())) - { - this.StatusProspeccaoFiltrados.Add(this.CancelStatusProspeccao); - } - else - { - DomainBase.Copy(this.StatusProspeccaoFiltrados.First((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id()), this.CancelStatusProspeccao); - } - this.StatusProspeccaoFiltrados = new ObservableCollection(this.StatusProspeccaoFiltrados); - this.SelectedStatusProspeccao = this.StatusProspeccaoFiltrados.First((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id()); - } - base.Alterar(false); - } - - public async void Excluir() - { - object obj; - if (this.SelectedStatusProspeccao != null && this.SelectedStatusProspeccao.get_Id() != 0) - { - if (await this._servicoProspeccao.BuscarProspeccoesPorStatus(this.SelectedStatusProspeccao).Count > 0) - { - await base.ShowMessage(string.Concat("O STATUS ", this.SelectedStatusProspeccao.get_Nome(), ", NÃO PODE SER EXCLUÍDO, POIS ESTÁ CADASTRADO EM UMA PROSPECÇÃO"), "OK", "", false); - } - else if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR O STATUS DE PROSPECÇÃO ", this.SelectedStatusProspeccao.get_Nome(), "?"), "SIM", "NÃO", false)) - { - base.Loading(true); - this.SelectedStatusProspeccao.set_Excluido(true); - this.SelectedStatusProspeccao.set_Ativo(false); - await this._servico.Save(this.SelectedStatusProspeccao); - if (this._servico.Sucesso) - { - StatusProspeccaoViewModel statusProspeccaoViewModel = this; - string str = string.Concat("EXCLUIU STATUS DE PROSPECÇÃO \"", this.SelectedStatusProspeccao.get_Nome(), "\""); - long id = this.SelectedStatusProspeccao.get_Id(); - TipoTela? nullable = new TipoTela?(57); - object id1 = this.SelectedStatusProspeccao.get_Id(); - obj = (this.SelectedStatusProspeccao.get_Ativo() ? "SIM" : "NÃO"); - statusProspeccaoViewModel.RegistrarAcao(str, id, nullable, string.Format("ID: {0}\nATIVO: {1}\nDESCRIÇÃO: \"{2}\"", id1, obj, this.SelectedStatusProspeccao.get_Descricao())); - this.StatusProspeccao.Remove(this.SelectedStatusProspeccao); - this.StatusProspeccaoFiltrados.Remove(this.SelectedStatusProspeccao); - Recursos.StatusProspeccao.Remove(this.SelectedStatusProspeccao); - this.SelectedStatusProspeccao = this.StatusProspeccaoFiltrados.FirstOrDefault(); - await this.SelecionaStatusProspeccao(); - base.Loading(false); - base.ToggleSnackBar("STATUS DE PROSPECÇÃO EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - public async Task> Filtrar(string value) - { - List statusDeProspeccaos = await Task.Run>(() => this.FiltrarStatusProspeccao(value)); - return statusDeProspeccaos; - } - - public List FiltrarStatusProspeccao(string filter) - { - this.StatusProspeccaoFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.StatusProspeccao) : new ObservableCollection( - from x in this.StatusProspeccao - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Ativo() descending, x.get_Nome() - select x)); - this.SelectedStatusProspeccao = this.StatusProspeccaoFiltrados.FirstOrDefault(); - return this.StatusProspeccaoFiltrados.ToList(); - } - - public void Incluir() - { - StatusDeProspeccao statusDeProspeccao = new StatusDeProspeccao(); - statusDeProspeccao.set_Ativo(true); - statusDeProspeccao.set_Excluido(false); - this.SelectedStatusProspeccao = statusDeProspeccao; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - object obj; - string str1; - List> keyValuePairs1 = this.SelectedStatusProspeccao.Validate(); - keyValuePairs1.AddRange(this.Validate()); - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedStatusProspeccao.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - StatusDeProspeccao statusDeProspeccao = await this._servico.Save(this.SelectedStatusProspeccao); - if (this._servico.Sucesso) - { - StatusProspeccaoViewModel statusProspeccaoViewModel = this; - string str2 = string.Concat(str1, " STATUS DE PROSPECÇÃO \"", statusDeProspeccao.get_Nome(), "\""); - long id = statusDeProspeccao.get_Id(); - TipoTela? nullable = new TipoTela?(57); - object id1 = statusDeProspeccao.get_Id(); - obj = (statusDeProspeccao.get_Ativo() ? "SIM" : "NÃO"); - statusProspeccaoViewModel.RegistrarAcao(str2, id, nullable, string.Format("ID: {0}\nATIVO: {1}\nDESCRIÇÃO: \"{2}\"", id1, obj, statusDeProspeccao.get_Descricao())); - if (!this.StatusProspeccao.Any((StatusDeProspeccao x) => x.get_Id() == statusDeProspeccao.get_Id())) - { - this.StatusProspeccao.Add(statusDeProspeccao); - } - else - { - DomainBase.Copy(this.StatusProspeccao.First((StatusDeProspeccao x) => x.get_Id() == statusDeProspeccao.get_Id()), statusDeProspeccao); - } - if (!this.StatusProspeccaoFiltrados.Any((StatusDeProspeccao x) => x.get_Id() == statusDeProspeccao.get_Id())) - { - this.StatusProspeccaoFiltrados.Add(statusDeProspeccao); - } - else - { - DomainBase.Copy(this.StatusProspeccaoFiltrados.First((StatusDeProspeccao x) => x.get_Id() == statusDeProspeccao.get_Id()), statusDeProspeccao); - } - this.StatusProspeccaoFiltrados = new ObservableCollection(this.StatusProspeccaoFiltrados); - this.WorkOnSelectedStatusProspeccao(statusDeProspeccao, false); - Recursos.StatusProspeccao = this.StatusProspeccao; - base.Alterar(false); - base.ToggleSnackBar("STATUS DE PROSPECÇÃO 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(57); - await this.SelecionaStatusProspeccao(); - base.Loading(false); - } - - private async Task SelecionaStatusProspeccao() - { - base.Loading(true); - List statusDeProspeccaos = await this._servico.BuscarProspeccoes(); - StatusProspeccaoViewModel list = this; - List statusDeProspeccaos1 = statusDeProspeccaos; - IEnumerable excluido = - from x in statusDeProspeccaos1 - where !x.get_Excluido() - select x; - IOrderedEnumerable ativo = - from x in excluido - orderby x.get_Ativo() descending - select x; - list.StatusProspeccao = ativo.ThenBy((StatusDeProspeccao x) => x.get_Nome()).ToList(); - this.StatusProspeccaoFiltrados = new ObservableCollection(this.StatusProspeccao); - this.SelectedStatusProspeccao = this.StatusProspeccaoFiltrados.FirstOrDefault(); - base.Loading(false); - } - - public List> Validate() - { - List> keyValuePairs = new List>(); - if (string.IsNullOrWhiteSpace(this.SelectedStatusProspeccao.get_Nome())) - { - return keyValuePairs; - } - if (this.StatusProspeccao.Any((StatusDeProspeccao x) => { - if (!x.get_Nome().Contains(this.SelectedStatusProspeccao.get_Nome())) - { - return false; - } - return x.get_Id() != this.SelectedStatusProspeccao.get_Id(); - })) - { - keyValuePairs.Add(new KeyValuePair("Nome", "UM STATUS DE PROSPECÇÃO COM O MESMO NOME JÁ EXISTE.")); - } - return keyValuePairs; - } - - private void WorkOnSelectedStatusProspeccao(StatusDeProspeccao value, bool registrar = true) - { - long? nullable; - this.CancelStatusProspeccao = (value == null || value.get_Id() == 0 ? this.CancelStatusProspeccao : (StatusDeProspeccao)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 57) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU STATUS DE PROSPECÇÃO \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(57), string.Format("ID: {0}\nATIVO: {1}\nDESCRIÇÃO: \"{2}\"", value.get_Id(), (value.get_Ativo() ? "SIM" : "NÃO"), value.get_Descricao())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 57; - StatusDeProspeccao selectedStatusProspeccao = this.SelectedStatusProspeccao; - if (selectedStatusProspeccao != null) - { - nullable = new long?(selectedStatusProspeccao.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedStatusProspeccao = this.StatusProspeccaoFiltrados.FirstOrDefault((StatusDeProspeccao x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/StatusViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/StatusViewModel.cs deleted file mode 100644 index 93b36c1..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/StatusViewModel.cs +++ /dev/null @@ -1,367 +0,0 @@ -using Gestor.Application.Helpers; -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.Generic; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class StatusViewModel : BaseSegurosViewModel - { - private readonly StatusServico _servico; - - private Gestor.Model.Domain.Seguros.Status _selectedStatus; - - public Gestor.Model.Domain.Seguros.Status CancelStatus; - - private ObservableCollection _statusFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public Gestor.Model.Domain.Seguros.Status SelectedStatus - { - get - { - return this._selectedStatus; - } - set - { - long? nullable; - this._selectedStatus = value; - this.WorkOnSelectedStatus(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedStatus"); - } - } - - public List Status - { - get; - set; - } - - public ObservableCollection StatusFiltrados - { - get - { - return this._statusFiltrados; - } - set - { - this._statusFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("StatusFiltrados"); - } - } - - public StatusViewModel() - { - this._servico = new StatusServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelStatus == null || !this.Status.Any((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == this.CancelStatus.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Status.First((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == this.CancelStatus.get_Id()), this.CancelStatus); - if (this.StatusFiltrados.Count <= 0 || !this.StatusFiltrados.Any((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == this.CancelStatus.get_Id())) - { - this.StatusFiltrados.Add(this.CancelStatus); - } - else - { - DomainBase.Copy(this.StatusFiltrados.First((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == this.CancelStatus.get_Id()), this.CancelStatus); - } - this.StatusFiltrados = new ObservableCollection(this.StatusFiltrados); - this.SelectedStatus = this.StatusFiltrados.First((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == this.CancelStatus.get_Id()); - } - base.Alterar(false); - } - - public async void Excluir() - { - object obj; - Gestor.Model.Domain.Seguros.Status statu; - if (this.SelectedStatus != null && this.SelectedStatus.get_Id() != 0) - { - base.Loading(true); - List documentos = await (new BaseServico()).BuscarDocumentosPorStatus(this.SelectedStatus.get_Id()); - base.Loading(false); - if (documentos.Count > 0) - { - string str = "ESTIPULANTE NÃO PODE SER EXCLUÍDO POIS ESTÁ VINCULADO AOS SEGUINTES DOCUMENTOS:"; - foreach (Documento documento in documentos) - { - if (!string.IsNullOrWhiteSpace(documento.get_Apolice())) - { - object[] newLine = new object[] { Environment.NewLine, documentos.IndexOf(documento) + 1, documento.get_Proposta(), documento.get_Apolice() }; - str = string.Concat(str, string.Format("{0}DOCUMENTO {1} (NÚMERO DA PROPOSTA: {2}, NÚMERO DA APÓLICE: {3})", newLine)); - } - else - { - str = string.Concat(str, string.Format("{0}DOCUMENTO {1} (NÚMERO DA PROPOSTA: {2})", Environment.NewLine, documentos.IndexOf(documento) + 1, documento.get_Proposta())); - } - } - await base.ShowMessage(str, "OK", "", false); - } - else if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false)) - { - base.Loading(true); - if (await this._servico.Delete(this.SelectedStatus)) - { - StatusViewModel statusViewModel = this; - string str1 = string.Concat("EXCLUIU STATUS \"", this.SelectedStatus.get_Nome(), "\""); - long id = this.SelectedStatus.get_Id(); - TipoTela? nullable = new TipoTela?(11); - object id1 = this.SelectedStatus.get_Id(); - obj = (this.SelectedStatus.get_Ativo() ? "SIM" : "NÃO"); - statusViewModel.RegistrarAcao(str1, id, nullable, string.Format("ID: {0}\nATIVO: {1}", id1, obj)); - int num = this.StatusFiltrados.IndexOf(this.SelectedStatus); - this.Status.Remove(this.SelectedStatus); - this.StatusFiltrados.Remove(this.SelectedStatus); - this.StatusFiltrados = new ObservableCollection(this.StatusFiltrados); - if (this.StatusFiltrados.Count <= 0) - { - this.SelectedStatus = new Gestor.Model.Domain.Seguros.Status(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - StatusViewModel statusViewModel1 = this; - statu = (num < this.StatusFiltrados.Count ? this.StatusFiltrados.ElementAt(num) : this.StatusFiltrados.Last()); - statusViewModel1.SelectedStatus = statu; - } - base.Loading(false); - base.ToggleSnackBar("ESTIPULANTE EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - internal async Task> Filtrar(string value) - { - List statuses = await Task.Run>(() => this.FiltrarStatus(value)); - return statuses; - } - - public List FiltrarStatus(string filter) - { - this.StatusFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Status) : new ObservableCollection( - from x in this.Status - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Ativo() descending, x.get_Nome() - select x)); - return this.StatusFiltrados.ToList(); - } - - public void Incluir() - { - Gestor.Model.Domain.Seguros.Status statu = new Gestor.Model.Domain.Seguros.Status(); - statu.set_Ativo(true); - this.SelectedStatus = statu; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - object obj; - string str1; - List> keyValuePairs1 = this.SelectedStatus.Validate(); - List> keyValuePairs2 = keyValuePairs1; - keyValuePairs2.AddRange(await this.Validate()); - keyValuePairs2 = null; - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedStatus.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Gestor.Model.Domain.Seguros.Status statu = await this._servico.Save(this.SelectedStatus); - if (this._servico.Sucesso) - { - StatusViewModel statusViewModel = this; - string str2 = string.Concat(str1, " STATUS ID \"", statu.get_Nome(), "\""); - long id = statu.get_Id(); - TipoTela? nullable = new TipoTela?(11); - object id1 = statu.get_Id(); - obj = (statu.get_Ativo() ? "SIM" : "NÃO"); - statusViewModel.RegistrarAcao(str2, id, nullable, string.Format("ID: {0}\nATIVO: {1}", id1, obj)); - if (!this.Status.Any((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == statu.get_Id())) - { - this.Status.Add(statu); - } - else - { - DomainBase.Copy(this.Status.First((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == statu.get_Id()), statu); - } - if (!this.StatusFiltrados.Any((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == statu.get_Id())) - { - this.StatusFiltrados.Add(statu); - } - else - { - DomainBase.Copy(this.StatusFiltrados.First((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == statu.get_Id()), statu); - } - this.StatusFiltrados = new ObservableCollection(this.StatusFiltrados); - this.WorkOnSelectedStatus(statu, false); - Recursos.Status = this.Status; - base.Alterar(false); - base.ToggleSnackBar("STATUS SALVO COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - keyValuePairs1 = null; - str1 = null; - return keyValuePairs; - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(11); - await this.SelecionaStatuses(); - base.Loading(false); - } - - public async void SelecionaStatus(Gestor.Model.Domain.Seguros.Status status) - { - Gestor.Model.Domain.Seguros.Status statu = await this._servico.BuscarStatusPorId(status.get_Id()); - DomainBase.Copy(this.StatusFiltrados.First((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == status.get_Id()), statu); - this.SelectedStatus = this.StatusFiltrados.First((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == status.get_Id()); - } - - private async Task SelecionaStatuses() - { - base.Loading(true); - List statuses = await (new BaseServico()).BuscarStatusAsync(); - StatusViewModel list = this; - List statuses1 = statuses; - IOrderedEnumerable ativo = - from x in statuses1 - orderby x.get_Ativo() descending - select x; - list.Status = ativo.ThenBy((Gestor.Model.Domain.Seguros.Status x) => x.get_Nome()).ToList(); - this.StatusFiltrados = new ObservableCollection(this.Status); - this.SelectedStatus = this.StatusFiltrados.FirstOrDefault(); - Recursos.Status = this.Status; - base.Loading(false); - } - - public async Task>> Validate() - { - List> keyValuePairs; - List> keyValuePairs1; - if (!string.IsNullOrWhiteSpace(this.SelectedStatus.get_Nome())) - { - keyValuePairs1 = new List>(); - bool flag = true; - List statuses = await (new BaseServico()).BuscarStatus(this.SelectedStatus.get_Nome()); - if (statuses.Count > 0) - { - statuses.ForEach((Gestor.Model.Domain.Seguros.Status x) => { - if (x.get_Id() == this.SelectedStatus.get_Id()) - { - return; - } - if (x.get_Nome() == this.SelectedStatus.get_Nome()) - { - flag = false; - } - }); - } - if (!flag) - { - keyValuePairs1.Add(new KeyValuePair("Nome", "UM STATUS COM O MESMO NOME JÁ EXISTE.")); - } - keyValuePairs = keyValuePairs1; - } - else - { - keyValuePairs = new List>(); - } - keyValuePairs1 = null; - return keyValuePairs; - } - - private void WorkOnSelectedStatus(Gestor.Model.Domain.Seguros.Status value, bool registrar = true) - { - long? nullable; - this.CancelStatus = (value == null || value.get_Id() == 0 ? this.CancelStatus : (Gestor.Model.Domain.Seguros.Status)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 11) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU STATUS \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(11), string.Format("ID: {0}\nATIVO: {1}", value.get_Id(), (value.get_Ativo() ? "SIM" : "NÃO"))); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 11; - Gestor.Model.Domain.Seguros.Status selectedStatus = this.SelectedStatus; - if (selectedStatus != null) - { - nullable = new long?(selectedStatus.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedStatus = this.StatusFiltrados.FirstOrDefault((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/TipoTarefaViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/TipoTarefaViewModel.cs deleted file mode 100644 index 07b51e1..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/TipoTarefaViewModel.cs +++ /dev/null @@ -1,325 +0,0 @@ -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.Ferramentas; -using Gestor.Model.Domain.Generic; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class TipoTarefaViewModel : BaseSegurosViewModel - { - private readonly TipoTarefaServico _servico; - - private readonly TarefaServico _servicoTarefa; - - public TipoDeTarefa CancelTipoTarefa; - - private ObservableCollection _tiposTarefaFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - private TipoDeTarefa _selectedTipoTarefa; - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public TipoDeTarefa SelectedTipoTarefa - { - get - { - return this._selectedTipoTarefa; - } - set - { - long? nullable; - this._selectedTipoTarefa = value; - this.WorkOnSelectedTipoTarefa(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedTipoTarefa"); - } - } - - public List TiposTarefa - { - get; - set; - } - - public ObservableCollection TiposTarefaFiltrados - { - get - { - return this._tiposTarefaFiltrados; - } - set - { - this._tiposTarefaFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("TiposTarefaFiltrados"); - } - } - - public TipoTarefaViewModel() - { - this._servico = new TipoTarefaServico(); - this._servicoTarefa = new TarefaServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelTipoTarefa == null || !this.TiposTarefa.Any((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.TiposTarefa.First((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id()), this.CancelTipoTarefa); - if (this.TiposTarefaFiltrados.Count <= 0 || !this.TiposTarefaFiltrados.Any((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id())) - { - this.TiposTarefaFiltrados.Add(this.CancelTipoTarefa); - } - else - { - DomainBase.Copy(this.TiposTarefaFiltrados.First((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id()), this.CancelTipoTarefa); - } - this.TiposTarefaFiltrados = new ObservableCollection(this.TiposTarefaFiltrados); - this.SelectedTipoTarefa = this.TiposTarefaFiltrados.First((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id()); - } - base.Alterar(false); - } - - public async void Excluir() - { - object obj; - if (this.SelectedTipoTarefa != null && this.SelectedTipoTarefa.get_Id() != 0) - { - if (await this._servicoTarefa.BuscarTarefasPorTipo(this.SelectedTipoTarefa).Count > 0) - { - await base.ShowMessage(string.Concat("O TIPO ", this.SelectedTipoTarefa.get_Nome(), ", NÃO PODE SER EXCLUÍDO, POIS ESTÁ CADASTRADO EM UMA TAREFA"), "OK", "", false); - } - else if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR O TIPO DE TAREFA ", this.SelectedTipoTarefa.get_Nome(), "?"), "SIM", "NÃO", false)) - { - base.Loading(true); - this.SelectedTipoTarefa.set_Excluido(true); - this.SelectedTipoTarefa.set_Ativo(false); - await this._servico.Save(this.SelectedTipoTarefa); - if (this._servico.Sucesso) - { - TipoTarefaViewModel tipoTarefaViewModel = this; - string str = string.Concat("EXCLUIU TIPO DE TAREFA \"", this.SelectedTipoTarefa.get_Nome(), "\""); - long id = this.SelectedTipoTarefa.get_Id(); - TipoTela? nullable = new TipoTela?(52); - object id1 = this.SelectedTipoTarefa.get_Id(); - obj = (this.SelectedTipoTarefa.get_Ativo() ? "SIM" : "NÃO"); - tipoTarefaViewModel.RegistrarAcao(str, id, nullable, string.Format("ID: {0}\nATIVO: {1}\nDESCRIÇÃO: \"{2}\"", id1, obj, this.SelectedTipoTarefa.get_Descricao())); - this.TiposTarefa.Remove(this.SelectedTipoTarefa); - this.TiposTarefaFiltrados.Remove(this.SelectedTipoTarefa); - Recursos.TiposTarefa.Remove(this.SelectedTipoTarefa); - this.SelectedTipoTarefa = this.TiposTarefaFiltrados.FirstOrDefault(); - await this.SelecionaTipoTarefa(); - base.Loading(false); - base.ToggleSnackBar("TIPO DE TAREFA EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - public async Task> Filtrar(string value) - { - List tipoDeTarefas = await Task.Run>(() => this.FiltrarTipoTarefa(value)); - return tipoDeTarefas; - } - - public List FiltrarTipoTarefa(string filter) - { - this.TiposTarefaFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.TiposTarefa) : new ObservableCollection( - from x in this.TiposTarefa - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Ativo() descending, x.get_Nome() - select x)); - this.SelectedTipoTarefa = this.TiposTarefaFiltrados.FirstOrDefault(); - return this.TiposTarefaFiltrados.ToList(); - } - - public void Incluir() - { - TipoDeTarefa tipoDeTarefa = new TipoDeTarefa(); - tipoDeTarefa.set_Ativo(true); - tipoDeTarefa.set_Excluido(false); - this.SelectedTipoTarefa = tipoDeTarefa; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - object obj; - string str1; - List> keyValuePairs1 = this.SelectedTipoTarefa.Validate(); - keyValuePairs1.AddRange(this.Validate()); - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedTipoTarefa.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - TipoDeTarefa tipoDeTarefa = await this._servico.Save(this.SelectedTipoTarefa); - if (this._servico.Sucesso) - { - TipoTarefaViewModel tipoTarefaViewModel = this; - string str2 = string.Concat(str1, " TIPO DE TAREFA \"", tipoDeTarefa.get_Nome(), "\""); - long id = tipoDeTarefa.get_Id(); - TipoTela? nullable = new TipoTela?(52); - object id1 = tipoDeTarefa.get_Id(); - obj = (tipoDeTarefa.get_Ativo() ? "SIM" : "NÃO"); - tipoTarefaViewModel.RegistrarAcao(str2, id, nullable, string.Format("ID: {0}\nATIVO: {1}\nDESCRIÇÃO: \"{2}\"", id1, obj, tipoDeTarefa.get_Descricao())); - if (!this.TiposTarefa.Any((TipoDeTarefa x) => x.get_Id() == tipoDeTarefa.get_Id())) - { - this.TiposTarefa.Add(tipoDeTarefa); - } - else - { - DomainBase.Copy(this.TiposTarefa.First((TipoDeTarefa x) => x.get_Id() == tipoDeTarefa.get_Id()), tipoDeTarefa); - } - if (!this.TiposTarefaFiltrados.Any((TipoDeTarefa x) => x.get_Id() == tipoDeTarefa.get_Id())) - { - this.TiposTarefaFiltrados.Add(tipoDeTarefa); - } - else - { - DomainBase.Copy(this.TiposTarefaFiltrados.First((TipoDeTarefa x) => x.get_Id() == tipoDeTarefa.get_Id()), tipoDeTarefa); - } - this.TiposTarefaFiltrados = new ObservableCollection(this.TiposTarefaFiltrados); - this.WorkOnSelectedTipoTarefa(tipoDeTarefa, false); - Recursos.TiposTarefa = this.TiposTarefa; - base.Alterar(false); - base.ToggleSnackBar("TIPO DE TAREFA 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(52); - await this.SelecionaTipoTarefa(); - base.Loading(false); - } - - private async Task SelecionaTipoTarefa() - { - base.Loading(true); - List tipoDeTarefas = await this._servico.BuscarTarefas(); - TipoTarefaViewModel list = this; - List tipoDeTarefas1 = tipoDeTarefas; - IEnumerable excluido = - from x in tipoDeTarefas1 - where !x.get_Excluido() - select x; - IOrderedEnumerable ativo = - from x in excluido - orderby x.get_Ativo() descending - select x; - list.TiposTarefa = ativo.ThenBy((TipoDeTarefa x) => x.get_Nome()).ToList(); - this.TiposTarefaFiltrados = new ObservableCollection(this.TiposTarefa); - this.SelectedTipoTarefa = this.TiposTarefaFiltrados.FirstOrDefault(); - base.Loading(false); - } - - public List> Validate() - { - List> keyValuePairs = new List>(); - if (string.IsNullOrWhiteSpace(this.SelectedTipoTarefa.get_Nome())) - { - return keyValuePairs; - } - if (this.TiposTarefa.Any((TipoDeTarefa x) => { - if (!x.get_Nome().Contains(this.SelectedTipoTarefa.get_Nome())) - { - return false; - } - return x.get_Id() != this.SelectedTipoTarefa.get_Id(); - })) - { - keyValuePairs.Add(new KeyValuePair("Nome", "UM TIPO DE TAREFA COM O MESMO NOME JÁ EXISTE.")); - } - return keyValuePairs; - } - - private void WorkOnSelectedTipoTarefa(TipoDeTarefa value, bool registrar = true) - { - long? nullable; - this.CancelTipoTarefa = (value == null || value.get_Id() == 0 ? this.CancelTipoTarefa : (TipoDeTarefa)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 52) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU TIPO DE TAREFA \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(52), string.Format("ID: {0}\nATIVO: {1}\nDESCRIÇÃO: \"{2}\"", value.get_Id(), (value.get_Ativo() ? "SIM" : "NÃO"), value.get_Descricao())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 52; - TipoDeTarefa selectedTipoTarefa = this.SelectedTipoTarefa; - if (selectedTipoTarefa != null) - { - nullable = new long?(selectedTipoTarefa.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedTipoTarefa = this.TiposTarefaFiltrados.FirstOrDefault((TipoDeTarefa x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/TipoVendedorViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/TipoVendedorViewModel.cs deleted file mode 100644 index c4ff8bc..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/TipoVendedorViewModel.cs +++ /dev/null @@ -1,338 +0,0 @@ -using Gestor.Application.Helpers; -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.Generic; -using Gestor.Model.Domain.Seguros; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class TipoVendedorViewModel : BaseSegurosViewModel - { - private readonly TipoVendedorServico _servico; - - public TipoVendedor CancelTipoVendedor; - - private Visibility _ativoVisibility = Visibility.Collapsed; - - private TipoVendedor _selectedTipoVendedor = new TipoVendedor(); - - private ObservableCollection _tipoVendedoresFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - public Visibility AtivoVisibility - { - get - { - return this._ativoVisibility; - } - set - { - this._ativoVisibility = value; - base.OnPropertyChanged("AtivoVisibility"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public TipoVendedor SelectedTipoVendedor - { - get - { - return this._selectedTipoVendedor; - } - set - { - long? nullable; - this._selectedTipoVendedor = value; - this.WorkOnSelectedTipoVendedor(value, true); - this.AtivoVisibility = ((value != null ? value.get_Id() != (long)1 : true) ? Visibility.Visible : Visibility.Collapsed); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedTipoVendedor"); - } - } - - public List TipoVendedores - { - get; - set; - } - - public ObservableCollection TipoVendedoresFiltrados - { - get - { - return this._tipoVendedoresFiltrados; - } - set - { - this._tipoVendedoresFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("TipoVendedoresFiltrados"); - } - } - - public TipoVendedorViewModel() - { - this._servico = new TipoVendedorServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public void CancelarAlteracao() - { - if (this.CancelTipoVendedor == null || !this.TipoVendedores.Any((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.TipoVendedores.First((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id()), this.CancelTipoVendedor); - if (this.TipoVendedoresFiltrados.Count <= 0 || !this.TipoVendedoresFiltrados.Any((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id())) - { - this.TipoVendedoresFiltrados.Add(this.CancelTipoVendedor); - } - else - { - DomainBase.Copy(this.TipoVendedoresFiltrados.First((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id()), this.CancelTipoVendedor); - } - this.TipoVendedoresFiltrados = new ObservableCollection(this.TipoVendedoresFiltrados); - this.SelectedTipoVendedor = this.TipoVendedoresFiltrados.First((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id()); - } - base.Alterar(false); - } - - public async void Excluir() - { - object obj; - TipoVendedor tipoVendedor; - if (this.SelectedTipoVendedor != null && this.SelectedTipoVendedor.get_Id() != 0 && this.SelectedTipoVendedor.get_Id() != (long)1) - { - if (await (new BaseServico()).TipoVendedorUtilizado(this.SelectedTipoVendedor.get_Id())) - { - await base.ShowMessage("TIPO VENDEDOR NÃO PODE SER EXCLUÍDO POIS ESTÁ SENDO UTILIZADO.", "OK", "", false); - } - else if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false)) - { - base.Loading(true); - if (await this._servico.Delete(this.SelectedTipoVendedor)) - { - TipoVendedorViewModel tipoVendedorViewModel = this; - string str = string.Concat("EXCLUIU TIPO VENDEDOR \"", this.SelectedTipoVendedor.get_Descricao(), "\""); - long id = this.SelectedTipoVendedor.get_Id(); - TipoTela? nullable = new TipoTela?(14); - object id1 = this.SelectedTipoVendedor.get_Id(); - obj = (!this.SelectedTipoVendedor.get_Ativo().HasValue || !this.SelectedTipoVendedor.get_Ativo().Value ? "NÃO" : "SIM"); - tipoVendedorViewModel.RegistrarAcao(str, id, nullable, string.Format("ID: {0}\nATIVO: {1}", id1, obj)); - int num = this.TipoVendedoresFiltrados.IndexOf(this.SelectedTipoVendedor); - this.TipoVendedores.Remove(this.SelectedTipoVendedor); - this.TipoVendedoresFiltrados.Remove(this.SelectedTipoVendedor); - this.TipoVendedoresFiltrados = new ObservableCollection(this.TipoVendedoresFiltrados); - if (this.TipoVendedoresFiltrados.Count <= 0) - { - this.SelectedTipoVendedor = new TipoVendedor(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - TipoVendedorViewModel tipoVendedorViewModel1 = this; - tipoVendedor = (num < this.TipoVendedoresFiltrados.Count ? this.TipoVendedoresFiltrados.ElementAt(num) : this.TipoVendedoresFiltrados.Last()); - tipoVendedorViewModel1.SelectedTipoVendedor = tipoVendedor; - } - Recursos.TipoVendedor = this.TipoVendedores; - base.Loading(false); - base.ToggleSnackBar("TIPO VENDEDOR EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - internal async Task> Filtrar(string value) - { - List tipoVendedors = await Task.Run>(() => this.FiltrarTipoVendedor(value)); - return tipoVendedors; - } - - public List FiltrarTipoVendedor(string filter) - { - this.TipoVendedoresFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.TipoVendedores) : new ObservableCollection( - from x in this.TipoVendedores - where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Ativo() descending, x.get_Descricao() - select x)); - this.SelectedTipoVendedor = this.TipoVendedoresFiltrados.FirstOrDefault(); - return this.TipoVendedoresFiltrados.ToList(); - } - - public void Incluir() - { - TipoVendedor tipoVendedor = new TipoVendedor(); - tipoVendedor.set_Ativo(new bool?(true)); - tipoVendedor.set_Inserido(new bool?(false)); - this.SelectedTipoVendedor = tipoVendedor; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - object obj; - string str1; - List> keyValuePairs1 = this.SelectedTipoVendedor.Validate(); - if (keyValuePairs1.Count <= 0) - { - str = (this.SelectedTipoVendedor.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - TipoVendedor tipoVendedor = await this._servico.Save(this.SelectedTipoVendedor); - if (this._servico.Sucesso) - { - TipoVendedorViewModel tipoVendedorViewModel = this; - string str2 = string.Concat(str1, " TIPO VENDEDOR \"", tipoVendedor.get_Descricao(), "\""); - long id = tipoVendedor.get_Id(); - TipoTela? nullable = new TipoTela?(14); - object id1 = tipoVendedor.get_Id(); - obj = (!tipoVendedor.get_Ativo().HasValue || !tipoVendedor.get_Ativo().Value ? "NÃO" : "SIM"); - tipoVendedorViewModel.RegistrarAcao(str2, id, nullable, string.Format("ID: {0}\nATIVO: {1}", id1, obj)); - if (!this.TipoVendedores.Any((TipoVendedor x) => x.get_Id() == tipoVendedor.get_Id())) - { - this.TipoVendedores.Add(tipoVendedor); - } - else - { - DomainBase.Copy(this.TipoVendedores.First((TipoVendedor x) => x.get_Id() == tipoVendedor.get_Id()), tipoVendedor); - } - if (!this.TipoVendedoresFiltrados.Any((TipoVendedor x) => x.get_Id() == tipoVendedor.get_Id())) - { - this.TipoVendedoresFiltrados.Add(tipoVendedor); - } - else - { - DomainBase.Copy(this.TipoVendedoresFiltrados.First((TipoVendedor x) => x.get_Id() == tipoVendedor.get_Id()), tipoVendedor); - } - this.TipoVendedoresFiltrados = new ObservableCollection(this.TipoVendedoresFiltrados); - this.WorkOnSelectedTipoVendedor(tipoVendedor, false); - Recursos.TipoVendedor = this.TipoVendedores; - base.Alterar(false); - base.ToggleSnackBar("TIPO VENDEDOR SALVO COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - str1 = null; - return keyValuePairs; - } - - public async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(14); - await this.SelecionaTipoVendedores(); - base.Loading(false); - } - - public void SelecionaTipoVendedor(TipoVendedor tipoVendedor) - { - this.SelectedTipoVendedor = tipoVendedor; - } - - private async Task SelecionaTipoVendedores() - { - base.Loading(true); - List tipoVendedors = await (new BaseServico()).BuscarTipoVendedoresAsync(); - TipoVendedorViewModel list = this; - List tipoVendedors1 = tipoVendedors; - IOrderedEnumerable ativo = - from x in tipoVendedors1 - orderby x.get_Ativo() descending - select x; - list.TipoVendedores = ativo.ThenBy((TipoVendedor x) => x.get_Descricao()).ToList(); - this.TipoVendedoresFiltrados = new ObservableCollection(this.TipoVendedores); - if (this.TipoVendedoresFiltrados.Count <= 0) - { - this.SelectedTipoVendedor = new TipoVendedor(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelecionaTipoVendedor(this.TipoVendedoresFiltrados.First()); - } - Recursos.TipoVendedor = tipoVendedors; - base.Loading(false); - } - - private void WorkOnSelectedTipoVendedor(TipoVendedor value, bool registrar = true) - { - long? nullable; - this.CancelTipoVendedor = (value == null || value.get_Id() == 0 ? this.CancelTipoVendedor : (TipoVendedor)value.Clone()); - if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 14) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU TIPO VENDEDOR \"", value.get_Descricao(), "\""), value.get_Id(), new TipoTela?(14), string.Format("ID: {0}\nATIVO: {1}", value.get_Id(), (!value.get_Ativo().HasValue || !value.get_Ativo().Value ? "NÃO" : "SIM"))); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 14; - TipoVendedor selectedTipoVendedor = this.SelectedTipoVendedor; - if (selectedTipoVendedor != null) - { - nullable = new long?(selectedTipoVendedor.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedTipoVendedor = this.TipoVendedoresFiltrados.FirstOrDefault((TipoVendedor x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs deleted file mode 100644 index 7f04040..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs +++ /dev/null @@ -1,826 +0,0 @@ -using Agger.Registro; -using Gestor.Application.Actions; -using Gestor.Application.Drawers; -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.Helpers; -using Gestor.Common.Security; -using Gestor.Common.Validation; -using Gestor.Model.API; -using Gestor.Model.Common; -using Gestor.Model.Domain.Common; -using Gestor.Model.Domain.Generic; -using Gestor.Model.Domain.Seguros; -using MaterialDesignThemes.Wpf; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Net.Http; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class UsuarioViewModel : BaseSegurosViewModel - { - private readonly UsuarioServico _servico; - - private readonly PermissaoUsuarioServico _permissaoUsuarioServico; - - public Usuario CancelUsuario; - - private string _inicioAcesso; - - private string _fimAcesso; - - private Usuario _selectedUsuario; - - private Empresa _selectedFilial; - - private bool _cartaoCriado; - - private ObservableCollection _usuariosFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - private bool _enableGrid = true; - - private Visibility _horarioAcessoVisible; - - private List _empresas = Recursos.Empresas; - - private string _confirmaSenha; - - private string _labelCartao; - - public Visibility AddUsuarioCentralSeguradoVisibility { get; set; } = (string.IsNullOrEmpty(Connection.UrlCentralSegurado) ? Visibility.Collapsed : Visibility.Visible); - - public bool CartaoCriado - { - get - { - return this._cartaoCriado; - } - set - { - this._cartaoCriado = value; - base.OnPropertyChanged("CartaoCriado"); - } - } - - public string ConfirmaSenha - { - get - { - return this._confirmaSenha; - } - set - { - this._confirmaSenha = value; - base.OnPropertyChanged("ConfirmaSenha"); - } - } - - public static DrawerHost Drawer - { - get; - set; - } - - public List Empresas - { - get - { - return this._empresas; - } - set - { - this._empresas = value; - base.OnPropertyChanged("Empresas"); - } - } - - public bool EnableGrid - { - get - { - return this._enableGrid; - } - set - { - this._enableGrid = value; - base.OnPropertyChanged("EnableGrid"); - } - } - - public string FimAcesso - { - get - { - return this._fimAcesso; - } - set - { - this._fimAcesso = value; - base.OnPropertyChanged("FimAcesso"); - } - } - - public Visibility HorarioAcessoVisible - { - get - { - return this._horarioAcessoVisible; - } - set - { - this._horarioAcessoVisible = value; - base.OnPropertyChanged("HorarioAcessoVisible"); - } - } - - public string InicioAcesso - { - get - { - return this._inicioAcesso; - } - set - { - this._inicioAcesso = value; - base.OnPropertyChanged("InicioAcesso"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public string LabelCartao - { - get - { - return this._labelCartao; - } - set - { - this._labelCartao = value; - base.OnPropertyChanged("LabelCartao"); - } - } - - public List PermissaoUsuario - { - get; - set; - } - - public Empresa SelectedFilial - { - get - { - return this._selectedFilial; - } - set - { - this._selectedFilial = value; - base.OnPropertyChanged("SelectedFilial"); - } - } - - public Usuario SelectedUsuario - { - get - { - return this._selectedUsuario; - } - set - { - long? nullable; - this._selectedUsuario = value; - this.WorkOnSelectedUsuario(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedUsuario"); - } - } - - private string SenhaOriginal - { - get; - set; - } - - public List Usuarios - { - get; - set; - } - - public ObservableCollection UsuariosFiltrados - { - get - { - return this._usuariosFiltrados; - } - set - { - this._usuariosFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("UsuariosFiltrados"); - } - } - - public UsuarioViewModel() - { - this._servico = new UsuarioServico(); - this._permissaoUsuarioServico = new PermissaoUsuarioServico(); - base.EnableMenu = true; - } - - public async Task AddUsuarioAdiministadorCentralSegurado() - { - string str; - string str1; - string str2; - string str3; - string str4; - string str5; - string str6; - string str7; - if (this.SelectedUsuario != null) - { - base.Loading(true); - str7 = "USUÁRIO CADASTRADO/ALTERADO COM SUCESSO!"; - try - { - str = (this.SelectedUsuario.get_Telefone() == null ? string.Empty : string.Concat("(", this.SelectedUsuario.get_Prefixo(), ") ", this.SelectedUsuario.get_Telefone())); - string str8 = str; - Token token = new Token(); - UsuarioCentralSegurado usuarioCentralSegurado = new UsuarioCentralSegurado(); - usuarioCentralSegurado.set_Id(""); - usuarioCentralSegurado.set_Senha(""); - usuarioCentralSegurado.set_Serial(token.Encrypt(Recursos.Empresa.get_Serial())); - usuarioCentralSegurado.set_FornecedorId(ApplicationHelper.IdFornecedor); - usuarioCentralSegurado.set_Nome(token.Encrypt(this.SelectedUsuario.get_Nome())); - usuarioCentralSegurado.set_Documento(token.Encrypt(this.SelectedUsuario.get_Documento().Clear())); - usuarioCentralSegurado.set_Email(token.Encrypt(this.SelectedUsuario.get_Email())); - usuarioCentralSegurado.set_IdEmpresa(this.SelectedUsuario.get_IdEmpresa()); - usuarioCentralSegurado.set_Telefone(token.Encrypt(str8)); - str1 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Endereco()) : string.Empty); - usuarioCentralSegurado.set_Rua(str1); - str2 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Numero()) : string.Empty); - usuarioCentralSegurado.set_Numero(str2); - str3 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Bairro()) : string.Empty); - usuarioCentralSegurado.set_Bairro(str3); - str4 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Cidade()) : string.Empty); - usuarioCentralSegurado.set_Cidade(str4); - str5 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Estado()) : string.Empty); - usuarioCentralSegurado.set_Estado(str5); - str6 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Cep()) : string.Empty); - usuarioCentralSegurado.set_Cep(str6); - usuarioCentralSegurado.set_Corretora(token.Encrypt(Recursos.Empresa.get_Nome())); - usuarioCentralSegurado.set_UriCorretora(token.Encrypt(Connection.UrlCentralSegurado)); - usuarioCentralSegurado.set_Admin(this.SelectedUsuario.get_AdministradorCentralSegurado()); - UsuarioCentralSegurado usuarioCentralSegurado1 = usuarioCentralSegurado; - using (HttpClient httpClient = new HttpClient()) - { - StringContent stringContent = new StringContent(JsonConvert.SerializeObject(usuarioCentralSegurado1), Encoding.UTF8, "application/json"); - Uri centralSegurado = Address.get_CentralSegurado(); - string[] strArrays = new string[] { "Usuario" }; - Uri uri = centralSegurado.Append(strArrays); - string[] strArrays1 = new string[] { "AddAggerApp" }; - Uri uri1 = uri.Append(strArrays1); - HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(uri1, stringContent); - await this._servico.AddCentralSegurado(this.SelectedUsuario.get_Id(), httpResponseMessage.get_IsSuccessStatusCode()); - if (!httpResponseMessage.get_IsSuccessStatusCode()) - { - string str9 = await httpResponseMessage.get_Content().ReadAsStringAsync(); - str7 = string.Concat("HOUVE(RAM) O(S) SEGUINTE(S) ERROS: ", str9.Replace(";", ", ").ToUpper()); - } - httpResponseMessage = null; - } - httpClient = null; - } - catch - { - str7 = "HOUVERAM ERROS AO CADASTRAR/ALTERAR O USUÁRIO!"; - } - base.Loading(false); - await base.ShowMessage(str7, "OK", "", false); - } - str7 = null; - } - - public async Task AlterarUsuario() - { - if (this.SelectedUsuario != null) - { - Usuario usuario = await this._servico.BuscarUsuarioPorId(this.SelectedUsuario.get_Id()); - this.SenhaOriginal = (new Token()).AggerDecrypt(usuario.get_Senha()); - await this.SelecionaUsuario(this.SelectedUsuario); - } - } - - public async void AtualizaUsuario() - { - if (!base.EnableFields) - { - await this.CarregarUsuarios(); - } - } - - private async Task BuscaAlteracaoUsuarios(long idUsuario) - { - bool flag; - bool valueOrDefault; - bool flag1; - bool? nullable; - Usuario usuario = await (new UsuarioServico()).BuscarUsuarioPorId(idUsuario); - if (usuario == null) - { - valueOrDefault = false; - } - else - { - if (usuario != null) - { - nullable = new bool?(usuario.get_AdministradorCentralSegurado()); - } - else - { - nullable = null; - } - bool? nullable1 = nullable; - bool administradorCentralSegurado = this.SelectedUsuario.get_AdministradorCentralSegurado(); - valueOrDefault = !(nullable1.GetValueOrDefault() == administradorCentralSegurado & nullable1.HasValue); - } - bool flag2 = valueOrDefault; - flag1 = (flag2 || !this.SelectedUsuario.get_AdministradorCentralSegurado() ? false : this.SelectedUsuario.get_Id() == (long)0); - bool flag3 = flag1; - List usuarios = this.Usuarios; - IEnumerable administradorCentralSegurado1 = - from x in usuarios - where x.get_AdministradorCentralSegurado() - select x; - List list = ( - from x in administradorCentralSegurado1 - orderby x.get_Nome() - select x).ToList(); - if (flag2 && !flag3 && list.Count == 0) - { - if (!await base.ShowMessage("ESTE USUÁRIO É O ÚNICO ADM DA CENTRAL DO SEGURADO.\nTEM CERTEZA QUE DESEJA REMOVER?", "SIM", "CANCELAR", false)) - { - this.CancelarAlteracao(); - flag = false; - return flag; - } - } - if (!(flag3 | flag2) || !string.IsNullOrEmpty(Connection.UrlCentralSegurado)) - { - flag = flag2 | flag3; - } - else - { - if (this.SelectedUsuario != null) - { - this.SelectedUsuario.set_AdministradorCentralSegurado(false); - } - await base.ShowMessage("NÃO FOI POSSÍVEL ADICIONAR UM USUÁRIO ADM CENTRAL SEGURADO, POR FAVOR ENTRE EM CONTATO COM O SUPORTE AGGER. \nURL AUSENTE!", "OK", "", false); - flag = false; - } - return flag; - } - - private async Task BuscaPermissao() - { - this.PermissaoUsuario = await this._permissaoUsuarioServico.PermissUsuario(Recursos.Usuario); - } - - public async Task CancelarAlteracao() - { - long id; - await this.CarregarUsuarios(); - if (!this.UsuariosFiltrados.Any()) - { - this.SelectedUsuario = new Usuario(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - Usuario cancelUsuario = this.CancelUsuario; - if (cancelUsuario != null) - { - id = cancelUsuario.get_Id(); - } - else - { - id = (long)0; - } - long num = id; - this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault((Usuario x) => x.get_Id() == num); - } - base.Alterar(false); - this.ConfirmaSenha = ""; - } - - private async Task CarregarUsuarios() - { - List usuarios = await (new BaseServico()).CarregarUsuarios(); - UsuarioViewModel list = this; - List usuarios1 = usuarios; - IEnumerable usuarios2 = usuarios1.Where((Usuario x) => { - if (x.get_Excluido()) - { - return false; - } - long? permissaoAggilizador = x.get_PermissaoAggilizador(); - long num = (long)4; - return !(permissaoAggilizador.GetValueOrDefault() == num & permissaoAggilizador.HasValue); - }); - list.Usuarios = ( - from x in usuarios2 - orderby x.get_Nome() - select x).ToList(); - this.UsuariosFiltrados = new ObservableCollection(this.Usuarios); - await this.BuscaPermissao(); - } - - public async Task CriarCartao(bool dadosUsuario) - { - await base.ShowMessage("CARTÃO CRIADO/ATUALIZADO COM SUCESSO", "OK", "", false); - } - - public async Task Excluir() - { - if (this.SelectedUsuario != null && this.SelectedUsuario.get_Id() != 0) - { - if (await (new VendedorUsuarioServico()).FindVinculoByUsuario(this.SelectedUsuario.get_Id())) - { - await base.ShowMessage("O USUÁRIO POSSUI VÍNCULO DE VENDEDOR, REMOVA O VÍNCULO ANTES DE EXCLUIR.", "OK", "", false); - } - else if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false)) - { - base.Loading(true); - if (await this._servico.Delete(this.SelectedUsuario)) - { - base.RegistrarAcao(string.Concat("EXCLUIU USUÁRIO \"", this.SelectedUsuario.get_Nome(), "\""), this.SelectedUsuario.get_Id(), new TipoTela?(16), string.Format("ID: {0}", this.SelectedUsuario.get_Id())); - await this.CarregarUsuarios(); - if (!this.UsuariosFiltrados.Any()) - { - this.SelectedUsuario = new Usuario(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault(); - } - base.Loading(false); - base.ToggleSnackBar("USUÁRIO EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - internal async Task> Filtrar(string value) - { - List usuarios = await Task.Run>(() => this.FiltrarUsuario(value)); - return usuarios; - } - - public List FiltrarUsuario(string filter) - { - this.UsuariosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Usuarios) : new ObservableCollection( - from x in this.Usuarios - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby !x.get_Excluido() descending, x.get_Nome() - select x)); - return this.UsuariosFiltrados.ToList(); - } - - public void Incluir() - { - Usuario usuario = new Usuario(); - usuario.set_IdEmpresa(Recursos.Usuario.get_IdEmpresa()); - usuario.set_Segunda(new bool?(true)); - usuario.set_Terca(new bool?(true)); - usuario.set_Quarta(new bool?(true)); - usuario.set_Quinta(new bool?(true)); - usuario.set_Sexta(new bool?(true)); - usuario.set_Sabado(new bool?(true)); - usuario.set_Domingo(new bool?(true)); - usuario.set_Excluido(false); - usuario.set_FiltroInicial(new TipoFiltroCliente?(0)); - this.SelectedUsuario = usuario; - this.SenhaOriginal = null; - base.Alterar(true); - } - - public async Task OpenPermissao() - { - bool selectedUsuario = this.SelectedUsuario == null; - if (selectedUsuario) - { - selectedUsuario = await base.ShowMessage("É NECESSÁRIO SELECIONAR UM USUÁRIO!", "OK", "", false); - } - if (!selectedUsuario) - { - Gestor.Application.Actions.Actions.AtualizaUsuario = (Action)Delegate.Remove(Gestor.Application.Actions.Actions.AtualizaUsuario, new Action(this.AtualizaUsuario)); - Gestor.Application.Actions.Actions.AtualizaUsuario = (Action)Delegate.Combine(Gestor.Application.Actions.Actions.AtualizaUsuario, new Action(this.AtualizaUsuario)); - base.ShowDrawer(new PermissaoUsuarioDrawer(this.SelectedUsuario), 0, false); - } - } - - public async Task OpenVinculo() - { - bool selectedUsuario = this.SelectedUsuario == null; - if (selectedUsuario) - { - selectedUsuario = await base.ShowMessage("É NECESSÁRIO SELECIONAR UM USUÁRIO!", "OK", "", false); - } - if (!selectedUsuario) - { - base.ShowDrawer(new VinculoVendedorDrawer(this.SelectedUsuario), 0, true); - } - } - - public async Task>> Salvar() - { - List> keyValuePairs; - DateTime dateTime; - DateTime dateTime1; - string str; - long num; - string str1; - string str2; - if (!DateTime.TryParse(this.InicioAcesso, out dateTime) || !DateTime.TryParse(this.FimAcesso, out dateTime1)) - { - DateTime? nullable = null; - this.SelectedUsuario.set_InicioAcesso(nullable); - nullable = null; - this.SelectedUsuario.set_FimAcesso(nullable); - } - else - { - this.SelectedUsuario.set_InicioAcesso(new DateTime?(dateTime)); - this.SelectedUsuario.set_FimAcesso(new DateTime?(dateTime1)); - } - Usuario selectedUsuario = this.SelectedUsuario; - str = (!string.IsNullOrEmpty(this.SelectedUsuario.get_Senha()) ? this.SelectedUsuario.get_Senha() : this.SenhaOriginal); - selectedUsuario.set_Senha(str); - List> keyValuePairs1 = this.SelectedUsuario.Validate(); - List> keyValuePairs2 = keyValuePairs1; - keyValuePairs2.AddRange(await this.Validate()); - keyValuePairs2 = null; - if (keyValuePairs1.Count <= 0) - { - this.SelectedUsuario.set_Senha((new Token()).AggerEncrypt(this.SelectedUsuario.get_Senha())); - Usuario usuario = this.SelectedUsuario; - num = (this.SelectedUsuario.get_IdEmpresa() == 0 ? Recursos.Usuario.get_IdEmpresa() : this.SelectedUsuario.get_IdEmpresa()); - usuario.set_IdEmpresa(num); - bool flag = await this.BuscaAlteracaoUsuarios(this.SelectedUsuario.get_Id()); - str1 = (this.SelectedUsuario.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str2 = str1; - Usuario usuario1 = await this._servico.Save(this.SelectedUsuario); - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str2, " USUÁRIO \"", usuario1.get_Nome(), "\""), usuario1.get_Id(), new TipoTela?(16), string.Format("ID: {0}", usuario1.get_Id())); - if (flag) - { - await this.AddUsuarioAdiministadorCentralSegurado(); - } - await this.CarregarUsuarios(); - this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault((Usuario x) => x.get_Id() == usuario1.get_Id()); - Recursos.Usuarios = this.Usuarios; - this.ConfirmaSenha = ""; - base.Alterar(false); - base.ToggleSnackBar("USUÁRIO SALVO COM SUCESSO", true); - this.IsExpanded = true; - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - keyValuePairs1 = null; - str2 = null; - return keyValuePairs; - } - - public async Task Seleciona() - { - Visibility visibility; - UsuarioViewModel usuarioViewModel = this; - visibility = (base.Restricao(94) ? Visibility.Collapsed : Visibility.Visible); - usuarioViewModel.HorarioAcessoVisible = visibility; - await base.PermissaoTela(16); - await this.SelecionaUsuarios(); - } - - public async Task SelecionaUsuario(Usuario usuario) - { - Usuario usuario1 = await this._servico.BuscarUsuarioPorId(usuario.get_Id()); - bool? segunda = usuario1.get_Segunda(); - usuario1.set_Segunda(new bool?(segunda.GetValueOrDefault(true))); - segunda = usuario1.get_Terca(); - usuario1.set_Terca(new bool?(segunda.GetValueOrDefault(true))); - segunda = usuario1.get_Quarta(); - usuario1.set_Quarta(new bool?(segunda.GetValueOrDefault(true))); - segunda = usuario1.get_Quinta(); - usuario1.set_Quinta(new bool?(segunda.GetValueOrDefault(true))); - segunda = usuario1.get_Sexta(); - usuario1.set_Sexta(new bool?(segunda.GetValueOrDefault(true))); - segunda = usuario1.get_Sabado(); - usuario1.set_Sabado(new bool?(segunda.GetValueOrDefault(true))); - segunda = usuario1.get_Domingo(); - usuario1.set_Domingo(new bool?(segunda.GetValueOrDefault(true))); - if (Recursos.Usuario.get_Id() == usuario.get_Id()) - { - usuario1.set_Senha((new Token()).AggerDecrypt(usuario1.get_Senha())); - this.SenhaOriginal = usuario1.get_Senha(); - this.ConfirmaSenha = ""; - DomainBase.Copy(this.UsuariosFiltrados.First((Usuario x) => x.get_Id() == usuario.get_Id()), usuario1); - } - this.SelectedUsuario = this.UsuariosFiltrados.First((Usuario x) => x.get_Id() == usuario.get_Id()); - } - - private async Task SelecionaUsuarios() - { - this.EnableGrid = false; - base.Loading(true); - await this.CarregarUsuarios(); - if (this.UsuariosFiltrados.Count <= 0) - { - Usuario usuario = new Usuario(); - usuario.set_Segunda(new bool?(true)); - usuario.set_Terca(new bool?(true)); - usuario.set_Quarta(new bool?(true)); - usuario.set_Quinta(new bool?(true)); - usuario.set_Sexta(new bool?(true)); - usuario.set_Sabado(new bool?(true)); - usuario.set_Domingo(new bool?(true)); - this.SelectedUsuario = usuario; - base.Alterar(false); - base.EnableMenu = false; - } - else - { - await this.SelecionaUsuario(this.UsuariosFiltrados.First()); - } - base.Loading(false); - this.EnableGrid = true; - } - - public async Task>> Validate() - { - List usuarios; - List> keyValuePairs = new List>(); - if (this.SenhaOriginal == null || this.SenhaOriginal != this.SelectedUsuario.get_Senha()) - { - string senha = (new Token()).Decrypt(this.SelectedUsuario.get_Senha()); - if (senha == null) - { - senha = this.SelectedUsuario.get_Senha(); - } - string str = senha; - if (string.IsNullOrWhiteSpace(this.ConfirmaSenha)) - { - keyValuePairs.Add(new KeyValuePair("ConfirmaSenha|CONFIRMAÇÃO SENHA", "OBRIGATÓRIO")); - } - else if (!string.Equals(this.ConfirmaSenha, str)) - { - keyValuePairs.Add(new KeyValuePair("ConfirmaSenha|CONFIRMAÇÃO SENHA", "INVÁLIDO")); - } - } - if (string.IsNullOrWhiteSpace(this.SelectedUsuario.get_Login())) - { - usuarios = new List(); - } - else - { - usuarios = await (new BaseServico()).BuscarUsuarioPorLoginInteiro(this.SelectedUsuario.get_Login()); - } - foreach (Usuario usuario in usuarios) - { - if (usuario.get_Id() == this.SelectedUsuario.get_Id()) - { - continue; - } - keyValuePairs.Add(new KeyValuePair("Login", string.Concat("O LOGIN JÁ ESTÁ CADASTRADO PARA O USUÁRIO \"", usuario.get_Nome(), "\"."))); - } - if (this.SelectedUsuario.get_InicioAcesso().HasValue && !this.SelectedUsuario.get_FimAcesso().HasValue) - { - keyValuePairs.Add(new KeyValuePair("FIM DO ACESSO", "NECESSÁRIO PREENCHER O CAMPO FIM DO ACESSO!")); - } - if (!this.SelectedUsuario.get_InicioAcesso().HasValue && this.SelectedUsuario.get_FimAcesso().HasValue) - { - keyValuePairs.Add(new KeyValuePair("INÍCIO DO ACESSO", "NECESSÁRIO PREENCHER O CAMPO INÍCIO DO ACESSO!")); - } - bool flag = !string.IsNullOrWhiteSpace(this.SelectedUsuario.get_Documento()); - if (flag) - { - flag = await (new BaseServico()).BuscarUsuarioMesmoDocumento(ValidationHelper.OnlyNumber(this.SelectedUsuario.get_Documento()), this.SelectedUsuario.get_Id(), this.SelectedUsuario.get_IdEmpresa()); - } - if (flag) - { - keyValuePairs.Add(new KeyValuePair("Documento", "O DOCUMENTO JÁ ESTÁ SENDO USADO EM OUTRO USUÁRIO")); - } - List> keyValuePairs1 = keyValuePairs; - keyValuePairs = null; - return keyValuePairs1; - } - - public async Task VerificaUsuarioAdmCentralSegurado() - { - await this.BuscaAlteracaoUsuarios(this.SelectedUsuario.get_Id()); - } - - private void WorkOnSelectedUsuario(Usuario value, bool registrar = true) - { - long? nullable; - this.CartaoCriado = false; - this.CancelUsuario = (value == null || value.get_Id() == 0 ? this.CancelUsuario : (Usuario)value.Clone()); - if (value == null || value.get_Id() == 0) - { - return; - } - value.set_Senha(EncryptionHelper.Decrypt(value.get_Senha())); - if (this.LastAccessId == value.get_Id() && this.LastAccessTela == 16) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU USUÁRIO \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(16), string.Format("ID USUÁRIO: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 16; - Usuario selectedUsuario = this.SelectedUsuario; - if (selectedUsuario != null) - { - nullable = new long?(selectedUsuario.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault((Usuario x) => x.get_Id() == value.get_Id()); - } - if (this.SelectedUsuario.get_InicioAcesso().HasValue && this.SelectedUsuario.get_FimAcesso().HasValue) - { - DateTime? inicioAcesso = this.SelectedUsuario.get_InicioAcesso(); - DateTime dateTime = inicioAcesso.Value; - this.InicioAcesso = dateTime.ToString("HH:mm"); - inicioAcesso = this.SelectedUsuario.get_FimAcesso(); - dateTime = inicioAcesso.Value; - this.FimAcesso = dateTime.ToString("HH:mm"); - } - if (!this.SelectedUsuario.get_InicioAcesso().HasValue && !this.SelectedUsuario.get_FimAcesso().HasValue) - { - this.InicioAcesso = null; - this.FimAcesso = null; - } - this.CartaoCriado = !string.IsNullOrEmpty(value.get_Visita()); - this.LabelCartao = (this.CartaoCriado ? "ATUALIZAR CARTÃO" : "CRIAR CARTÃO"); - } - } -} \ No newline at end of file diff --git a/Gestor.Application/ViewModels/Ferramentas/VendedorViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/VendedorViewModel.cs deleted file mode 100644 index 32b04c4..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/VendedorViewModel.cs +++ /dev/null @@ -1,913 +0,0 @@ -using CsQuery.ExtensionMethods.Internal; -using Gestor.Application.Helpers; -using Gestor.Application.Servicos.Ferramentas; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.ViewModels.Generic; -using Gestor.Common.Validation; -using Gestor.Model.Attributes; -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 System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using System.Windows; - -namespace Gestor.Application.ViewModels.Ferramentas -{ - public class VendedorViewModel : BaseSegurosViewModel - { - private readonly VendedorServico _servico; - - public Vendedor CancelVendedor; - - private Vendedor _selectedVendedor; - - private GridLength _gridHeight = new GridLength(1, GridUnitType.Star); - - private GridLength _gridHeight2 = new GridLength(0); - - private ObservableCollection _vendedoresFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - private VendedorTelefone _selectedTelefone = new VendedorTelefone(); - - private ObservableCollection _telefones = new ObservableCollection(); - - private Repasse _selectedRepasse = new Repasse(); - - private ObservableCollection _repasses = new ObservableCollection(); - - private string _pesquisa; - - private Visibility _mostrarRamo; - - private ObservableCollection _ramos = new ObservableCollection(); - - private Visibility _visualizacaoPropriaCorretora { get; set; } = Visibility.Collapsed; - - public bool CoCorretagemAtiva { get; set; } = Recursos.Configuracoes.Any(new Func((// - // Current member / type: System.Boolean Gestor.Application.ViewModels.Ferramentas.VendedorViewModel::CoCorretagemAtiva() - // File path: C:\AggerSeguros\Gestor.Application.exe - // - // Product version: 0.0.0.0 - // Exception in: System.Boolean CoCorretagemAtiva() - // - // Object reference not set to an instance of an object. - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.GetArgumentName(ParameterReference parameter) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 2276 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.VisitLambdaParameterExpression(LambdaParameterExpression node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 4496 - // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351 - // at Telerik.JustDecompiler.Languages.BaseLanguageWriter.Write(Action writeEntity) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseLanguageWriter.cs:line 339 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 1133 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.VisitMethodParametersInternal(IList`1 list, Boolean isExtensionMethod) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 2769 - // at Telerik.JustDecompiler.Languages.CSharp.CSharpWriter.VisitLambdaExpression(LambdaExpression node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\CSharp\CSharpWriter.cs:line 1077 - // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351 - // at Telerik.JustDecompiler.Languages.BaseLanguageWriter.Write(Action writeEntity) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseLanguageWriter.cs:line 339 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 1133 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.VisitDelegateCreationExpression(DelegateCreationExpression node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 4667 - // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351 - // at Telerik.JustDecompiler.Languages.BaseLanguageWriter.Write(Action writeEntity) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseLanguageWriter.cs:line 339 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 1133 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.VisitMethodParametersInternal(IList`1 list, Boolean isExtensionMethod) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 2769 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.VisitMethodInvocationExpression(MethodInvocationExpression node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 2750 - // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351 - // at Telerik.JustDecompiler.Languages.BaseLanguageWriter.Write(Action writeEntity) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseLanguageWriter.cs:line 339 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 1133 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.WriteInitializedAutoProperty(PropertyDefinition property, Expression assignment) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseImperativeLanguageWriter.cs:line 1457 - // at Telerik.JustDecompiler.Languages.BaseImperativeLanguageWriter.Write(PropertyDefinition property) - // at Telerik.JustDecompiler.Languages.BaseLanguageWriter.WriteInternal(IMemberDefinition member) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Languages\BaseLanguageWriter.cs:line 583 - // - // mailto: JustDecompilePublicFeedback@telerik.com - - - public GridLength GridHeight - { - get - { - return this._gridHeight; - } - set - { - this._gridHeight = value; - base.OnPropertyChanged("GridHeight"); - } - } - - public GridLength GridHeight2 - { - get - { - return this._gridHeight2; - } - set - { - this._gridHeight2 = value; - base.OnPropertyChanged("GridHeight2"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public Visibility MostrarRamo - { - get - { - return this._mostrarRamo; - } - set - { - this._mostrarRamo = value; - base.OnPropertyChanged("MostrarRamo"); - } - } - - public string Pesquisa - { - get - { - return this._pesquisa; - } - set - { - this._pesquisa = value; - base.OnPropertyChanged("Pesquisa"); - } - } - - public ObservableCollection Ramos - { - get - { - return this._ramos; - } - set - { - this._ramos = value; - base.OnPropertyChanged("Ramos"); - } - } - - public ObservableCollection Repasses - { - get - { - return this._repasses; - } - set - { - if (value != null && value.Count > 0) - { - foreach (Repasse repasse in value) - { - if (repasse.get_Ramo() != null) - { - continue; - } - repasse.set_Ramo(new Ramo()); - } - } - this._repasses = value; - base.OnPropertyChanged("Repasses"); - } - } - - public Repasse SelectedRepasse - { - get - { - return this._selectedRepasse; - } - set - { - this._selectedRepasse = value; - base.OnPropertyChanged("SelectedRepasse"); - } - } - - public VendedorTelefone SelectedTelefone - { - get - { - return this._selectedTelefone; - } - set - { - this._selectedTelefone = value; - base.OnPropertyChanged("SelectedTelefone"); - } - } - - public Vendedor SelectedVendedor - { - get - { - return this._selectedVendedor; - } - set - { - long? nullable; - this._selectedVendedor = value; - this.WorkOnSelectedVendedor(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedVendedor"); - } - } - - public ObservableCollection Telefones - { - get - { - return this._telefones; - } - set - { - this._telefones = value; - base.OnPropertyChanged("Telefones"); - } - } - - public List TiposRepasseFiltrados - { - get - { - return Enum.GetValues(typeof(TipoRepasse)).Cast().Where((TipoRepasse tipo) => { - TipoAttribute tipoAttribute = (TipoAttribute)typeof(TipoRepasse).GetField(tipo.ToString()).GetCustomAttributes(typeof(TipoAttribute), false).FirstOrDefault(); - if (tipoAttribute == null || tipoAttribute.get_Tipo() == "0" || this.CoCorretagemAtiva) - { - return true; - } - TipoRepasse? nullable = this.SelectedRepasse.get_Tipo(); - return tipo == nullable.GetValueOrDefault() & nullable.HasValue; - }).ToList(); - } - } - - public List Vendedores - { - get; - set; - } - - public ObservableCollection VendedoresFiltrados - { - get - { - return this._vendedoresFiltrados; - } - set - { - this._vendedoresFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("VendedoresFiltrados"); - } - } - - public Visibility VisualizacaoPropriaCorretora - { - get - { - return this._visualizacaoPropriaCorretora; - } - set - { - this._visualizacaoPropriaCorretora = value; - base.OnPropertyChanged("VisualizacaoPropriaCorretora"); - } - } - - public VendedorViewModel() - { - this._servico = new VendedorServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public async Task AtivarInativarRepasse(Repasse repasse) - { - bool id; - Ramo ramo; - object obj; - string str; - if (repasse != null && repasse.get_Id() != 0) - { - str = (repasse.get_Ativo() ? "INATIVOU REPASSE" : "ATIVOU REPASSE"); - repasse.set_Ativo(!repasse.get_Ativo()); - Repasse repasse1 = repasse; - Ramo ramo1 = repasse.get_Ramo(); - if (ramo1 != null) - { - id = ramo1.get_Id() == (long)0; - } - else - { - id = false; - } - if (id) - { - ramo = null; - } - else - { - ramo = repasse.get_Ramo(); - } - repasse1.set_Ramo(ramo); - repasse = await this._servico.Save(repasse); - long num = this.SelectedVendedor.get_Id(); - VendedorViewModel vendedorViewModel = this; - string str1 = string.Concat(str, " \"", this.SelectedVendedor.get_Nome(), "\""); - long id1 = this.SelectedVendedor.get_Id(); - TipoTela? nullable = new TipoTela?(15); - object[] objArray = new object[] { repasse.get_Id(), repasse.get_ValorNovo(), repasse.get_ValorRenovacao(), null }; - obj = (repasse.get_Ativo() ? "SIM" : "NÃO"); - objArray[3] = obj; - vendedorViewModel.RegistrarAcao(str1, id1, nullable, string.Format("ID: {0}\nVALOR NOVO: {1:N2}\nVALOR RENOVAÇÃO: {2:N2}\nATIVO: {3}", objArray)); - this.Pesquisa = string.Empty; - this.SelectedVendedor = null; - await this.SelecionaVendedores(false); - this.SelectedVendedor = this.VendedoresFiltrados.FirstOrDefault((Vendedor x) => x.get_Id() == num); - Recursos.Vendedores = this.Vendedores; - base.Alterar(false); - base.ToggleSnackBar("REPASSE SALVO COM SUCESSO", true); - } - str = null; - } - - public async Task AtivarInativarVendedor(Vendedor vendedor) - { - object nome; - object obj; - string str; - Vendedor vendedor1 = vendedor; - if (vendedor1 != null && vendedor1.get_Id() != 0) - { - str = (vendedor1.get_Ativo() ? "INATIVOU VENDEDOR" : "ATIVOU VENDEDOR"); - vendedor1.set_Ativo(!vendedor1.get_Ativo()); - Vendedor vendedor2 = await this._servico.Save(vendedor1, this.Repasses.ToList()); - vendedor1 = vendedor2; - VendedorViewModel vendedorViewModel = this; - string str1 = string.Concat(str, " \"", vendedor1.get_Nome(), "\""); - long id = vendedor1.get_Id(); - TipoTela? nullable = new TipoTela?(15); - object[] agencia = new object[] { vendedor1.get_Id(), Recursos.Empresas.First((Empresa x) => x.get_Id() == (vendedor1.get_IdEmpresa() == 0 ? (long)1 : vendedor1.get_IdEmpresa())).get_Nome(), vendedor1.get_Documento(), null, null, null, null, null }; - Banco banco = vendedor1.get_Banco(); - if (banco != null) - { - nome = banco.get_Nome(); - } - else - { - nome = null; - } - agencia[3] = nome; - agencia[4] = vendedor1.get_Agencia(); - agencia[5] = vendedor1.get_Conta(); - agencia[6] = vendedor1.get_Desconto(); - obj = (vendedor1.get_Ativo() ? "SIM" : "NÃO"); - agencia[7] = obj; - vendedorViewModel.RegistrarAcao(str1, id, nullable, string.Format("ID: {0}\nFILIAL DO VENDEDOR: {1}\nDOCUMENTO: {2}\nBANCO: {3}\nAGÊNCIA: {4}\nCONTA: {5}\nDESCONTO: {6:N2}\nATIVO: {7}", agencia)); - this.Pesquisa = string.Empty; - this.SelectedVendedor = null; - await this.SelecionaVendedores(false); - this.SelectedVendedor = this.VendedoresFiltrados.FirstOrDefault((Vendedor x) => x.get_Id() == vendedor1.get_Id()); - Recursos.Vendedores = this.Vendedores; - base.Alterar(false); - base.ToggleSnackBar("VENDEDOR SALVO COM SUCESSO", true); - } - str = null; - } - - public void CancelarAlteracao() - { - if (this.CancelVendedor == null || !this.Vendedores.Any((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id())) - { - this.Incluir(); - } - else - { - DomainBase.Copy(this.Vendedores.First((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id()), this.CancelVendedor); - if (this.VendedoresFiltrados.Count <= 0 || !this.VendedoresFiltrados.Any((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id())) - { - this.VendedoresFiltrados.Add(this.CancelVendedor); - } - else - { - DomainBase.Copy(this.VendedoresFiltrados.First((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id()), this.CancelVendedor); - } - this.VendedoresFiltrados = new ObservableCollection(this.VendedoresFiltrados); - this.SelectedVendedor = this.VendedoresFiltrados.First((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id()); - } - base.Alterar(false); - } - - public void ExcluirTelefone(VendedorTelefone telefone) - { - this.Telefones.Remove(telefone); - } - - public async Task ExcluirVinculo(VinculoRepasse vinculo) - { - if (await base.ShowMessage("DESEJA REALMENTE EXCLUIR O VÍNCULO DO REPASSE SELECIONADO?", "SIM", "NÃO", false)) - { - await this._servico.Delete(vinculo); - this.Repasses = new ObservableCollection((IEnumerable)await this._servico.BuscaRepassesPorIdVendedor(this.SelectedVendedor.get_Id())); - base.ToggleSnackBar("VINCULO EXCLUÍDO COM SUCESSO", true); - } - } - - internal async Task> Filtrar(string value) - { - List vendedors = await Task.Run>(() => this.FiltrarVendedor(value)); - return vendedors; - } - - public List FiltrarVendedor(string filter) - { - this.VendedoresFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Vendedores) : new ObservableCollection( - from x in this.Vendedores - where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - orderby x.get_Ativo() descending, x.get_Nome() - select x)); - this.SelectedVendedor = this.VendedoresFiltrados.FirstOrDefault(); - return this.VendedoresFiltrados.ToList(); - } - - public void Incluir() - { - Vendedor vendedor = new Vendedor(); - vendedor.set_Ativo(true); - vendedor.set_Desconto(new decimal?(new decimal())); - this.SelectedVendedor = vendedor; - this.Telefones = new ObservableCollection(); - this.Repasses = new ObservableCollection(); - base.Alterar(true); - } - - public void IncluirRepasse() - { - if (this.SelectedVendedor == null) - { - return; - } - if (this.Repasses == null) - { - this.Repasses = new ObservableCollection(); - } - Repasse repasse = new Repasse(); - repasse.set_Vendedor(this.SelectedVendedor); - repasse.set_Forma(new FormaRepasse?(1)); - repasse.set_Incidencia(new TipoIncidencia?(1)); - repasse.set_Tipo(new TipoRepasse?(2)); - repasse.set_Ativo(true); - repasse.set_Ramo(this.Ramos.First()); - Repasse repasse1 = repasse; - this.Repasses.Insert(0, repasse1); - this.SelectedRepasse = repasse1; - } - - public void IncluirTelefone() - { - if (this.SelectedVendedor == null) - { - return; - } - if (this.Telefones == null) - { - this.Telefones = new ObservableCollection(); - } - VendedorTelefone vendedorTelefone = new VendedorTelefone(); - vendedorTelefone.set_Vendedor(this.SelectedVendedor); - vendedorTelefone.set_Tipo(new TipoTelefone?(1)); - VendedorTelefone vendedorTelefone1 = vendedorTelefone; - this.Telefones.Add(vendedorTelefone1); - this.SelectedTelefone = vendedorTelefone1; - } - - public async Task>> Salvar() - { - List> keyValuePairs1; - string str; - object nome; - object obj; - VendedorViewModel.u003cu003ec__DisplayClass55_0 variable; - List list; - string str1; - this.SelectedVendedor.set_Telefones(this.Telefones.ToList()); - List> keyValuePairs2 = this.SelectedVendedor.Validate(); - List> keyValuePairs3 = keyValuePairs2; - keyValuePairs3.AddRange(await this.Validate()); - keyValuePairs3 = null; - if (keyValuePairs2.Count <= 0) - { - Vendedor selectedVendedor = this.SelectedVendedor; - ObservableCollection telefones = this.Telefones; - selectedVendedor.set_Telefones(( - from x in telefones - where !string.IsNullOrEmpty(x.get_Nome()) - select x).ToList()); - List repasses = this.Repasses.ToList(); - list = repasses.Where((Repasse x) => { - List> keyValuePairs = x.Validate(); - if (keyValuePairs == null) - { - return false; - } - return keyValuePairs.Count == 0; - }).ToList(); - if (list.Count < this.Repasses.Count) - { - if (!await base.ShowMessage(string.Concat("HÁ REPASSES INVÁLIDOS, DESEJA PROSSEGUIR?", Environment.NewLine, "CASO PROSSIGA OS REPASSES INVÁLIDOS NÃO SERÃO SALVOS."), "SIM", "NÃO", false)) - { - this.Repasses.ToList().ForEach((Repasse x) => keyValuePairs2.AddRange(x.Validate())); - keyValuePairs1 = keyValuePairs2; - variable = null; - list = null; - str1 = null; - return keyValuePairs1; - } - } - this.Repasses = new ObservableCollection(list); - str = (this.SelectedVendedor.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Vendedor vendedor = await this._servico.Save(this.SelectedVendedor, this.Repasses.ToList()); - Vendedor vendedor1 = vendedor; - if (this._servico.Sucesso) - { - VendedorViewModel vendedorViewModel = this; - string str2 = string.Concat(str1, " VENDEDOR \"", vendedor1.get_Nome(), "\""); - long id = vendedor1.get_Id(); - TipoTela? nullable = new TipoTela?(15); - object[] agencia = new object[] { vendedor1.get_Id(), Recursos.Empresas.First((Empresa x) => x.get_Id() == (vendedor1.get_IdEmpresa() == 0 ? (long)1 : vendedor1.get_IdEmpresa())).get_Nome(), vendedor1.get_Documento(), null, null, null, null, null }; - Banco banco = vendedor1.get_Banco(); - if (banco != null) - { - nome = banco.get_Nome(); - } - else - { - nome = null; - } - agencia[3] = nome; - agencia[4] = vendedor1.get_Agencia(); - agencia[5] = vendedor1.get_Conta(); - agencia[6] = vendedor1.get_Desconto(); - obj = (vendedor1.get_Ativo() ? "SIM" : "NÃO"); - agencia[7] = obj; - vendedorViewModel.RegistrarAcao(str2, id, nullable, string.Format("ID: {0}\nFILIAL DO VENDEDOR: {1}\nDOCUMENTO: {2}\nBANCO: {3}\nAGÊNCIA: {4}\nCONTA: {5}\nDESCONTO: {6:N2}\nATIVO: {7}", agencia)); - this.Pesquisa = string.Empty; - this.SelectedVendedor = null; - await this.SelecionaVendedores(false); - this.SelectedVendedor = this.VendedoresFiltrados.FirstOrDefault((Vendedor x) => x.get_Id() == vendedor1.get_Id()); - Recursos.Vendedores = this.Vendedores; - base.Alterar(false); - base.ToggleSnackBar("VENDEDOR SALVO COM SUCESSO", true); - keyValuePairs1 = null; - } - else - { - keyValuePairs1 = null; - } - } - else - { - keyValuePairs1 = keyValuePairs2; - } - variable = null; - list = null; - str1 = null; - return keyValuePairs1; - } - - public async Task SalvarVinculo(VinculoRepasse vinculo) - { - await this._servico.Save(vinculo); - this.Repasses = new ObservableCollection((IEnumerable)await this._servico.BuscaRepassesPorIdVendedor(this.SelectedVendedor.get_Id())); - base.ToggleSnackBar("VINCULO SALVO COM SUCESSO", true); - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(15); - await this.SelecionaVendedores(true); - await this.SelecionaRamos(); - base.Loading(false); - } - - private async Task SelecionaRamos() - { - Visibility visibility; - VendedorViewModel vendedorViewModel = this; - List configuracoes = Recursos.Configuracoes; - visibility = (configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 20) ? Visibility.Collapsed : Visibility.Visible); - vendedorViewModel.MostrarRamo = visibility; - ObservableCollection ramos = this.Ramos; - Ramo ramo = new Ramo(); - ramo.set_Nome("TODOS OS RAMOS"); - ramos.Add(ramo); - List ramos1 = await (new BaseServico()).BuscarRamosAsync(); - ObservableCollection observableCollection = this.Ramos; - List ramos2 = ramos1; - IEnumerable ativo = - from x in ramos2 - where x.get_Ativo() - select x; - ExtensionMethods.AddRange(observableCollection, - from x in ativo - orderby x.get_Nome() - select x); - } - - private async Task SelecionaVendedores(bool selecionar = true) - { - List vendedors = await (new BaseServico()).BuscarVendedoresAsync(); - VendedorViewModel list = this; - List vendedors1 = vendedors; - IEnumerable vendedors2 = vendedors1.Where((Vendedor x) => { - if (Recursos.Usuario.get_IdEmpresa() == (long)1) - { - return true; - } - return x.get_IdEmpresa() == Recursos.Usuario.get_IdEmpresa(); - }); - IOrderedEnumerable ativo = - from x in vendedors2 - orderby x.get_Ativo() descending - select x; - list.Vendedores = ativo.ThenBy((Vendedor x) => x.get_Nome()).ToList(); - this.VendedoresFiltrados = new ObservableCollection(this.Vendedores); - if (selecionar) - { - this.SelectedVendedor = this.VendedoresFiltrados.FirstOrDefault(); - } - Recursos.Vendedores = vendedors; - } - - private async Task>> Validate() - { - List vendedors; - IEnumerable repasses; - List> keyValuePairs = new List>(); - if (!ValidationHelper.ValidateDocument(this.SelectedVendedor.get_Documento())) - { - vendedors = new List(); - } - else - { - vendedors = await (new BaseServico()).BuscarVendedor(this.SelectedVendedor.get_Documento()); - } - Vendedor vendedor = vendedors.FirstOrDefault((Vendedor x) => { - if (x.get_Id() == this.SelectedVendedor.get_Id() || !(x.get_Documento() == this.SelectedVendedor.get_Documento())) - { - return false; - } - return x.get_Ativo(); - }); - if (vendedor != null) - { - List configuracoes = Recursos.Configuracoes; - if (configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 7)) - { - keyValuePairs.Add(new KeyValuePair("Documento", string.Concat("O DOCUMENTO JÁ ESTÁ CADASTRADO PARA O VENDEDOR ", vendedor.get_Nome(), "."))); - } - } - List configuracaoSistemas = Recursos.Configuracoes; - if (configuracaoSistemas.All((ConfiguracaoSistema x) => x.get_Configuracao() != 15)) - { - ObservableCollection observableCollection = this.Repasses; - if (observableCollection != null) - { - repasses = observableCollection.Where((Repasse x) => { - if (x.get_Tipo().GetValueOrDefault() != 2) - { - return false; - } - if (x.get_ValorNovo() > new decimal(100)) - { - return true; - } - return x.get_ValorRenovacao() > new decimal(100); - }); - } - else - { - repasses = null; - } - IEnumerable repasses1 = repasses; - if (repasses1 != null && repasses1.Any()) - { - keyValuePairs.Add(new KeyValuePair("VALOR REPASSE", "O VALOR DE REPASSE NÃO PODE SER SUPERIOR A 100%")); - } - } - ObservableCollection observableCollection1 = await this._servico.BuscaRepassesPorIdVendedor(this.SelectedVendedor.get_Id()); - if (observableCollection1 != null && observableCollection1.Count > 0) - { - foreach (Repasse repasse1 in observableCollection1) - { - if (!this.Repasses.Any((Repasse repasse) => { - long? nullable; - long? nullable1; - long? nullable2; - bool id; - if (repasse1.get_Id() != repasse.get_Id()) - { - return false; - } - TipoRepasse? tipo = repasse1.get_Tipo(); - TipoRepasse? tipo1 = repasse.get_Tipo(); - if (tipo.GetValueOrDefault() == tipo1.GetValueOrDefault() & tipo.HasValue == tipo1.HasValue && !(repasse1.get_ValorNovo() != repasse.get_ValorNovo()) && !(repasse1.get_ValorRenovacao() != repasse.get_ValorRenovacao())) - { - TipoIncidencia? incidencia = repasse1.get_Incidencia(); - TipoIncidencia? incidencia1 = repasse.get_Incidencia(); - if (incidencia.GetValueOrDefault() == incidencia1.GetValueOrDefault() & incidencia.HasValue == incidencia1.HasValue) - { - FormaRepasse? forma = repasse1.get_Forma(); - FormaRepasse? forma1 = repasse.get_Forma(); - if (forma.GetValueOrDefault() == forma1.GetValueOrDefault() & forma.HasValue == forma1.HasValue) - { - BaseRepasse? @base = repasse1.get_Base(); - BaseRepasse? base1 = repasse.get_Base(); - if (@base.GetValueOrDefault() == base1.GetValueOrDefault() & @base.HasValue == base1.HasValue) - { - long? seguradora = repasse1.get_Seguradora(); - long? seguradora1 = repasse.get_Seguradora(); - if (seguradora.GetValueOrDefault() == seguradora1.GetValueOrDefault() & seguradora.HasValue == seguradora1.HasValue) - { - if (repasse1.get_Ramo() == null) - { - Ramo ramo = repasse.get_Ramo(); - id = (ramo != null ? ramo.get_Id() != (long)0 : true); - if (!id) - { - return false; - } - } - Ramo ramo1 = repasse1.get_Ramo(); - if (ramo1 != null) - { - nullable1 = new long?(ramo1.get_Id()); - } - else - { - nullable = null; - nullable1 = nullable; - } - seguradora1 = nullable1; - Ramo ramo2 = repasse.get_Ramo(); - if (ramo2 != null) - { - nullable2 = new long?(ramo2.get_Id()); - } - else - { - nullable = null; - nullable2 = nullable; - } - seguradora = nullable2; - return !(seguradora1.GetValueOrDefault() == seguradora.GetValueOrDefault() & seguradora1.HasValue == seguradora.HasValue); - } - } - } - } - } - return true; - })) - { - continue; - } - if (await this._servico.BuscarVendedorParcela(repasse1.get_Id()).Count > 1) - { - keyValuePairs.Add(new KeyValuePair("REPASSE", string.Format("O REPASSE, DE ID {0}, NÃO PODE SER ALTERADO POIS JÁ ESTÁ CADASTRADO EM ALGUM DOCUMENTO!", repasse1.get_Id()))); - } - } - } - List> keyValuePairs1 = keyValuePairs; - keyValuePairs = null; - return keyValuePairs1; - } - - private async void WorkOnSelectedVendedor(Vendedor value, bool registrar = true) - { - Vendedor vendedor; - long? nullable; - bool corretora; - bool flag; - object nome; - object obj; - VendedorViewModel vendedorViewModel = this; - vendedor = (value == null || value.get_Id() == 0 ? this.CancelVendedor : (Vendedor)value.Clone()); - vendedorViewModel.CancelVendedor = vendedor; - if (value != null && value.get_Id() != 0) - { - base.Loading(true); - this.Repasses = new ObservableCollection((IEnumerable)await this._servico.BuscaRepassesPorIdVendedor(value.get_Id())); - this.Telefones = new ObservableCollection((IEnumerable)await this._servico.BuscarTelefonesAsync(value.get_Id())); - base.Loading(false); - if (this.LastAccessId != value.get_Id() || this.LastAccessTela != 15) - { - if (registrar) - { - VendedorViewModel vendedorViewModel1 = this; - string str = string.Concat("ACESSOU VENDEDOR \"", value.get_Nome(), "\""); - long id = value.get_Id(); - TipoTela? nullable1 = new TipoTela?(15); - object[] agencia = new object[] { value.get_Id(), Recursos.Empresas.First((Empresa x) => x.get_Id() == (value.get_IdEmpresa() == 0 ? (long)1 : value.get_IdEmpresa())).get_Nome(), value.get_Documento(), null, null, null, null, null }; - Banco banco = value.get_Banco(); - if (banco != null) - { - nome = banco.get_Nome(); - } - else - { - nome = null; - } - agencia[3] = nome; - agencia[4] = value.get_Agencia(); - agencia[5] = value.get_Conta(); - agencia[6] = value.get_Desconto(); - obj = (value.get_Ativo() ? "SIM" : "NÃO"); - agencia[7] = obj; - vendedorViewModel1.RegistrarAcao(str, id, nullable1, string.Format("ID: {0}\nFILIAL DO VENDEDOR: {1}\nDOCUMENTO: {2}\nBANCO: {3}\nAGÊNCIA: {4}\nCONTA: {5}\nDESCONTO: {6:N2}\nATIVO: {7}", agencia)); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 15; - Vendedor selectedVendedor = this.SelectedVendedor; - if (selectedVendedor != null) - { - nullable = new long?(selectedVendedor.get_Id()); - } - else - { - nullable = null; - } - long? nullable2 = nullable; - long num = value.get_Id(); - if (nullable2.GetValueOrDefault() != num | !nullable2.HasValue) - { - this.SelectedVendedor = this.VendedoresFiltrados.FirstOrDefault((Vendedor x) => x.get_Id() == value.get_Id()); - } - VendedorViewModel vendedorViewModel2 = this; - Vendedor selectedVendedor1 = this.SelectedVendedor; - if (selectedVendedor1 != null) - { - corretora = selectedVendedor1.get_Corretora(); - } - else - { - corretora = false; - } - vendedorViewModel2.VisualizacaoPropriaCorretora = (corretora ? Visibility.Visible : Visibility.Collapsed); - if (Recursos.Usuario.get_Id() == 0) - { - Vendedor vendedor1 = this.SelectedVendedor; - if (vendedor1 != null) - { - flag = vendedor1.get_Corretora(); - } - else - { - flag = false; - } - if (!flag) - { - this._alterarPermissEnabled = false; - base.EnableAlterar = false; - } - else - { - this._alterarPermissEnabled = true; - base.EnableAlterar = true; - } - } - } - } - } - } -} \ No newline at end of file -- cgit v1.2.3