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.Configuracoes; using Gestor.Model.Domain.Ferramentas; using Gestor.Model.Domain.Generic; 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.Drawer { public class TarefaDrawerViewModel : BaseTarefaViewModel { private bool _enableMenu = true; private GridLength _dados = new GridLength(0, GridUnitType.Pixel); private GridLength _grid = new GridLength(1, GridUnitType.Star); private GridLength _anotacoesLength = new GridLength(0, GridUnitType.Pixel); private GridLength _descricaoLength = new GridLength(1, GridUnitType.Star); private GridLength _anotacoesInternasLength = new GridLength(0, GridUnitType.Pixel); private GridLength _descricaoInternaLength = new GridLength(1, GridUnitType.Star); private bool _enableAlterarTarefa = true; private Visibility _visibilityMenu; private bool _isVisibleDescricao; private bool _isSelected; private bool _concluido; private bool _carregando; private string _tituloTarefas; private string _titulo; private string _subTitulo; private Gestor.Model.Domain.Ferramentas.Tarefa _tarefa = new Gestor.Model.Domain.Ferramentas.Tarefa(); private ObservableCollection _tarefasFiltradas = new ObservableCollection(); private List _tarefas = new List(); private bool _isAnotacoes = true; private Gestor.Model.Domain.Ferramentas.Tarefa _selectedTarefa; private ObservableCollection _usuarios; private ObservableCollection _tiposTarefa; private List _telefones; private DateTime _dataAgendamento = Funcoes.GetNetworkTime(); private DateTime _horaAgendamento = Funcoes.GetNetworkTime(); private Usuario _selectedUsuario; private TipoDeTarefa _selectedTipoTarefa; private Gestor.Model.Domain.Common.ArquivoDigital _selectedAnexado = new Gestor.Model.Domain.Common.ArquivoDigital(); private ObservableCollection _arquivosAnexados = new ObservableCollection(); private List _arquivosFinais = new List(); private bool _inclusaoArquivoDigitalEnable = true; public GridLength AnotacoesInternasLength { get { return this._anotacoesInternasLength; } set { this._anotacoesInternasLength = value; base.OnPropertyChanged("AnotacoesInternasLength"); } } public GridLength AnotacoesLength { get { return this._anotacoesLength; } set { this._anotacoesLength = value; base.OnPropertyChanged("AnotacoesLength"); } } public ObservableCollection ArquivosAnexados { get { return this._arquivosAnexados; } set { this._arquivosAnexados = value; base.OnPropertyChanged("ArquivosAnexados"); } } public List ArquivosFinais { get { return this._arquivosFinais; } set { this._arquivosFinais = value; base.OnPropertyChanged("ArquivosFinais"); } } public bool Carregando { get { return this._carregando; } set { this._carregando = value; base.IsEnabled = !value; base.OnPropertyChanged("Carregando"); } } public bool Concluido { get { return this._concluido; } set { this._concluido = value; base.OnPropertyChanged("Concluido"); } } public GridLength Dados { get { return this._dados; } set { this._dados = value; base.OnPropertyChanged("Dados"); } } 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 GridLength DescricaoInternaLength { get { return this._descricaoInternaLength; } set { this._descricaoInternaLength = value; base.OnPropertyChanged("DescricaoInternaLength"); } } public GridLength DescricaoLength { get { return this._descricaoLength; } set { this._descricaoLength = value; base.OnPropertyChanged("DescricaoLength"); } } public override bool EnableAlterarTarefa { get { return this._enableAlterarTarefa; } set { this._enableAlterarTarefa = this._alterarPermissEnabled & value; base.OnPropertyChanged("EnableAlterarTarefa"); } } public GridLength Grid { get { return this._grid; } set { this._grid = value; base.OnPropertyChanged("Grid"); } } 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 long IdCliente { get; set; } public bool InclusaoArquivoDigitalEnable { get { return this._inclusaoArquivoDigitalEnable; } set { this._inclusaoArquivoDigitalEnable = value; base.OnPropertyChanged("InclusaoArquivoDigitalEnable"); } } private int Index { get; set; } = 1; public bool IsAnotacoes { get { return this._isAnotacoes; } set { this._isAnotacoes = value; base.OnPropertyChanged("IsAnotacoes"); } } public bool IsSelected { get { return this._isSelected; } set { this._isSelected = value; base.OnPropertyChanged("IsSelected"); } } public bool IsVisibleDescricao { get { return this._isVisibleDescricao; } set { this._isVisibleDescricao = value; base.OnPropertyChanged("IsVisibleDescricao"); } } public Gestor.Model.Domain.Common.ArquivoDigital SelectedAnexado { get { return this._selectedAnexado; } set { this._selectedAnexado = value; base.OnPropertyChanged("SelectedAnexado"); } } public override Gestor.Model.Domain.Ferramentas.Tarefa SelectedTarefa { get { return this._selectedTarefa; } set { DateTime agendamento; DateTime dateTime; bool status; ObservableCollection observableCollection; bool tipoDeTarefa; TipoDeTarefa tipoDeTarefa1; long? nullable; bool usuario; ObservableCollection observableCollection1; DateTime networkTime = Funcoes.GetNetworkTime(); this.IsSelected = value != null; this._selectedTarefa = value; Gestor.Model.Domain.Ferramentas.Tarefa tarefa = value; if (tarefa != null) { agendamento = tarefa.get_Agendamento(); } else { agendamento = networkTime; } this.DataAgendamento = agendamento; Gestor.Model.Domain.Ferramentas.Tarefa tarefa1 = value; if (tarefa1 != null) { dateTime = tarefa1.get_Agendamento(); } else { dateTime = networkTime; } this.HoraAgendamento = dateTime; this.IsVisibleDescricao = value != null; Gestor.Model.Domain.Ferramentas.Tarefa tarefa2 = value; if (tarefa2 != null) { status = tarefa2.get_Status() == 2; } else { status = false; } this.Concluido = status; if (value == null) { observableCollection = new ObservableCollection(); } else { observableCollection = (value.get_Responsaveis() == null ? new ObservableCollection() : new ObservableCollection(value.get_Responsaveis())); } base.Responsaveis = observableCollection; if (!base.Responsaveis.Any()) { Gestor.Model.Domain.Ferramentas.Tarefa tarefa3 = value; if (tarefa3 != null) { usuario = tarefa3.get_Usuario(); } else { usuario = false; } if (!usuario) { 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); } base.Responsaveis = observableCollection1; } if (value != null && value.get_Id() > (long)0) { this.AlterarTamanho(false); } if (value != null) { this.AnotacoesLength = new GridLength(0, GridUnitType.Pixel); this.AnotacoesInternasLength = new GridLength(0, GridUnitType.Pixel); this.DescricaoLength = (string.IsNullOrWhiteSpace(value.get_Descricao()) ? new GridLength(0, GridUnitType.Pixel) : new GridLength(1, GridUnitType.Star)); this.DescricaoInternaLength = (string.IsNullOrWhiteSpace(value.get_DescricaoInterna()) ? new GridLength(0, GridUnitType.Pixel) : new GridLength(1, GridUnitType.Star)); } Gestor.Model.Domain.Ferramentas.Tarefa tarefa4 = value; if (tarefa4 != null) { tipoDeTarefa = tarefa4.get_TipoDeTarefa(); } else { tipoDeTarefa = false; } if (tipoDeTarefa) { if (!this.TiposTarefa.All((TipoDeTarefa x) => x.get_Id() != value.get_Id()) || value.get_TipoDeTarefa().get_Ativo()) { this.TiposTarefa = new ObservableCollection(( from x in this.TiposTarefa where x.get_Ativo() select x).ToList()); } else { this.TiposTarefa.Add(value.get_TipoDeTarefa()); } } Gestor.Model.Domain.Ferramentas.Tarefa tarefa5 = value; if (tarefa5 != null) { tipoDeTarefa1 = tarefa5.get_TipoDeTarefa(); } else { tipoDeTarefa1 = null; } this.SelectedTipoTarefa = tipoDeTarefa1; if (base.EnableIncluir || base.EnableFields || base.EnableButtons) { Gestor.Model.Domain.Ferramentas.Tarefa tarefa6 = value; if (tarefa6 != null) { nullable = new long?(tarefa6.get_Id()); } else { nullable = null; } base.VerificarEnables(nullable); } 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"); } } private new TarefaServico Servico { get; } public string SubTitulo { get { return this._subTitulo; } set { this._subTitulo = value; base.OnPropertyChanged("SubTitulo"); } } public Gestor.Model.Domain.Ferramentas.Tarefa Tarefa { get { return this._tarefa; } set { this._tarefa = value; base.OnPropertyChanged("Tarefa"); } } public List Tarefas { get { return this._tarefas; } set { this._tarefas = value; base.OnPropertyChanged("Tarefas"); } } public ObservableCollection TarefasFiltradas { get { return this._tarefasFiltradas; } set { this._tarefasFiltradas = value; base.OnPropertyChanged("TarefasFiltradas"); } } public List 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 string Titulo { get { return this._titulo; } set { this._titulo = value; base.OnPropertyChanged("Titulo"); } } public string TituloTarefas { get { return this._tituloTarefas; } set { this._tituloTarefas = value; base.OnPropertyChanged("TituloTarefas"); } } public ObservableCollection Usuarios { get { return this._usuarios; } set { this._usuarios = value; base.OnPropertyChanged("Usuarios"); } } public Visibility VisibilityMenu { get { return this._visibilityMenu; } set { this._visibilityMenu = value; base.OnPropertyChanged("VisibilityMenu"); } } public TarefaDrawerViewModel(Gestor.Model.Domain.Ferramentas.Tarefa tarefa, bool enableMenu) { this.Servico = new TarefaServico(); this.Tarefa = tarefa; this._enableMenu = enableMenu; this.CarregarUsuarios(); this.TiposTarefa = new ObservableCollection(( from x in Recursos.TiposTarefa where x.get_Ativo() select x).ToList()); DateTime? conclusao = tarefa.get_Conclusao(); this.SelecionarTarefas(tarefa, new bool?(conclusao.HasValue)); this.TituloTarefas = (tarefa.get_Conclusao().HasValue ? "TAREFAS CONCLUÍDAS" : "TAREFAS PENDENTES"); base.EnableMenu = true; } public void AdcionarResponsavel() { if (this.SelectedUsuario == null) { return; } 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 void AlterarTamanho(bool alterar) { if (!alterar) { if (this.TituloTarefas.Contains("TODAS")) { this.TituloTarefas = "TODAS TAREFAS DO CLIENTE"; } else if (this.TituloTarefas.Contains("PENDENTES")) { this.TituloTarefas = "TAREFAS PENDENTES"; } else if (this.TituloTarefas.Contains("CONCLUÍDAS")) { this.TituloTarefas = "TAREFAS CONCLUÍDAS"; } } this.Grid = (alterar ? new GridLength(0, GridUnitType.Star) : new GridLength(1, GridUnitType.Star)); this.Dados = (alterar ? new GridLength(1, GridUnitType.Star) : new GridLength(360, GridUnitType.Pixel)); } public void AlterarTarefa() { string descricao; string descricaoInterna; this.CarregarUsuarios(); if (this.SelectedTarefa == null) { return; } this.EnableAlterarTarefa = false; this.AlterarTamanho(true); this.TituloTarefas = string.Concat(this.TituloTarefas, " (ALTERANDO \"", this.SelectedTarefa.get_Titulo(), "\")"); base.Alterar(true); this.AnotacoesLength = new GridLength(1, GridUnitType.Star); this.AnotacoesInternasLength = new GridLength(1, GridUnitType.Star); Gestor.Model.Domain.Ferramentas.Tarefa selectedTarefa = this.SelectedTarefa; if (selectedTarefa != null) { descricao = selectedTarefa.get_Descricao(); } else { descricao = null; } this.DescricaoLength = (string.IsNullOrWhiteSpace(descricao) ? new GridLength(0, GridUnitType.Pixel) : new GridLength(1, GridUnitType.Star)); Gestor.Model.Domain.Ferramentas.Tarefa tarefa = this.SelectedTarefa; if (tarefa != null) { descricaoInterna = tarefa.get_DescricaoInterna(); } else { descricaoInterna = null; } this.DescricaoInternaLength = (string.IsNullOrWhiteSpace(descricaoInterna) ? new GridLength(0, GridUnitType.Pixel) : new GridLength(1, GridUnitType.Star)); this.TarefasFiltradas = new ObservableCollection() { this.SelectedTarefa }; base.ListaUsuariosResponsaveis(); base.Responsaveis.ToList().ForEach((ResponsavelTarefa x) => this.Usuarios.Remove(x.get_Usuario())); } public async void Anexar() { this.InclusaoArquivoDigitalEnable = false; List arquivoDigitals = await base.AddAttachments(this.ArquivosAnexados.ToList(), new List()); await Task.Run(async () => { await Task.Delay(200); this.InclusaoArquivoDigitalEnable = true; }); if (arquivoDigitals != null) { arquivoDigitals.AddRange(this.ArquivosAnexados); this.ArquivosAnexados = new ObservableCollection(arquivoDigitals); } arquivoDigitals = null; } public async Task Cancelar() { long id; this.CarregarUsuarios(); this.AlterarTamanho(false); Gestor.Model.Domain.Ferramentas.Tarefa selectedTarefa = this.SelectedTarefa; if (selectedTarefa != null) { id = selectedTarefa.get_Id(); } else { id = (long)0; } long num = id; await this.CarregarTarefas(this.Index); base.Alterar(false); await base.ValidaPermissaoParaEditarTarefa(); if (num != 0) { this.SelectedTarefa = this.TarefasFiltradas.FirstOrDefault((Gestor.Model.Domain.Ferramentas.Tarefa x) => x.get_Id() == num); } } public async void CarregarInformacoes(Gestor.Model.Domain.Ferramentas.Tarefa tarefa) { string str; string str1; ClienteServico clienteServico = new ClienteServico(); TarefaDrawerViewModel tarefaDrawerViewModel = this; str = (tarefa.get_IdEntidade() != 0 ? "TODAS AS TAREFAS PENDENTES DO CLIENTE" : ""); tarefaDrawerViewModel.SubTitulo = str; this.IdCliente = tarefa.get_IdCliente(); this.Titulo = tarefa.get_Cliente(); ObservableCollection observableCollection = await clienteServico.BuscarTelefonesAsync(tarefa.get_IdCliente()); TarefaDrawerViewModel list = this; ObservableCollection observableCollection1 = observableCollection; IEnumerable clienteTelefones = from x in observableCollection1 where Gestor.Model.Helper.ValidationHelper.ValidacaoTelefone(x.get_Numero()) select x; list.Telefones = 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(); if (tarefa.get_IdEntidade() != 0) { TipoTarefa entidade = tarefa.get_Entidade(); if (entidade == null) { Documento documento = await (new ApoliceServico()).BuscarApoliceAsync(tarefa.get_IdEntidade(), false, false); this.IdCliente = documento.get_Controle().get_Cliente().get_Id(); this.Titulo = documento.get_Controle().get_Cliente().get_Nome(); TarefaDrawerViewModel tarefaDrawerViewModel1 = this; if (documento.get_Tipo() != 0 || string.IsNullOrWhiteSpace(documento.get_Apolice())) { str1 = (documento.get_Tipo() > 0 ? string.Concat("APÓLICE NÚMERO ", documento.get_Apolice(), " ENDOSSO ", documento.get_Endosso()) : string.Concat("PROPOSTA NÚMERO ", documento.get_Proposta())); } else { str1 = string.Concat("APÓLICE NÚMERO ", documento.get_Apolice()); } tarefaDrawerViewModel1.SubTitulo = str1; observableCollection = await clienteServico.BuscarTelefonesAsync(documento.get_Controle().get_Cliente().get_Id()); TarefaDrawerViewModel list1 = this; ObservableCollection observableCollection2 = observableCollection; IEnumerable clienteTelefones1 = from x in observableCollection2 where Gestor.Model.Helper.ValidationHelper.ValidacaoTelefone(x.get_Numero()) select x; list1.Telefones = clienteTelefones1.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(); } else if (entidade == 4) { Sinistro sinistro = await (new SinistroServico()).BuscarSinistro(tarefa.get_IdEntidade()); if (sinistro != null) { this.IdCliente = sinistro.get_ControleSinistro().get_Item().get_Documento().get_Controle().get_Cliente().get_Id(); this.Titulo = sinistro.get_ControleSinistro().get_Item().get_Documento().get_Controle().get_Cliente().get_Nome(); this.SubTitulo = string.Concat("SINISTRO ", sinistro.get_Numero(), " ITEM ", sinistro.get_ItemSinistrado()); observableCollection = await clienteServico.BuscarTelefonesAsync(this.IdCliente); TarefaDrawerViewModel list2 = this; ObservableCollection observableCollection3 = observableCollection; IEnumerable clienteTelefones2 = from x in observableCollection3 where Gestor.Model.Helper.ValidationHelper.ValidacaoTelefone(x.get_Numero()) select x; list2.Telefones = clienteTelefones2.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(); } else { clienteServico = null; return; } } } clienteServico = null; } public async Task CarregarTarefas(int index) { List tarefas; Gestor.Model.Domain.Ferramentas.Tarefa tarefa; if (this.Tarefa.get_IdEntidade() != 0) { this.Carregando = true; Gestor.Model.Domain.Ferramentas.Tarefa tarefa1 = new Gestor.Model.Domain.Ferramentas.Tarefa(); tarefa1.set_Cliente(this.Tarefa.get_Cliente()); tarefa1.set_IdCliente(this.Tarefa.get_IdCliente()); tarefa1.set_Entidade(this.Tarefa.get_Entidade()); tarefa1.set_IdEntidade(this.Tarefa.get_IdEntidade()); Gestor.Model.Domain.Ferramentas.Tarefa tarefa2 = tarefa1; this.Index = index; int num = index; if (num == 1) { this.CarregarInformacoes(tarefa2); tarefas = await this.Servico.BuscarTarefas(this.Tarefa.get_Entidade(), this.Tarefa.get_IdEntidade(), new bool?(false)); } else if (num == 2) { tarefa2.set_Entidade(2); this.CarregarInformacoes(tarefa2); tarefas = await this.Servico.BuscarTarefasCliente(this.Tarefa.get_IdCliente()); } else { this.CarregarInformacoes(tarefa2); tarefas = await this.Servico.BuscarTarefas(this.Tarefa.get_Entidade(), this.Tarefa.get_IdEntidade(), new bool?(true)); } TarefaDrawerViewModel list = this; List tarefas1 = tarefas; list.Tarefas = ( from x in tarefas1 orderby x.get_Agendamento() descending select x).ToList(); this.TarefasFiltradas = new ObservableCollection(this.Tarefas); TarefaDrawerViewModel tarefaDrawerViewModel = this; if (this.TarefasFiltradas == null || this.TarefasFiltradas.Count == 0) { tarefa = null; } else { tarefa = (tarefa2.get_Id() != 0 ? this.TarefasFiltradas.FirstOrDefault((Gestor.Model.Domain.Ferramentas.Tarefa x) => x.get_Id() == tarefa2.get_Id()) : this.TarefasFiltradas.First()); } tarefaDrawerViewModel.SelectedTarefa = tarefa; this.Carregando = false; } } public async Task CarregarTarefas(Gestor.Model.Domain.Ferramentas.Tarefa tarefa, bool? concluido) { Gestor.Model.Domain.Ferramentas.Tarefa tarefa1; this.Carregando = true; if (tarefa.get_IdEntidade() != 0) { List tarefas = await this.Servico.BuscarTarefas(tarefa.get_Entidade(), tarefa.get_IdEntidade(), concluido); TarefaDrawerViewModel list = this; List tarefas1 = tarefas; list.Tarefas = ( from x in tarefas1 orderby x.get_Agendamento() select x).ToList(); this.TarefasFiltradas = new ObservableCollection(this.Tarefas); TarefaDrawerViewModel tarefaDrawerViewModel = this; if (this.TarefasFiltradas == null || this.TarefasFiltradas.Count == 0) { tarefa1 = null; } else { tarefa1 = (tarefa.get_Id() != 0 ? this.TarefasFiltradas.FirstOrDefault((Gestor.Model.Domain.Ferramentas.Tarefa x) => x.get_Id() == tarefa.get_Id()) : this.TarefasFiltradas.First()); } tarefaDrawerViewModel.SelectedTarefa = tarefa1; } else if (tarefa.get_Id() > (long)0) { this.SelectedTarefa = await this.Servico.BuscarTarefa(tarefa.get_Id()); } this.Carregando = false; } 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() || x.get_Excluido()) { return false; } long? permissaoAggilizador = x.get_PermissaoAggilizador(); long num = (long)4; return !(permissaoAggilizador.GetValueOrDefault() == num & permissaoAggilizador.HasValue); }).OrderBy((Usuario x) => x.get_Nome()).ToList()); } public void Delete(Gestor.Model.Domain.Common.ArquivoDigital arquivo) { if (this.SelectedAnexado == null) { return; } Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = this.ArquivosAnexados.First((Gestor.Model.Domain.Common.ArquivoDigital x) => x.get_Descricao() == arquivo.get_Descricao()); this.ArquivosAnexados.Remove(arquivoDigital); this.ArquivosAnexados = new ObservableCollection(this.ArquivosAnexados); } public async void Editar(IndiceArquivoDigital arquivo) { if (arquivo != null && arquivo.get_IdArquivoDigital() != 0) { await this.ArquivoDigitalServico.Save(arquivo); } } public async Task Excluir(Gestor.Model.Domain.Ferramentas.Tarefa item) { bool flag; string titulo; if (this.VisibilityMenu != Visibility.Collapsed) { string[] strArrays = new string[] { "DESEJA REALMENTE EXCLUIR A TAREFA ", item.get_Titulo(), "?", Environment.NewLine, "ESSE PROCEDIMENTO É IRREVERSÍVEL" }; if (await base.ShowMessage(string.Concat(strArrays), "SIM", "NÃO", false)) { titulo = item.get_Titulo(); long id = item.get_Id(); if (await this.Servico.Excluir(item.get_Id())) { base.RegistrarAcao("EXCLUIU TAREFA", item.get_Id(), new TipoTela?(38), string.Format("TAREFA \"{0}\", ID: {1}", titulo, id)); await this.CarregarTarefas(this.Index); base.Alterar(false); flag = true; } else { base.Alterar(false); flag = true; } } else { flag = false; } } else { await base.ShowMessage("NÃO É POSSÍVEL EXCLUIR TAREFA PELO RELATÓRIO!", "OK", "", false); flag = false; } titulo = null; return flag; } 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 async Task Incluir() { TarefaDrawerViewModel observableCollection = this; observableCollection.CarregarUsuarios(); observableCollection.Responsaveis = new ObservableCollection(); TarefaDrawerViewModel tarefaDrawerViewModel = observableCollection; Gestor.Model.Domain.Ferramentas.Tarefa tarefa = new Gestor.Model.Domain.Ferramentas.Tarefa(); tarefa.set_IdCliente(observableCollection.IdCliente); tarefa.set_Cliente(observableCollection.Titulo); tarefa.set_Referencia(observableCollection.SubTitulo); tarefa.set_Entidade(observableCollection.Tarefa.get_Entidade()); tarefa.set_IdEntidade(observableCollection.Tarefa.get_IdEntidade()); tarefa.set_Trilha(observableCollection.Tarefa.get_Trilha()); tarefa.set_Status(0); tarefa.set_Agendamento(Funcoes.GetNetworkTime().AddHours(1)); tarefa.set_UsuarioCadastro(Recursos.Usuario); ObservableCollection usuarios = observableCollection.Usuarios; tarefa.set_Usuario(usuarios.FirstOrDefault((Usuario x) => x.get_Id() == Recursos.Usuario.get_Id())); tarefa.set_Restrito(new bool?(false)); tarefa.set_Responsaveis(observableCollection.Responsaveis.ToList()); tarefaDrawerViewModel.SelectedTarefa = tarefa; observableCollection.ArquivosFinais = new List(); observableCollection.AlterarTamanho(true); observableCollection.TituloTarefas = string.Concat(observableCollection.TituloTarefas, " (INCLUINDO)"); observableCollection.Alterar(true); observableCollection.AnotacoesLength = new GridLength(1, GridUnitType.Star); observableCollection.AnotacoesInternasLength = new GridLength(1, GridUnitType.Star); observableCollection.DescricaoLength = new GridLength(0, GridUnitType.Pixel); observableCollection.DescricaoInternaLength = new GridLength(0, GridUnitType.Pixel); observableCollection.EnableAlterarTarefa = false; } public void LimparAnexos() { this.ArquivosAnexados = new ObservableCollection(); } 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); base.RegistrarAcao("IMPRIMIU A TAREFA", this.SelectedTarefa.get_Id(), new TipoTela?(38), string.Format("TAREFA \"{0}\", ID: {1}", this.SelectedTarefa.get_Titulo(), this.SelectedTarefa.get_Id())); } public async Task>> Salvar(string anotacoes, string anotacoesInternas) { List> keyValuePairs; Usuario usuario; 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)); } if (this.SelectedTarefa.get_Status() == null) { this.SelectedTarefa.set_Conclusao(null); } this.SelectedTarefa.set_Responsaveis(base.Responsaveis.ToList()); Gestor.Model.Domain.Ferramentas.Tarefa selectedTarefa = this.SelectedTarefa; ResponsavelTarefa responsavelTarefa = base.Responsaveis.FirstOrDefault(); if (responsavelTarefa != null) { usuario = responsavelTarefa.get_Usuario(); } else { usuario = null; } selectedTarefa.set_Usuario(usuario); Gestor.Model.Domain.Ferramentas.Tarefa tarefa = this.SelectedTarefa; List configuracaoSistemas = Recursos.Configuracoes; tarefa.set_AgendamentoRetroativo(configuracaoSistemas.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 45)); List> keyValuePairs1 = this.SelectedTarefa.Validate(); if (this.SelectedTarefa.get_Descricao() == null && string.IsNullOrWhiteSpace(anotacoes) && string.IsNullOrWhiteSpace(anotacoesInternas)) { keyValuePairs1.Add(new KeyValuePair("ANOTAÇÕES", "OBRIGATÓRIO")); } if (keyValuePairs1.Count <= 0) { if (!string.IsNullOrWhiteSpace(anotacoes)) { this.SelectedTarefa.set_Anotacoes(Funcoes.AdicionarLog(this.SelectedTarefa.get_Anotacoes())); this.SelectedTarefa.set_Descricao(string.Concat(this.SelectedTarefa.get_Anotacoes(), "

", this.SelectedTarefa.get_Descricao(), "

")); } if (!string.IsNullOrWhiteSpace(anotacoesInternas)) { this.SelectedTarefa.set_AnotacoesInternas(Funcoes.AdicionarLog(this.SelectedTarefa.get_AnotacoesInternas())); this.SelectedTarefa.set_DescricaoInterna(string.Concat(this.SelectedTarefa.get_AnotacoesInternas(), "

", this.SelectedTarefa.get_DescricaoInterna(), "

")); } this.SelectedTarefa.set_TipoDeTarefa(this.SelectedTipoTarefa); bool id = this.SelectedTarefa.get_Id() == (long)0; this.SelectedTarefa = await this.Servico.Salvar(this.SelectedTarefa); string str = (id ? "INCLUIU" : "ALTEROU"); base.RegistrarAcao(string.Concat(str, " TAREFA"), this.SelectedTarefa.get_Id(), new TipoTela?(38), string.Format("TAREFA \"{0}\", ID: {1}", this.SelectedTarefa.get_Titulo(), this.SelectedTarefa.get_Id())); if (id) { foreach (Gestor.Model.Domain.Common.ArquivoDigital arquivosFinai in this.ArquivosFinais) { arquivosFinai.set_IdTarefa(this.SelectedTarefa.get_Id()); } await this.ArquivoDigitalServico.Insert(this.ArquivosFinais); } if (this.Servico.Sucesso) { long num = this.SelectedTarefa.get_Id(); await this.CarregarTarefas(this.Index); this.SelectedTarefa = this.TarefasFiltradas.FirstOrDefault((Gestor.Model.Domain.Ferramentas.Tarefa x) => x.get_Id() == num); keyValuePairs = null; } else { keyValuePairs = null; } } else { keyValuePairs = keyValuePairs1; } return keyValuePairs; } public void SalvarAnexos() { this.ArquivosFinais = this.ArquivosAnexados.ToList(); } public async void SelecionarTarefas(Gestor.Model.Domain.Ferramentas.Tarefa tarefa, bool? concluido) { await base.PermissaoTela(38); this.CarregarInformacoes(tarefa); await this.CarregarTarefas(tarefa, concluido); if (tarefa.get_Id() != 0 && !this._enableMenu) { this.VisibilityMenu = Visibility.Collapsed; } } } }