Compile function DIALOG_REACT_MODE_EXPORT_EVENTS(CtrlEntId, Event, @PARAMS)
#pragma precomp SRP_PreCompiler
#window DIALOG_REACT_MODE_EXPORT

Declare subroutine Set_Property,Send_Message, SRP_Show_Window
Declare function Get_Property, Utility, Msg, Datetime, SRP_Datetime

$insert APP_INSERTS
$insert EVENT_SETUP
$insert MSG_EQUATES

// Update the arguments so that the OpenInsight OLE event will treate the ActiveX event as a native event handler.
If Event EQ 'OLE' then
	Transfer Event to OIEvent
	Transfer Param1 to Event
	Transfer Param2 to Param1
	Transfer Param3 to Param2
	*    Transfer Param4 to Param3
	*    Transfer Param5 to Param4
	*    Transfer Param6 to Param5
	*    Transfer Param7 to Param6
	*    Transfer Param8 to Param7
end

GoToEvent Event for CtrlEntID

Return EventFlow else EVENT_CONTINUE$

Event WINDOW.CREATE(CreateParam)
	
	GoSub Setup_OLE_Controls
	FormSize = '' 
	SRP_Show_Window(@Window, '', 'C', 'C', 1, '', False$, False$, FormSize)
	
end event

Event OLE_DATEPICKER_FROM.OnSelChange(FirstDate)
	
	
	SelectedDate    = Get_Property(CtrlEntId, 'OLE.Selection')
	Set_Property(@Window : '.OLE_SCHEDULE', 'OLE.Date', SelectedDate)
	Set_Property(@Window : '.DATE_FROM','DEFPROP', OCONV(SelectedDate,'DT4/HS'))
	
end event

Event OLE_DATEPICKER_TO.OnSelChange(FirstDate)
	
	
	SelectedDate    = Get_Property(CtrlEntId, 'OLE.Selection')
	Set_Property(@Window : '.OLE_SCHEDULE', 'OLE.Date', SelectedDate)
	Set_Property(@Window : '.DATE_TO','DEFPROP', OCONV(SelectedDate,'DT4/HS'))
	
end event

Event PUB_DIR_BROWSE.CLICK
	value = "Select a directory" : @fm : "c:\temp"
	dir   = Utility( "CHOOSEDIR", @window, value)
	
	if dir NE '' then
		Set_Property(@Window : '.FILE_PATH', 'DEFPROP', dir: '\')	
	end
	
end event

Event PUB_EXPORT.CLICK()
    StartDt  = Get_Property(@WINDOW:'.DATE_FROM','TEXT')
    EndDt    = Get_Property(@WINDOW:'.DATE_TO','TEXT')
    FilePath = Get_Property(@WINDOW:'.FILE_PATH','TEXT')
    If StartDt EQ '' then
       Msg(@Window, 'You must select FROM date.')
       return
    end
    If EndDt EQ '' then
       Msg(@Window, 'You must select a TO date.')
       return
    end
    IF ICONV(EndDt, "DT") LT ICONV(StartDt, "DT") then
       Msg(@Window, 'End date is less than start date.')
       return
    end
    IF FilePath EQ '' then
       Msg(@Window, 'You must select a directory to export to.')
       return
    end
    End_Dialog( @WINDOW, StartDt:@FM:EndDt:@FM:FilePath )
end event

Event PUB_LAST_13.CLICK()
	TimeNow = Datetime()
	StartTime = SRP_DateTime('AddHours', TimeNow, -13)
	Set_Property(@Window : '.DATE_FROM','TEXT', OCONV(StartTime,'DT4/HS'))
	Set_Property(@Window : '.DATE_TO','TEXT', OCONV(TimeNow,'DT4/HS'))
	
end event

Event PUB_LAST_25.CLICK()
	TimeNow = Datetime()
	StartTime = SRP_DateTime('AddHours', TimeNow, -25)
	Set_Property(@Window : '.DATE_FROM','TEXT', OCONV(StartTime,'DT4/HS'))
	Set_Property(@Window : '.DATE_TO','TEXT', OCONV(TimeNow,'DT4/HS'))
	
end event

Setup_OLE_Controls:

Ctrl = @Window : '.OLE_DATEPICKER_FROM'
Set_Property(Ctrl, 'OLE.Border', 'XP Flat')
Set_Property(Ctrl, 'OLE.Font', 'Segoe UI' : @SVM : '9')
Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnSelChange', 1)

Ctrl = @Window : '.OLE_DATEPICKER_TO'
Set_Property(Ctrl, 'OLE.Border', 'XP Flat')
Set_Property(Ctrl, 'OLE.Font', 'Segoe UI' : @SVM : '9')
Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnSelChange', 1)

return


