summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Views/Ferramentas/EmpresaView.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Codemerx/Gestor.Application/Views/Ferramentas/EmpresaView.cs')
-rw-r--r--Codemerx/Gestor.Application/Views/Ferramentas/EmpresaView.cs424
1 files changed, 424 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/Views/Ferramentas/EmpresaView.cs b/Codemerx/Gestor.Application/Views/Ferramentas/EmpresaView.cs
new file mode 100644
index 0000000..f431ae6
--- /dev/null
+++ b/Codemerx/Gestor.Application/Views/Ferramentas/EmpresaView.cs
@@ -0,0 +1,424 @@
+using Gestor.Application.Componentes;
+using Gestor.Application.Drawers;
+using Gestor.Application.Drawers.Configuracoes;
+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.Validation;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.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.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.Ferramentas
+{
+ public class EmpresaView : BaseUserControl, IComponentConnector
+ {
+ internal DataGrid EmpresaGrid;
+
+ internal MenuItem Alterar;
+
+ internal TextBox DocumentoPrincipalBox;
+
+ internal TextBox NomeBox;
+
+ internal TextBox CepBox;
+
+ internal TextBox EnderecoBox;
+
+ internal TextBox BairroBox;
+
+ internal TextBox CidadeBox;
+
+ internal TextBox EstadoBox;
+
+ internal CustomPasswordBox SenhaBox;
+
+ private bool _contentLoaded;
+
+ public EmpresaViewModel ViewModel
+ {
+ get;
+ set;
+ }
+
+ [DebuggerNonUserCode]
+ [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
+ internal Delegate _CreateDelegate(Type delegateType, string handler)
+ {
+ return Delegate.CreateDelegate(delegateType, this, handler);
+ }
+
+ public EmpresaView()
+ {
+ base.Tag = "CADASTRO DE EMPRESA E FILIAIS";
+ this.ViewModel = new EmpresaViewModel();
+ 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, 13).get_Consultar())
+ {
+ FiltroArquivoDigital filtroArquivoDigital = new FiltroArquivoDigital();
+ filtroArquivoDigital.set_Id(this.ViewModel.SelectedEmpresa.get_Id());
+ filtroArquivoDigital.set_Tipo(13);
+ filtroArquivoDigital.set_Parente(this.ViewModel.SelectedEmpresa);
+ 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)13), "."), "OK", "", false);
+ }
+ }
+
+ private void AbrirLog_OnClick(object sender, RoutedEventArgs e)
+ {
+ this.ViewModel.AbrirLog(18, this.ViewModel.SelectedEmpresa.get_Id());
+ }
+
+ private void AbrirLogEmail_OnClick(object sender, RoutedEventArgs e)
+ {
+ this.ViewModel.AbrirLogEmail(18, this.ViewModel.SelectedEmpresa.get_Id());
+ }
+
+ private void Alterar_OnClick(object sender, RoutedEventArgs e)
+ {
+ this.ViewModel.CancelEmpresa = (Empresa)this.ViewModel.SelectedEmpresa.Clone();
+ this.ViewModel.Alterar(true);
+ this.PermissaoAuteracao();
+ this.ViewModel.PassWordReadOnly = this.ViewModel.EnableFields;
+ this.ViewModel.ConfirmacaoSenha = (this.ViewModel.SelectedEmpresa.get_Id() == (long)1 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed);
+ }
+
+ private async void AnexarLogo_OnClick(object sender, RoutedEventArgs e)
+ {
+ this.ViewModel.Loading(true);
+ await this.ViewModel.AnexarLogo();
+ this.ViewModel.Loading(false);
+ }
+
+ private void AutoCompleteBox_OnTextChanged(object sender, RoutedEventArgs e)
+ {
+ if (!string.IsNullOrWhiteSpace(((AutoCompleteBox)sender).get_Text()))
+ {
+ return;
+ }
+ this.ViewModel.FiltrarEmpresa("");
+ }
+
+ private void AutoCompleteBoxEmpresa_Populating(object sender, PopulatingEventArgs e)
+ {
+ e.set_Cancel(true);
+ this.ViewModel.Filtrar(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task<List<Empresa>> 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();
+ if (Recursos.Usuario.get_Id() == 0)
+ {
+ this.Alterar.IsEnabled = true;
+ }
+ this.NomeBox.IsReadOnly = true;
+ this.DocumentoPrincipalBox.IsReadOnly = true;
+ this.ViewModel.PassWordReadOnly = this.ViewModel.EnableFields;
+ this.ViewModel.ConfirmacaoSenha = System.Windows.Visibility.Collapsed;
+ }
+
+ private async void Configuracoes_OnClick(object sender, RoutedEventArgs e)
+ {
+ if (await this.ViewModel.VerificarRestricao(64, false, true))
+ {
+ this.ViewModel.ShowDrawer(new ConfiguracoesDrawer(), 0, false);
+ }
+ }
+
+ private void ContentLoad()
+ {
+ this.EmpresaGrid.SelectedIndex = 0;
+ this.EmpresaGrid.SelectionChanged += new SelectionChangedEventHandler(this.EmpresaGrid_OnSelectionChanged);
+ this.EmpresaGrid.MouseDoubleClick += new MouseButtonEventHandler((object sender, MouseButtonEventArgs args) => {
+ });
+ if (Recursos.Usuario.get_Id() == 0)
+ {
+ this.Alterar.IsEnabled = true;
+ }
+ }
+
+ private void DocumentoPrincipalBox_LostFocus(object sender, RoutedEventArgs e)
+ {
+ if (((TextBox)sender).IsReadOnly)
+ {
+ return;
+ }
+ string str = this.DocumentoPrincipalBox.Text.Clear();
+ 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 EmpresaGrid_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ DataGrid dataGrid = (DataGrid)sender;
+ if (dataGrid != null && dataGrid.SelectedIndex < 0)
+ {
+ return;
+ }
+ this.ViewModel.SelecionaEmpresa((Empresa)((dataGrid != null ? dataGrid.Items[dataGrid.SelectedIndex] : null)));
+ }
+
+ [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/empresaview.xaml", UriKind.Relative));
+ }
+
+ public void PermissaoAuteracao()
+ {
+ if (Recursos.Usuario.get_Id() != 0)
+ {
+ this.DocumentoPrincipalBox.IsReadOnly = true;
+ this.NomeBox.IsReadOnly = true;
+ return;
+ }
+ this.ViewModel.ConfirmacaoSenha = (this.ViewModel.SelectedEmpresa.get_Id() == (long)1 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed);
+ this.ViewModel.PassWordReadOnly = true;
+ this.Alterar.IsEnabled = false;
+ this.DocumentoPrincipalBox.IsReadOnly = false;
+ this.NomeBox.IsReadOnly = false;
+ }
+
+ private async void PostcodeBox_OnLostFocus(object sender, RoutedEventArgs e)
+ {
+ if (this.ViewModel.EnableFields)
+ {
+ string str = ValidationHelper.FormatPostCode(((TextBox)sender).Text);
+ this.CepBox.Text = str;
+ if (ValidationHelper.ValidatePostCode(str))
+ {
+ EnderecoBase enderecoBase = await this.ViewModel.BuscaCep(str);
+ if (enderecoBase != null)
+ {
+ this.EnderecoBox.Text = enderecoBase.get_Endereco();
+ this.CidadeBox.Text = enderecoBase.get_Cidade();
+ this.EstadoBox.Text = enderecoBase.get_Estado();
+ this.BairroBox.Text = enderecoBase.get_Bairro();
+ }
+ }
+ }
+ }
+
+ private async void Salvar_OnClick(object sender, RoutedEventArgs e)
+ {
+ System.Windows.Visibility visibility;
+ 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);
+ this.ViewModel.PassWordReadOnly = this.ViewModel.EnableFields;
+ EmpresaViewModel viewModel = this.ViewModel;
+ visibility = (keyValuePairs == null || keyValuePairs.Count <= 0 ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible);
+ viewModel.ConfirmacaoSenha = visibility;
+ if (Recursos.Usuario.get_Id() == 0)
+ {
+ this.Alterar.IsEnabled = true;
+ this.NomeBox.IsReadOnly = true;
+ this.DocumentoPrincipalBox.IsReadOnly = true;
+ }
+ 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:
+ {
+ ((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, EmpresaView.AutoCompleteBoxEmpresa_Populating));
+ ((AutoCompleteBox)target).add_TextChanged(new RoutedEventHandler(this.AutoCompleteBox_OnTextChanged));
+ return;
+ }
+ case 2:
+ {
+ this.EmpresaGrid = (DataGrid)target;
+ return;
+ }
+ case 3:
+ {
+ this.Alterar = (MenuItem)target;
+ this.Alterar.Click += new RoutedEventHandler(this.Alterar_OnClick);
+ return;
+ }
+ case 4:
+ {
+ ((MenuItem)target).Click += new RoutedEventHandler(this.Salvar_OnClick);
+ return;
+ }
+ case 5:
+ {
+ ((MenuItem)target).Click += new RoutedEventHandler(this.Cancelar_OnClick);
+ return;
+ }
+ case 6:
+ {
+ ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirAquivoDigital_Click);
+ return;
+ }
+ case 7:
+ {
+ ((MenuItem)target).Click += new RoutedEventHandler(this.AnexarLogo_OnClick);
+ return;
+ }
+ case 8:
+ {
+ ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLog_OnClick);
+ return;
+ }
+ case 9:
+ {
+ ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLogEmail_OnClick);
+ return;
+ }
+ case 10:
+ {
+ ((MenuItem)target).Click += new RoutedEventHandler(this.Configuracoes_OnClick);
+ return;
+ }
+ case 11:
+ {
+ this.DocumentoPrincipalBox = (TextBox)target;
+ this.DocumentoPrincipalBox.LostFocus += new RoutedEventHandler(this.DocumentoPrincipalBox_LostFocus);
+ EmpresaView empresaView = this;
+ this.DocumentoPrincipalBox.PreviewTextInput += new TextCompositionEventHandler(empresaView.SomenteNumeros);
+ return;
+ }
+ case 12:
+ {
+ this.NomeBox = (TextBox)target;
+ return;
+ }
+ case 13:
+ {
+ this.CepBox = (TextBox)target;
+ this.CepBox.LostFocus += new RoutedEventHandler(this.PostcodeBox_OnLostFocus);
+ EmpresaView empresaView1 = this;
+ this.CepBox.PreviewTextInput += new TextCompositionEventHandler(empresaView1.SomenteNumeros);
+ return;
+ }
+ case 14:
+ {
+ this.EnderecoBox = (TextBox)target;
+ return;
+ }
+ case 15:
+ {
+ this.BairroBox = (TextBox)target;
+ return;
+ }
+ case 16:
+ {
+ this.CidadeBox = (TextBox)target;
+ return;
+ }
+ case 17:
+ {
+ this.EstadoBox = (TextBox)target;
+ return;
+ }
+ case 18:
+ {
+ this.SenhaBox = (CustomPasswordBox)target;
+ return;
+ }
+ case 19:
+ {
+ EmpresaView empresaView2 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(empresaView2.SomenteNumeros);
+ return;
+ }
+ case 20:
+ {
+ EmpresaView empresaView3 = this;
+ ((TextBox)target).LostFocus += new RoutedEventHandler(empresaView3.FormatarTelefone);
+ EmpresaView empresaView4 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(empresaView4.SomenteNumeros);
+ return;
+ }
+ case 21:
+ {
+ EmpresaView empresaView5 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(empresaView5.SomenteNumeros);
+ return;
+ }
+ case 22:
+ {
+ EmpresaView empresaView6 = this;
+ ((TextBox)target).LostFocus += new RoutedEventHandler(empresaView6.FormatarTelefone);
+ EmpresaView empresaView7 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(empresaView7.SomenteNumeros);
+ return;
+ }
+ case 23:
+ {
+ EmpresaView empresaView8 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(empresaView8.SomenteNumeros);
+ return;
+ }
+ case 24:
+ {
+ EmpresaView empresaView9 = this;
+ ((TextBox)target).PreviewTextInput += new TextCompositionEventHandler(empresaView9.SomenteNumeros);
+ return;
+ }
+ }
+ this._contentLoaded = true;
+ }
+ }
+} \ No newline at end of file