From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../Views/Ferramentas/CadastroEmailView.cs | 400 +++++++++++++++++++++ 1 file changed, 400 insertions(+) create mode 100644 Codemerx/Gestor.Application/Views/Ferramentas/CadastroEmailView.cs (limited to 'Codemerx/Gestor.Application/Views/Ferramentas/CadastroEmailView.cs') diff --git a/Codemerx/Gestor.Application/Views/Ferramentas/CadastroEmailView.cs b/Codemerx/Gestor.Application/Views/Ferramentas/CadastroEmailView.cs new file mode 100644 index 0000000..d4691ca --- /dev/null +++ b/Codemerx/Gestor.Application/Views/Ferramentas/CadastroEmailView.cs @@ -0,0 +1,400 @@ +using Gestor.Application.Componentes; +using Gestor.Application.Helpers; +using Gestor.Application.ViewModels.Ferramentas; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Ferramentas; +using Gestor.Model.Domain.Generic; +using System; +using System.CodeDom.Compiler; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; +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; + +namespace Gestor.Application.Views.Ferramentas +{ + public class CadastroEmailView : UserControl, IComponentConnector + { + internal DataGrid CredenciaisGrid; + + internal MenuItem SalvarApoliceButton; + + internal MenuItem CancelarApoliceButton; + + internal MenuItem MaisOpcoesButton; + + internal TextBox DescricaoBox; + + internal TextBox HeaderBox; + + internal ComboBox TipoBox; + + internal TextBox PortaBox; + + internal TextBox DominioBox; + + internal TextBox EmailBox; + + internal CustomPasswordBox SenhaBox; + + internal TextBox LoginBox; + + internal TextBlock CabecalhoTitulo; + + internal WebEditor Cabecalho; + + internal TextBlock AssinaturaTitulo; + + internal WebEditor Assinatura; + + private bool _contentLoaded; + + public CadastroEmailViewModel ViewModel + { + get; + set; + } + + [DebuggerNonUserCode] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + internal Delegate _CreateDelegate(Type delegateType, string handler) + { + return Delegate.CreateDelegate(delegateType, this, handler); + } + + public CadastroEmailView() + { + base.Tag = "CADASTRO DE E-MAIL"; + this.ViewModel = new CadastroEmailViewModel(); + 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(17, this.ViewModel.SelectedCredencial.get_Id()); + } + + private void Alterar_OnClick(object sender, RoutedEventArgs e) + { + this.Assinatura.Visibility = System.Windows.Visibility.Visible; + this.AssinaturaTitulo.Visibility = System.Windows.Visibility.Visible; + this.Cabecalho.Visibility = System.Windows.Visibility.Visible; + this.CabecalhoTitulo.Visibility = System.Windows.Visibility.Visible; + this.ViewModel.Alterar(true); + this.ValidarTela(); + this.ViewModel.SelectedCredencial.Initialize(); + } + + private void AutoCompleteBox_OnTextChanged(object sender, RoutedEventArgs e) + { + if (!string.IsNullOrWhiteSpace(((AutoCompleteBox)sender).get_Text())) + { + return; + } + this.ViewModel.FiltrarCredenciais(""); + } + + private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e) + { + e.set_Cancel(true); + this.ViewModel.Filtrar(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task> searchResult) => { + if (searchResult.Result == null) + { + return; + } + AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; + autoCompleteBox.set_ItemsSource(searchResult.Result); + autoCompleteBox.PopulateComplete(); + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + + private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.Loading(true); + bool flag = await this.ViewModel.EnviarTesteEmail(); + this.ViewModel.Loading(false); + if (flag) + { + this.ViewModel.ToggleSnackBar("E-MAIL ENVIADO COM SUCESSO.", true); + } + } + + private async void Cancelar_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.Loading(true); + await this.ViewModel.CancelarAlteracao(); + this.Assinatura.Initialize(null); + this.Assinatura.Visibility = System.Windows.Visibility.Collapsed; + this.AssinaturaTitulo.Visibility = System.Windows.Visibility.Collapsed; + this.Cabecalho.Initialize(null); + this.Cabecalho.Visibility = System.Windows.Visibility.Collapsed; + this.CabecalhoTitulo.Visibility = System.Windows.Visibility.Collapsed; + this.ViewModel.Loading(false); + this.ScrollToItem(); + } + + private async void ContentLoad() + { + this.ViewModel.Loading(true); + await this.ViewModel.SelecionaCredenciais(); + this.ViewModel.Loading(false); + } + + private void EmailBox_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) + { + if (((TextBox)sender).Text.Contains("@gmail.com")) + { + this.TipoBox.SelectedItem = (TipoEmail)1; + } + } + + private async void Excluir_OnClick(object sender, RoutedEventArgs e) + { + await this.ViewModel.Excluir(); + this.ScrollToItem(); + } + + private void Incluir_OnClick(object sender, RoutedEventArgs e) + { + this.Assinatura.Visibility = System.Windows.Visibility.Visible; + this.AssinaturaTitulo.Visibility = System.Windows.Visibility.Visible; + this.ViewModel.Incluir(); + this.ValidarTela(); + } + + [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/ferramentas/cadastroemailview.xaml", UriKind.Relative)); + } + + public string ReplaceLocalImages(string mailBody) + { + string[] array = ( + from Match m in Regex.Matches(mailBody, "", RegexOptions.IgnoreCase) + select m.Groups[0].Value).ToArray(); + for (int i = 0; i < (int)array.Length; i++) + { + string value = Regex.Match(array[i], "(?<=src=\")(.*?)(?=\")", RegexOptions.IgnoreCase).Value; + string str = Regex.Match(value, "file:(///).*\\.(.*)", RegexOptions.IgnoreCase).Groups[2].Value; + if (str == "jpg") + { + str = "jpeg"; + } + if (Uri.IsWellFormedUriString(value, UriKind.Absolute)) + { + Uri uri = new Uri(value); + if (File.Exists(uri.LocalPath)) + { + mailBody = mailBody.Replace(value, string.Concat("data:image/", str, ";base64,", Convert.ToBase64String(File.ReadAllBytes(uri.LocalPath)))); + } + } + } + return mailBody; + } + + private async void Salvar_OnClick(object sender, RoutedEventArgs e) + { + bool flag; + this.ViewModel.Loading(true); + this.ViewModel.SelectedCredencial.set_Assinatura(this.ReplaceLocalImages(this.Assinatura.GetHtml())); + this.ViewModel.SelectedCredencial.set_Cabecalho(this.ReplaceLocalImages(this.Cabecalho.GetHtml())); + List> keyValuePairs = await this.ViewModel.Salvar(); + this.ValidateFields(keyValuePairs, true); + flag = (keyValuePairs == null ? true : keyValuePairs.Count == 0); + this.ViewModel.Loading(false); + if (!flag) + { + await this.ViewModel.ShowMessage(keyValuePairs, this.ViewModel.ErroCamposInvalidos, "OK", ""); + } + else + { + this.Assinatura.Visibility = System.Windows.Visibility.Collapsed; + this.AssinaturaTitulo.Visibility = System.Windows.Visibility.Collapsed; + this.Cabecalho.Visibility = System.Windows.Visibility.Collapsed; + this.CabecalhoTitulo.Visibility = System.Windows.Visibility.Collapsed; + this.ScrollToItem(); + } + } + + private void ScrollToItem() + { + if (this.CredenciaisGrid.SelectedItem == null) + { + return; + } + this.CredenciaisGrid.UpdateLayout(); + this.CredenciaisGrid.ScrollIntoView(this.CredenciaisGrid.SelectedItem); + } + + [DebuggerNonUserCode] + [EditorBrowsable(EditorBrowsableState.Never)] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) + { + switch (connectionId) + { + case 1: + { + ((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, CadastroEmailView.AutoCompleteBox_Populating)); + ((AutoCompleteBox)target).add_TextChanged(new RoutedEventHandler(this.AutoCompleteBox_OnTextChanged)); + return; + } + case 2: + { + this.CredenciaisGrid = (DataGrid)target; + return; + } + case 3: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Incluir_OnClick); + return; + } + case 4: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Alterar_OnClick); + return; + } + case 5: + { + this.SalvarApoliceButton = (MenuItem)target; + this.SalvarApoliceButton.Click += new RoutedEventHandler(this.Salvar_OnClick); + return; + } + case 6: + { + this.CancelarApoliceButton = (MenuItem)target; + this.CancelarApoliceButton.Click += new RoutedEventHandler(this.Cancelar_OnClick); + return; + } + case 7: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Excluir_OnClick); + return; + } + case 8: + { + this.MaisOpcoesButton = (MenuItem)target; + return; + } + case 9: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.ButtonBase_OnClick); + return; + } + case 10: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLog_OnClick); + return; + } + case 11: + { + this.DescricaoBox = (TextBox)target; + return; + } + case 12: + { + this.HeaderBox = (TextBox)target; + return; + } + case 13: + { + this.TipoBox = (ComboBox)target; + this.TipoBox.SelectionChanged += new SelectionChangedEventHandler(this.Tipo_OnSelectionChanged); + return; + } + case 14: + { + this.PortaBox = (TextBox)target; + return; + } + case 15: + { + this.DominioBox = (TextBox)target; + return; + } + case 16: + { + this.EmailBox = (TextBox)target; + this.EmailBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.EmailBox_OnLostKeyboardFocus); + return; + } + case 17: + { + this.SenhaBox = (CustomPasswordBox)target; + return; + } + case 18: + { + this.LoginBox = (TextBox)target; + return; + } + case 19: + { + this.CabecalhoTitulo = (TextBlock)target; + return; + } + case 20: + { + this.Cabecalho = (WebEditor)target; + return; + } + case 21: + { + this.AssinaturaTitulo = (TextBlock)target; + return; + } + case 22: + { + this.Assinatura = (WebEditor)target; + return; + } + } + this._contentLoaded = true; + } + + private void Tipo_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + TipoEmail? selectedItem = (TipoEmail?)((ComboBox)sender).SelectedItem; + if (selectedItem.GetValueOrDefault() == 0 & selectedItem.HasValue && this.ViewModel.SelectedCredencial.get_Email() != null && this.ViewModel.SelectedCredencial.get_Email().Contains("@gmail.com")) + { + this.EmailBox.Text = ""; + } + } + + private void ValidarTela() + { + if (this.ViewModel.SelectedCredencial == null) + { + return; + } + List> keyValuePairs = this.ViewModel.SelectedCredencial.Validate(); + this.ValidateFields(keyValuePairs, false); + } + } +} \ No newline at end of file -- cgit v1.2.3