summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Ferramentas
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/ViewModels/Ferramentas
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Ferramentas')
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs362
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/CadastroParceiroViewModel.cs413
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/ComboModelo.cs43
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/ComboVariavel.cs45
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/DownloadViewModel.cs550
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs512
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs380
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/EtiquetaViewModel.cs1163
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs110
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs110
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/MalaDiretaViewModel.cs821
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/ManutencaoPagamentosViewModel.cs821
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/NotaFiscalViewModel.cs482
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/ProdutoViewModel.cs303
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/ProtocoloDocumentosViewModel.cs399
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/ProtocoloEtiqueta.cs26
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/QualificacaoViewModel.cs122
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs332
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs769
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs621
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs358
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/StatusProspeccaoViewModel.cs326
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/StatusViewModel.cs367
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/TipoTarefaViewModel.cs325
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/TipoVendedorViewModel.cs338
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs826
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/VendedorViewModel.cs913
27 files changed, 11837 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs
new file mode 100644
index 0000000..2294490
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs
@@ -0,0 +1,362 @@
+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<Credencial> _credenciaisFiltrados = new ObservableCollection<Credencial>();
+
+ private bool _isExpanded;
+
+ public List<Credencial> Credenciais
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Credencial> 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<Credencial>())
+ {
+ 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>((Credencial x) => x.get_Id() == num);
+ }
+ base.Alterar(false);
+ }
+
+ private async Task CarregarCredenciais()
+ {
+ List<Credencial> 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<Credencial> credencials1 = credencials;
+ list.Credenciais = (
+ from x in credencials1
+ orderby x.get_Descricao()
+ select x).ToList<Credencial>();
+ this.CredenciaisFiltrados = new ObservableCollection<Credencial>(this.Credenciais);
+ }
+
+ public async Task<bool> 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<Credencial>())
+ {
+ this.SelectedCredencial = new Credencial();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault<Credencial>();
+ }
+ base.Loading(false);
+ base.ToggleSnackBar("E-MAIL EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ internal async Task<List<Credencial>> Filtrar(string value)
+ {
+ List<Credencial> credencials = await Task.Run<List<Credencial>>(() => this.FiltrarCredenciais(value));
+ return credencials;
+ }
+
+ public List<Credencial> FiltrarCredenciais(string filter)
+ {
+ this.CredenciaisFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Credencial>(this.Credenciais) : new ObservableCollection<Credencial>(
+ from x in this.Credenciais
+ where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
+ select x));
+ this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault<Credencial>();
+ return this.CredenciaisFiltrados.ToList<Credencial>();
+ }
+
+ 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string str1;
+ List<KeyValuePair<string, string>> 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>((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<Credencial>();
+ base.Loading(false);
+ }
+
+ public void SelecionaCredencial(Credencial credencial)
+ {
+ this.SelectedCredencial = this.CredenciaisFiltrados.First<Credencial>((Credencial x) => x.get_Id() == credencial.get_Id());
+ }
+
+ public List<KeyValuePair<string, string>> Validate()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (this.Credenciais.Any<Credencial>((Credencial x) => {
+ if (x.get_Id() == this.SelectedCredencial.get_Id())
+ {
+ return false;
+ }
+ return x.get_Descricao() == this.SelectedCredencial.get_Descricao();
+ }))
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("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>((Credencial x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/CadastroParceiroViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/CadastroParceiroViewModel.cs
new file mode 100644
index 0000000..9b8f08c
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/CadastroParceiroViewModel.cs
@@ -0,0 +1,413 @@
+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<Parceiro> _parceirosFiltrados = new ObservableCollection<Parceiro>();
+
+ 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<Parceiro> Parceiros
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Parceiro> 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>((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Parceiro, Parceiro>(this.Parceiros.First<Parceiro>((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id()), this.CancelParceiro);
+ if (this.ParceirosFiltrados.Count <= 0 || !this.ParceirosFiltrados.Any<Parceiro>((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id()))
+ {
+ this.ParceirosFiltrados.Add(this.CancelParceiro);
+ }
+ else
+ {
+ DomainBase.Copy<Parceiro, Parceiro>(this.ParceirosFiltrados.First<Parceiro>((Parceiro x) => x.get_Id() == this.CancelParceiro.get_Id()), this.CancelParceiro);
+ }
+ this.ParceirosFiltrados = new ObservableCollection<Parceiro>(this.ParceirosFiltrados);
+ this.SelecionarParceiro(this.ParceirosFiltrados.First<Parceiro>((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<Parceiro>(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<Parceiro>(num) : this.ParceirosFiltrados.Last<Parceiro>());
+ cadastroParceiroViewModel1.SelecionarParceiro(parceiro);
+ }
+ base.Loading(false);
+ base.ToggleSnackBar("PARCEIRO EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ internal async Task<List<Parceiro>> Filtrar(string value)
+ {
+ List<Parceiro> parceiros = await Task.Run<List<Parceiro>>(() => this.FiltrarParceiro(value));
+ return parceiros;
+ }
+
+ public List<Parceiro> FiltrarParceiro(string filter)
+ {
+ this.ParceirosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Parceiro>(this.Parceiros) : new ObservableCollection<Parceiro>(
+ from x in this.Parceiros
+ where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
+ select x));
+ return this.ParceirosFiltrados.ToList<Parceiro>();
+ }
+
+ public void Incluir()
+ {
+ this.SelectedParceiro = new Parceiro();
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string complemento;
+ string str1;
+ List<KeyValuePair<string, string>> 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>((Parceiro x) => x.get_Id() == parceiro.get_Id()))
+ {
+ this.Parceiros.Add(parceiro);
+ }
+ else
+ {
+ DomainBase.Copy<Parceiro, Parceiro>(this.Parceiros.First<Parceiro>((Parceiro x) => x.get_Id() == parceiro.get_Id()), parceiro);
+ }
+ if (!this.ParceirosFiltrados.Any<Parceiro>((Parceiro x) => x.get_Id() == parceiro.get_Id()))
+ {
+ this.ParceirosFiltrados.Add(parceiro);
+ }
+ else
+ {
+ DomainBase.Copy<Parceiro, Parceiro>(this.ParceirosFiltrados.First<Parceiro>((Parceiro x) => x.get_Id() == parceiro.get_Id()), parceiro);
+ }
+ this.ParceirosFiltrados = new ObservableCollection<Parceiro>(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<Parceiro> parceiros = await (new BaseServico()).BuscarParceirosAsync();
+ CadastroParceiroViewModel list = this;
+ List<Parceiro> parceiros1 = parceiros;
+ list.Parceiros = (
+ from x in parceiros1
+ orderby x.get_Nome()
+ select x).ToList<Parceiro>();
+ this.ParceirosFiltrados = new ObservableCollection<Parceiro>(this.Parceiros);
+ CadastroParceiroViewModel cadastroParceiroViewModel = this;
+ Parceiro parceiro1 = parceiro;
+ if (parceiro1 == null)
+ {
+ parceiro1 = this.ParceirosFiltrados.FirstOrDefault<Parceiro>();
+ }
+ 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<Parceiro, Parceiro>(this.ParceirosFiltrados.First<Parceiro>((Parceiro x) => x.get_Id() == parceiro.get_Id()), parceiro1);
+ this.SelectedParceiro = this.ParceirosFiltrados.First<Parceiro>((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<Parceiro, Parceiro>(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/Codemerx/Gestor.Application/ViewModels/Ferramentas/ComboModelo.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ComboModelo.cs
new file mode 100644
index 0000000..97b1ae0
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ComboModelo.cs
@@ -0,0 +1,43 @@
+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/Codemerx/Gestor.Application/ViewModels/Ferramentas/ComboVariavel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ComboVariavel.cs
new file mode 100644
index 0000000..6fd4392
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ComboVariavel.cs
@@ -0,0 +1,45 @@
+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/Codemerx/Gestor.Application/ViewModels/Ferramentas/DownloadViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/DownloadViewModel.cs
new file mode 100644
index 0000000..66da49e
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/DownloadViewModel.cs
@@ -0,0 +1,550 @@
+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<Gestor.Model.API.Version>(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<DownloadWindow>();
+ str1 = null;
+ return;
+ }
+ }
+ catch (Exception exception)
+ {
+ Funcoes.Destroy<DownloadWindow>();
+ }
+ }
+ else if (type != 88)
+ {
+ if (type == 99)
+ {
+ Gestor.Model.API.Version version2 = await Gestor.Application.Helpers.Connection.Get<Gestor.Model.API.Version>(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<Gestor.Model.API.Version>(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<DownloadWindow>();
+ }
+
+ 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<string> GetCurrentVersion(string name)
+ {
+ string str1 = await Task.Run<string>(() => {
+ string[] directories = Directory.GetDirectories("c:\\AggerSeguros\\");
+ List<long> nums = new List<long>();
+ 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<long>());
+ });
+ return str1;
+ }
+
+ public void Open()
+ {
+ if (!this.Parameters.get_Run())
+ {
+ Funcoes.Destroy<DownloadWindow>();
+ 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<DownloadWindow>();
+ }
+
+ 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/Codemerx/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs
new file mode 100644
index 0000000..6f528ac
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/EmpresaViewModel.cs
@@ -0,0 +1,512 @@
+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<Empresa> _empresasFiltradas = new ObservableCollection<Empresa>();
+
+ 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<Empresa> Empresas
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Empresa> 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>((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Empresa, Empresa>(this.Empresas.First<Empresa>((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()), this.CancelEmpresa);
+ if (this.EmpresasFiltradas.Count <= 0 || !this.EmpresasFiltradas.Any<Empresa>((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()))
+ {
+ this.EmpresasFiltradas.Add(this.CancelEmpresa);
+ }
+ else
+ {
+ DomainBase.Copy<Empresa, Empresa>(this.EmpresasFiltradas.First<Empresa>((Empresa x) => x.get_Id() == this.CancelEmpresa.get_Id()), this.CancelEmpresa);
+ }
+ this.EmpresasFiltradas = new ObservableCollection<Empresa>(this.EmpresasFiltradas);
+ this.SelectedEmpresa = this.EmpresasFiltradas.First<Empresa>((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<List<Empresa>> Filtrar(string value)
+ {
+ List<Empresa> empresas = await Task.Run<List<Empresa>>(() => this.FiltrarEmpresa(value));
+ return empresas;
+ }
+
+ public List<Empresa> FiltrarEmpresa(string filter)
+ {
+ this.EmpresasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Empresa>(this.Empresas) : new ObservableCollection<Empresa>(
+ 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<Empresa>();
+ }
+
+ public void Incluir()
+ {
+ this.SelectedEmpresa = new Empresa();
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string str1;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedEmpresa.Validate();
+ if (this.VisualizacaoMatriz != Visibility.Collapsed && this.ConfirmaSenha != this.Senha)
+ {
+ keyValuePairs1.Add(new KeyValuePair<string, string>("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>((Empresa x) => x.get_Id() == empresa.get_Id()))
+ {
+ this.Empresas.Add(empresa);
+ }
+ else
+ {
+ DomainBase.Copy<Empresa, Empresa>(this.Empresas.First<Empresa>((Empresa x) => x.get_Id() == empresa.get_Id()), empresa);
+ }
+ if (!this.EmpresasFiltradas.Any<Empresa>((Empresa x) => x.get_Id() == empresa.get_Id()))
+ {
+ this.EmpresasFiltradas.Add(empresa);
+ }
+ else
+ {
+ DomainBase.Copy<Empresa, Empresa>(this.EmpresasFiltradas.First<Empresa>((Empresa x) => x.get_Id() == empresa.get_Id()), empresa);
+ }
+ this.EmpresasFiltradas = new ObservableCollection<Empresa>(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<Empresa, Empresa>(this.EmpresasFiltradas.First<Empresa>((Empresa x) => x.get_Id() == empresa.get_Id()), empresa1);
+ this.SelectedEmpresa = this.EmpresasFiltradas.First<Empresa>((Empresa x) => x.get_Id() == empresa.get_Id());
+ }
+
+ private async Task SelecionaEmpresas()
+ {
+ base.Loading(true);
+ List<Empresa> empresas = await (new BaseServico()).BuscarEmpresasAsync();
+ EmpresaViewModel list = this;
+ List<Empresa> empresas1 = empresas;
+ IEnumerable<Empresa> empresas2 = empresas1.Where<Empresa>((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<Empresa>();
+ this.EmpresasFiltradas = new ObservableCollection<Empresa>(this.Empresas);
+ if (this.EmpresasFiltradas.Count <= 0)
+ {
+ this.SelectedEmpresa = new Empresa();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelecionaEmpresa(this.EmpresasFiltradas.First<Empresa>());
+ }
+ 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>((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/Codemerx/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs
new file mode 100644
index 0000000..a084abd
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs
@@ -0,0 +1,380 @@
+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<Estipulante> _estipulantesFiltrados = new ObservableCollection<Estipulante>();
+
+ private bool _isExpanded;
+
+ public List<Estipulante> Estipulantes
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Estipulante> 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>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Estipulante, Estipulante>(this.Estipulantes.First<Estipulante>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()), this.CancelEstipulante);
+ if (this.EstipulantesFiltrados.Count <= 0 || !this.EstipulantesFiltrados.Any<Estipulante>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()))
+ {
+ this.EstipulantesFiltrados.Add(this.CancelEstipulante);
+ }
+ else
+ {
+ DomainBase.Copy<Estipulante, Estipulante>(this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()), this.CancelEstipulante);
+ }
+ this.EstipulantesFiltrados = new ObservableCollection<Estipulante>(this.EstipulantesFiltrados);
+ this.SelectedEstipulante = this.EstipulantesFiltrados.First<Estipulante>((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<Documento> 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<Estipulante>(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<Estipulante>(num) : this.EstipulantesFiltrados.Last<Estipulante>());
+ 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<List<Estipulante>> Filtrar(string value)
+ {
+ List<Estipulante> estipulantes = await Task.Run<List<Estipulante>>(() => this.FiltrarEstipulante(value));
+ return estipulantes;
+ }
+
+ public List<Estipulante> FiltrarEstipulante(string filter)
+ {
+ this.EstipulantesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Estipulante>(this.Estipulantes) : new ObservableCollection<Estipulante>(
+ 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<Estipulante>();
+ return this.EstipulantesFiltrados.ToList<Estipulante>();
+ }
+
+ 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string str1;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedEstipulante.Validate();
+ List<KeyValuePair<string, string>> 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>((Estipulante x) => x.get_Id() == estipulante.get_Id()))
+ {
+ this.Estipulantes.Add(estipulante);
+ }
+ else
+ {
+ DomainBase.Copy<Estipulante, Estipulante>(this.Estipulantes.First<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante);
+ }
+ if (!this.EstipulantesFiltrados.Any<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()))
+ {
+ this.EstipulantesFiltrados.Add(estipulante);
+ }
+ else
+ {
+ DomainBase.Copy<Estipulante, Estipulante>(this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante);
+ }
+ this.EstipulantesFiltrados = new ObservableCollection<Estipulante>(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<Estipulante, Estipulante>(this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante1);
+ this.SelectedEstipulante = this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id());
+ }
+
+ private async Task SelecionaEstipulantes()
+ {
+ base.Loading(true);
+ List<Estipulante> estipulantes = await (new BaseServico()).BuscarEstipulantesAsync();
+ EstipulanteViewModel list = this;
+ List<Estipulante> estipulantes1 = estipulantes;
+ IEnumerable<Estipulante> estipulantes2 = estipulantes1.Where<Estipulante>((Estipulante x) => {
+ if (Recursos.Usuario.get_IdEmpresa() == (long)1)
+ {
+ return true;
+ }
+ return Recursos.Usuario.get_IdEmpresa() == x.get_IdEmpresa();
+ });
+ IOrderedEnumerable<Estipulante> ativo =
+ from x in estipulantes2
+ orderby x.get_Ativo() descending
+ select x;
+ list.Estipulantes = ativo.ThenBy<Estipulante, string>((Estipulante x) => x.get_Nome()).ToList<Estipulante>();
+ this.EstipulantesFiltrados = new ObservableCollection<Estipulante>(this.Estipulantes);
+ if (this.EstipulantesFiltrados.Count <= 0)
+ {
+ this.SelectedEstipulante = new Estipulante();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelecionaEstipulante(this.EstipulantesFiltrados.First<Estipulante>());
+ }
+ Recursos.Estipulantes = estipulantes;
+ base.Loading(false);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<Estipulante> estipulantes;
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ bool flag = !string.IsNullOrEmpty(this.SelectedEstipulante.get_Nome());
+ if (!ValidationHelper.ValidateDocument(this.SelectedEstipulante.get_Documento()))
+ {
+ estipulantes = new List<Estipulante>();
+ }
+ else
+ {
+ estipulantes = await (new BaseServico()).BuscarEstipulante(this.SelectedEstipulante.get_Documento());
+ }
+ List<Estipulante> 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<string, string>("Documento", string.Concat("O DOCUMENTO ESTÁ CADASTRADO PARA O ESTIPULANTE ", nome, ".")));
+ }
+ List<KeyValuePair<string, string>> 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>((Estipulante x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/EtiquetaViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/EtiquetaViewModel.cs
new file mode 100644
index 0000000..c19b97e
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/EtiquetaViewModel.cs
@@ -0,0 +1,1163 @@
+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<string> _tiposEtiqueta = new List<string>()
+ {
+ "CLIENTE",
+ "APÓLICE"
+ };
+
+ private string _tipoEtiqueta = "CLIENTE";
+
+ private bool? _allSelected;
+
+ private ObservableCollection<Documento> _apolicesFiltrados = new ObservableCollection<Documento>();
+
+ private bool _duasColunas = true;
+
+ private bool _tresColunas;
+
+ private bool _umaPagina;
+
+ private bool _mostrarNascimento;
+
+ private int _pular;
+
+ private object _visibilityColunas;
+
+ private bool _mostrarApolice = true;
+
+ private bool _mostrarVendedor = true;
+
+ private bool _mostrarItem = true;
+
+ public 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<Documento>(this.Apolices);
+ base.OnPropertyChanged("AllSelected");
+ }
+ }
+
+ public List<Documento> Apolices
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Documento> 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<string> 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<Documento> list, bool apenasCliente)
+ {
+ ObservableCollection<Item> observableCollection;
+ List<Documento> documentos = list.ToList<Documento>();
+ List<Cliente> clientes = documentos.Select<Documento, Cliente>((Documento x) => {
+ Cliente cliente = new Cliente();
+ cliente.set_Id(x.get_Controle().get_Cliente().get_Id());
+ return cliente;
+ }).ToList<Cliente>();
+ ClienteServico clienteServico = new ClienteServico();
+ ItemServico itemServico = new ItemServico();
+ List<Cliente> clientes1 = clientes;
+ List<ClienteEndereco> clienteEnderecos = await clienteServico.BuscarEnderecosPorCliente((
+ from x in clientes1
+ where x.get_Id() > (long)0
+ select x).ToList<Cliente>());
+ if (!apenasCliente)
+ {
+ observableCollection = await itemServico.BuscarItens(list.ToList<Documento>());
+ }
+ else
+ {
+ observableCollection = null;
+ }
+ ObservableCollection<Item> 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<ClienteEndereco>() == 0)
+ {
+ continue;
+ }
+ if (documento.get_Controle().get_Cliente().get_Id() > (long)0)
+ {
+ Cliente cliente2 = documento.get_Controle().get_Cliente();
+ List<ClienteEndereco> clienteEnderecos1 = (
+ from y in clienteEnderecos
+ where y.get_Cliente().get_Id() == documento.get_Controle().get_Cliente().get_Id()
+ select y).ToList<ClienteEndereco>();
+ cliente2.set_Enderecos(new ObservableCollection<ClienteEndereco>(
+ 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<Item>());
+ }
+ this.TipoEtiqueta = (apenasCliente ? "CLIENTE" : "APÓLICE");
+ EtiquetaViewModel etiquetaViewModel = this;
+ List<Documento> documentos1 = list;
+ IEnumerable<Documento> documentos2 = documentos1.Where<Documento>((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<ClienteEndereco>() > 0;
+ });
+ etiquetaViewModel.Apolices = (
+ from x in documentos2
+ orderby x.get_Controle().get_Cliente().get_Nome()
+ select x).ToList<Documento>();
+ this.ApolicesFiltrados = new ObservableCollection<Documento>(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<Documento> list = (
+ from x in this.Apolices
+ where x.get_Selecionado()
+ select x).ToList<Documento>();
+ string tipoEtiqueta = this.TipoEtiqueta;
+ if (tipoEtiqueta == "CLIENTE")
+ {
+ list = this.Apolices.Where<Documento>((Documento x) => {
+ if (!x.get_Selecionado())
+ {
+ return false;
+ }
+ return x.get_Controle().get_Cliente().get_Enderecos() != null;
+ }).ToList<Documento>();
+ 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 = "<html><head><style type='text/css'>@page{size: Letter; margin: 0cm}</style><title>ETIQUETAS</title></head><body><div align='center'>";
+ int num4 = 0;
+ while (num4 < list.Count)
+ {
+ str18 = string.Concat(str18, "<div style='clear: both; page-break-after:always;'>");
+ bool flag = (num4 == 0 ? true : num4 == num1 * num2);
+ str18 = string.Concat(str18, "<table><tr style='height: ", (flag ? "0.55" : "0.85"), "cm;'></tr>");
+ for (int i = 0; i < num1 * num2; i += num2)
+ {
+ str18 = string.Concat(str18, "<tr style='height: 2.60cm;'>");
+ if (this.DuasColunas)
+ {
+ str18 = string.Concat(str18, "<td style='width: 0.4cm;'>");
+ }
+ else if (this.TresColunas)
+ {
+ str18 = string.Concat(str18, "<td style='width: 0.05cm;'>");
+ }
+ str18 = string.Concat(str18, "</td>");
+ for (int j = 0; j < num2; j++)
+ {
+ str18 = string.Concat(str18, "<td style='width: ", num3.ToString(CultureInfo.InvariantCulture), "cm;'><font size='1px' face='Arial'>");
+ 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<ClienteEndereco>() > 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] = " <br>";
+ 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<ClienteEndereco>();
+ 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<ClienteEndereco>();
+ 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<ClienteEndereco>();
+ if (clienteEndereco2 != null)
+ {
+ complemento = clienteEndereco2.get_Complemento();
+ }
+ else
+ {
+ complemento = null;
+ }
+ if (!string.IsNullOrWhiteSpace(complemento))
+ {
+ ClienteEndereco clienteEndereco3 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault<ClienteEndereco>();
+ if (clienteEndereco3 != null)
+ {
+ str4 = clienteEndereco3.get_Complemento().Trim();
+ }
+ else
+ {
+ str4 = null;
+ }
+ str5 = string.Concat("<br>", str4);
+ }
+ else
+ {
+ str5 = "";
+ }
+ strArrays1[3] = str5;
+ strArrays1[4] = "<br>";
+ ClienteEndereco clienteEndereco4 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault<ClienteEndereco>();
+ 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<ClienteEndereco>();
+ if (clienteEndereco5 != null)
+ {
+ cidade = clienteEndereco5.get_Cidade();
+ }
+ else
+ {
+ cidade = null;
+ }
+ if (!string.IsNullOrEmpty(cidade))
+ {
+ ClienteEndereco clienteEndereco6 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault<ClienteEndereco>();
+ 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<ClienteEndereco>();
+ if (clienteEndereco7 != null)
+ {
+ estado = clienteEndereco7.get_Estado();
+ }
+ else
+ {
+ estado = null;
+ }
+ if (!string.IsNullOrEmpty(estado))
+ {
+ ClienteEndereco clienteEndereco8 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault<ClienteEndereco>();
+ 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] = " <br>";
+ if (item.get_Controle().get_Cliente().get_Id() == 0)
+ {
+ obj = "";
+ }
+ else
+ {
+ ClienteEndereco clienteEndereco9 = item.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault<ClienteEndereco>();
+ 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, "</font></td>");
+ if (j < num2 - 1)
+ {
+ if (this.DuasColunas)
+ {
+ str18 = string.Concat(str18, "<td style='width: 0.5cm;'>");
+ }
+ else if (this.TresColunas)
+ {
+ str18 = string.Concat(str18, "<td style='width: 0.3cm;'>");
+ }
+ }
+ str18 = string.Concat(str18, "</td>");
+ }
+ }
+ str18 = string.Concat(str18, "</table>");
+ str18 = string.Concat(str18, "</div>");
+ }
+ this.Pular = (pular + list.Count) % (num1 * num2);
+ }
+ else
+ {
+ str18 = "<html><head><style type='text/css'>@page{size: landscape}</style><title>ETIQUETAS</title></head><body>";
+ for (int k = 0; k < list.Count; k++)
+ {
+ str18 = string.Concat(str18, "<div style='clear: both; page-break-after:always; margin-top:");
+ str18 = string.Concat(str18, (k == 0 ? "25%'>" : "30%'>"));
+ str18 = string.Concat(str18, "<div align='center'>");
+ str18 = string.Concat(str18, "<table style='text-align: center;'>");
+ str18 = string.Concat(str18, "<tr style='height: 2.48cm;'>");
+ num = 10.7;
+ str18 = string.Concat(str18, "<td style='width: ", num.ToString(CultureInfo.InvariantCulture), "cm;'><font size='3px' face='Arial'>");
+ 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] = " <br>";
+ 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<ClienteEndereco>();
+ 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<ClienteEndereco>();
+ 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<ClienteEndereco>();
+ if (clienteEndereco12 != null)
+ {
+ complemento1 = clienteEndereco12.get_Complemento();
+ }
+ else
+ {
+ complemento1 = null;
+ }
+ if (!string.IsNullOrWhiteSpace(complemento1))
+ {
+ ClienteEndereco clienteEndereco13 = documento.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault<ClienteEndereco>();
+ if (clienteEndereco13 != null)
+ {
+ string complemento2 = clienteEndereco13.get_Complemento();
+ if (complemento2 != null)
+ {
+ str13 = complemento2.Trim();
+ }
+ else
+ {
+ str13 = null;
+ }
+ }
+ else
+ {
+ str13 = null;
+ }
+ str14 = string.Concat("<br>", str13);
+ }
+ else
+ {
+ str14 = "";
+ }
+ strArrays3[3] = str14;
+ strArrays3[4] = "<br>";
+ ClienteEndereco clienteEndereco14 = documento.get_Controle().get_Cliente().get_Enderecos().FirstOrDefault<ClienteEndereco>();
+ 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<ClienteEndereco>();
+ 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<ClienteEndereco>();
+ 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] = " <br>";
+ 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<ClienteEndereco>();
+ if (clienteEndereco17 != null)
+ {
+ obj1 = clienteEndereco17.get_Cep().Trim();
+ }
+ else
+ {
+ obj1 = null;
+ }
+ if (obj1 == null)
+ {
+ obj1 = "";
+ }
+ }
+ strArrays2[7] = (string)obj1;
+ strArrays2[8] = " <br>";
+ str18 = string.Concat(strArrays2);
+ str18 = string.Concat(str18, "</font></td>");
+ str18 = string.Concat(str18, "</tr>");
+ str18 = string.Concat(str18, "</table>");
+ str18 = string.Concat(str18, "</div>");
+ str18 = string.Concat(str18, "</div>");
+ }
+ }
+ 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 = "<html><head><style type='text/css'>@page{size: Letter; margin: 0cm}</style><title>ETIQUETAS</title></head><body><div align='center'>";
+ int num8 = 0;
+ while (num8 < list.Count)
+ {
+ str18 = string.Concat(str18, "<div style='clear: both; page-break-after:always;'>");
+ str18 = string.Concat(str18, "<table><tr style='height: ", (num8 == 0 ? "0.55" : "0.8"), "cm;'></tr>");
+ for (int l = 0; l < num5 * num6; l += num6)
+ {
+ str18 = string.Concat(str18, "<tr style='height: 2.6cm;'>");
+ for (int m = 0; m < num6; m++)
+ {
+ str18 = string.Concat(str18, "<td style='width: ", num7.ToString(CultureInfo.InvariantCulture), "cm; padding: 10px;'><font size='1px' face='Arial'>");
+ 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(), " <br>", null, null, null, null };
+ if (this.MostrarItem)
+ {
+ if (item1.get_ItensAtivo().Count > 1)
+ {
+ obj2 = "APÓLICE COLETIVA <br>";
+ }
+ else
+ {
+ Item item2 = item1.get_ItensAtivo().FirstOrDefault<Item>();
+ if (item2 != null)
+ {
+ upper = item2.get_Descricao().ToUpper();
+ }
+ else
+ {
+ upper = null;
+ }
+ obj2 = string.Concat(upper, "<br>");
+ }
+ 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} <br>", 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()) ? "<br>" : string.Concat(" /", item1.get_Endosso(), " <br>")))) ?? "";
+ }
+ 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(), " <br>"));
+ 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, "</font></td>");
+ }
+ }
+ str18 = string.Concat(str18, "</table>");
+ str18 = string.Concat(str18, "</div>");
+ }
+ this.Pular = (pular1 + list.Count) % (num5 * num6);
+ }
+ else
+ {
+ str18 = "<html><head><style type='text/css'>@page{size: landscape}</style><title>ETIQUETAS</title></head><body>";
+ for (int n = 0; n < list.Count; n++)
+ {
+ str18 = string.Concat(str18, "<div style='clear: both; page-break-after:always; margin-top:");
+ str18 = string.Concat(str18, (n == 0 ? "25%'>" : "30%'>"));
+ str18 = string.Concat(str18, "<div align='center'>");
+ str18 = string.Concat(str18, "<table style='text-align: center;'>");
+ str18 = string.Concat(str18, "<tr style='height: 2.5cm;'>");
+ num = 10.7;
+ str18 = string.Concat(str18, "<td style='width: ", num.ToString(CultureInfo.InvariantCulture), "cm;'><font size='1px' face='Arial'>");
+ Documento documento1 = list[n];
+ string[] strArrays5 = new string[] { str18, documento1.get_Controle().get_Cliente().get_Nome().Trim(), " <br>", null, null, null, null };
+ if (this.MostrarItem)
+ {
+ if (documento1.get_ItensAtivo().Count > 1)
+ {
+ obj5 = "APÓLICE COLETIVA <br>";
+ }
+ else
+ {
+ Item item3 = documento1.get_ItensAtivo().FirstOrDefault<Item>();
+ if (item3 != null)
+ {
+ upper1 = item3.get_Descricao().ToUpper();
+ }
+ else
+ {
+ upper1 = null;
+ }
+ obj5 = string.Concat(upper1, "<br>");
+ }
+ 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} <br>", 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()) ? "<br>" : string.Concat(" /", documento1.get_Endosso(), " <br>")))) ?? "";
+ }
+ 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(), " <br>"));
+ 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, "</font></td>");
+ str18 = string.Concat(str18, "</tr>");
+ str18 = string.Concat(str18, "</table>");
+ str18 = string.Concat(str18, "</div>");
+ str18 = string.Concat(str18, "</div>");
+ }
+ }
+ 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<long>(", ",
+ from x in list
+ select x.get_Id())));
+ }
+ str18 = string.Concat(str18, "</body></html>");
+ 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<List<Documento>> Filtrar(string value)
+ {
+ List<Documento> documentos = await Task.Run<List<Documento>>(() => this.FiltrarApolice(value));
+ return documentos;
+ }
+
+ public List<Documento> FiltrarApolice(string filter)
+ {
+ this.ApolicesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Documento>(this.Apolices) : new ObservableCollection<Documento>(
+ 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<Documento>();
+ }
+
+ private void RecheckAllSelected()
+ {
+ if (this._allSelectedChanging)
+ {
+ return;
+ }
+ try
+ {
+ this._allSelectedChanging = true;
+ if (this.Apolices.All<Documento>((Documento e) => e.get_Selecionado()))
+ {
+ this.AllSelected = new bool?(true);
+ }
+ else if (!this.Apolices.All<Documento>((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/Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs
new file mode 100644
index 0000000..89f3758
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs
@@ -0,0 +1,110 @@
+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<Ramo> _ramosAdicionadas;
+
+ private ObservableCollection<Ramo> _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<Ramo> Ramos
+ {
+ get
+ {
+ return this._ramos;
+ }
+ set
+ {
+ this._ramos = value;
+ base.OnPropertyChanged("Ramos");
+ }
+ }
+
+ public List<Ramo> 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<Ramo> ramos)
+ {
+ this.RamosAdicionadas = ramos;
+ }
+
+ public async void Pesquisar()
+ {
+ if (!string.IsNullOrWhiteSpace(this.Filtro) && this.Filtro.Length >= 3)
+ {
+ string str = Uri.EscapeDataString(this.Filtro);
+ List<Ramo> ramos = await Connection.Get<List<Ramo>>(string.Concat("Ramos/search?ramo=", str), true, false);
+ this.Ramos = new ObservableCollection<Ramo>(
+ from x in ramos
+ where this.RamosAdicionadas.All<Ramo>((Ramo y) => y.get_Id() != x.get_Id())
+ select x);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs
new file mode 100644
index 0000000..ebeed40
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs
@@ -0,0 +1,110 @@
+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<Seguradora> _seguradorasAdicionadas;
+
+ private ObservableCollection<Seguradora> _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<Seguradora> Seguradoras
+ {
+ get
+ {
+ return this._seguradoras;
+ }
+ set
+ {
+ this._seguradoras = value;
+ base.OnPropertyChanged("Seguradoras");
+ }
+ }
+
+ public List<Seguradora> 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<Seguradora> seguradoras)
+ {
+ this.SeguradorasAdicionadas = seguradoras;
+ }
+
+ public async void Pesquisar()
+ {
+ if (!string.IsNullOrWhiteSpace(this.Filtro) && this.Filtro.Length >= 3)
+ {
+ string str = Uri.EscapeDataString(this.Filtro);
+ List<Seguradora> seguradoras = await Connection.Get<List<Seguradora>>(string.Concat("Seguradoras/search?cia=", str), true, false);
+ this.Seguradoras = new ObservableCollection<Seguradora>(
+ from x in seguradoras
+ where this.SeguradorasAdicionadas.All<Seguradora>((Seguradora y) => y.get_Id() != x.get_Id())
+ select x);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/MalaDiretaViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/MalaDiretaViewModel.cs
new file mode 100644
index 0000000..0009fb4
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/MalaDiretaViewModel.cs
@@ -0,0 +1,821 @@
+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<Gestor.Model.Domain.MalaDireta.MalaDireta> _malaDireta = new ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta>();
+
+ private ObservableCollection<ComboVariavel> _variaveis = new ObservableCollection<ComboVariavel>();
+
+ private bool _enableCredencial;
+
+ private ObservableCollection<ComboModelo> _modelos = new ObservableCollection<ComboModelo>();
+
+ private ComboModelo _selectedModelo = new ComboModelo();
+
+ private ComboVariavel _selectedVariavel;
+
+ private string _assunto;
+
+ private string _corpo;
+
+ private ObservableCollection<Credencial> _credenciais = new ObservableCollection<Credencial>();
+
+ private Credencial _selectedCredencial = new Credencial();
+
+ private ObservableCollection<IndiceArquivoDigital> _arquivos = new ObservableCollection<IndiceArquivoDigital>();
+
+ private ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital> _arquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>();
+
+ 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<IndiceArquivoDigital> Arquivos
+ {
+ get
+ {
+ return this._arquivos;
+ }
+ set
+ {
+ this._arquivos = value;
+ base.OnPropertyChanged("Arquivos");
+ }
+ }
+
+ public ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital> 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<Credencial> 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<Gestor.Model.Domain.MalaDireta.MalaDireta> MalaDireta
+ {
+ get
+ {
+ return this._malaDireta;
+ }
+ set
+ {
+ this._malaDireta = value;
+ base.OnPropertyChanged("MalaDireta");
+ }
+ }
+
+ public ObservableCollection<ComboModelo> Modelos
+ {
+ get
+ {
+ return this._modelos;
+ }
+ set
+ {
+ Func<string, bool> func = null;
+ List<string> list = (
+ from variavel in (VariaveisMalaDireta[])Enum.GetValues(typeof(VariaveisMalaDireta))
+ select ValidationHelper.GetEntity(variavel)).ToList<string>();
+ List<string> strs = (
+ from x in this.Variaveis
+ where !x.Indisponivel
+ select x into v
+ select ValidationHelper.GetEntity(v.VariaveisMalaDireta)).ToList<string>();
+ List<ComboModelo> comboModelos = new List<ComboModelo>();
+ foreach (ComboModelo comboModelo in value)
+ {
+ IEnumerable<string> strs1 = list.Where<string>(new Func<string, bool>(comboModelo.ModeloMalaDireta.get_Corpo().Contains));
+ Func<string, bool> func1 = func;
+ if (func1 == null)
+ {
+ Func<string, bool> func2 = (string s) => strs.Contains(s);
+ Func<string, bool> func3 = func2;
+ func = func2;
+ func1 = func3;
+ }
+ if (!strs1.All<string>(func1))
+ {
+ comboModelos.Add(new ComboModelo()
+ {
+ ModeloMalaDireta = comboModelo.ModeloMalaDireta,
+ Indisponivel = true
+ });
+ }
+ else
+ {
+ comboModelos.Add(comboModelo);
+ }
+ }
+ this._modelos = new ObservableCollection<ComboModelo>(
+ 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<ComboVariavel> Variaveis
+ {
+ get
+ {
+ return this._variaveis;
+ }
+ set
+ {
+ this._variaveis = new ObservableCollection<ComboVariavel>(
+ 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<IndiceArquivoDigital> arquivos = this.Arquivos;
+ List<Gestor.Model.Domain.Common.ArquivoDigital> list = arquivos.Select<IndiceArquivoDigital, Gestor.Model.Domain.Common.ArquivoDigital>((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<Gestor.Model.Domain.Common.ArquivoDigital>();
+ List<Gestor.Model.Domain.Common.ArquivoDigital> arquivoDigitals = await base.AddAttachments(this.ArquivosAnexados.ToList<Gestor.Model.Domain.Common.ArquivoDigital>(), list);
+ if (arquivoDigitals != null)
+ {
+ arquivoDigitals.AddRange(this.ArquivosAnexados);
+ this.ArquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>(arquivoDigitals);
+ }
+ }
+
+ private async void BuscarCredenciais()
+ {
+ Credencial credencial;
+ await base.PermissaoTela(39);
+ base.VerificarEnables(null);
+ List<Credencial> credencials = await (new BaseServico()).BuscarCredenciais();
+ MalaDiretaViewModel observableCollection = this;
+ List<Credencial> credencials1 = credencials;
+ observableCollection.Credenciais = new ObservableCollection<Credencial>(
+ from x in credencials1
+ orderby x.get_Descricao()
+ select x);
+ this.EnableCredencial = !base.Restricao(110);
+ MalaDiretaViewModel malaDiretaViewModel = this;
+ if (this.EnableCredencial)
+ {
+ ObservableCollection<Credencial> credenciais = this.Credenciais;
+ credencial = credenciais.FirstOrDefault<Credencial>((Credencial x) => x.get_IdUsuario() == Recursos.Usuario.get_Id());
+ if (credencial == null)
+ {
+ credencial = this.Credenciais.FirstOrDefault<Credencial>();
+ }
+ }
+ else
+ {
+ ObservableCollection<Credencial> credenciais1 = this.Credenciais;
+ credencial = credenciais1.FirstOrDefault<Credencial>((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<Gestor.Model.Domain.MalaDireta.MalaDireta> 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<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDiretas = maladireta;
+ IEnumerable<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDiretas1 =
+ from x in malaDiretas
+ where x.get_Cliente() != null
+ select x;
+ List<long> nums = (
+ from x in malaDiretas1
+ select x.get_Cliente().get_Id()).ToList<long>();
+ MalaDiretaViewModel malaDiretaViewModel = this;
+ visibility = (nums.Count > 1 ? Visibility.Hidden : Visibility.Visible);
+ malaDiretaViewModel.VisibilitySalvarAnexos = visibility;
+ List<ClienteEmail> clienteEmails = await clienteServico.BuscarEmailsPorCliente(nums);
+ List<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDiretas2 = new List<Gestor.Model.Domain.MalaDireta.MalaDireta>();
+ 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<IndiceArquivoDigital> arquivoDigital = x.get_ArquivoDigital();
+ Func<IndiceArquivoDigital, bool> 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<IndiceArquivoDigital>(u003cu003e9_8417);
+ }
+ u003cu003e4_this.Assinatura = flag;
+ List<ClienteEmail> list = (
+ from e in clienteEmails
+ where e.get_Cliente().get_Id() == this.x.get_Cliente().get_Id()
+ select e).ToList<ClienteEmail>();
+ int num = 0;
+ Func<ClienteEmail, int> 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<ClienteEmail, int>(u003cu003e9_8419).ToList<ClienteEmail>().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<Gestor.Model.Domain.MalaDireta.MalaDireta, Gestor.Model.Domain.MalaDireta.MalaDireta>(malaDiretum, x);
+ malaDiretas2.Add(malaDiretum);
+ }
+ else
+ {
+ Gestor.Model.Domain.MalaDireta.MalaDireta malaDiretum1 = new Gestor.Model.Domain.MalaDireta.MalaDireta();
+ DomainBase.Copy<Gestor.Model.Domain.MalaDireta.MalaDireta, Gestor.Model.Domain.MalaDireta.MalaDireta>(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<Gestor.Model.Domain.MalaDireta.MalaDireta, Gestor.Model.Domain.MalaDireta.MalaDireta>(malaDiretum2, x);
+ malaDiretas2.Add(malaDiretum2);
+ });
+ MalaDiretaViewModel observableCollection = this;
+ List<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDiretas3 = malaDiretas2;
+ IOrderedEnumerable<Gestor.Model.Domain.MalaDireta.MalaDireta> nome =
+ from x in malaDiretas3
+ orderby x.get_Cliente().get_Nome()
+ select x;
+ observableCollection.MalaDireta = new ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta>(nome.ThenBy<Gestor.Model.Domain.MalaDireta.MalaDireta, int>((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<ComboVariavel> variaveis = this.Variaveis;
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDireta = this.MalaDireta;
+ comboVariavel = (malaDireta.Any<Gestor.Model.Domain.MalaDireta.MalaDireta>((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Cliente().get_VencimentoHabilitacao().HasValue) ? new ComboVariavel(16, false) : new ComboVariavel(16, true));
+ variaveis.Add(comboVariavel);
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDireta1 = this.MalaDireta;
+ if (!malaDireta1.Any<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<ComboVariavel> variaveis1 = this.Variaveis;
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> observableCollection1 = this.MalaDireta;
+ comboVariavel1 = (observableCollection1.Any<Gestor.Model.Domain.MalaDireta.MalaDireta>((Gestor.Model.Domain.MalaDireta.MalaDireta x) => {
+ if (x.get_ArquivoDigital() == null)
+ {
+ return false;
+ }
+ return x.get_ArquivoDigital().Any<IndiceArquivoDigital>((IndiceArquivoDigital z) => !string.IsNullOrWhiteSpace(z.get_UrlAssinatura()));
+ }) ? new ComboVariavel(17, false) : new ComboVariavel(17, true));
+ variaveis1.Add(comboVariavel1);
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDireta2 = this.MalaDireta;
+ if (!malaDireta2.All<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<ComboVariavel> variaveis2 = this.Variaveis;
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> observableCollection2 = this.MalaDireta;
+ comboVariavel7 = (observableCollection2.Any<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDireta3 = this.MalaDireta;
+ if (!malaDireta3.Any<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<Gestor.Model.Domain.MalaDireta.MalaDireta> observableCollection3 = this.MalaDireta;
+ if (!observableCollection3.All<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<ComboVariavel> variaveis3 = this.Variaveis;
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDireta4 = this.MalaDireta;
+ comboVariavel2 = (malaDireta4.All<Gestor.Model.Domain.MalaDireta.MalaDireta>((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.get_Item() != null) ? new ComboVariavel(11, false) : new ComboVariavel(11, true));
+ variaveis3.Add(comboVariavel2);
+ ObservableCollection<ComboVariavel> variaveis4 = this.Variaveis;
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> observableCollection4 = this.MalaDireta;
+ comboVariavel3 = (observableCollection4.All<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<ComboVariavel>(this.Variaveis);
+ ObservableCollection<ComboVariavel> variaveis5 = this.Variaveis;
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDireta5 = this.MalaDireta;
+ comboVariavel4 = (malaDireta5.Any<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<ComboVariavel> observableCollection5 = this.Variaveis;
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDireta6 = this.MalaDireta;
+ comboVariavel5 = (malaDireta6.Any<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<ComboVariavel> variaveis6 = this.Variaveis;
+ ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta> observableCollection6 = this.MalaDireta;
+ comboVariavel6 = (observableCollection6.Any<Gestor.Model.Domain.MalaDireta.MalaDireta>((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<ModeloMalaDireta> modeloMalaDiretas = await this._servico.BuscarModelos();
+ List<ComboModelo> comboModelos = new List<ComboModelo>();
+ foreach (ModeloMalaDireta modeloMalaDiretum in modeloMalaDiretas)
+ {
+ comboModelos.Add(new ComboModelo()
+ {
+ ModeloMalaDireta = modeloMalaDiretum
+ });
+ }
+ this.Modelos = new ObservableCollection<ComboModelo>(comboModelos);
+ if (modelo != null)
+ {
+ this.SelectedModelo = this.Modelos.FirstOrDefault<ComboModelo>((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>((Gestor.Model.Domain.Common.ArquivoDigital x) => x.get_Descricao() == arquivo.get_Descricao());
+ this.ArquivosAnexados.Remove(arquivoDigital);
+ this.ArquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>(this.ArquivosAnexados);
+ }
+
+ public async Task<bool> 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<Gestor.Model.Domain.MalaDireta.MalaDireta> malaDireta = this.MalaDireta;
+ List<Gestor.Model.Domain.MalaDireta.MalaDireta> list = (
+ from x in malaDireta
+ where x.get_Selecionado()
+ select x).ToList<Gestor.Model.Domain.MalaDireta.MalaDireta>();
+ if (list.Count != 0)
+ {
+ await base.ShowEnviarEmailsDialog(list, this.Assinatura, this.EnviarOriginal, this.ArquivosAnexados.ToList<Gestor.Model.Domain.Common.ArquivoDigital>(), 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> 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<KeyValuePair<string, string>> 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<Gestor.Model.Domain.MalaDireta.MalaDireta>().ForEach((Gestor.Model.Domain.MalaDireta.MalaDireta x) => x.set_Selecionado(!x.get_Selecionado()));
+ this.MalaDireta = new ObservableCollection<Gestor.Model.Domain.MalaDireta.MalaDireta>(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/Codemerx/Gestor.Application/ViewModels/Ferramentas/ManutencaoPagamentosViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ManutencaoPagamentosViewModel.cs
new file mode 100644
index 0000000..5270c3f
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ManutencaoPagamentosViewModel.cs
@@ -0,0 +1,821 @@
+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<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> _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<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> _filtroPersonalizadoSelecionado;
+
+ private ObservableCollection<FiltroRelatorio> _filtroRelatorioSelecionado = new ObservableCollection<FiltroRelatorio>();
+
+ private ObservableCollection<Vendedor> _vendedores = new ObservableCollection<Vendedor>();
+
+ private Vendedor _selectedVendedor;
+
+ private bool _enableExcluirManutPagamento;
+
+ private ObservableCollection<ManutencaoPagamentos> _pagamentos;
+
+ private ListCollectionView _view;
+
+ private bool _allSelected;
+
+ private string _selectedFiltro;
+
+ private ObservableCollection<string> _filtros;
+
+ private DateTime? _inicio;
+
+ private DateTime? _fim;
+
+ private List<ManutencaoPagamentos> _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<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> FiltroPersonalizadoSelecionado
+ {
+ get
+ {
+ return this._filtroPersonalizadoSelecionado;
+ }
+ set
+ {
+ this._filtroPersonalizadoSelecionado = value;
+ base.OnPropertyChanged("FiltroPersonalizadoSelecionado");
+ }
+ }
+
+ public ObservableCollection<FiltroRelatorio> FiltroRelatorioSelecionado
+ {
+ get
+ {
+ return this._filtroRelatorioSelecionado;
+ }
+ set
+ {
+ this._filtroRelatorioSelecionado = value;
+ base.OnPropertyChanged("FiltroRelatorioSelecionado");
+ }
+ }
+
+ public ObservableCollection<string> 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<ManutencaoPagamentos> 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<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> 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<ManutencaoPagamentos> TodosPagamentos
+ {
+ get
+ {
+ return this._todosPagamentos;
+ }
+ set
+ {
+ this.FiltrosPersonalizados = (value == null || !value.Any<ManutencaoPagamentos>() ? 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<Vendedor> Vendedores
+ {
+ get
+ {
+ return this._vendedores;
+ }
+ set
+ {
+ this._vendedores = value;
+ this.SelectedVendedor = this.SelectedVendedor ?? value.FirstOrDefault<Vendedor>();
+ 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<FiltroRelatorio>();
+ this._vendedores = new ObservableCollection<Vendedor>();
+ 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<string>()
+ {
+ "DATA DE EMISSÃO DO RECEBIMENTO",
+ "DATA DE EMISSÃO DO RECIBO DE PAGAMENTO"
+ };
+ this.SelectedFiltro = this.Filtros.First<string>();
+ List<Vendedor> list = (
+ from x in Recursos.Vendedores
+ where x.get_Ativo()
+ orderby x.get_Nome()
+ select x).ToList<Vendedor>();
+ Vendedor vendedor = new Vendedor();
+ vendedor.set_Id((long)0);
+ vendedor.set_Nome("TODAS OS VENDEDORES");
+ list.Insert(0, vendedor);
+ this.Vendedores = new ObservableCollection<Vendedor>(list);
+ this.RelatorioFiltroPersonalizado = Funcoes.PopularFiltroPersonalizado<ManutencaoPagamentos>();
+ }
+
+ public async void AdcionarFiltroPersonalizado()
+ {
+ string str;
+ DateTime dateTime;
+ decimal num;
+ int num1;
+ long num2;
+ List<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> filtroPersonalizados;
+ List<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> filtroPersonalizados1;
+ if (this.FiltroPersonalizado != null)
+ {
+ if (this.SemValor)
+ {
+ filtroPersonalizados = (this.FiltroPersonalizadoSelecionado == null ? new List<Gestor.Model.Domain.Relatorios.FiltroPersonalizado>() : (
+ from x in this.FiltroPersonalizadoSelecionado
+ where x.get_Propriedade() == this.FiltroPersonalizado.get_Propriedade()
+ select x).ToList<Gestor.Model.Domain.Relatorios.FiltroPersonalizado>());
+ List<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> 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<Gestor.Model.Domain.Relatorios.FiltroPersonalizado>() : this.FiltroPersonalizadoSelecionado.Where<Gestor.Model.Domain.Relatorios.FiltroPersonalizado>((Gestor.Model.Domain.Relatorios.FiltroPersonalizado x) => {
+ if (x.get_Propriedade() != this.FiltroPersonalizado.get_Propriedade())
+ {
+ return false;
+ }
+ return x.get_SemValor();
+ }).ToList<Gestor.Model.Domain.Relatorios.FiltroPersonalizado>());
+ List<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> 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<Gestor.Model.Domain.Relatorios.FiltroPersonalizado>();
+ }
+ ObservableCollection<Gestor.Model.Domain.Relatorios.FiltroPersonalizado> 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<long>()
+ {
+ 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<ManutencaoPagamentos>(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<ManutencaoPagamentos> pagamentos = this.Pagamentos;
+ List<ManutencaoPagamentos> list = (
+ from x in pagamentos
+ where x.get_Selecionado()
+ select x).ToList<ManutencaoPagamentos>();
+ 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<ManutencaoPagamentos>(this.TodosPagamentos.CustomWhere<ManutencaoPagamentos>(this.FiltroPersonalizadoSelecionado.ToList<Gestor.Model.Domain.Relatorios.FiltroPersonalizado>(), false));
+ }
+
+ public void Selecionar(bool value)
+ {
+ if (this.Pagamentos == null || this.Pagamentos.Count == 0)
+ {
+ return;
+ }
+ ExtensionMethods.ForEach<ManutencaoPagamentos>(this.Pagamentos, (ManutencaoPagamentos x) => x.set_Selecionado(value));
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/NotaFiscalViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/NotaFiscalViewModel.cs
new file mode 100644
index 0000000..61ee285
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/NotaFiscalViewModel.cs
@@ -0,0 +1,482 @@
+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<Estipulante> _estipulantes;
+
+ private List<Seguradora> _seguradoras;
+
+ private ObservableCollection<NotaFiscal> _notasFiscaisFiltrados = new ObservableCollection<NotaFiscal>();
+
+ 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<Estipulante> 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<NotaFiscal> NotasFiscais
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<NotaFiscal> 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<Seguradora> 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<Seguradora>();
+ this.Estipulantes = (
+ from e in Recursos.Estipulantes
+ where e.get_Ativo()
+ select e).ToList<Estipulante>();
+ this.Apelido = Recursos.Configuracoes.Any<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() == 6);
+ base.EnableMenu = true;
+ this.Seleciona();
+ }
+
+ public async Task<decimal> BuscarImposto()
+ {
+ decimal iss;
+ List<Imposto> impostos = await (new ImpostoServico()).Buscar(new bool?(true));
+ Imposto imposto = impostos.FirstOrDefault<Imposto>((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<Imposto> impostos1 = impostos;
+ imposto = impostos1.FirstOrDefault<Imposto>((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>((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<NotaFiscal, NotaFiscal>(this.NotasFiscais.First<NotaFiscal>((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id()), this.CancelNotaFiscal);
+ if (this.NotasFiscaisFiltrados.Count <= 0 || !this.NotasFiscaisFiltrados.Any<NotaFiscal>((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id()))
+ {
+ this.NotasFiscaisFiltrados.Add(this.CancelNotaFiscal);
+ }
+ else
+ {
+ DomainBase.Copy<NotaFiscal, NotaFiscal>(this.NotasFiscaisFiltrados.First<NotaFiscal>((NotaFiscal x) => x.get_Id() == this.CancelNotaFiscal.get_Id()), this.CancelNotaFiscal);
+ }
+ this.NotasFiscaisFiltrados = new ObservableCollection<NotaFiscal>(this.NotasFiscaisFiltrados);
+ this.SelectedNotaFiscal = this.NotasFiscaisFiltrados.First<NotaFiscal>((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<List<NotaFiscal>> Filtrar(string value)
+ {
+ List<NotaFiscal> notaFiscals = await Task.Run<List<NotaFiscal>>(() => this.FiltrarNotaFiscal(value));
+ return notaFiscals;
+ }
+
+ public List<NotaFiscal> FiltrarNotaFiscal(string filter)
+ {
+ this.NotasFiscaisFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<NotaFiscal>(this.NotasFiscais) : new ObservableCollection<NotaFiscal>(this.NotasFiscais.Where<NotaFiscal>((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, string>((NotaFiscal x) => x.get_Seguradora().get_Nome())));
+ return this.NotasFiscaisFiltrados.ToList<NotaFiscal>();
+ }
+
+ 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ long? nullable;
+ bool valueOrDefault;
+ object obj;
+ string str1;
+ List<KeyValuePair<string, string>> 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>((NotaFiscal x) => x.get_Id() == notaFiscal.get_Id()))
+ {
+ this.NotasFiscais.Add(notaFiscal);
+ }
+ else
+ {
+ DomainBase.Copy<NotaFiscal, NotaFiscal>(this.NotasFiscais.First<NotaFiscal>((NotaFiscal x) => x.get_Id() == notaFiscal.get_Id()), notaFiscal);
+ }
+ if (!this.NotasFiscaisFiltrados.Any<NotaFiscal>((NotaFiscal x) => x.get_Id() == notaFiscal.get_Id()))
+ {
+ this.NotasFiscaisFiltrados.Add(notaFiscal);
+ }
+ else
+ {
+ DomainBase.Copy<NotaFiscal, NotaFiscal>(this.NotasFiscaisFiltrados.First<NotaFiscal>((NotaFiscal x) => x.get_Id() == notaFiscal.get_Id()), notaFiscal);
+ }
+ this.NotasFiscaisFiltrados = new ObservableCollection<NotaFiscal>(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<NotaFiscal> 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<NotaFiscal> notaFiscals = await this._servico.BuscarNotasFiscais();
+ NotaFiscalViewModel list = this;
+ List<NotaFiscal> notaFiscals1 = notaFiscals;
+ list.NotasFiscais = (
+ from x in notaFiscals1
+ orderby x.get_Seguradora().get_Nome()
+ select x).ToList<NotaFiscal>();
+ this.NotasFiscaisFiltrados = new ObservableCollection<NotaFiscal>(this.NotasFiscais);
+ this.SelectedNotaFiscal = this.NotasFiscaisFiltrados.FirstOrDefault<NotaFiscal>();
+ 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>((NotaFiscal x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProdutoViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProdutoViewModel.cs
new file mode 100644
index 0000000..40f14ae
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProdutoViewModel.cs
@@ -0,0 +1,303 @@
+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<Produto> _produtosFiltrados = new ObservableCollection<Produto>();
+
+ private bool _isExpanded;
+
+ public bool IsExpanded
+ {
+ get
+ {
+ return this._isExpanded;
+ }
+ set
+ {
+ this._isExpanded = value;
+ base.OnPropertyChanged("IsExpanded");
+ }
+ }
+
+ public List<Produto> Produtos
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Produto> 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>((Produto x) => x.get_Id() == this.CancelProduto.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Produto, Produto>(this.Produtos.First<Produto>((Produto x) => x.get_Id() == this.CancelProduto.get_Id()), this.CancelProduto);
+ if (this.ProdutosFiltrados.Count <= 0 || !this.ProdutosFiltrados.Any<Produto>((Produto x) => x.get_Id() == this.CancelProduto.get_Id()))
+ {
+ this.ProdutosFiltrados.Add(this.CancelProduto);
+ }
+ else
+ {
+ DomainBase.Copy<Produto, Produto>(this.ProdutosFiltrados.First<Produto>((Produto x) => x.get_Id() == this.CancelProduto.get_Id()), this.CancelProduto);
+ }
+ this.ProdutosFiltrados = new ObservableCollection<Produto>(this.ProdutosFiltrados);
+ this.SelectedProduto = this.ProdutosFiltrados.First<Produto>((Produto x) => x.get_Id() == this.CancelProduto.get_Id());
+ }
+ base.Alterar(false);
+ }
+
+ internal async Task<List<Produto>> Filtrar(string value)
+ {
+ List<Produto> produtos = await Task.Run<List<Produto>>(() => this.FiltrarProduto(value));
+ return produtos;
+ }
+
+ public List<Produto> FiltrarProduto(string filter)
+ {
+ this.ProdutosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Produto>(this.Produtos) : new ObservableCollection<Produto>(
+ 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<Produto>();
+ return this.ProdutosFiltrados.ToList<Produto>();
+ }
+
+ public void Incluir()
+ {
+ Produto produto = new Produto();
+ produto.set_Ativo(true);
+ this.SelectedProduto = produto;
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string str1;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedProduto.Validate();
+ List<KeyValuePair<string, string>> 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>((Produto x) => x.get_Id() == produto.get_Id()))
+ {
+ this.Produtos.Add(produto);
+ }
+ else
+ {
+ DomainBase.Copy<Produto, Produto>(this.Produtos.First<Produto>((Produto x) => x.get_Id() == produto.get_Id()), produto);
+ }
+ if (!this.ProdutosFiltrados.Any<Produto>((Produto x) => x.get_Id() == produto.get_Id()))
+ {
+ this.ProdutosFiltrados.Add(produto);
+ }
+ else
+ {
+ DomainBase.Copy<Produto, Produto>(this.ProdutosFiltrados.First<Produto>((Produto x) => x.get_Id() == produto.get_Id()), produto);
+ }
+ this.ProdutosFiltrados = new ObservableCollection<Produto>(this.ProdutosFiltrados);
+ List<Produto> produtos = this.Produtos;
+ Recursos.Produtos = (
+ from x in produtos
+ orderby x.get_Nome()
+ select x).ToList<Produto>();
+ 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<Produto> produtos = await (new BaseServico()).BuscarProdutosAsync();
+ ProdutoViewModel list = this;
+ List<Produto> produtos1 = produtos;
+ IOrderedEnumerable<Produto> ativo =
+ from x in produtos1
+ orderby x.get_Ativo() descending
+ select x;
+ list.Produtos = ativo.ThenBy<Produto, string>((Produto x) => x.get_Nome()).ToList<Produto>();
+ this.ProdutosFiltrados = new ObservableCollection<Produto>(this.Produtos);
+ this.SelectedProduto = this.ProdutosFiltrados.FirstOrDefault<Produto>();
+ List<Produto> produtos2 = this.Produtos;
+ Recursos.Produtos = (
+ from x in produtos2
+ orderby x.get_Nome()
+ select x).ToList<Produto>();
+ base.Loading(false);
+ base.Loading(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ List<KeyValuePair<string, string>> keyValuePairs1;
+ if (!string.IsNullOrWhiteSpace(this.SelectedProduto.get_Nome()))
+ {
+ keyValuePairs1 = new List<KeyValuePair<string, string>>();
+ bool flag = true;
+ List<Produto> 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<string, string>("Nome", "UM PRODUTO COM O MESMO NOME JÁ EXISTE."));
+ }
+ keyValuePairs = keyValuePairs1;
+ }
+ else
+ {
+ keyValuePairs = new List<KeyValuePair<string, string>>();
+ }
+ 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>((Produto x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProtocoloDocumentosViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProtocoloDocumentosViewModel.cs
new file mode 100644
index 0000000..027f344
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProtocoloDocumentosViewModel.cs
@@ -0,0 +1,399 @@
+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<Documento> _apolicesFiltradas = new ObservableCollection<Documento>();
+
+ private ObservableCollection<ProtocoloEtiqueta> _apolicesAdicionadas = new ObservableCollection<ProtocoloEtiqueta>();
+
+ private FiltroStatusDocumento _selectedStatus;
+
+ public ObservableCollection<ProtocoloEtiqueta> ApolicesAdicionadas
+ {
+ get
+ {
+ return this._apolicesAdicionadas;
+ }
+ set
+ {
+ this._apolicesAdicionadas = value;
+ base.OnPropertyChanged("ApolicesAdicionadas");
+ }
+ }
+
+ public ObservableCollection<Documento> 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<ProtocoloEtiqueta> 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<ProtocoloEtiqueta> apolicesAdicionadas1 = this.ApolicesAdicionadas;
+ observableCollection.ApolicesAdicionadas = new ObservableCollection<ProtocoloEtiqueta>(
+ 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>((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<ProtocoloEtiqueta> 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<ProtocoloEtiqueta> apolicesAdicionadas1 = this.ApolicesAdicionadas;
+ IOrderedEnumerable<ProtocoloEtiqueta> tipo =
+ from x in apolicesAdicionadas1
+ orderby x.Tipo
+ select x;
+ observableCollection.ApolicesAdicionadas = new ObservableCollection<ProtocoloEtiqueta>(tipo.ThenBy<ProtocoloEtiqueta, long>((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<ClienteEndereco> observableCollection = new ObservableCollection<ClienteEndereco>()
+ {
+ clienteEndereco
+ };
+ ObservableCollection<ProtocoloEtiqueta> 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<ProtocoloEtiqueta> apolicesAdicionadas1 = protocoloDocumentosViewModel.ApolicesAdicionadas;
+ IOrderedEnumerable<ProtocoloEtiqueta> tipo =
+ from x in apolicesAdicionadas1
+ orderby x.Tipo
+ select x;
+ observableCollection1.ApolicesAdicionadas = new ObservableCollection<ProtocoloEtiqueta>(tipo.ThenBy<ProtocoloEtiqueta, long>((ProtocoloEtiqueta x) => x.Documento.get_Controle().get_Cliente().get_Id()));
+ }
+
+ public async void AdicionarProtocolo(Documento documento)
+ {
+ bool flag = this.ApolicesAdicionadas.Any<ProtocoloEtiqueta>((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<ProtocoloEtiqueta> 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<ProtocoloEtiqueta> apolicesAdicionadas1 = this.ApolicesAdicionadas;
+ observableCollection.ApolicesAdicionadas = new ObservableCollection<ProtocoloEtiqueta>(
+ 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<ProtocoloEtiqueta> apolicesAdicionadas = this.ApolicesAdicionadas;
+ if (!apolicesAdicionadas.All<ProtocoloEtiqueta>((ProtocoloEtiqueta x) => x.Tipo != 0))
+ {
+ ObservableCollection<ProtocoloEtiqueta> observableCollection = this.ApolicesAdicionadas;
+ if (observableCollection.Any<ProtocoloEtiqueta>((ProtocoloEtiqueta x) => x.Tipo == 0))
+ {
+ ProtocoloDocumentosViewModel protocoloDocumentosViewModel = this;
+ ObservableCollection<ProtocoloEtiqueta> apolicesAdicionadas1 = this.ApolicesAdicionadas;
+ IEnumerable<ProtocoloEtiqueta> protocoloEtiquetas =
+ from x in apolicesAdicionadas1
+ where x.Tipo == 0
+ select x;
+ List<Documento> documentos = await protocoloDocumentosViewModel.ShowProtocoloDialog((
+ from x in protocoloEtiquetas
+ select x.Documento).ToList<Documento>());
+ 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<ProtocoloEtiqueta> observableCollection1 = this.ApolicesAdicionadas;
+ if (!observableCollection1.All<ProtocoloEtiqueta>((ProtocoloEtiqueta x) => x.Tipo != 1))
+ {
+ ObservableCollection<ProtocoloEtiqueta> apolicesAdicionadas2 = this.ApolicesAdicionadas;
+ if (apolicesAdicionadas2.Any<ProtocoloEtiqueta>((ProtocoloEtiqueta x) => {
+ if (x.Tipo != 1)
+ {
+ return false;
+ }
+ return x.Documento.get_Id() == (long)0;
+ }))
+ {
+ ObservableCollection<ProtocoloEtiqueta> observableCollection2 = this.ApolicesAdicionadas;
+ if (observableCollection2.Any<ProtocoloEtiqueta>((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<ProtocoloEtiqueta> apolicesAdicionadas3 = this.ApolicesAdicionadas;
+ IEnumerable<ProtocoloEtiqueta> protocoloEtiquetas1 = apolicesAdicionadas3.Where<ProtocoloEtiqueta>((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<Documento>(), true), "ETIQUETAS", new double?((double)900), new double?((double)600), false)).Show();
+ }
+ ObservableCollection<ProtocoloEtiqueta> observableCollection3 = this.ApolicesAdicionadas;
+ if (observableCollection3.Any<ProtocoloEtiqueta>((ProtocoloEtiqueta x) => {
+ if (x.Tipo != 1)
+ {
+ return false;
+ }
+ return x.Documento.get_Id() != (long)0;
+ }))
+ {
+ ObservableCollection<ProtocoloEtiqueta> apolicesAdicionadas4 = this.ApolicesAdicionadas;
+ IEnumerable<ProtocoloEtiqueta> protocoloEtiquetas2 = apolicesAdicionadas4.Where<ProtocoloEtiqueta>((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<Documento>(), 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<Documento> documentos, bool doisPorPagina)
+ {
+ if (await base.ShowMessage("DESEJA EMITIR O CHECKLIST?", "SIM", "NÃO", false))
+ {
+ await base.EmitirCheckList(documentos);
+ }
+ if (documentos != null)
+ {
+ List<Documento> documentos1 = documentos;
+ List<Tuple<long, string>> list = (
+ from x in documentos1
+ select new Tuple<long, string>(x.get_Id(), x.get_ObsProtocolo())).ToList<Tuple<long, string>>();
+ 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/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProtocoloEtiqueta.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProtocoloEtiqueta.cs
new file mode 100644
index 0000000..7e46a89
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ProtocoloEtiqueta.cs
@@ -0,0 +1,26 @@
+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/Codemerx/Gestor.Application/ViewModels/Ferramentas/QualificacaoViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/QualificacaoViewModel.cs
new file mode 100644
index 0000000..c259f93
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/QualificacaoViewModel.cs
@@ -0,0 +1,122 @@
+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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ if (await this._servico.BuscarQualificacaoAsync().get_Id() == 0)
+ {
+ this.SelectedQualificacao.set_Id((long)0);
+ }
+ List<KeyValuePair<string, string>> 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/Codemerx/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs
new file mode 100644
index 0000000..09ab1ea
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/RamoViewModel.cs
@@ -0,0 +1,332 @@
+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<Ramo> _ramosFiltrados = new ObservableCollection<Ramo>();
+
+ private bool _isExpanded;
+
+ private List<CoberturaPadrao> _coberturas = new List<CoberturaPadrao>();
+
+ private ObservableCollection<CoberturaPadrao> _coberturasFiltradas = new ObservableCollection<CoberturaPadrao>();
+
+ public Ramo CancelRamo;
+
+ public List<CoberturaPadrao> Coberturas
+ {
+ get
+ {
+ return this._coberturas;
+ }
+ set
+ {
+ this._coberturas = value;
+ base.OnPropertyChanged("Coberturas");
+ }
+ }
+
+ public ObservableCollection<CoberturaPadrao> 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<Ramo> Ramos
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Ramo> 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>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()))
+ {
+ DomainBase.Copy<Ramo, Ramo>(this.Ramos.First<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()), this.CancelRamo);
+ if (this.RamosFiltrados.Count <= 0 || !this.RamosFiltrados.Any<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()))
+ {
+ this.RamosFiltrados.Add(this.CancelRamo);
+ }
+ else
+ {
+ DomainBase.Copy<Ramo, Ramo>(this.RamosFiltrados.First<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id()), this.CancelRamo);
+ }
+ this.RamosFiltrados = new ObservableCollection<Ramo>(this.RamosFiltrados);
+ this.SelectedRamo = this.RamosFiltrados.First<Ramo>((Ramo x) => x.get_Id() == this.CancelRamo.get_Id());
+ }
+ base.Alterar(false);
+ }
+
+ internal async Task<List<Ramo>> Filtrar(string value)
+ {
+ List<Ramo> ramos = await Task.Run<List<Ramo>>(() => this.FiltrarRamo(value));
+ return ramos;
+ }
+
+ internal async Task<List<CoberturaPadrao>> FiltrarCobertura(string value)
+ {
+ List<CoberturaPadrao> coberturaPadraos = await Task.Run<List<CoberturaPadrao>>(() => this.FiltrarCoberturaRamo(value));
+ return coberturaPadraos;
+ }
+
+ public List<CoberturaPadrao> FiltrarCoberturaRamo(string filter)
+ {
+ this.CoberturasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<CoberturaPadrao>(this.Coberturas) : new ObservableCollection<CoberturaPadrao>(
+ from x in this.Coberturas
+ where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
+ select x));
+ return this.CoberturasFiltradas.ToList<CoberturaPadrao>();
+ }
+
+ public List<Ramo> FiltrarRamo(string filter)
+ {
+ this.RamosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Ramo>(this.Ramos) : new ObservableCollection<Ramo>(
+ 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<Ramo>();
+ }
+
+ 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string str1;
+ this.SelectedRamo.set_Iof(this.Iof);
+ List<KeyValuePair<string, string>> 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>((Ramo x) => x.get_Id() == ramo1.get_Id()))
+ {
+ this.Ramos.Add(ramo1);
+ }
+ else
+ {
+ DomainBase.Copy<Ramo, Ramo>(this.Ramos.First<Ramo>((Ramo x) => x.get_Id() == ramo1.get_Id()), ramo1);
+ }
+ if (!this.RamosFiltrados.Any<Ramo>((Ramo x) => x.get_Id() == ramo1.get_Id()))
+ {
+ this.RamosFiltrados.Add(ramo1);
+ }
+ else
+ {
+ DomainBase.Copy<Ramo, Ramo>(this.RamosFiltrados.First<Ramo>((Ramo x) => x.get_Id() == ramo1.get_Id()), ramo1);
+ }
+ this.RamosFiltrados = new ObservableCollection<Ramo>(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<Ramo> ramos = await (new BaseServico()).BuscarRamosAsync();
+ RamoViewModel list = this;
+ List<Ramo> ramos1 = ramos;
+ IOrderedEnumerable<Ramo> ativo =
+ from x in ramos1
+ orderby x.get_Ativo() descending
+ select x;
+ list.Ramos = ativo.ThenBy<Ramo, string>((Ramo x) => x.get_Nome()).ToList<Ramo>();
+ this.RamosFiltrados = new ObservableCollection<Ramo>(this.Ramos);
+ RamoViewModel ramoViewModel = this;
+ ramo1 = (ramo == null ? this.RamosFiltrados.First<Ramo>() : this.RamosFiltrados.FirstOrDefault<Ramo>((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<CoberturaPadrao>();
+ this.CoberturasFiltradas = new ObservableCollection<CoberturaPadrao>(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>((Ramo x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs
new file mode 100644
index 0000000..e00947c
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/ReciboViewModel.cs
@@ -0,0 +1,769 @@
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos;
+using Gestor.Application.Servicos.Ferramentas;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Ferramentas;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Drawing;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.ViewModels.Ferramentas
+{
+ public class ReciboViewModel : BaseSegurosViewModel
+ {
+ private readonly ReciboServico _servico;
+
+ public Recibo CancelRecibo;
+
+ private Recibo _selectedRecibo = new Recibo();
+
+ private DateTime? _horaRecibo;
+
+ private ObservableCollection<Recibo> _recibosFiltrados = new ObservableCollection<Recibo>();
+
+ private bool _isExpanded;
+
+ private Cliente _pagante;
+
+ private Cliente _recebedor;
+
+ public DateTime? HoraRecibo
+ {
+ get
+ {
+ return this._horaRecibo;
+ }
+ set
+ {
+ DateTime? nullable;
+ this._horaRecibo = value;
+ if (!value.HasValue)
+ {
+ return;
+ }
+ Recibo selectedRecibo = this.SelectedRecibo;
+ DateTime? dataRecibo = this.SelectedRecibo.get_DataRecibo();
+ if (dataRecibo.HasValue)
+ {
+ dataRecibo = this.SelectedRecibo.get_DataRecibo();
+ nullable = new DateTime?(DateTime.Parse(string.Format("{0:d} {1:T}", dataRecibo.Value, value)));
+ }
+ else
+ {
+ dataRecibo = null;
+ nullable = dataRecibo;
+ }
+ selectedRecibo.set_DataRecibo(nullable);
+ base.OnPropertyChanged("HoraRecibo");
+ }
+ }
+
+ public bool IsExpanded
+ {
+ get
+ {
+ return this._isExpanded;
+ }
+ set
+ {
+ this._isExpanded = value;
+ base.OnPropertyChanged("IsExpanded");
+ }
+ }
+
+ public Cliente Pagante
+ {
+ get
+ {
+ return this._pagante;
+ }
+ set
+ {
+ this._pagante = value;
+ this.WorkOnSelectedPagante(value);
+ base.OnPropertyChanged("Pagante");
+ }
+ }
+
+ public Cliente Recebedor
+ {
+ get
+ {
+ return this._recebedor;
+ }
+ set
+ {
+ this._recebedor = value;
+ this.WorkOnSelectedRecebedor(value);
+ base.OnPropertyChanged("Recebedor");
+ }
+ }
+
+ public List<Recibo> Recibos
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Recibo> RecibosFiltrados
+ {
+ get
+ {
+ return this._recibosFiltrados;
+ }
+ set
+ {
+ this._recibosFiltrados = value;
+ this.IsExpanded = (value != null ? value.Count > 0 : false);
+ base.OnPropertyChanged("RecibosFiltrados");
+ }
+ }
+
+ public Recibo SelectedRecibo
+ {
+ get
+ {
+ return this._selectedRecibo;
+ }
+ set
+ {
+ long? nullable;
+ this._selectedRecibo = value;
+ this.WorkOnSelectedRecibo(value, true);
+ if (value != null)
+ {
+ nullable = new long?(value.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ base.VerificarEnables(nullable);
+ if (!value.get_DataRecibo().HasValue)
+ {
+ value.set_DataRecibo(new DateTime?(DateTime.Now));
+ }
+ if (value != null)
+ {
+ this.HoraRecibo = value.get_DataRecibo();
+ }
+ base.OnPropertyChanged("SelectedRecibo");
+ }
+ }
+
+ public ReciboViewModel()
+ {
+ this._servico = new ReciboServico();
+ base.EnableMenu = true;
+ this.Seleciona();
+ }
+
+ public void CancelarAlteracao()
+ {
+ if (this.CancelRecibo == null || !this.Recibos.Any<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Recibo, Recibo>(this.Recibos.First<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()), this.CancelRecibo);
+ if (this.RecibosFiltrados.Count <= 0 || !this.RecibosFiltrados.Any<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()))
+ {
+ this.RecibosFiltrados.Add(this.CancelRecibo);
+ }
+ else
+ {
+ DomainBase.Copy<Recibo, Recibo>(this.RecibosFiltrados.First<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id()), this.CancelRecibo);
+ }
+ this.RecibosFiltrados = new ObservableCollection<Recibo>(this.RecibosFiltrados);
+ this.SelectedRecibo = this.RecibosFiltrados.First<Recibo>((Recibo x) => x.get_Id() == this.CancelRecibo.get_Id());
+ }
+ base.Alterar(false);
+ }
+
+ public async void Excluir()
+ {
+ string description;
+ object obj;
+ if (this.SelectedRecibo != null && this.SelectedRecibo.get_Id() != 0)
+ {
+ if (await base.ShowMessage("DESEJA REALMENTE EXCLUIR O RECIBO PERMANENTEMENTE?", "SIM", "NÃO", false))
+ {
+ base.Loading(true);
+ if (await this._servico.Delete(this.SelectedRecibo))
+ {
+ ReciboViewModel reciboViewModel = this;
+ string str = string.Format("EXCLUIU RECIBO DE NÚMERO \"{0}\"", this.SelectedRecibo.get_Id());
+ long id = this.SelectedRecibo.get_Id();
+ TipoTela? nullable = new TipoTela?(42);
+ object[] valor = new object[9];
+ if (this.SelectedRecibo.get_Tipo().HasValue)
+ {
+ TipoRecibo? tipo = this.SelectedRecibo.get_Tipo();
+ description = ValidationHelper.GetDescription(tipo.Value);
+ if (description == null)
+ {
+ description = "";
+ }
+ }
+ else
+ {
+ description = "-";
+ }
+ valor[0] = description;
+ TipoPagamento? pagamento = this.SelectedRecibo.get_Pagamento();
+ if (pagamento.HasValue)
+ {
+ obj = ValidationHelper.GetDescription(pagamento.GetValueOrDefault());
+ }
+ else
+ {
+ obj = null;
+ }
+ valor[1] = obj;
+ valor[2] = this.SelectedRecibo.get_Valor();
+ valor[3] = this.SelectedRecibo.get_DataRecibo();
+ valor[4] = this.SelectedRecibo.get_Pagante();
+ valor[5] = this.SelectedRecibo.get_DocumentoPagante();
+ valor[6] = this.SelectedRecibo.get_Recebedor();
+ valor[7] = this.SelectedRecibo.get_DocumentoRecebedor();
+ valor[8] = this.SelectedRecibo.get_Referente();
+ reciboViewModel.RegistrarAcao(str, id, nullable, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", valor));
+ await this.SelecionaRecibo();
+ base.Loading(false);
+ base.ToggleSnackBar("RECIBO EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ internal async Task<List<Recibo>> Filtrar(string value)
+ {
+ List<Recibo> recibos = await Task.Run<List<Recibo>>(() => this.FiltrarRecibo(value));
+ return recibos;
+ }
+
+ public List<Recibo> FiltrarRecibo(string filter)
+ {
+ this.RecibosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Recibo>(this.Recibos) : new ObservableCollection<Recibo>(this.Recibos.Where<Recibo>((Recibo x) => {
+ if (ValidationHelper.RemoveDiacritics(x.get_Pagante().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)))
+ {
+ return true;
+ }
+ return ValidationHelper.RemoveDiacritics(x.get_Recebedor()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter));
+ })));
+ return this.RecibosFiltrados.ToList<Recibo>();
+ }
+
+ private static string GetImage(byte[] bytes, string extensao)
+ {
+ string str;
+ try
+ {
+ Image image = Image.FromStream(new MemoryStream(bytes));
+ string str1 = (extensao.ToUpper().Contains("JPG") ? string.Concat("data:image/jpeg;base64,", Convert.ToBase64String(bytes, Base64FormattingOptions.None)) : string.Concat("data:image/png;base64,", Convert.ToBase64String(bytes, Base64FormattingOptions.None)));
+ string[] strArrays = new string[] { "<img style=\"WIDTH=", null, null, null, null, null, null };
+ int width = image.Width;
+ strArrays[1] = width.ToString();
+ strArrays[2] = "; HEIGHT=";
+ width = image.Height;
+ strArrays[3] = width.ToString();
+ strArrays[4] = "; max-height: 250px; max-width: 250px; margin-bottom: 0px; margin-left: 100px; margin-top: 0px;\" src=\"";
+ strArrays[5] = str1;
+ strArrays[6] = "\"/>";
+ str = string.Concat(strArrays);
+ }
+ catch (Exception exception)
+ {
+ str = "";
+ }
+ return str;
+ }
+
+ public void Incluir()
+ {
+ this.SelectedRecibo = new Recibo();
+ base.Alterar(true);
+ }
+
+ private bool IsImage(string extensao)
+ {
+ if (extensao == null)
+ {
+ return false;
+ }
+ if (extensao.ToLower().Contains("jpg"))
+ {
+ return true;
+ }
+ if (extensao.ToLower().Contains("jpeg"))
+ {
+ return true;
+ }
+ if (extensao.ToLower().Contains("png"))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public async void Print()
+ {
+ bool referente;
+ byte[] arquivo;
+ string str;
+ string str1;
+ string str2;
+ string upper;
+ string str3;
+ string str4;
+ string upper1;
+ string description;
+ object obj;
+ string extensao;
+ string extensao1;
+ long? nullable;
+ string bd;
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital;
+ string image;
+ string str5;
+ Recibo selectedRecibo = this.SelectedRecibo;
+ if (selectedRecibo != null)
+ {
+ referente = selectedRecibo.get_Referente();
+ }
+ else
+ {
+ referente = false;
+ }
+ if (referente && this.SelectedRecibo.get_Recebedor() != null)
+ {
+ arquivoDigital = null;
+ List<IndiceArquivoDigital> indiceArquivoDigitals = await this.ArquivoDigitalServico.BuscarPorTipo(13, Recursos.Empresa.get_Id());
+ if (indiceArquivoDigitals != null)
+ {
+ List<IndiceArquivoDigital> indiceArquivoDigitals1 = indiceArquivoDigitals;
+ if (indiceArquivoDigitals1.Any<IndiceArquivoDigital>((IndiceArquivoDigital x) => x.get_Descricao() == "LOGO"))
+ {
+ List<IndiceArquivoDigital> indiceArquivoDigitals2 = indiceArquivoDigitals;
+ IndiceArquivoDigital indiceArquivoDigital = indiceArquivoDigitals2.FirstOrDefault<IndiceArquivoDigital>((IndiceArquivoDigital x) => x.get_Descricao() == "LOGO");
+ if (indiceArquivoDigital != null)
+ {
+ nullable = new long?(indiceArquivoDigital.get_IdArquivoDigital());
+ }
+ else
+ {
+ nullable = null;
+ }
+ long? nullable1 = nullable;
+ List<IndiceArquivoDigital> indiceArquivoDigitals3 = indiceArquivoDigitals;
+ IndiceArquivoDigital indiceArquivoDigital1 = indiceArquivoDigitals3.FirstOrDefault<IndiceArquivoDigital>((IndiceArquivoDigital x) => x.get_Descricao() == "LOGO");
+ if (indiceArquivoDigital1 != null)
+ {
+ bd = indiceArquivoDigital1.get_Bd();
+ }
+ else
+ {
+ bd = null;
+ }
+ string str6 = bd;
+ if (nullable1.HasValue)
+ {
+ arquivoDigital = await this.ArquivoDigitalServico.BuscarPorId(nullable1.Value, str6);
+ }
+ }
+ }
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital1 = arquivoDigital;
+ if (arquivoDigital1 != null)
+ {
+ arquivo = arquivoDigital1.get_Arquivo();
+ }
+ else
+ {
+ arquivo = null;
+ }
+ byte[] numArray = arquivo;
+ image = "";
+ if (numArray != null && numArray.Length != 0)
+ {
+ ReciboViewModel reciboViewModel = this;
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital2 = arquivoDigital;
+ if (arquivoDigital2 != null)
+ {
+ extensao = arquivoDigital2.get_Extensao();
+ }
+ else
+ {
+ extensao = null;
+ }
+ if (reciboViewModel.IsImage(extensao))
+ {
+ byte[] numArray1 = numArray;
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital3 = arquivoDigital;
+ if (arquivoDigital3 != null)
+ {
+ extensao1 = arquivoDigital3.get_Extensao();
+ }
+ else
+ {
+ extensao1 = null;
+ }
+ image = ReciboViewModel.GetImage(numArray1, extensao1);
+ }
+ }
+ string longDatePattern = (new CultureInfo("pt-PT", false)).DateTimeFormat.LongDatePattern;
+ DateTime? dataRecibo = this.SelectedRecibo.get_DataRecibo();
+ if (dataRecibo.HasValue)
+ {
+ DateTime valueOrDefault = dataRecibo.GetValueOrDefault();
+ str = valueOrDefault.ToString(longDatePattern, new CultureInfo("pt-PT"));
+ }
+ else
+ {
+ str = null;
+ }
+ str5 = str;
+ bool flag = await base.ShowMessage("DESEJA IMPRIMIR DUAS VIAS DO RECIBO?", "SIM", "NÃO", false);
+ int num = (!flag ? 1 : 2);
+ flag = !string.IsNullOrEmpty(image);
+ if (flag)
+ {
+ flag = await base.ShowMessage("DESEJA IMPRIMIR O LOGO DA CORRETORA NO RECIBO?\nPARA ADICIONAR UM LOGO, É NECESSÁRIO COLOCÁ-LO NO ARQUIVO\nDIGITAL NA TELA DE EMPRESA E FILIAIS COM DESCRIÇÃO \"LOGO\"", "SIM", "NÃO", false);
+ }
+ bool flag1 = flag;
+ string str7 = "<html><head><style type='text/css'>@page{size: A4; margin: 0cm}</style><title>RECIBO</title><link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css' integrity='sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh' crossorigin='anonymous'></head><body>";
+ for (int i = 0; i < num; i++)
+ {
+ if (!flag1)
+ {
+ str7 = string.Concat(str7, "<div style='margin: 50px 100px 50px 100px; font-size: 20px;'>");
+ }
+ else
+ {
+ str7 = string.Concat(str7, "<div>", image, "</div>");
+ str7 = string.Concat(str7, "<div style='margin: 0px 100px 0px 100px; font-size: 20px;'>");
+ }
+ str7 = string.Concat(str7, string.Format("<div style='text-align: right'><strong>N° {0}</strong></div><br>", this.SelectedRecibo.get_Id()));
+ str7 = string.Concat(str7, "<strong>R E C I B O</strong><br><br>");
+ if (this.SelectedRecibo.get_Tipo().GetValueOrDefault() != 1)
+ {
+ str1 = (this.SelectedRecibo.get_DocumentoPagante() == null || this.SelectedRecibo.get_DocumentoPagante().Clear().Length < 12 ? "EU" : "A");
+ string str8 = str1;
+ str2 = (this.SelectedRecibo.get_DocumentoPagante() == null || this.SelectedRecibo.get_DocumentoPagante().Clear().Length < 12 ? "CPF" : "CNPJ");
+ string str9 = str2;
+ string str10 = (str8 == "EU" ? "O" : "A");
+ string str11 = (str8 == "EU" ? "PAGUEI" : "PAGOU");
+ object[] pagante = new object[] { str8, this.SelectedRecibo.get_Pagante(), str10, str9, this.SelectedRecibo.get_DocumentoPagante(), str10, str11, this.SelectedRecibo.get_DataRecibo(), this.SelectedRecibo.get_Valor(), ValidationHelper.GetDescription(this.SelectedRecibo.get_Pagamento()), this.SelectedRecibo.get_Recebedor(), this.SelectedRecibo.get_DocumentoRecebedor(), this.SelectedRecibo.get_Referente().ToUpper() };
+ str7 = string.Concat(str7, string.Format("PELO PRESENTE, {0}, <strong>{1}</strong>, INSCRIT{2} NO {3} SOB Nº <strong>{4}</strong>, DECLAR{5} QUE {6}, NA DATA DE HOJE, <strong>{7:dd/MM/yyyy HH:mm}</strong>, O VALOR DE <strong>R$ {8:0.00}</strong> POR MEIO DE <strong>{9}</strong>, PARA <strong>{10}</strong>, INSCRITO NO CPF/CNPJ SOB Nº <strong>{11}</strong>, REFERENTE À(AO) <strong>{12}</strong>. DANDO-LHE POR ESTE RECIBO A DEVIDA QUITAÇÃO.<br>", pagante));
+ string[] cidade = new string[] { str7, "<br><strong>", Recursos.Empresa.get_Cidade(), ", ", null, null };
+ string str12 = str5;
+ if (str12 != null)
+ {
+ upper = str12.ToUpper();
+ }
+ else
+ {
+ upper = null;
+ }
+ cidade[4] = upper;
+ cidade[5] = ".</strong><br><br>";
+ str7 = string.Concat(cidade);
+ string[] recebedor = new string[] { str7, "_________________________________<br><strong>ASSINATURA </strong>", this.SelectedRecibo.get_Recebedor(), "<br>", this.SelectedRecibo.get_DocumentoRecebedor() };
+ str7 = string.Concat(recebedor);
+ }
+ else
+ {
+ str3 = (this.SelectedRecibo.get_DocumentoRecebedor() == null || this.SelectedRecibo.get_DocumentoRecebedor().Clear().Length < 12 ? "EU" : "A");
+ string str13 = str3;
+ str4 = (this.SelectedRecibo.get_DocumentoRecebedor() == null || this.SelectedRecibo.get_DocumentoRecebedor().Clear().Length < 12 ? "CPF" : "CNPJ");
+ string str14 = str4;
+ string str15 = (str13 == "EU" ? "O" : "A");
+ string str16 = (str13 == "EU" ? "RECEBI" : "RECEBEU");
+ object[] objArray = new object[] { str13, this.SelectedRecibo.get_Recebedor(), str15, str14, this.SelectedRecibo.get_DocumentoRecebedor(), str15, str16, this.SelectedRecibo.get_DataRecibo(), this.SelectedRecibo.get_Valor(), ValidationHelper.GetDescription(this.SelectedRecibo.get_Pagamento()), this.SelectedRecibo.get_Pagante(), this.SelectedRecibo.get_DocumentoPagante(), this.SelectedRecibo.get_Referente().ToUpper() };
+ str7 = string.Concat(str7, string.Format("PELO PRESENTE, {0}, <strong>{1}</strong>, INSCRIT{2} NO {3} SOB Nº <strong>{4}</strong>, DECLAR{5} QUE {6}, NA DATA DE HOJE, <strong>{7:dd/MM/yyyy HH:mm}</strong>, O VALOR DE <strong>R$ {8:0.00}</strong> POR MEIO DE <strong>{9}</strong>, DE <strong>{10}</strong>, INSCRITO NO CPF/CNPJ SOB Nº <strong>{11}</strong>, REFERENTE À(AO) <strong>{12}</strong>. DANDO-LHE POR ESTE RECIBO A DEVIDA QUITAÇÃO.<br>", objArray));
+ string[] strArrays = new string[] { str7, "<strong>", Recursos.Empresa.get_Cidade(), ", ", null, null };
+ string str17 = str5;
+ if (str17 != null)
+ {
+ upper1 = str17.ToUpper();
+ }
+ else
+ {
+ upper1 = null;
+ }
+ strArrays[4] = upper1;
+ strArrays[5] = ".</strong><br><br>";
+ str7 = string.Concat(strArrays);
+ string[] recebedor1 = new string[] { str7, "_________________________________<br><strong>ASSINATURA </strong>", this.SelectedRecibo.get_Recebedor(), "<br>", this.SelectedRecibo.get_DocumentoRecebedor() };
+ str7 = string.Concat(recebedor1);
+ }
+ str7 = string.Concat(str7, "<hr /></div>");
+ }
+ str7 = string.Concat(str7, "<script src='https://code.jquery.com/jquery-3.4.1.slim.min.js' integrity='sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n' crossorigin='anonymous'></script> <script src = 'https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js' integrity = 'sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo' crossorigin = 'anonymous' ></script><script src = 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js' integrity = 'sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6' crossorigin = 'anonymous' ></script> </body></html>");
+ string tempPath = Path.GetTempPath();
+ string str18 = string.Format("{0}_{1:ddMMyyyyhhmmss}.html", tempPath, Funcoes.GetNetworkTime());
+ StreamWriter streamWriter = new StreamWriter(str18, true, Encoding.UTF8);
+ streamWriter.Write(str7);
+ streamWriter.Close();
+ Process.Start(str18);
+ ReciboViewModel reciboViewModel1 = this;
+ string str19 = string.Format("IMPRIMIU O RECIBO DE NÚMERO \"{0}\"", this.SelectedRecibo.get_Id());
+ long id = this.SelectedRecibo.get_Id();
+ TipoTela? nullable2 = new TipoTela?(42);
+ object[] valor = new object[9];
+ if (this.SelectedRecibo.get_Tipo().HasValue)
+ {
+ TipoRecibo? tipo = this.SelectedRecibo.get_Tipo();
+ description = ValidationHelper.GetDescription(tipo.Value);
+ if (description == null)
+ {
+ description = "";
+ }
+ }
+ else
+ {
+ description = "-";
+ }
+ valor[0] = description;
+ TipoPagamento? pagamento = this.SelectedRecibo.get_Pagamento();
+ if (pagamento.HasValue)
+ {
+ obj = ValidationHelper.GetDescription(pagamento.GetValueOrDefault());
+ }
+ else
+ {
+ obj = null;
+ }
+ valor[1] = obj;
+ valor[2] = this.SelectedRecibo.get_Valor();
+ valor[3] = this.SelectedRecibo.get_DataRecibo();
+ valor[4] = this.SelectedRecibo.get_Pagante();
+ valor[5] = this.SelectedRecibo.get_DocumentoPagante();
+ valor[6] = this.SelectedRecibo.get_Recebedor();
+ valor[7] = this.SelectedRecibo.get_DocumentoRecebedor();
+ valor[8] = this.SelectedRecibo.get_Referente();
+ reciboViewModel1.RegistrarAcao(str19, id, nullable2, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", valor));
+ }
+ arquivoDigital = null;
+ image = null;
+ str5 = null;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string description;
+ object obj;
+ string str1;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedRecibo.Validate();
+ if (keyValuePairs1.Count <= 0)
+ {
+ str = (this.SelectedRecibo.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
+ str1 = str;
+ Recibo recibo = await this._servico.Save(this.SelectedRecibo);
+ if (this._servico.Sucesso)
+ {
+ ReciboViewModel reciboViewModel = this;
+ string str2 = string.Format("{0} RECIBO DE NÚMERO \"{1}\"", str1, recibo.get_Id());
+ long id = recibo.get_Id();
+ TipoTela? nullable = new TipoTela?(42);
+ object[] valor = new object[9];
+ if (recibo.get_Tipo().HasValue)
+ {
+ TipoRecibo? tipo = recibo.get_Tipo();
+ description = ValidationHelper.GetDescription(tipo.Value);
+ if (description == null)
+ {
+ description = "";
+ }
+ }
+ else
+ {
+ description = "-";
+ }
+ valor[0] = description;
+ TipoPagamento? pagamento = recibo.get_Pagamento();
+ if (pagamento.HasValue)
+ {
+ obj = ValidationHelper.GetDescription(pagamento.GetValueOrDefault());
+ }
+ else
+ {
+ obj = null;
+ }
+ valor[1] = obj;
+ valor[2] = recibo.get_Valor();
+ valor[3] = recibo.get_DataRecibo();
+ valor[4] = recibo.get_Pagante();
+ valor[5] = recibo.get_DocumentoPagante();
+ valor[6] = recibo.get_Recebedor();
+ valor[7] = recibo.get_DocumentoRecebedor();
+ valor[8] = recibo.get_Referente();
+ reciboViewModel.RegistrarAcao(str2, id, nullable, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", valor));
+ if (!this.Recibos.Any<Recibo>((Recibo x) => x.get_Id() == recibo.get_Id()))
+ {
+ this.Recibos.Add(recibo);
+ }
+ else
+ {
+ DomainBase.Copy<Recibo, Recibo>(this.Recibos.First<Recibo>((Recibo x) => x.get_Id() == recibo.get_Id()), recibo);
+ }
+ if (!this.RecibosFiltrados.Any<Recibo>((Recibo x) => x.get_Id() == recibo.get_Id()))
+ {
+ this.RecibosFiltrados.Add(recibo);
+ }
+ else
+ {
+ DomainBase.Copy<Recibo, Recibo>(this.RecibosFiltrados.First<Recibo>((Recibo x) => x.get_Id() == recibo.get_Id()), recibo);
+ }
+ this.RecibosFiltrados = new ObservableCollection<Recibo>(this.RecibosFiltrados);
+ this.WorkOnSelectedRecibo(recibo, false);
+ base.Alterar(false);
+ base.ToggleSnackBar("RECIBO SALVO COM SUCESSO", true);
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = null;
+ }
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ str1 = null;
+ return keyValuePairs;
+ }
+
+ private async void Seleciona()
+ {
+ base.Loading(true);
+ await base.PermissaoTela(42);
+ await this.SelecionaRecibo();
+ base.Loading(false);
+ }
+
+ private async Task SelecionaRecibo()
+ {
+ base.Loading(true);
+ List<Recibo> recibos = await this._servico.BuscarRecibos();
+ this.Recibos = recibos.ToList<Recibo>();
+ this.RecibosFiltrados = new ObservableCollection<Recibo>(this.Recibos);
+ if (this.RecibosFiltrados.Count <= 0)
+ {
+ this.SelectedRecibo = new Recibo();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelectedRecibo = this.RecibosFiltrados.First<Recibo>();
+ }
+ base.Loading(false);
+ }
+
+ private void WorkOnSelectedPagante(Cliente value)
+ {
+ if (value != null)
+ {
+ this.SelectedRecibo.set_Pagante(Regex.Replace(value.get_NomeSocial(), "\\-\\s\\d.*", "").Trim());
+ this.SelectedRecibo.set_DocumentoPagante(value.get_Documento());
+ this.SelectedRecibo = this.SelectedRecibo;
+ }
+ }
+
+ private void WorkOnSelectedRecebedor(Cliente value)
+ {
+ if (value != null)
+ {
+ this.SelectedRecibo.set_Recebedor(Regex.Replace(value.get_NomeSocial(), "\\-\\s\\d.*", "").Trim());
+ this.SelectedRecibo.set_DocumentoRecebedor(value.get_Documento());
+ this.SelectedRecibo = this.SelectedRecibo;
+ }
+ }
+
+ private void WorkOnSelectedRecibo(Recibo value, bool registrar = true)
+ {
+ long? nullable;
+ string description;
+ object obj;
+ this.CancelRecibo = (value == null || value.get_Id() == 0 ? this.CancelRecibo : (Recibo)value.Clone());
+ if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 42)
+ {
+ return;
+ }
+ if (registrar)
+ {
+ string str = string.Format("ACESSOU RECIBO DE NÚMERO \"{0}\"", value.get_Id());
+ long id = value.get_Id();
+ TipoTela? nullable1 = new TipoTela?(42);
+ object[] valor = new object[9];
+ if (value.get_Tipo().HasValue)
+ {
+ TipoRecibo? tipo = value.get_Tipo();
+ description = ValidationHelper.GetDescription(tipo.Value) ?? "";
+ }
+ else
+ {
+ description = "-";
+ }
+ valor[0] = description;
+ TipoPagamento? pagamento = value.get_Pagamento();
+ if (pagamento.HasValue)
+ {
+ obj = ValidationHelper.GetDescription(pagamento.GetValueOrDefault());
+ }
+ else
+ {
+ obj = null;
+ }
+ valor[1] = obj;
+ valor[2] = value.get_Valor();
+ valor[3] = value.get_DataRecibo();
+ valor[4] = value.get_Pagante();
+ valor[5] = value.get_DocumentoPagante();
+ valor[6] = value.get_Recebedor();
+ valor[7] = value.get_DocumentoRecebedor();
+ valor[8] = value.get_Referente();
+ base.RegistrarAcao(str, id, nullable1, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", valor));
+ }
+ this.LastAccessId = value.get_Id();
+ this.LastAccessTela = 42;
+ Recibo selectedRecibo = this.SelectedRecibo;
+ if (selectedRecibo != null)
+ {
+ nullable = new long?(selectedRecibo.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ long? nullable2 = nullable;
+ long num = value.get_Id();
+ if (nullable2.GetValueOrDefault() != num | !nullable2.HasValue)
+ {
+ this.SelectedRecibo = this.RecibosFiltrados.FirstOrDefault<Recibo>((Recibo x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs
new file mode 100644
index 0000000..f7daced
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs
@@ -0,0 +1,621 @@
+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<SeguradoraContato> _contatos = new ObservableCollection<SeguradoraContato>();
+
+ private ObservableCollection<SeguradoraEndereco> _enderecos = new ObservableCollection<SeguradoraEndereco>();
+
+ private SeguradoraContato _selectedTelefone = new SeguradoraContato();
+
+ private Visibility _tipoTelefone;
+
+ private Visibility _telefone;
+
+ private Visibility _prefixo;
+
+ private ObservableCollection<ConfigExtratoImport> _configFiltrados = new ObservableCollection<ConfigExtratoImport>();
+
+ public Seguradora CancelSeguradora;
+
+ public ObservableCollection<SeguradoraEndereco> CancelEnderecos;
+
+ public ObservableCollection<SeguradoraContato> CancelContatos;
+
+ private ObservableCollection<Seguradora> _seguradorasFiltradas = new ObservableCollection<Seguradora>();
+
+ private bool _isExpanded;
+
+ public bool Apelido
+ {
+ get
+ {
+ return this._apelido;
+ }
+ set
+ {
+ this._apelido = value;
+ base.OnPropertyChanged("Apelido");
+ }
+ }
+
+ public List<ConfigExtratoImport> Config
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<ConfigExtratoImport> ConfigFiltrados
+ {
+ get
+ {
+ return this._configFiltrados;
+ }
+ set
+ {
+ this._configFiltrados = value;
+ base.OnPropertyChanged("ConfigFiltrados");
+ }
+ }
+
+ public ObservableCollection<SeguradoraContato> Contatos
+ {
+ get
+ {
+ return this._contatos;
+ }
+ set
+ {
+ this._contatos = value;
+ base.OnPropertyChanged("Contatos");
+ }
+ }
+
+ public ObservableCollection<SeguradoraEndereco> 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<Seguradora> Seguradoras
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Seguradora> 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>((ConfiguracaoSistema x) => x.get_Configuracao() == 6);
+ base.EnableMenu = true;
+ this.Seleciona();
+ }
+
+ public void CancelarAlteracao()
+ {
+ if (this.CancelSeguradora != null && this.Seguradoras.Any<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()))
+ {
+ DomainBase.Copy<Seguradora, Seguradora>(this.Seguradoras.First<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()), this.CancelSeguradora);
+ if (this.SeguradorasFiltradas.Count <= 0 || !this.SeguradorasFiltradas.Any<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()))
+ {
+ this.SeguradorasFiltradas.Add(this.CancelSeguradora);
+ }
+ else
+ {
+ DomainBase.Copy<Seguradora, Seguradora>(this.SeguradorasFiltradas.First<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()), this.CancelSeguradora);
+ }
+ this.SeguradorasFiltradas = new ObservableCollection<Seguradora>(this.SeguradorasFiltradas);
+ this.ConfigFiltrados = new ObservableCollection<ConfigExtratoImport>(this.ConfigFiltrados);
+ this.SelectedSeguradora = this.SeguradorasFiltradas.First<Seguradora>((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<SeguradoraEndereco>(this.Enderecos);
+ this.CancelContatos = new ObservableCollection<SeguradoraContato>(this.Contatos);
+ }
+
+ public void ExcluirEndereco(SeguradoraEndereco endereco)
+ {
+ this.Enderecos.Remove(endereco);
+ }
+
+ public void ExcluirTelefone(SeguradoraContato contato)
+ {
+ this.Contatos.Remove(contato);
+ }
+
+ internal async Task<List<Seguradora>> Filtrar(string value)
+ {
+ List<Seguradora> seguradoras = await Task.Run<List<Seguradora>>(() => this.FiltrarSeguradora(value));
+ return seguradoras;
+ }
+
+ internal async Task<List<ConfigExtratoImport>> FiltrarConfig(string value)
+ {
+ List<ConfigExtratoImport> configExtratoImports = await Task.Run<List<ConfigExtratoImport>>(() => this.FiltrarDescricao(value));
+ return configExtratoImports;
+ }
+
+ public List<ConfigExtratoImport> FiltrarDescricao(string filter)
+ {
+ this.ConfigFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<ConfigExtratoImport>(this.Config) : new ObservableCollection<ConfigExtratoImport>(
+ 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<ConfigExtratoImport>();
+ }
+
+ public List<Seguradora> FiltrarSeguradora(string filter)
+ {
+ this.Pesquisa = filter;
+ this.SeguradorasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Seguradora>(this.Seguradoras) : new ObservableCollection<Seguradora>(this.Seguradoras.Where<Seguradora>((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, bool>((Seguradora x) => x.get_Ativo()).ThenBy<Seguradora, string>((Seguradora x) => x.get_Nome())));
+ return this.SeguradorasFiltradas.ToList<Seguradora>();
+ }
+
+ 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 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 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedSeguradora.Validate();
+ keyValuePairs1.AddRange(this.Validate(this.Contatos.ToList<SeguradoraContato>()));
+ keyValuePairs1.AddRange(this.Validate(this.Enderecos.ToList<SeguradoraEndereco>()));
+ if (keyValuePairs1.Count <= 0)
+ {
+ Seguradora selectedSeguradora = this.SelectedSeguradora;
+ ObservableCollection<SeguradoraContato> contatos = this.Contatos;
+ selectedSeguradora.set_Contatos(contatos.Where<SeguradoraContato>((SeguradoraContato x) => {
+ if (!string.IsNullOrEmpty(x.get_NomeContato()))
+ {
+ return true;
+ }
+ return x.get_TipoContato() == 1;
+ }).ToList<SeguradoraContato>());
+ Seguradora seguradora = this.SelectedSeguradora;
+ ObservableCollection<SeguradoraEndereco> enderecos = this.Enderecos;
+ seguradora.set_Enderecos((
+ from x in enderecos
+ where !string.IsNullOrEmpty(x.get_Bairro())
+ select x).ToList<SeguradoraEndereco>());
+ 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>((Seguradora x) => x.get_Id() == seguradora2.get_Id());
+ if (seguradora3 == null)
+ {
+ seguradora3 = this.SeguradorasFiltradas.FirstOrDefault<Seguradora>();
+ }
+ 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<ConfigExtratoImport>(this.Config);
+ base.Loading(false);
+ }
+
+ private async Task SelecionaSeguradoras(Seguradora seguradora = null)
+ {
+ base.Loading(true);
+ List<Seguradora> seguradoras = await (new BaseServico()).BuscarSeguradorasAsync();
+ SeguradoraViewModel list = this;
+ List<Seguradora> seguradoras1 = seguradoras;
+ IOrderedEnumerable<Seguradora> ativo =
+ from x in seguradoras1
+ orderby x.get_Ativo() descending
+ select x;
+ list.Seguradoras = ativo.ThenBy<Seguradora, string>((Seguradora x) => x.get_Nome()).ToList<Seguradora>();
+ this.SeguradorasFiltradas = new ObservableCollection<Seguradora>(this.Seguradoras);
+ if (seguradora != null)
+ {
+ this.SelecionaSeguradora(this.SeguradorasFiltradas.FirstOrDefault<Seguradora>((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<Seguradora>());
+ }
+ Recursos.Seguradoras = seguradoras;
+ base.Loading(false);
+ }
+
+ public List<KeyValuePair<string, string>> Validate(List<SeguradoraEndereco> endereco)
+ {
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (endereco != null)
+ {
+ endereco.ForEach((SeguradoraEndereco x) => keyValuePairs.AddRange(x.Validate()));
+ }
+ return keyValuePairs.Distinct<KeyValuePair<string, string>>().ToList<KeyValuePair<string, string>>();
+ }
+
+ public List<KeyValuePair<string, string>> Validate(List<SeguradoraContato> contatos)
+ {
+ List<SeguradoraContato> list;
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ 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<SeguradoraContato>();
+ }
+ else
+ {
+ list = null;
+ }
+ List<SeguradoraContato> seguradoraContatos = list;
+ if (seguradoraContatos == null)
+ {
+ return keyValuePairs;
+ }
+ if (seguradoraContatos.Count > 4)
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("ASSISTÊNCIAS 24 HORAS", "NÃO É POSSÍVEL ADICIONAR MAIS QUE 4 NUMEROS DE ASSISTÊNCIA 24 HORAS"));
+ }
+ return keyValuePairs.Distinct<KeyValuePair<string, string>>().ToList<KeyValuePair<string, string>>();
+ }
+
+ 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<SeguradoraEndereco>(this.Enderecos);
+ this.CancelContatos = new ObservableCollection<SeguradoraContato>(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<SeguradoraContato>(this.SelectedSeguradora.get_Contatos());
+ }
+ Seguradora seguradora = this.SelectedSeguradora;
+ if (seguradora != null)
+ {
+ enderecos = seguradora.get_Enderecos();
+ }
+ else
+ {
+ enderecos = false;
+ }
+ if (enderecos)
+ {
+ this.Enderecos = new ObservableCollection<SeguradoraEndereco>(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>((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/Codemerx/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs
new file mode 100644
index 0000000..d946d89
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/SocioViewModel.cs
@@ -0,0 +1,358 @@
+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<Empresa> _empresas = new ObservableCollection<Empresa>();
+
+ private Empresa _selectedEmpresa;
+
+ private Socio _selectedSocio = new Socio();
+
+ private ObservableCollection<Socio> _sociosFiltradas = new ObservableCollection<Socio>();
+
+ private bool _isExpanded;
+
+ private bool _isLoading;
+
+ public ObservableCollection<Empresa> 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<Socio> Socios
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Socio> 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>((Socio x) => x.get_Id() == this.CancelSocio.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Socio, Socio>(this.Socios.First<Socio>((Socio x) => x.get_Id() == this.CancelSocio.get_Id()), this.CancelSocio);
+ if (this.SociosFiltradas.Count <= 0 || !this.SociosFiltradas.Any<Socio>((Socio x) => x.get_Id() == this.CancelSocio.get_Id()))
+ {
+ this.SociosFiltradas.Add(this.CancelSocio);
+ }
+ else
+ {
+ DomainBase.Copy<Socio, Socio>(this.SociosFiltradas.First<Socio>((Socio x) => x.get_Id() == this.CancelSocio.get_Id()), this.CancelSocio);
+ }
+ this.SociosFiltradas = new ObservableCollection<Socio>(this.SociosFiltradas);
+ this.SelectedSocio = this.SociosFiltradas.First<Socio>((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<Socio>(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<Socio>(num) : this.SociosFiltradas.Last<Socio>());
+ 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<List<Socio>> Filtrar(string value)
+ {
+ List<Socio> socios = await Task.Run<List<Socio>>(() => this.FiltrarSocio(value));
+ return socios;
+ }
+
+ public List<Socio> FiltrarSocio(string filter)
+ {
+ this.SociosFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Socio>(this.Socios) : new ObservableCollection<Socio>(
+ 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<Socio>();
+ }
+
+ public void Incluir()
+ {
+ Socio socio = new Socio();
+ socio.set_IdEmpresa(this.SelectedEmpresa.get_Id());
+ this.SelectedSocio = socio;
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string str1;
+ List<KeyValuePair<string, string>> 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>((Socio x) => x.get_Id() == socio.get_Id()))
+ {
+ this.Socios.Add(socio);
+ }
+ else
+ {
+ DomainBase.Copy<Socio, Socio>(this.Socios.First<Socio>((Socio x) => x.get_Id() == socio.get_Id()), socio);
+ }
+ if (!this.SociosFiltradas.Any<Socio>((Socio x) => x.get_Id() == socio.get_Id()))
+ {
+ this.SociosFiltradas.Add(socio);
+ }
+ else
+ {
+ DomainBase.Copy<Socio, Socio>(this.SociosFiltradas.First<Socio>((Socio x) => x.get_Id() == socio.get_Id()), socio);
+ }
+ this.SociosFiltradas = new ObservableCollection<Socio>(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<Empresa>(await (new EmpresaServico()).BuscarEmpresas());
+ base.Loading(false);
+ this.SelectedEmpresa = this.Empresas.FirstOrDefault<Empresa>();
+ }
+
+ 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<Socio> socios = await (new BaseServico()).BuscarSociosAsync(id.Value);
+ SocioViewModel list = this;
+ List<Socio> socios1 = socios;
+ list.Socios = (
+ from x in socios1
+ orderby x.get_Nome()
+ select x).ToList<Socio>();
+ this.SociosFiltradas = new ObservableCollection<Socio>(this.Socios);
+ this.SelectedSocio = this.SociosFiltradas.FirstOrDefault<Socio>();
+ 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>((Socio x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/StatusProspeccaoViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/StatusProspeccaoViewModel.cs
new file mode 100644
index 0000000..4643cd1
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/StatusProspeccaoViewModel.cs
@@ -0,0 +1,326 @@
+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<StatusDeProspeccao> _statusProspeccaoFiltrados = new ObservableCollection<StatusDeProspeccao>();
+
+ 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<StatusDeProspeccao> StatusProspeccao
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<StatusDeProspeccao> 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>((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<StatusDeProspeccao, StatusDeProspeccao>(this.StatusProspeccao.First<StatusDeProspeccao>((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id()), this.CancelStatusProspeccao);
+ if (this.StatusProspeccaoFiltrados.Count <= 0 || !this.StatusProspeccaoFiltrados.Any<StatusDeProspeccao>((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id()))
+ {
+ this.StatusProspeccaoFiltrados.Add(this.CancelStatusProspeccao);
+ }
+ else
+ {
+ DomainBase.Copy<StatusDeProspeccao, StatusDeProspeccao>(this.StatusProspeccaoFiltrados.First<StatusDeProspeccao>((StatusDeProspeccao x) => x.get_Id() == this.CancelStatusProspeccao.get_Id()), this.CancelStatusProspeccao);
+ }
+ this.StatusProspeccaoFiltrados = new ObservableCollection<StatusDeProspeccao>(this.StatusProspeccaoFiltrados);
+ this.SelectedStatusProspeccao = this.StatusProspeccaoFiltrados.First<StatusDeProspeccao>((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<StatusDeProspeccao>();
+ await this.SelecionaStatusProspeccao();
+ base.Loading(false);
+ base.ToggleSnackBar("STATUS DE PROSPECÇÃO EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ public async Task<List<StatusDeProspeccao>> Filtrar(string value)
+ {
+ List<StatusDeProspeccao> statusDeProspeccaos = await Task.Run<List<StatusDeProspeccao>>(() => this.FiltrarStatusProspeccao(value));
+ return statusDeProspeccaos;
+ }
+
+ public List<StatusDeProspeccao> FiltrarStatusProspeccao(string filter)
+ {
+ this.StatusProspeccaoFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<StatusDeProspeccao>(this.StatusProspeccao) : new ObservableCollection<StatusDeProspeccao>(
+ 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<StatusDeProspeccao>();
+ return this.StatusProspeccaoFiltrados.ToList<StatusDeProspeccao>();
+ }
+
+ public void Incluir()
+ {
+ StatusDeProspeccao statusDeProspeccao = new StatusDeProspeccao();
+ statusDeProspeccao.set_Ativo(true);
+ statusDeProspeccao.set_Excluido(false);
+ this.SelectedStatusProspeccao = statusDeProspeccao;
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ object obj;
+ string str1;
+ List<KeyValuePair<string, string>> 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>((StatusDeProspeccao x) => x.get_Id() == statusDeProspeccao.get_Id()))
+ {
+ this.StatusProspeccao.Add(statusDeProspeccao);
+ }
+ else
+ {
+ DomainBase.Copy<StatusDeProspeccao, StatusDeProspeccao>(this.StatusProspeccao.First<StatusDeProspeccao>((StatusDeProspeccao x) => x.get_Id() == statusDeProspeccao.get_Id()), statusDeProspeccao);
+ }
+ if (!this.StatusProspeccaoFiltrados.Any<StatusDeProspeccao>((StatusDeProspeccao x) => x.get_Id() == statusDeProspeccao.get_Id()))
+ {
+ this.StatusProspeccaoFiltrados.Add(statusDeProspeccao);
+ }
+ else
+ {
+ DomainBase.Copy<StatusDeProspeccao, StatusDeProspeccao>(this.StatusProspeccaoFiltrados.First<StatusDeProspeccao>((StatusDeProspeccao x) => x.get_Id() == statusDeProspeccao.get_Id()), statusDeProspeccao);
+ }
+ this.StatusProspeccaoFiltrados = new ObservableCollection<StatusDeProspeccao>(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<StatusDeProspeccao> statusDeProspeccaos = await this._servico.BuscarProspeccoes();
+ StatusProspeccaoViewModel list = this;
+ List<StatusDeProspeccao> statusDeProspeccaos1 = statusDeProspeccaos;
+ IEnumerable<StatusDeProspeccao> excluido =
+ from x in statusDeProspeccaos1
+ where !x.get_Excluido()
+ select x;
+ IOrderedEnumerable<StatusDeProspeccao> ativo =
+ from x in excluido
+ orderby x.get_Ativo() descending
+ select x;
+ list.StatusProspeccao = ativo.ThenBy<StatusDeProspeccao, string>((StatusDeProspeccao x) => x.get_Nome()).ToList<StatusDeProspeccao>();
+ this.StatusProspeccaoFiltrados = new ObservableCollection<StatusDeProspeccao>(this.StatusProspeccao);
+ this.SelectedStatusProspeccao = this.StatusProspeccaoFiltrados.FirstOrDefault<StatusDeProspeccao>();
+ base.Loading(false);
+ }
+
+ public List<KeyValuePair<string, string>> Validate()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (string.IsNullOrWhiteSpace(this.SelectedStatusProspeccao.get_Nome()))
+ {
+ return keyValuePairs;
+ }
+ if (this.StatusProspeccao.Any<StatusDeProspeccao>((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<string, string>("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>((StatusDeProspeccao x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/StatusViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/StatusViewModel.cs
new file mode 100644
index 0000000..93b36c1
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/StatusViewModel.cs
@@ -0,0 +1,367 @@
+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<Gestor.Model.Domain.Seguros.Status> _statusFiltrados = new ObservableCollection<Gestor.Model.Domain.Seguros.Status>();
+
+ 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<Gestor.Model.Domain.Seguros.Status> Status
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Gestor.Model.Domain.Seguros.Status> 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>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == this.CancelStatus.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Gestor.Model.Domain.Seguros.Status, Gestor.Model.Domain.Seguros.Status>(this.Status.First<Gestor.Model.Domain.Seguros.Status>((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>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == this.CancelStatus.get_Id()))
+ {
+ this.StatusFiltrados.Add(this.CancelStatus);
+ }
+ else
+ {
+ DomainBase.Copy<Gestor.Model.Domain.Seguros.Status, Gestor.Model.Domain.Seguros.Status>(this.StatusFiltrados.First<Gestor.Model.Domain.Seguros.Status>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == this.CancelStatus.get_Id()), this.CancelStatus);
+ }
+ this.StatusFiltrados = new ObservableCollection<Gestor.Model.Domain.Seguros.Status>(this.StatusFiltrados);
+ this.SelectedStatus = this.StatusFiltrados.First<Gestor.Model.Domain.Seguros.Status>((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<Documento> 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<Gestor.Model.Domain.Seguros.Status>(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<Gestor.Model.Domain.Seguros.Status>(num) : this.StatusFiltrados.Last<Gestor.Model.Domain.Seguros.Status>());
+ statusViewModel1.SelectedStatus = statu;
+ }
+ base.Loading(false);
+ base.ToggleSnackBar("ESTIPULANTE EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ internal async Task<List<Gestor.Model.Domain.Seguros.Status>> Filtrar(string value)
+ {
+ List<Gestor.Model.Domain.Seguros.Status> statuses = await Task.Run<List<Gestor.Model.Domain.Seguros.Status>>(() => this.FiltrarStatus(value));
+ return statuses;
+ }
+
+ public List<Gestor.Model.Domain.Seguros.Status> FiltrarStatus(string filter)
+ {
+ this.StatusFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Gestor.Model.Domain.Seguros.Status>(this.Status) : new ObservableCollection<Gestor.Model.Domain.Seguros.Status>(
+ 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<Gestor.Model.Domain.Seguros.Status>();
+ }
+
+ 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ object obj;
+ string str1;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedStatus.Validate();
+ List<KeyValuePair<string, string>> 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>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == statu.get_Id()))
+ {
+ this.Status.Add(statu);
+ }
+ else
+ {
+ DomainBase.Copy<Gestor.Model.Domain.Seguros.Status, Gestor.Model.Domain.Seguros.Status>(this.Status.First<Gestor.Model.Domain.Seguros.Status>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == statu.get_Id()), statu);
+ }
+ if (!this.StatusFiltrados.Any<Gestor.Model.Domain.Seguros.Status>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == statu.get_Id()))
+ {
+ this.StatusFiltrados.Add(statu);
+ }
+ else
+ {
+ DomainBase.Copy<Gestor.Model.Domain.Seguros.Status, Gestor.Model.Domain.Seguros.Status>(this.StatusFiltrados.First<Gestor.Model.Domain.Seguros.Status>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == statu.get_Id()), statu);
+ }
+ this.StatusFiltrados = new ObservableCollection<Gestor.Model.Domain.Seguros.Status>(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<Gestor.Model.Domain.Seguros.Status, Gestor.Model.Domain.Seguros.Status>(this.StatusFiltrados.First<Gestor.Model.Domain.Seguros.Status>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == status.get_Id()), statu);
+ this.SelectedStatus = this.StatusFiltrados.First<Gestor.Model.Domain.Seguros.Status>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == status.get_Id());
+ }
+
+ private async Task SelecionaStatuses()
+ {
+ base.Loading(true);
+ List<Gestor.Model.Domain.Seguros.Status> statuses = await (new BaseServico()).BuscarStatusAsync();
+ StatusViewModel list = this;
+ List<Gestor.Model.Domain.Seguros.Status> statuses1 = statuses;
+ IOrderedEnumerable<Gestor.Model.Domain.Seguros.Status> ativo =
+ from x in statuses1
+ orderby x.get_Ativo() descending
+ select x;
+ list.Status = ativo.ThenBy<Gestor.Model.Domain.Seguros.Status, string>((Gestor.Model.Domain.Seguros.Status x) => x.get_Nome()).ToList<Gestor.Model.Domain.Seguros.Status>();
+ this.StatusFiltrados = new ObservableCollection<Gestor.Model.Domain.Seguros.Status>(this.Status);
+ this.SelectedStatus = this.StatusFiltrados.FirstOrDefault<Gestor.Model.Domain.Seguros.Status>();
+ Recursos.Status = this.Status;
+ base.Loading(false);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ List<KeyValuePair<string, string>> keyValuePairs1;
+ if (!string.IsNullOrWhiteSpace(this.SelectedStatus.get_Nome()))
+ {
+ keyValuePairs1 = new List<KeyValuePair<string, string>>();
+ bool flag = true;
+ List<Gestor.Model.Domain.Seguros.Status> 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<string, string>("Nome", "UM STATUS COM O MESMO NOME JÁ EXISTE."));
+ }
+ keyValuePairs = keyValuePairs1;
+ }
+ else
+ {
+ keyValuePairs = new List<KeyValuePair<string, string>>();
+ }
+ 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>((Gestor.Model.Domain.Seguros.Status x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/TipoTarefaViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/TipoTarefaViewModel.cs
new file mode 100644
index 0000000..07b51e1
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/TipoTarefaViewModel.cs
@@ -0,0 +1,325 @@
+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<TipoDeTarefa> _tiposTarefaFiltrados = new ObservableCollection<TipoDeTarefa>();
+
+ 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<TipoDeTarefa> TiposTarefa
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<TipoDeTarefa> 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>((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<TipoDeTarefa, TipoDeTarefa>(this.TiposTarefa.First<TipoDeTarefa>((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id()), this.CancelTipoTarefa);
+ if (this.TiposTarefaFiltrados.Count <= 0 || !this.TiposTarefaFiltrados.Any<TipoDeTarefa>((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id()))
+ {
+ this.TiposTarefaFiltrados.Add(this.CancelTipoTarefa);
+ }
+ else
+ {
+ DomainBase.Copy<TipoDeTarefa, TipoDeTarefa>(this.TiposTarefaFiltrados.First<TipoDeTarefa>((TipoDeTarefa x) => x.get_Id() == this.CancelTipoTarefa.get_Id()), this.CancelTipoTarefa);
+ }
+ this.TiposTarefaFiltrados = new ObservableCollection<TipoDeTarefa>(this.TiposTarefaFiltrados);
+ this.SelectedTipoTarefa = this.TiposTarefaFiltrados.First<TipoDeTarefa>((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<TipoDeTarefa>();
+ await this.SelecionaTipoTarefa();
+ base.Loading(false);
+ base.ToggleSnackBar("TIPO DE TAREFA EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ public async Task<List<TipoDeTarefa>> Filtrar(string value)
+ {
+ List<TipoDeTarefa> tipoDeTarefas = await Task.Run<List<TipoDeTarefa>>(() => this.FiltrarTipoTarefa(value));
+ return tipoDeTarefas;
+ }
+
+ public List<TipoDeTarefa> FiltrarTipoTarefa(string filter)
+ {
+ this.TiposTarefaFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<TipoDeTarefa>(this.TiposTarefa) : new ObservableCollection<TipoDeTarefa>(
+ 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<TipoDeTarefa>();
+ return this.TiposTarefaFiltrados.ToList<TipoDeTarefa>();
+ }
+
+ public void Incluir()
+ {
+ TipoDeTarefa tipoDeTarefa = new TipoDeTarefa();
+ tipoDeTarefa.set_Ativo(true);
+ tipoDeTarefa.set_Excluido(false);
+ this.SelectedTipoTarefa = tipoDeTarefa;
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ object obj;
+ string str1;
+ List<KeyValuePair<string, string>> 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>((TipoDeTarefa x) => x.get_Id() == tipoDeTarefa.get_Id()))
+ {
+ this.TiposTarefa.Add(tipoDeTarefa);
+ }
+ else
+ {
+ DomainBase.Copy<TipoDeTarefa, TipoDeTarefa>(this.TiposTarefa.First<TipoDeTarefa>((TipoDeTarefa x) => x.get_Id() == tipoDeTarefa.get_Id()), tipoDeTarefa);
+ }
+ if (!this.TiposTarefaFiltrados.Any<TipoDeTarefa>((TipoDeTarefa x) => x.get_Id() == tipoDeTarefa.get_Id()))
+ {
+ this.TiposTarefaFiltrados.Add(tipoDeTarefa);
+ }
+ else
+ {
+ DomainBase.Copy<TipoDeTarefa, TipoDeTarefa>(this.TiposTarefaFiltrados.First<TipoDeTarefa>((TipoDeTarefa x) => x.get_Id() == tipoDeTarefa.get_Id()), tipoDeTarefa);
+ }
+ this.TiposTarefaFiltrados = new ObservableCollection<TipoDeTarefa>(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<TipoDeTarefa> tipoDeTarefas = await this._servico.BuscarTarefas();
+ TipoTarefaViewModel list = this;
+ List<TipoDeTarefa> tipoDeTarefas1 = tipoDeTarefas;
+ IEnumerable<TipoDeTarefa> excluido =
+ from x in tipoDeTarefas1
+ where !x.get_Excluido()
+ select x;
+ IOrderedEnumerable<TipoDeTarefa> ativo =
+ from x in excluido
+ orderby x.get_Ativo() descending
+ select x;
+ list.TiposTarefa = ativo.ThenBy<TipoDeTarefa, string>((TipoDeTarefa x) => x.get_Nome()).ToList<TipoDeTarefa>();
+ this.TiposTarefaFiltrados = new ObservableCollection<TipoDeTarefa>(this.TiposTarefa);
+ this.SelectedTipoTarefa = this.TiposTarefaFiltrados.FirstOrDefault<TipoDeTarefa>();
+ base.Loading(false);
+ }
+
+ public List<KeyValuePair<string, string>> Validate()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (string.IsNullOrWhiteSpace(this.SelectedTipoTarefa.get_Nome()))
+ {
+ return keyValuePairs;
+ }
+ if (this.TiposTarefa.Any<TipoDeTarefa>((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<string, string>("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>((TipoDeTarefa x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/TipoVendedorViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/TipoVendedorViewModel.cs
new file mode 100644
index 0000000..c4ff8bc
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/TipoVendedorViewModel.cs
@@ -0,0 +1,338 @@
+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<TipoVendedor> _tipoVendedoresFiltrados = new ObservableCollection<TipoVendedor>();
+
+ 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<TipoVendedor> TipoVendedores
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<TipoVendedor> 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>((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<TipoVendedor, TipoVendedor>(this.TipoVendedores.First<TipoVendedor>((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id()), this.CancelTipoVendedor);
+ if (this.TipoVendedoresFiltrados.Count <= 0 || !this.TipoVendedoresFiltrados.Any<TipoVendedor>((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id()))
+ {
+ this.TipoVendedoresFiltrados.Add(this.CancelTipoVendedor);
+ }
+ else
+ {
+ DomainBase.Copy<TipoVendedor, TipoVendedor>(this.TipoVendedoresFiltrados.First<TipoVendedor>((TipoVendedor x) => x.get_Id() == this.CancelTipoVendedor.get_Id()), this.CancelTipoVendedor);
+ }
+ this.TipoVendedoresFiltrados = new ObservableCollection<TipoVendedor>(this.TipoVendedoresFiltrados);
+ this.SelectedTipoVendedor = this.TipoVendedoresFiltrados.First<TipoVendedor>((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<TipoVendedor>(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<TipoVendedor>(num) : this.TipoVendedoresFiltrados.Last<TipoVendedor>());
+ 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<List<TipoVendedor>> Filtrar(string value)
+ {
+ List<TipoVendedor> tipoVendedors = await Task.Run<List<TipoVendedor>>(() => this.FiltrarTipoVendedor(value));
+ return tipoVendedors;
+ }
+
+ public List<TipoVendedor> FiltrarTipoVendedor(string filter)
+ {
+ this.TipoVendedoresFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<TipoVendedor>(this.TipoVendedores) : new ObservableCollection<TipoVendedor>(
+ 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<TipoVendedor>();
+ return this.TipoVendedoresFiltrados.ToList<TipoVendedor>();
+ }
+
+ 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ object obj;
+ string str1;
+ List<KeyValuePair<string, string>> 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>((TipoVendedor x) => x.get_Id() == tipoVendedor.get_Id()))
+ {
+ this.TipoVendedores.Add(tipoVendedor);
+ }
+ else
+ {
+ DomainBase.Copy<TipoVendedor, TipoVendedor>(this.TipoVendedores.First<TipoVendedor>((TipoVendedor x) => x.get_Id() == tipoVendedor.get_Id()), tipoVendedor);
+ }
+ if (!this.TipoVendedoresFiltrados.Any<TipoVendedor>((TipoVendedor x) => x.get_Id() == tipoVendedor.get_Id()))
+ {
+ this.TipoVendedoresFiltrados.Add(tipoVendedor);
+ }
+ else
+ {
+ DomainBase.Copy<TipoVendedor, TipoVendedor>(this.TipoVendedoresFiltrados.First<TipoVendedor>((TipoVendedor x) => x.get_Id() == tipoVendedor.get_Id()), tipoVendedor);
+ }
+ this.TipoVendedoresFiltrados = new ObservableCollection<TipoVendedor>(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<TipoVendedor> tipoVendedors = await (new BaseServico()).BuscarTipoVendedoresAsync();
+ TipoVendedorViewModel list = this;
+ List<TipoVendedor> tipoVendedors1 = tipoVendedors;
+ IOrderedEnumerable<TipoVendedor> ativo =
+ from x in tipoVendedors1
+ orderby x.get_Ativo() descending
+ select x;
+ list.TipoVendedores = ativo.ThenBy<TipoVendedor, string>((TipoVendedor x) => x.get_Descricao()).ToList<TipoVendedor>();
+ this.TipoVendedoresFiltrados = new ObservableCollection<TipoVendedor>(this.TipoVendedores);
+ if (this.TipoVendedoresFiltrados.Count <= 0)
+ {
+ this.SelectedTipoVendedor = new TipoVendedor();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelecionaTipoVendedor(this.TipoVendedoresFiltrados.First<TipoVendedor>());
+ }
+ 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>((TipoVendedor x) => x.get_Id() == value.get_Id());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs
new file mode 100644
index 0000000..7f04040
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs
@@ -0,0 +1,826 @@
+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<Usuario> _usuariosFiltrados = new ObservableCollection<Usuario>();
+
+ private bool _isExpanded;
+
+ private bool _enableGrid = true;
+
+ private Visibility _horarioAcessoVisible;
+
+ private List<Empresa> _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<Empresa> 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<Gestor.Model.Domain.Seguros.PermissaoUsuario> 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<Usuario> Usuarios
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Usuario> 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<bool> 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<Usuario> usuarios = this.Usuarios;
+ IEnumerable<Usuario> administradorCentralSegurado1 =
+ from x in usuarios
+ where x.get_AdministradorCentralSegurado()
+ select x;
+ List<Usuario> list = (
+ from x in administradorCentralSegurado1
+ orderby x.get_Nome()
+ select x).ToList<Usuario>();
+ 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<Usuario>())
+ {
+ 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>((Usuario x) => x.get_Id() == num);
+ }
+ base.Alterar(false);
+ this.ConfirmaSenha = "";
+ }
+
+ private async Task CarregarUsuarios()
+ {
+ List<Usuario> usuarios = await (new BaseServico()).CarregarUsuarios();
+ UsuarioViewModel list = this;
+ List<Usuario> usuarios1 = usuarios;
+ IEnumerable<Usuario> usuarios2 = usuarios1.Where<Usuario>((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<Usuario>();
+ this.UsuariosFiltrados = new ObservableCollection<Usuario>(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<Usuario>())
+ {
+ this.SelectedUsuario = new Usuario();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault<Usuario>();
+ }
+ base.Loading(false);
+ base.ToggleSnackBar("USUÁRIO EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ internal async Task<List<Usuario>> Filtrar(string value)
+ {
+ List<Usuario> usuarios = await Task.Run<List<Usuario>>(() => this.FiltrarUsuario(value));
+ return usuarios;
+ }
+
+ public List<Usuario> FiltrarUsuario(string filter)
+ {
+ this.UsuariosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Usuario>(this.Usuarios) : new ObservableCollection<Usuario>(
+ 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<Usuario>();
+ }
+
+ 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> 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<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedUsuario.Validate();
+ List<KeyValuePair<string, string>> 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>((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<Usuario, Usuario>(this.UsuariosFiltrados.First<Usuario>((Usuario x) => x.get_Id() == usuario.get_Id()), usuario1);
+ }
+ this.SelectedUsuario = this.UsuariosFiltrados.First<Usuario>((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<Usuario>());
+ }
+ base.Loading(false);
+ this.EnableGrid = true;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<Usuario> usuarios;
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ 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<string, string>("ConfirmaSenha|CONFIRMAÇÃO SENHA", "OBRIGATÓRIO"));
+ }
+ else if (!string.Equals(this.ConfirmaSenha, str))
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("ConfirmaSenha|CONFIRMAÇÃO SENHA", "INVÁLIDO"));
+ }
+ }
+ if (string.IsNullOrWhiteSpace(this.SelectedUsuario.get_Login()))
+ {
+ usuarios = new List<Usuario>();
+ }
+ 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<string, string>("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<string, string>("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<string, string>("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<string, string>("Documento", "O DOCUMENTO JÁ ESTÁ SENDO USADO EM OUTRO USUÁRIO"));
+ }
+ List<KeyValuePair<string, string>> 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>((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/Codemerx/Gestor.Application/ViewModels/Ferramentas/VendedorViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/VendedorViewModel.cs
new file mode 100644
index 0000000..32b04c4
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/VendedorViewModel.cs
@@ -0,0 +1,913 @@
+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<Vendedor> _vendedoresFiltrados = new ObservableCollection<Vendedor>();
+
+ private bool _isExpanded;
+
+ private VendedorTelefone _selectedTelefone = new VendedorTelefone();
+
+ private ObservableCollection<VendedorTelefone> _telefones = new ObservableCollection<VendedorTelefone>();
+
+ private Repasse _selectedRepasse = new Repasse();
+
+ private ObservableCollection<Repasse> _repasses = new ObservableCollection<Repasse>();
+
+ private string _pesquisa;
+
+ private Visibility _mostrarRamo;
+
+ private ObservableCollection<Ramo> _ramos = new ObservableCollection<Ramo>();
+
+ private Visibility _visualizacaoPropriaCorretora { get; set; } = Visibility.Collapsed;
+
+ public bool CoCorretagemAtiva { get; set; } = Recursos.Configuracoes.Any<ConfiguracaoSistema>(new Func<ConfiguracaoSistema, bool>((//
+ // 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<Ramo> Ramos
+ {
+ get
+ {
+ return this._ramos;
+ }
+ set
+ {
+ this._ramos = value;
+ base.OnPropertyChanged("Ramos");
+ }
+ }
+
+ public ObservableCollection<Repasse> 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<VendedorTelefone> Telefones
+ {
+ get
+ {
+ return this._telefones;
+ }
+ set
+ {
+ this._telefones = value;
+ base.OnPropertyChanged("Telefones");
+ }
+ }
+
+ public List<TipoRepasse> TiposRepasseFiltrados
+ {
+ get
+ {
+ return Enum.GetValues(typeof(TipoRepasse)).Cast<TipoRepasse>().Where<TipoRepasse>((TipoRepasse tipo) => {
+ TipoAttribute tipoAttribute = (TipoAttribute)typeof(TipoRepasse).GetField(tipo.ToString()).GetCustomAttributes(typeof(TipoAttribute), false).FirstOrDefault<object>();
+ if (tipoAttribute == null || tipoAttribute.get_Tipo() == "0" || this.CoCorretagemAtiva)
+ {
+ return true;
+ }
+ TipoRepasse? nullable = this.SelectedRepasse.get_Tipo();
+ return tipo == nullable.GetValueOrDefault() & nullable.HasValue;
+ }).ToList<TipoRepasse>();
+ }
+ }
+
+ public List<Vendedor> Vendedores
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Vendedor> 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>((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<Repasse>());
+ 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>((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>((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>((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id()))
+ {
+ this.Incluir();
+ }
+ else
+ {
+ DomainBase.Copy<Vendedor, Vendedor>(this.Vendedores.First<Vendedor>((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id()), this.CancelVendedor);
+ if (this.VendedoresFiltrados.Count <= 0 || !this.VendedoresFiltrados.Any<Vendedor>((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id()))
+ {
+ this.VendedoresFiltrados.Add(this.CancelVendedor);
+ }
+ else
+ {
+ DomainBase.Copy<Vendedor, Vendedor>(this.VendedoresFiltrados.First<Vendedor>((Vendedor x) => x.get_Id() == this.CancelVendedor.get_Id()), this.CancelVendedor);
+ }
+ this.VendedoresFiltrados = new ObservableCollection<Vendedor>(this.VendedoresFiltrados);
+ this.SelectedVendedor = this.VendedoresFiltrados.First<Vendedor>((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<Repasse>((IEnumerable<!0>)await this._servico.BuscaRepassesPorIdVendedor(this.SelectedVendedor.get_Id()));
+ base.ToggleSnackBar("VINCULO EXCLUÍDO COM SUCESSO", true);
+ }
+ }
+
+ internal async Task<List<Vendedor>> Filtrar(string value)
+ {
+ List<Vendedor> vendedors = await Task.Run<List<Vendedor>>(() => this.FiltrarVendedor(value));
+ return vendedors;
+ }
+
+ public List<Vendedor> FiltrarVendedor(string filter)
+ {
+ this.VendedoresFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Vendedor>(this.Vendedores) : new ObservableCollection<Vendedor>(
+ 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<Vendedor>();
+ return this.VendedoresFiltrados.ToList<Vendedor>();
+ }
+
+ 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<VendedorTelefone>();
+ this.Repasses = new ObservableCollection<Repasse>();
+ base.Alterar(true);
+ }
+
+ public void IncluirRepasse()
+ {
+ if (this.SelectedVendedor == null)
+ {
+ return;
+ }
+ if (this.Repasses == null)
+ {
+ this.Repasses = new ObservableCollection<Repasse>();
+ }
+ 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<Ramo>());
+ 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 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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs1;
+ string str;
+ object nome;
+ object obj;
+ VendedorViewModel.u003cu003ec__DisplayClass55_0 variable;
+ List<Repasse> list;
+ string str1;
+ this.SelectedVendedor.set_Telefones(this.Telefones.ToList<VendedorTelefone>());
+ List<KeyValuePair<string, string>> keyValuePairs2 = this.SelectedVendedor.Validate();
+ List<KeyValuePair<string, string>> keyValuePairs3 = keyValuePairs2;
+ keyValuePairs3.AddRange(await this.Validate());
+ keyValuePairs3 = null;
+ if (keyValuePairs2.Count <= 0)
+ {
+ Vendedor selectedVendedor = this.SelectedVendedor;
+ ObservableCollection<VendedorTelefone> telefones = this.Telefones;
+ selectedVendedor.set_Telefones((
+ from x in telefones
+ where !string.IsNullOrEmpty(x.get_Nome())
+ select x).ToList<VendedorTelefone>());
+ List<Repasse> repasses = this.Repasses.ToList<Repasse>();
+ list = repasses.Where<Repasse>((Repasse x) => {
+ List<KeyValuePair<string, string>> keyValuePairs = x.Validate();
+ if (keyValuePairs == null)
+ {
+ return false;
+ }
+ return keyValuePairs.Count == 0;
+ }).ToList<Repasse>();
+ 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<Repasse>().ForEach((Repasse x) => keyValuePairs2.AddRange(x.Validate()));
+ keyValuePairs1 = keyValuePairs2;
+ variable = null;
+ list = null;
+ str1 = null;
+ return keyValuePairs1;
+ }
+ }
+ this.Repasses = new ObservableCollection<Repasse>(list);
+ str = (this.SelectedVendedor.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
+ str1 = str;
+ Vendedor vendedor = await this._servico.Save(this.SelectedVendedor, this.Repasses.ToList<Repasse>());
+ 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>((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>((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<Repasse>((IEnumerable<!0>)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<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
+ visibility = (configuracoes.All<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() != 20) ? Visibility.Collapsed : Visibility.Visible);
+ vendedorViewModel.MostrarRamo = visibility;
+ ObservableCollection<Ramo> ramos = this.Ramos;
+ Ramo ramo = new Ramo();
+ ramo.set_Nome("TODOS OS RAMOS");
+ ramos.Add(ramo);
+ List<Ramo> ramos1 = await (new BaseServico()).BuscarRamosAsync();
+ ObservableCollection<Ramo> observableCollection = this.Ramos;
+ List<Ramo> ramos2 = ramos1;
+ IEnumerable<Ramo> ativo =
+ from x in ramos2
+ where x.get_Ativo()
+ select x;
+ ExtensionMethods.AddRange<Ramo>(observableCollection,
+ from x in ativo
+ orderby x.get_Nome()
+ select x);
+ }
+
+ private async Task SelecionaVendedores(bool selecionar = true)
+ {
+ List<Vendedor> vendedors = await (new BaseServico()).BuscarVendedoresAsync();
+ VendedorViewModel list = this;
+ List<Vendedor> vendedors1 = vendedors;
+ IEnumerable<Vendedor> vendedors2 = vendedors1.Where<Vendedor>((Vendedor x) => {
+ if (Recursos.Usuario.get_IdEmpresa() == (long)1)
+ {
+ return true;
+ }
+ return x.get_IdEmpresa() == Recursos.Usuario.get_IdEmpresa();
+ });
+ IOrderedEnumerable<Vendedor> ativo =
+ from x in vendedors2
+ orderby x.get_Ativo() descending
+ select x;
+ list.Vendedores = ativo.ThenBy<Vendedor, string>((Vendedor x) => x.get_Nome()).ToList<Vendedor>();
+ this.VendedoresFiltrados = new ObservableCollection<Vendedor>(this.Vendedores);
+ if (selecionar)
+ {
+ this.SelectedVendedor = this.VendedoresFiltrados.FirstOrDefault<Vendedor>();
+ }
+ Recursos.Vendedores = vendedors;
+ }
+
+ private async Task<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<Vendedor> vendedors;
+ IEnumerable<Repasse> repasses;
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (!ValidationHelper.ValidateDocument(this.SelectedVendedor.get_Documento()))
+ {
+ vendedors = new List<Vendedor>();
+ }
+ else
+ {
+ vendedors = await (new BaseServico()).BuscarVendedor(this.SelectedVendedor.get_Documento());
+ }
+ Vendedor vendedor = vendedors.FirstOrDefault<Vendedor>((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<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
+ if (configuracoes.All<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() != 7))
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("Documento", string.Concat("O DOCUMENTO JÁ ESTÁ CADASTRADO PARA O VENDEDOR ", vendedor.get_Nome(), ".")));
+ }
+ }
+ List<ConfiguracaoSistema> configuracaoSistemas = Recursos.Configuracoes;
+ if (configuracaoSistemas.All<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() != 15))
+ {
+ ObservableCollection<Repasse> observableCollection = this.Repasses;
+ if (observableCollection != null)
+ {
+ repasses = observableCollection.Where<Repasse>((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<Repasse> repasses1 = repasses;
+ if (repasses1 != null && repasses1.Any<Repasse>())
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("VALOR REPASSE", "O VALOR DE REPASSE NÃO PODE SER SUPERIOR A 100%"));
+ }
+ }
+ ObservableCollection<Repasse> 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 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<string, string>("REPASSE", string.Format("O REPASSE, DE ID {0}, NÃO PODE SER ALTERADO POIS JÁ ESTÁ CADASTRADO EM ALGUM DOCUMENTO!", repasse1.get_Id())));
+ }
+ }
+ }
+ List<KeyValuePair<string, string>> 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<Repasse>((IEnumerable<!0>)await this._servico.BuscaRepassesPorIdVendedor(value.get_Id()));
+ this.Telefones = new ObservableCollection<VendedorTelefone>((IEnumerable<!0>)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>((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>((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