public uint?FindByDescricao(GDASession session, uint idMedidaProjeto, string descricao) { var trataDescr = "REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(Descricao, ' ', ''), '.', ''), 'ã', 'a'), 'á', 'a'), 'â', 'a'), 'é', 'e'), 'ê', 'e'), 'í', 'i'), 'ç', 'c')"; var parametroDescricao = new GDAParameter("?descricao", MedidaProjetoModelo.TrataDescricao(descricao)); if (idMedidaProjeto > 0) { if (objPersistence.ExecuteSqlQueryCount(string.Format("SELECT COUNT(*) FROM medida_projeto WHERE IdMedidaProjeto={0} AND {1}=?descricao", idMedidaProjeto, trataDescr), parametroDescricao) > 0) { return(idMedidaProjeto); } } if (!string.IsNullOrWhiteSpace(descricao)) { var sqlBase = string.Format("SELECT {0} FROM medida_projeto WHERE {1}=?descricao", "{0}", trataDescr); if (objPersistence.ExecuteSqlQueryCount(string.Format(sqlBase, "COUNT(*)"), parametroDescricao) > 0) { return(ExecuteScalar <uint?>(string.Format(sqlBase, "IdMedidaProjeto"), parametroDescricao)); } } return(null); }
/// <summary> /// Verifica se a descrição da medida está sendo usada em alguma expressão /// </summary> /// <param name="descricao"></param> /// <returns></returns> private bool EstaEmUso(GDASession sessao, string descricao) { if (objPersistence.ExecuteSqlQueryCount(sessao, "Select Count(*) From peca_projeto_modelo Where InStr(calculoQtde, ?calcQtd)>0", new GDAParameter("?calcQtd", MedidaProjetoModelo.TrataDescricao(descricao).ToUpper())) > 0) { return(true); } if (objPersistence.ExecuteSqlQueryCount(sessao, "Select Count(*) From peca_projeto_modelo Where InStr(calculoAltura, ?calcAlt)>0", new GDAParameter("?calcAlt", MedidaProjetoModelo.TrataDescricao(descricao).ToUpper())) > 0) { return(true); } if (objPersistence.ExecuteSqlQueryCount(sessao, "Select Count(*) From peca_projeto_modelo Where InStr(calculoLargura, ?calcLarg)>0", new GDAParameter("?calcLarg", MedidaProjetoModelo.TrataDescricao(descricao).ToUpper())) > 0) { return(true); } if (objPersistence.ExecuteSqlQueryCount(sessao, "Select Count(*) From material_projeto_modelo Where InStr(calculoQtde, ?calcQtd)>0", new GDAParameter("?calcQtd", MedidaProjetoModelo.TrataDescricao(descricao).ToUpper())) > 0) { return(true); } if (objPersistence.ExecuteSqlQueryCount(sessao, "Select Count(*) From material_projeto_modelo Where InStr(calculoAltura, ?calcAlt)>0", new GDAParameter("?calcAlt", MedidaProjetoModelo.TrataDescricao(descricao).ToUpper())) > 0) { return(true); } if (objPersistence.ExecuteSqlQueryCount(sessao, "Select Count(*) From posicao_peca_modelo Where InStr(calc, ?calc)>0", new GDAParameter("?calc", MedidaProjetoModelo.TrataDescricao(descricao).ToUpper())) > 0) { return(true); } if (objPersistence.ExecuteSqlQueryCount(sessao, "Select Count(*) From posicao_peca_individual Where InStr(calc, ?calc)>0", new GDAParameter("?calc", MedidaProjetoModelo.TrataDescricao(descricao).ToUpper())) > 0) { return(true); } return(false); }