using Gestor.Application.Actions; using Gestor.Application.Componentes; using Gestor.Application.Drawers; using Gestor.Application.Helpers; using Gestor.Application.Servicos; using Gestor.Application.ViewModels; using Gestor.Application.ViewModels.Generic; using Gestor.Application.ViewModels.Seguros; using Gestor.Application.ViewModels.Seguros.Itens; using Gestor.Application.Views.Generic; using Gestor.Application.Views.Seguros; using Gestor.Common.Validation; using Gestor.Model.Common; using Gestor.Model.Domain.Common; using Gestor.Model.Domain.Configuracoes; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using Gestor.Model.Helper; 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.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.Seguros.Itens { public class AutoView : BaseUserControl, IComponentConnector { public AutoViewModel ViewModel; private readonly MenuItemViewModel _menuItemViewModel; internal MenuItem IncluirItemButton; internal MenuItem SinistroButton; internal WrapPanel PainelDadosAuto; internal TextBox FipeBox; internal AutoCompleteBox AutoCompleteFabricacao; internal TextBox ModeloBox; internal TextBox AnoModeloBox; internal TextBox CepCirculacaoBox; internal TextBox CepPernoiteBox; internal ComboBox ComboBoxTipoCorrecao; internal RadioButton CoberturasRadioButton; internal RadioButton MaisInformacoesRadioButton; internal System.Windows.Controls.ContentControl ContentControl; internal CustomItemValidation MaisInformacoes; private bool _contentLoaded; [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public AutoView(MenuItemViewModel menuItemViewModel, bool lockInsert = false, bool substituir = false, ManutencaoItem manutencao = null, Item itemSelecionado = null, Ramo ramo = null, bool endossoRenovacao = false) { this._menuItemViewModel = menuItemViewModel; this.ViewModel = new AutoViewModel(substituir, manutencao, itemSelecionado, ramo, endossoRenovacao); 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 { } if (!lockInsert) { return; } this.IncluirItemButton.IsEnabled = false; this.SinistroButton.Visibility = System.Windows.Visibility.Collapsed; } private async void AbrirAquivoDigital_Click(object sender, RoutedEventArgs e) { if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 4).get_Consultar()) { FiltroArquivoDigital filtroArquivoDigital = new FiltroArquivoDigital(); filtroArquivoDigital.set_Id(this.ViewModel.SelectedItem.get_Id()); filtroArquivoDigital.set_IdApolice(this.ViewModel.SelectedItem.get_Documento().get_Id()); filtroArquivoDigital.set_Tipo(4); filtroArquivoDigital.set_Parente(this.ViewModel.SelectedItem); 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 ", Gestor.Common.Validation.ValidationHelper.GetDescription((TipoArquivoDigital)4), "."), "OK", "", false); } } private void AbrirLog_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AbrirLog(3, this.ViewModel.SelectedItem.get_Id()); } private void AbrirLogEmail_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AbrirLogEmail(3, this.ViewModel.SelectedItem.get_Id()); } private void Alterar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.Alterar(true); } private void AutoCompleteFabricanteBox_Populating(object sender, PopulatingEventArgs e) { if (e.get_Parameter().Length < 3) { return; } e.set_Cancel(true); this.ViewModel.BuscaFabricante(Gestor.Common.Validation.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 BaixarXls_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.BaixarXls(); } private async void BuscarModelo_OnClick(object sender, RoutedEventArgs e) { Fipe fipe = await this.ViewModel.ShowBuscaModeloDialog(this.ModeloBox.Text, this.AnoModeloBox.Text); Fipe fipe1 = fipe; if (fipe1 != null) { this.FipeBox.Text = fipe1.get_Codigo(); this.ModeloBox.Text = fipe1.get_Modelo(); this.AutoCompleteFabricacao.set_Text(fipe1.get_Marca()); this.ViewModel.SelectedItem.get_Auto().set_Fabricante(this.ViewModel.Fabricantes.FirstOrDefault((Fabricante x) => x.get_Descricao() == fipe1.get_Marca())); } } private void Cancelar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.CancelarAlteracao(); } private void Cep_OnLostFocus(object sender, RoutedEventArgs e) { bool auto; TextBox textBox = (TextBox)sender; Item selectedItem = this.ViewModel.SelectedItem; if (selectedItem != null) { auto = selectedItem.get_Auto(); } else { auto = false; } if (!auto) { return; } if (string.IsNullOrWhiteSpace(textBox.Text)) { return; } if ((textBox.Name == "CepCirculacaoBox" || textBox.Name == "CepPernoiteBox") && Gestor.Common.Validation.ValidationHelper.ValidaCep(textBox.Text)) { return; } if (!Gestor.Model.Helper.ValidationHelper.ValidacaoCep(Gestor.Common.Validation.ValidationHelper.FormatPostCode(textBox.Text))) { return; } textBox.Text = Gestor.Common.Validation.ValidationHelper.FormatPostCode(textBox.Text); } private void Ci_OnLostFocus(object sender, RoutedEventArgs e) { TextBox textBox = (TextBox)sender; textBox.Text = Gestor.Common.Validation.ValidationHelper.FormatCi(textBox.Text); } private void ComboBoxTipoCorrecao_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.ComboBoxTipoCorrecao.SelectedItem == null) { return; } this.ViewModel.Atualiza(this.ComboBoxTipoCorrecao.SelectedItem.ToString().ToUpper()); } private void ContentLoad() { this.CoberturasRadioButton.Checked += new RoutedEventHandler(this.Documento_OnChecked); this.MaisInformacoesRadioButton.Checked += new RoutedEventHandler(this.Documento_OnChecked); } private void CopyCodItem(object sender, MouseButtonEventArgs e) { this.ViewModel.CodigoItem.CopyToClipboard(); this.ViewModel.ToggleSnackBar(string.Concat("COPIADO - ", this.ViewModel.CodigoItem), true); } private void Documento_OnChecked(object sender, RoutedEventArgs e) { RadioButton radioButton = (RadioButton)sender; if (string.IsNullOrEmpty(radioButton.GroupName)) { return; } this.ViewModel.Descarregar(); this.ContentControl.Visibility = System.Windows.Visibility.Collapsed; this.MaisInformacoes.Visibility = System.Windows.Visibility.Collapsed; this.MaisInformacoes.ClearInvalid(); this.ContentControl.ClearInvalid(); if (radioButton.Name == "MaisInformacoesRadioButton") { this.MaisInformacoes.Visibility = System.Windows.Visibility.Visible; return; } this.ContentControl.Visibility = System.Windows.Visibility.Visible; this.ViewModel.CarregaCobertura(); } private async void Excluir_OnClick(object sender, RoutedEventArgs e) { if (await this.ViewModel.Excluir()) { MenuItemViewModel menuItemViewModel = this._menuItemViewModel; if (menuItemViewModel != null) { menuItemViewModel.RecarregarItens(null); } else { } } } private async void Fipe_LostFocus(object sender, RoutedEventArgs e) { int num; bool auto; object obj; TextBox textBox = (TextBox)sender; Item selectedItem = this.ViewModel.SelectedItem; if (selectedItem != null) { auto = selectedItem.get_Auto(); } else { auto = false; } if (auto) { if (!string.IsNullOrWhiteSpace(textBox.Text)) { string str = Gestor.Model.Helper.ValidationHelper.FormataFipe(textBox.Text.Replace("-", "")); if (Gestor.Model.Helper.ValidationHelper.ValidaFipe(str)) { textBox.Text = str; if (!int.TryParse(Gestor.Model.Helper.ValidationHelper.OnlyNumber(str), out num) || num != 0) { Fipe fipe = await this.ViewModel.BuscaModelo(textBox.Text); if (fipe != null) { this.ModeloBox.Text = fipe.get_Modelo(); AutoCompleteBox autoCompleteFabricacao = this.AutoCompleteFabricacao; List fabricantes = this.ViewModel.Fabricantes; if (fabricantes != null) { obj = fabricantes.FirstOrDefault((Fabricante x) => x.get_Descricao() == fipe.get_Marca()); } else { obj = null; } autoCompleteFabricacao.set_SelectedItem(obj); } else { this.ViewModel.ToggleSnackBar(string.Concat("MODELO NÃO ENCONTRADO PARA O CÓDIGO FIPE ", textBox.Text), true); } } } } } textBox = null; } private async void ImportarXls_OnClick(object sender, RoutedEventArgs e) { bool flag; this.ViewModel.Loading(true); Action enablePesquisarClientes = Gestor.Application.Actions.Actions.EnablePesquisarClientes; if (enablePesquisarClientes != null) { enablePesquisarClientes(false); } else { } Action enableMenu = Gestor.Application.Actions.Actions.EnableMenu; if (enableMenu != null) { enableMenu(false); } else { } Action enableMainMenu = Gestor.Application.Actions.Actions.EnableMainMenu; if (enableMainMenu != null) { enableMainMenu(false); } else { } List> keyValuePairs = await this.ViewModel.ImportarXls(); flag = (keyValuePairs == null ? true : keyValuePairs.Count == 0); Action action = Gestor.Application.Actions.Actions.EnablePesquisarClientes; if (action != null) { action(true); } else { } Action enableMenu1 = Gestor.Application.Actions.Actions.EnableMenu; if (enableMenu1 != null) { enableMenu1(true); } else { } Action enableMainMenu1 = Gestor.Application.Actions.Actions.EnableMainMenu; if (enableMainMenu1 != null) { enableMainMenu1(true); } else { } this.ViewModel.Loading(false); if (!flag) { await this.ViewModel.ShowMessage(keyValuePairs, this.ViewModel.ErroCamposInvalidos, "OK", ""); } else if (this.ViewModel.SelectedItem.get_Id() > (long)0) { MenuItemViewModel menuItemViewModel = this._menuItemViewModel; if (menuItemViewModel != null) { menuItemViewModel.RecarregarItens(this.ViewModel.SelectedItem); } else { } } } private async void Incluir_OnClick(object sender, RoutedEventArgs e) { await this.ViewModel.Incluir(false); Item selectedItem = this.ViewModel.SelectedItem; List configuracoes = Recursos.Configuracoes; bool flag = configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 18); List configuracaoSistemas = Recursos.Configuracoes; List> keyValuePairs = selectedItem.Validate(flag, configuracaoSistemas.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 27)); this.ValidateFields(keyValuePairs, true); } [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/itens/autoview.xaml", UriKind.Relative)); } private void KeyUpBase_OnKeyUp(object sender, KeyEventArgs e) { TextBox textBox = (TextBox)sender; if (!Regex.IsMatch(textBox.Text.Replace(".", ""), "^[0-9.]{11}$")) { textBox.Text = Regex.Replace(textBox.Text, "[^\\d]*", ""); } } public void Manter(ManutencaoItem manutencao) { this.ViewModel.Manter(ConsultaViewModel.ItemSelecionado, manutencao); } private void MenuItem_OnClick(object sender, RoutedEventArgs e) { double? nullable = null; double? nullable1 = nullable; nullable = null; (new HosterWindow(new SinistroView(this.ViewModel.SelectedItem, false), string.Concat("CADASTRO DE SINISTROS - ", this.ViewModel.SelectedItem.get_Descricao()), nullable1, nullable, false)).ShowDialog(); MenuItemViewModel menuItemViewModel = this._menuItemViewModel; if (menuItemViewModel == null) { return; } menuItemViewModel.RecarregarItens(this.ViewModel.SelectedItem); } private void Placa(object sender, KeyEventArgs e) { Gestor.Model.Helper.ValidationHelper.FormataPlaca(((TextBox)sender).Text); } private void Renavam_OnLostFocus(object sender, RoutedEventArgs e) { TextBox textBox = (TextBox)sender; textBox.Text = Gestor.Common.Validation.ValidationHelper.FormatRenavam(textBox.Text); } public async void Salvar_OnClick(object sender, RoutedEventArgs e) { bool flag; this.ViewModel.Loading(true); this.FipeBox.Focus(); 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 if (this.ViewModel.SelectedItem.get_Id() > (long)0) { MenuItemViewModel menuItemViewModel = this._menuItemViewModel; if (menuItemViewModel != null) { menuItemViewModel.RecarregarItens(this.ViewModel.SelectedItem); } else { } } } public async Task Selecionar(Item item) { await this.ViewModel.SelecionaItem(item, true); } private void SelecionaUsoVeiculo(object sender, SelectionChangedEventArgs e) { if (this.ViewModel.UsoVeiculo.GetValueOrDefault() == 2 || this.ViewModel.UsoVeiculo.GetValueOrDefault() == 3) { this.ViewModel.SelectedItem.get_Auto().set_Categoria(new Categoria?(3)); } } public void Substituir() { this.ViewModel.Substituir(ConsultaViewModel.ItemSelecionado); } [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.IncluirItemButton = (MenuItem)target; this.IncluirItemButton.Click += new RoutedEventHandler(this.Incluir_OnClick); return; } case 2: { ((MenuItem)target).Click += new RoutedEventHandler(this.Alterar_OnClick); return; } case 3: { ((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick); return; } case 4: { ((MenuItem)target).Click += new RoutedEventHandler(this.Cancelar_OnClick); return; } case 5: { ((MenuItem)target).Click += new RoutedEventHandler(this.Excluir_OnClick); return; } case 6: { ((TextBox)target).MouseDoubleClick += new MouseButtonEventHandler(this.CopyCodItem); return; } case 7: { ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirAquivoDigital_Click); return; } case 8: { this.SinistroButton = (MenuItem)target; this.SinistroButton.Click += new RoutedEventHandler(this.MenuItem_OnClick); return; } case 9: { ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLog_OnClick); return; } case 10: { ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLogEmail_OnClick); return; } case 11: { ((MenuItem)target).Click += new RoutedEventHandler(this.ImportarXls_OnClick); return; } case 12: { ((MenuItem)target).Click += new RoutedEventHandler(this.BaixarXls_OnClick); return; } case 13: { this.PainelDadosAuto = (WrapPanel)target; return; } case 14: { this.FipeBox = (TextBox)target; AutoView autoView = this; this.FipeBox.PreviewTextInput += new TextCompositionEventHandler(autoView.SomenteNumeros); this.FipeBox.LostFocus += new RoutedEventHandler(this.Fipe_LostFocus); return; } case 15: { AutoView autoView1 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(autoView1.Placa); ((TextBox)target).PreviewKeyDown += new KeyEventHandler(this.Placa); return; } case 16: { this.AutoCompleteFabricacao = (AutoCompleteBox)target; this.AutoCompleteFabricacao.add_Populating(new PopulatingEventHandler(this, AutoView.AutoCompleteFabricanteBox_Populating)); return; } case 17: { this.ModeloBox = (TextBox)target; return; } case 18: { ((Button)target).Click += new RoutedEventHandler(this.BuscarModelo_OnClick); return; } case 19: { ((ComboBox)target).SelectionChanged += new SelectionChangedEventHandler(this.SelecionaUsoVeiculo); return; } case 20: { AutoView autoView2 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(autoView2.SomenteNumeros); ((TextBox)target).LostFocus += new RoutedEventHandler(this.Renavam_OnLostFocus); ((TextBox)target).PreviewKeyUp += new KeyEventHandler(this.KeyUpBase_OnKeyUp); return; } case 21: { ((ToggleButton)target).Checked += new RoutedEventHandler(this.ZeroKmToggleButton_Changed); ((ToggleButton)target).Unchecked += new RoutedEventHandler(this.ZeroKmToggleButton_Changed); return; } case 22: { AutoView autoView3 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(autoView3.SomenteNumeros); return; } case 23: { this.AnoModeloBox = (TextBox)target; AutoView autoView4 = this; this.AnoModeloBox.PreviewTextInput += new TextCompositionEventHandler(autoView4.SomenteNumeros); return; } case 24: { AutoView autoView5 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(autoView5.SomenteNumeros); return; } case 25: { AutoView autoView6 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(autoView6.SomenteNumeros); return; } case 26: { this.CepCirculacaoBox = (TextBox)target; this.CepCirculacaoBox.LostFocus += new RoutedEventHandler(this.Cep_OnLostFocus); AutoView autoView7 = this; this.CepCirculacaoBox.PreviewTextInput += new TextCompositionEventHandler(autoView7.SomenteNumeros); return; } case 27: { this.CepPernoiteBox = (TextBox)target; this.CepPernoiteBox.LostFocus += new RoutedEventHandler(this.Cep_OnLostFocus); AutoView autoView8 = this; this.CepPernoiteBox.PreviewTextInput += new TextCompositionEventHandler(autoView8.SomenteNumeros); return; } case 28: { this.ComboBoxTipoCorrecao = (ComboBox)target; this.ComboBoxTipoCorrecao.SelectionChanged += new SelectionChangedEventHandler(this.ComboBoxTipoCorrecao_SelectionChanged); return; } case 29: { ((TextBox)target).LostFocus += new RoutedEventHandler(this.Ci_OnLostFocus); AutoView autoView9 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(autoView9.SomenteNumeros); return; } case 30: { AutoView autoView10 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(autoView10.SomenteNumeros); return; } case 31: { this.CoberturasRadioButton = (RadioButton)target; return; } case 32: { this.MaisInformacoesRadioButton = (RadioButton)target; return; } case 33: { this.ContentControl = (System.Windows.Controls.ContentControl)target; return; } case 34: { this.MaisInformacoes = (CustomItemValidation)target; return; } } this._contentLoaded = true; } private void ZeroKmToggleButton_Changed(object sender, RoutedEventArgs e) { if (this.ViewModel.SelectedItem == null) { return; } List> keyValuePairs = this.ViewModel.SelectedItem.Validate(); this.ValidateFields(keyValuePairs, true); } } }