summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Views/Seguros/PerfilView.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Codemerx/Gestor.Application/Views/Seguros/PerfilView.cs')
-rw-r--r--Codemerx/Gestor.Application/Views/Seguros/PerfilView.cs320
1 files changed, 320 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/Views/Seguros/PerfilView.cs b/Codemerx/Gestor.Application/Views/Seguros/PerfilView.cs
new file mode 100644
index 0000000..2a23628
--- /dev/null
+++ b/Codemerx/Gestor.Application/Views/Seguros/PerfilView.cs
@@ -0,0 +1,320 @@
+using Gestor.Application.Helpers;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Application.ViewModels.Seguros;
+using Gestor.Application.Views.Generic;
+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.ComponentModel;
+using System.Diagnostics;
+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
+{
+ public class PerfilView : BaseUserControl, IComponentConnector
+ {
+ public PerfilViewModel ViewModel;
+
+ private Controle _controle;
+
+ internal MenuItem CancelarApoliceButton;
+
+ internal DatePicker NascimentoBox;
+
+ private bool _contentLoaded;
+
+ [DebuggerNonUserCode]
+ [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
+ internal Delegate _CreateDelegate(Type delegateType, string handler)
+ {
+ return Delegate.CreateDelegate(delegateType, this, handler);
+ }
+
+ public PerfilView(Controle controle)
+ {
+ this._controle = controle;
+ base.Tag = "CADASTRO DE PERFIL";
+ this.ViewModel = new PerfilViewModel(controle);
+ 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 Alterar_OnClick(object sender, RoutedEventArgs e)
+ {
+ this.ViewModel.Alterar(true);
+ this.ValidarTela();
+ }
+
+ private void Cancelar_OnClick(object sender, RoutedEventArgs e)
+ {
+ this.ViewModel.CancelarAlteracao();
+ }
+
+ private void ContentLoad()
+ {
+ this.NascimentoBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(Funcoes.DatePicker_OnLostKeyboardFocus);
+ this.NascimentoBox.PreviewKeyDown += new KeyEventHandler(Funcoes.DatePicker_PreviewKeyDown);
+ }
+
+ private void CpfBox_OnLostFocus(object sender, RoutedEventArgs e)
+ {
+ TextBox textBox = (TextBox)sender;
+ textBox.Text = ValidationHelper.FormatDocument(textBox.Text);
+ }
+
+ private async void Excluir_OnClick(object sender, RoutedEventArgs e)
+ {
+ await this.ViewModel.Excluir();
+ }
+
+ private void Incluir_OnClick(object sender, RoutedEventArgs e)
+ {
+ 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/seguros/perfilview.xaml", UriKind.Relative));
+ }
+
+ private void PostcodeBox_OnLostFocus(object sender, RoutedEventArgs e)
+ {
+ TextBox textBox = (TextBox)sender;
+ if (string.IsNullOrWhiteSpace(textBox.Text))
+ {
+ return;
+ }
+ string str = ValidationHelper.FormatPostCode(textBox.Text);
+ if (!ValidationHelper.ValidatePostCode(str))
+ {
+ return;
+ }
+ textBox.Text = str;
+ }
+
+ private void RelacaoComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ string documento;
+ TimeSpan? nullable;
+ if (((ComboBox)sender).SelectedIndex == 0)
+ {
+ Cliente cliente = this._controle.get_Cliente();
+ if (cliente != null)
+ {
+ documento = cliente.get_Documento();
+ }
+ else
+ {
+ documento = null;
+ }
+ string str = ValidationHelper.FormatDocument(ValidationHelper.Clear(documento));
+ bool flag = Regex.IsMatch(str, "\\d{3}\\.\\d{3}\\.\\d{3}-\\d{2}");
+ Perfil perfil = (Perfil)this.ViewModel.SelectedPerfil.Clone();
+ perfil.set_Cpf((flag ? str : ""));
+ perfil.set_Nome(this._controle.get_Cliente().get_Nome());
+ perfil.set_Nascimento(this._controle.get_Cliente().get_Nascimento());
+ perfil.set_Sexo(this._controle.get_Cliente().get_Sexo());
+ perfil.set_EstadoCivil(this._controle.get_Cliente().get_EstadoCivil());
+ perfil.set_Habilitacao(this._controle.get_Cliente().get_Habilitacao());
+ DateTime? primeiraHabilitacao = this._controle.get_Cliente().get_PrimeiraHabilitacao();
+ if (primeiraHabilitacao.HasValue)
+ {
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ primeiraHabilitacao = this._controle.get_Cliente().get_PrimeiraHabilitacao();
+ if (primeiraHabilitacao.HasValue)
+ {
+ nullable = new TimeSpan?(networkTime - primeiraHabilitacao.GetValueOrDefault());
+ }
+ else
+ {
+ nullable = null;
+ }
+ TimeSpan? nullable1 = nullable;
+ if (nullable1.Value.Days > 3650)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(10));
+ }
+ else if (nullable1.Value.Days > 3285)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(9));
+ }
+ else if (nullable1.Value.Days > 2920)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(8));
+ }
+ else if (nullable1.Value.Days > 2555)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(7));
+ }
+ else if (nullable1.Value.Days > 2190)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(6));
+ }
+ else if (nullable1.Value.Days > 1825)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(5));
+ }
+ else if (nullable1.Value.Days > 1460)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(4));
+ }
+ else if (nullable1.Value.Days > 1095)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(3));
+ }
+ else if (nullable1.Value.Days > 730)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(2));
+ }
+ else if (nullable1.Value.Days <= 365)
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(0));
+ }
+ else
+ {
+ perfil.set_TempoHabilitacao(new TempoHabilitacao?(1));
+ }
+ }
+ this.ViewModel.SelectedPerfil = perfil;
+ }
+ }
+
+ private async void Salvar_OnClick(object sender, RoutedEventArgs e)
+ {
+ bool flag;
+ this.ViewModel.Loading(true);
+ List<KeyValuePair<string, string>> 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", "");
+ }
+ }
+
+ [DebuggerNonUserCode]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
+ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
+ {
+ switch (connectionId)
+ {
+ case 1:
+ {
+ ((MenuItem)target).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:
+ {
+ this.CancelarApoliceButton = (MenuItem)target;
+ this.CancelarApoliceButton.Click += new RoutedEventHandler(this.Cancelar_OnClick);
+ return;
+ }
+ case 5:
+ {
+ ((MenuItem)target).Click += new RoutedEventHandler(this.Excluir_OnClick);
+ return;
+ }
+ case 6:
+ {
+ ((ComboBox)target).SelectionChanged += new SelectionChangedEventHandler(this.RelacaoComboBox_OnSelectionChanged);
+ return;
+ }
+ case 7:
+ {
+ ((TextBox)target).LostFocus += new RoutedEventHandler(this.CpfBox_OnLostFocus);
+ PerfilView perfilView = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(perfilView.SomenteNumeros);
+ return;
+ }
+ case 8:
+ {
+ this.NascimentoBox = (DatePicker)target;
+ this.NascimentoBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus);
+ this.NascimentoBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick);
+ return;
+ }
+ case 9:
+ {
+ PerfilView perfilView1 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(perfilView1.SomenteNumeros);
+ return;
+ }
+ case 10:
+ {
+ PerfilView perfilView2 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(perfilView2.SomenteNumeros);
+ return;
+ }
+ case 11:
+ {
+ PerfilView perfilView3 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(perfilView3.SomenteNumeros);
+ return;
+ }
+ case 12:
+ {
+ ((TextBox)target).LostFocus += new RoutedEventHandler(this.PostcodeBox_OnLostFocus);
+ PerfilView perfilView4 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(perfilView4.SomenteNumeros);
+ return;
+ }
+ case 13:
+ {
+ ((TextBox)target).LostFocus += new RoutedEventHandler(this.PostcodeBox_OnLostFocus);
+ PerfilView perfilView5 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(perfilView5.SomenteNumeros);
+ return;
+ }
+ }
+ this._contentLoaded = true;
+ }
+
+ private void ValidarTela()
+ {
+ if (this.ViewModel.SelectedPerfil == null)
+ {
+ return;
+ }
+ List<KeyValuePair<string, string>> keyValuePairs = this.ViewModel.SelectedPerfil.Validate();
+ this.ValidateFields(keyValuePairs, false);
+ }
+ }
+} \ No newline at end of file