using Gestor.Application.Actions; using Gestor.Application.Componentes; using Gestor.Application.Drawers; using Gestor.Application.Helpers; using Gestor.Application.Servicos; using Gestor.Application.ViewModels.BI; using Gestor.Application.ViewModels.Generic; using Gestor.Application.Views.Ferramentas; using Gestor.Application.Views.Generic; using Gestor.Common.Validation; using Gestor.Model.Common; using Gestor.Model.Domain.Ferramentas; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.MalaDireta; using Gestor.Model.Domain.Seguros; using MaterialDesignThemes.Wpf; using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Threading; using Xceed.Wpf.AvalonDock.Controls; namespace Gestor.Application.Views.BI { public class TarefaView : BaseUserControl, IComponentConnector, IStyleConnector { internal ComboBox UsuarioBox; internal DatePicker InicioBox; internal DatePicker FimBox; internal TextBox TituloTarefaLabel; internal DatePicker AgendamentoBox; internal ComboBox ResponsavelBox; internal RadioButton AnotacoesButton; internal RadioButton AnotacoesInternasButton; internal WebEditor Anotacoes; internal WebEditor Historico; internal WebEditor AnotacoesInternas; internal WebEditor HistoricoInterno; private bool _contentLoaded; public TarefaBIViewModel ViewModel { get; set; } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public TarefaView() { this.ViewModel = new TarefaBIViewModel(); base.DataContext = this.ViewModel; this.InitializeComponent(); System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher; if (dispatcher == null) { return; } dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(this.ContentLoad)); } private void AbrirLog_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AbrirLog(38, this.ViewModel.SelectedTarefa.get_Id()); } private void AdicionarFiltro_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AdcionarFiltro(); } private void AdicionarResponsavel_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AdcionarResponsavel(); } private void Alterar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AlterarTarefa(); this.Anotacoes.Initialize(null); this.AnotacoesInternas.Initialize(null); } private async void AnexoTarefa_OnClick(object sender, RoutedEventArgs e) { if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 15).get_Consultar()) { FiltroArquivoDigital filtroArquivoDigital = new FiltroArquivoDigital(); filtroArquivoDigital.set_Id(this.ViewModel.SelectedTarefa.get_Id()); filtroArquivoDigital.set_Tipo(15); filtroArquivoDigital.set_Parente(this.ViewModel.SelectedTarefa); this.ViewModel.ShowDrawer(new ArquivoDigitalDrawer(filtroArquivoDigital), 0, false); } else { await this.ViewModel.ShowMessage(string.Concat("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR\nARQUIVO DIGITAL DE ", ValidationHelper.GetDescription((TipoArquivoDigital)15), "."), "OK", "", false); } } private void Anotacoes_OnChecked(object sender, RoutedEventArgs e) { this.ViewModel.IsAnotacoes = true; } private void AnotacoesInternas_OnChecked(object sender, RoutedEventArgs e) { this.ViewModel.IsAnotacoes = false; } private void Apolice_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.Abrir((this.ViewModel.SelectedTarefa.get_Entidade() == 3 ? 3 : 0)); } private void ArquivoDigital_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AbrirArquivoDigital(); } private async void Cancelar_OnClick(object sender, RoutedEventArgs e) { await this.ViewModel.Cancelar(); } private void Cliente_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.Abrir(2); } private async void Concluida_OnClick(object sender, RoutedEventArgs e) { if (this.ViewModel.SelectedTarefa == null) { await this.ViewModel.ShowMessage("NECESSÁRIO SELECIONAR UMA TAREFA ANTES DE CONCLUIR.", "OK", "", false); } else if (await this.ViewModel.ValidaPermissaoParaEditarTarefa()) { this.ViewModel.SelectedTarefa.set_Conclusao(new DateTime?(Funcoes.GetNetworkTime())); this.ViewModel.SelectedTarefa.set_Status(2); await this.ViewModel.ConcluirTarefa(this.ViewModel.SelectedTarefa); await this.ViewModel.CarregarTarefas(); } else { await this.ViewModel.ShowMessage(string.Format("APENAS O USUÁRIO {0} (ID: {1}) PODE CONCLUIR ESSA TAREFA.", this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Nome(), this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Id()), "OK", "", false); } } private void ContentLoad() { this.AnotacoesButton.IsChecked = new bool?(this.ViewModel.IsAnotacoes); this.AnotacoesInternasButton.IsChecked = new bool?(!this.ViewModel.IsAnotacoes); this.AnotacoesButton.Checked += new RoutedEventHandler(this.Anotacoes_OnChecked); this.AnotacoesInternasButton.Checked += new RoutedEventHandler(this.AnotacoesInternas_OnChecked); } private void CopyTelefoneToClipBoard_Click(object sender, RoutedEventArgs e) { Button button = (Button)sender; if (button.DataContext != null) { TelefoneBase dataContext = button.DataContext as TelefoneBase; if (dataContext != null) { string.Concat(dataContext.get_Prefixo(), ValidationHelper.OnlyNumber(dataContext.get_Numero())).CopyToClipboard(); this.ViewModel.ToggleSnackBar(string.Concat("COPIADO - ", dataContext.get_Prefixo(), ValidationHelper.OnlyNumber(dataContext.get_Numero())), true); return; } } } private async void Email_OnClick(object sender, RoutedEventArgs e) { MalaDireta malaDiretum = await this.ViewModel.CriarMalaDireta(this.ViewModel.SelectedTarefa.get_Entidade()); if (malaDiretum != null) { if (Funcoes.IsWindowOpen("ENVIO DE E-MAIL")) { Funcoes.Destroy("ENVIO DE E-MAIL"); } string str = string.Concat("Cliente: ", this.ViewModel.SelectedTarefa.get_Cliente(), "
"); str = string.Concat(str, string.Format("Número do Atendimento: {0}
", this.ViewModel.SelectedTarefa.get_Id())); str = string.Concat(str, string.Format("Data/Hora da Solicitação: {0}
", this.ViewModel.SelectedTarefa.get_Agendamento())); if (this.ViewModel.SelectedTarefa.get_Conclusao().HasValue) { str = string.Concat(str, string.Format("Data/Hora da Conclusão: {0}
", this.ViewModel.SelectedTarefa.get_Conclusao())); } if (this.ViewModel.SelectedTarefa.get_Usuario() != null) { str = string.Concat(str, "Atendente: ", this.ViewModel.SelectedTarefa.get_Usuario().get_Nome(), "
"); } if (this.ViewModel.SelectedTarefa.get_TipoDeTarefa() != null) { str = string.Concat(str, "Tipo: ", this.ViewModel.SelectedTarefa.get_TipoDeTarefa().get_Nome(), "
"); } str = string.Concat(str, "Assunto: ", this.ViewModel.SelectedTarefa.get_Titulo(), "
"); str = string.Concat(str, "Situação do Atendimento: ", ValidationHelper.GetDescription(this.ViewModel.SelectedTarefa.get_Status()), "

"); str = string.Concat(str, "Prezado cliente,
"); str = string.Concat(str, "Segue, abaixo, a descrição do seu atendimento prestado pela corretora.

"); List malaDiretas = new List() { malaDiretum }; (new HosterWindow(new MalaDiretaView(malaDiretas, this.ViewModel.SelectedTarefa.get_Titulo(), string.Concat(str, this.ViewModel.Descricao), null), "ENVIO DE E-MAIL", new double?((double)1200), new double?((double)600), true)).Show(); } else { await this.ViewModel.ShowMessage("NECESSÁRIO SELECIONAR AO MENOS UM CLIENTE PARA PROSSEGUIR.", "OK", "", false); } } private async void Excluir_OnClick(object sender, RoutedEventArgs e) { if (!this.ViewModel.SelectedTarefa.get_Restrito().HasValue || !this.ViewModel.SelectedTarefa.get_Restrito().Value || this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Id() == Recursos.Usuario.get_Id() || Recursos.Usuario.get_Administrador()) { await this.ViewModel.Excluir(); } else { await this.ViewModel.ShowMessage(string.Format("APENAS O USUÁRIO {0} (ID: {1}) PODE EXCLUIR ESSA TAREFA.", this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Nome(), this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Id()), "OK", "", false); } } private void ExcluirFiltro_onClick(object sender, RoutedEventArgs e) { Chip chip = sender as Chip; if (chip == null) { return; } ListBox listBox = Extentions.FindVisualAncestor(chip); string item = (string)listBox.Items[listBox.Items.IndexOf(chip.DataContext)]; if (item == null) { return; } this.ViewModel.ExcluirFiltro(item); } private void ExcluirResponsavel_OnClick(object sender, RoutedEventArgs e) { Chip chip = sender as Chip; if (chip == null) { return; } ResponsavelTarefa dataContext = (ResponsavelTarefa)chip.DataContext; if (dataContext == null) { return; } this.ViewModel.Responsaveis.Remove(dataContext); this.ViewModel.Usuarios.Add(dataContext.get_Usuario()); this.ViewModel.Usuarios = new ObservableCollection( from x in this.ViewModel.Usuarios orderby x.get_Nome() select x); } private async void ExcluirTarefa_OnClick(object sender, RoutedEventArgs e) { if (await this.ViewModel.ValidaPermissaoParaExcluirTarefa(null)) { await this.ViewModel.Excluir(); } else { await this.ViewModel.ShowMessage(string.Format("APENAS O USUÁRIO {0} (ID: {1}) PODE EXCLUIR ESSA TAREFA.", this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Nome(), this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Id()), "OK", "", false); } } private void Imprimir_OnClick(object sender, RoutedEventArgs e) { if (this.ViewModel.SelectedTarefa.get_Id() == 0) { return; } this.ViewModel.Print(); } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] public void InitializeComponent() { if (this._contentLoaded) { return; } this._contentLoaded = true; System.Windows.Application.LoadComponent(this, new Uri("/Gestor.Application;component/views/bi/tarefaview.xaml", UriKind.Relative)); } private async void NaoConcluida_OnClick(object sender, RoutedEventArgs e) { if (this.ViewModel.SelectedTarefa != null) { this.ViewModel.SelectedTarefa.set_Conclusao(null); this.ViewModel.SelectedTarefa.set_Status(0); await this.ViewModel.ConcluirTarefa(this.ViewModel.SelectedTarefa); await this.ViewModel.CarregarTarefas(); } else { await this.ViewModel.ShowMessage("NECESSÁRIO SELECIONAR UMA TAREFA ANTES DE MARCAR COMO NÃO CONCLUÍDO.", "OK", "", false); } } private async void Salvar_OnClick(object sender, RoutedEventArgs e) { bool flag; this.ViewModel.SelectedTarefa.set_Anotacoes(this.Anotacoes.GetHtml()); this.ViewModel.SelectedTarefa.set_AnotacoesInternas(this.AnotacoesInternas.GetHtml()); this.ViewModel.SelectedTarefa.set_Usuario((Usuario)this.ResponsavelBox.SelectedItem); List> keyValuePairs = await this.ViewModel.Salvar(this.TituloTarefaLabel.Text); flag = (keyValuePairs == null ? true : keyValuePairs.Count == 0); this.ViewModel.Loading(false); if (!flag) { await this.ViewModel.ShowMessage(keyValuePairs, this.ViewModel.ErroCamposInvalidos, "OK", ""); } else { this.ViewModel.ToggleSnackBar("TAREFA SALVA COM SUCESSO.", true); this.ViewModel.Alterar(false); } } private void Sinistro_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.Abrir(4); } [DebuggerNonUserCode] [EditorBrowsable(EditorBrowsableState.Never)] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: { this.UsuarioBox = (ComboBox)target; return; } case 2: { this.InicioBox = (DatePicker)target; this.InicioBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); this.InicioBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 3: { this.FimBox = (DatePicker)target; this.FimBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); this.FimBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 4: { ((Button)target).Click += new RoutedEventHandler(this.AdicionarFiltro_OnClick); return; } case 5: case 6: case 7: case 22: case 23: case 28: { this._contentLoaded = true; return; } case 8: { ((MenuItem)target).Click += new RoutedEventHandler(this.Concluida_OnClick); return; } case 9: { ((MenuItem)target).Click += new RoutedEventHandler(this.NaoConcluida_OnClick); return; } case 10: { ((MenuItem)target).Click += new RoutedEventHandler(this.Alterar_OnClick); return; } case 11: { ((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick); return; } case 12: { ((MenuItem)target).Click += new RoutedEventHandler(this.Cancelar_OnClick); return; } case 13: { ((MenuItem)target).Click += new RoutedEventHandler(this.Excluir_OnClick); return; } case 14: { ((MenuItem)target).Click += new RoutedEventHandler(this.AnexoTarefa_OnClick); return; } case 15: { ((MenuItem)target).Click += new RoutedEventHandler(this.Cliente_OnClick); return; } case 16: { ((MenuItem)target).Click += new RoutedEventHandler(this.Apolice_OnClick); return; } case 17: { ((MenuItem)target).Click += new RoutedEventHandler(this.ArquivoDigital_OnClick); return; } case 18: { ((MenuItem)target).Click += new RoutedEventHandler(this.Sinistro_OnClick); return; } case 19: { ((MenuItem)target).Click += new RoutedEventHandler(this.Imprimir_OnClick); return; } case 20: { ((MenuItem)target).Click += new RoutedEventHandler(this.Email_OnClick); return; } case 21: { ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLog_OnClick); return; } case 24: { this.TituloTarefaLabel = (TextBox)target; return; } case 25: { this.AgendamentoBox = (DatePicker)target; this.AgendamentoBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); return; } case 26: { this.ResponsavelBox = (ComboBox)target; return; } case 27: { ((Button)target).Click += new RoutedEventHandler(this.AdicionarResponsavel_OnClick); return; } case 29: { this.AnotacoesButton = (RadioButton)target; return; } case 30: { this.AnotacoesInternasButton = (RadioButton)target; return; } case 31: { this.Anotacoes = (WebEditor)target; return; } case 32: { this.Historico = (WebEditor)target; return; } case 33: { this.AnotacoesInternas = (WebEditor)target; return; } case 34: { this.HistoricoInterno = (WebEditor)target; return; } default: { this._contentLoaded = true; return; } } } [DebuggerNonUserCode] [EditorBrowsable(EditorBrowsableState.Never)] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target) { if (connectionId > 22) { if (connectionId == 23) { ((Button)target).Click += new RoutedEventHandler(this.WhatsAppMessage_Click); return; } if (connectionId != 28) { return; } ((Chip)target).add_DeleteClick(new RoutedEventHandler(this.ExcluirResponsavel_OnClick)); return; } switch (connectionId) { case 5: { ((Chip)target).add_DeleteClick(new RoutedEventHandler(this.ExcluirFiltro_onClick)); return; } case 6: { ((Button)target).Click += new RoutedEventHandler(this.ExcluirTarefa_OnClick); return; } case 7: { ((Button)target).Click += new RoutedEventHandler(this.TarefaConcluida_OnClick); return; } default: { if (connectionId == 22) { break; } else { return; } } } ((Button)target).Click += new RoutedEventHandler(this.CopyTelefoneToClipBoard_Click); } private async void TarefaConcluida_OnClick(object sender, RoutedEventArgs e) { Tarefa dataContext = ((Button)sender).DataContext as Tarefa; if (dataContext != null) { if (await this.ViewModel.ValidaPermissaoParaEditarTarefa()) { dataContext.set_Conclusao(new DateTime?(Funcoes.GetNetworkTime())); dataContext.set_Status(2); await this.ViewModel.ConcluirTarefa(dataContext); await this.ViewModel.CarregarTarefas(); Action atualizaTrilhas = Gestor.Application.Actions.Actions.AtualizaTrilhas; if (atualizaTrilhas != null) { atualizaTrilhas(); } else { } } else { await this.ViewModel.ShowMessage(string.Format("APENAS O USUÁRIO {0} (ID: {1}) PODE CONCLUIR ESSA TAREFA.", this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Nome(), this.ViewModel.SelectedTarefa.get_UsuarioCadastro().get_Id()), "OK", "", false); } } dataContext = null; } private async void WhatsAppMessage_Click(object sender, RoutedEventArgs e) { string str; Button button = (Button)sender; if (button.DataContext != null) { TelefoneBase dataContext = button.DataContext as TelefoneBase; if (dataContext != null) { str = (!dataContext.get_Tipo().HasValue || dataContext.get_Tipo().GetValueOrDefault() != 8 ? string.Concat("55", dataContext.get_Prefixo(), dataContext.get_Numero().Clear()) : string.Concat(dataContext.get_Prefixo(), dataContext.get_Numero()).Clear()); if (!str.EnviarWhatsapp(null)) { await this.ViewModel.ShowMessage("HOUVE UM PROBLEMA AO ABRIR LINK DO WHATSAPP, O LINK FOI COPIADO EM SUA MAQUINA, BASTA ABRIR O NAVEGADOR DE INTERNET E COLAR NA BARRA DE ENDEREÇOS", "OK", "", false); } return; } } } } }