PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 25 → WX - Exemplo de um Relatório Manual
WX - Exemplo de um Relatório Manual
Débuté par adrianoboller, 23 avr. 2016 02:06 - Aucune réponse
Membre enregistré
3 655 messages
Popularité : +175 (223 votes)
Posté le 23 avril 2016 - 02:06
Prezados,

Exemplo de um relatório manual





-- Script generated by WinDev on 22/04/2016 20:32:34
-- Tables of RelatorioManual.wda analysis
-- for Generic SQL (ANSI 92)

-- Creating the Clientes table
CREATE TABLE "Clientes" (
"Codigo" INTEGER ,
"Nome" VARCHAR(50) ,
"Endereco" VARCHAR(50) ,
"Telefone" VARCHAR(20) ,
"Cidade" VARCHAR(20) ,
"UF" VARCHAR(2) );


Crie essas Variáveis Globais:





GLOBAL
gnRelNumPagina is int
gnRelContaLinhas is int
gnRelLimiteLinhas is int
gnRelLimiteColunas is int

garrRelCabecalho is array of strings
garrRelCabecalhoComp is array of string

gsRelTitulo is string
gsRelSubTitulo is string
gnRelID is int
gsRelVersao is string
gbRelPrimeiraPagina is boolean

gsPastaReport is string = "C:\Temp"

gbSQLError is boolean = False


Procedures Globais - uso genérico:





// Summary: <specify the procedure action>
// Syntax:
//[ <Result> = ] CenterString (<spTexto> [, <npTamanho>])
//
// Parameters:
// spTexto: <specify the role of Param1>
// npTamanho (default value=0): <specify the role of npTamanho>
// Return Value:
// ANSI string: // None
//
// For instance:
// Indicate an example.
//
Procedure CenterString(spTexto,npTamanho = 0)

IF npTamanho = 0 THEN // Assume largura da folha
npTamanho = gnRelLimiteColunas
END

nEspaco_ is int = (npTamanho - Length(NoSpace(spTexto))) / 2
sTexto_ is string = QtdeX(nEspaco_) + spTexto

RESULT sTexto_




// Summary: <specify the procedure action>
// Syntax:
//ProgBarra (<psBarra>, <pnMaximo>)
//
// Parameters:
// psBarra: <specify the role of PROGBAR_Barra>
// pnMaximo: <specify the role of Param2>
// Return Value:
// None
//
// For instance:
// Indicate an example.
//
Procedure ProgBarra(psBarra,pnMaximo)

sNome_ is string = psBarra..Name

{sNome_}..Visible = True
{sNome_}..Value = 0
{sNome_}..MinValue = 0
{sNome_}..MaxValue = pnMaximo




// Summary: <specify the procedure action>
// Syntax:
//[ <Result> = ] QtdeX (<npQtde>)
//
// Parameters:
// npQtde: <specify the role of npQtde>
// Return Value:
// variant: // None
//
// For instance:
// Indicate an example.
//
Procedure QtdeX(npQtde)

RESULT RepeatString(" ",npQtde)




// Summary: <specify the procedure action>
// Syntax:
//ReportBegin (<npDestino>, <npImpressora>, <npOrientation> [, <npLinhas> [, <npColunas>]])
//
// Parameters:
// npDestino: <specify the role of COMBO_Destino>
// npImpressora: <specify the role of COMBO_Impressora>
// npOrientation: <specify the role of Param3>
// npLinhas (default value=116): <specify the role of npLinhas>
// npColunas (default value=149): <specify the role of npColunas>
// Return Value:
// None
//
// For instance:
// Indicate an example.
//
Procedure ReportBegin(npDestino,npImpressora,npOrientation,npLinhas = 116,npColunas = 149)

// Define o nome do arquivo PDF e job de impressão
sPastaPDF_ is string
sTitulo is string = Replace(gsRelTitulo,"/","_",IgnoreCase)
sTitulo = Replace(sTitulo,"\","_",IgnoreCase)
sJobName_ is string = sTitulo + "_" + DateToString(DateSys(),"AAAAMMDD") + "_" + TimeToString(Now(),"HHMMSS")

// Formatação da impressão
iReset()

// Define destino
SWITCH npDestino
CASE 1 // Visualização
iPreview(1)
CASE 2 // Impressão
sNomeImpressora is string = npImpressora[npImpressora] // Impressão

iConfigure(sNomeImpressora)
iDestination(iPrinter,sJobName_)
CASE 3 // PDF
sPastaPDF_ = gsPastaReport
iDestination(iPDF,gsPastaReport + ["\"] + sJobName_) // PDF
END

iParameter(iPaperSize, iPaperSize_A4)
iParameter(iOrientation, npOrientation)

iMargin(10, 0, 10, 10)

// Formatação das fontes
iCreateFont(1, 8, iNormal, "Courier new", iBlack, 0) // Cabeçalho
iCreateFont(2, 6, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 6
iCreateFont(3, 6, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 6
iCreateFont(4, 7, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 7
iCreateFont(5, 7, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 7
iCreateFont(60, 8, iItalic, “Courier new, iBlack, 0) // Detalhes tamanho 8 italic
iCreateFont(6, 8, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 8
iCreateFont(7, 8, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 8
iCreateFont(8, 9, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 9
iCreateFont(9, 9, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 9
iCreateFont(10, 14, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 14
iCreateFont(11, 14, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 14
iCreateFont(12, 12, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 12
iCreateFont(13, 12, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 12
iCreateFont(14, 16, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 16
iCreateFont(15, 16, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 16
iCreateFont(16, 10, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 10
iCreateFont(17, 10, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 10
iCreateFont(18, 5, iBold, “Courier new, iBlack, 0) // Titulos e totalizadores tamanho 5
iCreateFont(19, 5, iNormal, “Courier new, iBlack, 0) // Detalhes tamanho 5

// Limite de linhas de acordo com a altura da impressão
IF npOrientation = iOrientation_Portrait THEN
gnRelLimiteLinhas = npLinhas //116 /118
gnRelLimiteColunas = npColunas //149
ELSE
IF npLinhas <> 116 THEN
gnRelLimiteLinhas = npLinhas
ELSE
gnRelLimiteLinhas = 77 //79
END
IF npColunas <> 149 THEN
gnRelLimiteColunas = npColunas
ELSE
gnRelLimiteColunas = 218
END
END

// Inicializa variáveis globais
gbRelPrimeiraPagina = True // após a impressão do cabeçalho será setado para false
gbSQLError = False // havendo erro de SQL será setado para true
gsRelSubTitulo = ""
gnRelContaLinhas = 999
gnRelNumPagina = 0

ArrayDeleteAll(garrRelCabecalho)
ArrayDeleteAll(garrRelCabecalhoComp)



// Summary: <specify the procedure action>
// Syntax:
//ReportEnd ( [<bpRodape>])
//
// Parameters:
// bpRodape (default value=1): <specify the role of bpRodape>
// Return Value:
// None
//
// For instance:
// Indicate an example.
//
Procedure ReportEnd(bpRodape = True)

IF bpRodape THEN
ReportFooter()
END

iEndPrinting




// Summary: <specify the procedure action>
// Syntax:
//ReportFooter ()
//
// Parameters:
// None
// Return Value:
// None
//
// For instance:
// Indicate an example.
//
Procedure ReportFooter()

sTexto_ is string
sSite_ is string = "www.seusite.com.br"
nLarguraTexto_, nLarguraCab_ are int

IF iParameter(iOrientation) = iOrientation_Portrait THEN
nLarguraCab_ = 108
ELSE
nLarguraCab_ = 160
END

iBorder(0, iPageHeight()-10, iPageWidth(), iPageHeight()-6, 1, 20, LightGray, iContinuous, iSolid)

sTexto_ = "Identificação do seu aplicativo"
nLarguraTexto_ = nLarguraCab_ - Length(sTexto_) - Length(sSite_)

iYPos(iPageHeight()-9)
iPrint(iFont(1) + QtdeX(2) + sTexto_ + QtdeX(nLarguraTexto_) + sSite_)




// Summary: <specify the procedure action>
// Syntax:
//ReportHeader (<npFont>)
//
// Parameters:
// npFont: <specify the role of npFontCabecalho_>
// Return Value:
// None
//
// For instance:
// Indicate an example.
//
Procedure ReportHeader(npFont)

sTexto_ is string
sEmpresa_ is string = "SUA EMPRESA LTDA"
nLarguraTexto_, nLarguraCab_ are int

IF iParameter(iOrientation) = iOrientation_Portrait THEN
nLarguraCab_ = 108
ELSE
nLarguraCab_ = 160
END

gnRelNumPagina ++
gnRelContaLinhas = 0

IF gsRelTitulo > "" THEN
IF gbRelPrimeiraPagina = False THEN
ReportFooter()

iSkipPage()
END
gbRelPrimeiraPagina = False

iBorder(0, 0, iPageWidth(), 11, 1, 20, LightGray, iContinuous, iSolid)

sTexto_ = "Folha: " + NumToString(gnRelNumPagina,"03d")
nLarguraTexto_ = nLarguraCab_ - Length(sTexto_) - Length(sEmpresa_)
iPrint(iFont(1) + iYPos(1) + QtdeX(2) + sEmpresa_ + QtdeX(nLarguraTexto_) + sTexto_)

sTexto_ = DateToString(DateSys(),"DD/MM/YYYY") + " " + TimeToString(Now(),"HH:MM")
nLarguraTexto_ = nLarguraCab_ - Length(gsRelTitulo) - Length(sTexto_)
iPrint(iFont(1) + QtdeX(2) + gsRelTitulo + QtdeX(nLarguraTexto_) + sTexto_)

sTexto_ = DateToString(Today(),"Mmmm/YYYY")
nLarguraTexto_ = nLarguraCab_ - Length(gsRelSubTitulo) - Length(sTexto_)
iPrint(iFont(1) + QtdeX(2) + gsRelSubTitulo + QtdeX(nLarguraTexto_) + sTexto_)
iSkipLine()

// Imprime complemento do titulo
IF ArrayCount(garrRelCabecalhoComp) > 0 THEN
// Apura a linha maior do array
nLarguraLin is int
FOR EACH iLinha OF garrRelCabecalhoComp
nLarguraLin = Max(nLarguraLin,Length(iLinha))
END
nDistanciaMargem is int = ((gnRelLimiteColunas - nLarguraLin) / 2)

// Imprime array
FOR EACH iLinha OF garrRelCabecalhoComp
iPrint(iFont(npFont) + QtdeX(nDistanciaMargem) + iLinha)
gnRelContaLinhas ++
END
iSkipLine()
gnRelContaLinhas ++

// Limpa array para que seja impresso apenas na primeira página
ArrayDeleteAll(garrRelCabecalhoComp)
END

// Imprime cabeçalho
IF ArrayCount(garrRelCabecalho) > 0 THEN
FOR EACH iLinha OF garrRelCabecalho
IF iLinha > "" THEN
iPrint(iFont(npFont) + QtdeX(1) + iLinha)
gnRelContaLinhas ++
END
END
END
iSkipLine()

// iPrint(iFont(npFont) + sRegua)
gnRelContaLinhas += 4
END




// Summary: <specify the procedure action>
// Syntax:
//ReportPrint (<npFont>, <spLinhaTexto> [, <npLinhaEmBrancoDepois> [, <npLinhaEmBrancoAntes> [, <bpBorda>]]])
//
// Parameters:
// npFont: <specify the role of npFont>
// spLinhaTexto: <specify the role of spLinhaTexto>
// npLinhaEmBrancoDepois (default value=0): <specify the role of npLinhaEmBrancoDepois>
// npLinhaEmBrancoAntes (default value=0): <specify the role of npLinhaEmBrancoAntes>
// bpBorda (default value=0): <specify the role of bpBorda>
// Return Value:
// None
//
// For instance:
// Indicate an example.
//
Procedure ReportPrint(npFont,spLinhaTexto,npLinhaEmBrancoDepois = 0, npLinhaEmBrancoAntes = 0, bpBorda = False)

npFontCabecalho_ is int
// Define tamanho da fonte para o "sub" cabeçalho
IF IsOdd(npFont) THEN
npFontCabecalho_ = npFont - 1
ELSE
npFontCabecalho_ = npFont
END

// Imprime linhas em branco ANTES da impressão do texto
IF npLinhaEmBrancoAntes > 0 THEN
FOR i = 1 _TO_ npLinhaEmBrancoAntes
iSkipLine()
gnRelContaLinhas ++

IF gnRelContaLinhas >= gnRelLimiteLinhas THEN
ReportHeader(npFontCabecalho_)
BREAK
END
END
END

// Imprime o cabeçalho se foi atingido o limite máximo de linhas
IF gnRelContaLinhas >= gnRelLimiteLinhas THEN
ReportHeader(npFontCabecalho_)
END

// Imprime borda
IF bpBorda THEN
iBorder(iXPos(),iYPos()-1,iPageWidth(),iYPos()+3,1,20,LightGray,iContinuous,iSolid)
END

// Imprime texto
iPrint(iFont(npFont) + spLinhaTexto)
gnRelContaLinhas ++

// Imprime linhas em branco APOS a impressão do texto
IF gnRelContaLinhas < gnRelLimiteLinhas THEN
IF npLinhaEmBrancoDepois > 0 THEN
FOR i = 1 _TO_ npLinhaEmBrancoDepois
iSkipLine()
gnRelContaLinhas ++
IF gnRelContaLinhas >= gnRelLimiteLinhas THEN
ReportHeader(npFontCabecalho_)
BREAK
END
END
END
END









CODE

Botão Cadastro de Clientes, Carga inicial:

// Cadastrar clientes
FOR ALL Clientes
HDelete(Clientes)
END

HReset(Clientes)
Clientes.Codigo = 1
Clientes.Nome = "JOAO"
Clientes.Endereco = "RUA X, numero 10"
Clientes.Telefone = "(51) 1111-2222"
Clientes.Cidade = "PORTO ALEGRE"
Clientes.UF = "RS"
HAdd(Clientes)

HReset(Clientes)
Clientes.Codigo = 2
Clientes.Nome = "PEDRO"
Clientes.Endereco = "RUA Y, numero 10"
Clientes.Telefone = "(51) 333-2222"
Clientes.Cidade = "PORTO ALEGRE"
Clientes.UF = "RS"
HAdd(Clientes)

HReset(Clientes)
Clientes.Codigo = 3
Clientes.Nome = "CARLOS"
Clientes.Endereco = "RUA Z, numero 12"
Clientes.Telefone = "(51) 1111-4444"
Clientes.Cidade = "CAXIAS DO SUL"
Clientes.UF = "RS"
HAdd(Clientes)

HReset(Clientes)
Clientes.Codigo = 4
Clientes.Nome = "ANTONIO"
Clientes.Endereco = "RUA W, numero 14"
Clientes.Telefone = "(51) 5555-2222"
Clientes.Cidade = "CAXIAS DO SUL"
Clientes.UF = "RS"
HAdd(Clientes)

HReset(Clientes)
Clientes.Codigo = 5
Clientes.Nome = "LUIS"
Clientes.Endereco = "RUA W, numero 14"
Clientes.Telefone = "(51) 1111-4444"
Clientes.Cidade = "PORTO ALEGRE"
Clientes.UF = "RS"
HAdd(Clientes)



CODE

Botão Imprimir Clientes

Open(WIN_RPT_0001_Cadastro_clientes)




Seleção: Visualizar ou Imprimir





Open da JANELA (GLOBAL)




Procedure WIN_RPT_0001_Cadastro_clientes()

gsJanela is string = MySelf..Name

gsRelTitulo = MyWindow..NoteTitle // "" para formulários sem cabeçalho

gsProcesso is string = ExtractString(gsJanela,2,"_") + ExtractString(gsJanela,3,"_")

gbImprimiu is boolean




COMBO_DESTINO
OPÇÕES:

Visualização
Impressão
PDF

//SELECTION ROW
// Habilita/Desabilita impressora
IF MySelf = 2 THEN
COMBO_Impressora..Grayed = False
ELSE
COMBO_Impressora..Grayed = True
END



COMBO_IMPRESSORAS





// Carrega lista de impressoras
ListAdd(MySelf, iListPrinter())

// Seleciona a impressora padrão
ListSelectPlus(MySelf, ListSeek(MySelf, iInfoPrinter(False, iPrinterName)))


BOTAO IMPRIMIR

CODE:

IF COMBO_Destino = 1 THEN
LocalImpressao()
ELSE
ThreadExecute("Impressao",threadNormal,LocalImpressao)
END




BOTAO CANCELAR

CODE:

IF BTN_ok..State = Grayed THEN
ThreadStop("Impressao",Infinite)
Info("Processo interrompido pelo usuário.")

PROGBAR_Barra..Value = 0
BTN_ok..Grayed = False
HourGlass(False)
RETURN
END

Close()



LOCAL PROCEDURE

CODE

// Summary: <specify the procedure action>
// Syntax:
//LocalEndReport (<npDestino>)
//
// Parameters:
// npDestino: <specify the role of npDestino>
// Return Value:
// None
//
// For instance:
// Indicate an example.
//
Procedure LocalEndReport(npDestino)

IF NOT gbSQLError THEN
IF gbRelPrimeiraPagina THEN
Info("Não há registros para imprimir.")
ELSE
ReportEnd()

IF npDestino = 3 THEN // Abre PDF
ShellExecute(iLastFile())
END
END
ELSE
iCloseReport()
Info("Documente a mensagem de erro para a JB Sistemas.",1)
END


LOCAL PROCEDURE

CODE
// Summary: <specify the procedure action>
// Syntax:
//LocalImpressao ()
//
// Parameters:
// None
// Return Value:
// None
//
// For instance:
// Indicate an example.
//
Procedure LocalImpressao()

// Confere se usuário deseja reimprimir o mesmo relatório novamente
IF gbImprimiu THEN
IF NOT YesNo("Você deseja reimprimir este relatório?") THEN
RETURN
END
END

gbImprimiu = True
BTN_ok..Grayed = True
HourGlass()

// Parâmetros do relatório
ReportBegin(COMBO_Destino,COMBO_Impressora,iOrientation_Landscape)
ArrayAdd(garrRelCabecalho," Código Nome Endereço Cidade UF Fone")

sCidadeAnt is string
dsQry is Data Source

sSql is string = [
SELECT
CLIENTES.CODIGO,
CLIENTES.NOME,
CLIENTES.ENDERECO,
CLIENTES.CIDADE,
CLIENTES.UF,
CLIENTES.TELEFONE
FROM CLIENTES
ORDER BY CLIENTES.CIDADE,CLIENTES.NOME
]

// Impressão
IF HExecuteSQLQuery(dsQry, hQueryDefault, sSql) THEN
ProgBarra(PROGBAR_Barra,HNbRec(dsQry))

FOR ALL dsQry
// Quebra por cidade
IF dsQry.Cidade > sCidadeAnt THEN
ReportPrint(2,CenterString("Cidade " + dsQry.Cidade),1,1,True)
END

ReportPrint(3,...
QtdeX(1) + NumToString(dsQry.Codigo,"7d") + ...
QtdeX(2) + Complete(dsQry.Nome,50) + ...
QtdeX(2) + Complete(dsQry.Endereco,50) + ...
QtdeX(2) + Complete(dsQry.Cidade,30) + ...
QtdeX(2) + dsQry.UF + ...
QtdeX(2) + dsQry.Telefone)

sCidadeAnt = dsQry.Cidade

PROGBAR_Barra..Value ++
END

PROGBAR_Barra..Visible = False
ELSE
Info(HErrorInfo() + CR + sSql)
END

LocalEndReport(COMBO_Destino)
HFreeQuery(dsQry)

BTN_ok..Grayed = False
HourGlass(False)


BONS ESTUDOS

NOVOS EXEMPLOS ME ENCAMINHEM!

:merci:

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.blogspot.com.br/