From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- Gestor.Application/Views/LoginWindow.cs | 825 -------------------------------- 1 file changed, 825 deletions(-) delete mode 100644 Gestor.Application/Views/LoginWindow.cs (limited to 'Gestor.Application/Views/LoginWindow.cs') diff --git a/Gestor.Application/Views/LoginWindow.cs b/Gestor.Application/Views/LoginWindow.cs deleted file mode 100644 index 96cac36..0000000 --- a/Gestor.Application/Views/LoginWindow.cs +++ /dev/null @@ -1,825 +0,0 @@ -using Agger.Registro; -using Gestor.Application; -using Gestor.Application.Componentes; -using Gestor.Application.Helpers; -using Gestor.Application.Servicos.Ajuda; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.ViewModels; -using Gestor.Application.ViewModels.Generic; -using Gestor.Application.Views.Ferramentas; -using Gestor.Infrastructure.UnitOfWork.Generic; -using Gestor.Infrastructure.UnitOfWork.Logic; -using Gestor.Model.API; -using Gestor.Model.Domain.Common; -using Gestor.Model.Domain.Generic; -using Gestor.Model.Domain.Seguros; -using Gestor.Model.License; -using Newtonsoft.Json.Linq; -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.Net; -using System.Net.Http; -using System.Net.Sockets; -using System.Reflection; -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.Media; -using System.Windows.Shapes; -using System.Windows.Threading; - -namespace Gestor.Application.Views -{ - public class LoginWindow : Window, IComponentConnector - { - internal LoginViewModel ViewModel; - - private bool _buttonClickable; - - private DispatcherTimer _carouselTimer; - - internal Image ProgressRing; - - internal TextBox UserBox; - - internal CustomSenhaLoginBox PasswordBox; - - internal TextBlock TrocaSenha; - - internal CustomSenhaLoginBox SenhaBox; - - internal CustomSenhaLoginBox ConfirmacaoBox; - - internal TextBox ChaveBox; - - internal Grid MinimizeButton; - - internal Grid CloseButton; - - private bool _contentLoaded; - - public bool Bloquear - { - get; - set; - } - - private JArray LoginSettings - { - get; - set; - } - - [DebuggerNonUserCode] - [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] - internal Delegate _CreateDelegate(Type delegateType, string handler) - { - return Delegate.CreateDelegate(delegateType, this, handler); - } - - public LoginWindow() - { - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; - this.ViewModel = new LoginViewModel(); - base.DataContext = this.ViewModel; - this.InitializeComponent(); - this.MinimizeButton.MouseEnter += new MouseEventHandler(LoginWindow.TopControls_OnMouseEnter); - this.MinimizeButton.MouseLeave += new MouseEventHandler(this.TopControls_OnMouseLeave); - this.CloseButton.MouseEnter += new MouseEventHandler(LoginWindow.TopControls_OnMouseEnter); - this.CloseButton.MouseLeave += new MouseEventHandler(this.TopControls_OnMouseLeave); - this.ViewModel.Head = string.Concat("AGGER GESTOR ", this.ViewModel.Version, " - AGUARDE ESTAMOS INICIALIZANDO"); - } - - private async Task Access(bool error = true) - { - string str; - if (string.IsNullOrEmpty(this.ViewModel.Login) || string.IsNullOrEmpty(this.ViewModel.Senha)) - { - if (error) - { - this.ViewModel.ErrorLoginVisibility = System.Windows.Visibility.Visible; - } - this.UserBox.Focus(); - } - else - { - this.Loading(true); - if (await this.ViewModel.Validate(this.ViewModel.Login, this.ViewModel.Senha)) - { - bool bloquear = this.Bloquear; - if (!bloquear) - { - bloquear = await this.VerificarAcesso(); - } - this.Bloquear = bloquear; - if (!this.Bloquear) - { - DateTime networkTime = Funcoes.GetNetworkTime(); - if (Recursos.Usuario.get_Id() > (long)0) - { - RegistroLog registroLog = new RegistroLog(); - registroLog.set_Acao(0); - registroLog.set_Usuario(Recursos.Usuario); - registroLog.set_DataHora(networkTime); - registroLog.set_Descricao(string.Format("O USUÁRIO {0} LOGOU NO SISTEMA, EM {1}.", Recursos.Usuario.get_Nome(), networkTime)); - registroLog.set_EntidadeId(Recursos.Usuario.get_Id()); - registroLog.set_Tela(49); - registroLog.set_Versao(LoginViewModel.VersaoAtual); - registroLog.set_NomeMaquina(Environment.MachineName); - registroLog.set_UsuarioMaquina(Environment.UserName); - IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList; - IPAddress pAddress = ((IEnumerable)addressList).FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork); - if (pAddress != null) - { - str = pAddress.ToString(); - } - else - { - str = null; - } - registroLog.set_Ip(str); - RegistroLog registroLog1 = registroLog; - using (UnitOfWork commited = Instancia.Commited) - { - (new BaseServico()).SaveLog(registroLog1, commited); - commited.Commit(); - } - } - Parameters parameter = new Parameters(); - parameter.set_Beta(ApplicationHelper.Beta); - parameter.set_Type(7); - parameter.set_Application("Agger.Gestor.exe"); - parameter.set_Directory(""); - parameter.set_Run(false); - (new DownloadWindow(parameter)).Show(); - (new MainWindow()).Show(); - base.Close(); - } - } - else - { - this.Loading(false); - this.UserBox.Focus(); - } - } - } - - private async void Acessar_Click(object sender, RoutedEventArgs e) - { - ((RepeatButton)sender).Click -= new RoutedEventHandler(this.Acessar_Click); - await this.Access(true); - ((RepeatButton)sender).Click += new RoutedEventHandler(this.Acessar_Click); - } - - private void CancelarRegistro(object sender, RoutedEventArgs e) - { - this.ViewModel.FecharRegistro(); - } - - private void CancelarTrocaSenha_OnClick(object sender, RoutedEventArgs e) - { - this.ViewModel.TrocaSenhaVisibility = System.Windows.Visibility.Collapsed; - this.ViewModel.LoginVisibility = System.Windows.Visibility.Visible; - } - - private void CentralAtendimento_OnPreviewMouseDown(object sender, MouseButtonEventArgs e) - { - Process.Start(new ProcessStartInfo() - { - FileName = this.ViewModel.CentralAtendimento, - UseShellExecute = true - }); - } - - public void CloseButton_Click() - { - base.Close(); - } - - [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/loginwindow.xaml", UriKind.Relative)); - } - - private void LinkImage_MouseDown(object sender, MouseButtonEventArgs e) - { - Process.Start(new ProcessStartInfo() - { - FileName = this.ViewModel.ImagemLink, - UseShellExecute = true - }); - } - - private void Loading(bool isLoading) - { - this.ViewModel.EnableFields = !isLoading; - this.ViewModel.LoadingVisibility = isLoading; - this.ViewModel.FieldsVisibility = !isLoading; - base.IsEnabled = !isLoading; - } - - private async void LoginWindow_OnLoaded(object sender, RoutedEventArgs e) - { - this.Loading(true); - await this.ViewModel.GetCfgJson(); - await this.SearchImage(); - this.ViewModel.EnableButtons = false; - LicenseHelper licenseHelper = new LicenseHelper(); - bool flag = await licenseHelper.VerificarRegistro(); - if (!flag) - { - string str = await licenseHelper.FindKey(); - bool flag1 = false; - if (str != null) - { - await licenseHelper.Registrar(str); - flag1 = true; - } - if (str == null && !string.IsNullOrWhiteSpace(Recursos.Registrar)) - { - await licenseHelper.Registrar(Recursos.Registrar); - flag1 = true; - } - if (flag1) - { - flag = await licenseHelper.VerificarRegistro(); - } - str = null; - } - if (!flag) - { - this.Loading(false); - this.ViewModel.AbrirRegistro(); - this.ViewModel.EnableButtons = true; - } - else - { - Tuple tuple = await licenseHelper.VerificarAcesso(); - if (tuple.Item1) - { - ConnectionHelper connectionHelper = new ConnectionHelper(); - Tuple tuple1 = await connectionHelper.PrimeiroAcesso(); - if (Gestor.Application.Helpers.Connection.ConnectionAddress == null || Gestor.Application.Helpers.Connection.ConnectionAddress.get_Type() == 4) - { - this.Loading(false); - this.ViewModel.AcessoNegado("Erro de conexão com Banco Gestor.\nEntre em contato com Suporte!"); - } - else if (!tuple1.Item1 || !tuple1.Item2) - { - (new TutorialView(tuple1)).Show(); - base.Close(); - } - else - { - Tuple tuple2 = await licenseHelper.VerificarVersao(); - if (tuple2.Item1) - { - Task.Run(() => { - try - { - if (!connectionHelper.BDConvertido()) - { - (new BaseServico()).BuscarEmpresa((long)1); - } - } - catch - { - } - }); - this.Loading(false); - if (!string.IsNullOrWhiteSpace(this.UserBox.Text)) - { - this.PasswordBox.PasswordBox.Focus(); - } - else - { - this.UserBox.Focus(); - } - this.ViewModel.EnableButtons = true; - string result = Gestor.Application.Helpers.Connection.Get(string.Concat("Customer/Name/", ApplicationHelper.NumeroSerial), true, false).Result; - this.ViewModel.Head = result; - } - else - { - this.Loading(false); - this.ViewModel.AcessoNegado(tuple2.Item2); - } - } - } - else - { - this.Loading(false); - this.ViewModel.AcessoNegado(tuple.Item2); - } - } - licenseHelper = null; - } - - public void MinimizeButton_Click() - { - base.WindowState = System.Windows.WindowState.Minimized; - } - - private void NovoPerfil_OnPreviewMouseDown(object sender, MouseButtonEventArgs e) - { - this.ViewModel.AbrirRegistro(); - this.ViewModel.EnableButtons = true; - } - - protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) - { - Size newSize; - base.OnRenderSizeChanged(sizeInfo); - if (sizeInfo.HeightChanged) - { - double top = base.Top; - double height = sizeInfo.PreviousSize.Height; - newSize = sizeInfo.NewSize; - base.Top = top + (height - newSize.Height) / 2; - } - if (sizeInfo.WidthChanged) - { - double left = base.Left; - double width = sizeInfo.PreviousSize.Width; - newSize = sizeInfo.NewSize; - base.Left = left + (width - newSize.Width) / 2; - } - } - - private async void PasswordBox_OnKeyDown(object sender, KeyEventArgs e) - { - if (e.Key == Key.Return) - { - await this.Access(true); - } - } - - private async void Registrar_OnClick(object sender, RoutedEventArgs e) - { - this.Loading(true); - LicenseHelper licenseHelper = new LicenseHelper(); - string str = await licenseHelper.Registrar(this.ViewModel.Chave); - if (str != "false") - { - if (str == "root") - { - await this.ViewModel.ShowMessage("CHAVE JÁ REGISTRADA ANTERIORMENTE.", "OK", "", false); - } - this.ViewModel.FecharRegistro(); - string result = Gestor.Application.Helpers.Connection.Get(string.Concat("Customer/Name/", ApplicationHelper.NumeroSerial), true, false).Result; - this.ViewModel.Head = result; - Tuple tuple = await licenseHelper.VerificarAcesso(); - if (tuple.Item1) - { - Tuple tuple1 = await (new ConnectionHelper()).PrimeiroAcesso(); - if (!tuple1.Item1 || !tuple1.Item2) - { - (new TutorialView(tuple1)).Show(); - base.Close(); - } - else - { - this.Loading(false); - await this.Access(false); - } - } - else - { - this.Loading(false); - this.ViewModel.AcessoNegado(tuple.Item2); - } - } - else - { - await this.ViewModel.ShowMessage("CHAVE INVÁLIDA", "OK", "", false); - this.Loading(false); - this.ViewModel.AbrirRegistro(); - } - licenseHelper = null; - } - - private async Task SearchImage() - { - string str2; - string str3; - try - { - using (HttpClient httpClient = new HttpClient()) - { - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; - httpClient.set_Timeout(TimeSpan.FromSeconds(30)); - string stringAsync = await httpClient.GetStringAsync(Address.get_LoginJsonV2()); - this.LoginSettings = JArray.Parse(stringAsync); - DateTime now = DateTime.Now; - foreach (JToken jToken2 in this.LoginSettings.Where((JToken x) => { - DateTime dateTime; - DateTime dateTime1; - bool flag; - List list; - string str; - string str1; - JToken item = x.get_Item("Ativo"); - flag = (item != null ? Extensions.Value(item) : false); - if (!flag) - { - return false; - } - JToken jToken = x.get_Item("Produto"); - if (jToken != null) - { - list = jToken.Values().ToList(); - } - else - { - list = null; - } - List nums = list; - if (nums != null) - { - List nums1 = nums; - Func u003cu003e9_201 = LoginWindow.u003cu003ec.u003cu003e9__20_1; - if (u003cu003e9_201 == null) - { - u003cu003e9_201 = (int p) => { - if (p == 0) - { - return true; - } - return p == 3; - }; - LoginWindow.u003cu003ec.u003cu003e9__20_1 = u003cu003e9_201; - } - if (nums1.Any(u003cu003e9_201)) - { - JToken item1 = x.get_Item("Inicio"); - if (item1 != null) - { - str = item1.ToString(); - } - else - { - str = null; - } - bool flag1 = DateTime.TryParse(str, out dateTime); - JToken jToken1 = x.get_Item("Fim"); - if (jToken1 != null) - { - str1 = jToken1.ToString(); - } - else - { - str1 = null; - } - bool flag2 = DateTime.TryParse(str1, out dateTime1); - if (flag1 & flag2) - { - if (now < dateTime) - { - return false; - } - return now <= dateTime1; - } - if (flag1) - { - return now >= dateTime; - } - if (!flag2) - { - return true; - } - return now <= dateTime1; - } - } - return false; - })) - { - ObservableCollection loginImages = this.ViewModel.LoginImages; - LoginImageModel loginImageModel = new LoginImageModel(); - JToken jToken3 = jToken2.get_Item("Imagem"); - if (jToken3 != null) - { - str2 = jToken3.ToString(); - } - else - { - str2 = null; - } - loginImageModel.Imagem = str2; - JToken jToken4 = jToken2.get_Item("UrlFixa"); - if (jToken4 != null) - { - str3 = jToken4.ToString(); - } - else - { - str3 = null; - } - loginImageModel.UrlFixa = str3; - loginImages.Add(loginImageModel); - } - this.ViewModel.SelectedImage = this.ViewModel.LoginImages.FirstOrDefault(); - base.Dispatcher.Invoke(new Action(this.StartCarousel)); - } - httpClient = null; - } - catch - { - } - } - - private void StartCarousel() - { - if (this.ViewModel.LoginImages.Count <= 1) - { - return; - } - this._carouselTimer = new DispatcherTimer() - { - Interval = TimeSpan.FromSeconds(10) - }; - this._carouselTimer.Tick += new EventHandler((object s, EventArgs e) => { - int num = (this.ViewModel.LoginImages.IndexOf(this.ViewModel.SelectedImage) + 1) % this.ViewModel.LoginImages.Count; - this.ViewModel.SelectedImage = this.ViewModel.LoginImages[num]; - }); - this._carouselTimer.Start(); - } - - [DebuggerNonUserCode] - [EditorBrowsable(EditorBrowsableState.Never)] - [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] - void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) - { - switch (connectionId) - { - case 1: - { - ((LoginWindow)target).Loaded += new RoutedEventHandler(this.LoginWindow_OnLoaded); - return; - } - case 2: - { - this.ProgressRing = (Image)target; - return; - } - case 3: - { - this.UserBox = (TextBox)target; - return; - } - case 4: - { - this.PasswordBox = (CustomSenhaLoginBox)target; - return; - } - case 5: - { - this.TrocaSenha = (TextBlock)target; - this.TrocaSenha.PreviewMouseDown += new MouseButtonEventHandler(this.TrocarSenha_OnPreviewMouseDown); - return; - } - case 6: - { - ((RepeatButton)target).Click += new RoutedEventHandler(this.Acessar_Click); - return; - } - case 7: - { - ((TextBlock)target).PreviewMouseDown += new MouseButtonEventHandler(this.NovoPerfil_OnPreviewMouseDown); - return; - } - case 8: - { - this.SenhaBox = (CustomSenhaLoginBox)target; - return; - } - case 9: - { - this.ConfirmacaoBox = (CustomSenhaLoginBox)target; - return; - } - case 10: - { - ((RepeatButton)target).Click += new RoutedEventHandler(this.CancelarTrocaSenha_OnClick); - return; - } - case 11: - { - ((RepeatButton)target).Click += new RoutedEventHandler(this.TrocarSenha_OnClick); - return; - } - case 12: - { - ((TextBlock)target).PreviewMouseDown += new MouseButtonEventHandler(this.CentralAtendimento_OnPreviewMouseDown); - return; - } - case 13: - { - this.ChaveBox = (TextBox)target; - return; - } - case 14: - { - ((RepeatButton)target).Click += new RoutedEventHandler(this.CancelarRegistro); - return; - } - case 15: - { - ((RepeatButton)target).Click += new RoutedEventHandler(this.Registrar_OnClick); - return; - } - case 16: - { - this.MinimizeButton = (Grid)target; - this.MinimizeButton.MouseLeftButtonDown += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonDown); - this.MinimizeButton.MouseLeftButtonUp += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonUp); - return; - } - case 17: - { - this.CloseButton = (Grid)target; - this.CloseButton.MouseLeftButtonDown += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonDown); - this.CloseButton.MouseLeftButtonUp += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonUp); - return; - } - } - this._contentLoaded = true; - } - - private static void TopControls_OnMouseEnter(object sender, MouseEventArgs e) - { - ((Grid)sender).Background = (((Grid)sender).Name == "CloseButton" ? new SolidColorBrush((Color)System.Windows.Application.Current.Resources["AggerYellow100"]) : new SolidColorBrush(Colors.Gray)); - Path child = VisualTreeHelper.GetChild((Grid)sender, 0) as Path; - if (child != null) - { - child.Stroke = new SolidColorBrush(Colors.White); - } - } - - private void TopControls_OnMouseLeave(object sender, MouseEventArgs e) - { - this._buttonClickable = false; - ((Grid)sender).Background = new SolidColorBrush(Colors.Transparent); - Path child = VisualTreeHelper.GetChild((Grid)sender, 0) as Path; - if (child != null) - { - child.Stroke = (((Grid)sender).Name == "CloseButton" ? new SolidColorBrush((Color)System.Windows.Application.Current.Resources["AggerYellow100"]) : new SolidColorBrush(Colors.DimGray)); - } - } - - private void TopControls_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - this._buttonClickable = true; - ((Grid)sender).Background = (((Grid)sender).Name == "CloseButton" ? new SolidColorBrush(Colors.DarkGoldenrod) : new SolidColorBrush(Colors.DimGray)); - } - - private void TopControls_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) - { - if (this._buttonClickable) - { - MethodInfo method = base.GetType().GetMethod(string.Concat(((Grid)sender).Name, "_Click")); - if (method == null) - { - return; - } - method.Invoke(this, null); - } - } - - private async void TrocarSenha_OnClick(object sender, RoutedEventArgs e) - { - this.Loading(true); - bool flag = await this.ViewModel.TrocaSenha(); - this.Loading(false); - if (flag) - { - await this.Access(true); - } - } - - private async void TrocarSenha_OnPreviewMouseDown(object sender, MouseButtonEventArgs e) - { - this.Loading(true); - await this.ViewModel.AbrirTrocaSenha(); - this.Loading(false); - } - - private async Task VerificarAcesso() - { - bool flag; - Instalacao instalacao; - LicenseHelper licenseHelper = new LicenseHelper(); - Tuple tuple = await licenseHelper.VerificarAcesso(); - if (tuple.Item1) - { - if (!this.ViewModel.Login.Contains("AGGER@")) - { - bool flag1 = false; - if (!await licenseHelper.VerificarMaquina()) - { - this.Loading(false); - while (!flag1) - { - List instalacoes = await licenseHelper.GetInstalacoes(); - if (instalacoes.Count != 0) - { - List instalacaos = instalacoes; - IOrderedEnumerable ultimoAcesso = - from x in instalacaos - orderby x.get_UltimoAcesso() descending - select x; - Instalacao instalacao1 = ultimoAcesso.FirstOrDefault((Instalacao x) => x.get_UsuarioId() == Recursos.Usuario.get_Id()); - bool flag2 = instalacao1 != null; - if (flag2) - { - flag2 = await this.ViewModel.ShowMessage(string.Concat("SEU ULTIMO ACESSO FOI NA MAQUINA ", instalacao1.get_NomeMaquina(), ". DESEJA SUBSTITUIR A LICENÇA PARA ESSA MAQUINA?"), "SIM", "NÃO", false); - } - if (!flag2) - { - instalacao = await this.ViewModel.ShowInstalacoes(instalacoes); - } - else - { - instalacao = instalacao1; - } - Instalacao instalacao2 = instalacao; - if (instalacao2 != null) - { - this.Loading(true); - await (new AjudaServico()).ExcluirInstalacao(instalacao2.get_Id()); - await Task.Delay(15000); - flag2 = await licenseHelper.VerificarMaquina(); - flag1 = flag2; - this.Loading(false); - instalacoes = null; - instalacao1 = null; - } - else - { - this.ViewModel.AcessoNegado("MÁQUINA NÃO REGISTRADA"); - flag = true; - licenseHelper = null; - return flag; - } - } - else - { - this.ViewModel.AcessoNegado("ACESSO NEGADO, NÃO EXISTEM LICENÇAS VÁLIDAS."); - flag = true; - licenseHelper = null; - return flag; - } - } - } - } - Tuple tuple1 = await licenseHelper.VerificarVersao(); - if (tuple1.Item1) - { - string str = await (new ConnectionHelper()).AtualizarBanco(); - if (str == null) - { - if (!await this.ViewModel.Load()) - { - base.Close(); - } - flag = false; - } - else - { - await this.ViewModel.ShowMessage(str, "OK", "", false); - flag = false; - } - } - else - { - this.Loading(false); - this.ViewModel.AcessoNegado(tuple1.Item2); - flag = true; - } - } - else - { - this.Loading(false); - this.ViewModel.AcessoNegado(tuple.Item2); - flag = true; - } - licenseHelper = null; - return flag; - } - } -} \ No newline at end of file -- cgit v1.2.3