summaryrefslogtreecommitdiff
path: root/Gestor.Application/Views/LoginWindow.cs
blob: 96cac3623602115271b2f2330511f4a88e8cf239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
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<IPAddress>)addressList).FirstOrDefault<IPAddress>((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<bool, string> tuple = await licenseHelper.VerificarAcesso();
				if (tuple.Item1)
				{
					ConnectionHelper connectionHelper = new ConnectionHelper();
					Tuple<bool, bool> 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<bool, string> 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>(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>(string.Concat("Customer/Name/", ApplicationHelper.NumeroSerial), true, false).Result;
				this.ViewModel.Head = result;
				Tuple<bool, string> tuple = await licenseHelper.VerificarAcesso();
				if (tuple.Item1)
				{
					Tuple<bool, bool> 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>((JToken x) => {
						DateTime dateTime;
						DateTime dateTime1;
						bool flag;
						List<int> list;
						string str;
						string str1;
						JToken item = x.get_Item("Ativo");
						flag = (item != null ? Extensions.Value<bool>(item) : false);
						if (!flag)
						{
							return false;
						}
						JToken jToken = x.get_Item("Produto");
						if (jToken != null)
						{
							list = jToken.Values<int>().ToList<int>();
						}
						else
						{
							list = null;
						}
						List<int> nums = list;
						if (nums != null)
						{
							List<int> nums1 = nums;
							Func<int, bool> 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<int>(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<LoginImageModel> 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<LoginImageModel>();
					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<bool> VerificarAcesso()
		{
			bool flag;
			Instalacao instalacao;
			LicenseHelper licenseHelper = new LicenseHelper();
			Tuple<bool, string> 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<Instalacao> instalacoes = await licenseHelper.GetInstalacoes();
							if (instalacoes.Count != 0)
							{
								List<Instalacao> instalacaos = instalacoes;
								IOrderedEnumerable<Instalacao> ultimoAcesso = 
									from x in instalacaos
									orderby x.get_UltimoAcesso() descending
									select x;
								Instalacao instalacao1 = ultimoAcesso.FirstOrDefault<Instalacao>((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<bool, string> 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;
		}
	}
}