Fórum Somar registros e filtrar Busca #466251
08/01/2014
0
Olá pessoal.
tenho em uma tabela firebird, dados como segue.
Nome_Aluno
Série (contém series 1ª, 2ª e 3ª)
Bimestre (contém bimestres 1º, 2º, 3º e 4º)
Ano_Letivo (2014, 2015, 2016, etc)
Aluno_Ativo (aqui vai um S ou N)
Preciso filtrar a tabela toda (todos os alunos) , de acordo com a escolha nos campos Edit do Bimestre, Série, Ano_Letivo, e aluno_Ativo
Por exemplo: Se os campos Edit, Série=1ª, o Bimestre=2º, Ano_letivo=2014 e Aluno_ativo=S, vai mostrar no Grid, todos os alunos dessa classe, filtrando pelos camposEdit.
Depois preciso tolalizar essa classe (quantos alunos ativos tem (aluno _ativo=S).
Fiz uma Query para filtrar isso, mas não atualiza o Grid.
Meu Datasource está ligado na Tabela (Firebird) e o Grid aponta para o Datasource.
A Query é quem teria que "mandar no DataSourrce, mas não sei como fazer isso.
Segue abaixo a rotina de locate (busca por nome ou por uma Query, dwe aocrdo com campos Edit), que tb dá erros se colocar a linha (query1.Open) no final)
Alguma santa Alma pode ajudar?
Agradeço e muito
procedure TfrmCadAlunos.btnLocalizarClick(Sender: TObject);
begin
frmPrincipal.TableCadAlunos.First;
if(frmPrincipal.TableCadAlunos.IsEmpty)then
begin
Panel1.Caption:='Tabela Cadastro de Alunos, vazia';
exit;
end;
if(RadioLocNome.Checked=true)then
begin
if(EdNomeAluno.Text='')then
begin
Panel1.Caption:='Digite o Nome do Aluno no Campo "Nome".';
exit;
end;
if not frmPrincipal.TableCadAlunos.Locate('Nome_Aluno',EdNomeAluno.Text,[LOPARTIALKEY,LOCASEINSENSITIVE])then
begin
Panel1.Caption:='Registro não Encontrado, Cadastre o Aluno';
EdNomeAluno.SetFocus;
exit;
end;
if frmPrincipal.TableCadAlunos.Locate('Nome_Aluno',EdNomeAluno.Text,[LOPARTIALKEY,LOCASEINSENSITIVE])then
begin
EdNomeAluno.Text:=frmPrincipal.TableCadAlunos.fieldByName('Nome_Aluno').AsString;
EdNum.Text:=frmPrincipal.TableCadAlunos.fieldByName('Num_Aluno').AsString;
EdAnoLetivo.Text:=frmPrincipal.TableCadAlunos.fieldByName('Ano_Letivo').AsString;
EdSerie.Text:=frmPrincipal.TableCadAlunos.fieldByName('serie').AsString;
EdBimestre.Text:=frmPrincipal.TableCadAlunos.fieldByName('bimestre').AsString;
EdAlunoAtivo.Text:=frmPrincipal.TableCadAlunos.fieldByName('Ativo_sn').AsString;
Panel1.Caption:='Registro Encontrado.';
exit;
end;
end;
if(RadioLocTurma.Checked=true)then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('Select * from TableCadAlunos where bimestre=:x1 and serie=:x2 and ano_letivo=:x3');
Query1.ParamByName('x1').AsString:=EdBimestre.Text;
Query1.ParamByName('x2').AsString:=EdSerie.Text;
Query1.ParamByName('x3').AsString:=EdAnoLetivo.Text;
//Query1.Open;
DBGrid1.Refresh;
end;
end;
tenho em uma tabela firebird, dados como segue.
Nome_Aluno
Série (contém series 1ª, 2ª e 3ª)
Bimestre (contém bimestres 1º, 2º, 3º e 4º)
Ano_Letivo (2014, 2015, 2016, etc)
Aluno_Ativo (aqui vai um S ou N)
Preciso filtrar a tabela toda (todos os alunos) , de acordo com a escolha nos campos Edit do Bimestre, Série, Ano_Letivo, e aluno_Ativo
Por exemplo: Se os campos Edit, Série=1ª, o Bimestre=2º, Ano_letivo=2014 e Aluno_ativo=S, vai mostrar no Grid, todos os alunos dessa classe, filtrando pelos camposEdit.
Depois preciso tolalizar essa classe (quantos alunos ativos tem (aluno _ativo=S).
Fiz uma Query para filtrar isso, mas não atualiza o Grid.
Meu Datasource está ligado na Tabela (Firebird) e o Grid aponta para o Datasource.
A Query é quem teria que "mandar no DataSourrce, mas não sei como fazer isso.
Segue abaixo a rotina de locate (busca por nome ou por uma Query, dwe aocrdo com campos Edit), que tb dá erros se colocar a linha (query1.Open) no final)
Alguma santa Alma pode ajudar?
Agradeço e muito
procedure TfrmCadAlunos.btnLocalizarClick(Sender: TObject);
begin
frmPrincipal.TableCadAlunos.First;
if(frmPrincipal.TableCadAlunos.IsEmpty)then
begin
Panel1.Caption:='Tabela Cadastro de Alunos, vazia';
exit;
end;
if(RadioLocNome.Checked=true)then
begin
if(EdNomeAluno.Text='')then
begin
Panel1.Caption:='Digite o Nome do Aluno no Campo "Nome".';
exit;
end;
if not frmPrincipal.TableCadAlunos.Locate('Nome_Aluno',EdNomeAluno.Text,[LOPARTIALKEY,LOCASEINSENSITIVE])then
begin
Panel1.Caption:='Registro não Encontrado, Cadastre o Aluno';
EdNomeAluno.SetFocus;
exit;
end;
if frmPrincipal.TableCadAlunos.Locate('Nome_Aluno',EdNomeAluno.Text,[LOPARTIALKEY,LOCASEINSENSITIVE])then
begin
EdNomeAluno.Text:=frmPrincipal.TableCadAlunos.fieldByName('Nome_Aluno').AsString;
EdNum.Text:=frmPrincipal.TableCadAlunos.fieldByName('Num_Aluno').AsString;
EdAnoLetivo.Text:=frmPrincipal.TableCadAlunos.fieldByName('Ano_Letivo').AsString;
EdSerie.Text:=frmPrincipal.TableCadAlunos.fieldByName('serie').AsString;
EdBimestre.Text:=frmPrincipal.TableCadAlunos.fieldByName('bimestre').AsString;
EdAlunoAtivo.Text:=frmPrincipal.TableCadAlunos.fieldByName('Ativo_sn').AsString;
Panel1.Caption:='Registro Encontrado.';
exit;
end;
end;
if(RadioLocTurma.Checked=true)then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('Select * from TableCadAlunos where bimestre=:x1 and serie=:x2 and ano_letivo=:x3');
Query1.ParamByName('x1').AsString:=EdBimestre.Text;
Query1.ParamByName('x2').AsString:=EdSerie.Text;
Query1.ParamByName('x3').AsString:=EdAnoLetivo.Text;
//Query1.Open;
DBGrid1.Refresh;
end;
end;
Alexandre
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)