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

	#INCLUDE "..\..\..\program files\microsoft visual foxpro 8\foxpro.h"
	*<DefinedPropArrayMethod>
		*m: afisare
		*m: cfiltru_assign
		*m: corder_assign
		*p: cfiltru
		*p: cfiltruoriginal
		*p: cgroup
		*p: corder
		*p: cselect
		*p: lafisare
		*p: lmodparam
	*</DefinedPropArrayMethod>

	*<PropValue>
		cfiltru = 
		cfiltruoriginal = 
		cgroup = 
		corder = 
		cselect = 
		Height = 22
		lafisare = .T.
		Name = "ca_baza"
		Width = 23
	*</PropValue>
	
	PROCEDURE afisare
		#Define CRLF Chr(13) + Chr(10)
		Local llReconnect, lnHandle, lnSucces, llSucces, lnEroare1, lnEroare2, lcTextEroare, llEroare
		Local laEroare2[1], lcCursor, lcErrorHTTP, lcLog, lcLunaHTTP, lcProgram, lcTempCursor, lcUserName
		Local lnRaspuns
		
		Local laEroare
		llSucces = .F.
		
		If This.lmodparam
			&& selectcmd nu are inclus where
			This.SelectCmd = This.cSelect
		Else
			This.SelectCmd = Left(Upper(This.SelectCmd), At('WHERE', Upper(This.SelectCmd)) - 1)
		Endif
		
		If !Empty(This.cFiltru) Or !Empty(This.cFiltruoriginal)
			This.SelectCmd = This.SelectCmd + ' WHERE '
		Else
			This.SelectCmd = This.SelectCmd + ' '
		Endif
		
		This.SelectCmd = This.SelectCmd + Alltrim(This.cFiltru)
		
		If !Empty(This.cFiltru) And !Empty(This.cFiltruoriginal)
			This.SelectCmd = This.SelectCmd + [ AND (]
		Else
			This.SelectCmd = This.SelectCmd + [ ]
		Endif
		
		This.SelectCmd = This.SelectCmd +  Alltrim(This.cFiltruoriginal)
		
		If !Empty(This.cFiltru) And !Empty(This.cFiltruoriginal)
			This.SelectCmd = This.SelectCmd + [) ]
		Else
			This.SelectCmd = This.SelectCmd + [ ]
		Endif
		
		This.SelectCmd = This.SelectCmd + Iif(!Empty(This.cgroup), " GROUP BY " + This.cgroup, " ") + Iif(!Empty(This.cOrder), ' ORDER BY ' + This.cOrder, ' ')
		
		*!*	ELSE
		*!*		THIS.SELECTCMD = LEFT(UPPER(THIS.SELECTCMD),AT('WHERE',UPPER(THIS.SELECTCMD))+LEN('WHERE')-1)+;
		*!*			SPACE(1)+THIS.CFiltru+IIF(!EMPTY(THIS.cgroup),SPACE(1)+"GROUP BY "+this.cgroup,"")+IIF(!EMPTY(THIS.CORder),SPACE(1)+'ORDER BY'+SPACE(1)+THIS.CORder,'')
		*!*	ENDIF
		
		
		
		
		Do While .T.
			If Type('goLog') = 'O'
				goLog.Log(This.SelectCmd, Program())
			Endif
			lcCursor = This.Alias
			If Used (lcCursor)
				Use In (lcCursor)
			Endif
			This.CursorAttach(lcCursor)
		
		
			If !Empty(This.CursorSchema)
				llSucces = This.CursorFill(.T.)
			Else
				llSucces = This.CursorFill()
			Endif
		
		
			If Used(lcCursor) And llSucces
				This.CursorDetach
		
				lcTempCursor =  Sys(2015)
				Use Dbf(lcCursor) In 0 Again Shared Alias (lcTempCursor)
				Use In (lcCursor)
				Use Dbf(lcTempCursor) In 0 Again Alias (lcCursor)
				Use In (lcTempCursor)
		
				Exit
			Endif
		
			If !llSucces
		
				Release laEroare
				Declare laEroare(1)
		
				Aerror(laEroare)
				If Alen(laEroare) > 1
					lnEroare1 = laEroare[1]
					lnEroare2 = laEroare[5]
					lcTextEroare = laEroare[3]
					lnHandle = laEroare[6]
					llEroare = .T.
		
					If Type('goMyXMLHTTP') = 'O'
						lcLunaHTTP = Iif(Type('gnLuna') = 'N', Transform(gnLuna) + "/", "") + Iif(Type('GNAN') = 'N', Transform(gnAn), "")
						lcErrorHTTP =  Sys(0) + ":" + Iif(Type('GCS') = 'C', " " + GCS, "") + ": " + lcLunaHTTP + ;
							CRLF + Alltrim(Str(lnEroare1)) + ' ' + Transform(laEroare[3]) + CRLF + Transform(This.SelectCmd) + CRLF + ;
							TRANSFORM(This.CursorSchema)  +  CRLF + CRLF + GETCALLSTACK()
		
						lcUserName = gcUserNameApp
						lcProgram = Juststem(Sys(16, 0))
						goMyXMLHTTP.postError(lcErrorHTTP, lcUserName, lcProgram)
					Endif
		
					If lnEroare1 <> 1526 && eroare <> ODBC
						lcTextEroare = Program() + CRLF + Alltrim(Str(lnEroare1)) + CRLF + laEroare[2] + CRLF + This.SelectCmd + CRLF + CRLF + This.CursorSchema + CRLF + CRLF + GETCALLSTACK()
						If Type('goLog') = 'O'
							goLog.Log(lcTextEroare, Program())
						Endif
						AMessagebox(lcTextEroare, 0, "Eroare")
						Quit
						Retry
					Endif
					*!*			IF lnHandle <> gnHandle && daca mesajul de eroare provine de la alta conexiune => nu s-a intamplat nici o eroare
					*!*				EXIT
					*!*			ENDIF
		
					If Inlist(lnEroare2, 12152, 3113, 3114, 12560, 4068, 28, 12) && 12512 = TNS: UNABLE TO SEND BREAK MESSAGE; 3114 = NOT CONNECTED TO ORACLE; 12560 = PROTOCOL ADAPTER ERROR
						If Type('goLog') = 'O'
							lcLog = laEroare(3) + CRLF
							goLog.Log(lcLog, Program())
						Endif
		
						Do While .T.
							lnRaspuns = AMessagebox('Eroare de conectare.' + CRLF + lcTextEroare + CRLF + 'Doriti reconectare?', 4 + 32, 'Eroare') && retry = 4; cancel = 2
							If lnRaspuns = 6
		
								*!*							goConn.disconnect()
								llReconnect = .T.
								lnHandle = goConn.Connect(goConn.cHost, goConn.cUser, goConn.cPassword, llReconnect)
		
								If lnHandle < 0
									Declare laEroare2(1)
									Aerror(laEroare2)
									lcTextEroare = laEroare2(3)
									Release laEroare2
									Loop
								Else
									This.Parent.Datasource = lnHandle
									Exit
								Endif
							Else
								Quit
								Retry
							Endif && lnRaspuns = 6
						Enddo && .T.
						Loop && daca am iesit cu un handle valid intru din nou in loop si fac cursorfill
					Else
						lcTextEroare = Program() + CRLF + Alltrim(Str(lnEroare1)) + CRLF + laEroare[3] + CRLF + This.SelectCmd + CRLF + CRLF + This.CursorSchema + CRLF + CRLF + GETCALLSTACK()
						lnRaspuns = AMessagebox(lcTextEroare, 0, 'Eroare') && ok = 0
						If Type('goLog') = 'O'
							goLog.Log(lcTextEroare, Program())
						Endif
						Quit
						Retry
					Endif
		
				Else
					Exit
				Endif && INLIST(lnEroare2,12152,3114)
			Endif && !llSucces
		
		Enddo && .T.
		Release laEroare
		
	ENDPROC

	PROCEDURE AutoOpen
		*** Setup code: DO NOT REMOVE
		if not pemstatus(This, '__VFPSetup', 5)
			This.AddProperty('__VFPSetup', 1)
			This.Init()
		endif
		*** End of Setup code: DO NOT REMOVE
		
	ENDPROC

	PROCEDURE cfiltru_assign
		LPARAMETERS vNewVal
		*To do: Modify this routine for the Assign method
		THIS.cfiltru = m.vNewVal
		
		IF this.lafisare 
			this.afisare()
		ENDIF 
		
	ENDPROC

	PROCEDURE corder_assign
		Lparameters vNewVal
		*To do: Modify this routine for the Assign method
		This.cOrder = m.vNewVal
		
		IF this.lafisare 
			this.afisare()
		ENDIF 
		
		
	ENDPROC

	PROCEDURE Init
		local llReturn
		do case
			case not pemstatus(This, '__VFPSetup', 5)
				This.AddProperty('__VFPSetup', 0)
			case This.__VFPSetup = 2
				This.__VFPSetup = 0
				return
		endcase
		llReturn = dodefault()
		*** Setup code: DO NOT REMOVE
		
		*** End of Setup code: DO NOT REMOVE
		if This.__VFPSetup = 1
			This.__VFPSetup = 2
		endif
		return llReturn
		
	ENDPROC

ENDDEFINE

DEFINE CLASS deca_baza AS _debase OF "_de_base.vcx" 
 	*< CLASSDATA: Baseclass="dataenvironment" Timestamp="" Scale="Pixels" Uniqueid="" />

	#INCLUDE "c:\program files\microsoft visual foxpro 8\foxpro.h"
	*<DefinedPropArrayMethod>
		*p: ctexteroare
		*p: leroare
		*p: neroare
	*</DefinedPropArrayMethod>

	*<PropValue>
		ctexteroare = 
		Name = "deca_baza"
		neroare = 0
	*</PropValue>

ENDDEFINE
