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.Generic; using Gestor.Model.Domain.Seguros; using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Collections.ObjectModel; 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.Data; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Threading; namespace Gestor.Application.Views.Seguros.Itens { public class RiscosDiversosView : BaseUserControl, IComponentConnector, IStyleConnector { public RiscosDiversosViewModel ViewModel; private readonly MenuItemViewModel _menuItemViewModel; private bool _salvando; internal MenuItem IncluirItemButton; internal MenuItem SinistroButton; internal RadioButton CoberturasRadioButton; internal RadioButton MaisInformacoesRadioButton; internal Menu BotoesTitulares; internal Separator SeparadorMaisInformacoes; internal System.Windows.Controls.ContentControl ContentControl; internal DataGrid DataGridTitulares; private bool _contentLoaded; [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public RiscosDiversosView(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 RiscosDiversosViewModel(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 ", 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 AlterarTitular_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AlterarTitular(); } private void AplicarTitular_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.AplicarTitular(); } private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e) { if (e.get_Parameter().Trim().Length < 3) { return; } e.set_Cancel(true); this.ViewModel.BuscarTitulares(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 BotoesTitulares_OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) { bool flag; if (!((Menu)sender).IsEnabled) { this.ViewModel.AlteracaoTitularesVisibility = System.Windows.Visibility.Collapsed; } DataGrid dataGridTitulares = this.DataGridTitulares; if (dataGridTitulares != null) { flag = dataGridTitulares.Columns.First(); } else { flag = false; } if (!flag) { return; } this.DataGridTitulares.Columns.First().Visibility = (((Menu)sender).IsEnabled ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed); } private void Cancelar_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.CancelarAlteracao(); } 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 DataGridTitulares_OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { string text; string str; string text1; if (!(e.EditingElement is TextBox)) { return; } TextBox editingElement = e.EditingElement as TextBox; string stringFormat = e.Column.ClipboardContentBinding.StringFormat; if (stringFormat == "d") { if (editingElement != null) { text = editingElement.Text; } else { text = null; } if (!string.IsNullOrEmpty(text)) { editingElement.Text = ValidationHelper.FormatDate(editingElement.Text); return; } if (editingElement != null) { editingElement.Text = null; return; } } else if (stringFormat == "c") { if (editingElement != null) { str = editingElement.Text; } else { str = null; } if (!string.IsNullOrEmpty(str)) { editingElement.Text = ValidationHelper.FormatCurrency(editingElement.Text); return; } if (editingElement != null) { editingElement.Text = null; } } else { if (editingElement != null) { text1 = editingElement.Text; } else { text1 = null; } if (!string.IsNullOrEmpty(text1)) { if (e.Column.SortMemberPath == "Cpf") { editingElement.Text = ValidationHelper.FormatDocument(editingElement.Text); return; } } else if (editingElement != null) { editingElement.Text = null; return; } } } private void Dependente_CellLoaded(object sender, RoutedEventArgs e) { bool valueOrDefault; if (sender == null) { return; } DataGridCell dataGridCell = (DataGridCell)sender; TitularesVida dataContext = (TitularesVida)((DataGridCell)sender).DataContext; if (dataContext != null) { valueOrDefault = dataContext.get_Tipo().GetValueOrDefault() == 2; } else { valueOrDefault = false; } dataGridCell.Visibility = (valueOrDefault ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed); } 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.DataGridTitulares.Visibility = System.Windows.Visibility.Collapsed; this.SeparadorMaisInformacoes.Visibility = System.Windows.Visibility.Collapsed; this.BotoesTitulares.Visibility = System.Windows.Visibility.Collapsed; this.DataGridTitulares.ClearInvalid(); this.ContentControl.ClearInvalid(); if (radioButton.Name != "MaisInformacoesRadioButton") { this.ContentControl.Visibility = System.Windows.Visibility.Visible; this.ViewModel.CarregaCobertura(); return; } this.SeparadorMaisInformacoes.Visibility = System.Windows.Visibility.Visible; this.DataGridTitulares.Visibility = System.Windows.Visibility.Visible; this.BotoesTitulares.Visibility = System.Windows.Visibility.Visible; } 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 void ExcluirTitular_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.ExcluirTitular(); } private async void ImportarTitulares_OnClick(object sender, RoutedEventArgs e) { await this.ViewModel.ImportarTitulares(); } private async void Incluir_OnClick(object sender, RoutedEventArgs e) { await this.ViewModel.Incluir(false); List> keyValuePairs = this.ViewModel.SelectedItem.Validate(); this.ValidateFields(keyValuePairs, true); } private void IncluirTitular_OnClick(object sender, RoutedEventArgs e) { this.ViewModel.IncluirTitular(); this.UpdateAutocompleteDependente(this.DataGridTitulares.Items.Cast().First()); } [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/riscosdiversosview.xaml", UriKind.Relative)); } 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); } public async void Salvar_OnClick(object sender, RoutedEventArgs e) { bool flag; this._salvando = true; this.ViewModel.Loading(true); this.DataGridTitulares.Focus(); List> keyValuePairs = await this.ViewModel.Salvar(this.DataGridTitulares.Items.Cast().ToList()); this.ValidateFields(keyValuePairs, true); flag = (keyValuePairs == null ? true : keyValuePairs.Count == 0); this.ViewModel.Loading(false); this._salvando = 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); } 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: { this.CoberturasRadioButton = (RadioButton)target; return; } case 12: { this.MaisInformacoesRadioButton = (RadioButton)target; return; } case 13: { this.BotoesTitulares = (Menu)target; this.BotoesTitulares.IsEnabledChanged += new DependencyPropertyChangedEventHandler(this.BotoesTitulares_OnIsEnabledChanged); return; } case 14: { ((MenuItem)target).Click += new RoutedEventHandler(this.IncluirTitular_OnClick); return; } case 15: { ((MenuItem)target).Click += new RoutedEventHandler(this.AlterarTitular_OnClick); return; } case 16: { ((MenuItem)target).Click += new RoutedEventHandler(this.ExcluirTitular_OnClick); return; } case 17: { ((MenuItem)target).Click += new RoutedEventHandler(this.ImportarTitulares_OnClick); return; } case 18: { this.SeparadorMaisInformacoes = (Separator)target; return; } case 19: { ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 20: { ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 21: { ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 22: { RiscosDiversosView riscosDiversosView = this; ((TextBox)target).LostFocus += new RoutedEventHandler(riscosDiversosView.FormatarDocumento); RiscosDiversosView riscosDiversosView1 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(riscosDiversosView1.SomenteNumeros); return; } case 23: { ((MenuItem)target).Click += new RoutedEventHandler(this.AplicarTitular_OnClick); return; } case 24: { this.ContentControl = (System.Windows.Controls.ContentControl)target; return; } case 25: { this.DataGridTitulares = (DataGrid)target; this.DataGridTitulares.CellEditEnding += new EventHandler(this.DataGridTitulares_OnCellEditEnding); return; } } this._contentLoaded = true; } [DebuggerNonUserCode] [EditorBrowsable(EditorBrowsableState.Never)] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target) { switch (connectionId) { case 26: { ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 27: { ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 28: { ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 29: { RiscosDiversosView riscosDiversosView = this; ((TextBox)target).LostFocus += new RoutedEventHandler(riscosDiversosView.FormatarDocumento); RiscosDiversosView riscosDiversosView1 = this; ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(riscosDiversosView1.SomenteNumeros); return; } case 30: { ((ComboBox)target).SelectionChanged += new SelectionChangedEventHandler(this.TipoComboBoxSelectionChanged); return; } case 31: { ((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, RiscosDiversosView.AutoCompleteBox_Populating)); return; } case 32: { EventSetter eventSetter = new EventSetter() { Event = FrameworkElement.LoadedEvent, Handler = new RoutedEventHandler(this.Dependente_CellLoaded) }; ((System.Windows.Style)target).Setters.Add(eventSetter); return; } default: { return; } } } private async void TipoComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { bool dataContext; ComboBox comboBox = (ComboBox)sender; if (comboBox != null) { dataContext = comboBox.DataContext; } else { dataContext = false; } if (dataContext) { TipoTitular? nullable = ((TitularesVida)((ComboBox)sender).DataContext).get_Tipo(); if (nullable.GetValueOrDefault() == 2 && !this._salvando) { ObservableCollection titulares = this.ViewModel.Titulares; if (!titulares.Any((TitularesVida x) => { TipoTitular? tipo = x.get_Tipo(); if (tipo.GetValueOrDefault() == 1) { return true; } tipo = x.get_Tipo(); return tipo.GetValueOrDefault() == 0 & tipo.HasValue; })) { ((ComboBox)sender).SelectedIndex = -1; nullable = null; ((TitularesVida)((ComboBox)sender).DataContext).set_Tipo(nullable); await this.ViewModel.ShowMessage("É NECESSÁRIO ADICIONAR PELO MENOS UM TITULAR DO TIPO SÓCIO OU FUNCIONÁRIO\nANTES DE ADICIONAR UM DEPENDENTE.", "OK", "", false); return; } } this.UpdateAutocompleteDependente((TitularesVida)((ComboBox)sender).DataContext); } } private void UpdateAutocompleteDependente(TitularesVida item) { this.DataGridTitulares.ScrollIntoView(item, this.DataGridTitulares.Columns.First((DataGridColumn x) => (string)x.Header == "TITULAR DEPENDENTE")); this.DataGridTitulares.UpdateLayout(); DataGridRow dataGridRow = (DataGridRow)this.DataGridTitulares.ItemContainerGenerator.ContainerFromItem(item); if (dataGridRow == null) { return; } ((DataGridCell)DataGridExtensions.GetVisualChild(dataGridRow).ItemContainerGenerator.ContainerFromIndex(12)).Visibility = (item.get_Tipo().GetValueOrDefault() == 2 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed); this.DataGridTitulares.ScrollIntoView(item, this.DataGridTitulares.Columns.First()); this.DataGridTitulares.UpdateLayout(); } } }