COMPILE FUNCTION Part(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for PART (Part Master window
	
	07/6/2010 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event, obj_Tables
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, 
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, Create_Note

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals, obj_Tables
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI, Select_Into, NextKey



$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT EPI_PART_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT RTI_STYLE_EQUATES
$INSERT PART_EQUATES


EQU CRLF$	TO \0D0A\
EQU TAB$	TO \09\

EQU COL$STEP		TO 1
EQU COL$STEP_PSN	TO 2
EQU COL$STEP_DESC	TO 3
EQU COL$PSN_STATUS	TO 4
EQU COL$REACT_TYPE	TO 5
EQU COL$TARG_THICK	TO 6
EQU COL$PRE_CLEAN	TO 7
EQU COL$POST_CLEAN	TO 8
EQU COL$TYPE		TO 9
EQU COL$MAKEUPS		TO 10


ErrTitle = 'Error in Part Commuter (PART)'
ErrorMsg = ''

Result = ''


BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CLEAR'			; GOSUB Clear
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
			CASE Event = 'READ'				; GOSUB Read
			CASE Event = 'WRITE'			; GOSUB Write
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
		
	CASE EntID = @WINDOW:'.LU_PART' AND Event = 'CLICK'	 		; GOSUB LUPart
	CASE EntID = @WINDOW:'.LU_REACT_TYPE' AND Event = 'CLICK'	; GOSUB LUReactType
	CASE EntID = @WINDOW:'.LU_EPI_PART_NO' AND Event = 'CLICK'	; GOSUB LUEpiPartNo
	CASE EntID = @WINDOW:'.COPY_LAST' AND Event = 'CLICK'	; GOSUB CopyLast
	
	CASE EntID = @WINDOW:'.PROC_STEP_NO'
		BEGIN CASE
			CASE Event = 'DBLCLK'			; GOSUB StepDC
		END CASE
	
	
	
	*CASE EntID = @WINDOW:'.CLEAN_RESULTS'
	*	BEGIN CASE 
	*		CASE Event = 'POSCHANGED'		; GOSUB CleanPC
	*		CASE Event = 'DBLCLK'			; GOSUB CleanDC
	*	END CASE
		
	
	*CASE EntID = @WINDOW:'.SEND_SPC' AND Event = 'CLICK' 	; GOSUB SendSPC
	
	CASE 1
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
		
END CASE

IF ErrorMsg NE '' THEN
	ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result





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

obj_Appwindow('Create',@WINDOW)

* Set result table special styles (Dropdowns)

/*
CleanStyles = Send_Message(@WINDOW:'.CLEAN_RESULTS','COLSTYLE',0,'')
	
CleanStyles<COL$CLEAN_TOOL>		= BitOr(CleanStyles<COL$CLEAN_TOOL>,DTCS_DROPDOWN$)
CleanStyles<COL$CLEAN_BOAT_ID>	= BitOr(CleanStyles<COL$CLEAN_BOAT_ID>,DTCS_DROPDOWN$)
CleanStyles<COL$CLEAN_SRD_NO>	= BitOr(CleanStyles<COL$CLEAN_SRD_NO>,DTCS_DROPDOWN$)

Send_Message(@WINDOW:'.CLEAN_RESULTS','COLSTYLE',0,CleanStyles)

ScanStyles = Send_Message(@WINDOW:'.SCAN_RESULTS','COLSTYLE',0,'')

ScanStyles<COL$SCAN_TOOL>			= BitOr(ScanStyles<COL$SCAN_TOOL>,DTCS_DROPDOWN$)
ScanStyles<COL$SCAN_HAZE_AVG_MIN>	= BitOr(ScanStyles<COL$SCAN_HAZE_AVG_MIN>,DTCS_SKIPPED$)
ScanStyles<COL$SCAN_HAZE_AVG_MAX>	= BitOr(ScanStyles<COL$SCAN_HAZE_AVG_MAX>,DTCS_SKIPPED$)

Send_Message(@WINDOW:'.SCAN_RESULTS','COLSTYLE',0,ScanStyles)


SSTools = Collect.IXVals ('SURF_SCAN_TOOL','TOOL_ID')
CONVERT @FM TO @VM IN SSTools

Send_Message(@WINDOW:'.SCAN_RESULTS','COLFORMAT',COL$SCAN_TOOL,SSTools)

*/

GOSUB Refresh

RETURN


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


IF Get_Property(@WINDOW,'@READONLY') THEN
	obj_AppWindow('ReadOnly',@RM:1)			;* Reenables data bound controls
	Set_Property(@WINDOW,'@READONLY',0)		;* Clear flag on window
END



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

GOSUB Refresh

RETURN


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

Record = Get_Property(@WINDOW,'RECORD')
Set_Property(@WINDOW,'@PREVREC',Record)

Forward_Event()

GOSUB Refresh

RETURN 1


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

* 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

StatusArray = Get_Property(@WINDOW:'.PROC_STEP_NO','ARRAY')<COL$PSN_STATUS>

LOOP
	StatusVal = StatusArray[-1,1]
UNTIL StatusVal NE @VM OR StatusArray = ''
	StatusArray[-1,1] = ''
REPEAT

StatCnt = COUNT(StatusArray,@VM) + (StatusArray NE '')

FOR I = 1 TO StatCnt
	StatusVal = StatusArray<1,I>
	
	IF StatusVal[1,1] = 'I' THEN
		stat = Send_Message(@WINDOW:'.PROC_STEP_NO','COLOR_BY_POS',COL$PSN_STATUS,I,RED$)
	END
NEXT I



RETURN


* * * * * * *
LUPart:
* * * * * * *

EpiPartNo = Get_Property(@WINDOW:'.EPI_PART_NO','DEFPROP')

TypeOver = ''

IF EpiPartNo NE '' THEN
	PartNos = XLATE('EPI_PART',EpiPartNo,EPI_PART_PART_NO$,'X')
	
	TypeOver<PMODE$>	= 'K'
	TypeOver<PDISPLAY$>	= PartNos
END

Set_Status(0)
PartNos = Popup(@WINDOW,TypeOver,'PART')
IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	RETURN
END

IF PartNos NE '' THEN
	IF INDEX(PartNos,@VM,1) THEN
		Send_Event(@WINDOW,'QBFINIT')
		Set_Property(@WINDOW,'QBFLIST',PartNos)
		Send_Event(@WINDOW,'QBFFIRST')
	END ELSE
		obj_AppWindow('LoadFormKeys',@WINDOW:@RM:PartNos)
	END
END

RETURN


* * * * * * *
LUReactType:
* * * * * * *


ReactType = Popup(@WINDOW,TypeOver,'REACTOR_TYPE')

IF ReactType NE '' THEN
	obj_Appwindow('LUValReturn',ReactType:@RM:@WINDOW:'.REACT_TYPE':@RM:'')
END

RETURN


* * * * * * *
LUEpiPartNo:
* * * * * * *

TypeOver = ''
TypeOver<PSELECT$> = 1	;* Single selection

EpiPartNo = Popup(@WINDOW,TypeOver,'EPI_PART_NOS')

IF EpiPartNo NE '' THEN
	obj_Appwindow('LUValReturn',EpiPartNo:@RM:@WINDOW:'.EPI_PART_NO':@RM:'')
END

RETURN



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


obj_Appwindow('CardReturn')

RETURN



* * * * * * *
StepDC:
* * * * * * *

CtrlEntID = @WINDOW:'.PROC_STEP_NO'

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

RowData = Get_Property(CtrlEntId,'ROWDATA')

Step 	= RowData<COL$STEP>
PSNo	= RowData<COL$STEP_PSN>


IF PSNo = '' THEN
	RETURN
	/*
	SearchString = 'CUST_ID':@VM:CompNo:@FM
	Option = ''
	Flag = ''
	OPEN 'DICT.PROD_SPEC' TO DictVar ELSE RETURN
	Btree.Extract(SearchString, 'PROD_SPEC', DictVar, PSNos, Option, Flag)
	IF Get_Status(errCode) THEN ErrMsg(errCode)
	IF PSNos = '' THEN
		ErrMsg('No PSNs on file for company ':QUOTE(CompNo))
		RETURN
	END
	PSNo = ''
	IF INDEX(PSNos,@VM,1) THEN
		TypeOver = ''
		TypeOver<PDISPLAY$> = PSNos
		PSNo = Popup(@WINDOW,TypeOver,'PROD_SPEC')
		IF Get_Status(errCode) THEN ErrMsg(errCode)
	END ELSE
		PSNo = PSNos
	END
	IF PSNo NE '' THEN
		obj_AppWindow('LUValReturn',PSNo:@RM:CtrlEntID:@RM:CurrPos)
	END
	*/
END ELSE
	* Display the Prod Spec Window
	obj_AppWindow('ViewRelated','PROD_SPEC':@RM:PSNo)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
END

RETURN


* * * * * * *
CopyLast:
* * * * * * *

PrevRec = Get_Property(@WINDOW,'@PREVREC')

DEBUG

PartNo = NextKey('PART')			;* Sequential part number assigned

PartRec = PrevRec

*PartRec<PART_SUB_PART_NO$> 	= ''
*PartRec<PART_SUB_PART_REV$>	= ''
*PartRec<PART_SUB_SUPPLIER$>	= ''

otParms = 'PART':@RM:PartNo:@RM:@RM:PartRec
obj_Tables('WriteRec',otParms)

obj_Appwindow('LoadFormKeys',@WINDOW:@RM:PartNo)


RETURN






