Compile function NDW_LOAD_UNLOAD_EXTRA_EVENTS(CtrlEntId, Event, @PARAMS)
#pragma precomp SRP_PreCompiler
#window NDW_LOAD_UNLOAD_EXTRA

Declare subroutine End_Dialog, Post_Event, Database_Services, Error_Services, Msg
Declare subroutine Set_Property, Rds_Services
Declare function Database_Services, Error_Services
Declare function Get_Property

$Insert EVENT_SETUP
$Insert LOGICAL
$Insert RDS_EQUATES

GoToEvent Event for CtrlEntId else
	// Event not implemented
end

Return EventFlow or 1

//-----------------------------------------------------------------------------
// EVENT HANDLERS
//-----------------------------------------------------------------------------

Event WINDOW.CREATE(CreateParam)
	ResponseValue = Set_Property(@Window, '@responsevalue', 0)
	RDSNo         = CreateParam
	If RowExists('RDS', RDSNo) then
		Set_Property(@Window : '.EDL_RDS', 'TEXT', RDSNo)
		GoSub Refresh
	end else
		ResponseValue = Set_Property(@Window, '@responsevalue', 0)
		Post_Event(@Window, 'CLOSE')
	end
	
End Event

Event WINDOW.CLOSE(CancelFlag)
	ResponseValue = Get_Property(@Window, '@responsevalue')
	End_Dialog(@Window, ResponseValue)
end event

//Signature buttons

Event PUB_SIGN_UNLOAD_EX_1.CLICK()
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	Rds_Services('SignUnloadExtra1', RDSNo, @USER4)
	If Error_Services('NoError') then
		Msg(@Window, 'Unload Extra 1 Signed!')
	end else
		Msg(@Window, Error_Services('GetMessage'))
	end
	GoSub Refresh	
end event

Event PUB_SIGN_LOAD_EX_1.CLICK()
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	Rds_Services('SignLoadExtra1', RDSNo, @USER4)
	If Error_Services('NoError') then
		Msg(@Window, 'Load Extra 1 Signed!')
	end else
		Msg(@Window, Error_Services('GetMessage'))
	end
	GoSub Refresh	
end event

Event PUB_SIGN_UNLOAD_EX_2.CLICK()
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	Rds_Services('SignUnloadExtra2', RDSNo, @USER4)
	If Error_Services('NoError') then
		Msg(@Window, 'Unload Extra 2 Signed!')
	end else
		Msg(@Window, Error_Services('GetMessage'))
	end
	GoSub Refresh	
end event

Event PUB_SIGN_LOAD_EX_2.CLICK()
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	Rds_Services('SignLoadExtra2', RDSNo, @USER4)
	If Error_Services('NoError') then
		Msg(@Window, 'Load Extra 2 Signed!')
	end else
		Msg(@Window, Error_Services('GetMessage'))
	end
	GoSub Refresh	
end event

//Clear Signature Buttons

Event PUB_CLEAR_UNLOAD_EX_1.CLICK()
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	Rds_Services('UnsignUnloadExtra1', RDSNo, @User4)
	If Error_Services('NoError') then
		Msg(@Window, 'Unload Extra 1 unsigned!')
	end else
		Msg(@Window, Error_Services('GetMessage'))
	end
	GoSub Refresh	
end event

Event PUB_CLEAR_LOAD_EX_1.CLICK()
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	Rds_Services('UnsignLoadExtra1', RDSNo, @User4)
	If Error_Services('NoError') then
		Msg(@Window, 'Load Extra 1 unsigned!')
	end else
		Msg(@Window, Error_Services('GetMessage'))
	end
	GoSub Refresh	
end event

Event PUB_CLEAR_UNLOAD_EX_2.CLICK()
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	Rds_Services('UnsignUnloadExtra2', RDSNo, @User4)
	If Error_Services('NoError') then
		Msg(@Window, 'Unload Extra 2 unsigned!')
	end else
		Msg(@Window, Error_Services('GetMessage'))
	end
	GoSub Refresh	
end event

Event PUB_CLEAR_LOAD_EX_2.CLICK()
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	Rds_Services('UnsignLoadExtra2', RDSNo, @User4)
	If Error_Services('NoError') then
		Msg(@Window, 'Load Extra 2 unsigned!')
	end else
		Msg(@Window, Error_Services('GetMessage'))
	end
	GoSub Refresh
end event

//-----------------------------------------------------------------------------
// INTERNAL GO-SUBS
//-----------------------------------------------------------------------------


***************
Refresh:
***************
	
	RDSNo = Get_Property(@Window : '.EDL_RDS', 'TEXT')
	If RowExists('RDS', RDSNo) then
		RDSRec                    = Database_Services('ReadDataRow', 'RDS', RDSNo)
		//Unload Extra 1
		UnloadExtra1Signature     = RDSRec<RDS_OP_OUT_EX1$>
		UnloadExtra1UserFirstLast = xlate( 'LSL_USERS', UnloadExtra1Signature, 'FIRST_LAST', 'X' )
		UnloadExtra1Date          = OConv(RDSRec<RDS_OP_OUT_EX1_DATE$>, 'D')
		UnloadExtra1Time          = Oconv(RDSRec<RDS_OP_OUT_EX1_TIME$>, 'MT')
		//Load Extra 1
		LoadExtra1Signature       = RDSRec<RDS_OP_IN_EX2$>
		LoadExtra1UserFirstLast   = xlate( 'LSL_USERS', LoadExtra1Signature, 'FIRST_LAST', 'X' )
		LoadExtra1Date            = Oconv(RDSRec<RDS_OP_IN_EX2_DATE$>, 'D')
		LoadExtra1Time            = Oconv(RDSRec<RDS_OP_IN_EX2_TIME$>, 'MT')
		//Unload Extra 2
		UnloadExtra2Signature     = RDSRec<RDS_OP_OUT_EX2$>
		UnloadExtra2UserFirstLast = xlate( 'LSL_USERS', UnloadExtra2Signature, 'FIRST_LAST', 'X' )
		UnloadExtra2Date          = Oconv(RDSRec<RDS_OP_OUT_EX2_DATE$>, 'D')
		UnloadExtra2Time          = Oconv(RDSRec<RDS_OP_OUT_EX2_TIME$>, 'MT')
		//Load Extra 2
		LoadExtra2Signature       = RDSRec<RDS_OP_IN_EX3$>
		LoadExtra2UserFirstLast   = xlate( 'LSL_USERS', LoadExtra2Signature, 'FIRST_LAST', 'X' )
		LoadExtra2Date            = Oconv(RDSRec<RDS_OP_IN_EX3_DATE$>, 'D')
		LoadExtra2Time            = Oconv(RDSRec<RDS_OP_IN_EX3_TIME$>, 'MT')
		
		//Populate text fields
		Set_Property(@Window : '.EDL_UNLOAD_EX_1_USER', 'TEXT', UnloadExtra1UserFirstLast)
		Set_Property(@Window : '.EDL_UNLOAD_EX_1_DATE', 'TEXT', UnloadExtra1Date)
		Set_Property(@Window : '.EDL_UNLOAD_EX_1_TIME', 'TEXT', UnloadExtra1Time)
		Set_Property(@Window : '.EDL_LOAD_EX_1_USER', 'TEXT', LoadExtra1UserFirstLast)
		Set_Property(@Window : '.EDL_LOAD_EX_1_DATE', 'TEXT', LoadExtra1Date)
		Set_Property(@Window : '.EDL_LOAD_EX_1_TIME', 'TEXT', LoadExtra1Time)
		Set_Property(@Window : '.EDL_UNLOAD_EX_2_USER', 'TEXT', UnloadExtra2UserFirstLast)
		Set_Property(@Window : '.EDL_UNLOAD_EX_2_DATE', 'TEXT', UnloadExtra2Date)
		Set_Property(@Window : '.EDL_UNLOAD_EX_2_TIME', 'TEXT', UnloadExtra2Time)
		Set_Property(@Window : '.EDL_LOAD_EX_2_USER', 'TEXT', LoadExtra2UserFirstLast)
		Set_Property(@Window : '.EDL_LOAD_EX_2_DATE', 'TEXT', LoadExtra2Date)
		Set_Property(@Window : '.EDL_LOAD_EX_2_TIME', 'TEXT', LoadExtra2Time)
	end else
		ResponseValue = Set_Property(@Window, '@responsevalue', 0)
		Post_Event(@Window, 'CLOSE')
	end
	
return


