Você está na página 1de 8

Relatrio Master Detalhes por passagem de parmetro A criao de formulrio master/detalhes requer o uso de uma tabela master e de uma

tabela detalhes, para este exemplo estaremos utilizando a tabela ORDEM_SERVICO como master e a tabela ORDEM_SERVICO_SERVICO

Componentes utilizados: 1 IBDataBase da guia Interbase; 1 - IBTransaction1 da guia Interbase; 2 DataSource da guia DataAccess; 2 IBQuery da guia Interbase; 2 frxDataSet da guia FastReport 4.0; 1 frxReport da guia FastReport 4.0; 1. Faa a ligao do IBDataBase com o banco de dados BANCO.GDB.

2. Ligue o IBTransaction com a IBDataBase e faa o teste de conexo.

3. A primeira query ligar com o primeiro datasource e preencher a SQL

4. Duplo clique sobre a query, boto direito e selecionar a opo Add All Fields, para adicionar todos os campos pertencente a tabela.

5. A segunda IBQuery deve ser ligada com o IBDataBase, preencha a opo SQL

6. E na opo DataSource da segunda query, aponte para DataSorce1 7. Duplo clique sobre a query, boto direito e selecionar a opo Add All Fields, para adicionar todos os campos pertencente a tabela. 8. Asinalar ao programa que esta utilizando a frxDataSet atravs do Menu Report Data Selecionar as duas; 9. Duplo clique sobre o frxReport; 10. Crie um novo Relatrio, e apague todas as bandas que foram inseridas automaticamente. 11. Insira novos Memol conforme o modelo:

12. Aps acertar o designer do seu relatrio, chegou a hora de codificar para passar os parmetros para a rea de Servios 13. Crie no seu formulrio um campo Edit para receber o numero da ordem de servio a ser impressa:

14. No boto imprimir digite: var StrLiga : String; NumeroProd : integer; begin StrLiga:= 'where';

IBQuery1.Close; with IBQuery1.SQL do begin Clear; Add('select OS.*, C.RSOCIAL, C.ENDERECO, '+ ' C.CIDADE, C.BAIRRO, C.CEP, C.FONE '+ ' from ORDEM_SERVICO OS inner join '+ ' CLIENTE C '+ ' on OS.ID_CLIENTE = C.ID '); if Edit1.Text <> '' then begin StrToInt(Edit1.Text); Add(StrLiga+' OS.ID = '+Edit1.Text); end; IBQuery1.Open; //Limpar Memo Codigo (frxReport1.FindObject('COD1') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('COD2') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('COD3') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('COD4') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('COD5') as TfrxMemoView).Memo.Text:= ''; //Limpa Descrio (frxReport1.FindObject('DES1') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('DES2') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('DES3') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('DES4') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('DES5') as TfrxMemoView).Memo.Text:= ''; //Limpa Quantidade (frxReport1.FindObject('QTD1') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('QTD2') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('QTD3') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('QTD4') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('QTD5') as TfrxMemoView).Memo.Text:= ''; //Limpa Valor Unitarios

(frxReport1.FindObject('VUN1') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('VUN2') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('VUN3') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('VUN4') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('VUN5') as TfrxMemoView).Memo.Text:= ''; //Limpa Valor Total (frxReport1.FindObject('VTO1') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('VTO2') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('VTO3') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('VTO4') as TfrxMemoView).Memo.Text:= ''; (frxReport1.FindObject('VTO5') as TfrxMemoView).Memo.Text:= ''; IBQuery2.Close; with IBQuery2.SQL do begin Clear; Add('select * from ORDEM_SERVICO_SERVICO '); if Edit1.Text <> '' then begin StrToInt(Edit1.Text); Add(StrLiga+' ID_ORDEM = '+Edit1.Text); end; IBQuery2.Open; IBQuery2.First; while not IBQuery2.Eof do begin for NumeroProd:= 1 to 5 do begin case NumeroProd of 1: begin (frxReport1.FindObject('COD1')as TfrxMemoView).Memo.Text:= IBQuery2ID_ORDEM.AsString; (frxReport1.FindObject('DES1')as TfrxMemoView).Memo.Text:= IBQuery2DESCRICAO.AsString; (frxReport1.FindObject('QTD1') as TfrxMemoView).Memo.Text:= IBQuery2QTDADE.AsString; (frxReport1.FindObject('VUN1') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_UNIT.AsString; (frxReport1.FindObject('VTO1') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_TOTAL.AsString; end;

2: begin (frxReport1.FindObject('COD2')as TfrxMemoView).Memo.Text:= IBQuery2ID_ORDEM.AsString; (frxReport1.FindObject('DES2')as TfrxMemoView).Memo.Text:= IBQuery2DESCRICAO.AsString; (frxReport1.FindObject('QTD2') as TfrxMemoView).Memo.Text:= IBQuery2QTDADE.AsString; (frxReport1.FindObject('VUN2') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_UNIT.AsString; (frxReport1.FindObject('VTO2') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_TOTAL.AsString; end; 3: begin (frxReport1.FindObject('COD3')as TfrxMemoView).Memo.Text:= IBQuery2ID_ORDEM.AsString; (frxReport1.FindObject('DES3')as TfrxMemoView).Memo.Text:= IBQuery2DESCRICAO.AsString; (frxReport1.FindObject('QTD3') as TfrxMemoView).Memo.Text:= IBQuery2QTDADE.AsString; (frxReport1.FindObject('VUN3') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_UNIT.AsString; (frxReport1.FindObject('VTO3') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_TOTAL.AsString; end; 4: begin (frxReport1.FindObject('COD4')as TfrxMemoView).Memo.Text:= IBQuery2ID_ORDEM.AsString; (frxReport1.FindObject('DES4')as TfrxMemoView).Memo.Text:= IBQuery2DESCRICAO.AsString; (frxReport1.FindObject('QTD4') as TfrxMemoView).Memo.Text:= IBQuery2QTDADE.AsString; (frxReport1.FindObject('VUN4') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_UNIT.AsString; (frxReport1.FindObject('VTO4') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_TOTAL.AsString; end; 5: begin (frxReport1.FindObject('COD5')as TfrxMemoView).Memo.Text:= IBQuery2ID_ORDEM.AsString; (frxReport1.FindObject('DES5')as TfrxMemoView).Memo.Text:= IBQuery2DESCRICAO.AsString; (frxReport1.FindObject('QTD5') as TfrxMemoView).Memo.Text:= IBQuery2QTDADE.AsString; (frxReport1.FindObject('VUN5') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_UNIT.AsString; (frxReport1.FindObject('VTO5') as TfrxMemoView).Memo.Text:= IBQuery2VALOR_TOTAL.AsString; end; end; IBQuery2.Next;

if IBQuery2.Eof then break; end; end; end; end; frxReport1.ShowReport;