*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="ferestre_comune.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS frm_login 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="_shape4" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_label1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_textbox1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_label2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_textbox2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cb_server" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cmd_login1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Odbcreg1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cmd_logoff1" UniqueID="" Timestamp="" />

	#INCLUDE "..\include\security.h"
	*<DefinedPropArrayMethod>
		*m: populate_host
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		Caption = "LOGIN"
		DoCreate = .T.
		Height = 181
		Name = "frm_login"
		Width = 303
		WindowState = 0
		_shape1.Name = "_shape1"
		_shape1.ZOrderSet = 2
		_shape2.Height = 29
		_shape2.Left = 271
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 32
		_shape2.ZOrderSet = 3
		Lb_titlu_alb_b121.Caption = "Not connected"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 7
		Lb_titlu_alb_b121.Visible = .T.
		Lb_titlu_alb_b121.ZOrderSet = 4
		But_termin1.Left = 274
		But_termin1.Name = "But_termin1"
		But_termin1.TabIndex = 6
		But_termin1.Top = 1
		But_termin1.ZOrderSet = 5
		Gridsort1.Left = 0
		Gridsort1.Name = "Gridsort1"
		Gridsort1.Top = 72
	*</PropValue>

	ADD OBJECT '_label1' AS _label WITH ;
		BackStyle = 0, ;
		Caption = "Operator", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 18, ;
		Name = "_label1", ;
		TabIndex = 8, ;
		Top = 79, ;
		Width = 53, ;
		ZOrderSet = 14
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT '_label2' AS _label WITH ;
		BackStyle = 0, ;
		Caption = "Parolă", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 18, ;
		Name = "_label2", ;
		TabIndex = 9, ;
		Top = 107, ;
		Width = 39, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT '_shape4' AS _shape WITH ;
		BackStyle = 0, ;
		BorderStyle = 1, ;
		Height = 61, ;
		Left = 12, ;
		Name = "_shape4", ;
		Top = 70, ;
		Width = 266, ;
		ZOrderSet = 1
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT '_textbox1' AS _textbox WITH ;
		AutoComplete = 4, ;
		ControlSource = "gcUserNameApp", ;
		Format = "!K", ;
		Height = 23, ;
		Left = 90, ;
		Name = "_textbox1", ;
		TabIndex = 2, ;
		Top = 76, ;
		Width = 178, ;
		ZOrderSet = 15
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT '_textbox2' AS _textbox WITH ;
		ControlSource = "gcPasswordApp", ;
		Format = "!K", ;
		Height = 23, ;
		Left = 90, ;
		Name = "_textbox2", ;
		PasswordChar = "*", ;
		TabIndex = 3, ;
		Top = 104, ;
		Width = 178, ;
		ZOrderSet = 17
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'Cb_server' AS cb_tx_simplu WITH ;
		BorderWidth = 0, ;
		Left = 2, ;
		Name = "Cb_server", ;
		TabIndex = 1, ;
		Top = 36, ;
		_cbbase1.Height = 23, ;
		_cbbase1.Left = 90, ;
		_cbbase1.Name = "_cbbase1", ;
		_cbbase1.Top = 3, ;
		_cbbase1.Width = 189, ;
		_lbbase1.Caption = "Server", ;
		_lbbase1.FontBold = .T., ;
		_lbbase1.Name = "_lbbase1"
		*< END OBJECT: ClassLib="..\..\..\roastart\comun\clase\lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Cmd_login1' AS cmd_login WITH ;
		Caption = "In\<tră", ;
		Height = 27, ;
		Left = 55, ;
		Name = "Cmd_login1", ;
		TabIndex = 4, ;
		Top = 141, ;
		Width = 85, ;
		ZOrderSet = 12
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Cmd_logoff1' AS cmd_logoff WITH ;
		Caption = "Re\<nunță", ;
		Height = 27, ;
		Left = 149, ;
		Name = "Cmd_logoff1", ;
		TabIndex = 5, ;
		Top = 141, ;
		Width = 85, ;
		ZOrderSet = 13
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Odbcreg1' AS odbcreg WITH ;
		Left = 240, ;
		Name = "Odbcreg1", ;
		Top = 144
		*< END OBJECT: ClassLib="registry.vcx" BaseClass="custom" />
	
	PROCEDURE actualizeaza_drepturi
		*!*
	ENDPROC

	PROCEDURE Destroy
		IF USED('crsHost')
			USE IN crsHost
		ENDIF 
	ENDPROC

	PROCEDURE do_login
		*LPARAMETERS tcHost,tcUserName,tcPassword,tcUserNameApp,tcPasswordApp,tnIdUtil,tnIdProgram
		Local llParametri,lcHost,lcUserName,lcPasword,lcUserNameApp,lcPaswordApp,lnIdutil,lnIdProgram, lcKey
		Local lcSchema, lcMode
		lcMode = ""
		*!*	lcEncKey = "233!do*32Di3-o23\409"
		lcEncKey = ENCRYPTKEY
		
		If goRoa.lParametri
			*!* daca parola transmisa de ROASTART ca parametru incepe cu *!* - este criptata - trebuie decryptata
		
			If Left(goRoa.cPassword, 3) = "*!*"
				goRoa.cPassword = Substr(goRoa.cPassword,4)
				If goRoa.lnewcryptxml=.T.
					goRoa.cPassword=Strconv(goRoa.cPassword,14)
					goRoa.cPassword = EncryptDecrypt(goRoa.cPassword, lcEncKey, "decrypt","blowfish")
				Else
					goRoa.cPassword = EncryptDecrypt(goRoa.cPassword, lcEncKey, "decrypt","old")
				Endif
			Endif
		
			lcHost = goRoa.cHost
			lcUserName = goRoa.cUserName
			lcPassword = goRoa.cPassword
			lcUserNameApp = goRoa.cUserNameApp
			lcPasswordApp = goRoa.cPasswordApp
			lnIdutil = goRoa.nIdUtil
			lnIdProgram = goRoa.nIdProgram
		Else
			******====================================================
			lcHost = Upper(Alltrim(This.cb_server._cbbase1.Value))
			lcSchema = ""
			lcPassword = ""
			lcMode = ""
			If !Empty(lcHost)
				If Used('crsHost')
					Select schema, pwd, IsEncrypted From crsHost Where Upper(Alltrim(Host)) = lcHost Into Cursor crsServer
					Select crsServer
					Go Top
					lcSchema = schema
					lcPassword = pwd
					lcMode = IsEncrypted
				Endif
			Endif
			goRoa.cHost = Alltrim(lcHost)
			goRoa.cUserName = Alltrim(lcSchema)
			goRoa.cPassword = Alltrim(lcPassword)
		
			*!*
			lcMode = Iif(Empty(lcMode), "0", lcMode)
			If Alltrim(lcMode) <> "0"
				&& parola este criptata
				If goRoa.lnewcryptxml=.T.
					goRoa.cPassword = EncryptDecrypt(goRoa.cPassword, lcEncKey, "decrypt","blowfish")
				Else
					goRoa.cPassword = EncryptDecrypt(goRoa.cPassword, lcEncKey, "decrypt","old")
				Endif
			Endif
		
			If Used('crsServer')
				Use In crsServer
			Endif
		
			llParametri = .F.
			lcHost = goRoa.cHost
			lcUserName = goRoa.cUserName
			lcPassword = goRoa.cPassword
			lcUserNameApp = Strtran(Upper(Alltrim(goRoa.cUserNameApp)),['],[''])
			lcPasswordApp = Upper(Alltrim(goRoa.cPasswordApp))
			lnIdutil = goRoa.nIdUtil
			lnIdProgram = goRoa.nIdProgram
		
		Endif
		
		
		* se logheaza pe schema <contafin_ORACLE> cu <123>
		* apeleaza <update_utilizatori>
		* verifica daca utilizatorul este in <v_utilizatori> si initializeaza variabila globala <goUtilizator>
		
		*** vad daca utilizatorul trebuie sa se logheze cu un alt DSN (jcsserver) cu alt username (contabilitate) fata de standard (jcsserver,contabilitate)
		Local lcFileUtilizatori,lcUtilizatori,lnLen,laUtilizatori
		
		lcFileUtilizatori = gcUtilizatoriPath + "utilizatori.txt"
		If File(lcFileUtilizatori)
			lcUtilizatori = Filetostr(lcFileUtilizatori)
		
			Declare laUtilizatori[1]
			lnLen = Alines(laUtilizatori,lcUtilizatori)
			If lnLen > 0
				For i = 1 To lnLen
					lnpos1 = At(';',laUtilizatori[i])
					lnpos2 = At(';',laUtilizatori[i],2)
					lnpos3 = At(';',laUtilizatori[i],3)
		
					If lnpos1 * lnpos2 * lnpos3 = 0
						Exit
					Endif
		
					lcUserApp = Upper(Alltrim(Substr(laUtilizatori[i],1,lnpos1-1)))
					lcHostBD = Upper(Alltrim(Substr(laUtilizatori[i],lnpos1 + 1,lnpos2 - lnpos1 - 1)))
					lcUserBD = Upper(Alltrim(Substr(laUtilizatori[i],lnpos2 + 1,lnpos3 - lnpos2 - 1)))
					If lcUserApp == Upper(Alltrim(goRoa.cUserNameApp))
		
						goRoa.cHost = lcHostBD
						goRoa.cUserName = lcUserBD
		
						Exit
					Endif
				Endfor
			Endif
		Endif
		
		
		Private pcexec,pnsucces
		lcLog = 'Incercare de conectare: ' + lcUserNameApp
		goRoa.scrieInLog(lcLog)
		If This.nhandle>0
			lcLog = "Sunteti deja conectat " + lcUserNameApp
			goRoa.scrieInLog(lcLog)
			aMessagebox("Sunteti deja conectat!",0+48,"Atentie")
			Return
		Endif
		
		This.MousePointer= 11
		
		
		This.nhandle = goRoa.oConn.Connect(lcHost, lcUserName, lcPassword)
		
		If This.nhandle <= 0
			Thisform.cmd_login1.SetFocus()
			Return
		Endif
		
		goRoa.cIdUtil = 0
		llSucces = .F.
		
		If goRoa.lParametri
			This.MousePointer= 11
			goRoa.cUserNameApp=verifica_id_util(gnIdUtil)
			This.MousePointer=0
			If !Empty(goRoa.cUserNameApp)
				llSucces=.T.
			Endif
		Else
			This.MousePointer= 11
			lnIdutil=verifica_utilizator(lcUserNameApp,lcPasswordApp)
			This.MousePointer= 0
			If lnIdutil>-1
				goRoa.nIdUtil = lnIdutil
				goRoa.cUserNameApp = Upper(Alltrim(lcUserNameApp))
				goRoa.cIdUtil = goRoa.nIdUtil
				llSucces = .T.
			Endif
		Endif
		
		If goRoa.lParametri
			llDrept = .T.
		Else
			goRoa.nIdProgram = GET_PROGRAMID(goRoa.cNumeProgram)
			llDrept = acces_program_util(goRoa.nIdProgram,gnIdUtil)
		Endif
		goRoa.nId_prg_owner = goRoa.nIdProgram
		
		If !llSucces Or !llDrept
			This.nhandle = -1
			gnHandle = This.nhandle
			SQLDisconnect(0)
		
			lcLog = 'Autentificarea nu a reusit: ' + lcUserNameApp + Iif(!llDrept,' Nu are drepturi pe acest program','')
			goRoa.scrieInLog(lcLog)
		
			aMessagebox("Autentificarea nu a reusit!" + Chr(13) + Chr(10)+ "Utilizator sau parola incorecte." +  Iif(!llDrept,Chr(13) + 'Nu are drepturi pe acest program',''),0+48,"Atentie")
			Thisform._textbox1.SetFocus()
			Return .F.
		Endif
		
		lcLog = 'Connected: ' + Sys(0) + ' ' + lcUserNameApp
		goRoa.scrieInLog(lcLog)
		Thisform.Visible=.F.
		This.lb_titlu_alb_b121.Caption = "Conectat: "+Alltrim(Str(This.nhandle))
		
		_Screen.Caption="Conectat: "+Sys(0)
		This.MousePointer= 0
		Thisform.Release
		Do Form fundal Name gofundal Linked
		*!*	IF TYPE('oprinc') = 'O'
		*!*		IF PEMSTATUS(oprinc, "pagefr1", 5)
		*!*			oprinc.pagefr1.p1.click()
		*!*		ENDIF 	
		*!*	ENDIF 	
		
	ENDPROC

	PROCEDURE do_logoff
		LOCAL lcLog 
		*lcLog = 'Attempting to logoff: ' + gcUserNameApp
		lcLog = 'Incercare de deconectare: ' + gcUserNameApp
		goRoa.scrieInLog(lcLog)
		
		Local lnSucces
		If This.nHandle>0
			lnSucces = SQLDISCONNECT(This.nHandle)
			If lnSucces = 1
				This.nHandle = -1
		*this.lb_titlu_alb_b121.ForeColor= RGB(128,0,0)
				This.lb_titlu_alb_b121.Caption = "Deconectat"
				aMessagebox("Ati fost deconectat!",0+64,"Info")
				_screen.caption="Deconectat: "+SYS(0)
				
				lcLog = 'Deconectat'
				thisform._textbox2.Value=""
				thisform._textbox1.SetFocus()
			ELSE
				AERROR(laEroare)
				IF TYPE('laEroare')!='U'
					lcLog = 'Eroare la deconectare: ' + gcUserNameApp + CHR(13) + CHR(10) + laEroare[3]
					RELEASE laEroare
				ELSE 
					lcLog = 'Eroare la deconectare: ' + gcUserNameApp 
				ENDIF 
		
				aMessagebox("Eroare la deconectare!",0+16,"Eroare")
			ENDIF
			goRoa.scrieInLog(lcLog)
		Endif
		
		GNHANDLE = This.nHandle
		
		
		Return Iif(This.nHandle<0,.T.,.F.)
		
	ENDPROC

	PROCEDURE do_modifica
		thisform._checkbox1.Visible=!thisform._checkbox1.Visible
	ENDPROC

	PROCEDURE Init
		DoDefault()
		LOCAL lcHost
		
		This.nhandle = goRoa.nHandle
		If This.nhandle <= 0
		*this.lb_titlu_alb_b121.ForeColor= RGB(128,0,0)
			This.lb_titlu_alb_b121.Caption = "Neconectat"
		Else
		*this.lb_titlu_alb_b121.ForeColor= RGB(0,128,128)
			This.lb_titlu_alb_b121.Caption = "Conectat: "+Alltrim(Str(This.nhandle))
		Endif
		
		lnHosts = This.populate_host()
		If lnHosts > 0
			Thisform.cb_server._CBBASE1.RowSourceType = 2
			Thisform.cb_server._CBBASE1.RowSource = 'crsHost.Host'
			Select crsHost
			Go Top
			lcHost = Host
			Thisform.cb_server._CBBASE1.Requery()
			Thisform.cb_server._CBBASE1.Value=lcHost
		Else
			Quit
		ENDIF
		
		&& daca am pornit programul prin parametri nu arat forma
		If goRoa.lParametri
			This.Visible = .F.
			This.do_login()
		Endif
	ENDPROC

	PROCEDURE KeyPress
		Lparameters nKeyCode, nShiftAltCtrl
		Do Case
		Case nKeyCode=27 And nShiftAltCtrl=0
			Nodefault
			If aMessagebox("Sunteti sigur ca doriti sa inchideti fereastra?",4+32+256,"Confirmare")==6
				This.do_renunt()
			ENDIF
		Case nKeyCode=6 And nShiftAltCtrl=2
			NODEFAULT
			This.do_termin()
		Endcase
		
	ENDPROC

	PROCEDURE populate_host
		Local lnValid
		lnValid = goRoa.GetcrsSecurity()
		Dimension laDrivere[30]
		Thisform.odbcreg1.getodbcdrvrs(@laDrivere,.T.)
		Select crshost
		Scan
			lcHost=Alltrim(Upper(Host))
			If Ascan(laDrivere,lcHost,1)=0
				Delete Next 1
			Endif
		Endscan
		Return lnValid
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_mesaj 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="lbl_mesaj1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Nu1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Da1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="imagine1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lbl_mesaj2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txt_numar" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*p: nnr
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		Desktop = .T.
		DoCreate = .T.
		Height = 192
		Name = "frm_mesaj"
		nnr = 0
		Width = 400
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 402
		_shape1.ZOrderSet = 3
		_SHAPE2.Height = 29
		_SHAPE2.Left = 367
		_SHAPE2.Name = "_SHAPE2"
		_SHAPE2.Top = 0
		_SHAPE2.Width = 34
		_SHAPE2.ZOrderSet = 6
		LB_TITLU_ALB_B121.Caption = "Titlu"
		LB_TITLU_ALB_B121.FontBold = .T.
		LB_TITLU_ALB_B121.Name = "LB_TITLU_ALB_B121"
		LB_TITLU_ALB_B121.TabIndex = 5
		LB_TITLU_ALB_B121.ZOrderSet = 7
		BUT_TERMIN1.Left = 368
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 1
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 9
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT 'Da1' AS but_da WITH ;
		Height = 30, ;
		Left = 151, ;
		Name = "Da1", ;
		TabIndex = 2, ;
		Top = 156, ;
		Width = 55, ;
		ZOrderSet = 2
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'imagine1' AS image WITH ;
		BackStyle = 0, ;
		Height = 33, ;
		Left = 12, ;
		Name = "imagine1", ;
		Picture = ..\..\, ;
		Top = 48, ;
		Width = 32, ;
		ZOrderSet = 4
		*< END OBJECT: BaseClass="image" />

	ADD OBJECT 'lbl_mesaj1' AS _lbbase WITH ;
		Alignment = 2, ;
		AutoSize = .F., ;
		Caption = "mesaj1", ;
		FontSize = 10, ;
		Height = 102, ;
		Left = 51, ;
		Name = "lbl_mesaj1", ;
		Style = 0, ;
		TabIndex = 4, ;
		Top = 42, ;
		Width = 339, ;
		WordWrap = .T., ;
		ZOrderSet = 0
		*< END OBJECT: ClassLib="_lb_base.vcx" BaseClass="label" />

	ADD OBJECT 'lbl_mesaj2' AS _lbbase WITH ;
		Alignment = 2, ;
		Caption = "mesaj2", ;
		FontSize = 10, ;
		Height = 18, ;
		Left = 178, ;
		Name = "lbl_mesaj2", ;
		TabIndex = 6, ;
		Top = 65, ;
		Width = 44, ;
		ZOrderSet = 5
		*< END OBJECT: ClassLib="_lb_base.vcx" BaseClass="label" />

	ADD OBJECT 'Nu1' AS but_nu WITH ;
		Height = 30, ;
		Left = 207, ;
		Name = "Nu1", ;
		TabIndex = 3, ;
		Top = 156, ;
		Width = 55, ;
		ZOrderSet = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'txt_numar' AS textbox WITH ;
		Alignment = 2, ;
		BackStyle = 0, ;
		BorderStyle = 0, ;
		ControlSource = "thisform.nnr", ;
		FontBold = .T., ;
		FontSize = 10, ;
		Height = 23, ;
		InputMask = (get_mask(12,gnPa)), ;
		Left = 264, ;
		Name = "txt_numar", ;
		TabIndex = 7, ;
		TabStop = .F., ;
		Top = 66, ;
		Width = 97, ;
		ZOrderSet = 8
		*< END OBJECT: BaseClass="textbox" />
	
	PROCEDURE actualizeaza_drepturi
		*!*
	ENDPROC

	PROCEDURE Init
		Lparameters tctitlu,tcimagine,tctip,tcmesaj1,tmesaj2
		
		DoDefault()
		
		With This
			.lb_titlu_alb_b121.Caption = tctitlu
			.imagine1.Picture = Iif(Empty(tcimagine),[info_c.ico],tcimagine)
			.lbl_mesaj1.Caption = Iif(Empty(tcmesaj1),[],tcmesaj1)
			If Type('tmesaj2') = 'N'
				.lbl_mesaj2.Visible = .F.
				.nnr = tmesaj2
				lnCul = Iif(.nnr<0,Rgb(255,0,0),Iif(.nnr>0,Rgb(0,0,255),Rgb(0,255,0)))
				.txt_numar.ForeColor = lnCul
				.txt_numar.Left = 151
			Else
				.lbl_mesaj2.Caption = Iif(Empty(tmesaj2),[],tmesaj2)
				.txt_numar.Visible = .F.
			Endif
		
			Do Case
			Case Upper(Alltrim(tctip)) = [AVERTIZARE] Or Upper(Alltrim(tctip)) = [INFORMARE] Or Empty(tctip)
				.da1.Visible = .F.
				.nu1.Visible = .F.
				._shape2.Visible = .T.
				.but_termin1.Visible = .T.
			Case Upper(Alltrim(tctip)) = [INTREBARE]
				.da1.Visible = .T.
				.nu1.Visible = .T.
				._shape2.Visible = .F.
				.but_termin1.Visible = .F.
			Endcase
		Endwith
	ENDPROC

	PROCEDURE KeyPress
		Lparameters nKeyCode, nShiftAltCtrl
		Do Case
		Case nKeyCode=27 And nShiftAltCtrl=0
			Nodefault
			This.do_renunt()
		Case nKeyCode=6 And nShiftAltCtrl=2
			NODEFAULT
			This.do_termin()
		Endcase
		
	ENDPROC

	PROCEDURE Show
		LPARAMETERS nStyle
		IF !FILE(THIS.Imagine1.PICTURE)
			THIS.IMagine1.Visible=.F.
		ENDIF 
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_start_firma_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="Image1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="CbFima" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="CbLuna" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="CbAn" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Lb_firma" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Lb_luna" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Lb_an" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: caut_luna_an
		*m: filtrez_luni
		*p: can
		*p: cfirma
		*p: cluna
		*p: nnrluna
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 0
		can = 
		cfirma = 
		cluna = 
		DoCreate = .T.
		Height = 144
		Name = "frm_start_firma_nou"
		nnrluna = 0
		Width = 404
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 435
		_shape1.ZOrderSet = 1
		_shape2.Height = 29
		_shape2.Left = 370
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 63
		_shape2.ZOrderSet = 2
		Lb_titlu_alb_b121.Caption = "ALEGEȚI FIRMA / ANUL / LUNA"
		Lb_titlu_alb_b121.FontSize = 10
		Lb_titlu_alb_b121.Left = 9
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 6
		Lb_titlu_alb_b121.Top = 11
		Lb_titlu_alb_b121.ZOrderSet = 3
		BUT_TERMIN1.Left = 375
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 4
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 4
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

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

	ADD OBJECT 'CbAn' AS combobox WITH ;
		ControlSource = "thisform.can", ;
		FontName = "Arial Narrow", ;
		Height = 24, ;
		Left = 173, ;
		Name = "CbAn", ;
		ReadOnly = .F., ;
		SpecialEffect = 1, ;
		Style = 2, ;
		TabIndex = 2, ;
		Top = 75, ;
		Width = 96, ;
		ZOrderSet = 8
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'CbFima' AS combobox WITH ;
		ColumnCount = 1, ;
		ControlSource = "thisform.cfirma", ;
		FontName = "Arial Narrow", ;
		Height = 24, ;
		HideSelection = .F., ;
		Left = 172, ;
		Name = "CbFima", ;
		RowSource = "v_firme.firma", ;
		RowSourceType = 2, ;
		SpecialEffect = 1, ;
		Style = 2, ;
		TabIndex = 1, ;
		Top = 40, ;
		Width = 213, ;
		ZOrderSet = 6
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'CbLuna' AS combobox WITH ;
		ControlSource = "thisform.cluna", ;
		FontName = "Arial Narrow", ;
		Height = 24, ;
		Left = 174, ;
		Name = "CbLuna", ;
		ReadOnly = .F., ;
		RowSource = "v_lunilean.numeluna", ;
		RowSourceType = 2, ;
		SpecialEffect = 1, ;
		Style = 2, ;
		TabIndex = 3, ;
		Top = 112, ;
		Width = 96, ;
		ZOrderSet = 7
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'Image1' AS image WITH ;
		Height = 150, ;
		Left = 0, ;
		Name = "Image1", ;
		Picture = ..\grafice\start.bmp, ;
		Stretch = 2, ;
		Top = 34, ;
		Width = 402, ;
		ZOrderSet = 0
		*< END OBJECT: BaseClass="image" />

	ADD OBJECT 'Lb_an' AS lb_simplu WITH ;
		Caption = "Anul:", ;
		FontBold = .T., ;
		FontName = "Courier New", ;
		FontSize = 11, ;
		Left = 83, ;
		Name = "Lb_an", ;
		TabIndex = 9, ;
		Top = 79, ;
		ZOrderSet = 11
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'Lb_firma' AS lb_simplu WITH ;
		Caption = "Firma:", ;
		FontBold = .T., ;
		FontName = "Courier New", ;
		FontSize = 11, ;
		Left = 82, ;
		Name = "Lb_firma", ;
		TabIndex = 7, ;
		Top = 44, ;
		ZOrderSet = 9
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'Lb_luna' AS lb_simplu WITH ;
		Caption = "Luna:", ;
		FontBold = .T., ;
		FontName = "Courier New", ;
		FontSize = 11, ;
		Left = 84, ;
		Name = "Lb_luna", ;
		TabIndex = 8, ;
		Top = 117, ;
		Width = 47, ;
		ZOrderSet = 10
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />
	
	PROCEDURE actualizeaza_drepturi
		*!*
	ENDPROC

	PROCEDURE caut_luna_an
		LOCAL lcSchema, lnIdFirma, lnSchema_noua
		
		
		
		THISFORM.cfirma = THIS.cbFima.DISPLAYVALUE
		
		SELECT v_firme
		LOCATE FOR ALLTRIM(firma) = ALLTRIM(THISFORM.cfirma)
		*---
		lcschemaParola=ALLTRIM(v_firme.parola)
		*---
		lcSchema = ALLTRIM(SCHEMA)
		lnschema_noua = schema_noua
		lnIdFirma = v_firme.id_firma
		*!*	modificare	17.12.2008
		gnIdFirma = lnIdFirma
		*!*	modificare	17.12.2008	^
		IF !FOUND()
			RETURN
		ENDIF
		IF USED("v_ancalendar")
			USE IN v_anCalendar
		ENDIF
		
		
		*---
		*DO schimba_firma WITH gnHandle,lcSchema,lcschemaParola,lnschema_noua
		lnsucces = schimba_firma(gnHandle,lcSchema,lnIdFirma,lcschemaParola,lnschema_noua)
		IF lnsucces<0
			aMESSAGEBOX(goExecutor.cEroare, 0+16, 'Eroare')
			RETURN
		ENDIF
		*---
		
		LOCAL lcNumeCal
		STORE '' TO lcNumeCal
		lcSelect = [select varvalue, col_an, col_luna, tip_col_an, tip_col_luna from syn_optiuni_programe WHERE id_prg_owner = ]+ALLTRIM(STR(gnIdProgram)) +[ and UPPER(varname) = 'CALENDAR']
		lcCursor = [crsNumeCal]
		lnsucces = goExecutor.oExecute(lcSelect,lcCursor)
		IF lnsucces < 0
			aMESSAGEBOX('Eroare la selectie ' + goExecutor.cEroare,0+16,"Eroare")
			RETURN
		ENDIF
		
		SELECT crsNumeCal
		IF RECCOUNT() = 0
			lcNumeCal = 'CALENDAR'
			lcCol_an = 'an'
			lcCol_luna = 'luna'
			lcSel_Col_an = 'an'
			lcSel_Col_luna = ' to_char(' + lcCol_luna + ') '
		ELSE
			lcNumeCal = ALLTRIM(crsNumeCal.varvalue)
			lcCol_an = ALLTRIM(col_an) && an
			lcCol_luna = ALLTRIM(col_luna) && luna
			lctip_col_an = UPPER(ALLTRIM(tip_col_an)) && roaCont = C, roaSal = N
			lctip_col_luna = UPPER(ALLTRIM(tip_col_luna))
			
			DO case
			CASE lctip_col_an = 'N'
				lcSel_Col_an = ' to_char(' + lcCol_an + ') '
			CASE lctip_col_an = 'C'
				lcSel_Col_an = lcCol_an
			ENDCASE 
				
			DO CASE 
			CASE lctip_col_luna = 'N'
				lcSel_Col_luna = ' to_char(' + lcCol_luna + ') '
			CASE lctip_col_luna = 'C'
				lcSel_Col_luna = lcCol_luna
			ENDCASE 	
		ENDIF
		
		* IF UPPER(lctip_col_an) = 'N'
		
		lcSelect = [select ] + lcSel_Col_an + [ as an, ] + lcSel_Col_luna + [ as nl ] + ;
			[ from ] + lcSchema + [.] + lcNumeCal + [ order by ] + lcCol_an + [ * 12 + ] + lcCol_luna
		
		* lcSelect = [select * from ] + lcSchema + [.] + lcNumeCal + [ order by an * 12 + nl]
		
		*lcSelect = [select * from ] + lcSchema + [.Calendar order by an * 12 + nl]
		lcCursor = [v_ancalendar]
		lnsucces = goExecutor.oExecute(lcSelect,lcCursor)
		IF lnsucces < 0
			aMESSAGEBOX(goExecutor.cEroare, 0+16, 'Eroare')
			RETURN
		ENDIF
		THISFORM.cban.ROWSOURCE = ''
		IF USED("crs_ani")
			USE IN crs_ani
		ENDIF
		
		SELECT DISTINCT an FROM v_anCalendar ORDER BY an INTO CURSOR crs_ani
		
		SELECT v_anCalendar
		GO BOTTOM
		IF gcS <> lcSchema
			gnLuna = 0
			gnAn = 0
		ENDIF
		IF gnLuna*gnAn <> 0
			*!*		SELECT v_lunilean
			*!*		LOCATE FOR nrluna = gnLuna
			SELECT crs_ani
			LOCATE FOR VAL(an) = gnAn
		
		
		ELSE
			*!*	*!*		SELECT v_lunilean
			*!*	*!*		LOCATE FOR nrluna = VAL(v_ancalendar.nl)
			SELECT crs_ani
			GO BOTTOM
		ENDIF
		
		*!*	thisform.cbLuna.DisplayValue = v_lunilean.numeluna
		*!*	thisform.nnrluna = v_lunilean.nrLuna
		SELECT crs_ani
		
		THISFORM.cban.ROWSOURCE = 'crs_ani.an'
		THISFORM.cban.ROWSOURCETYPE = 2
		THISFORM.cban.DISPLAYVALUE = crs_ani.an
		
		THIS.cban.REFRESH
		*!*	this.cbluna.Refresh
		*thisform.Refresh
		
		THISFORM.filtrez_luni
		
	ENDPROC

	PROCEDURE do_termin
		IF this.inainte_de_do_termin()
			gnButon = 1
			pnButon = 1
			Buton = 1
			pnIesire = 1
			this.hide 
			 
		 ENDIF 
		
		
	ENDPROC

	PROCEDURE filtrez_luni
		*!*	thisform.cAn = thisform.cbAn.DisplayValue 
		SELECT v_ancalendar
		SELECT c.nl,c.an,l.numeluna,l.nrluna ;
			FROM v_ancalendar c;
			JOIN v_lunilean l ON VAL(c.nl) = l.nrLuna AND VAL(c.an) = VAL(thisform.cAn) INTO CURSOR v_luni;
			ORDER BY l.nrluna
		thisform.cbLuna.RowSource = "v_luni.numeluna"
		IF gnLuna # 0 AND gnAn = VAL(thisform.cAn) AND ALLTRIM(gcs) = ALLTRIM(this.cbfima.DisplayValue)
			SELECT v_luni
			LOCATE FOR nrLuna = gnLuna
		ELSE 
			SELECT v_luni
			GO BOTTOM 
		ENDIF 
		SELECT v_luni
		thisform.cLuna = v_luni.numeluna
		thisform.cbLuna.DisplayValue = v_luni.numeluna
		thisform.nnrluna = v_luni.nrLuna
		thisform.cbluna.Refresh 
		
	ENDPROC

	PROCEDURE inainte_de_do_termin
		If Empty(This.cfirma)
			aMESSAGEBOX("Alegeti firma si dupa aceea apasati butonul Terminat",0,"Alegeti firma")
			Return .F.
		Else
			Public gcNumeUtilEnt
			gcNumeUtilEnt = []
			lcSql = [begin pack_def.citesteNumeEnt(?gnIdUtil,?@gcNumeUtilEnt); end;]
			If !goExecutor.oExecuta(lcSql)
				gcNumeUtilEnt = gcUserNameApp
			Endif
		Endif
		Return .T.
	ENDPROC

	PROCEDURE But_renunt1.Click
		IF thisform.inainte_de_do_renunt()
			gnButon = 2
			pnButon = 2
			Buton = 2
			pnIesire = 2
			
			
			Quit
			If buton = 1
				thisform.Release
			EndIf 
		ENDIF 
		
	ENDPROC

	PROCEDURE CbAn.InteractiveChange
		thisform.cAn = thisform.cbAn.DisplayValue 
		thisform.filtrez_luni 
	ENDPROC

	PROCEDURE CbFima.GotFocus
		thisform.caut_luna_an 
	ENDPROC

	PROCEDURE CbFima.InteractiveChange
		thisform.caut_luna_an 
	ENDPROC

	PROCEDURE CbFima.LostFocus
		*thisform.caut_luna_an 
	ENDPROC

	PROCEDURE CbLuna.InteractiveChange
		SELECT v_luni
		LOCATE FOR ALLTRIM(numeluna) = ALLTRIM(this.DisplayValue)
		IF FOUND()
			thisform.nnrluna = v_luni.nrLuna
		ENDIF 
	ENDPROC

	PROCEDURE CbLuna.LostFocus
		SELECT v_luni
		LOCATE FOR ALLTRIM(numeluna) = ALLTRIM(this.DisplayValue)
		IF FOUND()
			thisform.nnrluna = v_luni.nrLuna
		ENDIF 
	ENDPROC

ENDDEFINE
