COMPILE FUNCTION Comm_PR_Spec(Instruction, Parm1,Parm2)

/*
	Commuter module for PR_SPEC (Product Specification) window
	
	06/07/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, Make.List
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Center_Window, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, obj_PR_Spec, Msg

$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT QUOTE_SIGS_EQU
$INSERT LSL_USERS_EQU

EQU CRLF$	TO \0D0A\

EQU COL$LAYER_SET		TO 1
EQU COL$LS_DOPANT		TO 2
EQU COL$LS_RECIPE		TO 3
EQU COL$LS_RECIPE_NAME	TO 4

EQU COL$SFC_STAGE		TO 1
EQU COL$SFC_DESC		TO 2


ErrTitle = 'Error in Comm_PR_Spec'
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 = 'Page'			; GOSUB Page
	CASE Instruction = 'LUPSNo'			; GOSUB LUPSNo
	CASE Instruction = 'PQClick'		; GOSUB PQClick
	CASE Instruction = 'QClick'			; GOSUB QClick
	CASE Instruction = 'PPClick'		; GOSUB PPClick
	CASE Instruction = 'PClick'			; GOSUB PClick
	CASE Instruction = 'LayerSetPC'		; GOSUB LayerSetPC
	CASE Instruction = 'LayerSetDC'		; GOSUB LayerSetDC
	CASE Instruction = 'SurfacePC'		; GOSUB SurfacePC
	CASE Instruction = 'SurfaceDC'		; GOSUB SurfaceDC
	CASE Instruction = 'SurfTestDC'		; GOSUB SurfTestDC
	CASE Instruction = 'Substrate'		; GOSUB Substrate
	CASE Instruction = 'ReactClick'		; GOSUB ReactClick
	CASE Instruction = 'InstrClick'		; GOSUB InstrClick
	CASE Instruction = 'ShipClick'		; GOSUB ShipClick
	
	CASE 1
		ErrorMsg = 'Unknown Instruction passed to routine.'
		ErrMsg(ErrorMsg)
END CASE

RETURN Result



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


obj_Appwindow('Create',@WINDOW)


GOSUB Refresh


RETURN

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

Send_Event(@WINDOW,'PAGE',1)


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

Ctrls  = @WINDOW:'.PREQUAL_SIG':@RM			; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.QUAL_SIG':@RM			; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.PREPROD_SIG':@RM			; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.PROD_SIG'				; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

PreQualSig	= Vals[1,@RM]
QualSig		= Vals[COL2()+1,@RM]
PreProdSig	= Vals[COL2()+1,@RM]
ProdSig		= Vals[COL2()+1,@RM]

BEGIN CASE
	CASE ProdSig NE ''
		StatText = 'Production'
		
	CASE PreProdSig NE ''
		StatText = 'PreProduction'
		
	CASE QualSig NE ''
		StatText = 'Qualification'
		
	CASE PreQualSig	NE ''
		StatText = 'PreQualification'
		
	CASE 1
		StatText = 'Setup'
		
END CASE

Set_Property(@WINDOW:'.SPEC_PHASE_TEXT','TEXT',StatText)

* Signature button text/enable-disable logic

bCtrls = @WINDOW:'.PREQUAL_BUTTON':@RM:@WINDOW:'.QUAL_BUTTON':@RM:@WINDOW:'.PREPROD_BUTTON':@RM:@WINDOW:'.PROD_BUTTON'
eProps = 'ENABLED':@RM:'ENABLED':@RM:'ENABLED':@RM:'ENABLED'
tProps = 'TEXT':@RM:'TEXT':@RM:'TEXT':@RM:'TEXT'
eVals = ''			;* Enabled values
tVals = ''			;* Text values

BEGIN CASE
	CASE PreQualSig = ''
		eVals = 1:@RM:0:@RM:0:@RM:0
		tVals = 'Sign':@RM:'Sign':@RM:'Sign':@RM:'Sign'
		
	CASE PreQualSig NE '' AND QualSig = ''
		eVals = 1:@RM:1:@RM:0:@RM:0
		tVals = 'Unsign':@RM:'Sign':@RM:'Sign':@RM:'Sign'
		
	CASE QualSig NE '' AND PreProdSig = ''
		eVals = 0:@RM:1:@RM:1:@RM:0
		tVals = 'Unsign':@RM:'Unsign':@RM:'Sign':@RM:'Sign'
	
	CASE PreProdSig NE '' AND ProdSig = ''
		eVals = 0:@RM:0:@RM:1:@RM:1
		tVals = 'Unsign':@RM:'Unsign':@RM:'Unsign':@RM:'Sign'
		
	CASE ProdSig NE ''
		eVals = 0:@RM:0:@RM:0:@RM:1
		tVals = 'Unsign':@RM:'Unsign':@RM:'Unsign':@RM:'Unsign'
		
END CASE

Set_Property(bCtrls,eProps,eVals)
Set_Property(bCtrls,tProps,tVals)

* Activity text label

ActStat = Get_Property(@WINDOW:'.ACT_STATUS','VALUE')
IF ActStat = 'P' THEN ActStatText = 'PreActivation'
IF ActStat = 'A' THEN ActStatText = 'Active'
IF ActStat = 'I' THEN ActStatText = 'InActive'
IF ActStat = '' THEN ActStatText = ''

Set_Property(@WINDOW:'.ACT_STATUS_TEXT','TEXT',ActStatText)

* QBF buttons

Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
END ELSE
	Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
END

Set_Property(Ctrls,Props,Vals)

* Turn edit table symbolic column backgrounds to green

ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow

ETCtrls	= ETSymbolics<1>
ETCols	= ETSymbolics<2>

FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
	ETCtrl	= ETCtrls<1,I>
	ETList = Get_Property(ETCtrl,'LIST')
	FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
		IF ETList<Line,1> NE '' THEN
			FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
				stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
			NEXT N
		END
	NEXT Line
NEXT I



RETURN

* * * * * * *
Page:
* * * * * * *

obj_Appwindow('Page')
GOSUB Refresh

RETURN

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

GOSUB Refresh

RETURN


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

RETURN


* * * * * * *
LUPSNo:
* * * * * * * 

ReturnTo = Parm1

PS_Nos = obj_PR_Spec('Find')

IF PS_Nos = '' THEN RETURN

IF PS_Nos NE '' THEN
	Make.List(0,PS_Nos, '', '')
	PS_Nos = Popup(@WINDOW,'','PROD_SPEC_QUERY')
END

IF INDEX(PS_Nos,@FM,1) THEN
	Send_Event(@WINDOW,'CLEAR')
	Set_Property(@WINDOW,'QBFLIST',PS_Nos)
	Send_Event(@WINDOW,'QBFFIRST')
	GOSUB Refresh
END ELSE
	obj_AppWindow('LUValReturn',PS_Nos:@RM:ReturnTo)
END

RETURN


* * * * * * *
PQClick:
* * * * * * *

Ctrls  = @WINDOW:'.PREQUAL_SIG':@RM			; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.PREQUAL_NAME':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.PREQUAL_SIG_DTM'			; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

Sig		= Vals[1,@RM]

CurrUser = @USER4

AuthUsers	= XLATE('CONFIG','QUOTE_SIGS',PSNPreQualSigs$,'X')
CurrUserPW 	= XLATE('LSL_USERS',CurrUser,LSL_USERS_PASSWORD$,'X')

LOCATE CurrUser IN AuthUsers USING @VM SETTING Dummy ELSE
	ErrMsg('You are not an authorized PreQualification signer.')
	RETURN
END

IF Sig = '' THEN
	* Doing Signature
	Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
    GoodPassword = Valid<1>
	IF GoodPassword THEN
		UserName = XLATE('LSL_USERS',CurrUser,'FIRST_LAST','X')
		CurrTimeDate = TimeDate()
		CurrTime = FIELD(CurrTimeDate,' ',1)
		CurrDate = FIELD(CurrTimeDate,' ',2,3)
		SignDTM	= OCONV(ICONV(CurrDate:' ':CurrTime,'DT'),'DT/S')
		Vals = CurrUser:@RM:UserName:@RM:SignDTM
		Set_Property(Ctrls,Props,Vals)
	END

END ELSE
	* Undoing Signature
	MsgInfo = ''
	MsgInfo<MTEXT$> = 'You are about to unsign this Product Specification. Proceed?'
	MsgInfo<MICON$> = '?'
	MsgInfo<MTYPE$> = 'BNY'

	Resp = Msg(@WINDOW,MsgInfo,'')

	IF Resp = 0 THEN RETURN
	Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
    GoodPassword = Valid<1>
	IF GoodPassword THEN
		Vals = '':@RM:'':@RM:''
		Set_Property(Ctrls,Props,Vals)
	END

END

GOSUB Refresh

RETURN



* * * * * * *
QClick:
* * * * * * *

Ctrls  = @WINDOW:'.QUAL_SIG':@RM			; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.QUAL_NAME':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.QUAL_SIG_DTM'			; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

Sig		= Vals[1,@RM]
Name	= Vals[COL2()+1,@RM]
SigDTM	= Vals[COL2()+1,@RM]

CurrUser = @USER4

AuthUsers	= XLATE('CONFIG','QUOTE_SIGS',PSNQualSigs$,'X')
CurrUserPW 	= XLATE('LSL_USERS',CurrUser,LSL_USERS_PASSWORD$,'X')

LOCATE CurrUser IN AuthUsers USING @VM SETTING Dummy ELSE
	ErrMsg('You are not an authorized Qualification signer.')
	RETURN
END

IF Sig = '' THEN
	* Doing Signature
		Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
        GoodPassword = Valid<1>
	IF GoodPassword THEN
		UserName = XLATE('LSL_USERS',CurrUser,'FIRST_LAST','X')
		CurrTimeDate = TimeDate()
		CurrTime = FIELD(CurrTimeDate,' ',1)
		CurrDate = FIELD(CurrTimeDate,' ',2,3)
		SignDTM	= OCONV(ICONV(CurrDate:' ':CurrTime,'DT'),'DT/S')
		Vals = CurrUser:@RM:UserName:@RM:SignDTM
		Set_Property(Ctrls,Props,Vals)
	END

END ELSE
	* Undoing Signature
	MsgInfo = ''
	MsgInfo<MTEXT$> = 'You are about to unsign this Product Specification. Proceed?'
	MsgInfo<MICON$> = '?'
	MsgInfo<MTYPE$> = 'BNY'

	Resp = Msg(@WINDOW,MsgInfo,'')

	IF Resp = 0 THEN RETURN
	Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
    GoodPassword = Valid<1>
	IF GoodPassword THEN
		Vals = '':@RM:'':@RM:''
		Set_Property(Ctrls,Props,Vals)
	END

END

GOSUB Refresh

RETURN


* * * * * * *
PPClick:
* * * * * * *

Ctrls  = @WINDOW:'.PREPROD_SIG':@RM			; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.PREPROD_NAME':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.PREPROD_SIG_DTM'			; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

Sig		= Vals[1,@RM]

CurrUser = @USER4

AuthUsers	= XLATE('CONFIG','QUOTE_SIGS',PSNPreProdSigs$,'X')
CurrUserPW 	= XLATE('LSL_USERS',CurrUser,LSL_USERS_PASSWORD$,'X')

LOCATE CurrUser IN AuthUsers USING @VM SETTING Dummy ELSE
	ErrMsg('You are not an authorized Production signer.')
	RETURN
END

IF Sig = '' THEN
	* Doing Signature
	Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
    GoodPassword = Valid<1>
	IF GoodPassword THEN
		UserName = XLATE('LSL_USERS',CurrUser,'FIRST_LAST','X')
		CurrTimeDate = TimeDate()
		CurrTime = FIELD(CurrTimeDate,' ',1)
		CurrDate = FIELD(CurrTimeDate,' ',2,3)
		SignDTM	= OCONV(ICONV(CurrDate:' ':CurrTime,'DT'),'DT/S')
		Vals = CurrUser:@RM:UserName:@RM:SignDTM
		Set_Property(Ctrls,Props,Vals)
	END

END ELSE
	* Undoing Signature
	MsgInfo = ''
	MsgInfo<MTEXT$> = 'You are about to unsign this Product Specification. Proceed?'
	MsgInfo<MICON$> = '?'
	MsgInfo<MTYPE$> = 'BNY'

	Resp = Msg(@WINDOW,MsgInfo,'')

	IF Resp = 0 THEN RETURN
	Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
    GoodPassword = Valid<1>
	IF GoodPassword THEN
		Vals = '':@RM:'':@RM:''
		Set_Property(Ctrls,Props,Vals)
	END

END

GOSUB Refresh

RETURN


* * * * * * *
PClick:
* * * * * * *

Ctrls  = @WINDOW:'.PROD_SIG':@RM			; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.PROD_NAME':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.PROD_SIG_DTM'			; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

Sig			= Vals[1,@RM]
CurrUser 	= @USER4

AuthUsers	= XLATE('CONFIG','QUOTE_SIGS',PSNProdSigs$,'X')
CurrUserPW 	= XLATE('LSL_USERS',CurrUser,LSL_USERS_PASSWORD$,'X')

LOCATE CurrUser IN AuthUsers USING @VM SETTING Dummy ELSE
	ErrMsg('You are not an authorized Production signer.')
	RETURN
END

IF Sig = '' THEN
	* Doing Signature
	Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
    GoodPassword = Valid<1>
	IF GoodPassword THEN
		UserName = XLATE('LSL_USERS',CurrUser,'FIRST_LAST','X')
		CurrTimeDate = TimeDate()
		CurrTime = FIELD(CurrTimeDate,' ',1)
		CurrDate = FIELD(CurrTimeDate,' ',2,3)
		SignDTM	= OCONV(ICONV(CurrDate:' ':CurrTime,'DT'),'DT/S')
		Vals = CurrUser:@RM:UserName:@RM:SignDTM
		Set_Property(Ctrls,Props,Vals)
	END

END ELSE
	* Undoing Signature
	MsgInfo = ''
	MsgInfo<MTEXT$> = 'You are about to unsign this Product Specification. Proceed?'
	MsgInfo<MICON$> = '?'
	MsgInfo<MTYPE$> = 'BNY'

	Resp = Msg(@WINDOW,MsgInfo,'')

	IF Resp = 0 THEN RETURN
	Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
    GoodPassword = Valid<1>
	IF GoodPassword THEN
		Vals = '':@RM:'':@RM:''
		Set_Property(Ctrls,Props,Vals)
	END

END

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


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



RETURN

* * * * * * *
LayerSetPC:
* * * * * * * 

RETURN


* * * * * * * 
LayerSetDC:
* * * * * * *

PSNo = Get_Property(@WINDOW,'ID')

CtrlEntID = @WINDOW:'.LAYER_SET'

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

LayerSet = Get_Property(CtrlEntID,'CELLPOS',COL$LAYER_SET:@FM:CurrRow)

IF PSNo NE '' AND LayerSet NE '' THEN
	IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
		Send_Event(@WINDOW,'WRITE')
	END
	
	DetWindow	= 'PRS_LAYER'
	DetKeys		= PSNo:'*':LayerSet
	DefaultRec	= ''
	RetKey		= PSNo
	RetPage		= 4
	RetCtrl		= CtrlEntID
	RetPos		= CurrPos
	
	oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

	obj_AppWindow('ViewNewDetail',oAParms)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
END
RETURN


* * * * * * *
SurfacePC:
* * * * * * *


RETURN



* * * * * * *
SurfaceDC:
* * * * * * *

PSNo = Get_Property(@WINDOW,'ID')

CtrlEntID = @WINDOW:'.SURFACE_KEYS'

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

SfcStage = Get_Property(CtrlEntID,'CELLPOS',COL$SFC_STAGE:@FM:CurrRow)

IF PSNo NE '' AND SfcStage NE '' THEN
	IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
		Send_Event(@WINDOW,'WRITE')
	END
	
	DetWindow	= 'PRS_SURFACE'
	DetKeys		= PSNo:'*':SfcStage
	DefaultRec	= ''
	RetKey		= PSNo
	RetPage		= 5
	RetCtrl		= CtrlEntID
	RetPos		= CurrPos
	
	oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

	obj_AppWindow('ViewNewDetail',oAParms)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
END
RETURN


* * * * * * *
SurfTestDC:
* * * * * * *

PSNo = Get_Property(@WINDOW,'ID')

CtrlEntID = @WINDOW:'.SURF_TESTS'

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

SfcStage = Get_Property(CtrlEntID,'CELLPOS',COL$SFC_STAGE:@FM:CurrRow)

IF PSNo NE '' AND SfcStage NE '' THEN
	IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
		Send_Event(@WINDOW,'WRITE')
	END
	
	DetWindow	= 'PRS_SURFACE'
	DetKeys		= PSNo:'*':SfcStage
	DefaultRec	= ''
	RetKey		= PSNo
	RetPage		= 5
	RetCtrl		= CtrlEntID
	RetPos		= CurrPos
	
	oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

	obj_AppWindow('ViewNewDetail',oAParms)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
END
RETURN



* * * * * * *
Substrate:
* * * * * * *

PSN = Get_Property(@WINDOW,'ID')

obj_AppWindow('ViewRelated','PRS_SUBSTRATE':@RM:PSN)

RETURN


* * * * * * *
ReactClick:
* * * * * * *

PSN = Get_Property(@WINDOW,'ID')

obj_AppWindow('ViewRelated','PRS_REACTOR':@RM:PSN)

RETURN


* * * * * * *
InstrClick:
* * * * * * *

PSN = Get_Property(@WINDOW,'ID')

obj_AppWindow('ViewRelated','PRS_INSTRUCTION':@RM:PSN)

RETURN


* * * * * * *
ShipClick:
* * * * * * *

PSN = Get_Property(@WINDOW,'ID')

obj_AppWindow('ViewRelated','PRS_SHIPPING':@RM:PSN)

RETURN

