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 --- .../ItemRepository.cs | 1450 -------------------- 1 file changed, 1450 deletions(-) delete mode 100644 Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs') diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs deleted file mode 100644 index 0d8590f..0000000 --- a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs +++ /dev/null @@ -1,1450 +0,0 @@ -using AutoMapper; -using Gestor.Infrastructure.Entities.Generic; -using Gestor.Infrastructure.Entities.Seguros; -using Gestor.Infrastructure.Helpers; -using Gestor.Infrastructure.Mappers; -using Gestor.Infrastructure.Repository.Generic; -using Gestor.Infrastructure.Repository.Interface; -using Gestor.Infrastructure.UnitOfWork.Generic; -using Gestor.Model.Common; -using Gestor.Model.Domain.Common; -using Gestor.Model.Domain.Generic; -using Gestor.Model.Domain.Seguros; -using NHibernate; -using NHibernate.Connection; -using NHibernate.Impl; -using NHibernate.Util; -using System; -using System.Collections; -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.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Gestor.Infrastructure.Repository.Logic -{ - public class ItemRepository : GenericRepository, IItemRepository, IGenericRepository - { - private readonly GenericUnitOfWork _unitOfWork; - - public ItemRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) - { - this._unitOfWork = unitOfWork; - } - - public async Task> BuscaItensPorObs(string pesquisa, FiltroStatusDocumento status, List vendedorVinculado, TipoPesquisa tipo, bool tipobusca = false) - { - List pesquisaAvancadas; - object connection; - object obj; - DateTime dateTime; - List pesquisaAvancadas1 = new List(); - DateTime date = Funcoes.GetNetworkTime().Date; - List condicaos = new List(); - Condicao condicao = new Condicao() - { - Campo = "d.excluido", - Valores = null, - Grupo = 1, - Operacao = Operacao.Or - }; - condicaos.Add(condicao); - Condicao condicao1 = new Condicao() - { - Campo = "d.excluido", - Valores = "0".CriarValor(), - Grupo = 1, - Operacao = Operacao.Or - }; - condicaos.Add(condicao1); - List condicaos1 = condicaos; - if (vendedorVinculado.Count > 0) - { - Condicao condicao2 = new Condicao() - { - Campo = "vp.IdVendedor", - Valores = vendedorVinculado.CriarValor() - }; - condicaos1.Add(condicao2); - } - switch (status) - { - case FiltroStatusDocumento.Vencidos: - { - List condicaos2 = new List(); - Condicao condicao3 = new Condicao() - { - Campo = "d.situacao", - Valores = new List() - { - 3, - 7 - }, - Operador = Operador.Diferente - }; - condicaos2.Add(condicao3); - Condicao condicao4 = new Condicao() - { - Campo = "d.vigencia2", - Valores = date.AddDays(-5).CriarValor(), - Operador = Operador.Menor - }; - condicaos2.Add(condicao4); - condicaos1.AddRange(condicaos2); - goto Label0; - } - case FiltroStatusDocumento.Cancelados: - { - Condicao condicao5 = new Condicao() - { - Campo = "d.situacao", - Valores = 3.CriarValor() - }; - condicaos1.Add(condicao5); - goto Label0; - } - case FiltroStatusDocumento.Recusados: - { - Condicao condicao6 = new Condicao() - { - Campo = "d.situacao", - Valores = 7.CriarValor() - }; - condicaos1.Add(condicao6); - goto Label0; - } - case FiltroStatusDocumento.Todos: - { - using (SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl) - { - SessionFactoryImpl sessionFactoryImpl = sessionFactory; - if (sessionFactoryImpl != null) - { - connection = sessionFactoryImpl.ConnectionProvider.GetConnection(); - } - else - { - connection = null; - } - using (SqlConnection sqlConnection = connection as SqlConnection) - { - using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) - { - List condicaos3 = condicaos1; - Condicao condicao7 = new Condicao() - { - Campo = "a.obs", - Valores = pesquisa.CriarValor(), - Grupo = 3, - Operacao = Operacao.Or, - Operador = (tipobusca ? Operador.Igual : Operador.Like) - }; - condicaos3.Add(condicao7); - List condicaos4 = condicaos1; - Condicao condicao8 = new Condicao() - { - Campo = "r.obs", - Valores = pesquisa.CriarValor(), - Grupo = 3, - Operacao = Operacao.Or, - Operador = (tipobusca ? Operador.Igual : Operador.Like) - }; - condicaos4.Add(condicao8); - List condicaos5 = condicaos1; - Condicao condicao9 = new Condicao() - { - Campo = "aero.obs", - Valores = pesquisa.CriarValor(), - Grupo = 3, - Operacao = Operacao.Or, - Operador = (tipobusca ? Operador.Igual : Operador.Like) - }; - condicaos5.Add(condicao9); - List condicaos6 = condicaos1; - Condicao condicao10 = new Condicao() - { - Campo = "g.obs", - Valores = pesquisa.CriarValor(), - Grupo = 3, - Operacao = Operacao.Or, - Operador = (tipobusca ? Operador.Igual : Operador.Like) - }; - condicaos6.Add(condicao10); - List condicaos7 = condicaos1; - Condicao condicao11 = new Condicao() - { - Campo = "v.obs", - Valores = pesquisa.CriarValor(), - Grupo = 3, - Operacao = Operacao.Or, - Operador = (tipobusca ? Operador.Igual : Operador.Like) - }; - condicaos7.Add(condicao11); - List condicaos8 = condicaos1; - Condicao condicao12 = new Condicao() - { - Campo = "rd.obs", - Valores = pesquisa.CriarValor(), - Grupo = 3, - Operacao = Operacao.Or, - Operador = (tipobusca ? Operador.Igual : Operador.Like) - }; - condicaos8.Add(condicao12); - List condicaos9 = condicaos1; - Condicao condicao13 = new Condicao() - { - Campo = "re.bens", - Valores = pesquisa.CriarValor(), - Grupo = 3, - Operacao = Operacao.Or, - Operador = (tipobusca ? Operador.Igual : Operador.Like) - }; - condicaos9.Add(condicao13); - SqlQueryCondition sqlQueryCondition = condicaos1.CreateParameters(0); - sqlCommand.CommandText = string.Concat("SELECT DISTINCT TOP 1000 c.IdControle,d.IdDocumento,d.Proposta,d.Contrato Apolice,d.Aditamento Endosso,d.Vigencia1 VigenciaInicial,c.IdCliente,d.Tipo Tipo,i.IdItem,i.Descricao,cli.Nome,vp.IdVendedor FROM documento d INNER JOIN controle c ON d.IdControle = c.idControle INNER JOIN cliente cli ON cli.IdCliente = c.IdCliente INNER JOIN item i ON d.IdDocumento = i.IdDocumento LEFT JOIN auto a ON i.IdItem = a.IdItem LEFT JOIN resempco r ON i.IdItem = r.IdItem LEFT JOIN aeronautico aero ON i.IdItem = aero.IdItem LEFT JOIN granizo g ON i.IdItem = g.IdItem LEFT JOIN vida v ON i.IdItem = v.IdItem LEFT JOIN riscosdiversos rd ON i.IdItem = rd.IdItem LEFT JOIN vendedorparcela vp ON d.IdDocumento = vp.IdDocumento LEFT JOIN resempco re ON i.IdItem = re.IdItem WHERE ", sqlQueryCondition.Condicao); - sqlCommand.Parameters.AddRange(sqlQueryCondition.Parametros.ToArray()); - using (SqlDataReader sqlDataReader = await sqlCommand.ExecuteReaderAsync()) - { - while (true) - { - if (!await sqlDataReader.ReadAsync()) - { - break; - } - object[] fieldValue = new object[] { sqlDataReader.GetFieldValue("Descricao", true, true), sqlDataReader.GetFieldValue("Apolice", true, true), null, null, null }; - obj = (sqlDataReader.GetFieldValue("Tipo", true, true) == 0 ? "" : string.Concat(" - ENDOSSO: ", sqlDataReader.GetFieldValue("Endosso", true, true))); - fieldValue[2] = obj; - fieldValue[3] = sqlDataReader.GetFieldValue("Proposta", true, true); - DateTime? nullable = sqlDataReader.GetFieldValue("VigenciaInicial", true, true); - dateTime = (nullable.HasValue ? nullable.GetValueOrDefault() : DateTime.Now); - fieldValue[4] = dateTime; - string str = string.Format("ITEM: {0} - APÓLICE: {1}{2} - PROPOSTA: {3} - VIGÊNCIA INICIAL: {4:d}", fieldValue); - PesquisaAvancada pesquisaAvancada = new PesquisaAvancada() - { - IdCliente = sqlDataReader.GetFieldValue("IdCliente", true, true), - IdDocumento = sqlDataReader.GetFieldValue("IdDocumento", true, true), - IdItem = sqlDataReader.GetFieldValue("IdItem", true, true), - Nome = sqlDataReader.GetFieldValue("Nome", true, true).ToUpper(), - Pesquisa = str.ToUpper() - }; - pesquisaAvancadas1.Add(pesquisaAvancada); - } - } - sqlDataReader = null; - } - sqlCommand = null; - } - sqlConnection = null; - } - sessionFactory = null; - pesquisaAvancadas = pesquisaAvancadas1; - break; - } - default: - { - List condicaos10 = new List(); - Condicao condicao14 = new Condicao() - { - Campo = "d.situacao" - }; - List objs = new List() - { - 1, - 2, - 4 - }; - condicao14.Valores = objs; - condicaos10.Add(condicao14); - Condicao condicao15 = new Condicao() - { - Campo = "d.vigencia2", - Valores = null, - Grupo = 2, - Operacao = Operacao.Or - }; - condicaos10.Add(condicao15); - Condicao condicao16 = new Condicao() - { - Campo = "d.vigencia2", - Valores = date.AddDays(-5).CriarValor(), - Grupo = 2, - Operacao = Operacao.Or, - Operador = Operador.Maior - }; - condicaos10.Add(condicao16); - condicaos1.AddRange(condicaos10); - goto Label0; - } - } - pesquisaAvancadas1 = null; - return pesquisaAvancadas; - } - - public Cliente BuscarCliente(long id) - { - return this.FindById(id).Documento.Controle.Cliente; - } - - public int ChecarQuantidade(long idDocumento) - { - return base.All().Count((ItemDb x) => x.Documento.Id == idDocumento); - } - - public void Delete(long id) - { - ItemDb itemDb = base.FindEntityById(id); - if (itemDb == null) - { - return; - } - base.Delete(itemDb); - } - - public void DeleteRange(List ids) - { - List list = ( - from x in base.All() - where ids.Contains(x.Id) - select x).ToList(); - base.DeleteRange(list); - } - - public List FindByDocumentsIds(long id, StatusItem status = 0, bool sinistroCompleto = false) - { - List condicaos; - DataTable dataTable1; - int length; - Item granizo; - long? nullable; - long? nullable1; - long? nullable2; - string str; - string str1; - string str2; - string str3; - string str4; - string str5; - string str6; - string str7; - object fabricante; - string str8; - string str9; - string str10; - string str11; - string str12; - string str13; - string str14; - string str15; - string str16; - int? nullable3; - TabelaReferencia tabelaReferencium; - string str17; - string str18; - Cor cor; - string str19; - string str20; - Action action = null; - List condicaos1 = new List() - { - new Condicao() - { - Campo = "d.idcontrole", - Valores = id.CriarValor() - } - }; - switch (status) - { - case StatusItem.Ativos: - { - condicaos1.AddRange(new List() - { - new Condicao() - { - Campo = "idsubstituido", - Valores = null - }, - new Condicao() - { - Campo = "cancelado", - Valores = null, - Grupo = 1, - Operacao = Operacao.Or - }, - new Condicao() - { - Campo = "cancelado", - Valores = "1".CriarValor(), - Grupo = 1, - Operacao = Operacao.Or, - Operador = Operador.Diferente - } - }); - break; - } - case StatusItem.Inativos: - { - condicaos1.AddRange(new List() - { - new Condicao() - { - Campo = "idsubstituido", - Valores = null, - Grupo = 1, - Operacao = Operacao.Or, - Operador = Operador.Diferente - }, - new Condicao() - { - Campo = "cancelado", - Valores = "1".CriarValor(), - Grupo = 1 - } - }); - break; - } - case StatusItem.Documento: - { - condicaos1 = new List() - { - new Condicao() - { - Campo = "d.iddocumento", - Valores = id.CriarValor() - } - }; - break; - } - } - DataTable dataTable2 = this._unitOfWork.Select(condicaos1.CreateParameters(0), "SELECT i.iditem, c.idramo, i.iddocumento, i.descricao, i.sinistrado, i.status, i.statusinc, i.idsubstituido, i.iddocumentocancelado, i.ordem FROM item i INNER JOIN documento d on d.iddocumento = i.iddocumento INNER JOIN controle c on c.idcontrole = d.idcontrole WHERE ", "ORDER BY i.ordem"); - if (dataTable2.Rows.Count == 0) - { - return new List(); - } - string str21 = dataTable2.AsEnumerable().First().Field("idramo").ToString(); - List list = dataTable2.AsEnumerable().Select((DataRow x) => x.Field("iditem")).ToList(); - DataTable dataTable3 = new DataTable(); - DataTable dataTable4 = new DataTable(); - DataTable dataTable5 = new DataTable(); - DataTable dataTable6 = new DataTable(); - DataTable dataTable7 = new DataTable(); - DataTable dataTable8 = new DataTable(); - DataTable dataTable9 = new DataTable(); - DataTable dataTable10 = new DataTable(); - DataTable dataTable11 = new DataTable(); - DataTable dataTable12 = new DataTable(); - while (list.Count > 0) - { - List nums = list.Take(1500).ToList(); - condicaos = new List() - { - new Condicao() - { - Campo = "iditem", - Valores = nums.CriarValor() - } - }; - dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT idcobertura, iditem, observacao, franquia, premio, lmi FROM cobertura WHERE ", ""); - dataTable12.Merge(dataTable1); - if (str21 != null) - { - length = str21.Length; - if (length == 1) - { - switch (str21[0]) - { - case '1': - case '2': - case '3': - { - goto Label1; - } - case '4': - case '8': - { - break; - } - case '5': - { - dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT a.*, f.descricao AS fabricante FROM auto a LEFT OUTER JOIN fabricante f ON f.idfabricante = a.IDFABRICANTE WHERE ", ""); - dataTable3.Merge(dataTable1); - goto Label0; - } - default: - { - goto Label0; - } - } - } - else if (length == 2) - { - switch (str21[1]) - { - case '0': - { - if (str21 == "10") - { - goto Label0; - } - if (str21 == "20") - { - dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT iditem, obs FROM granizo WHERE ", ""); - dataTable11.Merge(dataTable1); - goto Label0; - } - else - { - goto Label0; - } - } - case '1': - { - if (str21 == "31" || str21 == "41") - { - break; - } - goto Label0; - } - case '3': - { - if (str21 == "23" || str21 == "33") - { - break; - } - if (str21 == "13") - { - dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT iditem, obs FROM aeronautico WHERE ", ""); - dataTable10.Merge(dataTable1); - goto Label0; - } - else - { - if (str21 == "53") - { - goto Label0; - } - goto Label0; - } - } - case '5': - { - if (str21 == "15") - { - goto Label1; - } - goto Label0; - } - case '6': - { - if (str21 == "16" || str21 == "26") - { - break; - } - goto Label0; - } - case '7': - { - if (str21 == "17") - { - break; - } - goto Label0; - } - case '8': - { - if (str21 == "18") - { - goto Label1; - } - if (str21 == "28") - { - break; - } - goto Label0; - } - case '9': - { - if (str21 == "19" || str21 == "39" || str21 == "59") - { - break; - } - goto Label0; - } - default: - { - goto Label0; - } - } - } - else - { - goto Label0; - } - dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT iditem, obs FROM riscosdiversos WHERE ", ""); - dataTable9.Merge(dataTable1); - } - Label0: - dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT * FROM controlesinistro WHERE ", ""); - dataTable5.Merge(dataTable1); - if (dataTable1.Rows.Count > 0) - { - List condicaos2 = new List() - { - new Condicao() - { - Campo = "idcontrolesinistro", - Valores = dataTable5.AsEnumerable().Select((DataRow x) => x.Field("idcontrolesinistro")).ToList().CriarValor() - } - }; - dataTable1 = this._unitOfWork.Select(condicaos2.CreateParameters(0), "SELECT * FROM sinistro WHERE ", ""); - dataTable6.Merge(dataTable1); - List condicaos3 = new List() - { - new Condicao() - { - Campo = "idsinistro", - Valores = dataTable6.AsEnumerable().Select((DataRow x) => x.Field("idsinistro")).ToList().CriarValor() - } - }; - dataTable1 = this._unitOfWork.Select(condicaos3.CreateParameters(0), "SELECT * FROM sinistrovida WHERE ", ""); - dataTable8.Merge(dataTable1); - dataTable1 = this._unitOfWork.Select(condicaos3.CreateParameters(0), "SELECT * FROM sinistroauto WHERE ", ""); - dataTable7.Merge(dataTable1); - } - list = (nums.Count < 1500 ? new List() : list.Except(nums).ToList()); - } - List items = new List(); - Label4: - foreach (DataRow row in dataTable2.Rows) - { - Item item = new Item() - { - Id = long.Parse(row["iditem"].ToString()), - Documento = new Documento() - { - Id = long.Parse(row["iddocumento"].ToString()) - }, - Sinistrado = row["sinistrado"].ToString() == "1", - Descricao = row["descricao"].ToString(), - Status = row["status"].ToString(), - Ordem = new int?(int.Parse(row["ordem"].ToString())), - StatusInclusao = row["statusinc"].ToString() - }; - if (string.IsNullOrEmpty(row["iddocumentocancelado"].ToString())) - { - nullable = null; - nullable1 = nullable; - } - else - { - nullable1 = new long?(long.Parse(row["iddocumentocancelado"].ToString())); - } - item.IdDocumentoCancelado = nullable1; - if (string.IsNullOrEmpty(row["idsubstituido"].ToString())) - { - nullable = null; - nullable2 = nullable; - } - else - { - nullable2 = new long?(long.Parse(row["idsubstituido"].ToString())); - } - item.Substituido = nullable2; - item.Coberturas = ( - from x in dataTable12.AsEnumerable().Where((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString())).ToList() - select new Cobertura() - { - Id = x.Field("idcobertura"), - Observacao = x.Field("observacao"), - Franquia = (x.Field("franquia") == null ? decimal.Zero : x.Field("franquia")), - Lmi = (x.Field("lmi") == null ? decimal.Zero : x.Field("lmi")), - Premio = (x.Field("premio") == null ? decimal.Zero : x.Field("premio")) - }).ToList(); - granizo = item; - string str22 = row["idramo"].ToString(); - if (str22 != null) - { - length = str22.Length; - if (length == 1) - { - switch (str22[0]) - { - case '1': - case '2': - case '3': - { - goto Label3; - } - case '4': - case '8': - { - break; - } - case '5': - { - if (dataTable3.AsEnumerable().Where((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString())).ToList().Count == 0) - { - continue; - } - DataRow dataRow4 = dataTable3.AsEnumerable().FirstOrDefault((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString())); - Item item1 = granizo; - Auto auto = new Auto(); - if (dataRow4 != null) - { - str7 = dataRow4["IDFABRICANTE"].ToString(); - } - else - { - str7 = null; - } - if (string.IsNullOrEmpty(str7)) - { - fabricante = null; - } - else - { - fabricante = new Fabricante(); - if (dataRow4 != null) - { - str19 = dataRow4["IDFABRICANTE"].ToString(); - } - else - { - str19 = null; - } - ((Fabricante)fabricante).Id = int.Parse(str19); - if (dataRow4 != null) - { - str20 = dataRow4["fabricante"].ToString(); - } - else - { - str20 = null; - } - ((Fabricante)fabricante).Descricao = str20; - } - auto.Fabricante = (Fabricante)fabricante; - if (dataRow4 != null) - { - str8 = dataRow4["modelo"].ToString(); - } - else - { - str8 = null; - } - auto.Modelo = str8; - if (dataRow4 != null) - { - str9 = dataRow4["anofab"].ToString(); - } - else - { - str9 = null; - } - auto.AnoFabricacao = str9; - if (dataRow4 != null) - { - str10 = dataRow4["anomod"].ToString(); - } - else - { - str10 = null; - } - auto.AnoModelo = str10; - if (dataRow4 != null) - { - str11 = dataRow4["placa"].ToString(); - } - else - { - str11 = null; - } - auto.Placa = str11; - if (dataRow4 != null) - { - str12 = dataRow4["chassi"].ToString(); - } - else - { - str12 = null; - } - auto.Chassi = str12; - if (dataRow4 != null) - { - str13 = dataRow4["ci"].ToString(); - } - else - { - str13 = null; - } - auto.Ci = str13; - if (dataRow4 != null) - { - str14 = dataRow4["renavam"].ToString(); - } - else - { - str14 = null; - } - auto.Renavam = str14; - if (dataRow4 != null) - { - str15 = dataRow4["CEPpernoite"].ToString(); - } - else - { - str15 = null; - } - auto.CepPernoite = str15; - if (dataRow4 != null) - { - str16 = dataRow4["financiado"].ToString(); - } - else - { - str16 = null; - } - auto.Financiado = new bool?(str16 == "1"); - auto.TipoCobertura = (!string.IsNullOrEmpty(dataRow4["idtipocobertura"].ToString()) ? new TipoCobertura?((TipoCobertura)int.Parse(dataRow4["idtipocobertura"].ToString())) : new TipoCobertura?(0)); - if (string.IsNullOrEmpty(dataRow4["bonus"].ToString())) - { - nullable3 = null; - } - else - { - nullable3 = new int?(int.Parse(dataRow4["bonus"].ToString())); - } - auto.Bonus = nullable3; - auto.RegiaoCirculacao = dataRow4["regiaocirculacao"].ToString(); - if (!string.IsNullOrEmpty(dataRow4["idtabelareferencia"].ToString())) - { - tabelaReferencium = (TabelaReferencia)int.Parse(dataRow4["idtabelareferencia"].ToString()); - } - else - { - tabelaReferencium = TabelaReferencia.Molicar; - } - auto.TabelaReferencia = new TabelaReferencia?(tabelaReferencium); - auto.PorcentagemReferencia = (string.IsNullOrEmpty(dataRow4["porcentagemreferencia"].ToString()) ? decimal.Zero : decimal.Parse(dataRow4["porcentagemreferencia"].ToString())); - auto.Fipe = dataRow4["CODFIPE"].ToString(); - if (dataRow4 != null) - { - str17 = dataRow4["idcor"].ToString(); - } - else - { - str17 = null; - } - if (!string.IsNullOrEmpty(str17)) - { - if (dataRow4 != null) - { - str18 = dataRow4["idcor"].ToString(); - } - else - { - str18 = null; - } - cor = (Cor)int.Parse(str18); - } - else - { - cor = Cor.OutrosNull; - } - auto.Cor = new Cor?(cor); - item1.Auto = auto; - goto Label2; - } - default: - { - goto Label2; - } - } - } - else if (length == 2) - { - switch (str22[1]) - { - case '0': - { - if (str22 == "10") - { - goto Label2; - } - if (str22 == "20") - { - if (dataTable11.AsEnumerable().Where((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString())).ToList().Count <= 0) - { - goto Label2; - } - granizo.Granizo = new Granizo() - { - Observacao = dataTable11.AsEnumerable().FirstOrDefault((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString()))["obs"].ToString() - }; - goto Label2; - } - else - { - goto Label2; - } - } - case '1': - { - if (str22 == "31" || str22 == "41") - { - break; - } - goto Label2; - } - case '3': - { - if (str22 == "53") - { - goto Label2; - } - if (str22 == "23" || str22 == "33") - { - break; - } - if (str22 == "13") - { - if (dataTable10.AsEnumerable().Where((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString())).ToList().Count <= 0) - { - goto Label2; - } - granizo.Aeronautico = new Aeronautico() - { - Observacao = dataTable10.AsEnumerable().FirstOrDefault((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString()))["obs"].ToString() - }; - goto Label2; - } - else - { - goto Label2; - } - } - case '5': - { - if (str22 == "15") - { - goto Label3; - } - goto Label2; - } - case '6': - { - if (str22 == "16" || str22 == "26") - { - break; - } - goto Label2; - } - case '7': - { - if (str22 == "17") - { - break; - } - goto Label2; - } - case '8': - { - if (str22 == "18") - { - goto Label3; - } - if (str22 == "28") - { - break; - } - goto Label2; - } - case '9': - { - if (str22 == "19" || str22 == "39" || str22 == "59") - { - break; - } - goto Label2; - } - default: - { - goto Label2; - } - } - } - else - { - goto Label2; - } - if (dataTable9.AsEnumerable().Where((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString())).ToList().Count > 0) - { - granizo.RiscosDiversos = new RiscosDiversos() - { - Observacao = dataTable9.AsEnumerable().FirstOrDefault((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString()))["obs"].ToString() - }; - } - } - Label2: - List sinistros = new List(); - granizo.Sinistros = new List(); - foreach (DataRow row1 in dataTable5.Rows) - { - if (row1["iditem"].ToString() != row["iditem"].ToString()) - { - continue; - } - long num = long.Parse(row1["idcontrolesinistro"].ToString()); - EnumerableRowCollection dataRows = dataTable6.AsEnumerable().Where((DataRow x) => x.Field("idcontrolesinistro") == num); - Action action1 = action; - if (action1 == null) - { - Action action2 = (DataRow x) => { - DataRow dataRow; - DataRow dataRow1; - object sinistroVida; - object sinistroAuto; - DataTable cSu0024u003cu003e8_locals1 = dataTable8; - if (cSu0024u003cu003e8_locals1 != null) - { - dataRow = cSu0024u003cu003e8_locals1.AsEnumerable().FirstOrDefault((DataRow s) => s.Field("idsinistro") == x.Field("idsinistro")); - } - else - { - dataRow = null; - } - DataRow dataRow2 = dataRow; - DataTable dataTable = dataTable7; - if (dataTable != null) - { - dataRow1 = dataTable.AsEnumerable().FirstOrDefault((DataRow s) => s.Field("idsinistro") == x.Field("idsinistro")); - } - else - { - dataRow1 = null; - } - DataRow dataRow3 = dataRow1; - if (dataRow2 == null) - { - sinistroVida = null; - } - else - { - sinistroVida = new SinistroVida(); - ((DomainBase)sinistroVida).Id = dataRow2.Field("idsinistrovida"); - ((SinistroVida)sinistroVida).Beneficiario = dataRow2.Field("beneficiario"); - } - SinistroVida sinistroVida1 = (SinistroVida)sinistroVida; - if (dataRow3 == null) - { - sinistroAuto = null; - } - else - { - sinistroAuto = new SinistroAuto(); - ((DomainBase)sinistroAuto).Id = dataRow3.Field("idsinistroauto"); - } - SinistroAuto sinistroAuto1 = (SinistroAuto)sinistroAuto; - sinistros.Add(new Sinistro() - { - Id = x.Field("idsinistro"), - Numero = x.Field("numsinistro"), - DataReclamacao = x.Field("datareclamacao"), - StatusSinistro = (x.Field("idstatussinistro") != null ? new StatusSinistro?((StatusSinistro)int.Parse(x.Field("idstatussinistro").ToString())) : null), - DataLiquidacao = x.Field("dataliquidacao"), - ItemSinistrado = x.Field("itemsinistrado"), - Motivo = x.Field("motivo"), - Valor = x.Field("valor").GetValueOrDefault(), - SinistroVida = sinistroVida1, - SinistroAuto = sinistroAuto1 - }); - }; - Action action3 = action2; - action = action2; - action1 = action3; - } - dataRows.ForEach(action1); - granizo.Sinistros.Add(new ControleSinistro() - { - Id = num, - DataSinistro = row1.Field("datasinistro"), - Item = new Item() - { - Id = long.Parse(row["iditem"].ToString()) - }, - Sinistros = sinistros - }); - } - items.Add(granizo); - } - return items; - Label1: - dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT * FROM resempco WHERE ", ""); - dataTable4.Merge(dataTable1); - goto Label0; - Label3: - if (dataTable4.AsEnumerable().Where((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString())).ToList().Count == 0) - { - goto Label4; - } - DataRow dataRow5 = dataTable4.AsEnumerable().FirstOrDefault((DataRow x) => x.Field("iditem") == long.Parse(this.i["iditem"].ToString())); - Item item2 = granizo; - Patrimonial patrimonial = new Patrimonial(); - if (dataRow5 != null) - { - str = dataRow5["endereco"].ToString(); - } - else - { - str = null; - } - patrimonial.Endereco = str; - if (dataRow5 != null) - { - str1 = dataRow5["numero"].ToString(); - } - else - { - str1 = null; - } - patrimonial.Numero = str1; - if (dataRow5 != null) - { - str2 = dataRow5["complemento"].ToString(); - } - else - { - str2 = null; - } - patrimonial.Complemento = str2; - if (dataRow5 != null) - { - str3 = dataRow5["bairro"].ToString(); - } - else - { - str3 = null; - } - patrimonial.Bairro = str3; - if (dataRow5 != null) - { - str4 = dataRow5["cidade"].ToString(); - } - else - { - str4 = null; - } - patrimonial.Cidade = str4; - if (dataRow5 != null) - { - str5 = dataRow5["uf"].ToString(); - } - else - { - str5 = null; - } - patrimonial.Estado = str5; - if (dataRow5 != null) - { - str6 = dataRow5["cep"].ToString(); - } - else - { - str6 = null; - } - patrimonial.Cep = str6; - item2.Patrimonial = patrimonial; - goto Label2; - } - - public Item FindById(long id) - { - ItemDb itemDb = base.FindEntityById(id); - return ApplicationMapper.Mapper.Map(itemDb); - } - - public List FindByIds(List ids) - { - List list = ( - from x in base.All() - where ids.Contains(x.Id) - select x).ToList(); - return ApplicationMapper.Mapper.Map, List>(list); - } - - public List FindItens(List ids) - { - List list = ( - from x in base.All() - where ids.Contains(x.Id) - select x).ToList(); - return ApplicationMapper.Mapper.Map, List>(list); - } - - public List FindItens(long id, StatusItem status) - { - List items; - object connection; - SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl; - string str = ""; - switch (status) - { - case StatusItem.Ativos: - { - str = string.Format("AND d.idcontrole = {0} AND (cancelado IS NULL OR cancelado != '1') AND idsubstituido IS NULL", id); - break; - } - case StatusItem.Inativos: - { - str = string.Format("AND d.idcontrole = {0} AND (cancelado IS NOT NULL AND cancelado = '1' OR idsubstituido IS NOT NULL)", id); - break; - } - case StatusItem.Documento: - { - str = string.Format("AND d.iddocumento = {0}", id); - break; - } - case StatusItem.Controle: - { - str = string.Format("AND d.idcontrole = {0}", id); - break; - } - } - DataTable dataTable = new DataTable(); - DataTable dataTable1 = new DataTable(); - if (sessionFactory != null) - { - connection = sessionFactory.ConnectionProvider.GetConnection(); - } - else - { - connection = null; - } - using (SqlConnection sqlConnection = connection as SqlConnection) - { - using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.CommandText = string.Concat("SELECT i.* FROM item i INNER JOIN documento d on d.iddocumento = i.iddocumento WHERE 1=1 ", str); - using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) - { - sqlDataAdapter.SelectCommand = sqlCommand; - sqlDataAdapter.Fill(dataTable); - } - if (dataTable.Rows.Count != 0) - { - string str1 = string.Concat(" AND iditem IN (", string.Join(",", ( - from x in dataTable.AsEnumerable().ToList() - select x.Field("iditem")).ToList()), ")"); - sqlCommand.CommandText = string.Concat("SELECT iditem, idcontrolesinistro, datasinistro FROM controlesinistro WHERE 1=1 ", str1); - using (SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter()) - { - sqlDataAdapter1.SelectCommand = sqlCommand; - sqlDataAdapter1.Fill(dataTable1); - return dataTable.AsEnumerable().ToList().Select((DataRow x) => { - Item item = new Item() - { - Id = x.Field("iditem"), - Descricao = x.Field("descricao"), - Ordem = x.Field("ordem"), - Sinistrado = (x.Field("sinistrado") == null ? false : x.Field("sinistrado") == "1"), - Cancelado = (x.Field("cancelado") == null ? false : x.Field("cancelado") == "1"), - Substituicao = x.Field("idsubstituicao"), - Substituido = x.Field("idsubstituido"), - Status = x.Field("status"), - StatusInclusao = x.Field("statusinc") - }; - IEnumerable list = - from s in dataTable1.AsEnumerable().ToList() - where s.Field("iditem") == x.Field("iditem") - select s; - Func u003cu003e9_104 = ItemRepository.u003cu003ec.u003cu003e9__10_4; - if (u003cu003e9_104 == null) - { - u003cu003e9_104 = (DataRow s) => { - ControleSinistro controleSinistro = new ControleSinistro() - { - Id = s.Field("idcontrolesinistro") - }; - DateTime? nullable = s.Field("datasinistro"); - controleSinistro.DataSinistro = new DateTime?((nullable.HasValue ? nullable.GetValueOrDefault() : DateTime.MinValue)); - return controleSinistro; - }; - ItemRepository.u003cu003ec.u003cu003e9__10_4 = u003cu003e9_104; - } - item.Sinistros = list.Select(u003cu003e9_104).ToList(); - return item; - }).OrderBy((Item x) => x.Ordem).ToList(); - } - } - else - { - items = new List(); - } - } - } - return items; - } - - public List FindItens(List documento) - { - List items; - object connection; - SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl; - DataTable dataTable = new DataTable(); - if (sessionFactory != null) - { - connection = sessionFactory.ConnectionProvider.GetConnection(); - } - else - { - connection = null; - } - using (SqlConnection sqlConnection = connection as SqlConnection) - { - using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.CommandText = string.Concat("SELECT * FROM item WHERE iddocumento IN (", string.Join(",", - from x in documento - select x.Id), ")"); - using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) - { - sqlDataAdapter.SelectCommand = sqlCommand; - sqlDataAdapter.Fill(dataTable); - } - if (dataTable.Rows.Count != 0) - { - return ( - from x in dataTable.AsEnumerable().ToList() - select new Item() - { - Id = x.Field("iditem"), - Descricao = x.Field("descricao"), - Ordem = x.Field("ordem"), - Documento = new Documento() - { - Id = x.Field("iddocumento") - } - } into x - orderby x.Ordem - select x).ToList(); - } - else - { - items = new List(); - } - } - } - return items; - } - - public List FindItens(long id) - { - List list = ( - from x in base.All() - where x.Documento.Id == id - select x).ToList(); - return ApplicationMapper.Mapper.Map, List>(list); - } - - public int FindNextItem(long id) - { - int? nullable; - int? nullable1; - int? ordem; - int? nullable2; - List items = this.FindItens(id, StatusItem.Ativos); - if (items != null) - { - Item item = items.LastOrDefault(); - if (item != null) - { - ordem = item.Ordem; - } - else - { - nullable1 = null; - ordem = nullable1; - } - nullable = ordem; - if (nullable.HasValue) - { - nullable2 = new int?(nullable.GetValueOrDefault() + 1); - } - else - { - nullable1 = null; - nullable2 = nullable1; - } - } - else - { - nullable = null; - nullable2 = nullable; - } - nullable = nullable2; - return nullable.GetValueOrDefault(1); - } - - public Item Merge(Item item) - { - bool count; - List list; - ItemDb itemDb = ApplicationMapper.Mapper.Map(item); - IList coberturaDbs = itemDb.Coberturas; - if (coberturaDbs != null) - { - count = coberturaDbs.Count == 0; - } - else - { - count = false; - } - bool flag = count; - List list1 = ( - from x in this._unitOfWork.Query() - where x.Item.Id == itemDb.Id - select x).ToList(); - if (list1 != null) - { - list = list1.Where((CoberturaDb x) => { - IList coberturas = itemDb.Coberturas; - Func u003cu003e9_42 = ItemRepository.u003cu003ec.u003cu003e9__4_2; - if (u003cu003e9_42 == null) - { - u003cu003e9_42 = (CoberturaDb c) => c.Id; - ItemRepository.u003cu003ec.u003cu003e9__4_2 = u003cu003e9_42; - } - return !coberturas.Select(u003cu003e9_42).ToList().Contains(x.Id); - }).ToList(); - } - else - { - list = null; - } - List coberturaDbs1 = list; - itemDb.Coberturas = list1; - base.Merge(itemDb); - if (coberturaDbs1 != null && coberturaDbs1.Count > 0) - { - this._unitOfWork.Repository().DeleteRange(coberturaDbs1); - } - if (flag) - { - this._unitOfWork.Repository().DeleteRange(itemDb.Coberturas); - } - itemDb.Coberturas = null; - return ApplicationMapper.Mapper.Map(itemDb); - } - - public Item SaveOrUpdate(Item item) - { - ItemDb itemDb = ApplicationMapper.Mapper.Map(item); - this.SaveOrUpdate(itemDb); - return ApplicationMapper.Mapper.Map(itemDb); - } - } -} \ No newline at end of file -- cgit v1.2.3