COMPILE FUNCTION Comm_RDS_Makeup(Method, Parm1)

/*
	Commuter module for Dialog_RDS_Makeup window.
	
	09/17/2004 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, ErrMsg, obj_WO_Mat
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Btree.Extract, Msg, Utility, Post_Event, Forward_Event
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Send_Message, Popup, Collect.IXVals, Msg, obj_RDS
DECLARE FUNCTION obj_RDS_Makeup, obj_MUWafers

EQU CRLF$	TO \0D0A\


EQU COL$SLOT		TO 1	;* Equates for MAKEUP_TABLE
EQU COL$SRC_RDS		TO 2
EQU COL$SRC_SLOT	TO 3
EQU COL$SOURCE_LOT	TO 4
EQU COL$DEST_RDS	TO 5
EQU COL$DEST_SLOT	TO 6
EQU COL$MAKEUP_BY	TO 7
EQU COL$MAKEUP_DTM	TO 8


EQU LTGREY$		TO	229 + (229*256) + (229*65536)	;* JCH standard colors for edittable backgrounds
EQU GREY$		TO	192 + (192*256) + (192*65536)
EQU GREEN$		TO	192 + (220*256) + (192*65536)
EQU RED$		TO	255 + (128*256) + (128*65536)
EQU BLUE$		TO	128 + (255*256) + (255*65536)
EQU WHITE$		TO	255 + (255*256) + (255*65536)
EQU YELLOW$		TO	255 + (255*256) + (202*65536)
EQU LTBLUE$		TO	128 + (255*256) + (255*65536)
EQU PURPLE$		TO	225 + (181*256) + (255*65536)


$INSERT RDS_MAKEUP_EQU
$INSERT RDS_EQU
$INSERT SCHEDULE_EQU
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT PS_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT MSG_EQUATES

ErrTitle = 'Error in Comm_RDS_Makeup'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'Read'			; GOSUB Read
	CASE Method = 'Write'			; GOSUB Write
	CASE Method = 'Close'			; GOSUB Close
	CASE Method = 'Refresh'			; GOSUB Refresh
	CASE Method = 'SelectSourceRDS'	; GOSUB SelectSourceRDS
	CASE Method = 'MakeupTableDC'	; GOSUB MakeupTableDC
	
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE


RETURN Result


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

obj_AppWindow('Create')

GOSUB Refresh

RETURN


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

Ctrls  = @WINDOW:'.SCHED_WAFER_QTY':@RM		; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.GOOD_WAFER_QTY':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.REM_WAFER_QTY':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.MAKEUP_TABLE'			; Props := 'LIST'

Vals = Get_Property(Ctrls,Props)

SchedQty 	= Vals[1,@RM]
GoodQty		= Vals[COL2()+1,@RM]
RemQty		= Vals[COL2()+1,@RM]
MakeUpList	= Vals[COL2()+1,@RM]

LineNo = 1
FOR SlotNo = SchedQty TO GoodQty Step -1
UNTIL SlotNo = GoodQty
	IF MakeUpList<LineNo,1> = '' THEN
		Set_Property(@WINDOW:'.MAKEUP_TABLE','CELLPOS',SlotNo,COL$SLOT:@FM:LineNo)
	END
	LineNo += 1
NEXT SlotNo


GOSUB Refresh

RETURN


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


RDSNo = Get_Property(@WINDOW,'ID')

Forward_Event()							;* Performs the write

RDSRec = XLATE('RDS',RDSNo,'','X')		;* This section added 7/25/2008 JCH **************************
WONo = RDSRec<RDS_WO$>
CassNo = RDSRec<RDS_CASS_NO$>
WOMatKey = WONo:'*':CassNo

obj_WO_Mat('ConvertMakeup',WOMatKey)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
END

Result = 0

RETURN


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

* Turn edit table symbolic column backgrounds to green

CtrlEntID = @WINDOW:'.MAKEUP_TABLE'

MadeUpRDS = Get_Property(@WINDOW,'ID')

MUList = Get_Property(CtrlEntID,'LIST')
MUArray = Get_Property(CtrlEntID,'ARRAY')

SrcRDS = MUArray<COL$SRC_RDS>
DestRDS = MUArray<COL$DEST_RDS>

CONVERT @VM TO '' IN SrcRDS
CONVERT @VM TO '' IN DestRDS

Ctrls = @WINDOW:'.BOX_TYPE':@RM:@WINDOW:'.BOX_TYPE':@RM:@WINDOW:'.SELECT_SOURCE_BUTTON'
Props = 'VISIBLE':@RM:'TEXT':@RM:'ENABLED'

BEGIN CASE
	CASE SrcRDS NE ''
		Vals = 1:@RM:'Merged Lots':@RM:1
		
	CASE DestRDS NE ''
		Vals = 1:@RM:'Makeup Box':@RM:0
		
	CASE 1
		Vals = 0:@RM:'':@RM:1
END CASE

Set_Property(Ctrls,Props,Vals)

FOR Line = 1 TO COUNT(MUList,@FM) + (MUList NE '')

	BEGIN CASE
		CASE MUList<Line,COL$SLOT> NE '' AND MUList<Line,COL$SRC_RDS> = '' AND MUList<Line,COL$DEST_RDS> = ''
			IF SrcRDS = '' THEN	Color = GREEN$
			IF DestRDS = '' THEN Color = RED$
			
		CASE MUList<Line,COL$SLOT> NE '' AND (MUList<Line,COL$SRC_RDS> NE '' OR MUList<Line,COL$DEST_RDS> NE '')
			Color = YELLOW$
			
		CASE 1
			Color = WHITE$
	END CASE
	
	IF MUList<Line,1> NE '' THEN
		stat = Send_Message(CtrlEntID,'COLOR_BY_POS',0,Line,Color)
	END
	
NEXT Line

RETURN

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

RDSNo = Get_Property(@WINDOW,'ID')
IF RDSNo NE '' THEN
	Send_Event(@WINDOW,'WRITE')
	
END

Post_Event('RDS_UNLOAD','READ')

RETURN 1



* * * * * * *
SelectSourceRDS:
* * * * * * *

RDSNo	= Get_Property(@WINDOW,'ID')
PSN		= Get_Property(@WINDOW:'.PROD_SPEC','DEFPROP')

RDSRec 		= XLATE('RDS',RDSNo,'','X')
RdsWONo		= RDSRec<RDS_WO$>

SourceRDSNos = obj_MUWafers('AvailWafers',RdsWONo:@RM:@RM:1)
TypeOver = ''
TypeOver<PDISPLAY$> = SourceRDSNos
TypeOver<PTITLE$> = 'Available Makeup Wafers for Prod Spec No ':PSN

SourceInfo = Popup(@WINDOW,TypeOver,'AVAIL_MU_WAFERS')

IF SourceInfo = '' THEN RETURN		;* User Bailed

*  This is copied from the bottom of the original stuff

SrcRDS	= SourceInfo<1,3>
AvailQty = SourceInfo<1,7>

MakeupList = Get_Property(@WINDOW:'.MAKEUP_TABLE','LIST')
MakeupArray = Get_Property(@WINDOW:'.MAKEUP_TABLE','ARRAY')

EmptySlots = ''

FOR I = 1 TO COUNT(MakeupList,@FM) + (MakeupList NE '')
	IF MakeupList<I,COL$SLOT> NE '' AND MakeupList<I,COL$SRC_RDS> = '' AND MakeupList<I,COL$DEST_RDS> = '' THEN
		EmptySlots<1,-1> = MakeupList<I,COL$SLOT>
	END
NEXT I

EmptySlots = FIELD(EmptySlots,@VM,1,AvailQty)	;* Trims any empty slots beyond number of makeups available.

* * * * * * ** * * * * Trimming function needs work.  It should trim from the top and not the bottom of the list

RemMUWfrResult = obj_RDS_Makeup('RemMUWafers',SrcRDS:@RM:RDSNo:@RM:EmptySlots)

SrcSlots	= RemMUWfrResult<1>
MUDtm		= RemMUWfrResult<2>

FOR I = 1 TO COUNT(EmptySlots,@VM) + (EmptySlots NE '')
	EmptySlot = EmptySlots<1,I>
	SrcSlot = SrcSlots<1,I>
	
	LOCATE EmptySlot IN MakeupArray<COL$SLOT> USING @VM Setting Pos THEN
		Set_Property(@WINDOW:'.MAKEUP_TABLE','CELLPOS',SrcSlot,COL$SRC_SLOT:@FM:Pos)
		Set_Property(@WINDOW:'.MAKEUP_TABLE','CELLPOS',SrcRDS,COL$SRC_RDS:@FM:Pos)
		Set_Property(@WINDOW:'.MAKEUP_TABLE','CELLPOS',@USER4,COL$MAKEUP_BY:@FM:Pos)
		Set_Property(@WINDOW:'.MAKEUP_TABLE','CELLPOS',MUDtm,COL$MAKEUP_DTM:@FM:Pos)
	END
NEXT I

GOSUB Refresh


RETURN


* * * * * * *
MakeupTableDC:
* * * * * * *

CtrlEntID = @WINDOW:'.MAKEUP_TABLE'

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

RowData = Get_Property(CtrlEntID,'ROWDATA')

IF CurrCol = COL$SRC_RDS THEN
	SourceRDS = RowData<COL$SRC_RDS>
	IF SourceRDS NE '' THEN
		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		obj_Appwindow('LoadFormKeys',@WINDOW:@RM:SourceRDS)
	END
END

IF CurrCol = COL$DEST_RDS THEN
	DestRDS = RowData<COL$DEST_RDS>
	IF DestRDS NE '' THEN
		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		obj_Appwindow('LoadFormKeys',@WINDOW:@RM:DestRDS)
	END
END

RETURN





