using Gestor.Application; using Gestor.Application.Helpers; using Gestor.Application.ViewModels.Drawer; using Gestor.Application.ViewModels.Generic; using Gestor.Application.Views.Ferramentas; using Gestor.Application.Views.Generic; 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.MalaDireta; using Gestor.Model.Domain.Seguros; using Gestor.Model.License; using MaterialDesignThemes.Wpf; using System; using System.CodeDom.Compiler; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Threading; using Xceed.Wpf.AvalonDock.Controls; namespace Gestor.Application.Drawers { public class ArquivoDigitalDrawer : UserControl, IComponentConnector, IStyleConnector { internal System.Windows.Controls.ProgressBar ProgressBar; internal TextBlock TitleBox; internal DataGrid ArquivoGrid; internal TextBox DocumentoBox; internal Snackbar SnackbarArquivoDigital; private bool _contentLoaded; private FiltroArquivoDigital Filtro { get; } public ArquivoDigitalViewModel ViewModel { get; set; } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public ArquivoDigitalDrawer(FiltroArquivoDigital filtro) { long? nullable; long? nullable1; string description; string str; long? nullable2; string description1; string str1; long num; this.ViewModel = new ArquivoDigitalViewModel(filtro); this.Filtro = filtro; base.DataContext = this.ViewModel; this.InitializeComponent(); System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher; if (dispatcher != null) { dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(this.ContentLoad)); } else { } ArquivoDigitalViewModel viewModel = this.ViewModel; if (filtro != null) { description = ValidationHelper.GetDescription(filtro.get_Tipo()); } else { description = null; } if ((filtro != null ? filtro.get_Id() != (long)0 : true)) { if (filtro != null) { nullable1 = new long?(filtro.get_Id()); } else { nullable = null; nullable1 = nullable; } str = string.Format(" DO DOCUMENTO DE ID \"{0}\"", nullable1); } else { str = ""; } string str2 = string.Concat("ACESSOU ARQUIVO DIGITAL DE ", description, str); num = (filtro != null ? filtro.get_Id() : (long)0); TipoTela? nullable3 = new TipoTela?(6); if (filtro != null) { description1 = ValidationHelper.GetDescription(filtro.get_Tipo()); } else { description1 = null; } if ((filtro != null ? filtro.get_Id() != (long)0 : true)) { if (filtro != null) { nullable2 = new long?(filtro.get_Id()); } else { nullable = null; nullable2 = nullable; } str1 = string.Format("\nID APÓLICE: {0}", nullable2); } else { str1 = ""; } viewModel.RegistrarAcao(str2, num, nullable3, string.Concat("TIPO: ", description1, str1)); } private void Abrir_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; if (button == null) { return; } this.ViewModel.Activated = false; DataGrid dataGrid = Extentions.FindVisualAncestor(button); IndiceArquivoDigital item = (IndiceArquivoDigital)dataGrid.Items[dataGrid.Items.IndexOf(button.DataContext)]; this.ViewModel.Baixar(item, true); this.ViewModel.Activated = true; } private void AlteraEventoAssinarOnClick(Button assinarButton, bool adiciona = true) { if (adiciona) { assinarButton.Click += new RoutedEventHandler(this.Assinar_OnClick); return; } assinarButton.Click -= new RoutedEventHandler(this.Assinar_OnClick); } private void AlteraEventoEnviarOnClick(MenuItem enviarMenu, bool adiciona = true) { if (adiciona) { enviarMenu.Click += new RoutedEventHandler(this.Enviar_OnClick); return; } enviarMenu.Click -= new RoutedEventHandler(this.Enviar_OnClick); } private void AnexarArquivos_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.Anexar(); } private void ArquivoGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { string path; if (e.EditAction != DataGridEditAction.Commit) { return; } DataGridBoundColumn column = e.Column as DataGridBoundColumn; if (column == null) { return; } Binding binding = column.Binding as Binding; if (binding != null) { path = binding.Path.Path; } else { path = null; } if (path != "Descricao") { return; } int index = e.Row.GetIndex(); TextBox editingElement = e.EditingElement as TextBox; if (editingElement == null) { return; } editingElement.Text = editingElement.Text.ToUpper(); IndiceArquivoDigital item = (IndiceArquivoDigital)this.ArquivoGrid.Items[index]; if (item.get_Descricao() == editingElement.Text) { return; } item.Initialize(); item.set_Descricao(editingElement.Text); this.ViewModel.Editar(item); } private async void Assinar_OnClick(object sender, RoutedEventArgs e) { object obj; Button button = (Button)sender; this.AlteraEventoAssinarOnClick(button, false); if (!this.ViewModel.Restricao(60)) { List produtos = LicenseHelper.Produtos; if (!produtos.All((Licenca x) => x.get_Produto() != 86)) { await this.ViewModel.EnviarParaAssinatura(); this.AlteraEventoAssinarOnClick(button, true); } else { Token token = new Token(); object[] numeroSerial = new object[] { ApplicationHelper.NumeroSerial, ApplicationHelper.IdFornecedor, Recursos.Usuario.get_Id(), null }; obj = (ApplicationHelper.Beta ? "1" : "0"); numeroSerial[3] = obj; string str = token.Encrypt(string.Format("{0}:{1}:{2}:{3}", numeroSerial)); Parameters parameter = new Parameters(); parameter.set_Beta(ApplicationHelper.Beta); parameter.set_Type(8); parameter.set_Application("Assinador.Application.exe"); parameter.set_Directory("Assinador.Application"); parameter.set_Arguments(str); parameter.set_Run(true); (new DownloadWindow(parameter)).Show(); this.AlteraEventoAssinarOnClick(button, true); } } else { await this.ViewModel.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ASSINATURA.", "OK", "", false); this.AlteraEventoAssinarOnClick(button, true); } button = null; } private void Baixar_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; if (button == null) { return; } DataGrid dataGrid = Extentions.FindVisualAncestor(button); IndiceArquivoDigital item = (IndiceArquivoDigital)dataGrid.Items[dataGrid.Items.IndexOf(button.DataContext)]; this.ViewModel.Baixar(item, false); } private async void BaixarTodos_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.Activated = false; if (await this.ViewModel.BaixarTodos()) { await this.ViewModel.ShowMessage("ARQUIVOS BAIXADOS COM SUCESSO!", "OK", "", false); } this.ViewModel.Activated = true; } private void CloseSlackBar() { Thread.Sleep(5000); System.Windows.Threading.Dispatcher dispatcher = App.ProgressRing.Dispatcher; if (dispatcher == null) { return; } dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.Toggle("", false))); } private void ContentLoad() { this.ArquivoGrid.CellEditEnding += new EventHandler(this.ArquivoGrid_CellEditEnding); this.DocumentoBox.LostFocus += new RoutedEventHandler(ArquivoDigitalDrawer.DocumentBox_OnLostFocus); this.DocumentoBox.PreviewTextInput += new TextCompositionEventHandler(ArquivoDigitalDrawer.SomenteNumeros); } private void CopiarLinkAssinatura_OnClick(object sender, RoutedEventArgs e) { IndiceArquivoDigital dataContext = (IndiceArquivoDigital)((Button)sender).DataContext; if (dataContext == null || string.IsNullOrWhiteSpace(dataContext.get_UrlAssinatura())) { return; } dataContext.get_UrlAssinatura().CopyToClipboard(); this.Toggle(string.Concat("LINK COPIADO - ", dataContext.get_UrlAssinatura()), true); } private void CopyTelefoneToClipBoard_Click(object sender, RoutedEventArgs e) { Button button = (Button)sender; ListBox listBox = Extentions.FindVisualAncestor(button); ClienteTelefone item = (ClienteTelefone)listBox.Items[listBox.Items.IndexOf(button.DataContext)]; string.Concat(item.get_Prefixo(), item.get_Numero()).CopyToClipboard(); this.Toggle(string.Concat("COPIADO - ", item.get_Prefixo(), ValidationHelper.OnlyNumber(item.get_Numero())), true); } private async Task CreateWhatsappMessage(IndiceArquivoDigital indice) { string str; string str1; Uri uri = await this.ViewModel.CreateLink(indice); StringBuilder stringBuilder = new StringBuilder(uri.ToString()); if (indice.get_Assinado()) { str = ""; } else if (indice.get_EnviadoAssinatura()) { string[] newLine = new string[] { "LINK PARA ASSINATURA", Environment.NewLine, indice.get_UrlAssinatura(), Environment.NewLine, Environment.NewLine }; str = string.Concat(newLine); } else { str = ""; } StringBuilder stringBuilder1 = new StringBuilder(str); foreach (IndiceArquivoDigital arquivo in this.ViewModel.Arquivos) { if (arquivo.get_Selecionado() && arquivo.get_IdArquivoDigital() != indice.get_IdArquivoDigital()) { if (stringBuilder.Length > 0) { stringBuilder.AppendLine("\r\n"); stringBuilder1.AppendLine(); } StringBuilder stringBuilder2 = stringBuilder; uri = await this.ViewModel.CreateLink(arquivo); stringBuilder2.AppendLine(uri.ToString()); stringBuilder2 = null; StringBuilder stringBuilder3 = stringBuilder1; if (arquivo.get_Assinado()) { str1 = ""; } else if (arquivo.get_EnviadoAssinatura()) { string[] strArrays = new string[] { "LINK PARA ASSINATURA", Environment.NewLine, arquivo.get_UrlAssinatura(), Environment.NewLine, Environment.NewLine }; str1 = string.Concat(strArrays); } else { str1 = ""; } stringBuilder3.AppendLine(str1); } } string str2 = this.ViewModel.CarregarMensagem().Replace("[*LINK*]", string.Format("LINK(S) PARA BAIXAR O(S) DOCUMENTO(S) (VÁLIDO(S) POR 7 DIAS){0}{1}", Environment.NewLine, stringBuilder)).Replace("<|LINKASSINATURA|>", stringBuilder1.ToString()); stringBuilder = null; stringBuilder1 = null; return str2; } private void DeleteArquivo_OnDeleteClick(object sender, RoutedEventArgs e) { Chip chip = sender as Chip; if (chip == null) { return; } ListBox listBox = Extentions.FindVisualAncestor(chip); Gestor.Model.Domain.Common.ArquivoDigital item = (Gestor.Model.Domain.Common.ArquivoDigital)listBox.Items[listBox.Items.IndexOf(chip.DataContext)]; if (item == null) { return; } this.ViewModel.Delete(item); } private static void DocumentBox_OnLostFocus(object sender, RoutedEventArgs e) { TextBox textBox = (TextBox)sender; if (textBox.Text == string.Empty) { return; } textBox.Text = ValidationHelper.FormatDocument(textBox.Text); } private async void Enviar_OnClick(object sender, RoutedEventArgs e) { object obj; MenuItem menuItem = (MenuItem)sender; this.AlteraEventoEnviarOnClick(menuItem, false); if (!this.ViewModel.Restricao(60)) { ObservableCollection arquivosTela = this.ViewModel.ArquivosTela; if (arquivosTela.Any((IndiceArquivoDigital x) => x.get_Assinar())) { List produtos = LicenseHelper.Produtos; if (produtos.All((Licenca x) => x.get_Produto() != 86)) { Token token = new Token(); object[] numeroSerial = new object[] { ApplicationHelper.NumeroSerial, ApplicationHelper.IdFornecedor, Recursos.Usuario.get_Id(), null }; obj = (ApplicationHelper.Beta ? "1" : "0"); numeroSerial[3] = obj; string str = token.Encrypt(string.Format("{0}:{1}:{2}:{3}", numeroSerial)); Parameters parameter = new Parameters(); parameter.set_Beta(ApplicationHelper.Beta); parameter.set_Type(8); parameter.set_Application("Assinador.Application.exe"); parameter.set_Directory("Assinador.Application"); parameter.set_Arguments(str); parameter.set_Run(true); (new DownloadWindow(parameter)).Show(); this.AlteraEventoEnviarOnClick(menuItem, true); menuItem = null; return; } else if (!await this.ViewModel.EnviarParaAssinatura()) { this.AlteraEventoEnviarOnClick(menuItem, true); menuItem = null; return; } } } else { await this.ViewModel.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ASSINATURA.\nCONTINUANDO COM O ENVIO APENAS.", "OK", "", false); } MalaDireta malaDiretum = await this.ViewModel.PrepararEnvio(); if (malaDiretum != null) { if (Funcoes.IsWindowOpen("ENVIO DE E-MAIL")) { Funcoes.Destroy("ENVIO DE E-MAIL"); } List malaDiretas = new List() { malaDiretum }; (new HosterWindow(new MalaDiretaView(malaDiretas, this.ViewModel.Assunto, this.ViewModel.Corpo, this.Filtro), "ENVIO DE E-MAIL", new double?((double)1200), new double?((double)600), true)).Show(); this.AlteraEventoEnviarOnClick(menuItem, true); } else { this.AlteraEventoEnviarOnClick(menuItem, true); } menuItem = null; } private async void EnviarPorWhatsApp_OnClick(object sender, RoutedEventArgs e) { string str; if (!this.ViewModel.Restricao(32)) { Button button = (Button)sender; if (button.DataContext != null) { ClienteTelefone dataContext = button.DataContext as ClienteTelefone; 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(this.ViewModel.Anotacoes)) { 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; } } } else { await this.ViewModel.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR O WHATSAPP", "OK", "", false); } } private async void Excluir_OnClick(object sender, RoutedEventArgs e) { IndiceArquivoDigital item; Button button = sender as Button; if (button != null) { DataGrid dataGrid = Extentions.FindVisualAncestor(button); item = (IndiceArquivoDigital)dataGrid.Items[dataGrid.Items.IndexOf(button.DataContext)]; if (item != null) { this.ViewModel.VerificarEnables(new long?(item.get_Id())); if (!this.ViewModel.EnableExcluir) { await this.ViewModel.ShowMessage(string.Concat("VOCÊ NÃO TEM PERMISSÃO PARA EXCLUIR ARQUIVO DIGITAL DO TIPO ", ValidationHelper.GetDescription(this.Filtro.get_Tipo()), "!"), "OK", "", false); } else if (item.get_NaoExcluir()) { await this.ViewModel.ShowMessage(string.Concat("O ARQUIVO ", item.get_Descricao(), " NÃO PODE SER EXCLUÍDO!"), "OK", "", false); } else if (await this.ViewModel.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR O ARQUIVO ", item.get_Descricao()), "SIM", "NÃO", false)) { await this.ViewModel.Excluir(item); } } } item = null; } private void Fechar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.CloseDrawer(); } [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/drawers/arquivodigitaldrawer.xaml", UriKind.Relative)); } private void LimparLista_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.LimparAnexos(); } private void Log_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; if (button == null) { return; } IndiceArquivoDigital dataContext = (IndiceArquivoDigital)button.DataContext; if (dataContext != null && dataContext.get_Id() != 0) { this.ViewModel.AbrirLog(6, dataContext.get_Id()); } } private async void PopupBox_OnOpened(object sender, RoutedEventArgs e) { if (this.ViewModel.Telefones.Count == 0) { ObservableCollection telefones = this.ViewModel.Telefones; ClienteTelefone clienteTelefone = new ClienteTelefone(); clienteTelefone.set_Prefixo(Recursos.Empresa.get_PrimeiroPrefixo()); clienteTelefone.set_Numero(Recursos.Empresa.get_PrimeiroTelefone()); telefones.Add(clienteTelefone); } IndiceArquivoDigital dataContext = (IndiceArquivoDigital)((PopupBox)sender).DataContext; ArquivoDigitalViewModel viewModel = this.ViewModel; viewModel.Anotacoes = await this.CreateWhatsappMessage(dataContext); viewModel = null; } private async void SalvarAnexos_OnClick(object sender, RoutedEventArgs e) { await this.ViewModel.SalvarAnexos(); } public void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { ScrollViewer scrollViewer = (ScrollViewer)sender; scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - (double)e.Delta); e.Handled = true; } private void SnackbarMessage_ActionClick(object sender, RoutedEventArgs e) { this.SnackbarArquivoDigital.set_IsActive(false); } private static void SomenteNumeros(object sender, TextCompositionEventArgs e) { Regex regex = new Regex("[^0-9]+"); e.Handled = regex.IsMatch(e.Text); } [DebuggerNonUserCode] [EditorBrowsable(EditorBrowsableState.Never)] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: { ((ScrollViewer)target).PreviewMouseWheel += new MouseWheelEventHandler(this.ScrollViewer_PreviewMouseWheel); return; } case 2: { this.ProgressBar = (System.Windows.Controls.ProgressBar)target; return; } case 3: { ((Button)target).Click += new RoutedEventHandler(this.Fechar_OnClick); return; } case 4: { this.TitleBox = (TextBlock)target; return; } case 5: case 6: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 21: { this._contentLoaded = true; return; } case 7: { ((TextBox)target).TextChanged += new TextChangedEventHandler(this.TextBoxBase_OnTextChanged); return; } case 8: { this.ArquivoGrid = (DataGrid)target; return; } case 16: { ((MenuItem)target).Click += new RoutedEventHandler(this.AnexarArquivos_OnClick); return; } case 17: { ((MenuItem)target).Click += new RoutedEventHandler(this.BaixarTodos_OnClick); return; } case 18: { ((MenuItem)target).Click += new RoutedEventHandler(this.Enviar_OnClick); return; } case 19: { this.DocumentoBox = (TextBox)target; return; } case 20: { ((Button)target).Click += new RoutedEventHandler(this.Assinar_OnClick); return; } case 22: { ((MenuItem)target).Click += new RoutedEventHandler(this.SalvarAnexos_OnClick); return; } case 23: { ((MenuItem)target).Click += new RoutedEventHandler(this.LimparLista_OnClick); return; } case 24: { this.SnackbarArquivoDigital = (Snackbar)target; return; } case 25: { ((SnackbarMessage)target).add_ActionClick(new RoutedEventHandler(this.SnackbarMessage_ActionClick)); 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) { switch (connectionId) { case 5: { ((Button)target).Click += new RoutedEventHandler(this.CopyTelefoneToClipBoard_Click); return; } case 6: { ((Button)target).Click += new RoutedEventHandler(this.WhatsAppMessage_Click); return; } case 7: case 8: case 16: case 17: case 18: case 19: case 20: { return; } case 9: { ((Button)target).Click += new RoutedEventHandler(this.CopiarLinkAssinatura_OnClick); return; } case 10: { ((PopupBox)target).add_Opened(new RoutedEventHandler(this.PopupBox_OnOpened)); return; } case 11: { ((Button)target).Click += new RoutedEventHandler(this.EnviarPorWhatsApp_OnClick); return; } case 12: { ((Button)target).Click += new RoutedEventHandler(this.Abrir_OnClick); return; } case 13: { ((Button)target).Click += new RoutedEventHandler(this.Baixar_OnClick); return; } case 14: { ((Button)target).Click += new RoutedEventHandler(this.Log_OnClick); return; } case 15: { ((Button)target).Click += new RoutedEventHandler(this.Excluir_OnClick); return; } case 21: { ((Chip)target).add_DeleteClick(new RoutedEventHandler(this.DeleteArquivo_OnDeleteClick)); return; } default: { return; } } } private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) { string text = ((TextBox)sender).Text; if (text.Length < 3) { this.ViewModel.ArquivosTela = this.ViewModel.Arquivos; return; } List list = ( from x in this.ViewModel.Arquivos where x.get_Descricao().Contains(text) select x).ToList(); if (list.Count <= 0) { this.ViewModel.ArquivosTela = new ObservableCollection(); return; } this.ViewModel.ArquivosTela = new ObservableCollection(); list.ForEach((IndiceArquivoDigital x) => this.ViewModel.ArquivosTela.Add(x)); } public void Toggle(string message, bool active = true) { this.SnackbarArquivoDigital.get_Message().Content = message; this.SnackbarArquivoDigital.set_IsActive(active); if (!active) { return; } Task.Factory.StartNew(new Action(this.CloseSlackBar)); } private async void WhatsAppMessage_Click(object sender, RoutedEventArgs e) { string str; if (!this.ViewModel.Restricao(32)) { Button button = (Button)sender; ListBox listBox = Extentions.FindVisualAncestor(button); ClienteTelefone item = (ClienteTelefone)listBox.Items[listBox.Items.IndexOf(button.DataContext)]; str = (!item.get_Tipo().HasValue || item.get_Tipo().GetValueOrDefault() != 8 ? string.Concat("55", item.get_Prefixo(), item.get_Numero().Clear()) : string.Concat(item.get_Prefixo(), item.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); } } else { await this.ViewModel.ShowMessage("VOCÊ NÃO POSSUI PERMISSÃO PARA ESSE MENU.", "OK", "", false); } } } }