using Gestor.Infrastructure.UnitOfWork.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Relatorios; using Gestor.Model.Validation; using Microsoft.CSharp.RuntimeBinder; using NHibernate; using NHibernate.Connection; using NHibernate.Impl; using NHibernate.Util; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using System.Net; using System.Net.Sockets; using System.Reflection; using System.Runtime.CompilerServices; namespace Gestor.Infrastructure.Helpers { internal static class Funcoes { public static System.Diagnostics.Stopwatch Stopwatch; public static DateTime? StartTime; private static Dictionary TypeMap { get; } static Funcoes() { Dictionary types = new Dictionary(); types[typeof(string)] = SqlDbType.NVarChar; types[typeof(char[])] = SqlDbType.NVarChar; types[typeof(byte)] = SqlDbType.TinyInt; types[typeof(short)] = SqlDbType.SmallInt; types[typeof(int)] = SqlDbType.Int; types[typeof(long)] = SqlDbType.BigInt; types[typeof(long)] = SqlDbType.BigInt; types[typeof(byte[])] = SqlDbType.Image; types[typeof(bool)] = SqlDbType.Bit; types[typeof(DateTime)] = SqlDbType.DateTime2; types[typeof(DateTimeOffset)] = SqlDbType.DateTimeOffset; types[typeof(decimal)] = SqlDbType.Money; types[typeof(float)] = SqlDbType.Real; types[typeof(double)] = SqlDbType.Float; types[typeof(TimeSpan)] = SqlDbType.Time; Gestor.Infrastructure.Helpers.Funcoes.TypeMap = types; } public static T Campo(this DataRow row, string field) { string name; bool isEnum; string str; object obj = row.Obj(field); if (!typeof(T).IsNullable()) { if (typeof(T).IsEnum) { if (obj == null) { return (T)typeof(T).GetEnumValues().First(); } return (T)Enum.Parse(typeof(T), obj.ToString()); } name = typeof(T).Name; if (name == "String") { if (obj == null) { return (T)""; } return (T)obj.ToString(); } if (name == "DateTime") { if (obj == null) { return (T)(object)DateTime.MinValue; } return (T)(object)DateTime.Parse(obj.ToString()); } if (name == "Decimal") { if (obj == null) { return (T)(object)0; } return (T)(object)decimal.Parse(obj.ToString()); } if (name == "Int64") { if (obj == null) { return (T)(object)0; } return (T)(object)long.Parse(obj.ToString()); } if (name != "Int") { return (T)null; } if (obj == null) { return (T)(object)0; } return (T)(object)int.Parse(obj.ToString()); } Type underlyingType = Nullable.GetUnderlyingType(typeof(T)); if (underlyingType != null) { isEnum = underlyingType.IsEnum; } else { isEnum = false; } if (isEnum) { if (obj == null) { return (T)null; } return (T)Enum.Parse(typeof(T), obj.ToString()); } Type type = Nullable.GetUnderlyingType(typeof(T)); if (type != null) { str = type.Name; } else { str = null; } name = str; if (name == "String") { if (obj == null) { return (T)null; } return (T)obj.ToString(); } if (name == "DateTime") { if (obj == null) { return (T)null; } return (T)(object)DateTime.Parse(obj.ToString()); } if (name == "Decimal") { if (obj == null) { return (T)null; } return (T)(object)decimal.Parse(obj.ToString()); } if (name == "Int64") { if (obj == null) { return (T)null; } return (T)(object)long.Parse(obj.ToString()); } if (name != "Int") { return (T)null; } if (obj == null) { return (T)null; } return (T)(object)int.Parse(obj.ToString()); } public static TipoTela? Convert(this string form) { TipoTela tipoTela; TipoTela? nullable; char chr; if (string.IsNullOrWhiteSpace(form)) { nullable = null; return nullable; } if (form.Contains("View") || form.Contains("Renovacao")) { nullable = null; return nullable; } string lower = form.ToLower(); if (lower != null) { switch (lower.Length) { case 7: { chr = lower[3]; if (chr == 'N') { if (lower == "frmNota") { return new TipoTela?(TipoTela.NotaFiscal); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else if (chr == 'a') { if (lower == "frmauto") { break; } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } } case 8: case 9: case 11: case 15: case 16: case 19: case 20: { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } case 10: { chr = lower[3]; if (chr == 'e') { if (lower == "frmendosso") { return new TipoTela?(TipoTela.Apolice); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else if (chr == 'i') { if (lower == "frmitemman") { break; } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else if (chr == 'p') { if (lower == "frmparcela") { return new TipoTela?(TipoTela.Parcela); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } } case 12: { chr = lower[3]; if (chr == 'r') { if (lower == "frmrenovacao") { return new TipoTela?(TipoTela.Apolice); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else if (chr == 'v') { if (lower == "frmvidagrupo") { break; } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } } case 13: { chr = lower[3]; if (chr == 'c') { if (lower == "frmcriticapdf") { return new TipoTela?(TipoTela.CriticaApolice); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else { switch (chr) { case 'p': { if (lower == "frmparcelanew") { return new TipoTela?(TipoTela.Parcela); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } case 'q': case 's': { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } case 'r': { if (lower == "frmresidencia") { return new TipoTela?(TipoTela.Item); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } case 't': { if (lower == "frmtransporte") { return new TipoTela?(TipoTela.Item); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } default: { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } } } break; } case 14: { chr = lower[3]; if (chr == 'a') { if (lower == "frmaeronautico") { break; } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else if (chr == 'e') { if (lower == "frmeducacional") { break; } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } } case 17: { chr = lower[3]; if (chr == 'm') { if (lower == "frmmanutpagamento") { return new TipoTela?(TipoTela.ManutencaoPagamentos); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else if (chr == 'r') { if (lower == "frmriscosdiversos") { break; } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else if (chr == 'v') { if (lower == "frmvidaindividual") { break; } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } else { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } } case 18: { if (lower == "frmparcelascritica") { return new TipoTela?(TipoTela.Parcela); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } case 21: { if (lower == "frmredirecionacritica") { return new TipoTela?(TipoTela.CriticaApolice); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } default: { tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } } return new TipoTela?(TipoTela.Item); } tipoTela = ((TipoTela[])Enum.GetValues(typeof(TipoTela))).ToList().FirstOrDefault((TipoTela x) => form.ToLower().Contains(x.ToString().ToLower())); if (tipoTela != TipoTela.Todas) { return new TipoTela?(tipoTela); } nullable = null; return nullable; } public static Relatorio? ConvertRelatorio(this string form) { Relatorio? nullable; char chr; if (string.IsNullOrWhiteSpace(form)) { nullable = null; return nullable; } if (form != null) { int length = form.Length; switch (length) { case 9: { if (form == "Renovacao") { break; } nullable = null; return nullable; } case 10: case 13: case 16: { nullable = null; return nullable; } case 11: { chr = form[3]; if (chr == 'M') { if (form == "frmMetaView") { return new Relatorio?(Relatorio.MetaSeguradora); } nullable = null; return nullable; } else if (chr == 'N') { if (form == "frmNotaView") { return new Relatorio?(Relatorio.NotaFiscal); } nullable = null; return nullable; } else { nullable = null; return nullable; } } case 12: { if (form == "frmRenovacao") { break; } nullable = null; return nullable; } case 14: { chr = form[3]; if (chr == 'C') { if (form == "frmClienteView") { return new Relatorio?(Relatorio.Cliente); } nullable = null; return nullable; } else if (chr == 'E') { if (form == "frmExtratoView") { return new Relatorio?(Relatorio.ExtratosBaixados); } nullable = null; return nullable; } else { nullable = null; return nullable; } } case 15: { chr = form[3]; if (chr == 'C') { if (form == "frmComissaoView") { return new Relatorio?(Relatorio.Comissao); } nullable = null; return nullable; } else if (chr == 'P') { if (form == "frmProducaoView") { return new Relatorio?(Relatorio.Producao); } nullable = null; return nullable; } else if (chr == 'S') { if (form == "frmSinistroView") { return new Relatorio?(Relatorio.Sinistro); } nullable = null; return nullable; } else { nullable = null; return nullable; } } case 17: { chr = form[3]; if (chr == 'F') { if (form == "frmFechamentoView") { return new Relatorio?(Relatorio.Fechamento); } nullable = null; return nullable; } else if (chr == 'U') { if (form == "frmUtilizacaoView") { return new Relatorio?(Relatorio.LogsUtilizacao); } nullable = null; return nullable; } else { nullable = null; return nullable; } } default: { if (length == 23) { if (form == "frmAgendaVencimentoView") { return new Relatorio?(Relatorio.Renovacao); } nullable = null; return nullable; } else { nullable = null; return nullable; } } } return new Relatorio?(Relatorio.Renovacao); } nullable = null; return nullable; } public static SqlQueryCondition CreateParameters(this List keyValues, int indexStart = 0) { if (keyValues == null) { return null; } List sqlParameters = new List(); List strs2 = new List(); int num = indexStart; ( from x in keyValues orderby x.Grupo group x by x.Grupo).ForEach>((IGrouping g) => { List strs1 = new List(); g.ForEach((Condicao x) => { string str = string.Concat(x.Campo, " "); List strs = new List(); if (x.Valores != null) { List valores = x.Valores; if (valores != null) { valores.ForEach((object v) => { SqlParameter sqlParameter; SqlParameter sqlParameter1; if (Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__0 == null) { Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__0 = CallSite>.Create(Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(CSharpBinderFlags.None, "GetType", null, typeof(Gestor.Infrastructure.Helpers.Funcoes), (IEnumerable)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }))); } object target = Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__0.Target(Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__0, v); if (Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__2 == null) { Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__2 = CallSite>.Create(Microsoft.CSharp.RuntimeBinder.Binder.UnaryOperation(CSharpBinderFlags.None, ExpressionType.IsTrue, typeof(Gestor.Infrastructure.Helpers.Funcoes), (IEnumerable)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }))); } !0 _u00210 = Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__2.Target; CallSite> u003cu003ep_2 = Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__2; if (Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__1 == null) { Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__1 = CallSite>.Create(Microsoft.CSharp.RuntimeBinder.Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.Equal, typeof(Gestor.Infrastructure.Helpers.Funcoes), (IEnumerable)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null) }))); } if (_u00210(u003cu003ep_2, Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__1.Target(Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__1, target, typeof(string)))) { sqlParameter = new SqlParameter() { ParameterName = string.Format("@param_{0}", num) }; SqlParameter target1 = sqlParameter; if (Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__4 == null) { Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__4 = CallSite>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(SqlDbType), typeof(Gestor.Infrastructure.Helpers.Funcoes))); } !0 _u002101 = Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__4.Target; CallSite> u003cu003ep_4 = Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__4; if (Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__3 == null) { Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__3 = CallSite>.Create(Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(CSharpBinderFlags.None, "GetDbType", null, typeof(Gestor.Infrastructure.Helpers.Funcoes), (IEnumerable)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.IsStaticType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }))); } target1.SqlDbType = _u002101(u003cu003ep_4, Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__3.Target(Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__3, typeof(Gestor.Infrastructure.Helpers.Funcoes), target)); sqlParameter.Size = 255; sqlParameter.Value = (x.Operador == Operador.Like || x.Operador == Operador.NotLike ? string.Format("%{0}%", v) : (x.Operador == Operador.ComecaCom ? string.Format("{0}%", v) : (x.Operador == Operador.TerminaCom ? string.Format("%{0}", v) : v))); sqlParameter1 = sqlParameter; } else { sqlParameter = new SqlParameter() { ParameterName = string.Format("@param_{0}", num) }; SqlParameter target2 = sqlParameter; if (Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__6 == null) { Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__6 = CallSite>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(SqlDbType), typeof(Gestor.Infrastructure.Helpers.Funcoes))); } !0 _u002102 = Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__6.Target; CallSite> u003cu003ep_6 = Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__6; if (Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__5 == null) { Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__5 = CallSite>.Create(Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(CSharpBinderFlags.None, "GetDbType", null, typeof(Gestor.Infrastructure.Helpers.Funcoes), (IEnumerable)(new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.IsStaticType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }))); } target2.SqlDbType = _u002102(u003cu003ep_6, Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__5.Target(Gestor.Infrastructure.Helpers.Funcoes.u003cu003eo__15.u003cu003ep__5, typeof(Gestor.Infrastructure.Helpers.Funcoes), target)); sqlParameter.Value = v; sqlParameter1 = sqlParameter; } SqlParameter sqlParameter2 = sqlParameter1; sqlParameters.Add(sqlParameter2); int cSu0024u003cu003e8_locals1 = num; num = cSu0024u003cu003e8_locals1 + 1; strs.Add(sqlParameter2.ParameterName); }); } else { } } else { str = string.Concat(str, (x.Operador == Operador.Igual ? "IS NULL" : "IS NOT NULL")); } if (strs.Count == 1) { str = string.Concat(str, x.Operador.GetDescription(), " "); str = string.Concat(str, strs.First()); } if (strs.Count > 1) { str = string.Concat(str, (x.Operador == Operador.Igual ? "IN" : (x.Operador == Operador.Diferente ? "NOT IN" : x.Operador.GetDescription())), " "); str = string.Concat(str, "(", string.Join(",", strs), ")"); } strs1.Add(str); }); strs2.Add(string.Concat("(", string.Join(g.First().Operacao.GetDescription(), strs1), ")")); }); return new SqlQueryCondition() { Condicao = string.Join(" AND ", strs2), Parametros = sqlParameters }; } public static DataTable CriarAuxiliar(this GenericUnitOfWork _unitOfWork) { DataTable dataTable; object connection; DataTable dataTable1 = new DataTable(); SessionFactoryImpl sessionFactory = _unitOfWork.Session.SessionFactory as SessionFactoryImpl; if (sessionFactory != null) { connection = sessionFactory.ConnectionProvider.GetConnection(); } else { connection = null; } using (SqlConnection sqlConnection = connection as SqlConnection) { if (sqlConnection != null) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandTimeout = 15000; Auxiliar.CriarAuxiliar(sqlCommand, true); return dataTable1; } } else { dataTable = null; } } return dataTable; } public static List CriarCondicao(this Filtros filtro, string referencia) { bool count; bool flag; bool count1; bool flag1; bool count2; bool flag2; bool count3; bool flag3; bool count4; bool flag4; bool count5; List condicaos = new List() { new Condicao() { Campo = referencia, Valores = filtro.Inicio.CriarValor(), Operador = Operador.MaiorEIgual }, new Condicao() { Campo = referencia, Valores = filtro.Fim.CriarValor(), Operador = Operador.MenorEIgual } }; List seguradoras = filtro.Seguradoras; if (seguradoras != null) { count = seguradoras.Count > 0; } else { count = false; } if (count) { condicaos.Add(new Condicao() { Campo = "c.idciaseg", Valores = filtro.Seguradoras.CriarValor() }); } List ramos = filtro.Ramos; if (ramos != null) { flag = ramos.Count > 0; } else { flag = false; } if (flag) { condicaos.Add(new Condicao() { Campo = "c.idramo", Valores = filtro.Ramos.CriarValor() }); } List status = filtro.Status; if (status != null) { count1 = status.Count > 0; } else { count1 = false; } if (count1) { condicaos.Add(new Condicao() { Campo = "d.situacao", Valores = filtro.Status.CriarValor() }); } List vendedores = filtro.Vendedores; if (vendedores != null) { flag1 = vendedores.Count > 0; } else { flag1 = false; } if (flag1) { condicaos.Add(new Condicao() { Campo = "vp.idvendedor", Valores = filtro.Vendedores.CriarValor() }); } List estipulantes = filtro.Estipulantes; if (estipulantes != null) { count2 = estipulantes.Count > 0; } else { count2 = false; } if (count2) { condicaos.Add(new Condicao() { Campo = "d.idestipulante", Valores = filtro.Estipulantes.CriarValor() }); } List produtos = filtro.Produtos; if (produtos != null) { flag2 = produtos.Count > 0; } else { flag2 = false; } if (flag2) { condicaos.Add(new Condicao() { Campo = "c.idproduto", Valores = filtro.Produtos.CriarValor() }); } List negocio = filtro.Negocio; if (negocio != null) { count3 = negocio.Count > 0; } else { count3 = false; } if (count3) { condicaos.Add(new Condicao() { Campo = "d.NegocioCorretora", Valores = filtro.Negocio.CriarValor() }); } List usuarios = filtro.Usuarios; if (usuarios != null) { flag3 = usuarios.Count > 0; } else { flag3 = false; } if (flag3) { condicaos.Add(new Condicao() { Campo = "IdUsuario", Valores = filtro.Usuarios.CriarValor() }); } List telas = filtro.Telas; if (telas != null) { count4 = telas.Count > 0; } else { count4 = false; } if (count4) { condicaos.Add(new Condicao() { Campo = "Tela", Valores = filtro.Telas.CriarValor() }); } List relatorios = filtro.Relatorios; if (relatorios != null) { flag4 = relatorios.Count > 0; } else { flag4 = false; } if (flag4) { condicaos.Add(new Condicao() { Campo = "Relatorio", Valores = filtro.Relatorios.CriarValor() }); } List parcelasEspeciais = filtro.ParcelasEspeciais; if (parcelasEspeciais != null) { count5 = parcelasEspeciais.Count > 0; } else { count5 = false; } if (count5) { if (filtro.ParcelasEspeciais.Any((FiltroTipoParcela x) => x.Selecionado)) { condicaos.Add(new Condicao() { Campo = "p.idsubtipo", Valores = ( from x in filtro.ParcelasEspeciais where x.Selecionado select (int)x.Tipo).CriarValor>() }); } } if (filtro.IdEmpresa > (long)0) { condicaos.Add(new Condicao() { Campo = "c.idempresa", Valores = filtro.IdEmpresa.CriarValor() }); } return condicaos; } public static List CriarValor(this T valor) { return new List() { valor }; } public static List CriarValor(this List lista) { return ( from in lista select x).ToList(); } public static SqlDbType GetDbType(Type giveType) { giveType = Nullable.GetUnderlyingType(giveType) ?? giveType; if (!Gestor.Infrastructure.Helpers.Funcoes.TypeMap.ContainsKey(giveType)) { throw new ArgumentException(string.Concat(giveType.FullName, " is not a supported .NET class")); } return Gestor.Infrastructure.Helpers.Funcoes.TypeMap[giveType]; } public static SqlDbType GetDbType() { return Gestor.Infrastructure.Helpers.Funcoes.GetDbType(typeof(T)); } public static DateTime GetNetworkTime() { DateTime value; try { if (!Gestor.Infrastructure.Helpers.Funcoes.StartTime.HasValue) { byte[] numArray = new byte[48]; numArray[0] = 27; IPEndPoint pEndPoint = new IPEndPoint(((IEnumerable)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(pEndPoint); socket.ReceiveTimeout = 3000; socket.Send(numArray); socket.Receive(numArray); socket.Close(); } ulong num = (ulong)numArray[40] << 24 | (ulong)numArray[41] << 16 | (ulong)numArray[42] << 8 | (ulong)numArray[43]; ulong num1 = (ulong)numArray[44] << 24 | (ulong)numArray[45] << 16 | (ulong)numArray[46] << 8 | (ulong)numArray[47]; ulong num2 = num * (long)1000 + num1 * (long)1000 / 4294967296L; DateTime dateTime = new DateTime(1900, 1, 1); dateTime = dateTime.AddMilliseconds((double)num2); Gestor.Infrastructure.Helpers.Funcoes.StartTime = new DateTime?(dateTime.ToLocalTime()); Gestor.Infrastructure.Helpers.Funcoes.Stopwatch = System.Diagnostics.Stopwatch.StartNew(); value = Gestor.Infrastructure.Helpers.Funcoes.StartTime.Value; } else { value = Gestor.Infrastructure.Helpers.Funcoes.StartTime.Value; value = value.AddMilliseconds((double)Gestor.Infrastructure.Helpers.Funcoes.Stopwatch.ElapsedMilliseconds); } } catch (Exception exception) { Gestor.Infrastructure.Helpers.Funcoes.StartTime = new DateTime?(DateTime.Now); Gestor.Infrastructure.Helpers.Funcoes.Stopwatch = System.Diagnostics.Stopwatch.StartNew(); value = Gestor.Infrastructure.Helpers.Funcoes.StartTime.Value; } return value; } public static bool IsNull(this DataRow row, string field) { return row.Obj(field) == null; } public static IQueryable NullSafeWhere(this IQueryable source, Expression> predicate) { if (predicate == null) { return source; } return source.Where(predicate); } public static object Obj(this DataRow row, string field) { return row.Field(field); } public static DataTable Select(this SqlCommand sqlCommand, SqlQueryCondition sqlCondition, string command, string group = "") { bool count; DataTable dataTable = new DataTable(); try { sqlCommand.CommandText = string.Concat(new string[] { command, " ", sqlCondition.Condicao, " ", group }); List parametros = sqlCondition.Parametros; if (parametros != null) { count = parametros.Count > 0; } else { count = false; } if (count) { sqlCondition.Parametros.ForEach((SqlParameter x) => sqlCommand.Parameters.Add(x)); } using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) { sqlDataAdapter.SelectCommand = sqlCommand; sqlDataAdapter.Fill(dataTable); } sqlCommand.Parameters.Clear(); } catch (Exception exception) { sqlCommand.CommandText = string.Empty; sqlCommand.Parameters.Clear(); throw; } return dataTable; } public static DataTable Select(this GenericUnitOfWork _unitOfWork, SqlQueryCondition sqlCondition, string command, string group = "") { DataTable dataTable; object connection; bool count; DataTable dataTable1 = new DataTable(); SessionFactoryImpl sessionFactory = _unitOfWork.Session.SessionFactory as SessionFactoryImpl; if (sessionFactory != null) { connection = sessionFactory.ConnectionProvider.GetConnection(); } else { connection = null; } using (SqlConnection sqlConnection = connection as SqlConnection) { if (sqlConnection != null) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandTimeout = 15000; sqlCommand.CommandText = string.Concat(new string[] { command, " ", sqlCondition.Condicao, " ", group }); List parametros = sqlCondition.Parametros; if (parametros != null) { count = parametros.Count > 0; } else { count = false; } if (count) { sqlCondition.Parametros.ForEach((SqlParameter x) => sqlCommand.Parameters.Add(x)); } using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) { sqlDataAdapter.SelectCommand = sqlCommand; sqlDataAdapter.Fill(dataTable1); return dataTable1; } } } else { dataTable = null; } } return dataTable; } public static bool Update(this SqlCommand sqlCommand, SqlQueryCondition sqlCondition, string command, List parameters = null) { bool flag; string condicao; bool count; if (string.IsNullOrEmpty(command)) { return false; } if (sqlCondition != null) { condicao = sqlCondition.Condicao; } else { condicao = null; } if (string.IsNullOrEmpty(condicao)) { return false; } if (sqlCondition.Parametros.Count == 0) { return false; } if (command.ToUpper().Contains("SELECT")) { return false; } try { sqlCommand.CommandText = string.Concat(command, " ", sqlCondition.Condicao); List parametros = sqlCondition.Parametros; if (parametros != null) { count = parametros.Count > 0; } else { count = false; } if (count) { sqlCondition.Parametros.ForEach((SqlParameter x) => sqlCommand.Parameters.Add(x)); } if (parameters != null && parameters.Count > 0) { parameters.ForEach((SqlParameter x) => sqlCommand.Parameters.Add(x)); } sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); return true; } catch (Exception exception) { sqlCommand.CommandText = string.Empty; sqlCommand.Parameters.Clear(); flag = false; } return flag; } } }