using Gestor.Application.Actions; using Gestor.Application.Drawers; 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.Application.Views.Generic; using Gestor.Application.Views.Seguros; 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.MalaDireta; using Gestor.Model.Domain.Seguros; using Gestor.Model.Helper; 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.Text; using System.Threading.Tasks; using System.Windows; namespace Gestor.Application.ViewModels.BI { public class TarefaBIViewModel : BaseTarefaViewModel { private bool _enableAlterarTarefa = true; private bool _administrador; private DateTime _inicio; private DateTime _fim; private List _status; private string _selectedStatus; private Visibility _isVisibleCliente; private Visibility _isVisibleApolice; private Visibility _isVisibleArquivoDigital; private Visibility _isVisibleSinistro; private ObservableCollection _usuariosFiltro; private ObservableCollection _usuarios; private ObservableCollection _tiposTarefa; private TipoDeTarefa _selectedTipoTarefa; private Usuario _selectedUsuarioFiltro; private Usuario _selectedUsuario; private DateTime _dataAgendamento; private DateTime _horaAgendamento; private bool _isAnotacoes; private string _descricao; private string _historicoInterno; private ObservableCollection _tarefas; private Tarefa _selectedTarefa; private ObservableCollection _telefones; private long _cancelTarefa; private ObservableCollection _tarefasFiltradas; private string _filtro; private ObservableCollection _filtroTarefa; private GridLength _columnUsuarioPrincipal; private GridLength _columnUsuarios; public bool Administrador { get { return this._administrador; } set { this._administrador = value; base.OnPropertyChanged("Administrador"); } } private Gestor.Application.Servicos.Seguros.ClienteServico ClienteServico { get; } public GridLength ColumnUsuarioPrincipal { get { return this._columnUsuarioPrincipal; } set { this._columnUsuarioPrincipal = value; base.OnPropertyChanged("ColumnUsuarioPrincipal"); } } public GridLength ColumnUsuarios { get { return this._columnUsuarios; } set { this._columnUsuarios = value; base.OnPropertyChanged("ColumnUsuarios"); } } public DateTime DataAgendamento { get { return this._dataAgendamento; } set { this._dataAgendamento = value; if (this.SelectedTarefa != null) { this.SelectedTarefa.set_Agendamento(DateTime.Parse(string.Format("{0:d} {1:T}", value, this.SelectedTarefa.get_Agendamento()))); } base.OnPropertyChanged("DataAgendamento"); } } public string Descricao { get { return this._descricao; } set { this._descricao = value; base.OnPropertyChanged("Descricao"); } } public override bool EnableAlterarTarefa { get { return this._enableAlterarTarefa; } set { this._enableAlterarTarefa = this._alterarPermissEnabled & value; base.OnPropertyChanged("EnableAlterarTarefa"); } } public string Filtro { get { return this._filtro; } set { this._filtro = value; base.OnPropertyChanged("Filtro"); } } public ObservableCollection FiltroTarefa { get { return this._filtroTarefa; } set { this._filtroTarefa = value; base.OnPropertyChanged("FiltroTarefa"); } } public DateTime Fim { get { return this._fim; } set { this._fim = value; this.CarregaTarefas(false); base.OnPropertyChanged("Fim"); } } public string HistoricoInterno { get { return this._historicoInterno; } set { this._historicoInterno = value; base.OnPropertyChanged("HistoricoInterno"); } } public DateTime HoraAgendamento { get { return this._horaAgendamento; } set { this._horaAgendamento = value; if (this.SelectedTarefa != null) { this.SelectedTarefa.set_Agendamento(DateTime.Parse(string.Format("{0:d} {1:T}", this.SelectedTarefa.get_Agendamento(), value))); } base.OnPropertyChanged("HoraAgendamento"); } } public DateTime Inicio { get { return this._inicio; } set { this._inicio = value; this.CarregaTarefas(false); base.OnPropertyChanged("Inicio"); } } public bool IsAnotacoes { get { return this._isAnotacoes; } set { this._isAnotacoes = value; base.OnPropertyChanged("IsAnotacoes"); } } public Visibility IsVisibleApolice { get { return this._isVisibleApolice; } set { this._isVisibleApolice = value; base.OnPropertyChanged("IsVisibleApolice"); } } public Visibility IsVisibleArquivoDigital { get { return this._isVisibleArquivoDigital; } set { this._isVisibleArquivoDigital = value; base.OnPropertyChanged("IsVisibleArquivoDigital"); } } public Visibility IsVisibleCliente { get { return this._isVisibleCliente; } set { this._isVisibleCliente = value; base.OnPropertyChanged("IsVisibleCliente"); } } public Visibility IsVisibleSinistro { get { return this._isVisibleSinistro; } set { this._isVisibleSinistro = value; base.OnPropertyChanged("IsVisibleSinistro"); } } public string SelectedStatus { get { return this._selectedStatus; } set { this._selectedStatus = value; this.CarregaTarefas(false); base.OnPropertyChanged("SelectedStatus"); } } public override Tarefa SelectedTarefa { get { return this._selectedTarefa; } set { long? nullable; this._cancelTarefa = (value != null ? value.get_Id() : (long)0); this.WorkOnSelectedTarefa(value); if (value != null) { nullable = new long?(value.get_Id()); } else { nullable = null; } base.VerificarEnables(nullable); this._selectedTarefa = value; base.ValidaPermissaoParaEditarTarefa(); base.OnPropertyChanged("SelectedTarefa"); } } public TipoDeTarefa SelectedTipoTarefa { get { return this._selectedTipoTarefa; } set { this._selectedTipoTarefa = value; base.OnPropertyChanged("SelectedTipoTarefa"); } } public Usuario SelectedUsuario { get { return this._selectedUsuario; } set { this._selectedUsuario = value; base.OnPropertyChanged("SelectedUsuario"); } } public Usuario SelectedUsuarioFiltro { get { return this._selectedUsuarioFiltro; } set { this._selectedUsuarioFiltro = value; this.CarregaTarefas(false); base.OnPropertyChanged("SelectedUsuarioFiltro"); } } private new TarefaServico Servico { get; } public List Status { get { return this._status; } set { this._status = value; this.CarregaTarefas(false); base.OnPropertyChanged("Status"); } } public ObservableCollection Tarefas { get { return this._tarefas; } set { this._tarefas = value; base.OnPropertyChanged("Tarefas"); } } public ObservableCollection TarefasFiltradas { get { return this._tarefasFiltradas; } set { this._tarefasFiltradas = value; base.IsVisible = (value.Count > 0 ? Visibility.Visible : Visibility.Collapsed); base.OnPropertyChanged("TarefasFiltradas"); } } public ObservableCollection Telefones { get { return this._telefones; } set { this._telefones = value; base.OnPropertyChanged("Telefones"); } } public ObservableCollection TiposTarefa { get { return this._tiposTarefa; } set { this._tiposTarefa = value; base.OnPropertyChanged("TiposTarefa"); } } public ObservableCollection Usuarios { get { return this._usuarios; } set { this._usuarios = value; base.OnPropertyChanged("Usuarios"); } } public ObservableCollection UsuariosFiltro { get { return this._usuariosFiltro; } set { this._usuariosFiltro = value; base.OnPropertyChanged("UsuariosFiltro"); } } public TarefaBIViewModel() { this._enableAlterarTarefa = true; DateTime date = Funcoes.GetNetworkTime().Date; this._inicio = date.AddDays(-4); date = Funcoes.GetNetworkTime().Date; this._fim = date.AddDays(4); this._status = new List() { "TODAS AS TAREFAS", Gestor.Common.Validation.ValidationHelper.GetDescription((StatusTarefa)0), Gestor.Common.Validation.ValidationHelper.GetDescription((StatusTarefa)2) }; this._isVisibleCliente = Visibility.Collapsed; this._isVisibleApolice = Visibility.Collapsed; this._isVisibleArquivoDigital = Visibility.Collapsed; this._isVisibleSinistro = Visibility.Collapsed; this._selectedUsuarioFiltro = new Usuario(); this._selectedUsuario = new Usuario(); this._dataAgendamento = Funcoes.GetNetworkTime(); this._horaAgendamento = Funcoes.GetNetworkTime(); this._isAnotacoes = true; this._descricao = ""; this._historicoInterno = ""; this._tarefasFiltradas = new ObservableCollection(); this._filtro = ""; this._filtroTarefa = new ObservableCollection(); this._columnUsuarioPrincipal = new GridLength(1, GridUnitType.Star); this._columnUsuarios = new GridLength(0, GridUnitType.Pixel); base(); this.Servico = new TarefaServico(); this.ClienteServico = new Gestor.Application.Servicos.Seguros.ClienteServico(); this.Administrador = (Recursos.Usuario.get_Id() == 0 ? true : Recursos.Usuario.get_Administrador()); this.CarregarUsuarios(); List list = Recursos.Usuarios.Where((Usuario x) => { if (!Recursos.Configuracoes.Any((ConfiguracaoSistema c) => c.get_Configuracao() == 36) && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa()) { return false; } return !x.get_Excluido(); }).OrderBy((Usuario x) => x.get_Nome()).ToList(); Usuario usuario = new Usuario(); usuario.set_Nome("TODOS OS USUÁRIOS"); usuario.set_Id((long)0); list.Insert(0, usuario); this.UsuariosFiltro = new ObservableCollection(list); this.TiposTarefa = new ObservableCollection(( from x in Recursos.TiposTarefa where x.get_Ativo() select x).ToList()); this.SelectedUsuarioFiltro = this.UsuariosFiltro.FirstOrDefault((Usuario x) => x.get_Id() == Recursos.Usuario.get_Id()) ?? this.UsuariosFiltro.FirstOrDefault(); this.SelectedStatus = this.Status[1]; this.CarregaTarefas(true); } public async void Abrir(TipoTarefa tipo) { double? nullable; long? nullable1; long? nullable2; switch (tipo) { case 0: { long idEntidade = this.SelectedTarefa.get_IdEntidade(); if (this.SelectedTarefa.get_Entidade() == 4) { Sinistro sinistro = await base.CarregaSinistroApolice(this.SelectedTarefa.get_IdEntidade()); if (sinistro != null) { ControleSinistro controleSinistro = sinistro.get_ControleSinistro(); if (controleSinistro != null) { Item item = controleSinistro.get_Item(); if (item != null) { Documento documento = item.get_Documento(); if (documento != null) { nullable2 = new long?(documento.get_Id()); } else { nullable1 = null; nullable2 = nullable1; } } else { nullable1 = null; nullable2 = nullable1; } } else { nullable1 = null; nullable2 = nullable1; } } else { nullable1 = null; nullable2 = nullable1; } nullable1 = nullable2; idEntidade = nullable1.GetValueOrDefault(); } if (idEntidade != 0) { nullable = null; double? nullable3 = nullable; nullable = null; (new HosterWindow(new ApoliceView(await base.CarregaApolice(idEntidade), true, false, 0, (long)0, false), string.Concat("CADASTRO DE APÓLICES - ", this.SelectedTarefa.get_Cliente()), nullable3, nullable, false)).Show(); goto case 1; } else { break; } } case 1: { break; } case 2: { nullable = null; double? nullable4 = nullable; nullable = null; (new HosterWindow(new ClienteView(await base.CarregaCliente(this.SelectedTarefa.get_IdCliente()), true, null), string.Concat("CADASTRO DE CLIENTES - ", this.SelectedTarefa.get_Cliente()), nullable4, nullable, false)).Show(); goto case 1; } case 3: { nullable = null; double? nullable5 = nullable; nullable = null; (new HosterWindow(new ApoliceView(await base.CarregaApoliceParcela(this.SelectedTarefa.get_IdEntidade()), true, false, 0, (long)0, false), string.Concat("CADASTRO DE APÓLICES - ", this.SelectedTarefa.get_Cliente(), " - ", this.SelectedTarefa.get_Referencia()), nullable5, nullable, false)).Show(); goto case 1; } case 4: { Sinistro sinistro1 = await base.CarregaSinistroApolice(this.SelectedTarefa.get_IdEntidade()); if (sinistro1 != null) { nullable = null; double? nullable6 = nullable; nullable = null; (new HosterWindow(new SinistroView(sinistro1.get_ControleSinistro().get_Item(), false), string.Concat("CADASTRO DE SINISTROS - ", this.SelectedTarefa.get_Cliente(), " - ", this.SelectedTarefa.get_Referencia()), nullable6, nullable, false)).Show(); goto case 1; } else { await base.ShowMessage("SINISTRO NÃO ENCONTRADO!", "OK", "", false); break; } } default: { goto case 1; } } } public async void AbrirArquivoDigital() { FiltroArquivoDigital filtroArquivoDigital; if (this.SelectedTarefa.get_IdEntidade() != 0) { filtroArquivoDigital = new FiltroArquivoDigital(); switch (this.SelectedTarefa.get_Entidade()) { case 0: { if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 2).get_Consultar()) { Documento documento = await base.CarregaApolice(this.SelectedTarefa.get_IdEntidade()); filtroArquivoDigital.set_Id(documento.get_Id()); filtroArquivoDigital.set_Tipo(2); filtroArquivoDigital.set_Parente(documento); goto case 7; } else { await base.ShowMessage(string.Concat("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR\nARQUIVO DIGITAL DE ", Gestor.Common.Validation.ValidationHelper.GetDescription((TipoArquivoDigital)2), "."), "OK", "", false); break; } } case 1: case 6: case 7: { base.ShowDrawer(new ArquivoDigitalDrawer(filtroArquivoDigital), 0, false); break; } case 2: { if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 1).get_Consultar()) { Cliente cliente = await base.CarregaCliente(this.SelectedTarefa.get_IdCliente()); filtroArquivoDigital.set_Id(cliente.get_Id()); filtroArquivoDigital.set_Tipo(1); filtroArquivoDigital.set_Parente(cliente); goto case 7; } else { await base.ShowMessage(string.Concat("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR\nARQUIVO DIGITAL DE ", Gestor.Common.Validation.ValidationHelper.GetDescription((TipoArquivoDigital)1), "."), "OK", "", false); break; } } case 3: { if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 3).get_Consultar()) { Parcela parcela = await base.CarregaParcela(this.SelectedTarefa.get_IdEntidade()); filtroArquivoDigital.set_Id(parcela.get_Id()); filtroArquivoDigital.set_Tipo(3); filtroArquivoDigital.set_Parente(parcela); filtroArquivoDigital.set_IdApolice(parcela.get_Documento().get_Id()); goto case 7; } else { await base.ShowMessage(string.Concat("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR\nARQUIVO DIGITAL DE ", Gestor.Common.Validation.ValidationHelper.GetDescription((TipoArquivoDigital)3), "."), "OK", "", false); break; } } case 4: { if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 5).get_Consultar()) { Sinistro sinistro = await base.CarregaSinistroApolice(this.SelectedTarefa.get_IdEntidade()); filtroArquivoDigital.set_Id(sinistro.get_Id()); filtroArquivoDigital.set_Tipo(5); filtroArquivoDigital.set_Parente(sinistro); filtroArquivoDigital.set_IdApolice(sinistro.get_ControleSinistro().get_Item().get_Documento().get_Id()); goto case 7; } else { await base.ShowMessage(string.Concat("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR\nARQUIVO DIGITAL DE ", Gestor.Common.Validation.ValidationHelper.GetDescription((TipoArquivoDigital)5), "."), "OK", "", false); break; } } case 5: { if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 11).get_Consultar()) { Prospeccao prospeccao = await base.CarregarProspeccao(this.SelectedTarefa.get_IdEntidade()); filtroArquivoDigital.set_Id(prospeccao.get_Id()); filtroArquivoDigital.set_Tipo(11); filtroArquivoDigital.set_Parente(prospeccao); goto case 7; } else { await base.ShowMessage(string.Concat("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR\nARQUIVO DIGITAL DE ", Gestor.Common.Validation.ValidationHelper.GetDescription((TipoArquivoDigital)11), "."), "OK", "", false); break; } } case 8: { break; } default: { goto case 7; } } } filtroArquivoDigital = null; } public void AdcionarFiltro() { if (string.IsNullOrEmpty(this.Filtro)) { return; } if (this.FiltroTarefa == null) { this.FiltroTarefa = new ObservableCollection(); } this.FiltroTarefa.Add(this.Filtro); this.Filtro = string.Empty; this.FiltrarTarefa(); } public async Task AdcionarResponsavel() { if (!await base.ValidaPermissaoParaEditarTarefa()) { await base.ShowMessage("VOCÊ NÃO TEM PERMISSÃO PARA EXCLUIR ESSA TAREFA!", "OK", "", false); } else if (this.SelectedUsuario != null) { ObservableCollection responsaveis = base.Responsaveis; ResponsavelTarefa responsavelTarefa = new ResponsavelTarefa(); responsavelTarefa.set_Usuario(this.SelectedUsuario); responsavelTarefa.set_IdTarefa(this.SelectedTarefa.get_Id()); responsaveis.Add(responsavelTarefa); this.Usuarios.Remove(this.SelectedUsuario); this.SelectedUsuario = null; } } public async Task AlterarTarefa() { GridLength gridLength; GridLength gridLength1; if (this.SelectedTarefa != null) { if (await base.ValidaPermissaoParaEditarTarefa()) { this.CarregarUsuarios(); base.Alterar(true); TarefaBIViewModel tarefaBIViewModel = this; gridLength = (base.EnableFields ? new GridLength(0, GridUnitType.Pixel) : new GridLength(1, GridUnitType.Star)); tarefaBIViewModel.ColumnUsuarioPrincipal = gridLength; TarefaBIViewModel tarefaBIViewModel1 = this; gridLength1 = (base.EnableFields ? new GridLength(1, GridUnitType.Star) : new GridLength(0, GridUnitType.Pixel)); tarefaBIViewModel1.ColumnUsuarios = gridLength1; base.ListaUsuariosResponsaveis(); base.HasResponsaveis = true; this.SelectedUsuario = null; base.Responsaveis.ToList().ForEach((ResponsavelTarefa x) => this.Usuarios.Remove(this.Usuarios.FirstOrDefault((Usuario u) => u.get_Id() == x.get_Usuario().get_Id()))); } else { await base.ShowMessage("VOCÊ NÃO TEM PERMISSÃO PARA EXCLUIR ESSA TAREFA!", "OK", "", false); } } } public async Task Cancelar() { if (this._cancelTarefa != 0) { long num = this._cancelTarefa; await this.CarregarTarefas(); this.SelectedTarefa = this.TarefasFiltradas.FirstOrDefault((Tarefa x) => x.get_Id() == num); base.Alterar(false); } } public async Task CarregarTarefas() { long id; bool? nullable; this.ColumnUsuarioPrincipal = new GridLength(1, GridUnitType.Star); this.ColumnUsuarios = new GridLength(0, GridUnitType.Pixel); this.Filtro = string.Empty; TarefaServico servico = this.Servico; Usuario selectedUsuarioFiltro = this.SelectedUsuarioFiltro; if (selectedUsuarioFiltro != null) { id = selectedUsuarioFiltro.get_Id(); } else { id = (long)0; } DateTime inicio = this.Inicio; DateTime fim = this.Fim; if (this.SelectedStatus == "TODAS AS TAREFAS") { nullable = null; } else { nullable = new bool?(this.SelectedStatus != "PENDENTE"); } List tarefas = await servico.BuscarTarefas(id, inicio, fim, nullable); TarefaBIViewModel observableCollection = this; List tarefas1 = tarefas; IEnumerable entidade = from x in tarefas1 where x.get_Entidade() != 1 select x; observableCollection.Tarefas = new ObservableCollection( from x in entidade orderby x.get_Agendamento() select x); this.TarefasFiltradas = this.Tarefas; this.SelectedTarefa = this.TarefasFiltradas.FirstOrDefault(); if (this.FiltroTarefa.Count > 0) { this.FiltrarTarefa(); } } private void CarregarUsuarios() { this.Usuarios = new ObservableCollection(Recursos.Usuarios.Where((Usuario x) => { if (!Recursos.Configuracoes.Any((ConfiguracaoSistema c) => c.get_Configuracao() == 36) && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa()) { return false; } return !x.get_Excluido(); }).OrderBy((Usuario x) => x.get_Nome()).ToList()); } public async void CarregaTarefas(bool permissoes = false) { if (permissoes) { await base.PermissaoTela(38); base.Alterar(false); } await this.CarregarTarefas(); } public async Task ConcluirTarefa(Tarefa tarefa) { Tarefa tarefa1; if (await base.ValidaPermissaoParaEditarTarefa()) { tarefa1 = await this.Servico.Salvar(tarefa); } else { await base.ShowMessage("VOCÊ NÃO TEM PERMISSÃO PARA EDITAR ESSA TAREFA!", "OK", "", false); tarefa1 = null; } return tarefa1; } public async Task CriarMalaDireta(TipoTarefa tipo) { MalaDireta malaDiretum; switch (tipo) { case 0: { Documento documento = await base.CarregaApolice(this.SelectedTarefa.get_IdEntidade()); MalaDireta malaDiretum1 = new MalaDireta(); malaDiretum1.set_Cliente(documento.get_Controle().get_Cliente()); malaDiretum1.set_Apolice(documento); malaDiretum1.set_Tela(2); malaDiretum = malaDiretum1; break; } case 1: case 6: case 7: { malaDiretum = null; break; } case 2: { Cliente cliente = await base.CarregaCliente(this.SelectedTarefa.get_IdCliente()); MalaDireta malaDiretum2 = new MalaDireta(); malaDiretum2.set_Cliente(cliente); malaDiretum2.set_Tela(1); malaDiretum = malaDiretum2; break; } case 3: { Documento documento1 = await base.CarregaApoliceParcela(this.SelectedTarefa.get_IdEntidade()); MalaDireta malaDiretum3 = new MalaDireta(); malaDiretum3.set_Cliente(documento1.get_Controle().get_Cliente()); malaDiretum3.set_Apolice(documento1); malaDiretum3.set_Tela(5); malaDiretum = malaDiretum3; break; } case 4: { Sinistro sinistro = await base.CarregaSinistroApolice(this.SelectedTarefa.get_IdEntidade()); MalaDireta malaDiretum4 = new MalaDireta(); malaDiretum4.set_Cliente(sinistro.get_ControleSinistro().get_Item().get_Documento().get_Controle().get_Cliente()); malaDiretum4.set_Apolice(sinistro.get_ControleSinistro().get_Item().get_Documento()); malaDiretum4.set_Sinistro(sinistro); malaDiretum4.set_Tela(7); malaDiretum = malaDiretum4; break; } case 5: { Prospeccao prospeccao = await base.CarregarProspeccao(this.SelectedTarefa.get_IdEntidade()); MalaDireta malaDiretum5 = new MalaDireta(); malaDiretum5.set_Prospeccao(prospeccao); malaDiretum5.set_Tela(33); malaDiretum = malaDiretum5; break; } case 8: { malaDiretum = null; break; } default: { goto case 7; } } return malaDiretum; } public async Task Excluir() { bool id; string titulo; Tarefa selectedTarefa = this.SelectedTarefa; if (selectedTarefa != null) { id = selectedTarefa.get_Id() == (long)0; } else { id = false; } if (!id) { TarefaBIViewModel tarefaBIViewModel = this; string[] newLine = new string[] { "DESEJA REALMENTE EXCLUIR A TAREFA ", null, null, null, null }; Tarefa tarefa = this.SelectedTarefa; if (tarefa != null) { titulo = tarefa.get_Titulo(); } else { titulo = null; } newLine[1] = titulo; newLine[2] = "?"; newLine[3] = Environment.NewLine; newLine[4] = "ESSE PROCEDIMENTO É IRREVERSÍVEL"; if (await tarefaBIViewModel.ShowMessage(string.Concat(newLine), "SIM", "NÃO", false)) { if (await this.Servico.Excluir(this.SelectedTarefa.get_Id())) { await this.CarregarTarefas(); Action atualizaTrilhas = Gestor.Application.Actions.Actions.AtualizaTrilhas; if (atualizaTrilhas != null) { atualizaTrilhas(); } else { } base.Alterar(false); } else { base.Alterar(false); } } } } public void ExcluirFiltro(string filtro) { this.FiltroTarefa.Remove(filtro); this.FiltrarTarefa(); } private List Filtrar() { List list = this.Tarefas.ToList(); this.FiltroTarefa.ToList().ForEach((string f) => list = list.Where((Tarefa x) => { if (Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Titulo()).ToUpper().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(f)) || Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Cliente()).ToUpper().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(f)) || Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Referencia()).ToUpper().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(f)) || x.get_Agendamento().ToString("d").ToUpper().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(f)) || x.get_Id().ToString().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(f)) || x.get_TipoDeTarefa() != null && Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_TipoDeTarefa().get_Nome()).ToUpper().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(f))) { return true; } if (x.get_Usuario() == null) { return false; } return x.get_Usuario().get_Nome().ToUpper().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(f)); }).ToList()); return list; } public void FiltrarTarefa() { this.TarefasFiltradas = new ObservableCollection(this.Filtrar()); this.SelectedTarefa = this.TarefasFiltradas.FirstOrDefault(); } public string GerarHtml() { string nome; string str = " TAREFA
"; str = string.Concat(str, "
"); str = string.Concat(str, "

"); str = string.Concat(str, "TAREFA


"); str = string.Concat(str, ""); int num = 0; string[] cliente = new string[] { str, ""; str = string.Concat(cliente); string[] referencia = new string[] { str, ""; str = string.Concat(referencia); string[] titulo = new string[] { str, ""; str = string.Concat(titulo); string[] strArrays = new string[] { str, ""; str = string.Concat(strArrays); string[] nome1 = new string[] { str, ""; str = string.Concat(nome1); string[] description = new string[] { str, ""; str = string.Concat(description); string[] strArrays1 = new string[] { str, ""; str = string.Concat(strArrays1); str = string.Concat(str, "

CLIENTE: "; cliente[4] = this.SelectedTarefa.get_Cliente(); cliente[5] = "

REFERÊNCIA: "; referencia[4] = this.SelectedTarefa.get_Referencia(); referencia[5] = "

TÍTULO: "; titulo[4] = this.SelectedTarefa.get_Titulo(); titulo[5] = "

AGENDAMENTO: "; DateTime agendamento = this.SelectedTarefa.get_Agendamento(); strArrays[4] = agendamento.ToString(); strArrays[5] = "

RESPONSÁVEL PRINCIPAL: "; nome1[4] = this.SelectedTarefa.get_Usuario().get_Nome(); nome1[5] = "

STATUS: "; description[4] = Gestor.Common.Validation.ValidationHelper.GetDescription(this.SelectedTarefa.get_Status()); description[5] = "

TIPO DE TAREFA: "; TipoDeTarefa selectedTipoTarefa = this.SelectedTipoTarefa; if (selectedTipoTarefa != null) { nome = selectedTipoTarefa.get_Nome(); } else { nome = null; } strArrays1[4] = nome; strArrays1[5] = "

"); if (base.Responsaveis != null && base.Responsaveis.Count > 0) { str = string.Concat(str, "

RESPONSÁVEIS VINCULADOS

"); str = string.Concat(str, "
"); str = string.Concat(str, ""); List strs = new List(); foreach (ResponsavelTarefa responsavei in base.Responsaveis) { strs.Add(responsavei.get_Usuario().get_Nome().Trim().ToUpper()); } str = string.Concat(str, ""); str = string.Concat(str, "

", string.Join(", ", strs), "

"); str = string.Concat(str, "

"); } str = string.Concat(str, "

"); if (this.SelectedTarefa.get_Descricao() != null) { str = string.Concat(str, "

ANOTAÇÕES

"); str = string.Concat(str, "
"); str = string.Concat(str, ""); str = string.Concat(str, ""); str = string.Concat(str, "

", this.SelectedTarefa.get_Descricao().Replace("", "").Replace("", ""), "

"); str = string.Concat(str, "

"); } str = string.Concat(str, "
"); return str; } public void Print() { string str = this.GerarHtml(); string tempPath = Path.GetTempPath(); string str1 = string.Format("{0}{1}_{2:ddMMyyyyhhmmss}.html", tempPath, (TipoTela)38, Funcoes.GetNetworkTime()); StreamWriter streamWriter = new StreamWriter(str1, true, Encoding.UTF8); streamWriter.Write(str); streamWriter.Close(); Process.Start(str1); } public async Task>> Salvar(string titulo) { List> keyValuePairs; Usuario usuario; string str; if (this.SelectedTarefa != null) { DateTime networkTime = Funcoes.GetNetworkTime(); List configuracoes = Recursos.Configuracoes; if (configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 45) && this.SelectedTarefa.get_Status() != 2 && this.SelectedTarefa.get_Agendamento() < networkTime) { this.SelectedTarefa.set_Agendamento(networkTime); } if (this.SelectedTarefa.get_Status() == 2) { this.SelectedTarefa.set_Conclusao(new DateTime?(networkTime)); } this.SelectedTarefa.set_Responsaveis(base.Responsaveis.ToList()); Tarefa selectedTarefa = this.SelectedTarefa; ResponsavelTarefa responsavelTarefa = base.Responsaveis.FirstOrDefault(); if (responsavelTarefa != null) { usuario = responsavelTarefa.get_Usuario(); } else { usuario = null; } selectedTarefa.set_Usuario(usuario); Tarefa tarefa = this.SelectedTarefa; List configuracaoSistemas = Recursos.Configuracoes; tarefa.set_AgendamentoRetroativo(configuracaoSistemas.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 45)); List> keyValuePairs1 = this.SelectedTarefa.Validate(); string text = Funcoes.GetText(this.SelectedTarefa.get_Anotacoes()); string text1 = Funcoes.GetText(this.SelectedTarefa.get_AnotacoesInternas()); if (string.IsNullOrEmpty(text) && string.IsNullOrEmpty(text1)) { keyValuePairs1.Add(new KeyValuePair("Anotações", "OBRIGATÓRIO")); } if (keyValuePairs1.Count <= 0) { this.SelectedTarefa.set_Anotacoes(Funcoes.AdicionarLog(this.SelectedTarefa.get_Anotacoes())); this.SelectedTarefa.set_Descricao(string.Concat(this.SelectedTarefa.get_Anotacoes(), "

", this.Descricao, "

")); Tarefa selectedTarefa1 = this.SelectedTarefa; str = (string.IsNullOrWhiteSpace(this.SelectedTarefa.get_AnotacoesInternas()) ? this.HistoricoInterno : string.Concat(this.SelectedTarefa.get_AnotacoesInternas(), "

", this.HistoricoInterno, "

")); selectedTarefa1.set_DescricaoInterna(str); this.SelectedTarefa.set_TipoDeTarefa(this.SelectedTipoTarefa); this.SelectedTarefa.set_Titulo(titulo); this.SelectedTarefa = await this.Servico.Salvar(this.SelectedTarefa); if (this.Servico.Sucesso) { long id = this.SelectedTarefa.get_Id(); await this.CarregarTarefas(); TarefaBIViewModel tarefaBIViewModel = this; Tarefa tarefa1 = this.TarefasFiltradas.FirstOrDefault((Tarefa x) => x.get_Id() == id); if (tarefa1 == null) { tarefa1 = this.TarefasFiltradas.FirstOrDefault(); } tarefaBIViewModel.SelectedTarefa = tarefa1; keyValuePairs = null; } else { keyValuePairs = null; } } else { keyValuePairs = keyValuePairs1; } } else { keyValuePairs = null; } return keyValuePairs; } private async void WorkOnSelectedTarefa(Tarefa value) { Usuario usuario; ObservableCollection observableCollection; TipoTelefone tipoTelefone; TipoTelefone tipoTelefone1; bool flag; ObservableCollection observableCollection1; if (value != null) { TarefaBIViewModel tarefaBIViewModel = this; if (value.get_Usuario() != null) { usuario = this.Usuarios.FirstOrDefault((Usuario x) => x.get_Id() == value.get_Usuario().get_Id()); } else { usuario = null; } tarefaBIViewModel.SelectedUsuario = usuario; this.DataAgendamento = value.get_Agendamento(); this.HoraAgendamento = value.get_Agendamento(); this.Descricao = value.get_Descricao(); this.HistoricoInterno = value.get_DescricaoInterna(); TarefaBIViewModel tarefaBIViewModel1 = this; if (value == null) { observableCollection = new ObservableCollection(); } else { observableCollection = (value.get_Responsaveis() == null ? new ObservableCollection() : new ObservableCollection(value.get_Responsaveis())); } tarefaBIViewModel1.Responsaveis = observableCollection; if (!base.Responsaveis.Any()) { TarefaBIViewModel tarefaBIViewModel2 = this; Tarefa tarefa = value; if (tarefa != null) { flag = tarefa.get_Usuario(); } else { flag = false; } if (!flag) { observableCollection1 = new ObservableCollection(); } else { ResponsavelTarefa[] responsavelTarefaArray = new ResponsavelTarefa[1]; ResponsavelTarefa responsavelTarefa = new ResponsavelTarefa(); responsavelTarefa.set_Usuario(value.get_Usuario()); responsavelTarefaArray[0] = responsavelTarefa; observableCollection1 = new ObservableCollection(responsavelTarefaArray); } tarefaBIViewModel2.Responsaveis = observableCollection1; } if (value.get_TipoDeTarefa() != null) { if (!this.TiposTarefa.All((TipoDeTarefa x) => x.get_Id() != value.get_Id()) || value.get_TipoDeTarefa().get_Ativo()) { TarefaBIViewModel observableCollection2 = this; ObservableCollection tiposTarefa = this.TiposTarefa; observableCollection2.TiposTarefa = new ObservableCollection(( from x in tiposTarefa where x.get_Ativo() select x).ToList()); } else { this.TiposTarefa.Add(value.get_TipoDeTarefa()); } } this.SelectedTipoTarefa = value.get_TipoDeTarefa(); this.IsVisibleCliente = Visibility.Collapsed; this.IsVisibleApolice = Visibility.Collapsed; this.IsVisibleSinistro = Visibility.Collapsed; this.IsVisibleArquivoDigital = Visibility.Collapsed; TipoTarefa entidade = value.get_Entidade(); switch (entidade) { case 0: case 3: { this.IsVisibleCliente = Visibility.Visible; this.IsVisibleApolice = Visibility.Visible; this.IsVisibleArquivoDigital = Visibility.Visible; goto case 1; } case 1: { entidade = value.get_Entidade(); if (entidade == 5) { Prospeccao prospeccao = await (new ProspeccaoServico()).BuscarProspeccao(value.get_IdEntidade()); this.Telefones = new ObservableCollection(); if (prospeccao != null && prospeccao.get_Telefone1() != null) { ObservableCollection telefones = this.Telefones; TelefoneBase telefoneBase1 = new TelefoneBase(); tipoTelefone1 = (prospeccao.get_Telefone1().StartsWith("9") ? 3 : 7); telefoneBase1.set_Tipo(new TipoTelefone?(tipoTelefone1)); telefoneBase1.set_Numero(prospeccao.get_Telefone1()); telefoneBase1.set_Prefixo(prospeccao.get_Prefixo1()); telefones.Add(telefoneBase1); } if (prospeccao != null && prospeccao.get_Telefone2() != null) { ObservableCollection telefones1 = this.Telefones; TelefoneBase telefoneBase2 = new TelefoneBase(); tipoTelefone = (prospeccao.get_Telefone2().StartsWith("9") ? 3 : 7); telefoneBase2.set_Tipo(new TipoTelefone?(tipoTelefone)); telefoneBase2.set_Numero(prospeccao.get_Telefone2()); telefoneBase2.set_Prefixo(prospeccao.get_Prefixo2()); telefones1.Add(telefoneBase2); } } else if (entidade == 8) { this.Telefones = new ObservableCollection(); } else { ObservableCollection observableCollection3 = await this.ClienteServico.BuscarTelefonesAsync(value.get_IdCliente()); TarefaBIViewModel tarefaBIViewModel3 = this; ObservableCollection observableCollection4 = observableCollection3; IEnumerable clienteTelefones = from x in observableCollection4 where Gestor.Model.Helper.ValidationHelper.ValidacaoTelefone(x.get_Numero()) select x; tarefaBIViewModel3.Telefones = new ObservableCollection(clienteTelefones.Select((ClienteTelefone x) => { TelefoneBase telefoneBase = new TelefoneBase(); telefoneBase.set_Tipo(x.get_Tipo()); telefoneBase.set_Id(x.get_Id()); telefoneBase.set_Numero(x.get_Numero()); telefoneBase.set_Prefixo(x.get_Prefixo()); return telefoneBase; }).ToList()); } break; } case 2: { this.IsVisibleCliente = Visibility.Visible; this.IsVisibleArquivoDigital = Visibility.Visible; goto case 1; } case 4: { this.IsVisibleCliente = Visibility.Visible; this.IsVisibleApolice = Visibility.Visible; this.IsVisibleSinistro = Visibility.Visible; this.IsVisibleArquivoDigital = Visibility.Visible; goto case 1; } default: { goto case 1; } } } else { base.Responsaveis = new ObservableCollection(); } } } }