From 0440c722a221b8068bbf388c1c0c51f0faff0451 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 14:17:46 -0300 Subject: some dlls --- .../Gestor.Model.Validation/ControleValidacao.cs | 14 +++ Gestor.Model/Gestor.Model.Validation/Funcoes.cs | 107 +++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 Gestor.Model/Gestor.Model.Validation/ControleValidacao.cs create mode 100644 Gestor.Model/Gestor.Model.Validation/Funcoes.cs (limited to 'Gestor.Model/Gestor.Model.Validation') diff --git a/Gestor.Model/Gestor.Model.Validation/ControleValidacao.cs b/Gestor.Model/Gestor.Model.Validation/ControleValidacao.cs new file mode 100644 index 0000000..a167c69 --- /dev/null +++ b/Gestor.Model/Gestor.Model.Validation/ControleValidacao.cs @@ -0,0 +1,14 @@ +using System; + +namespace Gestor.Model.Validation; + +public class ControleValidacao +{ + public string Nome { get; set; } + + public string Tag { get; set; } + + public string Estilo { get; set; } + + public Type Tipo { get; set; } +} diff --git a/Gestor.Model/Gestor.Model.Validation/Funcoes.cs b/Gestor.Model/Gestor.Model.Validation/Funcoes.cs new file mode 100644 index 0000000..dd943d9 --- /dev/null +++ b/Gestor.Model/Gestor.Model.Validation/Funcoes.cs @@ -0,0 +1,107 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Reflection; +using Gestor.Model.Common; + +namespace Gestor.Model.Validation; + +public static class Funcoes +{ + public static Stopwatch Stopwatch; + + public static DateTime? StartTime; + + public static string GetDescription(this Enum genericEnum) + { + if (genericEnum == null) + { + return ""; + } + MemberInfo[] member = genericEnum.GetType().GetMember(genericEnum.ToString()); + if (member.Length == 0) + { + return genericEnum.ToString(); + } + object[] customAttributes = member[0].GetCustomAttributes(typeof(DescriptionAttribute), inherit: false); + if (!customAttributes.Any()) + { + return genericEnum.ToString(); + } + return ((DescriptionAttribute)customAttributes.ElementAt(0)).Description; + } + + public static ParentescoVinculo? ParentescoInverso(ParentescoVinculo? parentesco) + { + return parentesco switch + { + ParentescoVinculo.MaePai => ParentescoVinculo.Filho, + ParentescoVinculo.Filho => ParentescoVinculo.MaePai, + ParentescoVinculo.Avo => ParentescoVinculo.Neto, + ParentescoVinculo.Neto => ParentescoVinculo.Avo, + ParentescoVinculo.Tio => ParentescoVinculo.Sobrinho, + ParentescoVinculo.Sobrinho => ParentescoVinculo.Tio, + ParentescoVinculo.Bisavo => ParentescoVinculo.Bisneto, + ParentescoVinculo.Bisneto => ParentescoVinculo.Bisavo, + ParentescoVinculo.Sogro => ParentescoVinculo.Genro, + ParentescoVinculo.Genro => ParentescoVinculo.Sogro, + ParentescoVinculo.MadrastaPadrasto => ParentescoVinculo.Enteado, + ParentescoVinculo.Enteado => ParentescoVinculo.MadrastaPadrasto, + ParentescoVinculo.Proprietario => ParentescoVinculo.Propriedade, + ParentescoVinculo.Propriedade => ParentescoVinculo.Proprietario, + ParentescoVinculo.Funcionario => ParentescoVinculo.Contratante, + ParentescoVinculo.Contratante => ParentescoVinculo.Funcionario, + _ => parentesco, + }; + } + + public static DateTime GetNetworkTime() + { + try + { + if (StartTime.HasValue) + { + return StartTime.Value.AddMilliseconds(Stopwatch.ElapsedMilliseconds); + } + byte[] array = new byte[48]; + array[0] = 27; + IPEndPoint remoteEP = new IPEndPoint(Dns.GetHostEntry("time.google.com").AddressList.First((IPAddress a) => a.AddressFamily == AddressFamily.InterNetwork), 123); + using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) + { + socket.Connect(remoteEP); + socket.ReceiveTimeout = 3000; + socket.Send(array); + socket.Receive(array); + socket.Close(); + } + ulong num = ((ulong)array[40] << 24) | ((ulong)array[41] << 16) | ((ulong)array[42] << 8) | array[43]; + ulong num2 = ((ulong)array[44] << 24) | ((ulong)array[45] << 16) | ((ulong)array[46] << 8) | array[47]; + ulong num3 = num * 1000 + num2 * 1000 / 4294967296L; + DateTime value = new DateTime(1900, 1, 1).AddMilliseconds((long)num3).ToLocalTime(); + StartTime = value; + Stopwatch = Stopwatch.StartNew(); + return StartTime.Value; + } + catch (Exception) + { + StartTime = DateTime.Now; + Stopwatch = Stopwatch.StartNew(); + return StartTime.Value; + } + } + + public static int GetAge(DateTime birth) + { + DateTime date = GetNetworkTime().Date; + int num = date.Year - birth.Year; + DateTime dateTime = date.AddYears(-num); + if (birth > dateTime) + { + num--; + } + return num; + } +} -- cgit v1.2.3