*!* PROCEDURI_RAPOARTE.PRG


*!* LISTARE RAPORT UTILIZATOR
*!* PARAMETRI : tcAlias - alias-ul cursorului; tcTipExport - FRX/XLS; tcRaport - numele raportului
*!* Se listeaza raportul USR_<tcRaport> din directorul \\SERVER\ROA\USERREPORTS\<APPLICATIE>\<FIRMA>\ daca exista
*!* Daca nu exista raporturl USR_<tcRaport> se listeaza raportul <tcRaport> default
PROCEDURE LISTAREUSERREPORT
LPARAMETERS tcAlias, tcTipExport, tcRaport, toListener, tnPreview, tcImprimanta
**	Valori pentru tnPreview
**	1	-	cu vizualizare
**	2	-	listare directa

LOCAL lcSelect, lcRaportPath, lcTipExport, lnPreview, lcImprimanta
STORE [] TO lcImprimanta

IF TYPE('tcTipExport') = 'C'
	lcTipExport = UPPER(ALLTRIM(tcTipExport))
ELSE
	IF EMPTY(tcRaport)
		lcTipExport = 'XLS'
	ELSE
		lcTipExport = 'FRX'
	ENDIF
ENDIF
IF EMPTY(tcAlias)
	RETURN
ENDIF
IF !USED(tcAlias)
	RETURN
ENDIF
IF EMPTY(tnPreview)
	lnPreview = 1
ELSE
	lnPreview = tnPreview
ENDIF

DO CASE
CASE lcTipExport = 'FRX'
	IF !EMPTY(tcImprimanta)
*!*	verificare ca tcImprimanta este instalata pe calculatorul respectiv
		IF APRINTERS(laPrinters) > 0 AND ASCAN(laPrinters,tcImprimanta,1,ALEN(laPrinters,1),1,15) > 0
			lcImprimanta = tcImprimanta
		ENDIF
	ENDIF

	RELEASE laPrinters

	lcRaportPath = getUserRepPath() + [USR_] + JUSTSTEM(tcRaport) + [.FRX]

	IF !FILE(lcRaportPath)
		lcRaportPath = tcRaport
	ENDIF

	lcSelect = SELECT()
	IF !EMPTY(tcAlias) AND USED(tcAlias)
		SELECT (tcAlias)
	ENDIF

	lnRaspuns = 6
	DO WHILE lnRaspuns = 6
		TRY
			IF !EMPTY(toListener)
				REPORT FORM (lcRaportPath) OBJECT toListener
			ELSE
				IF lnPreview = 1
					KEYBOARD '{CTRL+F10}'
					REPORT FORM (lcRaportPath) TO PRINTER PROMPT PREVIEW
				ELSE
					IF !EMPTY(lcImprimanta)
						lcImprimantaTemp = SYS(6)
						SET PRINTER TO NAME (lcImprimanta)
						REPORT FORM (lcRaportPath) TO PRINTER
						IF !EMPTY(NVL(lcImprimantaTemp,[]))
							SET PRINTER TO (lcImprimantaTemp)
						ELSE
							SET PRINTER TO
						ENDIF
					ELSE
						REPORT FORM (lcRaportPath) TO PRINTER PROMPT
					ENDIF
				ENDIF
			ENDIF
			lnRaspuns = 7
		CATCH TO oEroare
			IF oEroare.MESSAGE='Error loading driver error.'
				lnRaspuns = aMESSAGEBOX("Eroare la driverul imprimantei.Doriti sa reincercati listarea?",4+32+256,"Confirmare relistare")
			ELSE
				aMESSAGEBOX(oEroare.MESSAGE,16,"Eroare")
				lnRaspuns = 7
			ENDIF
		ENDTRY
	ENDDO

	SELECT (lcSelect)

CASE lcTipExport = 'XLS'
	export_xls(tcAlias)
ENDCASE


ENDPROC && LISTAREUSERREPORT

********************* INCEPUT Modifica_raport_utilizator **********************
* PROCEDURE Modifica_raport_utilizator
* Date : 26.07.2006, 17:44:33
* author : marius.mutu
PROCEDURE Modifica_raport_utilizator

lcUserRepPath = getUserRepPath()
CD (lcUserRepPath)
lcFile = GETFILE("frx","Alegeti un raport","Alege")
IF FILE(lcFile) AND UPPER(JUSTEXT(lcFile)) = "FRX"
	MODIFY REPORT (lcFile)
ENDIF

ENDPROC && Modifica_raport_utilizator
********************* SFARSIT Modifica_raport_utilizator **********************

*!* INTOARCE DIRECTORUL CU RAPOARTE UTILIZATOR PENTRU APLICATIA, SCHEMA CURENTA
FUNCTION getUserRepPath
LOCAL lcAppPath, lcAppName, liAt, lcDirgen, lcUserRepPath
lcAppPath=ADDBS(JUSTPATH(SYS(16,0)))
lcAppName=ALLT(UPPE(JUSTSTEM(SYS(16,0))))
liAt=RAT("\",lcAppPath,2)
lcDirgen=ADDBS(LEFT(lcAppPath,liAt-1))
lcUserRepPath = lcDirgen + 'USERREPORTS\'
IF !DIRECTORY(lcUserRepPath)
	MD (lcUserRepPath)
ENDIF
lcUserRepPath = lcUserRepPath + lcAppName + '\'
IF !DIRECTORY(lcUserRepPath)
	MD (lcUserRepPath)
ENDIF
lcUserRepPath = lcUserRepPath + gcS + '\'
IF !DIRECTORY(lcUserRepPath)
	MD (lcUserRepPath)
ENDIF

RETURN lcUserRepPath

ENDFUNC

****************************************************************************
*!* extrage frx din executabil pe disc in directorul USERREPORTS
PROCEDURE UserReport2File
LPARAMETERS tcRaport

LOCAL lcRaport, lcFile
IF EMPTY(tcRaport)
	lcRaport= INPUTBOX("Raport","Scrieti numele raportului","raport.frx")
ELSE
	lcRaport = tcRaport
ENDIF

IF EMPTY(lcRaport)
	RETURN
ENDIF

lcRaport = JUSTSTEM(lcRaport) + '.frx'
lcFile = getUserRepPath() + "USR_" + lcRaport
IF FILE(lcFile)
	RETURN
ENDIF

*!*		TRY
*!*		USE (lcRaport) IN 0 again SHARED ALIAS crsRaportTemp
*!*		ENDTRY

IF !FILE(lcRaport)
	aMESSAGEBOX('Nu exista raportul ' + lcRaport)
ELSE
	USE (lcRaport) IN 0 AGAIN SHARED ALIAS crsRaportTemp
	SELECT crsRaportTemp
	COPY TO (lcFile)
	USE IN crsRaportTemp
ENDIF

ENDPROC && UserReport2File