Demo entry 4123341

Selectie unitate

   

Submitted by selunit on Mar 22, 2016 at 05:49
Language: FoxPro. Code size: 6.6 kB.

PARAMETER  poz_x, poz_y, cond_alg

IF oapplic.issql
	* cond_alg = 'appunit.cod_unit ' + sqlval(mydb)
	IF EMPTY(cond_alg)
		cond_alg = '1=1' 		
	ENDIF
	
	DO CASE
		CASE oapplic.abreviererol = 'ADM'
		CASE oapplic.abreviererol = 'AUD'
			*
		CASE oapplic.abreviererol = 'ADG'
			cond_alg = cond_alg + ' AND appunit.idparent = ' + sqlval(oapplic.iduser)
		OTHERWISE
			IF oapplic.iserp
				m.iduseradg = dac(oapplic.gene.accuser.sursadb,'idparent', 'idacc = ' + sqlval(oapplic.iduser))
				IF m.iduseradg != 0 AND m.iduseradg != oapplic.iduser
					cond_alg = cond_alg + ' AND appunit.idparent = ' + sqlval(m.iduseradg)
				ENDIF
			ENDIF
	ENDCASE
	
	***marius - 17.12.2012
	
	TEXT TO mycmd TEXTMERGE NOSHOW PRETEXT 7
		SELECT unitatea, cod_unit, tipunitate, connext  
		FROM <<oapplic.tblappunit>> appunit 
		<<IIF(oapplic.idrol != 0, ' LEFT JOIN ADMINDB..gene_accunit accunit ON accunit.idappunit = appunit.idappunit LEFT JOIN ADMINDB..gene_accuser accuser ON accuser.idacc = accunit.idacc ', '')>>		
		WHERE appunit.idapplic = <<sqlval(oapplic.idapplic)>>
		<<IIF(oapplic.idrol != 0, ' AND accunit.idacc = ' + sqlval(oapplic.iduser), '')>>  
	    AND <<cond_alg>>
		ORDER BY 1
	ENDTEXT 
	arsqlexec(mycmd)
 	tempunit = danume_f('tempunit.dbf')
	arcopy(tempunit)
	
	IF !oapplic.azure AND oapplic.sqllogin != '' AND LOWER(oapplic.sqllogin) != 'sa' AND !INLIST(oapplic.abreviererol, 'ADM', 'AUD')
		tempaccunit = danume_f('tempaccunit.dbf')
	*	arsqlexec('exec sp_MSloginmappings' + sqlval(oapplic.sqllogin))  &&  'FMM' 

		activez(tempunit)	
 		sqlcmd = ''
 		SCAN			
			TEXT TO sqlcmd ADDITIVE TEXTMERGE NOSHOW PRETEXT 7 
 				SELECT '<<ALLTRIM(cod_unit)>>' AS DBName , HAS_PERMS_BY_NAME('<<ALLTRIM(cod_unit)>>', 'DATABASE', 'ANY') AS perms
 				UNION ALL 				  		
 			ENDTEXT

*!*				TEXT TO sqlcmd ADDITIVE TEXTMERGE NOSHOW PRETEXT 7 
*!*	 				SELECT '<<ALLTRIM(cod_unit)>>' AS DBName , COALESCE(HAS_DBACCESS ('<<ALLTRIM(cod_unit)>>'), 0) AS perms
*!*	 				UNION ALL 				  		
*!*	 			ENDTEXT 			
 		ENDSCAN
 		sqlcmd = LEFT(sqlcmd, RAT('UNION ALL', sqlcmd)-1)
		arsqlexec(sqlcmd) 	
 		arcopy(tempaccunit)			
	 	activez(tempunit)	
 		SCAN		
 			IF dac(tempaccunit, 'perms', 'DBName = ' + sqlval(ALLTRIM(tempunit.cod_unit))) = 0
 				DELETE
 			ENDIF
 		ENDSCAN	
 	ENDIF			
 
 	activez(tempunit)	
	DO CASE 
		CASE RECCOUNT() = 0		&& Nu mai exista unitate
			alert('Nu aveti acces la baza de date ' + STREXTRACT(cond_alg, '=', ''))
			arlogout()			
		CASE RECCOUNT() > 1	OR oapplic.connectionstringi != oapplic.connectionstring	&& nu e unitate unica
   		 			
   			m.unitatea = dac(m.tempunit, 'unitatea', 'cod_unit = ' + sqlval(oapplic.activdbi) +  ' AND connext = ' + sqlval(oapplic.connectionstringi) )	
   			IF _TALLY = 0 AND daconfig('MULTISERVER')='ON'   		
   				INSERT INTO (tempunit) (cod_unit, unitatea, connext) ;
   				VALUES (oapplic.activdbi, oapplic.unitatai, oapplic.connectionstringi)
   			ENDIF
   			* am plecat de la regie la directie de acolo la ocol si sa pot revin 
    
  			IF !EMPTY(oapplic.multiserver)

   				INSERT INTO (tempunit) (cod_unit, unitatea, connext) ;
	   				VALUES (oapplic.activdbi, REPLICATE('-', 7) + ' Servere ' + REPLICATE('-', 7), '')  					

  				nrserver = ALINES(aserver, oapplic.multiserver, 0, '|')
  				FOR EACH element IN aserver
  				
  					mydb = STREXTRACT(element + ';', 'DATABASE=', ';')
  					myunitati = STREXTRACT(element, '', '#')
  					myconnectionstring = STREXTRACT(element, '#', '')	   				
	   				INSERT INTO (tempunit) (cod_unit, unitatea, connext) ;
	   				VALUES (mydb, myunitati, myconnectionstring)  					
  				ENDFOR 
  			ENDIF
  				
   			argotop()
   			IF  RECCOUNT()> 1 
   				makeglist('Unitatea#Unitatea#220', '', .F., 1, 1, 1)
   			ENDIF
	ENDCASE

				
	m.calea = ALLTRIM(Cod_Unit)  
	m.numeunit = ALLTRIM(Unitatea)   
	oapplic.activdb = m.calea 
	 
  
	IF !EMPTY(connext) AND oapplic.connectionstring != connext  && fac o noua conexiune  && exista deja in lista de coneziuni ?
	
		TRY
			p_handle = openconnexion(connext, m.calea)
		CATCH TO err
			arwait('Conectare nereusita!',3)
			p_handle = openconnexion(oapplic.connectionstringi, oapplic.activdbi)		
		ENDTRY
			
		oapplic.sqlhandle = p_handle
		oapplic.connectionstring = 	connext
		oapplic.serveractiv = m.numeunit
	ENDIF
					
	IF !ExistSQLDB(oapplic.activdb) 
		alert('Eroare conectare baza de date: ' + oapplic.activdb,5,'OK')	
		IF 'Da' = alert('Stergeti referinta catre baza de date: ' + oapplic.activdb + ' ?',5,'Nu;Da')
			mycmd = 'DELETE FROM ' +  oapplic.tblappunit + ' WHERE idapplic = ' + sqlval(oapplic.idapplic) + ' AND Cod_Unit = ' + sqlval(oapplic.activdb)
			arsqlexec(mycmd)
			arwait('Stergere referinta catre baza de date: ' + oapplic.activdb, 2, 'LOG')
		ENDIF
		arlogout()
	ELSE
	
		IF oapplic.issql AND !oapplic.azure 
			arsqlexec('USE '+ oapplic.activdb)
			oapplic.database = oapplic.activdb
		ENDIF
	ENDIF
	IF !EMPTY(oapplic.serveractiv)	
		_SCREEN.caption = oapplic.appname + ' ' + oapplic.serveractiv
	ENDIF
ELSE  && dbf

	IF EMPTY(poz_x)
		poz_x = 4
	ENDIF
	IF EMPTY(poz_y)
		poz_y = 19
	ENDIF

	m.tempuni=danume_f('TEMPUNI') 
	Gen_Unit(m.tempuni)

	m.uniord=danume_f('UNIORD') 
	SELECT * from (m.tempuni) INTO TABLE (m.uniord) ORDER BY unitatea

	IF LASTKEY() != 10
		SET FILTER TO activ
	ENDIF

	IF !EMPTY(cond_alg)
		LOCATE FOR &cond_alg
		IF !FOUND()
			alert("Specificatia din configurarea initiala pentru;" + ;
				"UNITATE SELECTATA este incorecta.", 'Q', "Ok")
		ENDIF
	ENDIF

	DO CASE
		CASE RECCOUNT() = 0		&& dupa stergerea ultimei unitati
			WAIT WINDOW 'Relansati aplicatia.' TIMEOUT 2
			QUIT
		CASE RECCOUNT() = 1		&& unitate unica
			m.calea = ALLTRIM(Cod_Unit)  
			m.numeunit = ALLTRIM(Unitatea)   
		OTHERWISE				&& mai multe unitati
			SELECT userunit FROM (m.user) INTO ARRAY idle;
			WHERE iduser = m.crtid AND idapplic = m.idapplic	
			gasit = !EMPTY(_TALLY)
			IF gasit
				LOCATE FOR cod_unit = IDLE[1]
			ENDIF		
			IF !FOUND() OR !gasit
				makelist('Unitatea','220','Lista unitatilor',1,1)			
	*			makeglist('Unitatea#Unitatea#220', '', .F., 1, 1, 1)
	
			ENDIF
			m.calea = ALLTRIM(Cod_Unit)  
			m.numeunit = ALLTRIM(Unitatea)   
	ENDCASE
	oapplic.activdb = m.calea 
ENDIF

calea1 = 'UNITATI\' + m.calea+'\'
IF AT('.INI', m.calea) = 0
	calea11 = m.calea10 + m.calea + '\'
ELSE
	calea11 = m.calea10 + STRTRAN(m.calea,'.INI','') + '\'
ENDIF

This snippet took 0.03 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).