COMPILE FUNCTION Comm_Dialog_NCR_SRJ_Epi(Method, Parm1, Parm2)

/*
	Commuter module for Dialog_NCR_SRJ_EPI window.
	
	01/20/2009 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status, ErrMsg, Send_Event, obj_RDS_Test
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Msg, End_Dialog, Send_Message,  ErrMsg
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Popup,  Send_Message, obj_Test_Point_Map, obj_RDS_Test


EQU CRLF$	TO \0D0A\

$INSERT MSG_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT NCR_EQU
$INSERT APPCOLORS

EQU WFR_COL$OUT_SLOT	TO 1
EQU WFR_COL$RDS			TO 2
EQU WFR_COL$POCKET		TO 3
EQU WFR_COL$ZONE		TO 4
EQU WFR_COL$IN_CASS		TO 5
EQU WFR_COL$IN_SLOT		TO 6
EQU WFR_COL$SLOT_NCR	TO 7
EQU WFR_COL$MU_WO_NO	TO 8
EQU WFR_COL$MU_STEP		TO 9
EQU WFR_COL$MU_CASS		TO 10
EQU WFR_COL$MU_SLOT		TO 11
EQU WFR_COL$UM_CASS_ID	TO 12
EQU WFR_COL$UM_SLOT		TO 13



EQU NCR_COL$OUT_CASS	TO 1		;* EpiPRO slot information
EQU NCR_COL$OUT_SLOT	TO 2
EQU NCR_COL$RDS			TO 3
EQU NCR_COL$POCKET		TO 4
EQU NCR_COL$ZONE		TO 5
EQU NCR_COL$IN_CASS		TO 6
EQU NCR_COL$IN_SLOT		TO 7
EQU NCR_COL$PREV_NCR	TO 8
EQU NCR_COL$MU_WO_NO	TO 9
EQU NCR_COL$MU_STEP		TO 10
EQU NCR_COL$MU_CASS		TO 11
EQU NCR_COL$MU_SLOT		TO 12




ErrTitle = 'Error in Comm_Dialog_NCR_Rej_Slot'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'WOMatClick'		; GOSUB WOMatClick
	CASE Method = 'RejWafers'		; GOSUB RejWafers
	CASE Method = 'RepWafers'		; GOSUB RepWafers
	CASE Method = 'Apply'			; GOSUB Apply
	CASE MEthod = 'Cancel'			; GOSUB Cancel
	
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE


RETURN Result


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


obj_AppWindow('Create')

* get the current style

EQU MULTILINE_STYLE$	TO 512 			;* MultiLine Select

* Set Material Slot edit table to multi-line select

Style = Get_Property(@WINDOW:'.WM_OUT_SLOT', 'STYLE')
									
IF Style [1,2] _EQC "0x" THEN
  CONVERT @LOWER.CASE TO @UPPER.CASE IN STYLE
  Style = ICONV(Style [3,99], "MX")
END

Style = BitOr(Style, MULTILINE_STYLE$)
Set_Property(@WINDOW:'.WM_OUT_SLOT', "STYLE", Style)


* Set NCR Reject Wafers edit table to multi-line select

Style = Get_Property(@WINDOW:'.SLOT_REJECT', 'STYLE')									

IF Style [1,2] _EQC "0x" THEN
  CONVERT @LOWER.CASE TO @UPPER.CASE IN STYLE
  Style = ICONV(Style [3,99], "MX")
END

Style = BitOr(Style, MULTILINE_STYLE$)
Set_Property(@WINDOW:'.SLOT_REJECT', "STYLE", Style)


CONVERT '/' TO @RM IN Parm1

Ctrls  = @WINDOW:'.WM_OUT_SLOT':@RM		; Props  = 'LIST':@RM
Ctrls := @WINDOW:'.SLOT_REJECT':@RM		; Props := 'LIST':@RM
Ctrls := @WINDOW:'.WO_NO':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.WO_STEP_NO':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.CASS_NO':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.NCR_NO'				; Props := 'DEFPROP'

Set_Property(Ctrls,Props,Parm1)

RETURN


* * * * * * *
WOMatClick:
* * * * * * *

SlotList = Get_Property(@WINDOW:'.WM_OUT_SLOT','LIST')
NCRNo	 = Get_Property(@WINDOW:'.NCR_NO','DEFPROP')

SlotSelection	= Get_Property(@WINDOW:'.WM_OUT_SLOT','SELPOS')

SelectedLines = SlotSelection<2>
SelCnt = COUNT(SelectedLines,@VM) + (SelectedLines NE '')

BadLines = ''

FOR I = 1 TO SelCnt
	LineNo = SelectedLines<1,I>
	a1 = SlotList<LineNo,WFR_COL$SLOT_NCR>
	a1 = SlotList<LineNo,WFR_COL$UM_CASS_ID>
	IF SlotList<LineNo,WFR_COL$SLOT_NCR> = NCRNo OR SlotList<LineNo,WFR_COL$UM_CASS_ID> NE '' THEN
		BadLines<1,-1> = LineNo
	END	
NEXT I


IF BadLines NE '' THEN
	Set_Property(@WINDOW:'.WM_OUT_SLOT','SELPOS',1:@FM:BadLines)
END
	
RETURN



* * * * * * *
Apply:
* * * * * * *

Ctrls  = @WINDOW:'.WM_OUT_SLOT':@RM		; Props  = 'ARRAY':@RM
Ctrls := @WINDOW:'.SLOT_REJECT':@RM		; Props := 'LIST':@RM
Ctrls := @WINDOW:'.WO_NO':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.CASS_NO':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.NCR_NO'				; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props,Parm1)

WOMatSlotArray	= Vals[1,@RM]
NCRRejList		= Vals[COL2()+1,@RM]
WONo			= Vals[COL2()+1,@RM]
CassNo			= Vals[COL2()+1,@RM]
NCRNo			= Vals[COL2()+1,@RM]

End_Dialog(@WINDOW,WOMatSlotArray:@RM:NCRRejList)

RETURN



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


RETURN



* * * * * * *
Cancel:
* * * * * * *

End_Dialog(@WINDOW,'')

RETURN


* * * * * * * 
RejWafers:
* * * * * * *

NCRNo 		= Get_Property(@WINDOW:'.NCR_NO','DEFPROP')
SlotList 	= Get_Property(@WINDOW:'.WM_OUT_SLOT','LIST')
CassNo		= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')

SlotSelection	= Get_Property(@WINDOW:'.WM_OUT_SLOT','SELPOS')
SelectedSlots = SlotSelection<2>

IF SelectedSlots = '' THEN RETURN
SelCnt = COUNT(SelectedSlots,@VM) + (SelectedSlots NE '')

WaferArray = Get_Property(@WINDOW:'.SLOT_REJECT','ARRAY')

FOR I = 1 TO SelCnt
	SlotLine	= SelectedSlots<1,I>
	OutSlotNo	= SlotList<SlotLine,WFR_COL$OUT_SLOT>
	RDSNo		= SlotList<SlotLine,WFR_COL$RDS>
	Pocket		= SlotList<SlotLine,WFR_COL$POCKET>
	Zone		= SlotList<SlotLine,WFR_COL$ZONE>
	InCass		= SlotList<SlotLine,WFR_COL$IN_CASS>
	InSlotNo	= SlotList<SlotLine,WFR_COL$IN_SLOT>
	PrevNCR		= SlotList<SlotLine,WFR_COL$SLOT_NCR>
	MUWONo		= SlotList<SlotLine,WFR_COL$MU_WO_NO>
	MUWOStep	= SlotList<SlotLine,WFR_COL$MU_STEP>
	MUCassID	= SlotList<SlotLine,WFR_COL$MU_CASS>
	MUSlot		= SlotList<SlotLine,WFR_COL$MU_SLOT>
	
	LOCATE OutSlotNo IN WaferArray<NCR_COL$OUT_SLOT> BY 'AR' USING @VM SETTING POS ELSE
		WaferArray = INSERT(WaferArray,NCR_COL$OUT_CASS,Pos,0,CassNo)
		WaferArray = INSERT(WaferArray,NCR_COL$OUT_SLOT,Pos,0,OutSlotNo)
		WaferArray = INSERT(WaferArray,NCR_COL$RDS,Pos,0,RDSNo)
		WaferArray = INSERT(WaferArray,NCR_COL$POCKET,Pos,0,Pocket)
		WaferArray = INSERT(WaferArray,NCR_COL$ZONE,Pos,0,Zone)
		WaferArray = INSERT(WaferArray,NCR_COL$IN_CASS,Pos,0,InCass)
		WaferArray = INSERT(WaferArray,NCR_COL$IN_SLOT,Pos,0,InSlotNo)
		WaferArray = INSERT(WaferArray,NCR_COL$PREV_NCR,Pos,0,PrevNCR)
		WaferArray = INSERT(WaferArray,NCR_COL$MU_WO_NO,Pos,0,MUWONo)
		WaferArray = INSERT(WaferArray,NCR_COL$MU_STEP,Pos,0,MUWOStep)
		WaferArray = INSERT(WaferArray,NCR_COL$MU_CASS,Pos,0,MUCassID)
		WaferArray = INSERT(WaferArray,NCR_COL$MU_SLOT,Pos,0,MUSlot)
	END
	
	SlotList<SlotLine,WFR_COL$RDS>		= ''
	SlotList<SlotLine,WFR_COL$POCKET>	= ''
	SlotList<SlotLine,WFR_COL$ZONE>		= ''
	SlotList<SlotLine,WFR_COL$IN_CASS>	= ''
	SlotList<SlotLine,WFR_COL$IN_SLOT>	= ''
	SlotList<SlotLine,WFR_COL$SLOT_NCR>	= NCRNo
	SlotList<SlotLine,WFR_COL$MU_WO_NO>	= ''
	SlotList<SlotLine,WFR_COL$MU_STEP>	= ''
	SlotList<SlotLine,WFR_COL$MU_CASS>	= ''
	SlotList<SlotLine,WFR_COL$MU_SLOT>	= ''

NEXT I

Set_Property(@WINDOW:'.SLOT_REJECT','ARRAY',WaferArray)
Set_Property(@WINDOW:'.WM_OUT_SLOT','LIST',SlotList)

RETURN


* * * * * * *
RepWafers:
* * * * * * *

WaferList	= Get_Property(@WINDOW:'.SLOT_REJECT','LIST')
WONo		= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
CassNo		= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')

NCRNo      = Get_Property(@Window:'.NCR_NO', 'TEXT')
SAPBatchNo = Xlate('NCR', NCRNo, 'SAP_BATCH_NO', 'X')

If SAPBatchNo EQ '' then
    
    WaferSelection	= Get_Property(@WINDOW:'.SLOT_REJECT','SELPOS')
    SelectedWafers = WaferSelection<2>

    IF SelectedWafers = '' THEN RETURN

    SelCnt = COUNT(SelectedWafers,@VM) + (SelectedWafers NE '')
    WaferCnt = COUNT(WaferList,@FM) + (WaferList NE '')

    IF SelCnt = WaferCnt THEN
        ErrMesg  = 'There must be at least one rejected wafer on the NCR. '
        ErrMesg := 'If you are moving wafers from one slot to another, '
        ErrMesg := 'reject wafers from the cassette and then replace '
        ErrMesg := 'from the NCR.':CRLF$:CRLF$
        ErrMesg := 'If you are going to delete the NCR completely, '
        ErrMesg := 'you do not need to replace the wafers.  The program '
        ErrMesg := 'will replace them during the NCR delete process.'
        ErrMsg(ErrMesg)
        RETURN
    END

    SlotList = Get_Property(@WINDOW:'.WM_OUT_SLOT','LIST')

    FOR I = SelCnt TO 1 STEP -1
        SelectedWafer = SelectedWafers<1,I>
        

        OutSlot		= WaferList<SelectedWafer,NCR_COL$OUT_SLOT>
        RDSNo		= WaferList<SelectedWafer,NCR_COL$RDS>
        Pocket		= WaferList<SelectedWafer,NCR_COL$POCKET>
        Zone		= WaferList<SelectedWafer,NCR_COL$ZONE>
        InCass		= WaferList<SelectedWafer,NCR_COL$IN_CASS>
        InSlot		= WaferList<SelectedWafer,NCR_COL$IN_SLOT>
        PrevNCR		= WaferList<SelectedWafer,NCR_COL$PREV_NCR>
        MUWONo		= WaferList<SelectedWafer,NCR_COL$MU_WO_NO>
        MUWOStep	= WaferList<SelectedWafer,NCR_COL$MU_STEP>
        MUCassID	= WaferList<SelectedWafer,NCR_COL$MU_CASS>
        MUSlot		= WaferList<SelectedWafer,NCR_COL$MU_SLOT>
        
        WaferList = DELETE(WaferList,SelectedWafer,0,0)							;* Removes rejected wafer from NCR list
        
        SlotList<OutSlot,WFR_COL$OUT_SLOT> = OutSlot
        SlotList<OutSlot,WFR_COL$RDS>		= RDSNo
        SlotList<OutSlot,WFR_COL$POCKET>	= Pocket
        SlotList<OutSlot,WFR_COL$ZONE>		= Zone
        SlotList<OutSlot,WFR_COL$IN_CASS>	= InCass
        SlotList<OutSlot,WFR_COL$IN_SLOT>	= InSlot
        SlotList<OutSlot,WFR_COL$SLOT_NCR>	= PrevNCR
        SlotList<OutSlot,WFR_COL$MU_WO_NO>	= MUWONo
        SlotList<OutSlot,WFR_COL$MU_STEP>	= MUWOStep
        SlotList<OutSlot,WFR_COL$MU_CASS>	= MUCassID
        SlotList<OutSlot,WFR_COL$MU_SLOT>	= MUSlot
        
    NEXT I

    Set_Property(@WINDOW:'.SLOT_REJECT','LIST',WaferList)
    Set_Property(@WINDOW:'.WM_OUT_SLOT','LIST',SlotList)
end else
    ErrMsg('Wafers cannot be replaced because an SAP batch number has been assigned. Contact FI for further assistance.')
end

RETURN


