COMPILE FUNCTION Comm_Surf_Scan(Instruction, Parm1,Parm2)

/*
	Commuter module for Surf_Scan window
	
	04/15/2004 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Center_Window, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message

$INSERT POPUP_EQUATES
$INSERT APPCOLORS

EQU CRLF$	TO \0D0A\

ErrTitle = 'Error in Comm_Surf_Scan'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Instruction = 'Create' 		; GOSUB Create
	CASE Instruction = 'Refresh'		; GOSUB Refresh
	CASE Instruction = 'Read'			; GOSUB Read
	CASE Instruction = 'Write'			; GOSUB Write
	CASE Instruction = 'Clear'			; GOSUB Clear
	CASE Instruction = 'LUStage'		; GOSUB LUStage
	CASE Instruction = 'LURdsNo'		; GOSUB LURdsNo
	CASE Instruction = 'SumOfDefAvgLF'	; GOSUB SumOfDefAvgLF
	CASE Instruction = 'HazeAvgAvgLF'	; GOSUB HazeAvgAvgLF
	CASE Instruction = 'Close'			; GOSUB Close
	CASE 1
		ErrorMsg = 'Unknown Instruction passed to routine.'
		ErrMsg(ErrorMsg)
END CASE

RETURN Result



* * * * * * *
Create:
* * * * * * *

obj_Appwindow('Create',@WINDOW)

GOSUB Refresh


RETURN

* * * * * * *
Clear:
* * * * * * *


* * * * * * *
Refresh:
* * * * * * *

Ctrls  = @WINDOW:'.SUM_OF_DEFECTS_SPEC':@RM			; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.HAZE_AVG_SPEC':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SUM_OF_DEF_AVG':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SUM_OF_DEF_MAX':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.HAZE_AVG_AVG'					; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

SumOfDefectsSpec	= Vals[1,@RM]
HazeAvgSpec			= Vals[COL2()+1,@RM]
SumOfDefectsAvg		= Vals[COL2()+1,@RM]
SumOfDefectsMax		= Vals[COL2()+1,@RM]
HazeAvgAvg			= Vals[COL2()+1,@RM]

OutOfSpec = ''
IF SumOfDefectsSpec NE '' THEN
	IF SumOfDefectsMax > SumOfDefectsSpec THEN
		OutOfSpec = 1
		Set_Property(@WINDOW:'.SUM_OF_DEF_MAX','BACKCOLOR',RED$)
	END
END

IF HazeAvgSpec NE '' THEN
	IF HazeAvgAvg > HazeAvgSpec THEN
		OutOfSpec = 1
		Set_Property(@WINDOW:'.HAZE_AVG_SPEC','BACKCOLOR',RED$)
	END
END

IF OutOfSpec THEN
	Set_Property(@WINDOW:'.OUT_OF_SPEC','VISIBLE',1)
END ELSE
	Set_Property(@WINDOW:'.OUT_OF_SPEC','VISIBLE',0)
	Set_Property(@WINDOW:'.SUM_OF_DEF_MAX','BACKCOLOR',WHITE$)
	Set_Property(@WINDOW:'.HAZE_AVG_AVG','BACKCOLOR',WHITE$)
END

RETURN


* * * * * * *
Read:
* * * * * * *

Stage = Get_Property(@WINDOW:'.STAGE','TEXT')

IF Stage = 'FW' THEN
	IF Get_Property(@WINDOW:'.SUM_OF_DEF_MIN','TEXT') = '' THEN
		Set_Property(@WINDOW:'.SUM_OF_DEF_MIN','TEXT','0')
	END
	IF Get_Property(@WINDOW:'.SUM_OF_DEF_MAX','TEXT') = '' THEN
		Set_Property(@WINDOW:'.SUM_OF_DEF_MAX','TEXT','0')
	END
	Set_Property(@WINDOW:'.SUM_OF_DEF_AVG','FOCUS',1)
END ELSE
	Set_Property(@WINDOW:'.SUM_OF_DEF_MIN','FOCUS',1)
END


IF Get_Property(@WINDOW:'.SCAN_DTM','TEXT') = '' THEN
	CurDt = OCONV(Date(),'D4-')
	CurTm = OCONV(Time(),'MTS')
	
	Set_Property(@WINDOW:'.SCAN_DTM','TEXT',CurDt:' ':CurTm)
END

IF Get_Property(@WINDOW:'.SCAN_USER','TEXT') = '' THEN
	Set_Property(@WINDOW:'.SCAN_USER','TEXT',@USER4)
END


GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *

Ctrls  = @WINDOW:'.SUM_OF_DEFECTS_SPEC':@RM			; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.HAZE_AVG_SPEC':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SUM_OF_DEF_MIN':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SUM_OF_DEF_MAX':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SUM_OF_DEF_AVG':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.HAZE_AVG_AVG':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDoW:'.SCAN_TOOL'						; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

SumOfDefectsSpec	= Vals[1,@RM]
HazeAvgSpec			= Vals[COL2()+1,@RM]
SumOfDefectsMin		= Vals[COL2()+1,@RM]
SumOfDefectsMax		= Vals[COL2()+1,@RM]
SumOfDefectsAvg		= Vals[COL2()+1,@RM]
HazeAvgAvg			= Vals[COL2()+1,@RM]
ScanTool			= Vals[COL2()+1,@RM]

Result = 1		;* Setup flag for write


IF ScanTool = '' THEN
	Result = 0
	ErrMsg('Scan Tool is a required field.')
	Set_Property(@WINDOW:'.SCAN_TOOL','FOCUS',1)
	RETURN
END

IF SumOfDefectsSpec NE '' THEN

	IF SumOfDefectsMin = '' THEN
		Result = 0
		ErrMsg('Sum Of Defects Minimum is a required field.':CRLF$:"Enter '0' if you don't have a value")
		Set_Property(@WINDOW:'.SUM_OF_DEF_MIN','FOCUS',1)
		RETURN
	END
	
	IF SumOfDefectsMax = '' THEN
		Result = 0
		ErrMsg('Sum Of Defects Maximum is a required field.':CRLF$:"Enter '0' if you don't have a value")
		Set_Property(@WINDOW:'.SUM_OF_DEF_MAX','FOCUS',1)
		RETURN
	END
	
	IF SumOfDefectsAvg = '' THEN
		Result = 0
		ErrMsg('Sum Of Defects Average is a required field.':CRLF$:"Enter '0' if you don't have a value")
		Set_Property(@WINDOW:'.SUM_OF_DEF_AVG','FOCUS',1)
		RETURN
	END
	
END

IF HazeAvgSpec NE '' THEN
	IF HazeAvgAvg = '' THEN
		Result = 0
		ErrMsg('Haze Avg(ppm) Average is a required field.':CRLF$:"Enter '0' if you don't have a value")
		Set_Property(@WINDOW:'.HAZE_AVG_AVG','FOCUS',1)
		RETURN
	END
END
	
Post_Event(@WINDOW,'CLOSE')

RETURN


* * * * * * *
SumOfDefAvgLF:
* * * * * * *

GOSUB Refresh

RETURN


* * * * * * *
HazeAvgAvgLF:
* * * * * * *

GOSUB Refresh

RETURN



* * * * * * *
LUStage:
* * * * * * *

FocusControl = Parm1

IF FocusControl = '' THEN
	FocusControl = Get_Property(@WINDOW,'FOCUS')
END

Stage = Popup(@WINDOW,'','STAGE')

IF Stage = '' THEN RETURN

obj_AppWindow('LUValReturn',Stage:@RM:FocusControl)

RETURN


* * * * * * 
LURdsNo:
* * * * * * 

FocusControl = Parm1

IF FocusControl = '' THEN
	FocusControl = Get_Property(@WINDOW,'FOCUS')
END

WONo    = Get_Property(@Window:'.WO_NO', 'TEXT')
RDSKeys = Dialog_Box('NDW_RDS_QUERY', @Window, WONo)

IF RDSKeys = '' THEN RETURN

CONVERT @FM TO @VM IN RDSKeys

TypeOver = ''
TypeOver<PDISPLAY$> = RDSKeys
TypeOver<PMODE$> = 'K'
TypeOver<PTYPE$> = 'F'
TypeOver<PFIELD$> = '3'
TypeOver<PSELECT$> = 1

RDSKey = Popup(@WINDOW,TypeOver,'RDS_QUERY')

IF RDSKey = '' THEN RETURN

obj_AppWindow('LUValReturn',RDSKey:@RM:FocusControl)

RETURN


* * * * * * *
Close:
* * * * * * *



RETURN

