using CurrencyTextBoxControl; using Gestor.Application.Drawers; using Gestor.Application.Helpers; using Gestor.Application.Servicos; using Gestor.Application.ViewModels.Ferramentas; using Gestor.Application.ViewModels.Generic; using Gestor.Application.Views.Generic; using Gestor.Common.Helpers; using Gestor.Common.Validation; using Gestor.Model.Common; using Gestor.Model.Domain.Configuracoes; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; 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.Ferramentas { public class SeguradoraView : BaseUserControl, IComponentConnector, IStyleConnector { public SeguradoraViewModel ViewModel; internal DataGrid SeguradoraGrid; internal DataGridTextColumn NomeField; internal DataGridTextColumn ApelidoField; internal MenuItem MaisOpcoesButton; internal ToggleButton AtivoBox; internal TextBox DocumentoPrincipalBox; internal TextBox AssistenciaBox; internal TextBox SusepBox; internal TextBox CodigoCiaBox; internal TextBox LinkAppAndroidBox; internal TextBox LinkAppIosBox; internal CurrencyTextBox ToleranciaComissaoBox; internal CurrencyTextBox ToleranciaPremioBox; internal TextBox ObservacaoBox; internal ListBox ContatosListBox; internal ListBox EnderecoSeguradoraBox; private bool _contentLoaded; [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public SeguradoraView() { base.Tag = "CADASTRO DE SEGURADORA"; this.Tela = 13; this.ViewModel = new SeguradoraViewModel(); 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 async void AbrirAquivoDigital_Click(object sender, RoutedEventArgs e) { if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 8).get_Consultar()) { FiltroArquivoDigital filtroArquivoDigital = new FiltroArquivoDigital(); filtroArquivoDigital.set_Id(this.ViewModel.SelectedSeguradora.get_Id()); filtroArquivoDigital.set_Tipo(8); filtroArquivoDigital.set_Parente(this.ViewModel.SelectedSeguradora); 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 ", EnumHelper.GetDescription(8), "."), "OK", "", false); } } private void AbrirLog_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AbrirLog(13, this.ViewModel.SelectedSeguradora.get_Id()); } private void AbrirLogEmail_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AbrirLogEmail(13, this.ViewModel.SelectedSeguradora.get_Id()); } private void Alterar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.Clonar(); this.ViewModel.Alterar(true); this.ValidarTela(); } private void AutoCompleteBox_OnTextChanged(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(((AutoCompleteBox)sender).get_Text())) { return; } this.ViewModel.FiltrarSeguradora(""); } private void AutoCompleteBoxDescricao_OnTextChanged(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(((AutoCompleteBox)sender).get_Text())) { return; } this.ViewModel.FiltrarDescricao(""); } private void AutoCompleteBoxDescricao_Populating(object sender, PopulatingEventArgs e) { e.set_Cancel(true); this.ViewModel.FiltrarConfig(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 void AutoCompleteBoxSeguradora_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 void Cancelar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.CancelarAlteracao(); } private void ContentLoad() { this.SeguradoraGrid.SelectedIndex = 0; this.SeguradoraGrid.SelectionChanged += new SelectionChangedEventHandler(this.SeguradoraGrid_OnSelectionChanged); this.SeguradoraGrid.MouseDoubleClick += new MouseButtonEventHandler((object sender, MouseButtonEventArgs args) => { }); this.NomeField.Visibility = (this.ViewModel.Apelido ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible); this.ApelidoField.Visibility = (!this.ViewModel.Apelido ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible); } private void DocumentoPrincipalBox_LostFocus(object sender, RoutedEventArgs e) { if (((TextBox)sender).IsReadOnly) { return; } string str = ValidationHelper.Clear(this.DocumentoPrincipalBox.Text); if (string.IsNullOrEmpty(str)) { return; } this.DocumentoPrincipalBox.Text = (str.Length == 11 ? ValidationHelper.FormatDocument(str.PadLeft(11, '0').Substring(0, 11)) : ValidationHelper.FormatDocument(str.PadLeft(14, '0').Substring(0, 14))); } private void ExcluirEndereco_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; if (button == null) { return; } ListBox listBox = Extentions.FindVisualAncestor(button); SeguradoraEndereco item = (SeguradoraEndereco)listBox.Items[listBox.Items.IndexOf(button.DataContext)]; this.ViewModel.ExcluirEndereco(item); } private void ExcluirTelefone_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; if (button == null) { return; } ListBox listBox = Extentions.FindVisualAncestor(button); SeguradoraContato item = (SeguradoraContato)listBox.Items[listBox.Items.IndexOf(button.DataContext)]; this.ViewModel.ExcluirTelefone(item); } private async void Impostos_OnClick(object sender, RoutedEventArgs e) { List configuracoes = Recursos.Configuracoes; if (configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 5)) { await this.ViewModel.ShowMessage("RECURSO NÃO HABILITADO, ACESSE AS CONFIGURAÇÕES DENTRO DO CADASTRO DE EMPRESAS E FILIAIS PARA HABILITAR O RECURSO.", "OK", "", false); } else if (await this.ViewModel.VerificarPermissao(56, false)) { this.ViewModel.ShowDrawer(new ImpostoDrawer(0, this.ViewModel.SelectedSeguradora.get_Id()), 0, false); } } private void Incluir_OnClick(object sender, RoutedEventArgs e) { IncluirSeguradoraView incluirSeguradoraView = new IncluirSeguradoraView(this.ViewModel.Seguradoras); (new HosterWindow(incluirSeguradoraView, "INCLUIR SEGURADORA", new double?((double)500), new double?((double)600), false)).ShowDialog(); if (incluirSeguradoraView.ViewModel.AdicionarSeguradora != null) { this.ViewModel.Incluir(incluirSeguradoraView.ViewModel.AdicionarSeguradora); } } private void IncluirEndereco_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.IncluirEndereco(); this.ValidarTela(); } private void IncluirTelefone_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.IncluirTelefone(); 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/seguradoraview.xaml", UriKind.Relative)); } public async void Metas_Click(object sender, RoutedEventArgs e) { this.ViewModel.Loading(true); if (await this.ViewModel.VerificarPermissao(31, false)) { this.ViewModel.ShowDrawer(new MetaSeguradoraView(this.ViewModel.SelectedSeguradora), 0, false); this.ViewModel.Loading(false); } } private async void PostcodeBox_OnLostFocus(object sender, RoutedEventArgs e) { ContentPresenter contentPresenter; DataTemplate contentTemplate; TextBox textBox = (TextBox)sender; string str = ValidationHelper.FormatPostCode(textBox.Text); if (ValidationHelper.ValidatePostCode(str)) { ListBox listBox = Extentions.FindVisualAncestor(textBox); ListBoxItem listBoxItem = (ListBoxItem)listBox.ItemContainerGenerator.ContainerFromIndex(listBox.Items.IndexOf(textBox.DataContext)); contentPresenter = FindVisualChild.Find(listBoxItem); contentTemplate = contentPresenter.ContentTemplate; ((TextBox)contentTemplate.FindName("CepBox", contentPresenter)).Text = str; EnderecoBase enderecoBase = await this.ViewModel.BuscaCep(str); if (enderecoBase != null) { TextBox endereco = (TextBox)contentTemplate.FindName("EnderecoBox", contentPresenter); TextBox cidade = (TextBox)contentTemplate.FindName("CidadeBox", contentPresenter); TextBox estado = (TextBox)contentTemplate.FindName("EstadoBox", contentPresenter); TextBox bairro = (TextBox)contentTemplate.FindName("BairroBox", contentPresenter); endereco.Text = enderecoBase.get_Endereco(); cidade.Text = enderecoBase.get_Cidade(); estado.Text = enderecoBase.get_Estado(); bairro.Text = enderecoBase.get_Bairro(); } } contentPresenter = null; contentTemplate = null; } private async void Salvar_OnClick(object sender, RoutedEventArgs e) { bool flag; this.ViewModel.Loading(true); this.ViewModel.SelectedSeguradora.set_NomeSocial(this.ViewModel.SelectedSeguradora.get_NomeSocialBanco().Trim()); if ((this.ToleranciaComissaoBox.get_Number() > new decimal(2) || this.ToleranciaPremioBox.get_Number() > new decimal(2)) && (this.ViewModel.Tolerancia != this.ToleranciaComissaoBox.get_Number() || this.ViewModel.Tolerancia != this.ToleranciaPremioBox.get_Number())) { bool? nullable = await this.ViewModel.ShowSenha("TOLERÂNCIA DE COMISSÃO, DIFERENÇA IMPORTAÇÃO OU REPASSE MAIOR QUE R$2,00, PREENCHA A SENHA ADM PARA PROSSEGUIR."); if (!nullable.HasValue) { this.ViewModel.Loading(false); return; } else if (!nullable.GetValueOrDefault()) { await this.ViewModel.ShowMessage("SENHA INVÁLIDA", "OK", "", false); this.ViewModel.Loading(false); return; } } 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", ""); } } private void SeguradoraGrid_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { DataGrid dataGrid = (DataGrid)sender; if (dataGrid != null && dataGrid.SelectedIndex < 0) { return; } this.ViewModel.SelecionaSeguradora((Seguradora)((dataGrid != null ? dataGrid.Items[dataGrid.SelectedIndex] : null))); } public void Selector_ContactChanged(object sender, SelectionChangedEventArgs e) { this.ViewModel.TipoTelefoneVisibility = System.Windows.Visibility.Visible; this.ViewModel.TelefoneVisibility = System.Windows.Visibility.Visible; this.ViewModel.PrefixoVisibility = System.Windows.Visibility.Visible; } [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, SeguradoraView.AutoCompleteBoxSeguradora_Populating)); ((AutoCompleteBox)target).add_TextChanged(new RoutedEventHandler(this.AutoCompleteBox_OnTextChanged)); return; } case 2: { ((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, SeguradoraView.AutoCompleteBoxSeguradora_Populating)); ((AutoCompleteBox)target).add_TextChanged(new RoutedEventHandler(this.AutoCompleteBox_OnTextChanged)); return; } case 3: { this.SeguradoraGrid = (DataGrid)target; return; } case 4: { this.NomeField = (DataGridTextColumn)target; return; } case 5: { this.ApelidoField = (DataGridTextColumn)target; return; } case 6: { ((MenuItem)target).Click += new RoutedEventHandler(this.Incluir_OnClick); return; } case 7: { ((MenuItem)target).Click += new RoutedEventHandler(this.Alterar_OnClick); return; } case 8: { ((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick); return; } case 9: { ((MenuItem)target).Click += new RoutedEventHandler(this.Cancelar_OnClick); return; } case 10: { ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirAquivoDigital_Click); return; } case 11: { this.MaisOpcoesButton = (MenuItem)target; return; } case 12: { ((MenuItem)target).Click += new RoutedEventHandler(this.Metas_Click); return; } case 13: { ((MenuItem)target).Click += new RoutedEventHandler(this.Impostos_OnClick); return; } case 14: { ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLog_OnClick); return; } case 15: { ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLogEmail_OnClick); return; } case 16: { this.AtivoBox = (ToggleButton)target; return; } case 17: { this.DocumentoPrincipalBox = (TextBox)target; SeguradoraView seguradoraView = this; this.DocumentoPrincipalBox.PreviewTextInput += new TextCompositionEventHandler(seguradoraView.SomenteNumeros); this.DocumentoPrincipalBox.LostFocus += new RoutedEventHandler(this.DocumentoPrincipalBox_LostFocus); return; } case 18: { this.AssistenciaBox = (TextBox)target; return; } case 19: { this.SusepBox = (TextBox)target; return; } case 20: { this.CodigoCiaBox = (TextBox)target; return; } case 21: { this.LinkAppAndroidBox = (TextBox)target; return; } case 22: { this.LinkAppIosBox = (TextBox)target; return; } case 23: { this.ToleranciaComissaoBox = (CurrencyTextBox)target; return; } case 24: { this.ToleranciaPremioBox = (CurrencyTextBox)target; return; } case 25: { this.ObservacaoBox = (TextBox)target; return; } case 26: { ((MenuItem)target).Click += new RoutedEventHandler(this.IncluirTelefone_OnClick); return; } case 27: { this.ContatosListBox = (ListBox)target; return; } case 28: case 29: case 30: case 31: case 34: case 35: case 36: { this._contentLoaded = true; return; } case 32: { ((MenuItem)target).Click += new RoutedEventHandler(this.IncluirEndereco_OnClick); return; } case 33: { this.EnderecoSeguradoraBox = (ListBox)target; return; } case 37: { ((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, SeguradoraView.AutoCompleteBoxDescricao_Populating)); ((AutoCompleteBox)target).add_TextChanged(new RoutedEventHandler(this.AutoCompleteBoxDescricao_OnTextChanged)); 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 28: { ((ComboBox)target).SelectionChanged += new SelectionChangedEventHandler(this.Selector_ContactChanged); return; } case 29: { SeguradoraView seguradoraView = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(seguradoraView.SomenteNumeros); return; } case 30: { SeguradoraView seguradoraView1 = this; ((TextBox)target).LostFocus += new RoutedEventHandler(seguradoraView1.FormatarTelefone); SeguradoraView seguradoraView2 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(seguradoraView2.SomenteNumeros); return; } case 31: { ((Button)target).Click += new RoutedEventHandler(this.ExcluirTelefone_OnClick); return; } case 32: case 33: { return; } case 34: { ((TextBox)target).LostFocus += new RoutedEventHandler(this.PostcodeBox_OnLostFocus); SeguradoraView seguradoraView3 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(seguradoraView3.SomenteNumeros); return; } case 35: { SeguradoraView seguradoraView4 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(seguradoraView4.SomenteNumeros); return; } case 36: { ((Button)target).Click += new RoutedEventHandler(this.ExcluirEndereco_OnClick); return; } default: { return; } } } private void ValidarTela() { object keyValuePairs; object obj; if (this.ViewModel.SelectedSeguradora == null) { return; } List> keyValuePairs1 = this.ViewModel.SelectedSeguradora.Validate(); List> keyValuePairs2 = keyValuePairs1; SeguradoraContato seguradoraContato = this.ViewModel.Contatos.FirstOrDefault(); if (seguradoraContato != null) { keyValuePairs = seguradoraContato.Validate(); } else { keyValuePairs = null; } if (keyValuePairs == null) { keyValuePairs = new List>(); } keyValuePairs2.AddRange((IEnumerable)keyValuePairs); List> keyValuePairs3 = keyValuePairs1; SeguradoraEndereco seguradoraEndereco = this.ViewModel.Enderecos.FirstOrDefault(); if (seguradoraEndereco != null) { obj = seguradoraEndereco.Validate(); } else { obj = null; } if (obj == null) { obj = new List>(); } keyValuePairs3.AddRange((IEnumerable)obj); this.ValidateFields(keyValuePairs1, false); } } }