COMPILE FUNCTION Comm_Dialog_NCR_Rej_Slot(Method, Parm1, Parm2)

/*
	Commuter module for Dialog_NCR_Rej_Slot window.
	
	08/20/2008 - 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$SLOT			TO 1
EQU WFR_COL$WAFER_ID		TO 2
EQU WFR_COL$SLOT_NCR		TO 3
EQU WFR_COL$MET_NO			TO 4
EQU WFR_COL$MOVED_TO_SLOT	TO 5
EQU WFR_COL$REPLACED_BY		TO 6

EQU NCR_COL$SLOT_NO		TO 1
EQU NCR_COL$WAFER_ID	TO 2
EQU NCR_COL$PREV_NCR	TO 3
EQU NCR_COL$REJ_MET_NO	TO 4


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:'.WO_MAT_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:'.WO_MAT_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:'.WO_MAT_SLOT':@RM		; Props  = 'LIST':@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'

Set_Property(Ctrls,Props,Parm1)



RETURN


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

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

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

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

BadLines = ''

FOR I = 1 TO SelCnt
	LineNo = SelectedLines<1,I>
	IF SlotList<LineNo,WFR_COL$WAFER_ID> = '' THEN
		BadLines<1,-1> = LineNo
	END	
NEXT I


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



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

Ctrls  = @WINDOW:'.WO_MAT_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:'.WO_MAT_SLOT','LIST')

SlotSelection	= Get_Property(@WINDOW:'.WO_MAT_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>
	SlotNo = SlotList<SlotLine,1>
	WaferID = SlotList<SlotLine,2>
	PrevNCR = SlotList<SlotLine,3>
	RejMetNo = SlotList<SLotLine,4>
	
	LOCATE SlotNo IN WaferArray<1> BY 'AR' USING @VM SETTING POS ELSE
		WaferArray = INSERT(WaferArray,1,Pos,0,SlotNo)
		WaferArray = INSERT(WaferArray,2,Pos,0,WaferID)
		WaferArray = INSERT(WaferArray,3,Pos,0,PrevNCR)
		WaferArray = INSERT(WaferArray,4,Pos,0,RejMetNo)
	END
	
	SlotList<SlotLine,WFR_COL$WAFER_ID> = ''
	SlotList<SlotLine,WFR_COL$SLOT_NCR> = NCRNo
	SlotList<SlotLine,WFR_COL$REPLACED_BY> = ''
	SlotList<SlotLine,WFR_COL$MET_NO> = ''

NEXT I

Set_Property(@WINDOW:'.SLOT_REJECT','ARRAY',WaferArray)
Set_Property(@WINDOW:'.WO_MAT_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:'.WO_MAT_SLOT','LIST')

    FOR I = SelCnt TO 1 STEP -1
        SelectedWafer = SelectedWafers<1,I>
        
        SlotNo	= WaferList<SelectedWafer,NCR_COL$SLOT_NO>
        WaferID	= WaferList<SelectedWafer,NCR_COL$WAFER_ID>
        PrevNCR	= WaferList<SelectedWafer,NCR_COL$PREV_NCR>
        RejMetNo = WaferList<SelectedWafer,NCR_COL$REJ_MET_NO>

        WaferList = DELETE(WaferList,SelectedWafer,0,0)
        
        SlotList<SlotNo,WFR_COL$SLOT>		= SlotNo
        SlotList<SlotNo,WFR_COL$WAFER_ID>	= WaferID
        SlotList<SlotNo,WFR_COL$SLOT_NCR>	= PrevNCR
        SlotList<SlotNo,WFR_COL$MET_NO>		= RejMetNo
        IF PrevNCR NE '' THEN
            SlotList<SlotNo,WFR_COL$REPLACED_BY> = WaferID
        END
    NEXT I

    Set_Property(@WINDOW:'.SLOT_REJECT','LIST',WaferList)
    Set_Property(@WINDOW:'.WO_MAT_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


