Lparameters llSilentios, lnOptiune, lnZile


If Empty(m.lnOptiune)
	lnOptiune = xmenu('Creeaza job import RORIS;Verifica log')
Endif
If Empty(m.lnOptiune)
	Return
Endif

lnHandle = SQLConnect('ROA', 'ACN', 'ROMFASTSOFT')

If m.lnHandle <= 0
	Aerror(laEroare)
	WriteLog(laEroare(3))
	IF !m.llSilentios
		Messagebox(laEroare(3))
	ENDIF 	
	Return
Endif

Do Case
	Case m.lnOptiune = 1
		IF EMPTY(m.lnZile)
			lcZile = Inputbox('Numar zile de tranzit pentru import (implicit 30)', 'Nr zile', '30')
			lnZile = Iif(!Empty(Val(m.lcZile)), Val(m.lcZile), 30)
		ENDIF 	

		Private ptLastGenerationTime
		ptLastGenerationTime = Date() - m.lnZile
		
		If m.llSilentios OR (Messagebox('Se lanseaza importul pentru tranzitele >= ' + Ttoc(m.ptLastGenerationTime) + '?',4+32,_Screen.Caption) = 6)
			lcSql = [begin pack_acn_import.import_roris_job(?ptLastGenerationTime); end;]
			lnSucces = SQLExec(m.lnHandle, m.lcSql)
			If m.lnSucces > 0
				WriteLog('S-a creat job-ul pentru import')
				
				IF !m.llSilentios
					Messagebox('S-a creat job-ul pentru import',0+64,_Screen.Caption,10)
				ENDIF 	
			Else
				Aerror(laEroare)
				WriteLog(laEroare(3))
				IF !m.llSilentios
					Messagebox(laEroare(3))
				ENDIF 	
			Endif
		Endif
	Case m.lnOptiune = 2
		lcSql = [select to_char(substr(info,1,200)) as info, dataora from info where locatia = 'import_roris' and trunc(dataora) = trunc(sysdate) order by dataora desc]
		lnSucces = SQLExec(m.lnHandle, m.lcSql, 'crsImportTemp')
		If m.lnSucces > 0
			CREATE CURSOR crsImport (info c(200) null, dataora T)
			SELECT crsImport
			APPEND FROM DBF('crsImportTemp')
			
			Select crsImport
			GO TOP 
			BROWSE TITLE 'LOG IMPORT (ESC pentru iesire)' PREFERENCE IMPORT
			USE IN (SELECT('crsImportTemp'))			
			USE IN (SELECT('crsImport'))						
		Else
			Aerror(laEroare)
			Messagebox(laEroare(3))
		ENDIF

	Case m.lnOptiune = 3
		TEXT TO lcsql NOSHOW 
SELECT LOG_ID,
   CAST(LOG_DATE AS DATE) as log_date,
   JOB_NAME,
   STATUS,
   CAST(actual_start_date AS DATE) as start_date,
   to_char(RUN_DURATION) AS duration,
   additional_info as errors
  FROM USER_SCHEDULER_JOB_RUN_DETAILS
  WHERE TRUNC(LOG_DATE) >= TRUNC(SYSDATE) - 7
 ORDER BY LOG_ID DESC
		ENDTEXT 
				
		lnSucces = SQLExec(m.lnHandle, m.lcSql, 'crsJobTemp')
		If m.lnSucces > 0
			CREATE CURSOR crsJob (log_id I, log_date T null, job_name C(200) null, status C(20) null, start_date T null, duration C(30) null, errors C(250) null)
			SELECT crsJob
			APPEND FROM DBF('crsJobTemp')
			
			Select crsJob
			GO TOP 
			BROWSE TITLE 'Stare joburi import (ESC pentru iesire)' PREFERENCE JOB
			USE IN (SELECT('crsJobTemp'))
			USE IN (SELECT('crsJob'))			
		Else
			Aerror(laEroare)
			Messagebox(laEroare(3))
		ENDIF		


Endcase

SQLDisconnect(m.lnHandle)



*-------------------------------------------
* Function...: Xmenu
* Author.....: MARTIN
* Date.......: 04/06/1997
* Notes......: Based on an idea from Steve Zimmelman for FoxPro 2.x
* Parameters.: tcItems = Semicolon-separated String with the various options
* ...........: tnBar   = Initially selected item (default=1)
* Returns....: Selected item number
* See Also...: PROMPT() [FoxPro Native]
*
Procedure xmenu
	Lparameters TCITEMS, TNBAR

	Local NITEMCOUNT, AITEMS, X, NROW, NCOL, CTITLE, NLASTPOS, CCOLOR, AITEMS

	Private CPOPMENU, NSELECT	&& They flow into the GetChoice internal procedure

	If Pcount() < 2
		TNBAR = 1
	Endif

	Activate Screen

	* Parse every item
	*
	m.NITEMCOUNT = Occurs( ';', TCITEMS ) + 1
	Dimen AITEMS[ m.nItemCount ]
	m.NLASTPOS = 1

	For m.X = 1 To m.NITEMCOUNT

		If m.X < m.NITEMCOUNT

			AITEMS[ m.x ] = Subs( m.TCITEMS, m.NLASTPOS, ;
				( At( ';', m.TCITEMS, m.X ) - 1 ) - m.NLASTPOS + 1 )
		Else
			AITEMS[ m.x ] = Subs( m.TCITEMS, m.NLASTPOS, ;
				( Len( m.TCITEMS ) - m.NLASTPOS ) + 1 )
		Endif

		If AITEMS[ m.x ] # "\-"

			AITEMS[ m.x ] = Allt( AITEMS[ m.x ] )
		Endif

		m.NLASTPOS = At( ';', m.TCITEMS, m.X ) + 1
	Next

	* Calculates the mouse pointer position
	*
	m.NROW = Iif( Mrow() + m.NITEMCOUNT < Srow(), Mrow() - 1, Srow() - m.NITEMCOUNT )
	m.NCOL = Iif( Mcol() + 10 < Scol(), Mcol() - 3, Mcol() - 13 )

	* Gets an unique name for the pop-up
	*
	m.CPOPMENU = 'M' + Sys(3) + "_"

	Define Popup ( m.CPOPMENU ) SHORTCUT Relative From NROW, NCOL

	For m.X = 1 To m.NITEMCOUNT

		Define Bar m.X Of ( m.CPOPMENU ) Prompt AITEMS[ m.x ]
	Next

	m.CANS = ""
	m.NSELECT = 0
	Clear Type

	On Selection Popup ( m.CPOPMENU ) Do GETCHOICE

	Activate Popup ( m.CPOPMENU ) Bar TNBAR

	Pop Key
	Release Popup ( m.CPOPMENU )

	Return Iif( Lastkey() = 27, 0, m.NSELECT )

Endproc && XMENU

*--------------------
Procedure GETCHOICE

	m.NSELECT = Bar()

	Deactivate Popup ( m.CPOPMENU )

Endproc && GETCHOICE

