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/Seguros/TrocarClienteView.cs | 154 +++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Codemerx/Gestor.Application/Views/Seguros/TrocarClienteView.cs (limited to 'Codemerx/Gestor.Application/Views/Seguros/TrocarClienteView.cs') diff --git a/Codemerx/Gestor.Application/Views/Seguros/TrocarClienteView.cs b/Codemerx/Gestor.Application/Views/Seguros/TrocarClienteView.cs new file mode 100644 index 0000000..61be59b --- /dev/null +++ b/Codemerx/Gestor.Application/Views/Seguros/TrocarClienteView.cs @@ -0,0 +1,154 @@ +using Gestor.Application.ViewModels.Generic; +using Gestor.Application.ViewModels.Seguros; +using Gestor.Application.Views.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Domain.Seguros; +using MaterialDesignThemes.Wpf; +using System; +using System.CodeDom.Compiler; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Markup; +using System.Windows.Threading; + +namespace Gestor.Application.Views.Seguros +{ + public class TrocarClienteView : BaseUserControl, IComponentConnector + { + public TrocarClienteViewModel ViewModel; + + internal System.Windows.Controls.ProgressBar ProgressBar; + + internal MaterialDesignThemes.Wpf.Snackbar Snackbar; + + private bool _contentLoaded; + + [DebuggerNonUserCode] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + internal Delegate _CreateDelegate(Type delegateType, string handler) + { + return Delegate.CreateDelegate(delegateType, this, handler); + } + + public TrocarClienteView(Documento documento) + { + this.ViewModel = new TrocarClienteViewModel() + { + SelectedDocumento = documento + }; + base.DataContext = this.ViewModel; + this.InitializeComponent(); + } + + private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e) + { + if (e.get_Parameter().Length < 3) + { + return; + } + e.set_Cancel(true); + this.ViewModel.BuscarCliente(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim()), null, 2).ContinueWith((Task> searchResult) => { + if (searchResult.Result == null) + { + return; + } + AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; + autoCompleteBox.set_ItemsSource(searchResult.Result); + autoCompleteBox.PopulateComplete(); + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + + private void CloseSlackBar() + { + Thread.Sleep(5000); + System.Windows.Threading.Dispatcher dispatcher = this.ProgressBar.Dispatcher; + if (dispatcher == null) + { + return; + } + dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.ToggleSnackBar("", false))); + } + + [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/seguros/trocarclienteview.xaml", UriKind.Relative)); + } + + private async void Salvar_OnClick(object sender, RoutedEventArgs e) + { + if (!await this.ViewModel.Salvar()) + { + this.ToggleSnackBar("ERRO AO TROCAR CLIENTE.", true); + } + else + { + this.ToggleSnackBar("CLIENTE TROCADO COM SUCESSO.", true); + } + } + + private void SnackbarMessage_ActionClick(object sender, RoutedEventArgs e) + { + this.Snackbar.set_IsActive(false); + } + + [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.ProgressBar = (System.Windows.Controls.ProgressBar)target; + return; + } + case 2: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick); + return; + } + case 3: + { + ((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, TrocarClienteView.AutoCompleteBox_Populating)); + return; + } + case 4: + { + this.Snackbar = (MaterialDesignThemes.Wpf.Snackbar)target; + return; + } + case 5: + { + ((SnackbarMessage)target).add_ActionClick(new RoutedEventHandler(this.SnackbarMessage_ActionClick)); + return; + } + } + this._contentLoaded = true; + } + + public void ToggleSnackBar(string message, bool active = true) + { + this.Snackbar.get_Message().Content = message; + this.Snackbar.set_IsActive(active); + if (!active) + { + return; + } + Task.Factory.StartNew(new Action(this.CloseSlackBar)); + } + } +} \ No newline at end of file -- cgit v1.2.3