public ItemEstoque RetornarUltimoAssociadoPorTipoId(int TipoItemEstoqueId) { ItemEstoque ItemsEstoque = null; using (var connection = DapperConnection.Create()) { ItemsEstoque = connection.Query <ItemEstoque, TipoItemEstoque, ItemEstoque>( @"select * from tbl_item_estoque ite inner join tbl_tipo_item_estoque tie on tie_id = ite_tie_id where ite_tie_id = @TipoItemEstoqueId and ite_pra_id is not null order by ite_id desc limit 1", (ITE, TIE) => { ITE.TipoItemEstoque = TIE; return(ITE); }, param: new { TipoItemEstoqueId }, splitOn: "ite_id, tie_id" ).FirstOrDefault(); } return(ItemsEstoque); }
public bool Alterar(T objeto) { string tabela = ""; try { tabela = typeof(T).GetCustomAttributesData().FirstOrDefault().ConstructorArguments.FirstOrDefault().Value.ToString(); } catch (Exception) { return(false); } string colunaId = ""; string colunasSet = ""; var valoresDictionary = new Dictionary <string, object>(); objeto.Mappings.PropertyMaps.ToList().ForEach(pm => { if (!pm.PropertyInfo.Name.Contains("READONLY")) { if (pm.PropertyInfo.Name != "Id") { if (pm.PropertyInfo.PropertyType.Namespace == "NetTopologySuite.Geometries") { var geometria = pm.PropertyInfo.GetValue(objeto); string geometriaString = geometria == null ? null : geometria.ToString(); valoresDictionary.Add("@" + pm.PropertyInfo.Name, geometriaString); } else { valoresDictionary.Add("@" + pm.PropertyInfo.Name, pm.PropertyInfo.GetValue(objeto)); } colunasSet += pm.ColumnName + " = @" + pm.PropertyInfo.Name + ", "; } else { colunaId = pm.ColumnName; } } }); colunasSet = colunasSet.Substring(0, colunasSet.Length - 2); string sql = "update " + tabela + " set " + colunasSet + " where " + colunaId + " = " + objeto.Id + ";"; var parametros = new DynamicParameters(valoresDictionary); int linhasAlteradas = 0; using (var connection = DapperConnection.Create()) { linhasAlteradas = connection.Execute(sql, parametros); } return(linhasAlteradas > 0); }
public List <SistemaConfiguracao> RetornarTodos() { List <SistemaConfiguracao> SistemaConfiguracao; using (var connection = DapperConnection.Create()) { SistemaConfiguracao = connection.Query <SistemaConfiguracao>( @"select * from tbl_sistema_configuracao sic where sic_ativo = true order by sic_nome" ).ToList(); } return(SistemaConfiguracao); }
public List <Armazem> RetornarTodos() { List <Armazem> Armazem; using (var connection = DapperConnection.Create()) { Armazem = connection.Query <Armazem>( @"select * from tbl_armazem arm where arm_ativo is true order by arm_nome" ).ToList(); } return(Armazem); }
public List <Prateleira> RetornarPorEstanteId(int estanteId) { List <Prateleira> Prateleiras = new List <Prateleira>(); using (var connection = DapperConnection.Create()) { Prateleiras = connection.Query <Prateleira>( @"select * from tbl_prateleira pra where pra_est_id = @estanteId", param: new { estanteId } ).ToList(); } return(Prateleiras); }
public List <Camada> RetornarTodos() { List <Camada> Camada; using (var connection = DapperConnection.Create()) { Camada = connection.Query <Camada>( @"select * from tbl_camada cam where cam_ativo is true order by cam_nome" ).ToList(); } return(Camada); }
public override Armazem RetornarPorId(int id) { Armazem Armazem; using (var connection = DapperConnection.Create()) { Armazem = connection.Query <Armazem>( @"select * from tbl_armazem arm where arm_id = @id limit 1", param: new { id } ).FirstOrDefault(); } return(Armazem); }
public SistemaConfiguracao RetornarPorNome(string nome) { SistemaConfiguracao SistemaConfiguracao; using (var connection = DapperConnection.Create()) { SistemaConfiguracao = connection.Query <SistemaConfiguracao>( @"select * from tbl_sistema_configuracao sic where lower(sic_nome) = @nome and sic_ativo = true limit 1", param: new { nome = nome.ToLower() } ).FirstOrDefault(); } return(SistemaConfiguracao); }
public override Prateleira RetornarPorId(int id) { Prateleira Prateleira; using (var connection = DapperConnection.Create()) { Prateleira = connection.Query <Prateleira>( @"select * from tbl_prateleira pra where pra_id = @id limit 1", param: new { id } ).FirstOrDefault(); } return(Prateleira); }
public override SistemaConfiguracao RetornarPorId(int id) { SistemaConfiguracao SistemaConfiguracao; using (var connection = DapperConnection.Create()) { SistemaConfiguracao = connection.Query <SistemaConfiguracao>( @"select * from tbl_sistema_configuracao sic where sic_id = @id limit 1", param: new { id } ).FirstOrDefault(); } return(SistemaConfiguracao); }
public Camada RetornarPorCamadaNomeArmazemId(string CamadaNome, int ArmazemId) { Camada Camada; using (var connection = DapperConnection.Create()) { Camada = connection.Query <Camada>( @"select * from tbl_camada cam where cam_nome = @CamadaNome and cam_arm_id = @ArmazemId limit 1", param: new { CamadaNome, ArmazemId } ).FirstOrDefault(); } return(Camada); }
public override Camada RetornarPorId(int id) { Camada Camada; using (var connection = DapperConnection.Create()) { Camada = connection.Query <Camada>( @"select * from tbl_camada cam where cam_id = @id limit 1", param: new { id } ).FirstOrDefault(); } return(Camada); }
public override TipoItemEstoque RetornarPorId(int id) { TipoItemEstoque TipoItemEstoque; using (var connection = DapperConnection.Create()) { TipoItemEstoque = connection.Query <TipoItemEstoque>( @"select * from tbl_tipo_item_estoque tie where tie_id = @id limit 1", param: new { id } ).FirstOrDefault(); } return(TipoItemEstoque); }
public List <TipoItemEstoque> RetornarTodosAssociados() { List <TipoItemEstoque> TipoItemEstoque; using (var connection = DapperConnection.Create()) { TipoItemEstoque = connection.Query <TipoItemEstoque>( @"select * from tbl_tipo_item_estoque tie where tie_ativo is true and exists (select 1 from tbl_item_estoque where ite_tie_id = tie_id and ite_pra_id is not null limit 1) order by tie_nome" ).ToList(); } return(TipoItemEstoque); }
public override Estante RetornarPorId(int id) { Estante Estante; using (var connection = DapperConnection.Create()) { Estante = connection.Query <Estante>( @"select * from tbl_estante est where est_id = @id limit 1", param: new { id } ).FirstOrDefault(); } return(Estante); }
public List <Estante> RetornarEstantesNaoPresentesNoMapa(int ArmazemId = 1) { List <Estante> Estante; using (var connection = DapperConnection.Create()) { Estante = connection.Query <Estante>( @"select * from tbl_estante est inner join tbl_poligono pol on est_pol_id = pol_id and pol_ativo is false where est_ativo is true and est_arm_id = @ArmazemId", new { ArmazemId } ).ToList(); } return(Estante); }
public List <Estante> RetornarTodosComItens(int ArmazemId = 1) { List <Estante> Estante = new List <Estante>(); using (var connection = DapperConnection.Create()) { connection.Query <Estante, Prateleira, Estante>( @"select * from tbl_estante est inner join tbl_prateleira pra on pra_est_id = est_id where est_ativo is true and est_arm_id = @ArmazemId", (EST, PRA) => { var estante = Estante.Where(est => est.Id == EST.Id).FirstOrDefault() ?? EST; if (estante.Prateleiras == null) { estante.Prateleiras = new List <Prateleira>(); } PRA.Estante = estante; estante.Prateleiras.Add(PRA); if (!Estante.Exists(est => est.Id == EST.Id)) { Estante.Add(EST); } return(EST); }, new { ArmazemId }, splitOn: "est_id, pra_id" ).ToList(); } var itemEstoqueCore = new ItemEstoqueCore(); Parallel.ForEach(Estante, estante => { Parallel.ForEach(estante.Prateleiras, prateleira => { prateleira.ItemsEstoque = itemEstoqueCore.RetornarPorPrateleiraId(prateleira.Id); }); }); return(Estante); }
public List <ItemEstoque> RetornarNaoEstocados() { List <ItemEstoque> ItemEstoque; using (var connection = DapperConnection.Create()) { ItemEstoque = connection.Query <ItemEstoque, TipoItemEstoque, ItemEstoque>( @"select * from tbl_item_estoque ite inner join tbl_tipo_item_estoque tie on tie_id = ite_tie_id where ite_ativo is true and ite_pra_id is null", (ITE, TIE) => { ITE.TipoItemEstoque = TIE; return(ITE); }, splitOn: "ite_id, tie_id" ).ToList(); } return(ItemEstoque); }
public bool Deletar(T objeto) { string tabela = ""; try { tabela = typeof(T).GetCustomAttributesData().FirstOrDefault().ConstructorArguments.FirstOrDefault().Value.ToString(); } catch (Exception) { return(false); } string colunaId = ""; objeto.Mappings.PropertyMaps.ToList().ForEach(pm => { if (pm.PropertyInfo.Name == "Id") { colunaId = pm.ColumnName; } }); if (colunaId == "") { return(false); } string sql = "delete from " + tabela + " where " + colunaId + " = " + objeto.Id + ";"; int linhasAlteradas = 0; using (var connection = DapperConnection.Create()) { linhasAlteradas = connection.Execute(sql); } return(linhasAlteradas > 0); }
public List <Poligono> RetornarPorCamadaId(int CamadaId) { List <Poligono> Poligonos; using (var connection = DapperConnection.Create()) { Poligonos = connection.Query <Poligono, Camada, Poligono>( @"select * from tbl_poligono pol inner join tbl_camada cam on cam_id = pol_cam_id where pol_cam_id = @CamadaId and pol_ativo is true", (POL, CAM) => { POL.Camada = CAM; return(POL); }, param: new { CamadaId }, splitOn: "pol_id, cam_id" ).ToList(); } return(Poligonos); }
public List <ItemEstoque> RetornarPorPrateleiraId(int prateleiraId) { var ItemsEstoque = new List <ItemEstoque>(); using (var connection = DapperConnection.Create()) { ItemsEstoque = connection.Query <ItemEstoque, TipoItemEstoque, ItemEstoque>( @"select * from tbl_item_estoque ite inner join tbl_tipo_item_estoque tie on tie_id = ite_tie_id where ite_pra_id = @prateleiraId", (ITE, TIE) => { ITE.TipoItemEstoque = TIE; return(ITE); }, param: new { prateleiraId }, splitOn: "ite_id, tie_id" ).ToList(); } return(ItemsEstoque); }
public List <Estante> RetornarEstantesAssociadas() { List <Estante> Estante = new List <Estante>(); using (var connection = DapperConnection.Create()) { connection.Query <Estante, Prateleira, Estante>( @"select * from tbl_estante est inner join tbl_prateleira pra on pra_est_id = est_id where est_ativo is true and est_pol_id is not null", (EST, PRA) => { var estante = Estante.Where(est => est.Id == EST.Id).FirstOrDefault() ?? EST; if (estante.Prateleiras == null) { estante.Prateleiras = new List <Prateleira>(); } PRA.Estante = estante; estante.Prateleiras.Add(PRA); if (!Estante.Exists(est => est.Id == EST.Id)) { Estante.Add(EST); } return(EST); }, null, splitOn: "est_id, pra_id" ).ToList(); } return(Estante); }
public override ItemEstoque RetornarPorId(int id) { ItemEstoque ItemEstoque; using (var connection = DapperConnection.Create()) { ItemEstoque = connection.Query <ItemEstoque, TipoItemEstoque, ItemEstoque>( @"select * from tbl_item_estoque ite inner join tbl_tipo_item_estoque tie on tie_id = ite_tie_id where ite_id = @id limit 1", (ITE, TIE) => { ITE.TipoItemEstoque = TIE; return(ITE); }, param: new { id }, splitOn: "ite_id, tie_id" ).FirstOrDefault(); } return(ItemEstoque); }
public List <TipoItemEstoque> RetornarTodos() { List <TipoItemEstoque> TipoItemEstoque; using (var connection = DapperConnection.Create()) { TipoItemEstoque = connection.Query <TipoItemEstoque, bool, TipoItemEstoque>( @"select *, exists (select 1 from tbl_item_estoque where ite_tie_id = tie_id and ite_pra_id is not null limit 1) as possui_associacao from tbl_tipo_item_estoque tie where tie_ativo is true order by tie_nome", (TIE, PossuiAssociacao) => { TIE.PossuiAssociacao = PossuiAssociacao; return(TIE); }, null, splitOn: "tie_id, possui_associacao" ).ToList(); } return(TipoItemEstoque); }
public List <Poligono> RetornarTodos() { List <Poligono> Poligonos; using (var connection = DapperConnection.Create()) { Poligonos = connection.Query <Poligono, Camada, Poligono>( @"select * from tbl_poligono pol inner join tbl_camada cam on cam_id = pol_cam_id and cam_ativo is true where pol_ativo = true order by cam_nome", (POL, CAM) => { POL.Camada = CAM; return(POL); }, null, splitOn: "pol_id, cam_id" ).ToList(); } return(Poligonos); }
public List <Estante> RetornarTodos(int ArmazemId = 1) { List <Estante> Estante; using (var connection = DapperConnection.Create()) { Estante = connection.Query <Estante, int?, Estante>( @"select est.*, pol_id from tbl_estante est left join tbl_poligono pol on est_pol_id = pol_id and pol_ativo is false where est_ativo is true and est_arm_id = @ArmazemId order by est_id desc", (EST, Associado) => { EST.Associado = Associado == null; return(EST); }, new { ArmazemId }, splitOn: "est_id, pol_id" ).ToList(); } return(Estante); }
public override Poligono RetornarPorId(int id) { Poligono Poligono; using (var connection = DapperConnection.Create()) { Poligono = connection.Query <Poligono, Camada, Poligono>( @"select * from tbl_poligono pol inner join tbl_camada cam on cam_id = pol_cam_id where pol_id = @id limit 1", (POL, CAM) => { POL.Camada = CAM; return(POL); }, param: new { id }, splitOn: "pol_id, cam_id" ).FirstOrDefault(); } return(Poligono); }
public bool Inserir(T novoObjeto) { string tabela = ""; try { tabela = typeof(T).GetCustomAttributesData().FirstOrDefault().ConstructorArguments.FirstOrDefault().Value.ToString(); } catch (Exception) { return(false); } string colunaId = ""; string colunas = ""; string valoresParam = ""; var valoresDictionary = new Dictionary <string, object>(); novoObjeto.Mappings.PropertyMaps.ToList().ForEach(pm => { if (!pm.PropertyInfo.Name.Contains("READONLY")) { if (pm.PropertyInfo.Name != "Id") { if (pm.PropertyInfo.PropertyType.Namespace == "NetTopologySuite.Geometries") { var geometria = pm.PropertyInfo.GetValue(novoObjeto); string geometriaString = geometria == null ? null : geometria.ToString(); valoresDictionary.Add("@" + pm.PropertyInfo.Name, geometriaString); } else { valoresDictionary.Add("@" + pm.PropertyInfo.Name, pm.PropertyInfo.GetValue(novoObjeto)); } colunas += pm.ColumnName + ", "; valoresParam += "@" + pm.PropertyInfo.Name + ", "; } else { colunaId = pm.ColumnName; } } }); colunas = colunas.Substring(0, colunas.Length - 2); valoresParam = valoresParam.Substring(0, valoresParam.Length - 2); string sql = "insert into " + tabela + " (" + colunas + ") values (" + valoresParam + ") returning " + colunaId + ";"; var parametros = new DynamicParameters(valoresDictionary); int idInserido = 0; using (var connection = DapperConnection.Create()) { idInserido = connection.QuerySingle <int>(sql, parametros); } novoObjeto.Id = idInserido; return(idInserido != 0); }