Fórum Ajuda em uma Função que checa se foi cadastrado um Advogado #430176
30/11/2012
0
var QueryAdvogado : TQuery;
begin
QueryAdvogado := TQuery.create(application);
QueryAdvogado.DatabaseName := 'SisRecurso';
QueryAdvogado.SessionName := 'default';
QueryAdvogado.Close;
QueryAdvogado.SQL.Clear;
QueryAdvogado.SQL.add('SELECT * FROM DoiAtos ');
QueryAdvogado.SQL.Add(' WHERE Livro =' +QuotedStr(sLivro)+ ' AND FolhaIni =' +QuotedStr(sFolha)+ ' AND Ordem =' +QuotedStr(sTermo)+ 'AND testatipocentral =' +QuotedStr(tipocentral));
QueryAdvogado.Prepare;
QueryAdvogado.Open;
QueryAdvogado.First;
while not(queryAdvogado.Eof) do
begin
if (QueryAdvogado.FieldByName('CESDQUALIDADE').AsString = 'ADVOGADO(A)') then
begin
Result := 'S';
break;
end
else
Result := 'N'
;
QueryAdvogado.Next;
end;
QueryAdvogado.close;
end;
essa é a função que filtra onde os registros de livro, folha e termo são iguais, se um dos registros tem advogado.
mas, com os meus testes mesmo cadastrando um advogado quando cai no IF, ele não esta trazendo nada, que por sua vez
considera que não existem advogados nos registros selecionados.
Alguém poderia me ajudar?
Luis Flores
Curtir tópico
+ 0Posts
30/11/2012
Roney Melo
if (not QueryAdvogado.IsEmpty) then// se o result da Query não for vazio, significa que teve alguma coisa.
begin
Result := 'S';
break;
end
else
Result := 'N';
Gostei + 0
30/11/2012
Claudia Nogueira
Ao meu ver o código ficaria melhor assim:
Vou usar citação pra ficar melhor pra visualizar.
function TFrmCadAtos.ChecaAdvogado(sLivro, sFolha, sTermo, tipocentral: String): String;
Var
QueryAdvogado : TQuery;
sSql : String;
begin
try
sSql := '';
if sLivro <> '' then
sSql := sSql + ' AND (Livro = '+QuotedStr(sLivro)+') ';
if sTermo <> '' then
sSql := sSql + ' AND (Ordem = '+QuotedStr(sTermo)+') ';
if tipocentral <> '' then
sSql := sSql + ' AND (testatipocentral = '+QuotedStr(tipocentral)+') ';
QueryAdvogado := TQuery.Create(application);
QueryAdvogado.DatabaseName := 'SisRecurso';
QueryAdvogado.SessionName := 'default';
QueryAdvogado.Close;
QueryAdvogado.SQL.Clear;
QueryAdvogado.SQL.add('SELECT * FROM DoiAtos ');
QueryAdvogado.SQL.Add('WHERE (CESDQUALIDADE = ''ADVOGADO(A)'') ');
QueryAdvogado.SQL.Add(sSql);
QueryAdvogado.Prepare;
QueryAdvogado.Open;
if (not QueryAdvogado.IsEmpty) then
Result := 'S'
else
Result := 'N';
QueryAdvogado.Close;
finally
QueryAdvogado.Free;
end;
end;
Gostei + 0
05/12/2012
Roney Melo
Ao meu ver o código ficaria melhor assim:
Vou usar citação pra ficar melhor pra visualizar.
function TFrmCadAtos.ChecaAdvogado(sLivro, sFolha, sTermo, tipocentral: String): String;
Var
QueryAdvogado : TQuery;
sSql : String;
begin
try
sSql := '';
if sLivro <> '' then
sSql := sSql + ' AND (Livro = '+QuotedStr(sLivro)+') ';
if sTermo <> '' then
sSql := sSql + ' AND (Ordem = '+QuotedStr(sTermo)+') ';
if tipocentral <> '' then
sSql := sSql + ' AND (testatipocentral = '+QuotedStr(tipocentral)+') ';
QueryAdvogado := TQuery.Create(application);
QueryAdvogado.DatabaseName := 'SisRecurso';
QueryAdvogado.SessionName := 'default';
QueryAdvogado.Close;
QueryAdvogado.SQL.Clear;
QueryAdvogado.SQL.add('SELECT * FROM DoiAtos ');
QueryAdvogado.SQL.Add('WHERE (CESDQUALIDADE = ''ADVOGADO(A)'') ');
QueryAdvogado.SQL.Add(sSql);
QueryAdvogado.Prepare;
QueryAdvogado.Open;
if (not QueryAdvogado.IsEmpty) then
Result := 'S'
else
Result := 'N';
QueryAdvogado.Close;
finally
QueryAdvogado.Free;
end;
end;
Show de bola Claudia!!!
Gostei + 0
05/12/2012
Luis Flores
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)