*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="orapoarte.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS ct_grup_camp AS _container OF "_baza.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="ck_ordine" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_nume_camp" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_actualizeaza_ordine
		*p: ccamp
		*p: cnumecamp
		*p: ngrupat
		*p: nordine
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderWidth = 0
		ccamp = 
		cnumecamp = 
		Height = 17
		Name = "ct_grup_camp"
		ngrupat = 0
		nordine = 0
		Width = 183
		_memberdata = <VFPData>
			<memberdata name="ccamp" type="Property" favorites="True"/>
			<memberdata name="cnumecamp" type="Property" favorites="True"/>
			<memberdata name="do_actualizeaza_ordine" type="Method" favorites="True"/>
			<memberdata name="ngrupat" type="Property" favorites="True"/>
			<memberdata name="nid_container" type="Property" favorites="True"/>
		</VFPData>
	*</PropValue>

	ADD OBJECT 'ck_ordine' AS _checkbox WITH ;
		Alignment = 0, ;
		AutoSize = .F., ;
		Caption = "[Grup camp]", ;
		Height = 17, ;
		Left = 122, ;
		Name = "ck_ordine", ;
		Top = 1, ;
		Width = 43
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'lb_nume_camp' AS lb_simplu WITH ;
		AutoSize = .F., ;
		Caption = "[Explicatie camp]", ;
		Height = 17, ;
		Left = 2, ;
		Name = "lb_nume_camp", ;
		Top = 1, ;
		Width = 118
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />
	
	PROCEDURE do_actualizeaza_ordine
		Lparameters tnOrdine
		If !Empty(tnOrdine)
			This.lb_nume_camp.FontBold = .T.
			This.ck_ordine.Caption = Alltrim(Str(tnOrdine))
			This.ngrupat = 1
		Else
			This.lb_nume_camp.FontBold = .F.
			This.ck_ordine.Caption = []
			This.ngrupat = 0
		Endif
		This.nordine = tnOrdine
		
	ENDPROC

	PROCEDURE Init
		Lparameters toHash
		This.ccamp = toHash.getValue('cCamp')
		This.cnumeCamp = toHash.getValue('cNumeCamp')
		This.lb_nume_camp.Caption = This.cnumeCamp
		This.do_actualizeaza_ordine(0)
		
	ENDPROC

	PROCEDURE ck_ordine.Click
		This.ProgrammaticChange()
		
	ENDPROC

	PROCEDURE ck_ordine.ProgrammaticChange
		This.Parent.Parent.Parent.do_modifica_ordine(This.Parent.Name,This.Parent.nordine,This.Value)
	ENDPROC

ENDDEFINE

DEFINE CLASS ct_grupare AS _container OF "_baza.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="lb_grupare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_scrollcontainer1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_adauga_ct
		*m: do_modifica_ordine
		*m: do_reset
		*m: do_sterge_ct
		*p: cclasa		&& Numele clasei ce va fi instantiata la adaugare.
		*p: nmax_ordine
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	*<PropValue>
		cclasa = ct_grup_camp
		Height = 200
		Name = "ct_grupare"
		nmax_ordine = 0
		Width = 353
		_memberdata = <VFPData>
			<memberdata name="cclasa" type="Property" favorites="True"/>
			<memberdata name="do_adauga_ct" type="Method" favorites="True"/>
			<memberdata name="do_modifica_ordine" type="Method" favorites="True"/>
			<memberdata name="do_sterge_ct" type="Method" favorites="True"/>
			<memberdata name="nmax_id_container" type="Property" favorites="True"/>
			<memberdata name="nmax_ordine" type="Property" favorites="True"/>
		</VFPData>
	*</PropValue>

	ADD OBJECT '_scrollcontainer1' AS _scrollcontainer WITH ;
		BorderWidth = 0, ;
		Height = 181, ;
		Left = 0, ;
		Name = "_scrollcontainer1", ;
		Top = 23, ;
		Width = 360, ;
		But_sus1.Left = 328, ;
		But_sus1.Name = "But_sus1", ;
		But_sus1.Top = 0, ;
		But_jos1.Left = 328, ;
		But_jos1.Name = "But_jos1", ;
		But_jos1.Top = 29
		*< END OBJECT: ClassLib="scrollcontainer.vcx" BaseClass="container" />

	ADD OBJECT 'lb_grupare' AS lb_simplu WITH ;
		Caption = "Grupat dupa :", ;
		FontItalic = .T., ;
		Height = 17, ;
		Left = 12, ;
		Name = "lb_grupare", ;
		TabIndex = 8, ;
		Top = 6, ;
		Visible = .T., ;
		Width = 76
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />
	
	PROCEDURE do_adauga_ct
		Lparameters tcCamp,tcNumeCamp
		Local lcClasa,lcNumeObiect,loHash As MyHash
		If Empty(This.cclasa)
			lcClasa = [CT_GRUP_CAMP]
		Else
			lcClasa = Upper(Alltrim(This.cclasa))
		Endif
		lcNumeObiect = Upper(Alltrim([ct_grup_] + Strtran(tcCamp,[.],[_])))
		loHash = GetHash()
		loHash.SetValue("cCamp", tcCamp)
		loHash.SetValue("cNumeCamp", tcNumeCamp)
		This._scrollcontainer1.do_adaugaobiect(lcNumeObiect,lcClasa,loHash)
		With This._scrollcontainer1.&lcNumeObiect.
			.Visible = .T.
		EndWith
		Release loHash
		*!*	This.AddObject(lcNumeObiect,lcClasa,tcCamp,tcNumeCamp)
		*!*	With This.&lcNumeObiect.
		*!*		.Left = This.nLeft
		*!*		.Top = This.nMaxTop
		*!*		This.nMaxTop = .Top + .Height - 2
		*!*		.Visible = .T.
		*!*	Endwith
	ENDPROC

	PROCEDURE do_modifica_ordine
		Lparameters tcNumeObiect,tnOrdine,tnValoare
		If Empty(This.cclasa)
			lcClasa = [CT_GRUP_CAMP]
		Else
			lcClasa = Upper(Alltrim(This.cclasa))
		Endif
		If tnValoare = 0
			For i = 1 To This._scrollcontainer1.Objects.Count
				With This._scrollcontainer1.Objects(i)
					If Upper(Alltrim(.Class))=lcClasa
						Do Case
						Case .nordine = tnOrdine
							If Pemstatus(This.Parent,"do_modifica",5)
		*!*	modificare	ROAGEST	v 2.0.144
		*!*							This.Parent.do_modifica(2,.ccamp,.nordine - 1)
								This.Parent.do_modifica(2,.ccamp,0)
		*!*	modificare	ROAGEST	v 2.0.144	^
							Endif
							.do_actualizeaza_ordine(0)
						Case .nordine > tnOrdine
							If Pemstatus(This.Parent,"do_modifica",5)
								This.Parent.do_modifica(2,.ccamp,.nordine - 1)
							Endif
							.do_actualizeaza_ordine(.nordine - 1)
						Endcase
					Endif
				Endwith
			Endfor
			This.nmax_ordine = This.nmax_ordine - 1
		Else
			This.nmax_ordine = This.nmax_ordine + 1
			With This._scrollcontainer1.&tcNumeObiect.
				If Pemstatus(This.Parent,"do_modifica",5)
					This.Parent.do_modifica(2,.ccamp,This.nmax_ordine)
				Endif
				.do_actualizeaza_ordine(This.nmax_ordine)
			Endwith
		Endif
		
	ENDPROC

	PROCEDURE do_reset
		This._SCROLLCONTAINER1.Init()
		
	ENDPROC

	PROCEDURE do_sterge_ct
		Lparameters tcCamp
		Local lcClasa,lcNumeObiect
		If Empty(This.cclasa)
			lcClasa = [CT_GRUP_CAMP]
		Else
			lcClasa = Upper(Alltrim(This.cclasa))
		Endif
		lcNumeObiect = Upper(Alltrim([ct_grup_] + Strtran(tcCamp,[.],[_])))
		If Type('this._scrollcontainer1.'+lcNumeObiect)<>'U'
			With This._scrollcontainer1.&lcNumeObiect.
		*!*			lnHeight = .Height
		*!*			lnTop = .Top
				lnOrdine = .nordine
			Endwith
		*!*		This.RemoveObject(lcNumeObiect,lcClasa)
			This._scrollcontainer1.do_stergeobiect(lcNumeObiect)
			For i = 1 To This._scrollcontainer1.Objects.Count
				With This._scrollcontainer1.Objects(i)
					If Upper(Alltrim(.Class))=lcClasa
						If lnOrdine > 0 And .nordine > lnOrdine
							If Pemstatus(This.Parent,"do_modifica",5)
								This.Parent.do_modifica(2,.ccamp,.nordine - 1)
							Endif
							.do_actualizeaza_ordine(.nordine - 1)
						Endif
		*!*					If .Top > lnTop
		*!*						.Top = .Top - lnHeight + 2
		*!*					Endif
					Endif
				Endwith
			Endfor
		*!*		This.nMaxTop = This.nMaxTop - lnHeight + 2
			This.nmax_ordine = This.nmax_ordine - Iif(lnOrdine = 0,0,1)
		Endif
	ENDPROC

	PROCEDURE _scrollcontainer1.Init
		Local lnNrObiecteVizibile,lnTop,lnLeft,lnWidth,lnDistantaVObiecte,lnDistantaOObiecte
		lnHeightGrupCamp = 15		&&	17 = inaltimea ct_grup_camp
		lnNrObiecteVizibile = Floor((This.Parent.Height - This.Top)/ lnHeightGrupCamp)
		lnTop = This.Top
		lnLeft = This.Left
		lnWidth = This.Parent.Width
		lnDistantaVObiecte = -2
		lnDistantaOObiecte = 0
		This.but_jos1.Left = lnWidth - 18
		This.but_sus1.Left = lnWidth - 18
		This.nmaxheight = lnHeightGrupCamp * lnNrObiecteVizibile
		DoDefault(lnNrObiecteVizibile,lnTop,lnLeft,lnWidth,lnDistantaVObiecte,lnDistantaOObiecte)
	ENDPROC

ENDDEFINE

DEFINE CLASS ct_ordine_camp AS _container OF "_baza.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="ck_ordine" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_nume_camp" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="opt_ordine" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_actualizeaza_ordine
		*p: ccamp
		*p: cnumecamp
		*p: csens
		*p: nordine
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderWidth = 0
		ccamp = 
		cnumecamp = 
		csens = 
		Height = 17
		Name = "ct_ordine_camp"
		nordine = 0
		Width = 302
	*</PropValue>

	ADD OBJECT 'ck_ordine' AS _checkbox WITH ;
		Alignment = 0, ;
		AutoSize = .F., ;
		Caption = "[Ordine camp]", ;
		Height = 17, ;
		Left = 122, ;
		Name = "ck_ordine", ;
		Top = 0, ;
		Width = 43
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'lb_nume_camp' AS lb_simplu WITH ;
		AutoSize = .F., ;
		Caption = "[Explicatie camp]", ;
		Height = 17, ;
		Left = 2, ;
		Name = "lb_nume_camp", ;
		Top = 0, ;
		Width = 118
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'opt_ordine' AS _optiongrup WITH ;
		BorderStyle = 0, ;
		Height = 28, ;
		Left = 160, ;
		Name = "opt_ordine", ;
		Top = -6, ;
		Width = 146, ;
		Option1.AutoSize = .T., ;
		Option1.Caption = "Crescator", ;
		Option1.FontName = "Arial Narrow", ;
		Option1.Left = 5, ;
		Option1.Name = "Option1", ;
		Option1.Top = 5, ;
		Option2.AutoSize = .T., ;
		Option2.Caption = "Descrescator", ;
		Option2.FontName = "Arial Narrow", ;
		Option2.Left = 68, ;
		Option2.Name = "Option2", ;
		Option2.Top = 5
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="optiongroup" />
	
	PROCEDURE do_actualizeaza_ordine
		Lparameters tnOrdine
		If !Empty(tnOrdine)
			This.lb_nume_camp.FontBold = .T.
			This.ck_ordine.Caption = Alltrim(Str(tnOrdine))
			This.opt_ordine.Visible = .T.
		Else
			This.lb_nume_camp.FontBold = .F.
			This.ck_ordine.Caption = []
			With This.opt_ordine
				.Visible = .F.
				.Value = 1
			Endwith
		Endif
		This.nordine = tnOrdine
		
	ENDPROC

	PROCEDURE Init
		Lparameters toHash
		This.ccamp = toHash.getValue('cCamp')
		This.cnumeCamp = toHash.getValue('cNumeCamp')
		This.lb_nume_camp.Caption = toHash.getValue('cNumeCamp')
		This.do_actualizeaza_ordine(0)
		
	ENDPROC

	PROCEDURE ck_ordine.Click
		This.ProgrammaticChange()
		
	ENDPROC

	PROCEDURE ck_ordine.ProgrammaticChange
		This.Parent.Parent.Parent.do_modifica_ordine(This.Parent.Name,This.Parent.nordine,This.Value)
	ENDPROC

	PROCEDURE opt_ordine.InteractiveChange
		If This.Value = 1
			This.Parent.csens = []
		Else
			This.Parent.csens = [DESC]
		Endif
		This.Parent.Parent.Parent.do_modifica_sens(This.Parent.ccamp,This.Value)
	ENDPROC

	PROCEDURE opt_ordine.ProgrammaticChange
		This.InteractiveChange()
	ENDPROC

ENDDEFINE

DEFINE CLASS ct_ordonare AS _container OF "_baza.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="lb_ordonare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_scrollcontainer1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_adauga_ct
		*m: do_modifica_ordine
		*m: do_modifica_sens
		*m: do_reset
		*m: do_sterge_ct
		*p: cclasa		&& Numele clasei ce va fi instantiata la adaugare.
		*p: nleft
		*p: nleft2		&& 90
		*p: nmaxtop
		*p: nmaxtop2
		*p: nmax_ordine
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	*<PropValue>
		cclasa = ct_ordine_camp
		Height = 200
		Name = "ct_ordonare"
		nleft = 9
		nleft2 = 90
		nmaxtop = 0
		nmaxtop2 = 0
		nmax_ordine = 0
		Width = 353
		_memberdata = <VFPData>
			<memberdata name="cclasa" type="Property" favorites="True"/>
			<memberdata name="do_adauga_ct" type="Method" favorites="True"/>
			<memberdata name="do_modifica_ordine" type="Method" favorites="True"/>
			<memberdata name="do_sterge_ct" type="Method" favorites="True"/>
			<memberdata name="nmax_id_container" type="Property" favorites="True"/>
			<memberdata name="nmax_ordine" type="Property" favorites="True"/>
		</VFPData>
	*</PropValue>

	ADD OBJECT '_scrollcontainer1' AS _scrollcontainer WITH ;
		BorderWidth = 0, ;
		Height = 181, ;
		Left = 0, ;
		Name = "_scrollcontainer1", ;
		Top = 23, ;
		Width = 360, ;
		But_sus1.Left = 328, ;
		But_sus1.Name = "But_sus1", ;
		But_sus1.Top = 1, ;
		But_jos1.Left = 328, ;
		But_jos1.Name = "But_jos1", ;
		But_jos1.Top = 30
		*< END OBJECT: ClassLib="scrollcontainer.vcx" BaseClass="container" />

	ADD OBJECT 'lb_ordonare' AS lb_simplu WITH ;
		Caption = "Ordonate dupa:", ;
		FontItalic = .T., ;
		Height = 17, ;
		Left = 8, ;
		Name = "lb_ordonare", ;
		TabIndex = 8, ;
		Top = 6, ;
		Visible = .T., ;
		Width = 87
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />
	
	PROCEDURE do_adauga_ct
		Lparameters tcCamp,tcNumeCamp
		Local lcClasa,lcNumeObiect,loHash As MyHash
		If Empty(This.cclasa)
			lcClasa = [CT_ORDINE_CAMP]
		Else
			lcClasa = Upper(Alltrim(This.cclasa))
		Endif
		lcNumeObiect = Upper(Alltrim([ct_ordine_] + Strtran(tcCamp,[.],[_])))
		loHash = GetHash()
		loHash.SetValue("cCamp", tcCamp)
		loHash.SetValue("cNumeCamp", tcNumeCamp)
		This._scrollcontainer1.do_adaugaobiect(lcNumeObiect,lcClasa,loHash)
		With This._scrollcontainer1.&lcNumeObiect.
			.Visible = .T.
		Endwith
		Release loHash
		*!*	This.AddObject(lcNumeObiect,lcClasa,tcCamp,tcNumeCamp)
		*!*	With This.&lcNumeObiect.
		*!*		.Left = This.nLeft
		*!*		.Top = This.nMaxTop
		*!*		This.nMaxTop = .Top + .Height - 2
		*!*		.Visible = .T.
		*!*	Endwith
	ENDPROC

	PROCEDURE do_modifica_ordine
		Lparameters tcNumeObiect,tnOrdine,tnValoare
		If Empty(This.cclasa)
			lcClasa = [CT_ORDINE_CAMP]
		Else
			lcClasa = Upper(Alltrim(This.cclasa))
		Endif
		If tnValoare = 0
			For i = 1 To This._scrollcontainer1.Objects.Count
				With This._scrollcontainer1.Objects(i)
					If Upper(Alltrim(.Class))=lcClasa
						Do Case
						Case .nordine = tnOrdine
							If Pemstatus(This.Parent,"do_modifica",5)
								This.Parent.do_modifica(3,.ccamp,0)
							Endif
							.do_actualizeaza_ordine(0)
						Case .nordine > tnOrdine
							If Pemstatus(This.Parent,"do_modifica",5)
								This.Parent.do_modifica(3,.ccamp,.nordine - 1)
							Endif
							.do_actualizeaza_ordine(.nordine - 1)
						Endcase
					Endif
				Endwith
			Endfor
			This.nmax_ordine = This.nmax_ordine - 1
		Else
			This.nmax_ordine = This.nmax_ordine + 1
			With This._scrollcontainer1.&tcNumeObiect.
				If Pemstatus(This.Parent,"do_modifica",5)
					This.Parent.do_modifica(3,.ccamp,This.nmax_ordine)
				Endif
				.do_actualizeaza_ordine(This.nmax_ordine)
			Endwith
		Endif
		
	ENDPROC

	PROCEDURE do_modifica_sens
		Lparameters tcCamp,tnSens
		If Pemstatus(This.Parent,"do_modifica",5)
			This.Parent.do_modifica(4,tcCamp,tnSens)
		Endif
	ENDPROC

	PROCEDURE do_reset
		This._SCROLLCONTAINER1.Init()
		
	ENDPROC

	PROCEDURE do_sterge_ct
		Lparameters tcCamp
		Local lcClasa,lcNumeObiect
		If Empty(This.cclasa)
			lcClasa = [CT_ORDINE_CAMP]
		Else
			lcClasa = Upper(Alltrim(This.cclasa))
		Endif
		lcNumeObiect = Upper(Alltrim([ct_ordine_] + Strtran(tcCamp,[.],[_])))
		If Type('this._scrollcontainer1.'+lcNumeObiect)<>'U'
			With This._scrollcontainer1.&lcNumeObiect.
		*!*			lnHeight = .Height
		*!*			lnTop = .Top
				lnOrdine = .nordine
			Endwith
		*!*		This.RemoveObject(lcNumeObiect,lcClasa)
			This._scrollcontainer1.do_stergeobiect(lcNumeObiect)
			For i = 1 To This._scrollcontainer1.Objects.Count
				With This._scrollcontainer1.Objects(i)
					If Upper(Alltrim(.Class))=lcClasa
						If lnOrdine > 0 And .nordine > lnOrdine
							If Pemstatus(This.Parent,"do_modifica",5)
								This.Parent.do_modifica(3,.ccamp,.nordine - 1)
							Endif
							.do_actualizeaza_ordine(.nordine - 1)
						Endif
		*!*					If .Top > lnTop
		*!*						.Top = .Top - lnHeight + 2
		*!*					Endif
					Endif
				Endwith
			Endfor
		*!*		This.nMaxTop = This.nMaxTop - lnHeight + 2
			This.nmax_ordine = This.nmax_ordine - Iif(lnOrdine = 0,0,1)
		Endif
	ENDPROC

	PROCEDURE _scrollcontainer1.Init
		Local lnNrObiecteVizibile,lnTop,lnLeft,lnWidth,lnDistantaVObiecte,lnDistantaOObiecte
		lnHeightOrdCamp = 15		&&	17 = inaltimea ct_grup_camp
		lnNrObiecteVizibile = Floor((This.Parent.Height - This.Top)/ lnHeightOrdCamp)
		lnTop = This.Top
		lnLeft = This.Left
		lnWidth = This.Width
		lnDistantaVObiecte = -2
		lnDistantaOObiecte = 0
		This.nmaxheight = lnHeightOrdCamp * lnNrObiecteVizibile
		DoDefault(lnNrObiecteVizibile,lnTop,lnLeft,lnWidth,lnDistantaVObiecte,lnDistantaOObiecte)
	ENDPROC

ENDDEFINE

DEFINE CLASS ct_selectie AS _container OF "_baza.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Ct_grupare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grupare1.lblAtentie" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_ordonare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_coloane" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_actualizeaza_culori_sume
		*m: do_adauga
		*m: do_compune_ordine_selectie
		*m: do_crosstabulare
		*m: do_instructiune_sql
		*m: do_modifica
		*m: do_reset
		*m: do_sterge
		*m: do_verifica_verticala
		*m: get_coloane_crosstabulare
		*m: get_coloane_grupare
		*m: get_coloane_ordonare
		*m: get_coloane_selectie
		*p: cclasa		&& Clasa folosita pentru checkbox-urile din selectii.
		*p: ccoloanesuma		&& Numele coloanelor care sunt agregate.
		*p: clistacoloaneordine		&& Lista delimitata prin virgula ce contine pozitiile din ccoloanesuma pentru care se vor adauga containere la ordonare.
		*p: cnumecoloanesuma
		*p: cnumetabela		&& Numele tabelei/view-ului din care se face selectia.
		*p: cordine
		*p: csql
		*p: lcrosstabulare		&& .T. daca a fost selectata o coloana pentru crosstabulare
		*p: ltitlucoloanesuma		&& Daca numele coloanelor selectate se face dupa valoare din cNumeColoaneSuma
		*p: nelemente		&& Numarul de elemente din this.aselectie
		*a: aselectie[30,6]
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	*<PropValue>
		cclasa = ct_selectie_camp
		ccoloanesuma = 
		clistacoloaneordine = 
		cnumecoloanesuma = 
		cnumetabela = 
		cordine = 
		csql = 
		Height = 364
		lcrosstabulare = .F.
		ltitlucoloanesuma = .F.
		Name = "ct_selectie"
		nelemente = 0
		ToolTipText = ' Pentru detalii despre generarea rapoartelor, apasati butonul "?".'
		Width = 332
		_memberdata = <VFPData>
			<memberdata name="ltitlucoloanesuma" type="Property" favorites="True"/>
			<memberdata name="cnumetabela" type="Property" favorites="True"/>
		</VFPData>
	*</PropValue>

	ADD OBJECT 'Ct_grupare1' AS ct_grupare WITH ;
		Height = 133, ;
		Left = 5, ;
		Name = "Ct_grupare1", ;
		Top = 227, ;
		Width = 320, ;
		lb_grupare.Name = "lb_grupare", ;
		_scrollcontainer1.But_jos1.Name = "But_jos1", ;
		_scrollcontainer1.But_sus1.Name = "But_sus1", ;
		_scrollcontainer1.Name = "_scrollcontainer1"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grupare1.lblAtentie' AS lb_simplu WITH ;
		AutoSize = .F., ;
		Caption = "Mesaj atentie", ;
		ForeColor = 255,0,0, ;
		Height = 17, ;
		Left = 91, ;
		Name = "lblAtentie", ;
		TabIndex = 9, ;
		Top = 6, ;
		Visible = .F., ;
		Width = 223
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'Ct_ordonare1' AS ct_ordonare WITH ;
		Height = 133, ;
		Left = 5, ;
		Name = "Ct_ordonare1", ;
		Top = 95, ;
		Width = 320, ;
		lb_ordonare.Name = "lb_ordonare", ;
		_scrollcontainer1.But_jos1.Name = "But_jos1", ;
		_scrollcontainer1.But_sus1.Name = "But_sus1", ;
		_scrollcontainer1.Name = "_scrollcontainer1"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'lb_coloane' AS lb_simplu WITH ;
		Caption = "Coloane in selectie:", ;
		FontItalic = .T., ;
		Height = 17, ;
		Left = 10, ;
		Name = "lb_coloane", ;
		TabIndex = 9, ;
		Top = 0, ;
		Width = 110
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />
	
	PROCEDURE do_actualizeaza_culori_sume
		Local lnTip
		lnTip = Iif(This.lcrosstabulare,2,1)
		For i = 1 To This.Objects.Count
			If Upper(This.Objects[i].Class) = 'CT_SELECTIE_CAMP' And This.Objects[i].lsuma
				This.Objects[i].do_seteaza_culoare(lnTip)
			Endif
		Endfor
		
	ENDPROC

	PROCEDURE do_adauga
		Lparameters lcCamp, lcNumeCamp, llGrupare, llOrdine, llColoaneSuma, lcCampId
		*!*	LPARAMETERS toSelectieCamp
		
		*!*	LOCAL lcCamp, lcNumeCamp, llGrupare, llOrdine, llColoaneSuma
		*!*	WITH toSelectieCamp
		*!*		lcCamp = .ccamp
		*!*		lcNumeCamp = .cnumecamp
		*!*		llGrupare = .lgrupare
		*!*		llOrdine = .lordine
		*!*		llColoaneSuma = .lSuma
		*!*	ENDWITH
		
		If !llColoaneSuma
			This.nelemente = This.nelemente + 1
			Ains(This.aselectie,This.nelemente)
		
			This.aselectie[This.nelemente,1] = Upper(Alltrim(lcCamp))
			This.aselectie[this.nelemente,2] = 0
			This.aselectie[this.nelemente,3] = 0
			This.aselectie[this.nelemente,4] = 0
		&&	modificare crosstabulare
			This.aselectie[this.nelemente,5] = .F.
			This.aselectie[this.nelemente,6] = Upper(Alltrim(Nvl(lcCampId,lcCamp)))
		&&	campul dupa ale carui valori se face crosstabularea
		&&	modificare crosstabulare	^
			If llGrupare
				This.ct_grupare1.do_adauga_ct(Upper(Alltrim(lcCamp)),lcNumeCamp)
			Endif
			If llOrdine
				This.ct_ordonare1.do_adauga_ct(Upper(Alltrim(lcCamp)),lcNumeCamp)
			Endif
		
		Else
			This.ccoloanesuma = This.ccoloanesuma + "|" + lcCamp
			This.cnumecoloanesuma = This.cnumecoloanesuma + "|" + lcNumeCamp
		Endif
		
	ENDPROC

	PROTECTED PROCEDURE do_compune_ordine_selectie
		Lparameters taArraySelectie
		Local lcOrdine, lcSens
		lcOrdine = []
		Asort(taArraySelectie,3)
		For i = 1 To Alen(taArraySelectie,1)
			If !Empty(taArraySelectie[i,1]) And !Empty(Nvl(taArraySelectie[i,3],0))
				If Empty(taArraySelectie[i,4]) Or (taArraySelectie[i,4] = 1)
					lcSens = []
				Else
					lcSens = [ DESC]
				Endif
				lcOrdine = lcOrdine + [,] + taArraySelectie[i,1] + lcSens
			Endif
		Endfor
		This.cOrdine = lcOrdine
	ENDPROC

	PROCEDURE do_crosstabulare
		&&	modificare crosstabulare
		Lparameters lcCamp, llCrosstabulare
		lnPozitie=Ascan(This.aselectie,Upper(Alltrim(lcCamp)),1,Alen(This.aselectie,1),1,9)
		If !This.lcrosstabulare
			If lnPozitie > 0
				This.aselectie(lnPozitie,5) = .T.
				This.lcrosstabulare = .T.
				llReturn = .T.
			Else
				llReturn = .F.
			Endif
		Else
			If lnPozitie > 0
				If This.aselectie(lnPozitie,5)
					This.aselectie(lnPozitie,5) = .F.
					This.lcrosstabulare = .F.
				Endif
			Endif
			llReturn = .F.
		Endif
		Return llReturn
		&&	modificare crosstabulare	^
	ENDPROC

	PROCEDURE do_instructiune_sql
		LPARAMETERS tcFiltru
		*!* 22.06.2010
		*!* marius.mutu
		*!* din frm_date_rapoarte_gen.do_cauta - apelez do_instructiune_sql cu filtrul dorit
		*!*	daca coloana de crostabulare face parte din filtru - transmit filtrul la pivot_gen.build_sql_complex - sa arat atatea coloane cate valori sunt in filtru
		
		*!* 08.07.2010
		*!* marius.mutu
		*!* am adaugat parametrul p_separator '|' la apelul build_sql_complex
		*!* daca in expresiile valorilor aparea virgula, era interpretata gresit ca separator de expresii
					
		Local llSelectieVida,lcSql,lcColoaneGrupate,lcAlteColoane,lcColoaneSuma,lcSelect,lcFiltru,lcGroupBy,lcOrderBy,lcOrdine,lcOrdineGrup
		Local lnPozitii,llReturn
		&&	modificare crosstabulare
		Local lcIdColoanaCrossTabulare,lcColoanaCrossTabulare,lnNumarColoane,lcColoaneSumaCT,lcNumeColoaneSumaCT,lcSelectCT,lcColoaneAgregareCT
		Store "" to lcIdColoanaCrossTabulare,lcColoanaCrossTabulare,lnNumarColoane,lcColoaneSumaCT,lcNumeColoaneSumaCT,lcSelectCT,lcColoaneAgregareCT
		&&	modificare crosstabulare	^
		Store .T. To llSelectieVida
		Store .T. to llReturn
		*!* 08.07.2010
		LOCAL lcSeparator
		lcSeparator = [|]
		*!* 08.07.2010 ^
		lcSql = ""
		lcMesajAtentie = ""
		lnNumarColoane = Alen(This.aselectie,2)	&&	numarul de coloane din array-ul this.aselectie
		
		If !Empty(This.clistacoloaneordine)
			lnPozitii = Getwordcount(This.clistacoloaneordine,[,]) + 1
		Else
			lnPozitii = 1
		Endif
		For i = lnPozitii To Alen(Thisform.ct_selectie1.aselectie,1)
			If !Empty(Thisform.ct_selectie1.aselectie[i,1])
				llSelectieVida = .F.
				Exit
			Endif
		Endfor
		If llSelectieVida
			lcSql = []
		Else
			Dimension laArraySelectie(This.nelemente,lnNumarColoane)
			Acopy(This.aselectie,laArraySelectie,1,This.nelemente*lnNumarColoane)
			This.do_compune_ordine_selectie(@laArraySelectie)
			lcColoaneAgregare = This.ccoloanesuma
			lcView = gcS + [.] + This.cnumetabela
			lcColoaneGrupate = []
			lcAlteColoane = []
			lcColoaneSuma = []
			lcSelect = []
			lcFiltru = [1=2]
			lcGroupBy = []
			lcOrderBy = []
			lcOrdine = This.cordine
			lcOrdineGrup = []
		&&	modificare crosstabulare
			lcIdColoanaCrossTabulare = []
			lcColoanaCrossTabulare = []
		&&	modificare crosstabulare	^
			If !Empty(This.clistacoloaneordine)
		*!*	sterg coloana pentru care se va face suma
				For i = 1 To lnPozitii - 1
					lnPozColoana = Val(Getwordnum(This.clistacoloaneordine,i,[,]))
					lcColoana = Getwordnum(This.ccoloanesuma,lnPozColoana,[|])
					lnRand = Ascan(laArraySelectie,lcColoana,1,Alen(laArraySelectie,1),1,15)
					Adel(laArraySelectie,lnRand)
		*!*				Adel(laArraySelectie,1)
				Endfor
				Dimension laArraySelectie(This.nelemente-lnPozitii+1,lnNumarColoane)
			Endif
			Asort(laArraySelectie,2)
			For i = 1 To Getwordcount(lcColoaneAgregare,[|])
				lcNumeColoana = Getwordnum(lcColoaneAgregare,i,[|])
		*!* daca se iau numele coloanelor suma din cNumeColoaneSuma sau chiar numele coloanei
				If This.ltitlucoloanesuma
					lcTitluColoana = Getwordnum(This.cNumecoloanesuma,i,[|])
					Try
						lcTitluColoana = strtranx(lcTitluColoana, "([^a-zA-Z0-9])", [_] )
					Catch
						lcTitluColoana = lcNumeColoana
					Endtry
		*!*				lcTitluColoana = ["] + lcTitluColoana + ["]
		
				Else
					lcTitluColoana = Getwordnum(lcColoaneAgregare,i,[|])
				Endif
		
				lcColoaneSuma = lcColoaneSuma + [,SUM(] + lcNumeColoana + [) as ] + lcTitluColoana
		&&	modificare crosstabulare
				lcColoaneAgregareCT = lcColoaneAgregareCT + [,SUM(] + lcNumeColoana + [) as ] + lcTitluColoana
				If This.do_verifica_verticala(lcNumeColoana)
					*!* 08.07.2010
					lcColoaneSumaCT = lcColoaneSumaCT + lcSeparator + lcNumeColoana
					lcNumeColoaneSumaCT = lcNumeColoaneSumaCT + lcSeparator + lcTitluColoana
					*!* 08.07.2010 ^
		*!*			Else
		*!*				lcColoaneAgregareCT = lcColoaneAgregareCT + [,SUM(] + lcNumeColoana + [) as ] + lcTitluColoana
				Endif
		&&	modificare crosstabulare	^
			Endfor
			For i = 1 To Alen(laArraySelectie,1)
				If !Empty(laArraySelectie[i,1])
					&&	modificare crosstabulare
					If This.lcrosstabulare And laArraySelectie[i,5]
						lcColoanaCrossTabulare = laArraySelectie[i,1]
						lcIdColoanaCrossTabulare = laArraySelectie[i,6]
					Else
					&&	modificare crosstabulare	^
						If !Empty(laArraySelectie[i,2])
							lcColoaneGrupate = lcColoaneGrupate + [,] + Alltrim(laArraySelectie[i,1])
						Else
							lcAlteColoane = lcAlteColoane + [,] + Alltrim(laArraySelectie[i,1])
						Endif
					&&	modificare crosstabulare
					Endif
					&&	modificare crosstabulare	^
				Endif
			Endfor
		*!* daca sunt campuri pentru care se face suma, trebuie sa fie si campuri dupa care se grupeaza
			If Empty(lcColoaneGrupate) And !Empty(lcColoaneSuma)
				lcSql = []
				lcMesajAtentie = "Trebuie sa bifati campurile pentru grupare!"
				llReturn = .F.
			Else
				If !Empty(lcColoaneGrupate)
					lcSelect = [GROUPING_ID(]+Substr(lcColoaneGrupate,2)+lcAlteColoane+[) AS GID] + lcColoaneGrupate
					lcOrdineGrup = Substr(lcColoaneGrupate,2) + [,GID]
					If Empty(lcAlteColoane)
		&&	modificare crosstabulare
						lcSelectCT = lcSelect
		&&	modificare crosstabulare	^
						lcSelect = lcSelect + lcColoaneSuma
						lcGroupBy = [ GROUP BY ROLLUP(]+Substr(lcColoaneGrupate,2)+[) ]
					Else
		&&	modificare crosstabulare
						lcSelectCT = lcSelect + lcAlteColoane
		&&	modificare crosstabulare	^
						lcSelect = lcSelect + lcAlteColoane + lcColoaneSuma
						lcGroupBy = [ GROUP BY ROLLUP(]+Substr(lcColoaneGrupate,2)+[,(]+Substr(lcAlteColoane,2)+[)) ]
					Endif
				Else
					lcSelect = lcSelect + [GROUPING_ID(] + Substr(lcAlteColoane,2) +[) AS GID] + ;
						lcAlteColoane + lcColoaneSuma
		&&	modificare crosstabulare
					lcSelectCT = lcSelectCT + [GROUPING_ID(] + Substr(lcAlteColoane,2) +[) AS GID] + ;
						lcAlteColoane
		&&	modificare crosstabulare	^				
					lcGroupBy = [ GROUP BY ROLLUP((] + Substr(lcAlteColoane,2) + [))]
					lcOrdineGrup = [GID]
				Endif
				Do Case
				Case !Empty(lcOrdine) And !Empty(lcOrdineGrup)
					lcOrderBy =  [ ORDER BY ] + lcOrdineGrup + lcOrdine
				Case !Empty(lcOrdine) And Empty(lcOrdineGrup)
					lcOrderBy = [ ORDER BY ] + Substr(lcOrdine,2)
				Case !Empty(lcOrdineGrup)
					lcOrderBy  = [ ORDER BY ] + lcOrdineGrup
				Otherwise
					lcOrderBy = []
				Endcase
		&&	modificare crosstabulare
				If This.lcrosstabulare
					If Empty(lcColoaneSumaCT)
						amessagebox("Ati ales coloana pentru crosstabulare," + ;
							"dar nu ati ales sumele care doriti sa fie calculate pentru valorile coloanei respective!",48,"Atentie")
						llReturn = .F.
						Return llReturn
					ENDIF
					*!* 22.06.2010
					IF UPPER(ALLTRIM(m.lcColoanaCrossTabulare))$UPPER(ALLTRIM(m.tcFiltru)) OR UPPER(ALLTRIM(m.lcIdColoanaCrossTabulare))$UPPER(ALLTRIM(m.tcFiltru)) 
						lcFiltru = STRTRAN(m.tcFiltru, ['], [''])
					ENDIF 
					*!* 22.06.2010 ^
								
					Local lcCursorCrossTab
					lcCursorCrossTab = [crscross]
					*!* 08.07.2010
					lcSql = [select pivot_gen.build_sql_complex('] + Strtran(lcView,gcS + [.],[]) + [',] + ;
							['] + Strtran(lcSelectCT,['],['']) + [',] + ;
							['] + Strtran(Substr(lcColoaneAgregareCT,2),['],['']) + [',] + ;
							['] + Strtran(lcIdColoanaCrossTabulare,['],['']) + [',] + ;
							['] + Strtran(lcColoanaCrossTabulare,['],['']) + [',] + ;
							['] + Strtran(Substr(lcColoaneSumaCT,2),['],['']) + [',] + ;
							['] + Strtran(Substr(lcNumeColoaneSumaCT,2),['],['']) + [',] + ;
							['SUM',] + ;
							['0',] + ;
							['] + lcFiltru + [',] + ;
							[0,] + ;
							['] + Strtran(lcGroupBy,[GROUP BY],[]) + [',] + ;
							['] + Strtran(Strtran(Strtran(lcOrderBy,[,]+lcColoanaCrossTabulare,[]),lcColoanaCrossTabulare+[,],[]),[ORDER BY],[]) + [',] + ;
							['|') as sir_sql from dual]
					*!* 08.07.2010 ^					
					lnSucces = goExecutor.oExecute(lcSql,lcCursorCrossTab)
					If lnSucces < 0
						lcSql = []
						lcMesajAtentie = [Eroare la crosstabulare!]
						amessagebox(goExecutor.cEroare,48,"Atentie")
						llReturn = .F.
					Else
						If Reccount(lcCursorCrossTab) > 0
							Select (lcCursorCrossTab)
							lcSql = Alltrim(sir_sql)
						Endif
						Use In (lcCursorCrossTab)
					Endif
				Else
		&&	modificare crosstabulare	^^
					lcSql = [SELECT ] + lcSelect +  [ FROM ] + lcView + ;
						[ WHERE ] + lcFiltru + lcGroupBy + lcOrderBy
		&&	modificare crosstabulare
				Endif
		&&	modificare crosstabulare	^^
				Release laArraySelectie
			Endif && EMPTY(lcColoaneGrupate) AND !EMPTY(lcColoaneSuma)
		Endif && llSelectieVida
		This.cSql = lcSql
		
		This.ct_grupare1.lblAtentie.Caption = lcMesajAtentie
		This.ct_grupare1.lblAtentie.Visible = !Empty(lcMesajAtentie)
		Return llReturn
		
	ENDPROC

	PROCEDURE do_modifica
		Lparameters tnColoana,tcCamp,tnValoare
		&&	tnColoana	:	2	-	ordine grupare
		&&					3	-	ordine la ordonare
		&&					4	-	sens la ordonare		=	1	-	ASC
		&&														2	-	DESC
		&&					5 	- 	cross-tabulare
		&&					6 	-	valoarea dupa care se face cross-tabularea
		lnPozitie=Ascan(This.aselectie,Upper(Alltrim(tcCamp)),1,30,1,9)
		If lnPozitie > 0
			This.aselectie[lnPozitie,tnColoana]=tnValoare
		Endif
		
	ENDPROC

	PROCEDURE do_reset
		Local i
		For i = 1 To This.Objects.Count
			If Upper(Alltrim(This.Objects(i).Class)) = [CT_SELECTIE_CAMP]
				This.Objects(i).ck_camp.Value = 0
		*!*			With This.Objects(i)
		*!*				This.do_sterge(.ccamp, .cnumecamp, .lSuma)
		*!*			Endwith
			Endif
		EndFor
		This.ct_GRUPARE1.do_reset()
		This.ct_orDONARE1.do_reset()
		Release i
	ENDPROC

	PROCEDURE do_sterge
		LPARAMETERS lcCamp, lcNumeCamp, llColoaneSuma
		*!*	LPARAMETERS toSelectieCamp
		
		*!*	LOCAL lcCamp, lcNumeCamp
		*!*	WITH toSelectieCamp
		*!*		lcCamp = .ccamp
		*!*		lcNumeCamp = .cnumecamp
		*!*		llColoaneSuma = .lSuma
		*!*	ENDWITH 	
		
		&&	modificare crosstabulare
		*!*	lnPozitie=Ascan(This.aselectie,Upper(Alltrim(lcCamp)),1,30,1,9)
		lnPozitie=Ascan(This.aselectie,Upper(Alltrim(lcCamp)),1,Alen(This.aselectie,1),1,9)
		&&	modificare crosstabulare	^
		If lnPozitie > 0
			&&	modificare crosstabulare
			If This.aselectie[lnPozitie,5]
				This.lcrosstabulare = .F.
			Endif
			&&	modificare crosstabulare	^
			Adel(This.aselectie,lnPozitie)
			This.nelemente = This.nelemente - 1
		Endif
		This.ct_grupare1.do_sterge_ct(lcCamp)
		This.ct_ordonare1.do_sterge_ct(lcCamp)
		
		*!*	AMESSAGEBOX(this.ccoloanesuma)
		*!*	AMESSAGEBOX(this.cnumecoloanesuma)
		IF llColoaneSuma
			this.ccoloanesuma = STRTRAN(this.ccoloanesuma + [|], [|] + lcCamp + [|], [|])
			IF RIGHT(this.ccoloanesuma,1) = [|]
				this.ccoloanesuma = LEFT(this.ccoloanesuma, LEN(this.ccoloanesuma) - 1)
			ENDIF 	
		
			this.cnumecoloanesuma = STRTRAN(this.cnumecoloanesuma + [|], [|] + lcNumeCamp + [|], [|])
			IF RIGHT(this.cnumecoloanesuma,1) = [|]
				this.cnumecoloanesuma = LEFT(this.cnumecoloanesuma, LEN(this.cnumecoloanesuma) - 1)
			ENDIF 	
		ENDIF
		*!*	AMESSAGEBOX(this.ccoloanesuma)
		*!*	AMESSAGEBOX(this.cnumecoloanesuma)
		
	ENDPROC

	PROCEDURE do_verifica_verticala
		Lparameters lcCamp
		Local j
		llVerticala = .F.
		For j = 1 To This.Objects.Count
			If Upper(This.Objects[j].Class) = 'CT_SELECTIE_CAMP' And Upper(This.Objects[j].ccamp) = Upper(lcCamp)
				llVerticala = This.Objects[j].lverticala
				Exit
			Endif
		Endfor
		Release j
		Return llVerticala
	ENDPROC

	PROCEDURE get_coloane_crosstabulare
		Local lcCrossTabulare
		lcCrossTabulare = []
		For j = 1 To This.Objects.Count
			If Upper(This.Objects[j].Class) = [CT_SELECTIE_CAMP]
				If This.Objects[j].lverticala
		*!*	modificare	28.04.2011 : campul dupa care se face crosstabularea trebuie sa-l pun pe prima pozitie, altfel, la
		*!*							incarcarea unui raport salvat, nu imi mai pune coloanele de la crosstabulare ( trebuie sa fie
		*!*							bifata mai intai coloana cu .cidcamp completat )
		*!*				lcCrossTabulare = lcCrossTabulare + [,] + Strtran(Upper(This.Objects[j].Name),[CT_SELECTIE_])
					If !Isnull(This.Objects[j].cidcamp)
						lcCrossTabulare = [,] + Strtran(Upper(This.Objects[j].Name),[CT_SELECTIE_]) + lcCrossTabulare
					ELSE
						lcCrossTabulare = lcCrossTabulare + [,] + Strtran(Upper(This.Objects[j].Name),[CT_SELECTIE_])
					ENDIF
		*!*	modificare	28.04.2011	^				
				Endif
			Endif
		Endfor
		Return Substr(lcCrossTabulare,2)
	ENDPROC

	PROCEDURE get_coloane_grupare
		Local laArray,lcGrupare
		lcGrupare = []
		Dimension laArray[Alen(this.aselectie,1),Alen(this.aselectie,2)]
		Acopy(This.aselectie,laArray)
		For i = 1 To Alen(laArray,1)
			If Empty(laArray[i,2])
				laArray[i,2] = 0
			Endif
		Endfor
		Asort(laArray,2)
		For i = 1 To Alen(laArray,1)
			If !Empty(laArray[i,2])
				lcGrupare = lcGrupare + [,] + Alltrim(Str(Ascan(this.aselectie,laArray[i,1],1,Alen(this.aselectie,1),1,9)))
			Endif
		Endfor
		Return Substr(lcGrupare,2)
	ENDPROC

	PROCEDURE get_coloane_ordonare
		Local laArray,lcGrupare
		lcOrdonare = []
		Dimension laArray[Alen(this.aselectie,1),Alen(this.aselectie,2)]
		Acopy(This.aselectie,laArray)
		For i = 1 To Alen(laArray,1)
			If Empty(laArray[i,3])
				laArray[i,3] = 0
			Endif
		Endfor
		Asort(laArray,3)
		For i = 1 To Alen(laArray,1)
			If !Empty(laArray[i,3])
				lcOrdonare = lcOrdonare + [,] + Alltrim(Str(Ascan(this.aselectie,laArray[i,1],1,Alen(this.aselectie,1),1,9))) + Iif(Empty(laArray[i,4]) Or laArray[i,4] = 1,[],[ DESC])
			Endif
		Endfor
		Return Substr(lcOrdonare,2)
	ENDPROC

	PROCEDURE get_coloane_selectie
		Local lcSelectie
		lcSelectie = []
		*!*	For i = 1 To Alen(This.aselectie,1)
		*!*		If !Empty(This.aselectie[i,1])
		*!*			lcSelectie = lcSelectie + [,] + This.aselectie[i,1]
		*!*		Endif
		*!*	EndFor
		*!*	lcColoaneSuma = Substr(This.ccoloanesuma,2)
		*!*	For i = 1 To Getwordcount(lcColoaneSuma,[,])
		*!*		lcColoana = Upper(Getwordnum(lcColoaneSuma,i,[,]))
		*!*		For j = 1 To This.Objects.Count
		*!*			If Upper(This.Objects[j].Class) = [CT_SELECTIE_CAMP]
		*!*				If Upper(This.Objects[j].ccamp) = lcColoana
		*!*					lcSelectie = lcSelectie + [,] + Strtran(Upper(This.Objects[j].Name),[CT_SELECTIE_])
		*!*				Endif
		*!*			Endif
		*!*		Endfor
		*!*	Endfor
		For j = 1 To This.Objects.Count
			If Upper(This.Objects[j].Class) = [CT_SELECTIE_CAMP]
				If This.Objects[j].ck_camp.Value = 1
					lcSelectie = lcSelectie + [,] + Strtran(Upper(This.Objects[j].Name),[CT_SELECTIE_])
				Endif
			Endif
		Endfor
		Return Substr(lcSelectie,2)
		
	ENDPROC

	PROCEDURE Init
		*!*	la ccoloanesuma si cnumecoloanesuma am ca separator <<|>> si nu <<,>> pentru ca pot avea ca si coloana o expresie de forma :
		*!*	round(....,...) si atunci nu-mi ia corect coloana
		
		If !Empty(This.clistacoloaneordine)
		*!*	se adauga la ordine si prima coloana din coloanele de sume
			lcLista = Alltrim(Iif(Type('This.clistacoloaneordine')='C',This.clistacoloaneordine,Str(This.clistacoloaneordine)))
			This.clistacoloaneordine=lcLista
			For i = 1 To Getwordcount(lcLista,[,])
				lnPozitie=Val(Getwordnum(lcLista,i,[,]))
				lcNume=Proper(Getwordnum(This.ccoloanesuma,lnPozitie,[|]))
				If !Empty(This.cnumecoloanesuma)
					lcNumeCamp=Proper(Getwordnum(This.cnumecoloanesuma,lnPozitie,[|]))
				Else
					lcNumeCamp = lcNume
				Endif
				This.do_adauga(lcNume,lcNumeCamp,.F.,.T.,.F.,.NULL.)
			Endfor
		Endif
		Bindevent(This,"lcrosstabulare",This,"do_actualizeaza_culori_sume",1)
		
	ENDPROC

ENDDEFINE

DEFINE CLASS ct_selectie_camp AS _container OF "_baza.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="ck_camp" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: actualizeaza_container
		*m: do_seteaza_culoare
		*p: ccamp
		*p: cidcamp		&& Numele campului care contine id-urile corespunzatoare coloanei "ccamp" ( pentru folosit la campurile cu lverticala = .T. ).
		*p: cnumecamp
		*p: csens
		*p: lgrupare		&& .T. daca se pot face grupari dupa acest camp.
		*p: lordine		&& .T. daca se poate ordona dupa acest camp.
		*p: lsuma		&& Acest camp va fi adaugat in proprietatea cColoaneSuma a containerului ct_selectie
		*p: lverticala		&& .T. daca valorile posibile pentru aceasta coloana vor aparea ca si coloane.
		*p: nid_container
		*p: nordine_grup
		*p: nordine_ordine
		*p: nselectat
		*p: rgbcrosstab		&& Culoarea folosita pentru coloana ale carei valori pot fi crosstabulate.
		*p: rgbnormal
		*p: rgbselectcrosstab		&& Culoarea coloanei dupa care se face crosstabularea.
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderWidth = 0
		ccamp = 
		cidcamp = .NULL.
		cnumecamp = 
		csens = 
		Height = 19
		lgrupare = .T.
		lordine = .T.
		lsuma = .F.
		lverticala = .F.
		Name = "ct_selectie_camp"
		nid_container = 0
		nordine_grup = 0
		nordine_ordine = 0
		nselectat = 0
		rgbcrosstab = 2,119,5
		rgbnormal = 0,0,0
		rgbselectcrosstab = 0,0,255
		Width = 108
		_memberdata = <VFPData>
			<memberdata name="lgrupare" type="property" display="lGrupare" favorites="True"/>
			<memberdata name="lordine" type="property" display="lOrdine" favorites="True"/>
			<memberdata name="lsuma" type="property" display="lSuma" favorites="True"/>
			<memberdata name="nid_container" type="property" display="nId_Container" favorites="True"/>
			<memberdata name="nordine_grup" type="property" display="nOrdine_Grup" favorites="True"/>
			<memberdata name="ccamp" type="Property" favorites="True"/>
			<memberdata name="cidcamp" type="Property" favorites="True"/>
			<memberdata name="cnumecamp" type="Property" favorites="True"/>
		</VFPData>
	*</PropValue>

	ADD OBJECT 'ck_camp' AS _checkbox WITH ;
		Alignment = 0, ;
		Caption = "Camp", ;
		Left = 9, ;
		Name = "ck_camp", ;
		Top = 1
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />
	
	PROCEDURE actualizeaza_container
		Lparameters llVizibil
		This.Visible=llVizibil
		This.ck_camp.FontBold = .F.
		This.ck_camp.Value = 0
		This.ngrupat = 0
	ENDPROC

	PROCEDURE do_seteaza_culoare
		Lparameters tnTip
		*!*	tnTip = 1 - rgbnormal
		*!*			2 - rgbcrosstab
		Local lcCuloare
		Store [] To lcCuloare
		If tnTip = 1
			lcCuloare = [Rgb(] + This.rgbnormal + [)]
			This.lverticala = .F.
		Else
			lcCuloare = [Rgb(] + This.rgbcrosstab + [)]
		Endif
		This.ck_camp.ForeColor = &lcCuloare
	ENDPROC

	PROCEDURE Init
		This.ck_camp.Caption = This.cnumecamp
		This.do_seteaza_culoare(Iif(Isnull(This.cidcamp),1,2))
	ENDPROC

	PROCEDURE ck_camp.Click
		This.ProgrammaticChange()
	ENDPROC

	PROCEDURE ck_camp.ProgrammaticChange
		This.Parent.nselectat = This.Value
		If This.Value = 1
			This.FontBold=.T.
			This.Parent.Parent.do_adauga(This.Parent.ccamp, This.Parent.cnumecamp, This.Parent.lgrupare, This.Parent.lordine, This.Parent.lSuma, This.Parent.cidcamp)
		Else
			This.FontBold = .F.
		&&	modificare crosstabulare
		*!*		lcCuloare = [Rgb(] + Iif(Isnull(This.Parent.cidcamp),This.Parent.rgbnormal,This.Parent.rgbcrosstab) + [)]
			lcCuloare = [Rgb(] + Iif((This.Parent.lsuma And This.Parent.Parent.lcrosstabulare) ;
					or !Isnull(This.Parent.cidcamp),This.Parent.rgbcrosstab,This.Parent.rgbnormal) + [)]
			This.ForeColor = &lcCuloare
			This.Parent.lverticala = .F.
		&&	modificare crosstabulare	^
			This.Parent.Parent.do_sterge(This.Parent.ccamp, This.Parent.cnumecamp, This.Parent.lSuma)
		Endif
	ENDPROC

	PROCEDURE ck_camp.RightClick
		&&	modificare crosstabulare
		If This.Value = 1
			If !Isnull(This.Parent.cidcamp)
				This.Parent.lverticala = This.Parent.Parent.do_crosstabulare(This.Parent.ccamp,This.Parent.lverticala)
			Endif
			If This.Parent.lsuma And This.Parent.Parent.lcrosstabulare
				This.Parent.lverticala = !This.Parent.lverticala
			Endif
			If This.Parent.lverticala
				lcCuloare = [Rgb(] + This.Parent.rgbselectcrosstab + [)]
			Else
				lcCuloare = [Rgb(] + Iif((This.Parent.lsuma And This.Parent.Parent.lcrosstabulare) ;
					or !Isnull(This.Parent.cidcamp),This.Parent.rgbcrosstab,This.Parent.rgbnormal) + [)]
			Endif
			This.ForeColor = &lcCuloare
		Endif
		&&	modificare crosstabulare	^
		
	ENDPROC

ENDDEFINE

DEFINE CLASS ct_selectie_sql AS _container OF "_baza.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="edtSelectie" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdParametri" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_coloane" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_actualizeaza_culori_sume
		*m: do_adauga
		*m: do_compune_ordine_selectie
		*m: do_crosstabulare
		*m: do_instructiune_sql
		*m: do_modifica
		*m: do_reset
		*m: do_sterge
		*m: do_verifica_verticala
		*m: get_coloane_crosstabulare
		*m: get_coloane_grupare
		*m: get_coloane_ordonare
		*m: get_coloane_selectie
		*p: cclasa		&& Clasa folosita pentru checkbox-urile din selectii.
		*p: ccoloanesuma		&& Numele coloanelor care sunt agregate.
		*p: clistacoloaneordine		&& Lista delimitata prin virgula ce contine pozitiile din ccoloanesuma pentru care se vor adauga containere la ordonare.
		*p: cnumecoloanesuma
		*p: cnumetabela		&& Numele tabelei/view-ului din care se face selectia.
		*p: cordine
		*p: csql
		*p: lcrosstabulare		&& .T. daca a fost selectata o coloana pentru crosstabulare
		*p: ltitlucoloanesuma		&& Daca numele coloanelor selectate se face dupa valoare din cNumeColoaneSuma
		*p: nelemente		&& Numarul de elemente din this.aselectie
		*a: aselectie[30,6]
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	*<PropValue>
		Anchor = 15
		cclasa = ct_selectie_camp
		ccoloanesuma = 
		clistacoloaneordine = 
		cnumecoloanesuma = 
		cnumetabela = 
		cordine = 
		csql = 
		Height = 364
		lcrosstabulare = .F.
		ltitlucoloanesuma = .F.
		Name = "ct_selectie_sql"
		nelemente = 0
		ToolTipText = ' Pentru detalii despre generarea rapoartelor, apasati butonul "?".'
		Width = 332
		_memberdata = <VFPData>
			<memberdata name="ltitlucoloanesuma" type="Property" favorites="True"/>
			<memberdata name="cnumetabela" type="Property" favorites="True"/>
		</VFPData>
	*</PropValue>

	ADD OBJECT 'cmdParametri' AS _commandbutton WITH ;
		Caption = "Optiuni", ;
		Height = 22, ;
		Left = 51, ;
		Name = "cmdParametri", ;
		SpecialEffect = 0, ;
		Top = 4, ;
		Width = 60
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'edtSelectie' AS _editbox WITH ;
		Anchor = 15, ;
		Height = 325, ;
		Left = 12, ;
		Name = "edtSelectie", ;
		Top = 30, ;
		Width = 312
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="editbox" />

	ADD OBJECT 'lb_coloane' AS lb_simplu WITH ;
		Caption = "SQL", ;
		FontItalic = .T., ;
		Height = 17, ;
		Left = 16, ;
		Name = "lb_coloane", ;
		TabIndex = 9, ;
		Top = 8, ;
		Width = 26
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />
	
	PROCEDURE do_actualizeaza_culori_sume
		Local lnTip
		lnTip = Iif(This.lcrosstabulare,2,1)
		For i = 1 To This.Objects.Count
			If Upper(This.Objects[i].Class) = 'CT_SELECTIE_CAMP' And This.Objects[i].lsuma
				This.Objects[i].do_seteaza_culoare(lnTip)
			Endif
		Endfor
		
	ENDPROC

	PROCEDURE do_adauga
		Lparameters lcCamp, lcNumeCamp, llGrupare, llOrdine, llColoaneSuma, lcCampId
		*!*	LPARAMETERS toSelectieCamp
		
		*!*	LOCAL lcCamp, lcNumeCamp, llGrupare, llOrdine, llColoaneSuma
		*!*	WITH toSelectieCamp
		*!*		lcCamp = .ccamp
		*!*		lcNumeCamp = .cnumecamp
		*!*		llGrupare = .lgrupare
		*!*		llOrdine = .lordine
		*!*		llColoaneSuma = .lSuma
		*!*	ENDWITH
		
		If !llColoaneSuma
			This.nelemente = This.nelemente + 1
			Ains(This.aselectie,This.nelemente)
		
			This.aselectie[This.nelemente,1] = Upper(Alltrim(lcCamp))
			This.aselectie[this.nelemente,2] = 0
			This.aselectie[this.nelemente,3] = 0
			This.aselectie[this.nelemente,4] = 0
		&&	modificare crosstabulare
			This.aselectie[this.nelemente,5] = .F.
			This.aselectie[this.nelemente,6] = Upper(Alltrim(Nvl(lcCampId,lcCamp)))
		&&	campul dupa ale carui valori se face crosstabularea
		&&	modificare crosstabulare	^
			If llGrupare
				This.ct_grupare1.do_adauga_ct(Upper(Alltrim(lcCamp)),lcNumeCamp)
			Endif
			If llOrdine
				This.ct_ordonare1.do_adauga_ct(Upper(Alltrim(lcCamp)),lcNumeCamp)
			Endif
		
		Else
			This.ccoloanesuma = This.ccoloanesuma + "|" + lcCamp
			This.cnumecoloanesuma = This.cnumecoloanesuma + "|" + lcNumeCamp
		Endif
		
	ENDPROC

	PROTECTED PROCEDURE do_compune_ordine_selectie
		Lparameters taArraySelectie
		Local lcOrdine, lcSens
		lcOrdine = []
		Asort(taArraySelectie,3)
		For i = 1 To Alen(taArraySelectie,1)
			If !Empty(taArraySelectie[i,1]) And !Empty(Nvl(taArraySelectie[i,3],0))
				If Empty(taArraySelectie[i,4]) Or (taArraySelectie[i,4] = 1)
					lcSens = []
				Else
					lcSens = [ DESC]
				Endif
				lcOrdine = lcOrdine + [,] + taArraySelectie[i,1] + lcSens
			Endif
		Endfor
		This.cOrdine = lcOrdine
	ENDPROC

	PROCEDURE do_crosstabulare
		&&	modificare crosstabulare
		Lparameters lcCamp, llCrosstabulare
		lnPozitie=Ascan(This.aselectie,Upper(Alltrim(lcCamp)),1,Alen(This.aselectie,1),1,9)
		If !This.lcrosstabulare
			If lnPozitie > 0
				This.aselectie(lnPozitie,5) = .T.
				This.lcrosstabulare = .T.
				llReturn = .T.
			Else
				llReturn = .F.
			Endif
		Else
			If lnPozitie > 0
				If This.aselectie(lnPozitie,5)
					This.aselectie(lnPozitie,5) = .F.
					This.lcrosstabulare = .F.
				Endif
			Endif
			llReturn = .F.
		Endif
		Return llReturn
		&&	modificare crosstabulare	^
	ENDPROC

	PROCEDURE do_instructiune_sql
		Lparameters tcFiltru
		
		Local llReturn, i, lcText, lcValue, llEroare
		Local lcFiltru, lnParametri, lcParametruValoare, lcParametru, lcValoare, lnAtPos1, lnAtPos2
		
		llReturn = .F.
		
		* EXTRAGERE VALORI PARAMETRI DIN TCFILTRU
		* TNAN = 2010 AND TNLUNA = 9 AND SUCURSALA
		* AN AND S
		Create Cursor crsParametriValori (parametru C(100), valoare M)
		
		lcFiltru = Strtran(Upper(Alltrim(tcFiltru)), 'AND' , '|')
		lnParametri = Getwordcount(lcFiltru, '|')
		For i = 1 To lnParametri
			lcParametruValoare = Getwordnum(lcFiltru, i, '|')
			If !Empty(m.lcParametruValoare) && TNAN = 2010
				lcParametru = Upper(Alltrim(Getwordnum(m.lcParametruValoare, 1, '='))) && TNAN
				
				* Se pare ca parametri de tip C au UPPER(parametru) = 'valoare'
				* Scot UPPER() 
				lcParametru = STRTRAN(m.lcParametru, 'UPPER(', '')
				lcParametru = STRTRAN(m.lcParametru, ')', '')	
				
				Do Case
					* parametri cuvinte rezervate trebuie sa fie definiti cu tipul E
					* pe camp cautare id trebuie sa fie tot numele parametrului
					Case lcParametru = 'SUCURSALA' && sucursala curenta
						lcValoare = gcCondSucursala
					Case lcParametru = 'AN' && an curent
						lcValoare = ALLTRIM(STR(gnAn)) && Alltrim(Str(m.gnAn))
					Case lcParametru = 'LUNA' && luna curenta
						lcValoare = ALLTRIM(STR(gnLuna)) && Alltrim(Str(m.gnLuna))
					Otherwise
						lcValoare = Alltrim(Getwordnum(m.lcParametruValoare, 2, '=')) && 2010
						* Scot apostroafele din valorile de tip caracter ex: UPPER(tnZIuaCURENTA) = '04102010'
						IF INLIST(LEFT(m.lcValoare,1), ['], ["]) AND INLIST(RIGHT(m.lcValoare,1), ['], ["])
							lcValoare = SUBSTR(m.lcValoare, 2, LEN(m.lcValoare) - 2)
						ENDIF 	
				Endcase
		
				Insert Into crsParametriValori (parametru, valoare) Values (lcParametru, lcValoare)
			Endif
		Endfor
		
		* RAW SQL
		* select * from act where an = <%=TNAN%> and luna = <%=TNLUNA%>
		lcText = Alltrim(This.edtSelectie.Value)
		
		* FAC MERGE VALORI PARAMETRI IN RAW SQL
		llEroare = .F.
		Do While Atcc('<%=', lcText) > 0
			* Get the start and end position of the next expression
			lnAtPos1 = Atcc('<%=', lcText)
			lnAtPos2 = Atcc('%>', lcText)
		
			* Extract the next expression
			lcParametru  = Substr(m.lcText, lnAtPos1 + 3, lnAtPos2 - lnAtPos1 - 3)
			* Remove any cariage returns from the expression as they could be inserted by an HTML editor
			lcParametru  = Upper(Alltrim(Chrtran(m.lcParametru, Chr(13) + Chr(10), '')))
			
			lcValue = ""
			Select crsParametriValori
			Locate For parametru = lcParametru
			If Found()
				lcValue = valoare
			ELSE 
				AMESSAGEBOX('Nu este completata valoarea parametrului ' + lcParametru + '!',0+48, _screen.Caption)	
				llEroare = .T.
				EXIT 
			Endif
			* Stuff the result back instead of the original expression
			lcText  = Stuffc(lcText, lnAtPos1, lnAtPos2 - lnAtPos1 + 2, lcValue)
		Enddo
		IF !llEroare
			This.cSql = m.lcText
			llReturn = .T.
		ELSE 
			This.cSql = ""
			llReturn = .F.
		ENDIF 
			
		Return llReturn
		
	ENDPROC

	PROCEDURE do_modifica
		Lparameters tnColoana,tcCamp,tnValoare
		&&	tnColoana	:	2	-	ordine grupare
		&&					3	-	ordine la ordonare
		&&					4	-	sens la ordonare		=	1	-	ASC
		&&														2	-	DESC
		&&					5 	- 	cross-tabulare
		&&					6 	-	valoarea dupa care se face cross-tabularea
		lnPozitie=Ascan(This.aselectie,Upper(Alltrim(tcCamp)),1,30,1,9)
		If lnPozitie > 0
			This.aselectie[lnPozitie,tnColoana]=tnValoare
		Endif
		
	ENDPROC

	PROCEDURE do_reset
		THIS.edtSelectie.Value = ""
	ENDPROC

	PROCEDURE do_sterge
		LPARAMETERS lcCamp, lcNumeCamp, llColoaneSuma
		*!*	LPARAMETERS toSelectieCamp
		
		*!*	LOCAL lcCamp, lcNumeCamp
		*!*	WITH toSelectieCamp
		*!*		lcCamp = .ccamp
		*!*		lcNumeCamp = .cnumecamp
		*!*		llColoaneSuma = .lSuma
		*!*	ENDWITH 	
		
		&&	modificare crosstabulare
		*!*	lnPozitie=Ascan(This.aselectie,Upper(Alltrim(lcCamp)),1,30,1,9)
		lnPozitie=Ascan(This.aselectie,Upper(Alltrim(lcCamp)),1,Alen(This.aselectie,1),1,9)
		&&	modificare crosstabulare	^
		If lnPozitie > 0
			&&	modificare crosstabulare
			If This.aselectie[lnPozitie,5]
				This.lcrosstabulare = .F.
			Endif
			&&	modificare crosstabulare	^
			Adel(This.aselectie,lnPozitie)
			This.nelemente = This.nelemente - 1
		Endif
		This.ct_grupare1.do_sterge_ct(lcCamp)
		This.ct_ordonare1.do_sterge_ct(lcCamp)
		
		*!*	AMESSAGEBOX(this.ccoloanesuma)
		*!*	AMESSAGEBOX(this.cnumecoloanesuma)
		IF llColoaneSuma
			this.ccoloanesuma = STRTRAN(this.ccoloanesuma + [|], [|] + lcCamp + [|], [|])
			IF RIGHT(this.ccoloanesuma,1) = [|]
				this.ccoloanesuma = LEFT(this.ccoloanesuma, LEN(this.ccoloanesuma) - 1)
			ENDIF 	
		
			this.cnumecoloanesuma = STRTRAN(this.cnumecoloanesuma + [|], [|] + lcNumeCamp + [|], [|])
			IF RIGHT(this.cnumecoloanesuma,1) = [|]
				this.cnumecoloanesuma = LEFT(this.cnumecoloanesuma, LEN(this.cnumecoloanesuma) - 1)
			ENDIF 	
		ENDIF
		*!*	AMESSAGEBOX(this.ccoloanesuma)
		*!*	AMESSAGEBOX(this.cnumecoloanesuma)
		
	ENDPROC

	PROCEDURE do_verifica_verticala
		Lparameters lcCamp
		Local j
		llVerticala = .F.
		For j = 1 To This.Objects.Count
			If Upper(This.Objects[j].Class) = 'CT_SELECTIE_CAMP' And Upper(This.Objects[j].ccamp) = Upper(lcCamp)
				llVerticala = This.Objects[j].lverticala
				Exit
			Endif
		Endfor
		Release j
		Return llVerticala
	ENDPROC

	PROCEDURE get_coloane_crosstabulare
		Local lcCrossTabulare
		lcCrossTabulare = []
		For j = 1 To This.Objects.Count
			If Upper(This.Objects[j].Class) = [CT_SELECTIE_CAMP]
				If This.Objects[j].lverticala
					lcCrossTabulare = lcCrossTabulare + [,] + Strtran(Upper(This.Objects[j].Name),[CT_SELECTIE_])
				Endif
			Endif
		Endfor
		Return Substr(lcCrossTabulare,2)
	ENDPROC

	PROCEDURE get_coloane_grupare
		Local laArray,lcGrupare
		lcGrupare = []
		Dimension laArray[Alen(this.aselectie,1),Alen(this.aselectie,2)]
		Acopy(This.aselectie,laArray)
		For i = 1 To Alen(laArray,1)
			If Empty(laArray[i,2])
				laArray[i,2] = 0
			Endif
		Endfor
		Asort(laArray,2)
		For i = 1 To Alen(laArray,1)
			If !Empty(laArray[i,2])
				lcGrupare = lcGrupare + [,] + Alltrim(Str(Ascan(this.aselectie,laArray[i,1],1,Alen(this.aselectie,1),1,9)))
			Endif
		Endfor
		Return Substr(lcGrupare,2)
	ENDPROC

	PROCEDURE get_coloane_ordonare
		Local laArray,lcGrupare
		lcOrdonare = []
		Dimension laArray[Alen(this.aselectie,1),Alen(this.aselectie,2)]
		Acopy(This.aselectie,laArray)
		For i = 1 To Alen(laArray,1)
			If Empty(laArray[i,3])
				laArray[i,3] = 0
			Endif
		Endfor
		Asort(laArray,3)
		For i = 1 To Alen(laArray,1)
			If !Empty(laArray[i,3])
				lcOrdonare = lcOrdonare + [,] + Alltrim(Str(Ascan(this.aselectie,laArray[i,1],1,Alen(this.aselectie,1),1,9))) + Iif(Empty(laArray[i,4]) Or laArray[i,4] = 1,[],[ DESC])
			Endif
		Endfor
		Return Substr(lcOrdonare,2)
	ENDPROC

	PROCEDURE get_coloane_selectie
		Local lcSelectie
		lcSelectie = []
		*!*	For i = 1 To Alen(This.aselectie,1)
		*!*		If !Empty(This.aselectie[i,1])
		*!*			lcSelectie = lcSelectie + [,] + This.aselectie[i,1]
		*!*		Endif
		*!*	EndFor
		*!*	lcColoaneSuma = Substr(This.ccoloanesuma,2)
		*!*	For i = 1 To Getwordcount(lcColoaneSuma,[,])
		*!*		lcColoana = Upper(Getwordnum(lcColoaneSuma,i,[,]))
		*!*		For j = 1 To This.Objects.Count
		*!*			If Upper(This.Objects[j].Class) = [CT_SELECTIE_CAMP]
		*!*				If Upper(This.Objects[j].ccamp) = lcColoana
		*!*					lcSelectie = lcSelectie + [,] + Strtran(Upper(This.Objects[j].Name),[CT_SELECTIE_])
		*!*				Endif
		*!*			Endif
		*!*		Endfor
		*!*	Endfor
		For j = 1 To This.Objects.Count
			If Upper(This.Objects[j].Class) = [CT_SELECTIE_CAMP]
				If This.Objects[j].ck_camp.Value = 1
					lcSelectie = lcSelectie + [,] + Strtran(Upper(This.Objects[j].Name),[CT_SELECTIE_])
				Endif
			Endif
		Endfor
		Return Substr(lcSelectie,2)
		
	ENDPROC

	PROCEDURE Init
		*!*	la ccoloanesuma si cnumecoloanesuma am ca separator <<|>> si nu <<,>> pentru ca pot avea ca si coloana o expresie de forma :
		*!*	round(....,...) si atunci nu-mi ia corect coloana
		
		If !Empty(This.clistacoloaneordine)
		*!*	se adauga la ordine si prima coloana din coloanele de sume
			lcLista = Alltrim(Iif(Type('This.clistacoloaneordine')='C',This.clistacoloaneordine,Str(This.clistacoloaneordine)))
			This.clistacoloaneordine=lcLista
			For i = 1 To Getwordcount(lcLista,[,])
				lnPozitie=Val(Getwordnum(lcLista,i,[,]))
				lcNume=Proper(Getwordnum(This.ccoloanesuma,lnPozitie,[|]))
				If !Empty(This.cnumecoloanesuma)
					lcNumeCamp=Proper(Getwordnum(This.cnumecoloanesuma,lnPozitie,[|]))
				Else
					lcNumeCamp = lcNume
				Endif
				This.do_adauga(lcNume,lcNumeCamp,.F.,.T.,.F.,.NULL.)
			Endfor
		Endif
		Bindevent(This,"lcrosstabulare",This,"do_actualizeaza_culori_sume",1)
		
	ENDPROC

	PROCEDURE cmdParametri.Click
		Local lcSql, lnIdRaport
		lcSql = This.Parent.edtSelectie.Value
		lnIdRaport = This.Parent.Parent.nIdRaport
		
		*** definesc parametri (ex: tnAn, tnLuna) si salvez filtrul in rapoarte_filtre
		lnButon = parametri_rapoarte_sql(m.lcSql, m.lnIdRaport) && In orapoarte_dinamice.prg
		IF lnButon = 1
			*** incarc filtrele pentru completarea criteriilor
			This.Parent.Parent.do_reset_filtru() && frm_date_rapoarte_gen_base.do_incarca_filtru()
		ENDIF 
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_date_rapoarte AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="But_salveaza1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_clb_raport" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_clb_raport.But_sterge1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Clb_data_referinta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Clb_perioada" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_opt_agent" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_opt_masina" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_opt_delegat" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_opt_client" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_selectie1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_selectie1.Ct_selectie_nract" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_selectie1.Ct_selectie_datascad" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_selectie1.Ct_selectie_nume_agent" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_selectie1.Ct_selectie_nume_delegat" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_selectie1.Ct_selectie_nume_client" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_selectie1.Ct_selectie_dataact" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_listare1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_adauga_filtru
		*m: do_cauta_agent
		*m: do_cauta_client
		*m: do_cauta_delegat
		*m: do_cauta_masina
	*</DefinedPropArrayMethod>

	*<PropValue>
		DoCreate = .T.
		Height = 470
		Name = "frm_date_rapoarte"
		Width = 696
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 696
		_shape2.Height = 29
		_shape2.Left = 600
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 96
		Lb_titlu_alb_b121.Caption = "CRITERII DE SELECTIE"
		Lb_titlu_alb_b121.FontBold = .T.
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 22
		BUT_TERMIN1.Left = 664
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 18
		BUT_TERMIN1.Top = 1
		GRIDSORT1.Left = 480
		GRIDSORT1.Name = "GRIDSORT1"
		GRIDSORT1.Top = 36
	*</PropValue>

	ADD OBJECT 'But_listare1' AS but_listare WITH ;
		Left = 634, ;
		Name = "But_listare1", ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_salveaza1' AS but_salveaza WITH ;
		Left = 603, ;
		Name = "But_salveaza1", ;
		TabIndex = 20, ;
		Top = 1, ;
		Visible = .F.
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Clb_data_referinta' AS clb_tx_simplu WITH ;
		Left = 383, ;
		Name = "Clb_data_referinta", ;
		TabIndex = 3, ;
		Top = 100, ;
		Text_simplu1.ControlSource = "poListare.data_referinta", ;
		Text_simplu1.Height = 23, ;
		Text_simplu1.Left = 126, ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Top = 3, ;
		Text_simplu1.Width = 159, ;
		Lb_simplu1.Caption = "Data de referinta", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Clb_perioada' AS clb_n1n2_simplu WITH ;
		Left = 383, ;
		Name = "Clb_perioada", ;
		TabIndex = 2, ;
		Top = 72, ;
		tx_n1.ControlSource = "poListare.datai", ;
		tx_n1.Left = 127, ;
		tx_n1.Name = "tx_n1", ;
		tx_n1.Top = 2, ;
		Lb_simplu1.Caption = "Perioada", ;
		Lb_simplu1.Name = "Lb_simplu1", ;
		tx_n2.ControlSource = "poListare.dataf", ;
		tx_n2.Name = "tx_n2"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_clb_raport' AS ct_clb_cautare WITH ;
		Height = 31, ;
		Left = 23, ;
		Name = "Ct_clb_raport", ;
		TabIndex = 21, ;
		Top = 36, ;
		Visible = .F., ;
		Width = 396, ;
		img_cautare.Height = 25, ;
		img_cautare.Left = 321, ;
		img_cautare.Name = "img_cautare", ;
		img_cautare.Top = 3, ;
		img_cautare.Width = 30, ;
		clb_tx_cautare.Lb_simplu1.Caption = "Raport", ;
		clb_tx_cautare.Lb_simplu1.Name = "Lb_simplu1", ;
		clb_tx_cautare.Name = "clb_tx_cautare", ;
		clb_tx_cautare.TabIndex = 1, ;
		clb_tx_cautare.Text_simplu1.Height = 23, ;
		clb_tx_cautare.Text_simplu1.Left = 71, ;
		clb_tx_cautare.Text_simplu1.Name = "Text_simplu1", ;
		clb_tx_cautare.Text_simplu1.Top = 3, ;
		clb_tx_cautare.Text_simplu1.Width = 239
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_clb_raport.But_sterge1' AS but_sterge WITH ;
		Height = 27, ;
		Left = 361, ;
		Name = "But_sterge1", ;
		TabIndex = 2, ;
		Top = 1, ;
		Width = 30
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ct_opt_agent' AS ct_opt_cautare WITH ;
		cprocedura = thisform.do_cauta_agent, ;
		cvar_afisata = poListare.nume_agent, ;
		Left = 383, ;
		Name = "Ct_opt_agent", ;
		TabIndex = 5, ;
		Top = 198, ;
		tx_cautare.Name = "tx_cautare", ;
		opt_cautare.Name = "opt_cautare", ;
		opt_cautare.OPTION1.Left = 5, ;
		opt_cautare.OPTION1.Name = "OPTION1", ;
		opt_cautare.OPTION1.Top = 5, ;
		opt_cautare.OPTION2.Left = 5, ;
		opt_cautare.OPTION2.Name = "OPTION2", ;
		opt_cautare.OPTION2.Top = 24, ;
		lb_explicatie.Caption = "Agent", ;
		lb_explicatie.Name = "lb_explicatie"
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_opt_client' AS ct_opt_cautare WITH ;
		cprocedura = thisform.do_cauta_client, ;
		cvar_afisata = poListare.nume_client, ;
		Left = 383, ;
		Name = "Ct_opt_client", ;
		TabIndex = 4, ;
		Top = 128, ;
		tx_cautare.Name = "tx_cautare", ;
		opt_cautare.Name = "opt_cautare", ;
		opt_cautare.OPTION1.Left = 5, ;
		opt_cautare.OPTION1.Name = "OPTION1", ;
		opt_cautare.OPTION1.Top = 5, ;
		opt_cautare.OPTION2.Left = 5, ;
		opt_cautare.OPTION2.Name = "OPTION2", ;
		opt_cautare.OPTION2.Top = 24, ;
		lb_explicatie.Caption = "Client", ;
		lb_explicatie.Name = "lb_explicatie"
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_opt_delegat' AS ct_opt_cautare WITH ;
		cprocedura = thisform.do_cauta_delegat, ;
		cvar_afisata = poListare.nume_delegat, ;
		Left = 383, ;
		Name = "Ct_opt_delegat", ;
		TabIndex = 6, ;
		Top = 268, ;
		tx_cautare.Name = "tx_cautare", ;
		opt_cautare.Name = "opt_cautare", ;
		opt_cautare.OPTION1.Left = 5, ;
		opt_cautare.OPTION1.Name = "OPTION1", ;
		opt_cautare.OPTION1.Top = 5, ;
		opt_cautare.OPTION2.Left = 5, ;
		opt_cautare.OPTION2.Name = "OPTION2", ;
		opt_cautare.OPTION2.Top = 24, ;
		lb_explicatie.Caption = "Delegat", ;
		lb_explicatie.Name = "lb_explicatie"
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_opt_masina' AS ct_opt_cautare WITH ;
		cprocedura = thisform.do_cauta_masina, ;
		cvar_afisata = poListare.nrinmat, ;
		Left = 383, ;
		Name = "Ct_opt_masina", ;
		TabIndex = 7, ;
		Top = 338, ;
		tx_cautare.Name = "tx_cautare", ;
		opt_cautare.Name = "opt_cautare", ;
		opt_cautare.OPTION1.Left = 5, ;
		opt_cautare.OPTION1.Name = "OPTION1", ;
		opt_cautare.OPTION1.Top = 5, ;
		opt_cautare.OPTION2.Left = 5, ;
		opt_cautare.OPTION2.Name = "OPTION2", ;
		opt_cautare.OPTION2.Top = 24, ;
		lb_explicatie.Caption = "Masina", ;
		lb_explicatie.Name = "lb_explicatie"
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_selectie1' AS ct_selectie WITH ;
		ccoloanesuma = facturat|incasat, ;
		cnumetabela = fact_vrap_fact_incasari, ;
		Left = 24, ;
		Name = "Ct_selectie1", ;
		Top = 72, ;
		Ct_grupare1.lblAtentie.Name = "lblAtentie", ;
		Ct_grupare1.lb_grupare.Name = "lb_grupare", ;
		Ct_grupare1.Name = "Ct_grupare1", ;
		Ct_ordonare1.lb_ordonare.Name = "lb_ordonare", ;
		Ct_ordonare1.Name = "Ct_ordonare1", ;
		lb_coloane.Name = "lb_coloane"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_selectie1.Ct_selectie_dataact' AS ct_selectie_camp WITH ;
		ccamp = dataact, ;
		cnumecamp = Data factura, ;
		Left = 17, ;
		Name = "Ct_selectie_dataact", ;
		nid_container = 2, ;
		TabIndex = 37, ;
		Top = 36, ;
		ck_camp.Alignment = 0, ;
		ck_camp.Name = "ck_camp"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_selectie1.Ct_selectie_datascad' AS ct_selectie_camp WITH ;
		ccamp = datascad, ;
		cnumecamp = Data scadenta, ;
		Left = 17, ;
		Name = "Ct_selectie_datascad", ;
		nid_container = 3, ;
		TabIndex = 31, ;
		Top = 51, ;
		ck_camp.Alignment = 0, ;
		ck_camp.Name = "ck_camp"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_selectie1.Ct_selectie_nract' AS ct_selectie_camp WITH ;
		ccamp = nract, ;
		cnumecamp = Nr. factura, ;
		Left = 17, ;
		Name = "Ct_selectie_nract", ;
		nid_container = 1, ;
		TabIndex = 30, ;
		Top = 22, ;
		ck_camp.Alignment = 0, ;
		ck_camp.Name = "ck_camp"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_selectie1.Ct_selectie_nume_agent' AS ct_selectie_camp WITH ;
		ccamp = nume_agent, ;
		cnumecamp = Agent, ;
		Left = 180, ;
		Name = "Ct_selectie_nume_agent", ;
		nid_container = 5, ;
		TabIndex = 33, ;
		Top = 22, ;
		ck_camp.Alignment = 0, ;
		ck_camp.Name = "ck_camp"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_selectie1.Ct_selectie_nume_client' AS ct_selectie_camp WITH ;
		ccamp = nume_client, ;
		cnumecamp = Client, ;
		Left = 17, ;
		Name = "Ct_selectie_nume_client", ;
		nid_container = 4, ;
		TabIndex = 36, ;
		Top = 67, ;
		ck_camp.Alignment = 0, ;
		ck_camp.Name = "ck_camp"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_selectie1.Ct_selectie_nume_delegat' AS ct_selectie_camp WITH ;
		ccamp = nume_delegat, ;
		cnumecamp = Delegat, ;
		Left = 180, ;
		Name = "Ct_selectie_nume_delegat", ;
		TabIndex = 34, ;
		Top = 36, ;
		ck_camp.Alignment = 0, ;
		ck_camp.Name = "ck_camp"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />
	
	PROCEDURE do_adauga_filtru
		Lparameters lcSql
		lcFiltru = [WHERE DATAACT BETWEEN ?poListare.datai AND ?poListare.dataf]
		If !Empty(Nvl(poListare.nume_client,[]))
			lcFiltru = lcFiltru + [ AND nume_client = ?poListare.nume_client]
		Endif
		
		If !Empty(Nvl(poListare.nume_agent,[]))
			lcFiltru = lcFiltru + [ AND nume_agent = ?poListare.nume_agent]
		Endif
		
		If !Empty(Nvl(poListare.nume_delegat,[]))
			lcFiltru = lcFiltru + [ AND nume_delegat = ?poListare.nume_delegat]
		Endif
		
		If !Empty(Nvl(poListare.nrinmat,[]))
			lcFiltru = lcFiltru + [ AND nrinmat = ?poListare.nrinmat]
		Endif
		poListare.csql = Strtran(lcSql,[WHERE 1=2],lcFiltru)
		
	ENDPROC

	PROCEDURE do_cauta_agent
		Private pnIdPart,pcNumePart
		lcTitlu=[ALEGETI AGENTUL]
		pnIdPart=0
		pcNumePart=[]
		
		If caut_partener_dupa_tip(gnIdTipAgenti,lcTitlu,@pnIdPart,@pcNumePart)
			poListare.id_agent = pnIdPart
			poListare.nume_agent = Alltrim(pcNumePart)
			Thisform.ct_opt_agent.Refresh()
			Thisform.ct_opt_delegat.SetFocus()
		Else
			If Empty(Nvl(poListare.nume_agent,[]))
				Thisform.ct_opt_agent.opt_cautare.Value=1
			Endif
			Thisform.ct_opt_agent.SetFocus()
		Endif
		
	ENDPROC

	PROCEDURE do_cauta_client
		Private pnIdPart,pcNumePart
		Store 0 To pnIdPart
		Store "" To pcNumePart
		If cauta_client(@pnIdPart,@pcNumePart)
			poListare.id_client = pnIdPart
			poListare.nume_client = pcNumePart
		
			Thisform.ct_opt_client.Refresh()
			Thisform.ct_opt_agent.SetFocus()
		Else
			If Empty(Nvl(poListare.nume_client,[]))
				Thisform.ct_opt_client.opt_cautare.Value=1
			Endif
			Thisform.ct_opt_client.SetFocus()
		Endif
		
	ENDPROC

	PROCEDURE do_cauta_delegat
		Local loCauta
		loCauta=caut_delegati()
		If !Empty(loCauta.id_responsabil)
			poListare.id_delegat = loCauta.id_responsabil
			poListare.nume_delegat = Alltrim(loCauta.nume)
			Thisform.ct_opt_delegat.Refresh()
			Thisform.ct_opt_masina.SetFocus()
		Else
			If Empty(Nvl(poListare.nume_delegat,[]))
				Thisform.ct_opt_delegat.opt_cautare.Value = 1
			Endif
			Thisform.ct_opt_delegat.SetFocus()
		Endif
		
	ENDPROC

	PROCEDURE do_cauta_masina
		locauta=caut_masina_gs()
		If !Empty(locauta.id_masina)
			poListare.nrinmat = Alltrim(locauta.nrinmat)
			poListare.id_masina = locauta.id_masina
		
			Thisform.ct_opt_masina.Refresh()
		Else
			If Empty(Nvl(poListare.nrinmat,[]))
				Thisform.ct_opt_masina.opt_cautare.Value = 1
			Endif
			Thisform.ct_opt_masina.SetFocus()
		Endif
		
	ENDPROC

	PROCEDURE do_listare
		lccontrol = Upper(This.ActiveControl.BaseClass )
		If Inlist(lccontrol,"TEXTBOX","EDITBOX","COMBOBOX")
			lcval=This.ActiveControl.ControlSource
			&lcval=Thisform.ActiveControl.Value
		Endif
		
		Do Case
		Case Empty(Nvl(poListare.datai,{}))
			amessagebox("Nu ati completat data initiala!",0+48,"Atentie")
			Thisform.clb_perioada.tx_n1.SetFocus()
			Return
		Case Empty(Nvl(poListare.dataf,{}))
			amessagebox("Nu ati completat data finala!",0+48,"Atentie")
			Thisform.clb_perioada.tx_n2.SetFocus()
			Return
		Case Empty(Nvl(poListare.data_referinta,{}))
			amessagebox("Nu ati completat data de referinta!",0+48,"Atentie")
			Thisform.clb_data_referinta.SetFocus()
			Return
		Otherwise
			With This.ct_selectie1
				.do_instructiune_sql()
				lcSql = .csql
			Endwith
			If Empty(lcSql)
				amessagebox("Nu ati ales coloane pentru selectie!",0+48,"Atentie")
				Thisform.ct_selectie1.SetFocus()
				Return
			Else
				This.do_adauga_filtru(lcSql)
			Endif
		Endcase
		
		If Used('crsraport')
			Use In crsraport
		Endif
		STRTOFILE(poListare.cSql,[c:\sql.txt])
		lnSucces = goExecutor.oExecute(poListare.csql,'crsraport')
		If lnSucces < 0
			amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
		Endif
		
		pcDataora = get_ora(2)
		If Reccount('crsraport')<>0
			Thisform.AlwaysOnTop = .F.
			Select crsraport
			Report Form raport_facturat To Printer Prompt Preview
			Thisform.AlwaysOnTop = .T.
		Else
			amessagebox("Nu exista rezultate pentru listare!",0+48,"Atentie")
		Endif
		
		If Used('crsraport')
			Use In crsraport
		Endif
	ENDPROC

	PROCEDURE Clb_perioada.tx_n1.Valid
		*!*
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_date_rapoarte_gen AS frm_date_rapoarte_gen_base OF "orapoarte.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Ct_selectie1" UniqueID="" Timestamp="" />

	*<PropValue>
		DoCreate = .T.
		Name = "frm_date_rapoarte_gen"
		_shape1.Name = "_shape1"
		_shape2.Name = "_shape2"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Gridsort1.Name = "Gridsort1"
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		But_listare1.Name = "But_listare1"
		But_excel1.Name = "But_excel1"
		But_help1.Name = "But_help1"
		But_cautare1.Name = "But_cautare1"
		But_sterge1.Name = "But_sterge1"
		ed_explicatii_filtru.Name = "ed_explicatii_filtru"
		ed_explicatii_filtru.Top = 63
		But_salveaza1.Name = "But_salveaza1"
		But_nou1.Name = "But_nou1"
		But_reset2.Name = "But_reset2"
		But_start_criterii1.Name = "But_start_criterii1"
		lb_raport_predefinit.Name = "lb_raport_predefinit"
	*</PropValue>

	ADD OBJECT 'Ct_selectie1' AS ct_selectie WITH ;
		Height = 391, ;
		Left = 7, ;
		Name = "Ct_selectie1", ;
		TabIndex = 11, ;
		Top = 36, ;
		Width = 332, ;
		ZOrderSet = 11, ;
		Ct_grupare1.lblAtentie.Name = "lblAtentie", ;
		Ct_grupare1.lb_grupare.Name = "lb_grupare", ;
		Ct_grupare1.Left = 5, ;
		Ct_grupare1.Name = "Ct_grupare1", ;
		Ct_grupare1.Top = 252, ;
		Ct_grupare1._scrollcontainer1.But_jos1.Name = "But_jos1", ;
		Ct_grupare1._scrollcontainer1.But_sus1.Name = "But_sus1", ;
		Ct_grupare1._scrollcontainer1.Name = "_scrollcontainer1", ;
		Ct_ordonare1.lb_ordonare.Name = "lb_ordonare", ;
		Ct_ordonare1.Left = 5, ;
		Ct_ordonare1.Name = "Ct_ordonare1", ;
		Ct_ordonare1.Top = 120, ;
		Ct_ordonare1._scrollcontainer1.But_jos1.Name = "But_jos1", ;
		Ct_ordonare1._scrollcontainer1.But_sus1.Name = "But_sus1", ;
		Ct_ordonare1._scrollcontainer1.Name = "_scrollcontainer1", ;
		lb_coloane.Name = "lb_coloane"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

ENDDEFINE

DEFINE CLASS frm_date_rapoarte_gen_base AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="But_listare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_excel1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_help1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_cautare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_sterge1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_nou1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ed_explicatii_filtru" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_salveaza1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_reset2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_raport_predefinit" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_start_criterii1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: creeaza_raport
		*m: do_adauga_filtru
		*m: do_cauta_raport
		*m: do_incarca_filtru
		*m: do_incarca_raport
		*m: do_modificabil
		*m: do_reset_filtru
		*p: cdenumire		&& Denumirea raportului.
		*p: cfiltruperioada		&& Campurile / campul dupa care se filtreaza perioada ( trebuie sa fie de forma an * 12 + luna ).
		*p: cnume_ct_selectie		&& Numele containerului bazat pe ct_selectie.
		*p: craport		&& Numele raportului pentru listare
		*p: craportinitial		&& Numele raportului folosit pentru listare.
		*p: ctitluraport
		*p: ctitluraportinitial		&& Titlul initial al raportului.
		*p: filtru_cript
		*p: ladaugalunacurenta		&& IN CAZUL IN CARE EXISTA PERIOADA IN FILTRU : .T. - daca adauga luna curenta in filtru la incarcarea unui raport ( daca nu exista deja o perioada salvata in filtru ), la resetare si la raport nou.
		*p: ldrepturi		&& Se acceseaza doar rapoartele pe care are drepturi utilizatorul
		*p: lfiltruperioada		&& .T. - este adaugat filtrul pe perioada; campul este specificat in cFiltruPerioada
		*p: lreadonly		&& Daca campurile de selectie, ordonare, grupare sunt blocate (pentru selectii predefinite)
		*p: nidformularraport		&& Id-ul formularului.
		*p: nidraport		&& Id-ul raportului incarcat.
		*p: nidraportinitial
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 3
		cdenumire = 
		cfiltruperioada = an*12+luna
		cnume_ct_selectie = ct_selectie1
		craport = 
		craportinitial = 
		ctitluraport = 
		ctitluraportinitial = Rapoarte generate dinamic
		DoCreate = .T.
		filtru_cript = 
		Height = 440
		lactiv4 = .T.
		ladaugalunacurenta = .T.
		ldrepturi = .F.
		lfiltruperioada = .T.
		lreadonly = .F.
		Name = "frm_date_rapoarte_gen_base"
		nidformularraport = .NULL.
		nidraport = .NULL.
		nidraportinitial = .NULL.
		Width = 696
		_memberdata = <VFPData>
			<memberdata name="craport" type="property" display="cRaport" favorites="True"/>
			<memberdata name="lreadonly" type="property" display="lReadOnly" favorites="True"/>
			<memberdata name="ctitluraport" type="Property" favorites="True"/>
			<memberdata name="do_adauga_filtru" type="Method" favorites="True"/>
			<memberdata name="do_cauta" type="Method" favorites="True"/>
			<memberdata name="do_excel" type="Method" favorites="True"/>
			<memberdata name="do_listare" type="Method" favorites="True"/>
			<memberdata name="ladauga<VFPData><memberdata name="craport" type="property" display="cRaport" favorites="True"/>
			<memberdata name="craport" type="property" display="cRaport" favorites="True"/>
		</VFPData>
		_shape1.Anchor = 10
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 696
		_shape1.ZOrderSet = 0
		_shape2.Height = 29
		_shape2.Left = 455
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 240
		_shape2.ZOrderSet = 1
		Lb_titlu_alb_b121.Caption = "Thisform.ctitluraportinitial"
		Lb_titlu_alb_b121.FontBold = .T.
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 10
		Lb_titlu_alb_b121.ZOrderSet = 2
		BUT_TERMIN1.Anchor = 9
		BUT_TERMIN1.Left = 666
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 8
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 4
		GRIDSORT1.Left = 480
		GRIDSORT1.Name = "GRIDSORT1"
		GRIDSORT1.Top = 36
	*</PropValue>

	ADD OBJECT 'But_cautare1' AS but_cautare WITH ;
		Anchor = 9, ;
		caction = do_cauta_raport, ;
		Height = 27, ;
		Left = 513, ;
		Name = "But_cautare1", ;
		TabIndex = 3, ;
		Top = 1, ;
		Width = 30
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_excel1' AS but_excel WITH ;
		Anchor = 9, ;
		Left = 605, ;
		Name = "But_excel1", ;
		TabIndex = 6, ;
		Top = 1, ;
		ZOrderSet = 6
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_help1' AS but_help WITH ;
		Anchor = 9, ;
		Left = 454, ;
		Name = "But_help1", ;
		TabIndex = 1, ;
		Top = 1, ;
		ZOrderSet = 7
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_listare1' AS but_listare WITH ;
		Anchor = 9, ;
		Left = 636, ;
		lvizibil = .F., ;
		Name = "But_listare1", ;
		TabIndex = 7, ;
		Top = 1, ;
		ZOrderSet = 5
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_nou1' AS but_nou WITH ;
		Anchor = 9, ;
		Left = 483, ;
		Name = "But_nou1", ;
		TabIndex = 2, ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_reset2' AS but_reset WITH ;
		Anchor = 9, ;
		caction = do_reset_filtru, ;
		Left = 624, ;
		Name = "But_reset2", ;
		TabIndex = 9, ;
		ToolTipText = "Reseteaza filtru", ;
		Top = 32, ;
		ZOrderSet = 14
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_salveaza1' AS but_salveaza WITH ;
		Anchor = 9, ;
		Height = 27, ;
		Left = 543, ;
		Name = "But_salveaza1", ;
		TabIndex = 4, ;
		ToolTipText = "Salvare raport", ;
		Top = 1, ;
		Width = 30, ;
		ZOrderSet = 13
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_start_criterii1' AS but_start_criterii WITH ;
		Anchor = 9, ;
		lcautare = .F., ;
		Left = 655, ;
		Name = "But_start_criterii1", ;
		TabIndex = 13, ;
		Top = 32, ;
		ZOrderSet = 15
		*< END OBJECT: ClassLib="ocriterii.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_sterge1' AS but_sterge WITH ;
		Anchor = 9, ;
		Left = 574, ;
		lvizibil = .F., ;
		Name = "But_sterge1", ;
		TabIndex = 5, ;
		ToolTipText = "Stergere raport (CTRL+D)", ;
		Top = 1, ;
		ZOrderSet = 10
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'ed_explicatii_filtru' AS _editbox WITH ;
		Anchor = 13, ;
		ControlSource = "Thisform.filtru_pretty_ro", ;
		Height = 364, ;
		Left = 360, ;
		Name = "ed_explicatii_filtru", ;
		ReadOnly = .T., ;
		TabIndex = 12, ;
		Top = 63, ;
		Width = 324, ;
		ZOrderSet = 12
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="editbox" />

	ADD OBJECT 'lb_raport_predefinit' AS _lbbase WITH ;
		Caption = "RAPORT PREDEFINIT", ;
		FontBold = .T., ;
		FontSize = 25, ;
		Height = 228, ;
		Left = 12, ;
		Name = "lb_raport_predefinit", ;
		Rotation = 35, ;
		TabIndex = 14, ;
		Top = 200, ;
		Visible = .F., ;
		Width = 300, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_lb_base.vcx" BaseClass="label" />
	
	PROCEDURE creeaza_raport
		If Used('crsraport')
			Use In crsraport
		Endif
		
		This.do_cauta()
		
		If Used('crsRaport') And Reccount('crsraport')<>0
			If Used('crsexport')
				Use In crsexport
			ENDIF
			*!* 23.09.2010
			IF TYPE('crsRaport.gid') <> 'U'
				Dimension aColoane[1]
				lcSelect = [SELECT Iif(gid<>0,'TOTAL',Space(5)) As explicatie]
				Afields(aColoane,'crsraport')
				For i = 1 To Alen(aColoane,1)
					If Upper(Alltrim(aColoane[i,1])) <> 'GID'
						lcNumeColoana =  Upper(Alltrim(aColoane[i,1]))
						lcSelect = lcSelect + [,] + Iif(aColoane[i,2] = 'T', [TTOD(] + lcNumeColoana + [) as ] + ;
							lcNumeColoana, lcNumeColoana)
					Endif
				Endfor
				lcSelect = lcSelect + [	From crsraport Into Cursor crsexport]
			ELSE
				lcSelect = [select * From crsraport Into Cursor crsexport]
			ENDIF 	
			*!* 23.09.2010 ^
			&lcSelect
		Endif
		If Used('crsRaport')
			Use In crsRaport
		Endif
		
	ENDPROC

	PROCEDURE do_adauga
		Thisform.do_reset()
		
	ENDPROC

	PROCEDURE do_adauga_filtru
	ENDPROC

	PROCEDURE do_cauta
		*!* 22.06.2010
		*!* marius.mutu
		*!* apelez do_instructiune_sql cu filtru
		*!* in do_instructiune_sql - trimit filtrul daca coloana de crostabulare face parte din filtru - sa arat atatea coloane cate valori sunt in filtru
		
		*!*	28.04.2011
		*!*	marius.atanasiu
		*!*	am adaugat gcCondSucursala in filtru, daca nu sunt pe firma mama
		
		Local llReturn,lcFiltruSucursala
		With Thisform.ct_selectie1
		*!* 22.06.2010
		*!*		If .do_instructiune_sql()
		 
			If .do_instructiune_sql(Thisform.filtru_pretty)
		*!* 22.06.2010 ^
				lcSql = .csql
				If Empty(lcSql)
					amessagebox("Nu ati ales coloane pentru selectie!",0+48,"Atentie")
					.SetFocus()
					llReturn = .F.
				Else
		*!*	28.04.2011
		*!*				lcSql = Strtran(lcSql,[WHERE 1=2],Iif(!Empty(Thisform.filtru_pretty),[WHERE ] + Thisform.filtru_pretty,[]))
					If Thisform.nIdformularraport = 2
						lcFiltruSucursala = []
					Else
						lcFiltruSucursala = Iif(glEMama,[],gcCondSucursala)
					Endif
					lcSql = Strtran(lcSql,[WHERE 1=2],Iif(!Empty(Thisform.filtru_pretty),[WHERE ] + Thisform.filtru_pretty + lcFiltruSucursala,;
						[] + SUBSTR(lcFiltruSucursala,5)))
		*!*	28.04.2011	^
					lnSucces = goExecutor.oExecute(lcSql,'crsraport')
					If lnSucces < 0
						amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
						llReturn = .F.
					Endif
				Endif
			Else
				llReturn = .F.
			Endif
		Endwith
		Return llReturn
	ENDPROC

	PROCEDURE do_cauta_raport
		Local loCauta
		loCauta = caut_raport(This.nidformularraport, this.lDrepturi)
		If gnButon = 1
			Thisform.nidraport = loCauta.id_raport
			Thisform.do_incarca_raport()
		Endif
		Release loCauta
	ENDPROC

	PROCEDURE do_excel
		Local lcFileName
		lcFileName = ""
		This.creeaza_raport()
		
		If Used('crsExport')
			lcFileName = strtranx(This.ctitluraport, "([^a-zA-Z0-9])", [_] )
			export_xls('crsexport', lcFileName)
			Use In crsExport
		Else
			amessagebox("Nu exista rezultate pentru export in Excel!",0+48,"Atentie")
		Endif
		
		
	ENDPROC

	PROCEDURE do_help
		*!* 23.09.2010
		*!* marius.mutu
		*!* raw sql nIdFormularRaport = 2
		
		Local lofrmhelprap
		lnIdFormular = this.nIdformularraport  
		IF EMPTY(NVL(m.lnIdFormular,0))
			m.lnIdFormular = 1
		ENDIF 
		lofrmhelprap = Createobject('frm_help_rapoarte', m.lnIdFormular)
		lofrmhelprap.Show(1)
		Release lofrmhelprap
	ENDPROC

	PROCEDURE do_incarca_filtru
		Local lcCursorFiltru
		IF EMPTY(NVL(Thisform.nidraport,0))
			RETURN
		ENDIF 
		lcCursorFiltru = [crsrapfiltru]
		If Used(lcCursorFiltru)
			Use In (lcCursorFiltru)
		ENDIF
		
		lcSql = [select valoare from rapoarte_filtre where id_raport = ] + Alltrim(Str(Thisform.nidraport))
		lnSucces = goExecutor.oExecute(lcSql,lcCursorFiltru)
		If lnSucces < 0
			amessagebox(goExecutor.cEroare,16,"Eroare")
		Else
			Select (lcCursorFiltru)
			Thisform.filtru_cript = valoare
		*!*	modificare	ROAGEST v 2.0.144
			If At(Upper([luna_curenta|]),Upper(Thisform.filtru_cript)) <> 0
				Thisform.filtru_cript = STRTRAN(Thisform.filtru_cript,UPPER([luna_curenta|]),Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|])
			Endif
		*!*	modificare	ROAGEST v 2.0.144	^
			Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
			Thisform.ed_explicatii_filtru.Refresh()
		Endif
		If Used(lcCursorFiltru)
			Use In (lcCursorFiltru)
		Endif
		Release lcCursorFiltru
		
	ENDPROC

	PROCEDURE do_incarca_raport
		*!* 23.09.2010
		*!* marius.mutu 
		*!* tratare idformular = 2 && raw sql
		
		Local i, lnCount, lcCamp, loCamp, lcNumeContainer, loContainer, lcListaCampuri, lcListaOrdonare, lcListaGrupare
		LOCAL lcCrossTabulare, lcListaCampuri2
		Local loException As Exception
		Local lcCursorRaport, lnIdFormular
		Local lcSql, lnSucces, lcRawSql, lcNumeCamp, lnIndexCamp, lcCampSelectat, lcElement
		*!* 23.09.2010
		lnIdFormular = THIS.nIdformularraport
		*!* 23.09.2010 ^
		
		If !Empty(Nvl(Thisform.nidraport,0))
			lcCursorRaport = [crsdateraport]
			If Used(lcCursorRaport)
				Use In (lcCursorRaport)
			Endif
			*!* 23.09.2010
			lcSql = [select denumire,titlu,nume_frx,modificabil,campuri,grupare,ordonare,crosstabulare, csql from vrapoarte ] + ;
				[where id_raport = ] + Alltrim(Str(Thisform.nidraport))
			*!* 23.09.2010 ^
			lnSucces = goExecutor.oExecute(lcSql,lcCursorRaport)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,16,"Eroare")
			Else
				lcNumeContainer = [thisform.] + Thisform.cnume_ct_selectie
				loContainer = &lcNumeContainer
				*!*	modificare	ROAGEST v 2.0.144
				Local llAdaugaLunaCurenta
				llAdaugaLunaCurenta = Thisform.ladaugalunacurenta
				Thisform.ladaugalunacurenta = .F.
				*!*	modificare	ROAGEST v 2.0.144	^
				Thisform.do_reset(.T.)
				*!* 23.09.2010
				Thisform.do_reset_filtru(.T.)
				*!* 23.09.2010 ^		
				*!*	modificare	ROAGEST v 2.0.144
				Thisform.ladaugalunacurenta = llAdaugaLunaCurenta
				*!*	modificare	ROAGEST v 2.0.144	^
				Select (lcCursorRaport)
				lcListaCampuri = campuri
				lcListaOrdonare = ordonare
				lcListaGrupare = grupare
				lcCrossTabulare = crosstabulare
				lcRawSql = csql
				lcListaCampuri2 = []
				Thisform.cdenumire = Upper(Alltrim(denumire))
				Thisform.ctitluraport = Upper(Alltrim(titlu))
				Thisform.cRaport = nume_frx
				Thisform.lReadOnly = Iif(modificabil = 1,.F.,.T.)
		
				With &lcNumeContainer
					.Enabled = !Thisform.lReadOnly
				Endwith
		
				Thisform.but_listare1.Visible = Iif(!Empty(Nvl(Thisform.cRaport,[])),.T.,.F.)
				Thisform.but_listare1.lvizibil = Iif(!Empty(Nvl(Thisform.cRaport,[])),.T.,.F.)
				Thisform.but_sterge1.Visible = !Thisform.lReadOnly
		
				This.lb_titlu_alb_b121.Caption = Upper(Alltrim(Iif(!Empty(Thisform.ctitluraport),Thisform.ctitluraport,Thisform.ctitluraportinitial)))
				*** NU INCARC NIMIC
		
				If m.lnIdFormular = 2 && raw sql
					loContainer.edtSelectie.value = m.lcRawSql
				ELSE 
					&& Completare campuri selectie predefinite
					If !Empty(Nvl(lcListaCampuri,[]))
						lnCount = Getwordcount(lcListaCampuri,",")
						For i = 1 To lnCount
							lcNumeCamp = Getwordnum(lcListaCampuri,i, ",")
							lcCamp = lcNumeContainer + [.ct_selectie_] + lcNumeCamp + [.ck_camp]&& ct_selectie_nnir
							Try
								loCamp = &lcCamp
								loCamp.Value = 1
								*!*	modificare ROAGEST v 2.0.143
								If !Evaluate(lcNumeContainer + [.ct_selectie_] + lcNumeCamp + [.lSuma])
									lcListaCampuri2 = lcListaCampuri2 + lcNumeCamp + [,]
								Endif
								*!*	modificare ROAGEST v 2.0.143	^
							Catch To loException
								amessagebox(loException.Message)
							Endtry
						Endfor
					Endif
		
					&& Completare campuri grupare predefinite
					&&	modificare ROAGEST v 2.0.143 : am inlocuit lcListaCampuri cu lcListaCampuri2
					If !Empty(Nvl(lcListaGrupare,[]))
						lnCount = Getwordcount(lcListaGrupare,",")
						For i = 1 To lnCount
							lnIndexCamp = Val(Getwordnum(lcListaGrupare,i, ","))
		
							lcCampSelectat = lcNumeContainer + [.ct_selectie_] + Getwordnum(lcListaCampuri2,lnIndexCamp, ",") + [.cCamp]
							lcCamp = &lcCampSelectat
							lcCamp = Upper(Alltrim(lcNumeContainer + [.ct_grupare1._scrollcontainer1.ct_grup_] + Strtran(lcCamp,[.],[_]))) + [.ck_ordine]
							Try
								loCamp = &lcCamp
								loCamp.Value = 1
							Catch To loException
								amessagebox(loException.Message)
							Endtry
		
						Endfor
					Endif
		
		
					&& Completare campuri ordonare predefinite
					&&	modificare ROAGEST v 2.0.143 : am inlocuit lcListaCampuri cu lcListaCampuri2
					If !Empty(Nvl(lcListaOrdonare,[]))
						Local llDesc
						lnCount = Getwordcount(lcListaOrdonare,",")
						For i = 1 To lnCount
							llDesc = .F.
							lcElement = Getwordnum(lcListaOrdonare,i, ",")
							If 'DESC'$Upper(lcElement)
								llDesc = .T.
								lnIndexCamp = Val(Alltrim(Strtran(Upper(lcElement),[DESC],[])))
							Else
								lnIndexCamp = Val(lcElement)
							Endif
		
							lcCampSelectat = lcNumeContainer + [.ct_selectie_] + Getwordnum(lcListaCampuri2,lnIndexCamp, ",") + [.cCamp]
							lcCamp = &lcCampSelectat
		
							lcCamp = Upper(Alltrim(lcNumeContainer + [.ct_ordonare1._scrollcontainer1.ct_ordine_] + Strtran(lcCamp,[.],[_]))) + [.ck_ordine]
							Try
								loCamp = &lcCamp
								loCamp.Value = 1
							Catch To loException
								amessagebox(loException.Message)
							Endtry
		
							If llDesc
								lcCamp = &lcCampSelectat
								lcCamp = Upper(Alltrim(lcNumeContainer + [.ct_ordonare1._scrollcontainer1.ct_ordine_] + Strtran(lcCamp,[.],[_]))) + [.opt_ordine]
								Try
									loCamp = &lcCamp
									loCamp.Value = 2
								Catch To loException
									amessagebox(loException.Message)
								Endtry
							Endif
		
						Endfor
					Endif
		
					&& Completare campuri crosstabulare predefinite
					If !Empty(Nvl(lcCrossTabulare,[]))
						lnCount = Getwordcount(lcCrossTabulare,",")
						For i = 1 To lnCount
							lcCamp = Getwordnum(lcCrossTabulare,i, ",")
							lcCamp = lcNumeContainer + [.ct_selectie_] + lcCamp + [.ck_camp]	&& ct_selectie_nnir
							Try
								loCamp = &lcCamp
								loCamp.RightClick()
							Catch To loException
								amessagebox(loException.Message)
							Endtry
						Endfor
					Endif
				Endif && lnIdFormular = 2
				&&	Incarcare filtru
				Thisform.do_incarca_filtru()
				Thisform.Refresh()
			Endif
			If Used(lcCursorRaport)
				Use In (lcCursorRaport)
			Endif
		Endif
		
	ENDPROC

	PROCEDURE do_listare
		Local lcQuickReport
		Local loListener
		Private pcDataOra, pcTitlu, pcSubtitlu
		This.creeaza_raport()
		
		If Used('crsExport')
			lcQuickReport = This.cRaport
			If !Empty(lcQuickReport)
				pcDataOra = get_ora(2)
				pcTitlu = Thisform.ctitluraport
				pcSubtitlu = Thisform.filtru_pretty_ro
				Thisform.AlwaysOnTop = .F.
				Select crsExport
				Report Form (lcQuickReport) To Printer Prompt Preview
				Thisform.AlwaysOnTop = .T.
			Endif
			Use In crsExport
		Else
			amessagebox("Nu exista rezultate pentru listare!",0+48,"Atentie")
		Endif
		
	ENDPROC

	PROCEDURE do_modificabil
		Thisform.lb_raport_predefinit.Visible = Thisform.lReadOnly
		If Type('thisform.but_sterge1')='O'
			Thisform.but_sterge1.Visible = Iif(Isnull(Thisform.nidraport),.F.,Thisform.lReadOnly)
			Thisform.but_sterge1.lvizibil = Iif(Isnull(Thisform.nidraport),.F.,Thisform.lReadOnly)
		Endif
	ENDPROC

	PROCEDURE do_reset
		Lparameters tlIncomplet
		*!*	.T.	-	este apelat din do_incarca_raport si nu trebuie sa reseteze nidraport pentru ca a fost setat din cautare
		*!*	.F. -	se reseteaza nidraport
		Local lcNumeContainer
		lcNumeContainer = [thisform.] + Thisform.cnume_ct_selectie
		Thisform.lReadOnly = .F.
		With &lcNumeContainer
			.Enabled = !Thisform.lReadOnly
			.do_reset()
		Endwith
		Thisform.do_reset_filtru()
		Thisform.ctitluraport = Thisform.ctitluraportinitial
		Thisform.cRaport = Thisform.cRaportinitial
		Thisform.cdenumire = Thisform.ctitluraportinitial
		If !tlIncomplet
			Thisform.nidraport = Thisform.nidraportinitial
		Endif
		This.but_listare1.Visible = .F.
		This.but_listare1.lvizibil = .F.
		This.lb_titlu_alb_b121.Caption = Upper(Alltrim(Thisform.ctitluraportinitial))
		If Isnull(Thisform.nidraport)
			Thisform.but_sterge1.Visible = .F.
		Endif
		
	ENDPROC

	PROCEDURE do_reset_filtru
		LPARAMETERS tlInitial
		
		Thisform.filtru_pretty = ""
		Thisform.filtru_pretty_ro = ""
		Thisform.filtru_pretty_ro_full = ""
		Thisform.filtru_cript = ""
		If Type("this.but_start_criterii1") = 'O'
			Thisform.but_start_criterii1.ToolTipText=Thisform.filtru_pretty_ro
			Thisform.but_start_criterii1.SetFocus
			Thisform.but_start_criterii1.pornit = "nu"
		Endif
		*!*	If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta And ;
		*!*			At([Perioada;]+Alltrim(Thisform.cfiltruperioada)+[;],Thisform.filtru_cript) = 0
		*!*		Thisform.filtru_cript = Thisform.filtru_cript + [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*			Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
		*!*		Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
		*!*	Endif
		lnIdFormular = This.nIdFormularRaport 
		*!* 23.09.2010
		If m.lnIdFormular = 2  && raw sql
			IF !tlInitial && do_incarca_raport() apeleaza si do_reset_filtru() si do_incarca_filtru() si nu mai trebuie sa apelez din nou
				This.do_incarca_filtru()
			ENDIF 	
		Else
			If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta
				Thisform.filtru_cript = [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
					Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
				Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
			Endif
		Endif
		*!* 23.09.2010 ^
		Thisform.ed_explicatii_filtru.Refresh()
		
	ENDPROC

	PROCEDURE do_salvare
		*!* 23.09.2010
		*!* marius.mutu 
		*!* tratare idformular = 2 && raw sql
		
		*!* 12.10.2015
		*!* marius.mutu
		*!* se salveaza si csql_parametri la adaugarea raportului (pentru raport nou din raport existent)
		
		Private pcDenumireRaport, pcTitluRaport, pnIdRaport, pnIdRaportNou, pcSql, pcSqlParametri
		Local lofrmraportnou,llArataFereastra, lcCampuri, lnIdFormular, lcIdFormular, lcGrupare, lcOrdonare, lcCrossTabulare
		Local lcNumeContainer, loContainerSelectie, lcMenu, lnx, lcRaport, lcModificabil
		Local lcValoriFiltru, lcSql, lnSucces
		
		pcSql = ""
		lcCampuri = ""
		lcGrupare = ""
		lcOrdonare = ""
		lcCrossTabulare = ""
		pcSqlParametri = ""
		
		lnIdFormular = THIS.nIdformularraport
		lcIdFormular = Alltrim(Str(m.lnIdFormular))	&&	id_formular_raport
			
		pcDenumireRaport = Thisform.cdenumire							&&	denumire
		pcTitluRaport = Iif(Empty(Thisform.ctitluraport),Thisform.ctitluraportinitial,Thisform.ctitluraport)	&&	titlu
		pnIdRaport = Iif(Thisform.lReadOnly,.Null.,Thisform.nidraport)	&&	raport
			&&	daca raportul e predefinit ( nu e modificabil ) atunci pot doar sa-l salvez ca unul nou
		pnIdRaportNou = 0
		llArataFereastra = .F.
		lcNumeContainer = [thisform.] + Thisform.cnume_ct_selectie
		loContainerSelectie = &lcNumeContainer
		*!* 23.09.2010
		IF m.lnIdFormular <> 2
			lcCampuri = loContainerSelectie.get_coloane_selectie()
		
			If Empty(m.lcCampuri)
				amessagebox("Nu ati selectat niciun camp!",48,"Atentie")
				Return
			Endif
		ELSE 
			pcSql = ALLTRIM(loContainerSelectie.edtSelectie.value)
		ENDIF 
		*!* 23.09.2010 ^
		
		If !Isnull(m.pnIdRaport)
			lcMenu = "Salveaza modificari;Salveaza modificari si schimba denumire/titlu;Salveaza ca raport nou"
			lnx = xmenu(m.lcMenu)
			Do Case
			Case lnx = 1
				llArataFereastra = .F.
			Case lnx = 2
				llArataFereastra = .T.
			Case lnx = 3
				llArataFereastra = .T.
				pnIdRaport = Null
				
				pcSqlParametri = ""
				lnSucces = goExecutor.oSelect2Value([select csql_parametri from rapoarte where id_raport = ?pnIdRaport], @pcSqlParametri)
		
				If lnSucces < 0
					amessagebox(goExecutor.cEroare,16,"Eroare")
				Endif
				
			Otherwise
				Return
			Endcase
		Else
			llArataFereastra = .T.
		Endif
		
		If llArataFereastra
			lofrmraportnou = Createobject('frm_raport_nou')
			lofrmraportnou.Show(1)
		Else
			gnButon = 1
		Endif
		If gnButon = 1
			lcRaport = Iif(Thisform.lReadOnly,Thisform.cRaportInitial,Thisform.cRaport)	&&	nume_frx
		*!*		lcModificabil = Iif(Thisform.lReadOnly,[0],[1])							&&	modificabil
			lcModificabil = [1]
		
			IF m.lnIdFormular <> 2
				lcGrupare = Nvl(loContainerSelectie.get_coloane_grupare(),[NULL])
				lcOrdonare = Nvl(loContainerSelectie.get_coloane_ordonare(),[NULL])
				lcCrossTabulare = Nvl(loContainerSelectie.get_coloane_crosstabulare(),[NULL])
			ENDIF 	
		*!*	modificare	ROAGEST	v 2.0.144
		*!*		If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta And ;
		*!*				At(Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*				Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),Upper(Thisform.filtru_cript)) <> 0
		*!*			Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*				Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),[luna_curenta|])
		*!*		Endif
			If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta And ;
					OccursRegExp(Upper("Perioada;" + Alltrim(Thisform.cfiltruperioada) + ";/[1-6]/;;" + ;
					Padl(Alltrim(Str(gnLuna)),2,[0]) + "/" + Alltrim(Str(gnAn)) + "|"),UPPER(Thisform.filtru_cript)) > 0
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;2;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;2;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;3;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;3;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;4;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;4;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;5;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;5;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;6;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;6;;luna_curenta|]))
			Endif
		*!*	modificare	ROAGEST	v 2.0.144	^
			lcValoriFiltru = Nvl(thisform.filtru_cript,[NULL])
			lcSql = [{call pack_rapoarte.salveaza_raport(?pnIdRaport,?@pnIdRaportNou,] + ;
				['] + Alltrim(pcDenumireRaport) + [','] + Alltrim(pcTitluRaport) + [',] + ;
				['] + Alltrim(Nvl(lcRaport,[])) + [',] + Alltrim(lcModificabil) + [,] + ;
				['] + Alltrim(lcCampuri) + [','] + Alltrim(lcGrupare) + [',] + ;
				['] + Alltrim(lcOrdonare) + [','] + Alltrim(lcCrossTabulare) + [',] + ;
				lcIdFormular + [,'] + lcValoriFiltru + [',] + ;
				[?gnIdUtil, ?pcSql, ?pcSqlParametri)}]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox("Salvarea nu a reusit!" + Chr(13) + Chr(10) + Chr(13) + Chr(10) + ;
					goExecutor.cEroare,16,"Eroare")
			Else
				amessagebox("Raportul a fost salvat in baza de date!",64,"Info salvare raport")
				Thisform.nidraport = pnIdRaportNou
				Thisform.cdenumire = pcDenumireRaport
				Thisform.ctitluraport = pcTitluRaport
				Thisform.cRaport = lcRaport
				Thisform.lReadOnly = .F.
				loContainerSelectie.Enabled = !Thisform.lReadOnly
				Thisform.but_sterge1.Visible = !Thisform.lReadOnly
				Thisform.but_listare1.Visible = Iif(!Empty(Thisform.cRaport),.T.,.F.)
				Thisform.but_listare1.lvizibil = Iif(!Empty(Thisform.cRaport),.T.,.F.)		
			Endif
		Endif
		Release pcDenumireRaport, pcTitluRaport, lofrmraportnou, pnIdRaport, pnIdRaportNou
	ENDPROC

	PROCEDURE do_sterge
		If amessagebox("Doriti sa stergeti raportul '"+Upper(Alltrim(Thisform.cdenumire)) + "' din baza de date?",4+32,"Confirmare stergere") = 6
			lcSql = [begin pack_rapoarte.sterge_raport(] + Alltrim(Str(Thisform.nidraport)) + [,] + ;
				[?gnIdUtil); end;]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,16,"Eroare")
			Else
				amessagebox("Raportul a fost sters!",64,"Info stergere")
				Thisform.nidraport = .Null.
			Endif
		Endif
	ENDPROC

	PROCEDURE Init
		Lparameters tnIdRaport, tlDrepturi
		*!* tnIdRaport: 1 = Rapoarte rulaj; 2 = Rapoarte SQL
		*!* tlDrepturi: .T. = Se afiseaza doar rapoartele pe care are drepturi utilizatorul 
		
		If Isnull(Thisform.nidformularraport)
			Thisform.RemoveObject('ct_clb_raport')
			Thisform.RemoveObject('but_salveaza1')
			Thisform.RemoveObject('but_modiparam1')
		
			If Isnull(Thisform.nidraport)
				Thisform.RemoveObject('but_sterge1')
			Endif
		Endif
		For i = 1 To Thisform.Objects.Count
			If Upper(Alltrim(Thisform.Objects[i].Class)) = [CT_SELECTIE]
				Thisform.cnume_ct_selectie = Thisform.Objects[i].Name
				Exit
			Endif
		Endfor
		This.lb_titlu_alb_b121.Caption = Upper(Alltrim(Thisform.ctitluraportinitial))
		Thisform.ctitluraport = Thisform.ctitluraportinitial
		Thisform.cRaport = Thisform.cRaportinitial
		Thisform.nidraport = Thisform.nidraportinitial
		*!* 07.03.2011
		IF PCOUNT() = 2
			Thisform.lDrepturi = tlDrepturi
		ENDIF 	
		*!* 07.03.2011 ^
		*!*	*!*	If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta And ;
		*!*	*!*			At([Perioada;]+Alltrim(Thisform.cfiltruperioada)+[;],Thisform.filtru_cript) = 0
		*!*	*!*		Thisform.filtru_cript = Thisform.filtru_cript + [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*	*!*			Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
		*!*	*!*		Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
		*!*	*!*	Endif
		*!*	modificare	ROAGEST	v 2.0.144
		*!*	If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta
		*!*		Thisform.filtru_cript = [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*			Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
		*!*		Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
		*!*	Endif
		*!*	modificare	ROAGEST	v 2.0.144	^
		Bindevent(Thisform,"lReadOnly",Thisform,"do_modificabil",1)
		DoDefault()
		If !Empty(tnIdRaport)
			Thisform.nidraport = tnIdRaport
			Thisform.do_incarca_raport()
		*!*	modificare	ROAGEST	v 2.0.144
		Else
			If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta
				Thisform.filtru_cript = [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
					Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
				Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
			Endif
		*!*	modificare	ROAGEST	v 2.0.144	^
		Endif
	ENDPROC

	PROCEDURE But_start_criterii1.initform
		Lparameters tlShowForm
		DoDefault(tlShowForm)
		Thisform.ed_explicatii_filtru.Refresh()
		This.SetFocus()
	ENDPROC

	PROCEDURE But_start_criterii1.loadcriterii
		*!* 23.09.2010
		*!* marius.mutu
		*!* tratare idformular = 2 && raw sql
		
		#Define CRLF Chr(13)+Chr(10)
		Local lnIdFormular, lnIdRaport
		
		*!* 23.09.2010
		lnIdFormular = Thisform.nIdformularraport
		lnIdRaport = Thisform.nIdRaport
		
		If m.lnIdFormular = 2 && raw sql
			*** obtin cursorul cu criterii
			Do criterii_rapoarte_sql With lnIdRaport In orapoarte_dinamice.prg
			*!*		crsParametriXML(parametru C(250), titlu C(100), CAMP M, TIPCAMP C(10), CAMPID C(100), CAMPCAUTARE C(100) )
			If Used('crsParametriXML')
				Select crsParametriXML
				Scan
					lcTitlu = Alltrim(titlu)
					lcCamp = Iif(Empty(Alltrim(camp)), "none",  Alltrim(camp))
					lcTipCamp = Iif(Empty(Alltrim(tipcamp)), "C", Alltrim(tipcamp))
					lcCampId = Iif(Empty(Alltrim(campid)), "none", Alltrim(campid))
					lcCampCautare = Iif(Empty(Alltrim(campcautare)), "none", Alltrim(campcautare))
					lcStringCriterii = lcStringCriterii + CRLF + ;
						lcTitlu + "\" + lcCamp + "\" + lcTipCamp + "\" + lcCampId + "\" + lcCampCautare + "\"
				Endscan
			Endif && used
			Use In (Select('crsParametriXML'))
		Else
			If Thisform.lfiltruperioada
				lcStringCriterii = lcStringCriterii + CRLF + ;
					"Perioada\" + Alltrim(Thisform.cfiltruperioada) + "\D1\none\"
			Endif
			lcStringCriterii = lcStringCriterii + IIF(glEMama,crlf + "Sucursala\sucursala\T\ID_SUCURSALA\nom_sucursala", "") && aleg sucursale doar daca sunt pe mama : 28.04.2011
		Endif && lnIdFormular
		*!* 23.09.2010 ^
		
		DoDefault()
		
	ENDPROC

	PROCEDURE lb_raport_predefinit.Init
		lcNumeContainer = [thisform.] + Thisform.cnume_ct_selectie
		loContainer = &lcNumeContainer
		This.Top = loContainer.Top + Round((loContainer.Height-This.Height)/2,0)
		This.Left = loContainer.Left + Round((loContainer.Width-This.Width)/2,0)
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_date_rapoarte_gen_original AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="But_listare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_excel1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_help1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_cautare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_sterge1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_selectie1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ed_explicatii_filtru" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_salveaza1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_reset2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_start_criterii1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_nou1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_raport_predefinit" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: creeaza_raport
		*m: do_adauga_filtru
		*m: do_cauta_raport
		*m: do_incarca_filtru
		*m: do_incarca_raport
		*m: do_modificabil
		*m: do_reset_filtru
		*m: do_salvare
		*p: cdenumire		&& Denumirea raportului.
		*p: cfiltruperioada		&& Campurile / campul dupa care se filtreaza perioada ( trebuie sa fie de forma an * 12 + luna ).
		*p: cnume_ct_selectie		&& Numele containerului bazat pe ct_selectie.
		*p: craport		&& Numele raportului pentru listare
		*p: craportinitial		&& Numele raportului folosit pentru listare.
		*p: ctitluraport
		*p: ctitluraportinitial		&& Titlul initial al raportului.
		*p: filtru_cript
		*p: ladaugalunacurenta		&& IN CAZUL IN CARE EXISTA PERIOADA IN FILTRU : .T. - daca adauga luna curenta in filtru la incarcarea unui raport ( daca nu exista deja o perioada salvata in filtru ), la resetare si la raport nou.
		*p: lfiltruperioada		&& .T. - este adaugat filtrul pe perioada; campul este specificat in cFiltruPerioada
		*p: lreadonly		&& Daca campurile de selectie, ordonare, grupare sunt blocate (pentru selectii predefinite)
		*p: nidformularraport		&& Id-ul formularului.
		*p: nidraport		&& Id-ul raportului incarcat.
		*p: nidraportinitial
	*</DefinedPropArrayMethod>

	*<PropValue>
		cdenumire = 
		cfiltruperioada = an*12+luna
		cnume_ct_selectie = ct_selectie1
		craport = 
		craportinitial = 
		ctitluraport = 
		ctitluraportinitial = Rapoarte generate dinamic
		DoCreate = .T.
		filtru_cript = 
		Height = 440
		lactiv4 = .T.
		ladaugalunacurenta = .T.
		lfiltruperioada = .T.
		lreadonly = .F.
		Name = "frm_date_rapoarte_gen"
		nidformularraport = .NULL.
		nidraport = .NULL.
		nidraportinitial = .NULL.
		Width = 696
		_memberdata = <VFPData>
			<memberdata name="craport" type="property" display="cRaport" favorites="True"/>
			<memberdata name="lreadonly" type="property" display="lReadOnly" favorites="True"/>
			<memberdata name="ctitluraport" type="Property" favorites="True"/>
			<memberdata name="do_adauga_filtru" type="Method" favorites="True"/>
			<memberdata name="do_cauta" type="Method" favorites="True"/>
			<memberdata name="do_excel" type="Method" favorites="True"/>
			<memberdata name="do_listare" type="Method" favorites="True"/>
			<memberdata name="ladauga<VFPData><memberdata name="craport" type="property" display="cRaport" favorites="True"/>
			<memberdata name="craport" type="property" display="cRaport" favorites="True"/>
		</VFPData>
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 696
		_shape1.ZOrderSet = 0
		_shape2.Height = 29
		_shape2.Left = 455
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 240
		_shape2.ZOrderSet = 1
		Lb_titlu_alb_b121.Caption = "Thisform.ctitluraportinitial"
		Lb_titlu_alb_b121.FontBold = .T.
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 10
		Lb_titlu_alb_b121.ZOrderSet = 2
		BUT_TERMIN1.Left = 666
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 8
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 4
		GRIDSORT1.Left = 480
		GRIDSORT1.Name = "GRIDSORT1"
		GRIDSORT1.Top = 36
	*</PropValue>

	ADD OBJECT 'But_cautare1' AS but_cautare WITH ;
		caction = do_cauta_raport, ;
		Height = 27, ;
		Left = 513, ;
		Name = "But_cautare1", ;
		TabIndex = 3, ;
		Top = 1, ;
		Width = 30
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_excel1' AS but_excel WITH ;
		Left = 605, ;
		Name = "But_excel1", ;
		TabIndex = 6, ;
		Top = 1, ;
		ZOrderSet = 6
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_help1' AS but_help WITH ;
		Left = 454, ;
		Name = "But_help1", ;
		TabIndex = 1, ;
		Top = 1, ;
		ZOrderSet = 7
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_listare1' AS but_listare WITH ;
		Left = 636, ;
		lvizibil = .F., ;
		Name = "But_listare1", ;
		TabIndex = 7, ;
		Top = 1, ;
		ZOrderSet = 5
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_nou1' AS but_nou WITH ;
		Left = 483, ;
		Name = "But_nou1", ;
		TabIndex = 2, ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_reset2' AS but_reset WITH ;
		caction = do_reset_filtru, ;
		Left = 624, ;
		Name = "But_reset2", ;
		TabIndex = 9, ;
		ToolTipText = "Reseteaza filtru", ;
		Top = 32, ;
		ZOrderSet = 14
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_salveaza1' AS but_salveaza WITH ;
		Height = 27, ;
		Left = 543, ;
		Name = "But_salveaza1", ;
		TabIndex = 4, ;
		ToolTipText = "Salvare raport", ;
		Top = 1, ;
		Width = 30, ;
		ZOrderSet = 13
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_start_criterii1' AS but_start_criterii WITH ;
		Anchor = 9, ;
		lcautare = .F., ;
		Left = 655, ;
		Name = "But_start_criterii1", ;
		TabIndex = 13, ;
		Top = 32, ;
		ZOrderSet = 15
		*< END OBJECT: ClassLib="ocriterii.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_sterge1' AS but_sterge WITH ;
		Left = 574, ;
		lvizibil = .F., ;
		Name = "But_sterge1", ;
		TabIndex = 5, ;
		ToolTipText = "Stergere raport (CTRL+D)", ;
		Top = 1, ;
		ZOrderSet = 10
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ct_selectie1' AS ct_selectie WITH ;
		Height = 391, ;
		Left = 12, ;
		Name = "Ct_selectie1", ;
		TabIndex = 11, ;
		Top = 36, ;
		Width = 332, ;
		ZOrderSet = 11, ;
		Ct_grupare1.lblAtentie.Name = "lblAtentie", ;
		Ct_grupare1.lb_grupare.Name = "lb_grupare", ;
		Ct_grupare1.Left = 5, ;
		Ct_grupare1.Name = "Ct_grupare1", ;
		Ct_grupare1.Top = 252, ;
		Ct_grupare1._scrollcontainer1.But_jos1.Name = "But_jos1", ;
		Ct_grupare1._scrollcontainer1.But_sus1.Name = "But_sus1", ;
		Ct_grupare1._scrollcontainer1.Name = "_scrollcontainer1", ;
		Ct_ordonare1.lb_ordonare.Name = "lb_ordonare", ;
		Ct_ordonare1.Left = 5, ;
		Ct_ordonare1.Name = "Ct_ordonare1", ;
		Ct_ordonare1.Top = 120, ;
		Ct_ordonare1._scrollcontainer1.But_jos1.Name = "But_jos1", ;
		Ct_ordonare1._scrollcontainer1.But_sus1.Name = "But_sus1", ;
		Ct_ordonare1._scrollcontainer1.Name = "_scrollcontainer1", ;
		lb_coloane.Name = "lb_coloane"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />

	ADD OBJECT 'ed_explicatii_filtru' AS _editbox WITH ;
		ControlSource = "Thisform.filtru_pretty_ro", ;
		Height = 364, ;
		Left = 360, ;
		Name = "ed_explicatii_filtru", ;
		ReadOnly = .T., ;
		TabIndex = 12, ;
		Top = 63, ;
		Width = 324, ;
		ZOrderSet = 12
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="editbox" />

	ADD OBJECT 'lb_raport_predefinit' AS _lbbase WITH ;
		Caption = "RAPORT PREDEFINIT", ;
		FontBold = .T., ;
		FontSize = 25, ;
		Height = 228, ;
		Left = 12, ;
		Name = "lb_raport_predefinit", ;
		Rotation = 35, ;
		TabIndex = 14, ;
		Top = 200, ;
		Visible = .F., ;
		Width = 300, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_lb_base.vcx" BaseClass="label" />
	
	PROCEDURE creeaza_raport
		If Used('crsraport')
			Use In crsraport
		Endif
		
		This.do_cauta()
		
		If Used('crsRaport') And Reccount('crsraport')<>0
			If Used('crsexport')
				Use In crsexport
			Endif
			Dimension aColoane[1]
			lcSelect = [SELECT Iif(gid<>0,'TOTAL',Space(5)) As explicatie]
			Afields(aColoane,'crsraport')
			For i = 1 To Alen(aColoane,1)
				If Upper(Alltrim(aColoane[i,1])) <> 'GID'
					lcNumeColoana =  Upper(Alltrim(aColoane[i,1]))
					lcSelect = lcSelect + [,] + Iif(aColoane[i,2] = 'T', [TTOD(] + lcNumeColoana + [) as ] + ;
						lcNumeColoana, lcNumeColoana)
				Endif
			Endfor
			lcSelect = lcSelect + [	From crsraport Into Cursor crsexport]
			&lcSelect
		Endif
		If Used('crsRaport')
			Use In crsRaport
		Endif
		
	ENDPROC

	PROCEDURE do_adauga
		Thisform.do_reset()
		
	ENDPROC

	PROCEDURE do_adauga_filtru
	ENDPROC

	PROCEDURE do_cauta
		*!* 22.06.2010
		*!* marius.mutu
		*!* apelez do_instructiune_sql cu filtru
		*!* in do_instructiune_sql - trimit filtrul daca coloana de crostabulare face parte din filtru - sa arat atatea coloane cate valori sunt in filtru
		
		Local llReturn
		With Thisform.ct_selectie1
		*!* 22.06.2010
		*!*		If .do_instructiune_sql()
			If .do_instructiune_sql(Thisform.filtru_pretty)
		*!* 22.06.2010 ^
				lcSql = .csql
				If Empty(lcSql)
					amessagebox("Nu ati ales coloane pentru selectie!",0+48,"Atentie")
					.SetFocus()
					llReturn = .F.
				Else
					lcSql = Strtran(lcSql,[WHERE 1=2],Iif(!Empty(Thisform.filtru_pretty),[WHERE ] + Thisform.filtru_pretty,[]))
					lnSucces = goExecutor.oExecute(lcSql,'crsraport')
					If lnSucces < 0
						amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
						llReturn = .F.
					Endif
				Endif
			Else
				llReturn = .F.
			Endif
		Endwith
		Return llReturn
	ENDPROC

	PROCEDURE do_cauta_raport
		Local loCauta
		loCauta = caut_raport(This.nidformularraport)
		If gnButon = 1
			Thisform.nidraport = loCauta.id_raport
			Thisform.do_incarca_raport()
		Endif
		Release loCauta
	ENDPROC

	PROCEDURE do_excel
		Local lcFileName
		lcFileName = ""
		This.creeaza_raport()
		
		If Used('crsExport')
			lcFileName = strtranx(This.ctitluraport, "([^a-zA-Z0-9])", [_] )
			export_xls('crsexport', lcFileName)
			Use In crsExport
		Else
			amessagebox("Nu exista rezultate pentru export in Excel!",0+48,"Atentie")
		Endif
		
		
	ENDPROC

	PROCEDURE do_help
		Local lofrmhelprap
		lofrmhelprap = Createobject('frm_help_rapoarte')
		lofrmhelprap.Show(1)
		Release lofrmhelprap
	ENDPROC

	PROCEDURE do_incarca_filtru
		Local lcCursorFiltru
		lcCursorFiltru = [crsrapfiltru]
		If Used(lcCursorFiltru)
			Use In (lcCursorFiltru)
		Endif
		lcSql = [select valoare from rapoarte_filtre where id_raport = ] + Alltrim(Str(Thisform.nidraport))
		lnSucces = goExecutor.oExecute(lcSql,lcCursorFiltru)
		If lnSucces < 0
			amessagebox(goExecutor.cEroare,16,"Eroare")
		Else
			Select (lcCursorFiltru)
			Thisform.filtru_cript = valoare
		*!*	modificare	ROAGEST v 2.0.144
			If At(Upper([luna_curenta|]),Upper(Thisform.filtru_cript)) <> 0
				Thisform.filtru_cript = STRTRAN(Thisform.filtru_cript,UPPER([luna_curenta|]),Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|])
			Endif
		*!*	modificare	ROAGEST v 2.0.144	^
			Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
			Thisform.ed_explicatii_filtru.Refresh()
		Endif
		If Used(lcCursorFiltru)
			Use In (lcCursorFiltru)
		Endif
		Release lcCursorFiltru
		
	ENDPROC

	PROCEDURE do_incarca_raport
		Local lcCursorRaport
		If !Empty(Nvl(Thisform.nidraport,0))
			lcCursorRaport = [crsdateraport]
			If Used(lcCursorRaport)
				Use In (lcCursorRaport)
			Endif
			lcSql = [select denumire,titlu,nume_frx,modificabil,campuri,grupare,ordonare,crosstabulare from vrapoarte ] + ;
				[where id_raport = ] + Alltrim(Str(Thisform.nidraport))
			lnSucces = goExecutor.oExecute(lcSql,lcCursorRaport)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,16,"Eroare")
			Else
				Local i, lnCount, lcCamp, loCamp, lnSelected, lcNumeContainer, lcListaCampuri, lcListaOrdonare, lcListaGrupare, ;
					lcCrossTabulare, lcListaCampuri2
				Local loException As Exception
		
				lcNumeContainer = [thisform.] + Thisform.cnume_ct_selectie
		*!*	modificare	ROAGEST v 2.0.144
				LOCAL llAdaugaLunaCurenta
				llAdaugaLunaCurenta = Thisform.ladaugalunacurenta
				Thisform.ladaugalunacurenta = .F.
		*!*	modificare	ROAGEST v 2.0.144	^
				Thisform.do_reset(.T.)
				Thisform.do_reset_filtru()
		*!*	modificare	ROAGEST v 2.0.144
				Thisform.ladaugalunacurenta = llAdaugaLunaCurenta
		*!*	modificare	ROAGEST v 2.0.144	^
				Select (lcCursorRaport)
				lcListaCampuri = campuri
				lcListaOrdonare = ordonare
				lcListaGrupare = grupare
				lcCrossTabulare = crosstabulare
				lcListaCampuri2 = []
				Thisform.cdenumire = Upper(Alltrim(denumire))
				Thisform.ctitluraport = Upper(Alltrim(titlu))
				Thisform.cRaport = nume_frx
				Thisform.lReadOnly = Iif(modificabil = 1,.F.,.T.)
		
				With &lcNumeContainer
					.Enabled = !Thisform.lReadOnly
				Endwith
		
				Thisform.but_listare1.Visible = Iif(!Empty(Nvl(Thisform.cRaport,[])),.T.,.F.)
				Thisform.but_listare1.lvizibil = Iif(!Empty(Nvl(Thisform.cRaport,[])),.T.,.F.)
				Thisform.but_sterge1.Visible = !Thisform.lReadOnly
		
				This.lb_titlu_alb_b121.Caption = Upper(Alltrim(Iif(!Empty(Thisform.ctitluraport),Thisform.ctitluraport,Thisform.ctitluraportinitial)))
		
		&& Completare campuri selectie predefinite
				If !Empty(Nvl(lcListaCampuri,[]))
					lnCount = Getwordcount(lcListaCampuri,",")
					For i = 1 To lnCount
						lcNumeCamp = Getwordnum(lcListaCampuri,i, ",")
						lcCamp = lcNumeContainer + [.ct_selectie_] + lcNumeCamp + [.ck_camp]&& ct_selectie_nnir
						Try
							loCamp = &lcCamp
							loCamp.Value = 1
							*!*	modificare ROAGEST v 2.0.143
							If !EVALUATE(lcNumeContainer + [.ct_selectie_] + lcNumeCamp + [.lSuma])
								lcListaCampuri2 = lcListaCampuri2 + lcNumeCamp + [,]
							Endif
							*!*	modificare ROAGEST v 2.0.143	^
						Catch To loException
							amessagebox(loException.Message)
						Endtry
					Endfor
				Endif
		
		&& Completare campuri grupare predefinite
		&&	modificare ROAGEST v 2.0.143 : am inlocuit lcListaCampuri cu lcListaCampuri2
				If !Empty(Nvl(lcListaGrupare,[]))
					lnCount = Getwordcount(lcListaGrupare,",")
					For i = 1 To lnCount
						lnIndexCamp = Val(Getwordnum(lcListaGrupare,i, ","))
		
						lcCampSelectat = lcNumeContainer + [.ct_selectie_] + Getwordnum(lcListaCampuri2,lnIndexCamp, ",") + [.cCamp]
						lcCamp = &lcCampSelectat
						lcCamp = Upper(Alltrim(lcNumeContainer + [.ct_grupare1._scrollcontainer1.ct_grup_] + Strtran(lcCamp,[.],[_]))) + [.ck_ordine]
						Try
							loCamp = &lcCamp
							loCamp.Value = 1
						Catch To loException
							amessagebox(loException.Message)
						Endtry
		
					Endfor
				Endif
		
			
		&& Completare campuri ordonare predefinite
		&&	modificare ROAGEST v 2.0.143 : am inlocuit lcListaCampuri cu lcListaCampuri2
				If !Empty(Nvl(lcListaOrdonare,[]))
					Local llDesc
					lnCount = Getwordcount(lcListaOrdonare,",")
					For i = 1 To lnCount
						llDesc = .F.
						lcElement = Getwordnum(lcListaOrdonare,i, ",")
						If 'DESC'$Upper(lcElement)
							llDesc = .T.
							lnIndexCamp = Val(Alltrim(Strtran(Upper(lcElement),[DESC],[])))
						Else
							lnIndexCamp = Val(lcElement)
						Endif
		
						lcCampSelectat = lcNumeContainer + [.ct_selectie_] + Getwordnum(lcListaCampuri2,lnIndexCamp, ",") + [.cCamp]
						lcCamp = &lcCampSelectat
		
						lcCamp = Upper(Alltrim(lcNumeContainer + [.ct_ordonare1._scrollcontainer1.ct_ordine_] + Strtran(lcCamp,[.],[_]))) + [.ck_ordine]
						Try
							loCamp = &lcCamp
							loCamp.Value = 1
						Catch To loException
							amessagebox(loException.Message)
						Endtry
		
						If llDesc
							lcCamp = &lcCampSelectat				
							lcCamp = Upper(Alltrim(lcNumeContainer + [.ct_ordonare1._scrollcontainer1.ct_ordine_] + Strtran(lcCamp,[.],[_]))) + [.opt_ordine]
							Try
								loCamp = &lcCamp
								loCamp.Value = 2
							Catch To loException
								amessagebox(loException.Message)
							Endtry
						Endif
		
					Endfor
				Endif
		
		&& Completare campuri crosstabulare predefinite
				If !Empty(Nvl(lcCrossTabulare,[]))
					lnCount = Getwordcount(lcCrossTabulare,",")
					For i = 1 To lnCount
						lcCamp = Getwordnum(lcCrossTabulare,i, ",")
						lcCamp = lcNumeContainer + [.ct_selectie_] + lcCamp + [.ck_camp]	&& ct_selectie_nnir
						Try
							loCamp = &lcCamp
							loCamp.RightClick()
						Catch To loException
							amessagebox(loException.Message)
						Endtry
					Endfor
				EndIf
				
		&&	Incarcare filtru
				Thisform.do_incarca_filtru()
				thisform.Refresh()
			Endif
			If Used(lcCursorRaport)
				Use In (lcCursorRaport)
			Endif
		Endif
	ENDPROC

	PROCEDURE do_listare
		Local lcQuickReport
		Local loListener
		Private pcDataOra, pcTitlu, pcSubtitlu
		This.creeaza_raport()
		
		If Used('crsExport')
			lcQuickReport = This.cRaport
			If !Empty(lcQuickReport)
				pcDataOra = get_ora(2)
				pcTitlu = Thisform.ctitluraport
				pcSubtitlu = Thisform.filtru_pretty_ro
				Thisform.AlwaysOnTop = .F.
				Select crsExport
				Report Form (lcQuickReport) To Printer Prompt Preview
				Thisform.AlwaysOnTop = .T.
			Endif
			Use In crsExport
		Else
			amessagebox("Nu exista rezultate pentru listare!",0+48,"Atentie")
		Endif
		
	ENDPROC

	PROCEDURE do_modificabil
		Thisform.lb_raport_predefinit.Visible = Thisform.lReadOnly
		If Type('thisform.but_sterge1')='O'
			Thisform.but_sterge1.Visible = Iif(Isnull(Thisform.nidraport),.F.,Thisform.lReadOnly)
			Thisform.but_sterge1.lvizibil = Iif(Isnull(Thisform.nidraport),.F.,Thisform.lReadOnly)
		Endif
	ENDPROC

	PROCEDURE do_reset
		Lparameters tlIncomplet
		*!*	.T.	-	este apelat din do_incarca_raport si nu trebuie sa reseteze nidraport pentru ca a fost setat din cautare
		*!*	.F. -	se reseteaza nidraport
		Local lcNumeContainer
		lcNumeContainer = [thisform.] + Thisform.cnume_ct_selectie
		Thisform.lReadOnly = .F.
		With &lcNumeContainer
			.Enabled = !Thisform.lReadOnly
			.do_reset()
		EndWith
		thisform.do_reset_filtru()
		Thisform.ctitluraport = Thisform.ctitluraportinitial
		Thisform.cRaport = Thisform.cRaportinitial
		Thisform.cdenumire = Thisform.ctitluraportinitial
		If !tlIncomplet
			Thisform.nidraport = Thisform.nidraportinitial
		Endif
		This.but_listare1.Visible = .F.
		This.but_listare1.lvizibil = .F.
		This.lb_titlu_alb_b121.Caption = Upper(Alltrim(Thisform.ctitluraportinitial))
		If Isnull(Thisform.nidraport)
			Thisform.but_sterge1.Visible = .F.
		Endif
		
	ENDPROC

	PROCEDURE do_reset_filtru
		Thisform.filtru_pretty = ""
		Thisform.filtru_pretty_ro = ""
		Thisform.filtru_pretty_ro_full = ""
		Thisform.filtru_cript = ""
		If Type("this.but_start_criterii1") = 'O'
			Thisform.but_start_criterii1.ToolTipText=Thisform.filtru_pretty_ro
			Thisform.but_start_criterii1.SetFocus
			Thisform.but_start_criterii1.pornit = "nu"
		Endif
		*!*	If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta And ;
		*!*			At([Perioada;]+Alltrim(Thisform.cfiltruperioada)+[;],Thisform.filtru_cript) = 0
		*!*		Thisform.filtru_cript = Thisform.filtru_cript + [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*			Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
		*!*		Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
		*!*	Endif
		If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta
			Thisform.filtru_cript = [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
				Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
			Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)		
		Endif
		Thisform.ed_explicatii_filtru.Refresh()
		
	ENDPROC

	PROCEDURE do_salvare
		Private pcDenumireRaport, pcTitluRaport, pnIdRaport, pnIdRaportNou
		Local lofrmraportnou,llArataFereastra
		pcDenumireRaport = Thisform.cdenumire							&&	denumire
		pcTitluRaport = Iif(Empty(Thisform.ctitluraport),Thisform.ctitluraportinitial,Thisform.ctitluraport)	&&	titlu
		pnIdRaport = Iif(Thisform.lReadOnly,.Null.,Thisform.nidraport)	&&	raport
			&&	daca raportul e predefinit ( nu e modificabil ) atunci pot doar sa-l salvez ca unul nou
		pnIdRaportNou = 0
		llArataFereastra = .F.
		lcNumeContainer = [thisform.] + Thisform.cnume_ct_selectie
		loContainerSelectie = &lcNumeContainer
		lcCampuri = loContainerSelectie.get_coloane_selectie()
		
		If Empty(lcCampuri)
			amessagebox("Nu ati selectat niciun camp!",48,"Atentie")
			Return
		Endif
		
		If !Isnull(pnIdRaport)
			lcMenu = "Salveaza modificari;Salveaza modificari si schimba denumire/titlu;Salveaza ca raport nou"
			lnx = xmenu(lcMenu)
			Do Case
			Case lnx = 1
				llArataFereastra = .F.
			Case lnx = 2
				llArataFereastra = .T.
			Case lnx = 3
				llArataFereastra = .T.
				pnIdRaport = Null
			Otherwise
				Return
			Endcase
		Else
			llArataFereastra = .T.
		Endif
		
		If llArataFereastra
			lofrmraportnou = Createobject('frm_raport_nou')
			lofrmraportnou.Show(1)
		Else
			gnButon = 1
		Endif
		If gnButon = 1
			lcRaport = Iif(Thisform.lReadOnly,Thisform.cRaportInitial,Thisform.cRaport)	&&	nume_frx
		*!*		lcModificabil = Iif(Thisform.lReadOnly,[0],[1])							&&	modificabil
			lcModificabil = [1]
			lcIdFormular = Alltrim(Str(Thisform.nidformularraport))	&&	id_formular_raport
			lcGrupare = Nvl(loContainerSelectie.get_coloane_grupare(),[NULL])
			lcOrdonare = Nvl(loContainerSelectie.get_coloane_ordonare(),[NULL])
			lcCrossTabulare = Nvl(loContainerSelectie.get_coloane_crosstabulare(),[NULL])
		*!*	modificare	ROAGEST	v 2.0.144
		*!*		If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta And ;
		*!*				At(Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*				Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),Upper(Thisform.filtru_cript)) <> 0
		*!*			Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*				Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),[luna_curenta|])
		*!*		Endif
			If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta And ;
					OccursRegExp(Upper("Perioada;" + Alltrim(Thisform.cfiltruperioada) + ";/[1-6]/;;" + ;
					Padl(Alltrim(Str(gnLuna)),2,[0]) + "/" + Alltrim(Str(gnAn)) + "|"),UPPER(Thisform.filtru_cript)) > 0
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;2;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;2;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;3;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;3;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;4;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;4;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;5;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;5;;luna_curenta|]))
				Thisform.filtru_cript = Strtran(Upper(Thisform.filtru_cript),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;6;;] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]),;
					Upper([Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;6;;luna_curenta|]))
			Endif
		*!*	modificare	ROAGEST	v 2.0.144	^
			lcValoriFiltru = Nvl(thisform.filtru_cript,[NULL])
			lcSql = [{call pack_rapoarte.salveaza_raport(?pnIdRaport,?@pnIdRaportNou,] + ;
				['] + Alltrim(pcDenumireRaport) + [','] + Alltrim(pcTitluRaport) + [',] + ;
				['] + Alltrim(Nvl(lcRaport,[])) + [',] + Alltrim(lcModificabil) + [,] + ;
				['] + Alltrim(lcCampuri) + [','] + Alltrim(lcGrupare) + [',] + ;
				['] + Alltrim(lcOrdonare) + [','] + Alltrim(lcCrossTabulare) + [',] + ;
				lcIdFormular + [,'] + lcValoriFiltru + [',] + ;
				[?gnIdUtil)}]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox("Salvarea nu a reusit!" + Chr(13) + Chr(10) + Chr(13) + Chr(10) + ;
					goExecutor.cEroare,16,"Eroare")
			Else
				amessagebox("Raportul a fost salvat in baza de date!",64,"Info salvare raport")
				Thisform.nidraport = pnIdRaportNou
				Thisform.cdenumire = pcDenumireRaport
				Thisform.ctitluraport = pcTitluRaport
				Thisform.cRaport = lcRaport
				Thisform.lReadOnly = .F.
				loContainerSelectie.Enabled = !Thisform.lReadOnly
				Thisform.but_sterge1.Visible = !Thisform.lReadOnly
				Thisform.but_listare1.Visible = Iif(!Empty(Thisform.cRaport),.T.,.F.)
				Thisform.but_listare1.lvizibil = Iif(!Empty(Thisform.cRaport),.T.,.F.)		
			Endif
		Endif
		Release pcDenumireRaport, pcTitluRaport, lofrmraportnou, pnIdRaport, pnIdRaportNou
	ENDPROC

	PROCEDURE do_sterge
		If amessagebox("Doriti sa stergeti raportul '"+Upper(Alltrim(Thisform.cdenumire)) + "' din baza de date?",4+32,"Confirmare stergere") = 6
			lcSql = [begin pack_rapoarte.sterge_raport(] + Alltrim(Str(Thisform.nidraport)) + [,] + ;
				[?gnIdUtil); end;]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,16,"Eroare")
			Else
				amessagebox("Raportul a fost sters!",64,"Info stergere")
				Thisform.nidraport = .Null.
			Endif
		Endif
	ENDPROC

	PROCEDURE Init
		Lparameters tnIdRaport
		If Isnull(Thisform.nidformularraport)
			Thisform.RemoveObject('ct_clb_raport')
			Thisform.RemoveObject('but_salveaza1')
			Thisform.RemoveObject('but_modiparam1')
			If Isnull(Thisform.nidraport)
				Thisform.RemoveObject('but_sterge1')
			Endif
		Endif
		For i = 1 To Thisform.Objects.Count
			If Upper(Alltrim(Thisform.Objects[i].Class)) = [CT_SELECTIE]
				Thisform.cnume_ct_selectie = Thisform.Objects[i].Name
				Exit
			Endif
		Endfor
		This.lb_titlu_alb_b121.Caption = Upper(Alltrim(Thisform.ctitluraportinitial))
		Thisform.ctitluraport = Thisform.ctitluraportinitial
		Thisform.cRaport = Thisform.cRaportinitial
		Thisform.nidraport = Thisform.nidraportinitial
		*!*	*!*	If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta And ;
		*!*	*!*			At([Perioada;]+Alltrim(Thisform.cfiltruperioada)+[;],Thisform.filtru_cript) = 0
		*!*	*!*		Thisform.filtru_cript = Thisform.filtru_cript + [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*	*!*			Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
		*!*	*!*		Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
		*!*	*!*	Endif
		*!*	modificare	ROAGEST	v 2.0.144
		*!*	If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta
		*!*		Thisform.filtru_cript = [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
		*!*			Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
		*!*		Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
		*!*	Endif
		*!*	modificare	ROAGEST	v 2.0.144	^
		Bindevent(Thisform,"lReadOnly",Thisform,"do_modificabil",1)
		DoDefault()
		If !Empty(tnIdRaport)
			Thisform.nidraport = tnIdRaport
			Thisform.do_incarca_raport()
		*!*	modificare	ROAGEST	v 2.0.144
		Else
			If Thisform.lfiltruperioada And Thisform.ladaugalunacurenta
				Thisform.filtru_cript = [Perioada;] + Alltrim(Thisform.cfiltruperioada) + [;1;;] + ;
					Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn)) + [|]
				Thisform.but_start_criterii1.loadfiltru(Thisform.filtru_cript)
			Endif
		*!*	modificare	ROAGEST	v 2.0.144	^
		Endif
	ENDPROC

	PROCEDURE But_start_criterii1.initform
		Lparameters tlShowForm
		DoDefault(tlShowForm)
		Thisform.ed_explicatii_filtru.Refresh()
		This.SetFocus()
	ENDPROC

	PROCEDURE But_start_criterii1.loadcriterii
		If Thisform.lfiltruperioada
			lcStringCriterii = lcStringCriterii + crlf + ;
				"Perioada\" + Alltrim(Thisform.cfiltruperioada) + "\D1\none\"
		Endif
		DoDefault()
	ENDPROC

	PROCEDURE lb_raport_predefinit.Init
		lcNumeContainer = [thisform.] + Thisform.cnume_ct_selectie
		loContainer = &lcNumeContainer
		This.Top = loContainer.Top + Round((loContainer.Height-This.Height)/2,0)
		This.Left = loContainer.Left + Round((loContainer.Width-This.Width)/2,0)
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_date_rapoarte_sql AS frm_date_rapoarte_gen_base OF "orapoarte.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Ct_selectie1" UniqueID="" Timestamp="" />

	*<PropValue>
		cbuton4 = but_reface1
		cbuton7 = but_sterge1;but_nou1
		DoCreate = .T.
		Name = "frm_date_rapoarte_sql"
		nidformularraport = 2
		_shape1.Name = "_shape1"
		_shape1.ZOrderSet = 1
		_shape2.Name = "_shape2"
		_shape2.ZOrderSet = 2
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.ZOrderSet = 3
		Gridsort1.Name = "Gridsort1"
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.ZOrderSet = 5
		But_listare1.Name = "But_listare1"
		But_listare1.ZOrderSet = 6
		But_excel1.Name = "But_excel1"
		But_excel1.ZOrderSet = 7
		But_help1.Name = "But_help1"
		But_help1.ZOrderSet = 8
		But_cautare1.Name = "But_cautare1"
		But_cautare1.ZOrderSet = 9
		But_nou1.Name = "But_nou1"
		But_nou1.Visible = .F.
		But_nou1.ZOrderSet = 13
		But_sterge1.Name = "But_sterge1"
		But_sterge1.ZOrderSet = 10
		ed_explicatii_filtru.Name = "ed_explicatii_filtru"
		ed_explicatii_filtru.Top = 63
		ed_explicatii_filtru.ZOrderSet = 11
		But_salveaza1.Name = "But_salveaza1"
		But_salveaza1.ZOrderSet = 12
		But_reset2.Name = "But_reset2"
		But_reset2.ZOrderSet = 14
		lb_raport_predefinit.Left = 14
		lb_raport_predefinit.Name = "lb_raport_predefinit"
		lb_raport_predefinit.Top = 200
		lb_raport_predefinit.ZOrderSet = 16
		But_start_criterii1.Name = "But_start_criterii1"
		But_start_criterii1.ZOrderSet = 15
	*</PropValue>

	ADD OBJECT 'Ct_selectie1' AS ct_selectie_sql WITH ;
		Left = 12, ;
		Name = "Ct_selectie1", ;
		Top = 63, ;
		ZOrderSet = 0, ;
		edtSelectie.Name = "edtSelectie", ;
		cmdParametri.Name = "cmdParametri", ;
		lb_coloane.Name = "lb_coloane"
		*< END OBJECT: ClassLib="orapoarte.vcx" BaseClass="container" />
	
	PROCEDURE Show
		LPARAMETERS nStyle
		
		DODEFAULT(nStyle)
		* Daca utilizatorul nu are drepturi de pe butonul adaugare, nu ii dau voie nici sa modificare
		* in acest caz modificarea este un raport nou (adaugare)
		this.ct_selectie1.Enabled = this.but_nou1.Visible 
		
	ENDPROC

	PROCEDURE But_start_criterii1.loadcriterii
		PARAMETERS tacriterii
		EXTERNAL ARRAY tacriterii
		#DEFINE crlf CHR(13)+CHR(10)
		lcStringCriterii=""
		DODEFAULT()
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_help_rapoarte AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="ed_text" UniqueID="" Timestamp="" />

	*<PropValue>
		DoCreate = .T.
		Height = 286
		Name = "frm_help_rapoarte"
		Width = 481
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 480
		_shape2.Height = 29
		_shape2.Left = 451
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 31
		Lb_titlu_alb_b121.Caption = "Ajutor generare rapoarte"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		BUT_TERMIN1.Left = 451
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.Top = 1
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT 'ed_text' AS _edbase WITH ;
		Height = 240, ;
		Left = 12, ;
		Name = "ed_text", ;
		ReadOnly = .T., ;
		Top = 36, ;
		Width = 456
		*< END OBJECT: ClassLib="_ed_base.vcx" BaseClass="editbox" />
	
	PROCEDURE Init
		Lparameters tnIdFormular
		Local lnIdFormular
		lnIdFormular = Iif(!Empty(Nvl(tnIdFormular,0)), tnIdFormular, 1)
		
		Local lcCrlf, lcTab
		lcCrlf = Chr(13) + Chr(10)
		lcTab = Chr(9)
		DoDefault()
		If m.lnIdFormular = 1
			This.ed_text.Value = ["Coloane in selectie" : ] + lcCrlf + ;
				lcTab + lcTab + [Daca numele este scris cu verde, atunci valorile coloanei respective pot fi inscrise pe ] + ;
				[coloane in loc de linii (crosstabulare). Pentru aceasta trebuie sa bifati casuta din dreptul numelui si sa faceti click ] + ;
				[dreapta pe el. Numele se va colora in albastru, iar numele coloanelor care se insumeaza vor fi colorate in ] + ;
				[verde.] + lcCrlf + lcCrlf + ;
				lcTab + lcTab + [Se urmeaza acelasi procedeu pentru coloanele cu sume care se doresc a aparea pentru fiecare ] + ;
				[valoare distincta din categoria care a fost selectata cu albastru.] + lcCrlf + ;
				lcTab + lcTab + [Diferenta este ca dintre cele care nu se insumeaza, doar valorile uneia pot fi aranjate pe ] + ;
				[coloane, in timp ce dintre cele care se insumeaza se pot selecta oricate.] + lcCrlf + ;
				lcTab + lcTab + [ATENTIE!!! Daca ati selectat o coloana pentru crosstabulare, atunci trebuie sa selectati ] + ;
				[pentru crosstabulare cel putin o coloana dintre cele care se insumeaza.]
		
		Else
			This.ed_text.Value = [Apasati pe butonul Binoclu pentru a completa valorile parametrilor : ] + lcCrlf + ;
				[Ex: In dreptul parametrului Ziua curenta zzllaaaa, completati 01012010]
		Endif
		
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_optiuni_rapoarte AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="opt_rapoarte" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grd_rapoarte" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grd_rapoarte.cDenumire.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grd_rapoarte.cDenumire.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grd_rapoarte.cTitlu.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grd_rapoarte.cTitlu.Text1" UniqueID="" Timestamp="" />

	*<PropValue>
		DoCreate = .T.
		Height = 320
		Name = "frm_optiuni_rapoarte"
		Width = 588
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 588
		_shape2.Height = 29
		_shape2.Left = 524
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 64
		Lb_titlu_alb_b121.Caption = "RAPOARTE"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		BUT_TERMIN1.Left = 557
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.Top = 1
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 526, ;
		Name = "But_renunt1", ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'grd_rapoarte' AS _grdrow WITH ;
		ColumnCount = 2, ;
		DeleteMark = .F., ;
		Enabled = .F., ;
		FontItalic = .T., ;
		FontName = "Arial Narrow", ;
		ForeColor = 128,128,128, ;
		Height = 221, ;
		Left = 23, ;
		Name = "grd_rapoarte", ;
		Panel = 1, ;
		RecordSource = "crsrapoarte", ;
		Top = 79, ;
		Width = 541, ;
		Column1.ControlSource = "denumire", ;
		Column1.Enabled = .F., ;
		Column1.FontItalic = .T., ;
		Column1.FontName = "Arial Narrow", ;
		Column1.ForeColor = 128,128,128, ;
		Column1.Name = "cDenumire", ;
		Column1.ReadOnly = .T., ;
		Column1.Width = 276, ;
		Column2.ControlSource = "titlu", ;
		Column2.Enabled = .F., ;
		Column2.FontItalic = .T., ;
		Column2.FontName = "Arial Narrow", ;
		Column2.ForeColor = 128,128,128, ;
		Column2.Name = "cTitlu", ;
		Column2.ReadOnly = .T., ;
		Column2.Width = 231
		*< END OBJECT: ClassLib="_grd_base.vcx" BaseClass="grid" />

	ADD OBJECT 'grd_rapoarte.cDenumire.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Denumire", ;
		FontItalic = .T., ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'grd_rapoarte.cDenumire.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		Enabled = .F., ;
		FontItalic = .T., ;
		FontName = "Arial Narrow", ;
		ForeColor = 128,128,128, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'grd_rapoarte.cTitlu.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Titlu", ;
		FontItalic = .T., ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'grd_rapoarte.cTitlu.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		Enabled = .F., ;
		FontItalic = .T., ;
		FontName = "Arial Narrow", ;
		ForeColor = 128,128,128, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'opt_rapoarte' AS _optiongrup WITH ;
		AutoSize = .F., ;
		Height = 276, ;
		Left = 12, ;
		Name = "opt_rapoarte", ;
		Top = 36, ;
		Width = 564, ;
		OPTION1.AutoSize = .T., ;
		OPTION1.Caption = "Raport nou", ;
		OPTION1.Left = 5, ;
		OPTION1.Name = "OPTION1", ;
		OPTION1.Top = 5, ;
		OPTION2.AutoSize = .T., ;
		OPTION2.Caption = "Raport existent", ;
		OPTION2.Left = 5, ;
		OPTION2.Name = "OPTION2", ;
		OPTION2.Top = 24
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="optiongroup" />
	
	PROCEDURE inainte_de_do_termin
		If Thisform.opt_rapoarte.Value = 1
			pnIdRaport = 0
		Else
			Select crsrapoarte
			pnIdRaport = id_raport
		Endif
		Return .T.
	ENDPROC

	PROCEDURE opt_rapoarte.InteractiveChange
		If This.Value = 2
			thisform.grd_rapoarte.FontItalic = .F.
			thisform.grd_rapoarte.ForeColor = Rgb(0,0,0)
			Thisform.grd_rapoarte.Enabled = .T.
			Thisform.grd_rapoarte.SetFocus()
		Else
			thisform.grd_rapoarte.FontItalic = .T.
			thisform.grd_rapoarte.ForeColor = Rgb(128,128,128)
			Thisform.grd_rapoarte.Enabled = .F.
		Endif
		
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_optiuni_rapoarte_sql AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cboFieldType" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="clbCaption" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="clbFieldSearchId" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="clbFieldSearch" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ed_tx_simplu1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ed_tx_simplu1._lbbase2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdParametri" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdParametri.cParametru.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdParametri.cParametru.Text1" UniqueID="" Timestamp="" />

	*<PropValue>
		DoCreate = .T.
		Height = 320
		Name = "frm_optiuni_rapoarte_sql"
		Width = 509
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 588
		_shape2.Height = 29
		_shape2.Left = 446
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 64
		Lb_titlu_alb_b121.Caption = "OPTIUNI"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 8
		BUT_TERMIN1.Left = 478
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 6
		BUT_TERMIN1.Top = 1
		Gridsort1.Left = 9
		Gridsort1.Name = "Gridsort1"
		Gridsort1.Top = 33
	*</PropValue>

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 447, ;
		Name = "But_renunt1", ;
		TabIndex = 7, ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cboFieldType' AS cb_tx_simplu WITH ;
		Height = 29, ;
		Left = 144, ;
		Name = "cboFieldType", ;
		TabIndex = 3, ;
		Top = 200, ;
		Width = 264, ;
		_cbbase1.ControlSource = "crsParametri.tipcamp", ;
		_cbbase1.Height = 23, ;
		_cbbase1.Left = 68, ;
		_cbbase1.Name = "_cbbase1", ;
		_cbbase1.RowSource = "C,N,D,D1,E,A", ;
		_cbbase1.RowSourceType = 1, ;
		_cbbase1.ToolTipText = "C = caracter, N = numar, D = data, D1 = perioada, E = expresie, A = lista valori", ;
		_cbbase1.Top = 3, ;
		_cbbase1.Width = 185, ;
		_lbbase1.Caption = "Tip camp", ;
		_lbbase1.Name = "_lbbase1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'clbCaption' AS clb_tx_simplu WITH ;
		Height = 29, ;
		Left = 144, ;
		Name = "clbCaption", ;
		TabIndex = 1, ;
		Top = 48, ;
		Width = 264, ;
		Text_simplu1.ControlSource = "crsParametri.titlu", ;
		Text_simplu1.Format = "K", ;
		Text_simplu1.Height = 23, ;
		Text_simplu1.Left = 68, ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Top = 3, ;
		Text_simplu1.Width = 184, ;
		Lb_simplu1.Caption = "Titlu", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'clbFieldSearch' AS clb_tx_simplu WITH ;
		Height = 29, ;
		Left = 144, ;
		Name = "clbFieldSearch", ;
		TabIndex = 5, ;
		Top = 272, ;
		Width = 264, ;
		Text_simplu1.ControlSource = "crsParametri.campcautare", ;
		Text_simplu1.Left = 70, ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Top = 3, ;
		Lb_simplu1.Caption = "Cautare", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'clbFieldSearchId' AS clb_tx_simplu WITH ;
		Height = 29, ;
		Left = 144, ;
		Name = "clbFieldSearchId", ;
		TabIndex = 4, ;
		Top = 236, ;
		Width = 264, ;
		Text_simplu1.ControlSource = "crsParametri.campid", ;
		Text_simplu1.Height = 23, ;
		Text_simplu1.Left = 101, ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Top = 3, ;
		Text_simplu1.Width = 152, ;
		Lb_simplu1.Caption = "Camp ID cautare", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ed_tx_simplu1' AS ed_tx_simplu WITH ;
		Height = 106, ;
		Left = 144, ;
		Name = "Ed_tx_simplu1", ;
		TabIndex = 2, ;
		Top = 89, ;
		Width = 361, ;
		_edbase1.ControlSource = "crsParametri.camp", ;
		_edbase1.Height = 97, ;
		_edbase1.Left = 68, ;
		_edbase1.Name = "_edbase1", ;
		_edbase1.ReadOnly = .T., ;
		_edbase1.Top = 2, ;
		_edbase1.Width = 284, ;
		_lbbase1.Caption = "Camp /", ;
		_lbbase1.Name = "_lbbase1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ed_tx_simplu1._lbbase2' AS _lbbase WITH ;
		Caption = "Expresie", ;
		Left = 8, ;
		Name = "_lbbase2", ;
		Top = 25
		*< END OBJECT: ClassLib="_lb_base.vcx" BaseClass="label" />

	ADD OBJECT 'grdParametri' AS _grdbase WITH ;
		ColumnCount = 1, ;
		DeleteMark = .F., ;
		Height = 252, ;
		Left = 12, ;
		Name = "grdParametri", ;
		Panel = 1, ;
		ReadOnly = .T., ;
		RecordSource = "crsParametri", ;
		ScrollBars = 2, ;
		TabIndex = 9, ;
		Top = 48, ;
		Width = 121, ;
		Column1.ControlSource = "crsParametri.parametru", ;
		Column1.Name = "cParametru", ;
		Column1.ReadOnly = .T., ;
		Column1.Width = 86
		*< END OBJECT: ClassLib="_grd_base.vcx" BaseClass="grid" />

	ADD OBJECT 'grdParametri.cParametru.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Parametru", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'grdParametri.cParametru.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: BaseClass="textbox" />
	
	PROCEDURE grdParametri.AfterRowColChange
		LPARAMETERS nColIndex
		thisform.Refresh()
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_raport_nou AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ed_denumire" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ed_titlu" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*p: nid
		*p: orec
	*</DefinedPropArrayMethod>

	*<PropValue>
		DoCreate = .T.
		Height = 190
		Name = "frm_raport_nou"
		Width = 374
		_shape1.Name = "_shape1"
		_shape2.Height = 29
		_shape2.Left = 312
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 64
		Lb_titlu_alb_b121.Caption = "DATE RAPORT"
		Lb_titlu_alb_b121.FontBold = .T.
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 5
		BUT_TERMIN1.Left = 344
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 3
		BUT_TERMIN1.Top = 1
		GRIDSORT1.Name = "GRIDSORT1"
	*</PropValue>

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 314, ;
		Name = "But_renunt1", ;
		TabIndex = 4, ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ed_denumire' AS ed_tx_simplu WITH ;
		Height = 58, ;
		Left = 13, ;
		Name = "Ed_denumire", ;
		TabIndex = 1, ;
		Top = 48, ;
		Width = 347, ;
		_edbase1.ControlSource = "pcDenumireRaport", ;
		_edbase1.Format = "!", ;
		_edbase1.Height = 53, ;
		_edbase1.Left = 65, ;
		_edbase1.Name = "_edbase1", ;
		_edbase1.Top = 2, ;
		_edbase1.Width = 279, ;
		_lbbase1.Caption = "Denumire", ;
		_lbbase1.Left = 5, ;
		_lbbase1.Name = "_lbbase1", ;
		_lbbase1.Top = 6
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ed_titlu' AS ed_tx_simplu WITH ;
		Height = 58, ;
		Left = 13, ;
		Name = "Ed_titlu", ;
		TabIndex = 2, ;
		Top = 105, ;
		Width = 347, ;
		_edbase1.ControlSource = "pcTitluRaport", ;
		_edbase1.Format = "!", ;
		_edbase1.Height = 53, ;
		_edbase1.Left = 65, ;
		_edbase1.Name = "_edbase1", ;
		_edbase1.Top = 2, ;
		_edbase1.Width = 279, ;
		_lbbase1.Caption = "Titlu", ;
		_lbbase1.Left = 5, ;
		_lbbase1.Name = "_lbbase1", ;
		_lbbase1.Top = 6
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />
	
	PROCEDURE inainte_de_do_termin
		Local llReturn
		llReturn = .F.
		Do Case
		Case Empty(Nvl(pcDenumireRaport,[]))
			amessagebox("Nu ati completat denumirea raportului!",48,"Atentie")
			Thisform.ed_denumire.SetFocus()
		Case Empty(Nvl(pcTitluRaport,[]))
			amessagebox("Nu ati completat titlul raportului!",48,"Atentie")
			Thisform.ed_titlu.SetFocus()
		Otherwise
			Private pcMesajVerificare
			pcMesajVerificare = []
			lcSql = [{call pack_rapoarte.verifica_detalii_raport(?pcDenumireRaport,?pcTitluRaport,?@pcMesajVerificare)}]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,16,"Eroare")
				llReturn = .F.
			Else
				If Empty(Nvl(pcMesajVerificare,[]))
					llReturn = .T.
				Else
					amessagebox(pcMesajVerificare,48,"Atentie")
					If Like(Chr(13)+Chr(10)+'*',pcMesajVerificare)
						Thisform.ed_titlu.SetFocus()
					Else
						Thisform.ed_denumire.SetFocus()
					Endif
					llReturn = .F.
				Endif
			Endif
		Endcase
		Return llReturn
		
	ENDPROC

ENDDEFINE
