Define Class printSettingsController As wwConfig
	cMode = "XML"
	nNrMaxDispozitiv = 0
	nBonFiscal = 1
	nNotaPlata = 2
	nNotaMasa = 3
	*******************************************************************************
	Procedure Init
		Dimension laListaDispozitive[1]
		AddProperty(This,'aListaDispozitive',CREATEOBJECT('Collection'))
		*!*	trebuie adaugate toate proprietatile obiectului care nu trebuie sa apara in fisierul xml (scrise fara majuscule)
		This.cPropertyExclusionList = This.cPropertyExclusionList + [,nnrmaxdispozitiv,alistadispozitive,nbonfiscal,nnotaplata,nnotamasa]
	Endproc
	*******************************************************************************
	Procedure seteazaFisier
		Lparameters tcCaleROA,tcNumeProgram,tcSchema
		Local lcCaleXML,lcBuffer,lcGeneralIniFile,lcIniPath
		lcGeneralIniFile = Alltrim(tcCaleROA) + [ROAPRINT\settings.ini]
		If !File(lcGeneralIniFile)
			lcCaleXML = Alltrim(tcCaleROA) + [USERCONFIG\] + Alltrim(tcNumeProgram) + [_] + Alltrim(tcSchema) + [.XML]
		Else
			lcBuffer = Space(255)
			GetPrivateProfileString( "initializari","Path","",@lcBuffer, Len(lcBuffer), lcGeneralIniFile)
			lcBuffer = Addbs(Alltrim(Strtran(lcBuffer,Chr(0),"")))
			If !Empty(lcBuffer)
				lcIniPath = lcBuffer
			Else
				lcIniPath = Alltrim(tcCaleROA) + [USERCONFIG\]
			Endif
			lcCaleXML = lcIniPath + Alltrim(tcNumeProgram) + [_] + Alltrim(tcSchema) + [.XML]
		Endif
		This.seteazaConfigurari(lcCaleXML)
	Endproc
	*******************************************************************************
	Procedure seteazaConfigurari
		Lparameters tcFisierConfigurare
		Local lcCursorTemp,lcNrD,lnNrDMax,i	&&	,loObiect
		This.cFileName = tcFisierConfigurare
		lcCursorTemp = [TMP] + Sys(2015)
		If !File(This.cFileName)
*!*				This.adauga_dispozitiv()
			This.Save()
		Else
			Xmltocursor(This.cFileName,lcCursorTemp,512)
			lnNrDMax = 0
			For i = 1 To Fcount(lcCursorTemp)
				lnNrD = VAL(Strtran(Lower(Field(i)),'device',''))
				This.adauga_dispozitiv(lnNrD)
				If lnNrD > lnNrDMax
					lnNrDMax = lnNrD
				Endif
			Endfor
			This.nNrMaxDispozitiv = lnNrDMax
			Use In (lcCursorTemp)
		Endif
		This.Load()
	Endproc
	*******************************************************************************
	Function citeste_nr_dispozitiv
		Lparameters tnTipListare, tcDescriere
		*!*	caut dupa tip listare si descriere ( ex : [NOTA MASA ]+ tcDescriere )
		Local lnNrDispozitiv, loObiect, i
		lnNrDispozitiv = 0
		With This.aListaDispozitive
			For i = 1 To .Count
				If .Item(i).nTipListare = tnTipListare AND UPPER(.Item(i).cDescription) = This.getDescription(tnTipListare,tcDescriere)
					lnNrDispozitiv = .Item(i).nNrDispozitiv
					Exit
				Endif
			Endfor
		Endwith
		IF lnNrDispozitiv = 0
			loObiect = This.adauga_dispozitiv()
			loObiect.nTipListare = tnTipListare
			loObiect.cDescription = This.getDescription(tnTipListare,tcDescriere)
			loObiect.cDeviceType = This.getDeviceType(tnTipListare)
			lnNrDispozitiv = loObiect.nNrDispozitiv
		ENDIF
		RETURN lnNrDispozitiv
	Endfunc	
	*******************************************************************************	
	Function adauga_dispozitiv
		Lparameters tnNrDispozitiv
		Local lcNumeObiect,lnNrDispozitiv, loObiect
		If Empty(tnNrDispozitiv)
			This.nNrMaxDispozitiv = This.nNrMaxDispozitiv + 1
			lnNrDispozitiv = This.nNrMaxDispozitiv
		Else
			lnNrDispozitiv = tnNrDispozitiv
		Endif
		lcNumeObiect = 'oDevice'+Alltrim(Str(lnNrDispozitiv))
		AddProperty(This,lcNumeObiect,Createobject("cDevice"))
		lcNumeObiect = [This.] + lcNumeObiect
		loObiect = &lcNumeObiect
		This.aListaDispozitive.Add(loObiect)
		loObiect.nNrDispozitiv = lnNrDispozitiv
		Return loObiect
	Endfunc
	*******************************************************************************	
	Function citeste_imprimanta_dispozitiv
		Lparameters tnNrDispozitiv
		Local lcImprimanta, i
		lcImprimanta = []
		With This.aListaDispozitive
			For i = 1 To .Count
				If .Item(i).nNrDispozitiv = tnNrDispozitiv
					lcImprimanta = .Item(i).cDeviceName
					Exit
				Endif
			Endfor
		Endwith
		Return lcImprimanta
	Endfunc
	*******************************************************************************		
	Function scrie_imprimanta_dispozitiv
		Lparameters tnNrDispozitiv,tcImprimanta,tnTipListare,tcDescriere
		*!*	scrie imprimanta si dispozitivul ( daca nu exista, atunci il creeaza; daca exista, atunci doar inlocuieste imprimanta)
		Local llNou, i, loObiect
		llNou = .T.
		With This.aListaDispozitive
			For i = 1 To .Count
				If .Item(i).nNrDispozitiv = tnNrDispozitiv
					.Item(i).cDeviceName = tcImprimanta
					.Item(i).cDescription = This.getDescription(tnTipListare,tcDescriere)
					llNou = .F.
					Exit
				Endif
			Endfor
		Endwith
		If llNou
			loObiect = This.adauga_dispozitiv()
			loObiect.nTipListare = tnTipListare
			loObiect.cDescription = This.getDescription(tnTipListare,tcDescriere)
			loObiect.cDeviceName = tcImprimanta
			loObiect.cDeviceType = This.getDeviceType(tnTipListare)
		Endif
		Return .T.
	Endfunc
	*******************************************************************************
	Function getDescription
		Lparameters tnTipListare,tcDescriere
		Local lcDescriere
		Do Case
			Case tnTipListare = This.nBonFiscal
				lcDescriere = Alltrim([BON FISCAL ] + tcDescriere)
			Case tnTipListare = This.nNotaPlata
				lcDescriere = Alltrim([NOTA PLATA ] + tcDescriere)
			Case tnTipListare = This.nNotaMasa
				lcDescriere = Alltrim([NOTA MASA ] + tcDescriere)
			Otherwise
				lcDescriere = Alltrim(tcDescriere)
		Endcase
		Return lcDescriere
	Endfunc
	*******************************************************************************	
	Function getDeviceType
		Lparameters tnTipListare
		Local lcTipDispozitiv
		Do Case
			Case tnTipListare = This.nBonFiscal
				lcTipDispozitiv = [ECR]
			Case tnTipListare = This.nNotaPlata
				lcTipDispozitiv = [PRINTER]
			Case tnTipListare = This.nNotaMasa
				lcTipDispozitiv = [PRINTER]
			Otherwise
				lcTipDispozitiv = []
		Endcase
		Return lcTipDispozitiv
	Endfunc
	*******************************************************************************	
	Procedure salveaza
		This.Save()
*!*			Release This
	Endproc
	*******************************************************************************
Enddefine
*******************************************************************************
Define Class cDevice As Relation
	nNrDispozitiv = 0
	nTiplistare = 0
	cDescription = ""
	cDeviceType=""
	cDeviceName = ""
	cDeviceDriver= ""
	cDeviceTemplate = ""
	cNetwork = "0"
	cExePath = ""
	cExeParams = ""
	cPrintPath = ""
	cErrorFileProcedure = ""
	cErrorFile = ""
	nErrorFileType = 0 && 1=se apeleaza procedura de eroare cu calea completa a fisierului de eroare, din tagul errorfile, in loc de tagul exepath
	nTimeOut = 0
	cTVAGrupe = "" && 19|9|5|0|N
	nNeplatitorTVA = 0 && 0=Platitor TVA, 1=Neplatitor TVA
Enddefine
*********************************************************************************
*!*	Define Class cDevice1 As Relation
*!*		nTiplistare = 1 && 1 = BON FISCAL
*!*		cDescription = "Bon Fiscal"
*!*		cDeviceType="ECR"
*!*		cDeviceName = "EURO500"
*!*		cDeviceDriver= "COMM2A"
*!*		cDeviceTemplate = "EURO500_WIN.TMPL"
*!*		cNetwork = "0"
*!*		cExePath = "C:\COMM2A\COMM2A.EXE"
*!*		cExeParams = "/RO /T /com:1 /speed:38400 /ECR:10 /num:1 /o:18 /data_file:items.txt  /err_file:Online.err /LEN:??numar_linii_bon??"
*!*		cPrintPath = "C:\COMM2A\ITEMS.TXT"
*!*		cErrorFileProcedure = "euro500_win.err"
*!*		cErrorFile = "C:\COMM2A\ONLINE.ERR"
*!*	Enddefine
*!*	*******************************************************************************
*!*	Define Class cDevice2 As Relation
*!*		nTiplistare = 2 && nota plata
*!*		cDescription = "Nota Plata"
*!*		cDeviceType = "PRINTER"
*!*		cDeviceName = "EPSONTM220"
*!*		cDeviceDriver = "EPSONTM220"
*!*		cDeviceTemplate = "NOTA.TMPL"
*!*		cNetwork = "0"
*!*		cExePath = ""
*!*		cExeParams = ""
*!*		cPrintPath = "C:\ITEMS.TXT"
*!*		cErrorFileProcedure = ""
*!*		cErrorFile = ""
*!*	Enddefine
*!*	*******************************************************************************
*!*	Define Class cDevice3 As Relation
*!*		nTiplistare = 3 && nota masa
*!*		cDescription = "Nota Masa"
*!*		cDeviceType = "PRINTER"
*!*		cDeviceName = "EPSONTM220"
*!*		cDeviceDriver = "EPSONTM220"
*!*		cDeviceTemplate = "NOTA.TMPL"
*!*		cNetwork = "0"
*!*		cExePath = ""
*!*		cExeParams = ""
*!*		cPrintPath = "C:\ITEMS.TXT"
*!*		cErrorFileProcedure = ""
*!*		cErrorFile = ""
*!*	Enddefine
*!*	*******************************************************************************