Procedure citeste_atasament_vanzari
Lparameters tnIdAtVanz,tcTip,tnNrAct
If !Empty(tnIdAtVanz)
	Private poDocument
	Store "" To poDocument
	If Used('crsat')
		Use In crsat
	Endif

	Local loTherm
	loTherm = Newobject("_thermometer","_therm","","Citire document din baza de date...")
	loTherm.AlwaysOnTop = .T.
	loTherm.Show()

	lcSelect = [select document from ] + gcS + [.atasamente_vanzari where ]
	lcFiltru = [id_at_vanz=]+Alltrim(Str(tnIdAtVanz))
	lcSchema = [document W]
	lcOrder = []
	llAfisare = .F.
	GENCURSOR('poDocument','crsat',lcSelect,lcFiltru,lcSchema,lcOrder,llAfisare)
	loTherm.Update(40, "Citire document din baza de date...")
	poDocument.ca_baza1.afisare()
	loTherm.Update(55, "Citire document din baza de date...")

	lcFisier = gcTempPath + Alltrim(Str(tnNrAct,14,0)) + [_] + Alltrim(tcTip) + [.pdf]
	loTherm.Update(65, "Testare creare fisier...")
	If File(lcFisier)
		Try
			Delete File (lcFisier)
		Catch To oException
			lcFisier = Strtran(lcFisier,[.pdf],Ttoc(Datetime(),1)+[.pdf])
		Endtry
	Endif
	Select crsat
	loTherm.Update(85, "Creare fisier...")
	Strtofile(Document,lcFisier)
	loTherm.Update(95, "Deschidere fisier...")
	open_default_app(lcFisier)
	loTherm.Complete()
	Use In crsat
	Release poDocument,loTherm
Endif
Endproc	&&	citeste_atasament_vanzari
***-----------------------------------------------------------------------------------------------------------------------------
Procedure arata_meniu_at_vanz
Lparameters tnCod,tcSerie,tnNrFactura,tcCampValoare
&&	daca este completat si tcCampValoare, atunci apare in meniu si optiunea "Copiaza"
&&	tcCampValoare trebuie sa fie de forma "cursor.coloana"
Local lnCod,lnNrAct,lcSerie
lnCod =  tnCod
lnNrAct = tnNrFactura
lcSerie = Alltrim(Nvl(tcSerie,[]))
If Used('crsmeniu')
	Use In crsmeniu
Endif
lcSql = [select a.id_at_vanz,a.tip,a.tip_doc from ] + gcS + [.vatasamente_vanzari a where a.cod = ] + Alltrim(Str(lnCod)) + [ order by a.tip]
lnSucces = goExecutor.oExecute(lcSql,[crsmeniu])
If lnSucces < 0
	amessagebox(goExecutor.cEroare,16,"Eroare")
Else
	Do Case
	Case !Empty(tcCampValoare)
		lcMeniu = [;\<Copiaza]
		If Reccount('crsmeniu') > 0
			lcMeniu = lcMeniu + [;\-]
			Select crsmeniu
			Scan
				lcMeniu = lcMeniu + [;] + Alltrim(tip_doc)
			Endscan
		Endif
		x = xmenu(Substr(lcMeniu,2))
		Do Case
		Case x = 1
			_Cliptext = Transform(Evaluate(tcCampValoare))
		Case Between(x,3,2+Reccount('crsmeniu'))
			Select crsmeniu
			Go (x - 2)
			citeste_atasament_vanzari(crsmeniu.id_at_vanz,crsmeniu.tip_doc,lnNrAct)
		Endcase
	Case Reccount('crsmeniu') = 1
		citeste_atasament_vanzari(crsmeniu.id_at_vanz,crsmeniu.tip_doc,lnNrAct)
	Case Reccount('crsmeniu')>0
		lcMeniu = []
		Select crsmeniu
		Scan
			lcMeniu = lcMeniu + [;] + Alltrim(tip_doc)
		Endscan
		x = xmenu(Substr(lcMeniu,2))
		Select crsmeniu
		Go x
		citeste_atasament_vanzari(crsmeniu.id_at_vanz,crsmeniu.tip_doc,lnNrAct)
	Otherwise
		amessagebox("Nu exista documente salvate in baza de date pentru factura "+lcSerie+" "+Alltrim(Str(lnNrAct,14,0)) + " !",48,"Atentie")
	Endcase
	Use In crsmeniu
Endif
Endproc	&&	arata_meniu_at_vanz
***-----------------------------------------------------------------------------------------------------------------------------
Procedure make_crsAtasamente
Parameters tlToate

Private poLink
Store '' To poLink

Local lcSchema, lcSelect, lcOrder, lcFiltru, lcFiltruOriginal, llAfiseaza, lcgroup, lcFiltruOriginal
lcSchema = [id_referinta N(5), id_atas N(5), descriere c(50), nume_fisier c(200), fisier w, dataora t, utilizator  c(100) ]

lcSelect = [select ar.id_referinta, ar.id_atas, ar.descriere, ar.nume_fisier, '' as fisier, dataora, utilizator ]+;
	[ from VATAS_REFERINTE ar ]

lcOrder = [ar.nume_fisier, ar.descriere]
lcgroup = []
lcFiltru = []

*lcFiltruOriginal = [l.sters=0 and l.nume_fisier is not null and l.id_reg =]+Alltrim(Str(goRegistratura.id_reg))
Do Case
Case Upper(Alltrim(gcNumeProgram)) = "ROAREGISTRATURA"
	lcFiltruOriginal = [ ar.nume_fisier is not null and ar.id_program = 70 and ar.id_entitate=]+Alltrim(Str(goRegistratura.id_reg))
Case Upper(Alltrim(gcNumeProgram)) = "ROACONTRACTE"
	lcFiltruOriginal = [ ar.nume_fisier is not null and ar.id_program = 21 and ar.id_entitate=]+Alltrim(Str(goContract.id_ctr))
Case Upper(Alltrim(gcNumeProgram)) = "ROALUCRARI"
	lcFiltruOriginal = [ ar.nume_fisier is not null and ar.id_program = 13 and ar.id_entitate=]+Alltrim(Str(crsProiecte.id_proiect))
Endcase

llModParam = .T.
llAfiseaza = .F.

GENCURSOR('poLink','crsAtasamenteI', lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza,  lcgroup, llModParam, lcFiltruOriginal)
poLink.ca_baza1.afisare()

Select * From crsAtasamenteI With (Buffering = .T.);
	into Cursor crsAtasamente Readwrite

If Used('crsAtasamenteI')
	Use In crsAtasamenteI
Endif

Endproc && make_crsAtasamente
***-----------------------------------------------------------------------------------------------------------------------------
PROCEDURE inchide_crsAtasamente

IF USED('crsAtasamente')
	USE IN crsAtasamente
ENDIF 

ENDPROC && inchide_crsAtasamente 
***-----------------------------------------------------------------------------------------------------------------------------
Procedure upload
Parameters tcTabel

Private pnId_entitate, pcLink, pcDescriere, pcFis_name, pcFisier, pnId_atas &&,pntip_entitate	modificare 30.05.2011
Store 0 To pnTip_entitate, pnId_atas	&&,pnTip_entitate	modificare 30.05.2011
Store "" To pcDescriere, pcFis_name, pcFisier, pcLink
* pcLink - private - folosit in frm_atas_nou

Local llReturn,lcSql,lnSucces
llReturn = .T.

Local lcTabelLinkuri
Store '' To lcTabelLinkuri

If !Empty(tcTabel)
	lcTabelLinkuri = Alltrim(tcTabel)  && Thisform.grid_linkuri.RecordSource
	Select (lcTabelLinkuri)
	Scatter Name poLink Blank Memo
Else
	Create Cursor crsAtasTemp (id_atas N(5), descriere c(50), nume_fisier c(200), fisier w)
	Select crsAtasTemp
	Scatter Name poLink Blank Memo
	Use In crsAtasTemp
Endif

If Upper(Alltrim(gcNumeProgram)) = "ROAREGISTRATURA"
	AddProperty(poLink,'id_proiect',goRegistratura.id_proiect)
	AddProperty(poLink,'proiect',Alltrim(goRegistratura.proiect))
Else
	AddProperty(poLink,'id_proiect',0)
	AddProperty(poLink,'proiect','')
Endif
AddProperty(poLink,'id_ctr',0)
AddProperty(poLink,'contract','')

lodn = Createobject("frm_atas_nou")
lodn.Show(1)
If gnButon = 2
	Return
Endif

If Upper(Alltrim(gcNumeProgram)) = "ROAREGISTRATURA"
	pnId_entitate = goRegistratura.id_reg
*!*		pnTip_entitate = 1		modificare	30.05.2011
Endif
If Upper(Alltrim(gcNumeProgram)) = "ROACONTRACTE"
	pnId_entitate = goContract.id_ctr
*!*		pnTip_entitate = 2		modificare	30.05.2011
Endif
If Upper(Alltrim(gcNumeProgram)) = "ROALUCRARI"
	pnId_entitate = Alltrim(Str(crsProiecte.id_proiect))
*!*		pnTip_entitate = 3		modificare	30.05.2011
Endif
pcDescriere = Upper(Alltrim(poLink.descriere))
pcFis_name = Upper(Alltrim(poLink.nume_fisier))
If Empty(pcLink)
	Return
Endif
pcFisier = Filetostr(pcLink)


lnSucces = SQLSetprop(gnhandle,"Transactions",2)
If lnSucces < 0
	amessagebox("Programul nu a reusit sa treaca pe tranzactie manuala! Reintrati in program si incercati din nou!",48,"Atentie")
Else
	lcSql = [insert into atas_atasamente(fisier, nume_fisier, descriere, id_util) ]+;
		[values (?pcFisier, ?pcFis_name, ?pcDescriere, ?gnIdUtil) ] + ;
		[ returning id_atas into ?@pnId_atas]
	lnSucces = goExecutor.oExecute(lcSql)
	If lnSucces < 0
		aMessagebox(goExecutor.cEroare,0+16,'Eroare')
	Else
		If Upper(Alltrim(gcNumeProgram)) = "ROAREGISTRATURA"
			lcSql = [update registratura set id_proiect = ?polink.id_proiect where id_reg = ?pnId_entitate]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				aMessagebox(goExecutor.cEroare,0+16,'Eroare')
			Else
				lcSql = [insert into atas_referinte(id_atas, id_program, id_entitate, id_util) ]+;
					[values (?pnId_atas, ?gnIdProgram, ?pnId_entitate, ?gnIdUtil) ] && registratura	modificare	30.05.2011 : am inlocuit pnTip_Entitate cu gnIdProgram
				lnSucces = goExecutor.oExecute(lcSql)
				If lnSucces < 0
					aMessagebox(goExecutor.cEroare,0+16,'Eroare')
				Else
					If !Empty(Nvl(poLink.id_ctr,0)) And poLink.id_ctr<> -1
						lcSql = [insert into atas_referinte(id_atas, id_program, id_entitate, id_util) ]+;
							[values (?pnId_atas, ?gnIdProgram, ?polink.id_ctr, ?gnIdUtil) ] && contracte modificare	30.05.2011 : am inlocuit pnTip_Entitate cu gnIdProgram
						lnSucces = goExecutor.oExecute(lcSql)
						If lnSucces < 0
							aMessagebox(goExecutor.cEroare,0+16,'Eroare')
						Else
							If !Empty(Nvl(poLink.id_proiect,0)) And poLink.id_proiect <> -1
								lcSql = [insert into atas_referinte(id_atas, id_program, id_entitate, id_util) ]+;
									[values (?pnId_atas, ?gnIdProgram, ?polink.id_proiect, ?gnIdUtil) ] && lucrari modificare	30.05.2011 : am inlocuit pnTip_Entitate cu gnIdProgram
								lnSucces = goExecutor.oExecute(lcSql)
								If lnSucces < 0
									aMessagebox(goExecutor.cEroare,0+16,'Eroare')
								Endif
							Endif
						Endif
					Endif
				Endif
			Endif
		Else && RoaContracte, RoaLucrari
			lcSql = [insert into atas_referinte(id_atas, id_program, id_entitate, id_util) ]+;
				[values (?pnId_atas, ?gnIdProgram, ?pnId_entitate, ?gnIdUtil) ]  &&	modificare	30.05.2011 : am inlocuit pnTip_Entitate cu gnIdProgram
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				aMessagebox(goExecutor.cEroare,0+16,'Eroare')
			Endif
		Endif
	Endif
Endif

If lnSucces < 0
	lcSql = "ROLLBACK"
Else
	lcSql = "COMMIT"
Endif
lnSucces2 = goExecutor.oExecute(lcSql)

If lnSucces2 < 0
	amessagebox(lcSql + Chr(13) + goExecutor.cEroare,0+16,"Eroare")
Endif

lnSucces2 = SQLSetprop(gnhandle,"Transactions",1)
If lnSucces2 < 0
	amessagebox('Programul nu a reusit sa treaca pe tranzactie automata. Iesiti din program si intrati din nou!',0+48,'Atentie!')
Else
	If lcSql = "COMMIT"
		If !Empty(lcTabelLinkuri)
			Select (lcTabelLinkuri)
			Append Blank
			Gather Name poLink Memo
			Replace fisier With pcFisier, id_atas With pnId_atas, nume_fisier With pcFis_name, descriere With pcDescriere, dataora With Datetime(), utilizator With gcUserNameApp
		Endif

		Do Case
		Case Upper(Alltrim(gcNumeProgram)) = "ROAREGISTRATURA"
			goRegistratura.proiect = poLink.proiect
			goRegistratura.id_proiect = poLink.id_proiect

			Replace are_link With 1 In cRegistratura
			Replace id_proiect With poLink.id_proiect In cRegistratura
			Replace proiect With poLink.proiect In cRegistratura
		Case Upper(Alltrim(gcNumeProgram)) = "ROACONTRACTE"
			Replace are_link With 1 In cContracte
		Endcase

	Endif
Endif


Endproc && upload
***-----------------------------------------------------------------------------------------------------------------------------
Procedure import_atasamente
Parameters tnTipEntitate
&& completare campuri nume_fis si link_bd din link - la versiunea 2.0.7 - se salveaza atasamentele in bd
&& ver. 2.0.12 - preluare din ctr_linkuri (reg_linkuri) in atas_atasamente, atas_referinte
&& tnTipEntitate/gnIdProgram = 70-RoaRegistratura, 21-RoaContracte, 13-RoaLucrari

Private poLink, pcFisier, pcNume_fis, pcDescriere, pnId_entitate, pnId_atas, pnId_link, pnTipEntitate
Store '' To poLink
Store 0 To pnId_entitate, pnId_atas, pnId_link
*!*	modificare 31.05.2011
*!*	If Empty(tnTipEntitate)
*!*		Return
*!*	Endif
*!*	pnTipEntitate= tnTipEntitate
pnTipEntitate = IIF(EMPTY(tnTipEntitate),gnIdProgram,tnTipEntitate)
*!*	modificare 31.05.2011	^

Local lcSchema, lcSelect, lcOrder, lcFiltru, lcFiltruOriginal, llAfiseaza, lcgroup, lcFiltruOriginal
lcSchema = [id_link N(5), id_entitate n(5), descriere c(50), link c(200) ]
Do Case
Case Upper(Alltrim(gcNumeProgram)) = "ROACONTRACTE"
	lcSelect = [select id_link, id_ctr as id_entitate, DENUMIRE AS descriere, link ]+;
		[from ctr_linkuri]
Case Upper(Alltrim(gcNumeProgram)) = "ROAREGISTRATURA"
	lcSelect = [select id_link, id_reg as id_entitate, DENUMIRE AS descriere, link ]+;
		[from reg_linkuri]
Case Upper(Alltrim(gcNumeProgram)) = "ROALUCRARI"
	lcSelect = [select id_link, id_proiect as id_entitate, DENUMIRE AS descriere, link ]+;
		[from con_linkuri]
Endcase

lcOrder = []
lcgroup = []
lcFiltru = [STERS=0]
lcFiltruOriginal = [link is not null and id_link not in (select id_link from atas_atasamente where id_tip_ent_prel = ?pnTipEntitate)]
llModParam = .T.
llAfiseaza = .F.

GENCURSOR('poLink','cCtrLink2', lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza,  lcgroup, llModParam, lcFiltruOriginal)
poLink.ca_baza1.afisare()

Private pnId_link, pcNume_fis, pcLink_bd
Local lcMesaj
lcMesaj = ''

Select cCtrLink2
Calculate Cnt() To lnFisiere
lnIndex = 0
Scan
	pnId_link = id_link
	pnId_entitate = id_entitate
	lcLink = Alltrim(Link)
	pcNume_fis = Justfname(lcLink)
	pcDescriere = Upper(Alltrim(descriere))
	lnIndex = lnIndex + 1
	Wait Window Alltrim(Str(lnIndex)) + '/' + Alltrim(Str(lnFisiere)) + " " + pcNume_fis Nowait
	If File(lcLink)
		pcFisier = Filetostr(lcLink)
*lcSql = [update ctr_linkuri set nume_fis=?pcNume_fis, link_bd = ?pcLink_bd where id_link=?pnId_link]
		lcSql = [insert into atas_atasamente (fisier, nume_fisier, id_util, descriere, id_link, id_tip_ent_prel) ]+;
			[values (?pcFisier, ?pcNume_fis, ?gnIdUtil, ?pcDescriere, ?pnId_link, ?pnTipEntitate) ] +;
			[returning id_atas into ?@pnId_atas]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			If amessagebox(goExecutor.cEroare + Chr(13) + Chr(10) + 'Doriti sa continuati?',4+48,'Eroare') # 6
				Exit
			Endif
		Else
			lcSql = [insert into atas_referinte (id_atas, id_program, id_entitate, id_util) ]+;
				[values (?pnId_atas, ?pnTipEntitate, ?pnId_entitate, ?gnIdUtil)]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				If amessagebox(goExecutor.cEroare + Chr(13) + Chr(10) + 'Doriti sa continuati?',4+48,'Eroare') # 6
					Exit
				Endif
			Endif
		Endif
	Else
		lcMes = 'Nu exista fisierul '+lcLink+Chr(13)
		lcMesaj = lcMesaj + lcMes

	Endif

	Select cCtrLink2
Endscan

If !Empty(lcMesaj)
	amessagebox(lcMesaj)
Endif

If Used('cCtrLink2')
	Use In cCtrLink2
Endif

Endproc && import_atasamente
***-----------------------------------------------------------------------------------------------------------------------------
Procedure modifica_atasament
Parameters tcTabel

Private pcDescriere, pnId_atas
Store 0 To pnId_atas
Store "" To pcDescriere
* pcLink - private - folosit in frm_atas_nou

Local llReturn,lcSql,lnSucces
llReturn = .T.

Local lcTabelLinkuri
If !Empty(tcTabel)
	lcTabelLinkuri = Alltrim(tcTabel)  && Thisform.grid_linkuri.RecordSource
	Select (lcTabelLinkuri)
	Scatter Name poLink Memo
Else
	Return
Endif

If Upper(Alltrim(gcNumeProgram)) = "ROAREGISTRATURA"
	AddProperty(poLink,'id_proiect',goRegistratura.id_proiect)
	AddProperty(poLink,'proiect',Alltrim(goRegistratura.proiect))
Else
	AddProperty(poLink,'id_proiect',0)
	AddProperty(poLink,'proiect','')
Endif
AddProperty(poLink,'id_ctr',0)
AddProperty(poLink,'contract','')

lodn = Createobject("frm_atas_nou")
lodn.Command3.Enabled=.F.
lodn.Show(1)
If gnButon = 2
	Return
Endif

pnId_atas = poLink.id_atas
pcDescriere = Upper(Alltrim(poLink.descriere))

lcSql = [update atas_atasamente set descriere = ?pcDescriere ]+;
	[where id_atas = ?pnId_atas]

lnSucces = goExecutor.oExecute(lcSql)
If lnSucces < 0
	aMessagebox(goExecutor.cEroare,0+16,'Eroare')
Endif

If !Empty(lcTabelLinkuri)
	Select (lcTabelLinkuri)
	Gather Name poLink Memo
	Replace descriere With pcDescriere
Endif

Endproc && modifica_atasament
***-----------------------------------------------------------------------------------------------------------------------------
Procedure salveaza_atasamente
	Parameters tcTabel

	Local lcTabel
	lcTabel = tcTabel

	lcSql = [select ar.id_referinta ]+;
		[ from VATAS_REFERINTE ar ]+;
		[ where ar.nume_fisier is not null and ar.id_program = ?gnIdProgram and ar.id_entitate=]+Alltrim(Str(goContract.id_ctr))
	lcCursor = 'crsAtasamente_server'
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
		Return lnSucces
	Endif

	* daca exista id_referinta in plus in cursorul de pe local, adaug pe server
	Private pnId_entitate, pcLink, pcDescriere, pcFis_name, pcFisier, pnId_atas
	Store 0 To pnId_entitate, pnId_atas
	Store "" To pcDescriere, pcFis_name, pcFisier, pcLink

	pnId_entitate = goContract.id_ctr

	Select * From (lcTabel) ;
		Where (Empty(id_referinta) Or Isnull(id_referinta)) ;
		INTO Cursor cAtasamente_nou

	Select cAtasamente_nou
	Scan
		pcDescriere = Upper(Alltrim(descriere))
		pcFis_name = Upper(Alltrim(nume_fisier))
		*!*			If Empty(pcLink)
		*!*				Return
		*!*			Endif
		* pcFisier = Filetostr(pcLink)
		pcFisier = fisier

		lcSql = [insert into atas_atasamente(fisier, nume_fisier, descriere, id_util) ]+;
			[values (?pcFisier, ?pcFis_name, ?pcDescriere, ?gnIdUtil) ] + ;
			[ returning id_atas into ?@pnId_atas]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			aMessagebox(goExecutor.cEroare,0+16,'Eroare')
		Endif

		lcSql = [insert into atas_referinte(id_atas, id_program, id_entitate, id_util) ]+;
			[values (?pnId_atas, ?gnIdProgram, ?pnId_entitate, ?gnIdUtil) ]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			aMessagebox(goExecutor.cEroare,0+16,'Eroare')
			Return lnSucces
		Endif
		Select cAtasamente_nou
	Endscan

	If Used('cAtasamente_nou')
		Use In cAtasamente_nou
	Endif

	* daca exista id_referinta pe server, care nu mai sunt pe local, sterg
	*!*		Select id_referinta From crsAtasamente_server ;
	*!*			Where id_referinta Not In (Select id_referinta From cId_ref) ;
	*!*			INTO Cursor cAtasamente_sters

	lcDeleted = Set("Deleted")

	Set Deleted Off
	Select * From (lcTabel) Where Deleted() And !Empty(id_referinta);
		INTO Cursor cAtasamente_sters

	Select cAtasamente_sters
	Scan
		*pcId_atas = Alltrim(Str(id_atas))
		lcId_referinta = Alltrim(Str(id_referinta))
		lcSql = [update atas_referinte set sters = 1, dataoras = SYSDATE, id_utils = ] + Alltrim(Str(gnIdUtil)) + ;
			[ WHERE id_referinta = ] + lcId_referinta
		lnSucces = goExecutor.oExecute(lcSql)

		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
			Return lnSucces
		Endif
		Select cAtasamente_sters
	Endscan

	If Used('cAtasamente_sters')
		Use In cAtasamente_sters
	Endif

	Set Deleted &lcDeleted

	If Used('cAtasamente_sters')
		Use In cAtasamente_sters
	Endif

	If Used('crsAtasamente_server')
		Use In crsAtasamente_server
	Endif

	Return lnSucces
Endproc && salveaza_atasamente
***-----------------------------------------------------------------------------------------------------------------------------
Procedure arata_linkuri

Private poLink
Store '' To poLink

Local lcMenu, lnx, lcDocument,lnNrLinkuri, lnIdAtas
Local lcSchema, lcSelect, lcOrder, lcFiltru, lcFiltruOriginal, llAfiseaza, lcgroup, lcFiltruOriginal
Store '' To lcMenu
Store 0 To lnNrLinkuri, lnIdAtas


Do make_crsAtasamente In oproceduri_atasamente.prg

lcMenu = lcMenu + "Ataseaza ...;\-;"
Select crsAtasamente
Scan
	lcMenu = lcMenu + Alltrim(Nvl(descriere,''))+ ' - ' + Alltrim(Nvl(nume_fisier,'')) +';'
	lnNrLinkuri = lnNrLinkuri + 1
	Select crsAtasamente
Endscan

If Upper(Alltrim(gcNumeProgram)) = "ROALUCRARI" And lnNrLinkuri > 0
	lcMenu = lcMenu + '\-;'+ "Vizualizare atasamente ...;"
Endif


If !Empty(lcMenu)
	lcMenu = Substr(lcMenu,1,Len(lcMenu)-1)
	lnx = xmenu(lcMenu)

	Do Case
	Case lnx = 1 && Ataseaza
		Do upload In oproceduri_atasamente.prg
	Case lnx = lnNrLinkuri + 4
		Select crsAtasamente
		Go Top

		ofrmVizAtas = Createobject('frm_viz_atasamente')
		ofrmVizAtas.Show(1)
		Release ofrmVizAtas
	Otherwise

		Select crsAtasamente
		Locate For Recno() = lnx - 2
		If Found()
			lnIdAtas = id_atas
			lcNume_fisier = Alltrim(nume_fisier)
			lcSchema = [fisier w ]
			lcSelect = [select fisier from atas_atasamente where id_atas = ] + Alltrim(Str(lnIdAtas))
			lcOrder = []
			lcgroup = []
			lcFiltru = []
			lcFiltruOriginal = []
			llModParam = .T.
			llAfiseaza = .F.

			GENCURSOR('poLink','cRegFisierTemp', lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza,  lcgroup, llModParam, lcFiltruOriginal)
			poLink.ca_baza1.afisare()
			If Used('cRegFisierTemp')
				lcFisier = fisier
				Use In (Select('cRegFisierTemp'))
				lcFisSalvat = Addbs(gcTempPath)+lcNume_fisier

				Strtofile(lcFisier, lcFisSalvat)
				open_default_app(lcFisSalvat)

			Endif
		Endif
	Endcase

	If Used('crsAtasamente')
		Use In crsAtasamente
	Endif
Endif

Endproc && arata_linkuri
***-----------------------------------------------------------------------------------------------------------------------------
