*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="onom_retete.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS ct_retetar AS _ctfrmbase OF "_ct_base.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_grid_search1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_listare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_nou1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_sterge1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_nou2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_sterge2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_modifica1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_reset1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_reset2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_copie" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cb_tx_cautare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Lb_cautare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_reset3" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_adauga_in_retetar
		*m: do_cauta_materiale
		*m: do_reset_cautare
		*p: cantf
		*p: canti
		*p: cfiltruoriginalreteta
		*p: colf
		*p: coli
		*p: nid_produs
		*p: ntip
		*p: rowf
		*p: rowi
	*</DefinedPropArrayMethod>

	*<PropValue>
		BackStyle = 0
		cantf = 0
		canti = 0
		cfiltruoriginalreteta = 
		colf = 0
		coli = 0
		Height = 614
		Name = "ct_retetar"
		nid_produs = 0
		ntip = 1
		rowf = 0
		rowi = 0
		Width = 644
		Gridsort1.Left = 24
		Gridsort1.Name = "Gridsort1"
		Gridsort1.Top = 4
		_ct_controller_keypress1.Left = 134
		_ct_controller_keypress1.Name = "_ct_controller_keypress1"
		_ct_controller_keypress1.Top = 127
	*</PropValue>

	ADD OBJECT 'But_copie' AS but_grafic WITH ;
		Anchor = 9, ;
		caction = do_copiaza, ;
		cpicturedown = copy_jos.bmp, ;
		cpictureup = copy_sus.bmp, ;
		Left = 605, ;
		Name = "But_copie", ;
		Picture = ..\grafice\copy_sus.bmp, ;
		TabIndex = 9, ;
		ToolTipText = "Copiere reteta", ;
		Top = 5, ;
		ZOrderSet = 13
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

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

	ADD OBJECT 'But_modifica1' AS but_modifica WITH ;
		Anchor = 9, ;
		Left = 488, ;
		Name = "But_modifica1", ;
		TabIndex = 10, ;
		Top = 17
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

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

	ADD OBJECT 'But_nou2' AS but_nou WITH ;
		Anchor = 12, ;
		Left = 487, ;
		Name = "But_nou2", ;
		TabIndex = 6, ;
		Top = 339
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_reset1' AS but_reset WITH ;
		Anchor = 8, ;
		Left = 575, ;
		Name = "But_reset1", ;
		TabIndex = 11, ;
		Top = 50
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_reset2' AS but_reset WITH ;
		Anchor = 12, ;
		Left = 575, ;
		Name = "But_reset2", ;
		TabIndex = 12, ;
		Top = 373
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_reset3' AS but_reset WITH ;
		Anchor = 12, ;
		caction = do_reset_cautare, ;
		Left = 454, ;
		Name = "But_reset3", ;
		TabIndex = 14, ;
		Top = 307
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_sterge1' AS but_sterge WITH ;
		Anchor = 9, ;
		Left = 517, ;
		Name = "But_sterge1", ;
		TabIndex = 3, ;
		Top = 17
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_sterge2' AS but_sterge WITH ;
		Anchor = 12, ;
		Left = 517, ;
		Name = "But_sterge2", ;
		TabIndex = 8, ;
		Top = 339, ;
		Visible = .T.
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Cb_tx_cautare1' AS cb_tx_cautare WITH ;
		Height = 27, ;
		Left = 175, ;
		Name = "Cb_tx_cautare1", ;
		TabIndex = 4, ;
		Top = 307, ;
		Width = 277, ;
		Text.Height = 25, ;
		Text.Left = 103, ;
		Text.Name = "Text", ;
		Text.Top = 1, ;
		Text.Width = 172, ;
		Criteriu.Name = "Criteriu"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_search1' AS ct_grid_search WITH ;
		Anchor = 15, ;
		Height = 276, ;
		Left = 12, ;
		Name = "Ct_grid_search1", ;
		TabIndex = 1, ;
		Top = 13, ;
		Width = 540, ;
		_GRID1.Height = 228, ;
		_GRID1.HighlightStyle = 2, ;
		_GRID1.Left = 6, ;
		_GRID1.Name = "_GRID1", ;
		_GRID1.Top = 36, ;
		_GRID1.Width = 529, ;
		Titlu.Left = 6, ;
		Titlu.Name = "Titlu", ;
		Titlu.Top = 9, ;
		Cb_tx_cautare1.Anchor = 10, ;
		Cb_tx_cautare1.criteriu.Name = "criteriu", ;
		Cb_tx_cautare1.Height = 27, ;
		Cb_tx_cautare1.Left = 162, ;
		Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Cb_tx_cautare1.Text.Name = "Text", ;
		Cb_tx_cautare1.Text.Width = 173, ;
		Cb_tx_cautare1.Top = 4, ;
		Cb_tx_cautare1.Width = 277
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_search2' AS ct_grid_search WITH ;
		Anchor = 14, ;
		Height = 268, ;
		Left = 12, ;
		Name = "Ct_grid_search2", ;
		TabIndex = 5, ;
		Top = 335, ;
		Width = 539, ;
		_GRID1.Height = 229, ;
		_GRID1.Left = 6, ;
		_GRID1.Name = "_GRID1", ;
		_GRID1.Top = 37, ;
		_GRID1.Width = 529, ;
		Titlu.Left = 6, ;
		Titlu.Name = "Titlu", ;
		Titlu.Top = 9, ;
		Cb_tx_cautare1.criteriu.Name = "criteriu", ;
		Cb_tx_cautare1.Left = 163, ;
		Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Cb_tx_cautare1.Text.Name = "Text", ;
		Cb_tx_cautare1.Text.Width = 173, ;
		Cb_tx_cautare1.Top = 4, ;
		Cb_tx_cautare1.Width = 277
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Lb_cautare' AS lb_simplu WITH ;
		Caption = "Retete care au in componenta articolele a caror denumire corespunde criteriului :", ;
		Left = 22, ;
		Name = "Lb_cautare", ;
		TabIndex = 13, ;
		Top = 288
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />
	
	PROCEDURE actualizeaza_cursoare
		If (!Used('crsRetete') And !Used('crsMateriale')) Or gcS!=This.cSchema
			This.creeaza_cursoare()
			This.cSchema=gcS
		Endif
		
	ENDPROC

	PROCEDURE creeaza_cursoare
		pnIdReteta = 0
		
		lcSelect1 = ['select id_reteta,id_articol,codmat,denumire,cod,principala,explicatie ] + ;
			[ from ] + gcS + [.vnom_retetar where 1=2']
		lcCursor1 = [crsRetete]
		lcSchema1 = ['']
		lcOrder1 = [denumire]
		lcFiltru1 = [1=1]
		lcNume_coloane1= [codmat;denumire;cod;principala;explicatie;]
		lcTitlu_coloane1 = [Cod produs,Denumire,Cod tehnologic,Principala,Explicatie]
		lcNrColoaneCheck = [5]
		
		lcSelect2 = ['select id_reteta_elem,id_reteta,id_articol,codmat,denumire,'+] +;
			['um,cont,cantitate from ] + gcS + [.vnom_retetar_elemente where 1=2']
		lcCursor2 = [crsMateriale]
		lcSchema2 = ['id_reteta_elem n(20),id_reteta n(20),id_articol n(20),codmat c(50),' +] +;
			['denumire c(100),um c(6),cont c(4),cantitate n(12,4)']
		lcOrder2 = [denumire]
		lcFiltru2 = [id_reteta = ?pnIdReteta ]
		lcNume_coloane2= [codmat;denumire;um;cont;cantitate]
		lcTitlu_coloane2 = [Cod material,Denumire,Unitate de masura,Cont,Cantitate]
		
		With This.ct_grid_search1
			.cSelect = lcSelect1
			.cSchema = lcSchema1
			.cFiltruOriginal = lcFiltru1
			.cFiltru = lcFiltru1
			.cTitlu = 'PRODUSE'
			.corder = lcOrder1
			.cnume_coloane = lcNume_coloane1
			.ctitlu_coloane = lcTitlu_coloane1
			.cnumecursor = lcCursor1
			.cnrcoloane_check = lcNrColoaneCheck
		Endwith
		
		*!*	modificare	ROAGRESTAURANT 0.0.19
		This.cfiltruoriginalreteta = This.ct_grid_search1.cFiltruOriginal
		*!*	modificare	ROAGRESTAURANT 0.0.19	^
		
		With This.ct_grid_search2
			.cSelect = lcSelect2
			.cSchema = lcSchema2
			.cFiltruOriginal = lcFiltru2
			.cFiltru = [1=1]
			.cTitlu = 'FISA TEHNOLOGICA'
			.corder = lcOrder2
			.cnume_coloane = lcNume_coloane2
			.ctitlu_coloane = lcTitlu_coloane2
			.cnumecursor = lcCursor2
		Endwith
		
		This.ct_grid_search1.initializare(.T.)
		Select crsRetete
		Go Top
		pnIdReteta = crsRetete.id_reteta
		This.ct_grid_search2.initializare(.T.)
		This.ct_grid_search2._GRID1.column6.ReadOnly = .F.
		
	ENDPROC

	PROCEDURE do_adauga
		Local lntip
		lntip = This.ntip
		
		Private pcLista_art
		Store '' To pcLista_art
		
		lcAlias1 = This.ct_grid_search1.cnumecursor
		lcAlias2 = This.ct_grid_search2.cnumecursor
		Do Case
			Case lntip = 1 && Produse
				Select (lcAlias1)
				Scatter Name loRec Blank
				lnIdRetetaTemp = pnIdReteta
				pnIdReteta = 0
				Do Adauga_Modifica_Inregistrare With "reteta",loRec,,"INSERT"
				lnIdRetetaAdaugare = pnIdReteta
				pnIdReteta = lnIdRetetaTemp
				If !Empty(lnIdRetetaAdaugare)
					pcLista_art = []
					*!*			lcFiltru = [ SUBSTR(TRIM(cont),1,1) = '3']
					pcLista_art = This.do_cauta_materiale()
					If !Empty(pcLista_art)
						This.do_adauga_in_retetar(lnIdRetetaAdaugare,pcLista_art)
					Else
						This.ct_grid_search1.actualizeaza_grid()
					Endif
				Endif
		
			Case lntip = 2 && Materiale
		
				*!*	modificare ROAPRODUCTIE v 2.0.2
				If Reccount(lcAlias1) > 0
				*!*	modificare ROAPRODUCTIE v 2.0.2	^
					*!*		lcFiltru = [ SUBSTR(TRIM(cont),1,1) = '3']
					*!*		DO viz_catalog_articole WITH .f.,.t.,lcFiltru,.t.,[Alegeti materialele] in oproceduri_articole.prg
					Select (lcAlias1)
					lnIdReteta = id_reteta
					lcFiltru = [ and id_articol not in (select id_articol from nom_retetar_elemente where id_reteta=]+Alltrim(Str(lnIdReteta))+;
						[ and sters=0)]
					pcLista_art = This.do_cauta_materiale(lcFiltru)
					If !Empty(pcLista_art)
						This.do_adauga_in_retetar(lnIdReteta,pcLista_art)
					Endif
				*!*	modificare ROAPRODUCTIE v 2.0.2
				Else
					amessagebox("Nu ati selectat produsul!",48,"Atentie")
				Endif
				*!*	modificare ROAPRODUCTIE v 2.0.2
		Endcase
		
	ENDPROC

	PROCEDURE do_adauga_in_retetar
		Parameters tnIdReteta,tcLista_Mat
		Local lntip
		lntip = This.ntip
		
		lnIdReteta = tnIdReteta
		lcLista_Mat = tcLista_Mat
		
		lnMat = Occurs(',',lcLista_Mat)
		
		If Right(lcLista_Mat,1) # ','
			lcLista_Mat = lcLista_Mat + ','
		Endif
		If Left(lcLista_Mat,1) # ','
			lcLista_Mat = ',' + lcLista_Mat
		Endif
		
		*!*	modificare ROAGEST v 2.0.
		*!*	*!*	modificare ROAPRODUCTIE v 2.0.2
		*!*	IF (RECCOUNT(lcAlias1)=0 AND lnTip = 1) OR (RECCOUNT(lcAlias2)=0 AND lnTip=2)
		IF RECCOUNT(lcAlias1) = 0 AND lnTip = 2
		*!*	modificare ROAGEST v 2.0.	^
			amessagebox("Nu ati selectat reteta!",48,"Atentie")
			RETURN
		ENDIF
		*!*	modificare ROAPRODUCTIE v 2.0.2	^
		
		lcAlias1 = This.ct_grid_search1.cnumecursor
		lcAlias2 = This.ct_grid_search2.cnumecursor
		For i=1 To lnMat+1
			lcId_material = Strextract(lcLista_Mat,[,],[,],i)
		
			lcSql = [begin pack_retete.adauga_material(] + Alltrim(Str(lnIdReteta)) + [,] + ;
			lcId_material + [,] + ALLTRIM(STR(gnIdUtil)) +[); end;]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				lcTextEroare = goExecutor.oPrelucrareEroare()
				lcMesaj = "Adaugarea nu s-a realizat!" + Chr(13) + Chr(10) + lcTextEroare
				AMESSAGEBOX(lcMesaj,0+16,"Atentie")
		*!*			Return
			Endif
		Endfor
		
		This.ct_grid_search1.actualizeaza_grid
		This.ct_grid_search2.actualizeaza_grid
		
		Select (lcAlias1)
		Locate For id_reteta = lnIdReteta
		This.ct_grid_search1.SetFocus
		
		If lntip = 2
			This.ct_grid_search2.SetFocus
		Endif
	ENDPROC

	PROCEDURE do_cauta
		*!*	modificare	ROAGRESTAURANT 0.0.19
		Local lcFiltru,lcValoare,lcCriteriu,lnCriteriu
		lcValoare = Strtran(Alltrim(Upper(This.cb_tx_cautare1.Text.Value)),['],[''])
		lnCriteriu = VAL(This.cb_tx_cautare1.criteriu.Value)
		lcFiltru = [ AND ID_RETETA IN (SELECT DISTINCT ID_RETETA FROM VNOM_RETETAR_ELEMENTE WHERE DENUMIRE ]
		Do Case
			Case lnCriteriu = 1 And !Empty(lcValoare)
				lcFiltru = lcFiltru + [ LIKE '] + lcValoare + [%')]
			Case lnCriteriu = 2 And !Empty(lcValoare)
				lcFiltru = lcFiltru + [ ='] + lcValoare + [')]
			Case lnCriteriu = 3 And !Empty(lcValoare)
				lcFiltru = lcFiltru + [ !='] + lcValoare + [')]
			Case lnCriteriu = 4 And !Empty(lcValoare)
				lcFiltru = lcFiltru + [ LIKE '%] + lcValoare + [%')]
			Case lnCriteriu = 5 And !Empty(lcValoare)
				lcFiltru = lcFiltru + [ NOT LIKE '%] + lcValoare + [%')]
			Otherwise
				lcFiltru = []
		Endcase
		This.ct_grid_search1.cfiltruoriginal = This.cfiltruoriginalreteta + lcFiltru
		lcCriteriu = This.ct_grid_search1.cb_tx_cautare1.criteriu.Value
		lcValoare = This.ct_grid_search1.cb_tx_cautare1.Text.Value
		If lcCriteriu <> "6" And Empty(lcValoare)
			This.ct_grid_search1.cb_tx_cautare1.criteriu.Value = "6"
			This.ct_grid_search1.cb_tx_cautare1.Text.Value = ""
		Endif
		This.ct_grid_search1.do_cauta()
		*!*	modificare	ROAGRESTAURANT 0.0.19	^
	ENDPROC

	PROCEDURE do_cauta_materiale
		Lparameters tcFiltru
		Local lcArticole, lcXMLArticole,lcFiltru
		lcArticole = ""
		lcFiltru = Iif(Empty(tcFiltru),[],tcFiltru)
		lcXMLArticole = cauta_nom_articole([(a.cont='301' or a.cont like '302%' or a.cont like '34%' or a.in_stoc = 0)] + lcFiltru)
		
		If !Empty(lcXMLArticole)
		
			Xmltocursor(lcXMLArticole, "crsArticoleTemp")
			lcArticole = cursor2lista("crsArticoleTemp", "id_articol", ",")
			Use In crsArticoleTemp
		Endif
		
		Return lcArticole
		
	ENDPROC

	PROCEDURE do_copiaza
		Local lcTabel, lnIdReteta_dest, lcDenumire_Dest, lnIdReteta_Sursa, lcDenumire_sursa, lnRaspuns, lcSql, lnSucces
		lcTabel = This.ct_grid_search1._GRID1.RecordSource
		Select (lcTabel)
		If Recno() = 0
			aMESSAGEBOX("Nu ati selectat produsul!",48,"Atentie")
			Return
		Endif
		
		Select (lcTabel)
		lnIdReteta_sursa = id_reteta
		lcDenumire_sursa = Alltrim(denumire)
		lcCod_sursa = Alltrim(Nvl(cod,[]))
		If Empty(lnIdReteta_sursa)
			Return
		Endif
		
		Local lcselect, lcfiltru, lcschema, lcorder, lccoloane, lcTitlu, lcTitluColoane, lcFiltruOriginal, lcNumeProc
		lcselect = [select id_reteta,id_articol,codmat,denumire,cod,explicatie FROM vnom_retetar]
		lcfiltru = [2=2]
		lcschema = []
		lcorder = [denumire]
		lccoloane = [denumire, codmat, explicatie]
		* lcTitlu = [Alegeti reteta pe care doriti s-o copiati]
		lcTitlu = [Alegeti produsul pentru care doriti sa inlocuiti fisa cu cea selectata]
		lcTitluColoane = [Denumire, Cod material ]
		lcFiltruOriginal = [id_reteta <> ]+Alltrim(Str(lnIdReteta_sursa))
		lcNumeProc = ""
		locauta = cauta_alfa(lcselect, lcfiltru, lcschema, lcorder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, .F., lcFiltruOriginal)	&& 11.07.2007
		
		If !Empty(locauta.id_articol)
			lnIdReteta_dest = locauta.id_reteta
			lcDenumire_dest = Alltrim(locauta.denumire)
			lcCod_dest = Alltrim(Nvl(locauta.cod,[]))
		
			lnRaspuns = AMESSAGEBOX([Doriti sa copiati fisa tehnologica a produsului ] + lcDenumire_sursa + ;
				IIF(!Empty(lcCod_Sursa),[ (cod: ] + lcCod_Sursa + [ ) ],[ ]) + ;
				[in cea a produsului ] + lcDenumire_Dest + Iif(!Empty(lcCod_Dest),[ (cod: ] + lcCod_Dest + [ ) ],[ ]) + ;
				[?],4+32,'Copiere fisa tehnologica')
			If lnRaspuns = 7
				Return
			Endif
		
			lcSql = [begin pack_retete.copiaza_reteta(] + Alltrim(Str(lnIdReteta_Sursa)) + [,] + ;
				Alltrim(Str(lnIdReteta_dest)) + [,] + Alltrim(Str(gnIdUtil)) +[); end;]
			lnSucces = goExecutor.oExecute(lcSql)
		
			If lnSucces < 0
				aMessagebox(goExecutor.oPrelucrareEroare(),0+16,"Eroare")
			Endif
		
			This.ct_grid_search2.actualizeaza_grid()
		Endif
		
	ENDPROC

	PROCEDURE do_listare
		Private poListRetetar
		Store '' To poListRetetar
		
		pcDataOra = get_ora(2)
		
		Local lcCriteriu
		lcCriteriu = This.ct_grid_search1.ocursor.ca_baza1.cfiltru
		If Type("lcCriteriu") <> "C"
			lcCriteriu = [2=2]
		Endif
		
		Local lcSchema1, lcSelect1, lcOrder1, lcFiltru1, llAfiseaza
		lcSelect1 = [select id_reteta, NVL(denumire,'') as denumire, cod, explicatie, NVL(denumire_mat,'') as denumire_mat,]+;
			[NVL(codmat_mat,'') as codmat_mat, NVL(um_mat,'') as um_mat, NVL(cantitate,0) as cant_mat from ] + gcS + [.prod_vrap_retetar ]
		lcOrder1 = [denumire, id_reteta, denumire_mat]
		lcgroup = []
		lcFiltru1 = lcCriteriu
		lcFiltruOriginal = []
		llModParam = .T.
		llAfiseaza = .F.
		
		gencursor('poListRetetar','cListRetetar', lcSelect1, lcFiltru1, lcSchema1, lcOrder1, llAfiseaza,  lcgroup, llModParam, lcFiltruOriginal)
		poListRetetar.ca_baza1.afisare()
		
		If Reccount('cListRetetar')>0
			If Type('this.parent.alwaysontop')<>'U'
				This.Parent.AlwaysOnTop=.F.
			Endif
		
			Select cListRetetar
			Report Form rap_retetar To Printer Prompt Preview
		
			If Type('this.parent.alwaysontop')<>'U'
				This.Parent.AlwaysOnTop=.T.
			Endif
		Else
			amessagebox("Nu exista inregistrari pentru listare!",0+48,"Atentie")
		Endif
		
		If Used("cListRetetar")
			Use In cListRetetar
		Endif
		
		Release poListRetetar
		
	ENDPROC

	PROCEDURE do_reset
		Local lntip
		lntip = This.ntip
		
		Do Case
		Case lntip=1
			With This.ct_grid_search1
				*!*	modificare ROAPRODUCTIE v 2.0.2
		*!*			.ocursor.ca_baza1.cfiltru=.cfiltruoriginal
				.cb_tx_cautare1.Text.Value=[]
				.do_cauta()
				*!*	modificare ROAPRODUCTIE v 2.0.2	^
			Endwith
		Case lntip=2
			With This.ct_grid_search2
				*!*	modificare ROAPRODUCTIE v 2.0.2
		*!*			.ocursor.ca_baza1.cfiltru=.cfiltruoriginal
				.cb_tx_cautare1.Text.Value=[]
				.do_cauta()
				*!*	modificare ROAPRODUCTIE v 2.0.2	^
			Endwith
		Endcase
	ENDPROC

	PROCEDURE do_reset_cautare
		*!*	modificare	ROAGRESTAURANT 0.0.19
		This.cb_tx_cautare1.Text.Value = []
		This.cb_tx_cautare1.criteriu.Value = "1"
		*!*	modificare	ROAGRESTAURANT 0.0.19	^
	ENDPROC

	PROCEDURE do_sterge
		Local lntip
		lntip = This.ntip
		
		lcAlias1 = This.ct_grid_search1.cnumecursor
		lcAlias2 = This.ct_grid_search2.cnumecursor
		
		*!*	modificare ROAPRODUCTIE v 2.0.2
		If (Reccount(lcAlias1)=0 And lntip = 1) Or (Reccount(lcAlias2)=0 And lntip = 2)
			amessagebox("Nu exista inregistrari pentru stergere!",48,"Atentie")
			Return
		Endif
		*!*	modificare ROAPRODUCTIE v 2.0.2	^
		
		Do Case
			Case lntip = 1 && Produse
				Select (lcAlias1)
				If amessagebox("Sunteti sigur ca doriti sa stergeti fisa tehnologica pentru "+Alltrim(denumire)+" ?",4+32,"Confirmare stergere")= 7
					This.ct_grid_search1.SetFocus()
					Return
				Endif
				lcIdReteta = Alltrim(Str(id_reteta))
				lcSql = [begin pack_retete.sterge_reteta(] + lcIdReteta + [,] + Alltrim(Str(gnIdUtil)) + [); end;]
			Case lntip = 2 && Materiale
				Select (lcAlias2)
				lcIdRetetaElem = Alltrim(Str(id_reteta_elem))
				*!*		lcIdMaterial = Alltrim(Str(id_articol))
				lcSql = [begin pack_retete.sterge_material(] + lcIdRetetaElem + [,] + ;
					Alltrim(Str(gnIdUtil)) + [); end;]
		Endcase
		
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			lcTextEroare = goExecutor.oPrelucrareEroare()
			lcMesaj = "Stergerea nu s-a realizat!" + Chr(13) + Chr(10) + lcTextEroare
			ofrm_er =Createobject('frm_mesaj',[Atentie],[exclam.ico],[Avertizare],lcMesaj)
			ofrm_er.Show()
			Release ofrm_er
			Return
		Endif
		
		This.ct_grid_search1.actualizeaza_grid
		This.ct_grid_search2.actualizeaza_grid
		This.ct_grid_search1.SetFocus
		This.ct_grid_search1.Refresh
		
		If lntip = 2
			This.ct_grid_search2.SetFocus
		Endif
		
		*!*	lcFocus = [this.ct_grid_search] + ALLTRIM(STR(lntip)) + [.SetFocus]
		*!*	&lcFocus
	ENDPROC

	PROCEDURE inainte_de_do_modifica
		Local lntip
		lntip = This.ntip
		
		lcAlias1 = This.ct_grid_search1.cnumecursor
		Do Case
			Case lntip = 1 && Produse
				*!*	modificare ROAPRODUCTIE v 2.0.2
				If Reccount(lcAlias1) > 0
					*!*	modificare ROAPRODUCTIE v 2.0.2	^
					Select (lcAlias1)
					Scatter Name loRec
					lnIdRetetaTemp = pnIdReteta
					pnIdReteta = 0
					Do Adauga_Modifica_Inregistrare With "reteta",loRec,loRec.Id_reteta,"UPDATE"
					This.ct_grid_search1.actualizeaza_grid()
					*!*	modificare ROAPRODUCTIE v 2.0.2
				Else
					amessagebox("Nu exista inregistrari pentru modificare!",48,"Atentie")
				Endif
				*!*	modificare ROAPRODUCTIE v 2.0.2	^
		Endcase
		
	ENDPROC

	PROCEDURE Init
		gcAcces=[1;2;3;4;]
		DoDefault()
		This.cb_tx_cautare1.criteriu.Value = [1]
		This.cb_tx_cautare1.criteriu.Refresh()
		
	ENDPROC

	PROCEDURE But_nou1.Click
		This.Parent.ntip =1
		DoDefault()
	ENDPROC

	PROCEDURE But_nou2.Click
		This.Parent.ntip =2
		DoDefault()
	ENDPROC

	PROCEDURE But_reset1.Click
		This.Parent.ntip=1
		DoDefault()
		
	ENDPROC

	PROCEDURE But_reset2.Click
		This.Parent.ntip=2
		DoDefault()
		
	ENDPROC

	PROCEDURE But_reset3.Click
		This.Parent.ntip=2
		DoDefault()
		
	ENDPROC

	PROCEDURE But_sterge1.Click
		This.Parent.ntip =1
		DoDefault()
	ENDPROC

	PROCEDURE But_sterge2.Click
		This.Parent.ntip =2
		DoDefault()
	ENDPROC

	PROCEDURE Cb_tx_cautare1.Text.KeyPress
		Lparameters nKeyCode, nShiftAltCtrl
		If nKeyCode = 13
			Nodefault
			This.Parent.Parent.do_cauta()
		Else
			DoDefault(nKeyCode, nShiftAltCtrl)
		Endif
		
	ENDPROC

	PROCEDURE Ct_grid_search1.Cb_tx_cautare1.Text.KeyPress
		*!*	modificare	ROAGRESTAURANT v 0.0.19
		Lparameters nKeyCode, nShiftAltCtrl
		If nKeyCode = 13
			Nodefault
			This.Parent.Parent.Parent.do_cauta()
		Else
			DoDefault(nKeyCode, nShiftAltCtrl)
		Endif
		*!*	modificare	ROAGRESTAURANT v 0.0.19	^
	ENDPROC

	PROCEDURE Ct_grid_search1.initializare
		Parameters tlNumerotare
		DoDefault(tlNumerotare)
		Local liColIndex,i
		For liColIndex=1 To This._grid1.ColumnCount
			With This._grid1.Columns(liColIndex)
				.ReadOnly=.T.
				.FontName='Arial Narrow'
			Endwith
		Endfor
	ENDPROC

	PROCEDURE Ct_grid_search1._GRID1.AfterRowColChange
		Lparameters nColIndex
		If This.RowColChange<>2
			pnIdReteta = crsRetete.id_reteta
			This.Parent.Parent.ct_grid_search2.actualizeaza_grid
		Endif
	ENDPROC

	PROCEDURE Ct_grid_search1._GRID1.SetFocus
		pnIdReteta = crsRetete.id_reteta
		This.Parent.Parent.ct_grid_search2.actualizeaza_grid
		
	ENDPROC

	PROCEDURE Ct_grid_search2.initializare
		Parameters tlNumerotare
		DoDefault(tlNumerotare)
		This._GRID1.column6.DynamicBackColor="RGB(217,241,255)"
	ENDPROC

	PROCEDURE Ct_grid_search2._GRID1.AfterRowColChange
		Lparameters nColIndex
		lcalias2  = This.Parent.cnumecursor
		Select (lcalias2)
		
		With This.Parent.Parent
			.rowf = This.ActiveRow
			.colf = This.ActiveColumn
			If .rowi <> 0 And .coli = 6
				Go  .rowi
				.cantf = cantitate
				If .canti <> .cantf
					Scatter Fields id_reteta_elem,cantitate Name loMat
					lcCantitate = Transform(loMat.cantitate)
					lcIdRetetaElem = Transform(loMat.id_reteta_elem)
					lcSql = [begin pack_retete.modifica_material_cant(] + lcIdRetetaElem + [,] + ;
						lcCantitate + [,] + Alltrim(Str(gnIdUtil)) + [); end;]
					lnSucces = goExecutor.oExecute(lcSql)
					If lnSucces < 0
						lcTextEroare = goExecutor.cEroare
						lcMesaj = "Modificarea nu s-a realizat!." + Chr(13) + Chr(10) + lcTextEroare
						ofrm_er =Createobject('frm_mesaj',[Atentie],[exclam.ico],[Avertizare],lcMesaj)
						ofrm_er.Show()
						Release ofrm_er
						Return
					Endif
				Endif
				If .rowf <= Reccount(lcalias2)
					Go .rowf
				Endif
			Endif
			.rowi = .rowf
			.coli = .colf
			If .coli = 6
				.canti = cantitate
			Endif
		Endwith
		
	ENDPROC

ENDDEFINE

DEFINE CLASS cus_odata_reteta AS _cusodatabase OF "..\..\..\roacomenzi\comun\clase\_cus_odata_base.vcx" 
 	*< CLASSDATA: Baseclass="custom" Timestamp="" Scale="Pixels" Uniqueid="" />

	*<PropValue>
		Name = "cus_odata_reteta"
	*</PropValue>
	
	PROCEDURE make_sql
		Lparameters toRec,tnId
		
		lcActiune = Alltrim(This.cActiune)
		
		If Inlist(lcActiune, "UPDATE",'INSERT') And Type('toRec') != "O"
			Return .F.
		Endif
		
		If Inlist(lcActiune, "UPDATE",'DELETE') And Type('tnId') != "N"
			Return .F.
		Endif
		
		If Inlist(lcActiune, "UPDATE",'DELETE')
			lcId = Alltrim(Str(tnId))
		Endif
		
		If Inlist(lcActiune, "UPDATE",'INSERT')
			lcCod=Alltrim(toRec.cod)
			lcIdArticol=Alltrim(STR(toRec.id_articol))
			lcExplicatie=Alltrim(NVL(toRec.explicatie,[]))
			lcPrincipala=ALLTRIM(STR(toRec.principala))
		Endif
		
		Do Case
		Case lcActiune = "INSERT"
			lcSql = [begin pack_retete.adauga_reteta('] + STRTRAN(lcCod,['],['']) + [',] + lcIdArticol + [,] +;
				['] + STRTRAN(lcExplicatie,['],['']) + [',] + lcPrincipala + [,] + Alltrim(Str(gnIdUtil)) + [,?@pnIdReteta); end;]
		
		Case lcActiune = "UPDATE"
			lcSql = [begin pack_retete.modifica_reteta(] + lcId + [,'] + STRTRAN(lcCod,['],['']) + [',] + lcIdArticol + [,] +;
				['] + STRTRAN(lcExplicatie,['],['']) + [',] + lcPrincipala + [,] + Alltrim(Str(gnIdUtil)) + [); end;]
		
		Case lcActiune = "DELETE"
			lcSql = [begin pack_retete.sterge_reteta(] + lcId + [,] + Alltrim(Str(gnIdUtil)) + [); end;]
		
		Endcase
		This.csql = lcSql
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_reteta_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="clb_cod" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="clb_denumire" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cus_odata_reteta1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ck_principala" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ed_explicatie" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Image1" UniqueID="" Timestamp="" />

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

	*<PropValue>
		DoCreate = .T.
		Height = 191
		Name = "frm_reteta_nou"
		Width = 348
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 348
		_shape2.Height = 29
		_shape2.Left = 286
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 64
		Lb_titlu_alb_b121.Caption = "TEHNOLOGIE"
		Lb_titlu_alb_b121.FontBold = .T.
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 7
		BUT_TERMIN1.Left = 318
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 5
		BUT_TERMIN1.Top = 1
		GRIDSORT1.Left = 13
		GRIDSORT1.Name = "GRIDSORT1"
		GRIDSORT1.Top = 42
	*</PropValue>

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

	ADD OBJECT 'ck_principala' AS _checkbox WITH ;
		Alignment = 0, ;
		Caption = "Principala", ;
		ControlSource = "porec.principala", ;
		Left = 228, ;
		Name = "ck_principala", ;
		TabIndex = 4, ;
		Top = 164
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'clb_cod' AS clb_tx_simplu WITH ;
		Left = 16, ;
		Name = "clb_cod", ;
		TabIndex = 1, ;
		Top = 44, ;
		Text_simplu1.ControlSource = "porec.cod", ;
		Text_simplu1.Name = "Text_simplu1", ;
		Lb_simplu1.Caption = "Cod tehnologic", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'clb_denumire' AS clb_tx_simplu WITH ;
		Left = 16, ;
		Name = "clb_denumire", ;
		TabIndex = 2, ;
		Top = 72, ;
		Text_simplu1.ControlSource = "porec.denumire", ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.ReadOnly = .T., ;
		Lb_simplu1.Caption = "Produs", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Cus_odata_reteta1' AS cus_odata_reteta WITH ;
		Left = 96, ;
		Name = "Cus_odata_reteta1", ;
		Top = 164
		*< END OBJECT: ClassLib="onom_retete.vcx" BaseClass="custom" />

	ADD OBJECT 'Ed_explicatie' AS ed_tx_simplu WITH ;
		Left = 16, ;
		Name = "Ed_explicatie", ;
		TabIndex = 3, ;
		Top = 100, ;
		_edbase1.ControlSource = "porec.explicatie", ;
		_edbase1.Name = "_edbase1", ;
		_lbbase1.Caption = "Explicatie", ;
		_lbbase1.Name = "_lbbase1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Image1' AS image WITH ;
		Height = 20, ;
		Left = 315, ;
		Name = "Image1", ;
		Picture = ..\grafice\alege.bmp, ;
		Stretch = 2, ;
		Top = 76, ;
		Width = 24, ;
		ZOrderSet = 31
		*< END OBJECT: BaseClass="image" />
	
	PROCEDURE do_cauta_articol
		locauta=caut_articol_gs(.F., .F., .F., [341,345,371])
		If !Isnull(locauta)
			porec.denumire = locauta.denumire
			porec.id_articol = locauta.id_articol
			Thisform.clb_denumire.Refresh()
		Endif
	ENDPROC

	PROCEDURE inainte_de_do_termin
		Local plReturn
		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(porec.cod,[]))
				amessagebox('Nu ati completat codul tehnologic!',0+48,"Atentie")
				Thisform.clb_cod.texT_SIMPLU1.SetFocus()
				plReturn=.F.
			Case Empty(Nvl(porec.denumire,[])) Or Empty(Nvl(porec.id_articol,0))
				amessagebox('Nu ati ales produsul!',0+48,"Atentie")
				Thisform.clb_produs.texT_SIMPLU1.SetFocus()
				plReturn=.F.
			Otherwise
				plReturn=Thisform.cus_odata_reteta1.salvare(This.OREC,This.NID)
		Endcase
		Return plReturn
	ENDPROC

	PROCEDURE Init
		Lparameters toRec, tnId, tcActiune
		
		DoDefault()
		
		This.orec= toRec
		This.nid = tnId
		This.cus_odata_reteta1.cactiune = tcActiune
	ENDPROC

	PROCEDURE clb_denumire.Text_simplu1.KeyPress
		Lparameters nKeyCode, nShiftAltCtrl
		If Inlist(nKeyCode,9,13) And nShiftAltCtrl=0 And Empty(porec.id_articol)
			Nodefault
			Thisform.do_cauta_articol()
		Endif
		
	ENDPROC

	PROCEDURE Image1.Click
		Thisform.do_cauta_articol()
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_retetar 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="Ct_retetar1" UniqueID="" Timestamp="" />

	*<PropValue>
		DoCreate = .T.
		Height = 650
		Name = "frm_retetar"
		Width = 661
		_shape1.Anchor = 11
		_shape1.Height = 29
		_shape1.Left = -1
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 661
		_shape2.Anchor = 9
		_shape2.Height = 29
		_shape2.Left = 624
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 37
		Lb_titlu_alb_b121.Caption = "FISA TEHNOLOGICA"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 8
		BUT_TERMIN1.Anchor = 9
		BUT_TERMIN1.Height = 27
		BUT_TERMIN1.Left = 628
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 7
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.Width = 30
		GRIDSORT1.Left = 9
		GRIDSORT1.Name = "GRIDSORT1"
		GRIDSORT1.Top = 48
	*</PropValue>

	ADD OBJECT 'Ct_retetar1' AS ct_retetar WITH ;
		Left = 5, ;
		Name = "Ct_retetar1", ;
		Top = 34, ;
		Gridsort1.Name = "Gridsort1", ;
		_ct_controller_keypress1.Name = "_ct_controller_keypress1", ;
		Ct_grid_search1.Cb_tx_cautare1.Criteriu.Name = "Criteriu", ;
		Ct_grid_search1.Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Ct_grid_search1.Cb_tx_cautare1.Text.Name = "Text", ;
		Ct_grid_search1.Name = "Ct_grid_search1", ;
		Ct_grid_search1.Titlu.Name = "Titlu", ;
		Ct_grid_search1._GRID1.Name = "_GRID1", ;
		Ct_grid_search2.Cb_tx_cautare1.Criteriu.Name = "Criteriu", ;
		Ct_grid_search2.Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Ct_grid_search2.Cb_tx_cautare1.Text.Name = "Text", ;
		Ct_grid_search2.Name = "Ct_grid_search2", ;
		Ct_grid_search2.Titlu.Name = "Titlu", ;
		Ct_grid_search2._GRID1.Name = "_GRID1", ;
		But_listare1.Name = "But_listare1", ;
		But_nou1.Name = "But_nou1", ;
		But_sterge1.Name = "But_sterge1", ;
		But_nou2.Name = "But_nou2", ;
		But_sterge2.Name = "But_sterge2", ;
		But_modifica1.Name = "But_modifica1", ;
		But_reset1.Name = "But_reset1", ;
		But_reset2.Name = "But_reset2", ;
		Cb_tx_cautare1.Criteriu.Name = "Criteriu", ;
		Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Cb_tx_cautare1.Text.Name = "Text", ;
		But_copie.Name = "But_copie", ;
		Lb_cautare.Name = "Lb_cautare", ;
		But_reset3.Name = "But_reset3"
		*< END OBJECT: ClassLib="onom_retete.vcx" BaseClass="container" />
	
	PROCEDURE Show
		Lparameters nStyle
		This.ct_retetar1.actualizeaza_cursoare()
		
	ENDPROC

ENDDEFINE
