COMPILE FUNCTION Comm_Dialog_Lot_No_Change(Method, Parm1)

/*
	Commuter module for Dialog_Lot_No_Change window.
	
	05/06/2004 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status, ErrMsg
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Msg, Btree.Extract

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Popup, Send_Message

EQU CRLF$	TO \0D0A\

$INSERT APPCOLORS
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT WO_MAT_EQUATES

EQU COL$WM_CASS_NO		TO 1
EQU COL$WM_LOT_NO		TO 2
EQU COL$WM_RDS_NO		TO 3

EQU COL$LOT_NO			TO 1
EQU COL$CASS_NOS		TO 2

ErrTitle = 'Error in Comm_Dialog_Lot_No_Change'
ErrorMsg = ''
ErrCode  = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'				; GOSUB Create
	CASE Method = 'OrgLotNoLF'			; GOSUB OrgLotNoLF
	CASE Method = 'NewLotNoLF'			; GOSUB NewLotNoLF
	CASE Method = 'CassNoLF'			; GOSUB CassNoLF
	CASE Method = 'SelectCassettes'		; GOSUB SelectCassettes
	CASE Method = 'SelectOriginal'		; GOSUB SelectOriginal
	CASE Method = 'SelectNew'			; GOSUB SelectNew
	CASE Method = 'LULotNo'				; GOSUB LULotNo
	CASE Method = 'OK'					; GOSUB OK
	CASE Method = 'Cancel'				; GOSUB Cancel
	CASE Method = 'Refresh'				; GOSUB Refresh
	CASE Method = 'LotNoPC'				; GOSUB LotNoPC
	
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE


RETURN Result


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

obj_AppWindow('Create')

WONo = Parm1[1,@FM]

Title = 'Work Order: ':WONo:' - Lot No Change'

Set_Property(@WINDOW,'TEXT',Title)

OPEN 'DICT.WO_MAT' TO DictVar ELSE
	ErrMsg('Unable to open "DICT.WO_MAT" for index lookup in COMM_DIALOG_LOT_NO_CHANGE routine.')
	RETURN
END	
	

SearchString  = 'WO_NO':@VM:WONo:@FM
WOMatKeys = ''
Flag = ''
Btree.Extract(SearchString, 'WO_MAT', DictVar, WOMatKeys, '', Flag)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	RETURN
END

IF INDEX(WOMatKeys,@VM,1) THEN
		
	WOMatKeys := @VM
	CONVERT @VM TO @RM IN WOMatKeys
	CALL V119('S','','A','R',WOMatKeys,'')
	IF Get_Status(errCode) THEN DEBUG
	CONVERT @RM TO @VM IN WOMatKeys
	WOMatKeys[-1,1] = ''					;* Strip trailing delimiter	
	
END ELSE
	NULL
END	



WOMatList = ''
LotNoArray = ''

LotNos	= ''
CassNos	= ''
RDSNos	= ''

OPEN 'WO_MAT' TO WOMatTable ELSE
	ErrMsg('Unable to open "WO_MAT" for reads in COMM_DIALOG_LOT_NO_CHANGE - Create Event')
	RETURN
END


kCnt = COUNT(WOMatKeys,@VM) + (WOMatKeys NE '')

FOR I = 1 TO kCnt
	WOMatKey = WOMatKeys<1,I>
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
	
		CassNo 	= FIELD(WOMatKey,'*',2)
		LotNo	= WOMatRec<WO_MAT_LOT_NO$>
		RDSNos	= WOMatRec<WO_MAT_RDS_NO$>
		
		SWAP @VM WITH ', ' IN RDSNos
		
		WOMatList<I> = CassNo:@VM:LotNo:@VM:RDSNos
		
		LOCATE LotNo IN LotNos USING @FM SETTING Pos THEN
			LOCATE CassNo IN CassNos<Pos> USING @VM SETTING vPos ELSE
				CassNos = INSERT(CassNos,Pos,vPos,0,CassNo)
			END
		END ELSE
			LotNos = INSERT(LotNos,Pos,0,0,LotNo)
			CassNos = INSERT(CassNos,Pos,0,0,CassNo)
		END
	END

NEXT I

Set_Property(@WINDOW:'.WO_MAT_KEYS','LIST',WOMatList)

SWAP @VM WITH ', ' IN CassNos
CONVERT @FM TO @VM IN CassNos
CONVERT @FM TO @VM IN LotNos

LotNoArray = LotNos:@FM:CassNos

Set_Property(@WINDOW:'.LOT_NOS','DEFPROP',LotNoArray)



RETURN


* * * * * * *
LotNoPC:
* * * * * * *

CtrlEntID = @WINDOW:'.LOT_NOS'

CurrList	= Get_Property(CtrlEntID,'LIST')
CurrPos		= Get_Property(CtrlEntID,'SELPOS')

CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CurrLotNo 	= CurrList<CurrRow,COL$LOT_NO>
CurrCassNos = CurrList<CurrRow,COL$CASS_NOS>

WOMatCtrl = @WINDOW:'.WO_MAT_KEYS'
WOMatList = Get_Property(WOMatCtrl,'LIST')

LineCnt = COUNT(WOMatList,@FM) + (WOMatList NE '')
	
	FOR Line = 1 TO LineCnt
		LineLotNo = WOMatList<Line,COL$WM_LOT_NO>
		
		IF LineLotNo  = CurrLotNo THEN	
			stat = Send_Message(WOMatCtrl,'COLOR_BY_POS',0,Line,YELLOW$)
		END ELSE
			stat = Send_Message(WOMatCtrl,'COLOR_BY_POS',0,Line,GREEN$)
		END
		
	NEXT Line

RETURN






* * * * * * *
LULotNo:
* * * * * * *

* * * * *   NOT USED JCH  - Remove when done on 2 DEC 2016  **********************************************

ReturnCtrl = Parm1[1,@RM]

IF ReturnCtrl = '' THEN ReturnCtrl = Get_Property(@WINDOW,'FOCUS')

LotList = Get_Property(@WINDOW,'@LOT_NOS')

TypeOver = ''
TypeOver<PDISPLAY$> = LotList

RetVal = Popup(@WINDOW,TypeOver,'CUST_LOT_NO')

IF RetVal NE '' THEN
	obj_Appwindow('LUValReturn',RetVal:@RM:ReturnCtrl)
END

RETURN


* * * * * * *
SelectOriginal:
* * * * * * * 

CtrlEntID = @WINDOW:'.LOT_NOS'

CurrList	= Get_Property(CtrlEntID,'LIST')
CurrPos		= Get_Property(CtrlEntID,'SELPOS')

CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CurrLotNo 	= CurrList<CurrRow,COL$LOT_NO>

Set_Property(@WINDOW:'.ORG_LOT_NO','DEFPROP',CurrLotNo)

Return


* * * * * * *
OrgLotNoLF:
* * * * * * *

OrgLotNo = Get_Property(@WINDOW:'.ORG_LOT_NO','TEXT')
IF OrgLotNo = '' THEN RETURN

ValidLotNos = Get_Property(@WINDOW,'@LOT_NOS')

LOCATE OrgLotNo IN ValidLotNos USING @VM SETTING Pos ELSE
	ErrMsg('Lot No:':QUOTE(OrgLotNo):' is not on this Work Order!')
	Set_Property(@WINDOW,'FOCUS',@WINDOW:'.ORG_LOT_NO')
	Set_Property(@WINDOW:'.ORG_LOT_NO','TEXT','')
END

Return

* * * * * * *
SelectNew:
* * * * * * *

CtrlEntID = @WINDOW:'.LOT_NOS'

CurrList	= Get_Property(CtrlEntID,'LIST')
CurrPos		= Get_Property(CtrlEntID,'SELPOS')

CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CurrLotNo 	= CurrList<CurrRow,COL$LOT_NO>

Set_Property(@WINDOW:'.NEW_LOT_NO','DEFPROP',CurrLotNo)

Return



* * * * * * *
NewLotNoLF:
* * * * * * *



Return


* * * * * * *
SelectCassettes:
* * * * * * *


WOMatCtrl = @WINDOW:'.WO_MAT_KEYS'

WOMatKeyList = Get_Property(WOMatCtrl,'LIST')

SlotSelection	= Get_Property(WOMatCtrl,'SELPOS')
SelectedRows	= SlotSelection<2>

CONVERT @VM TO @FM in SelectedRows

SelCnt		= COUNT(SelectedRows,@FM) + (SelectedRows NE '')
IF SelCnt	= 0 THEN
	ErrMsg('No WO Cassettes selected.')
	RETURN
End

CassNoDisp = ''
For I = 1 To SelCnt
	SelectedRow = SelectedRows<I>
	CassNoDisp<-1> = WOMatKeyList<SelectedRow,COL$WM_CASS_NO>
Next I

Swap @FM With ', ' In CassNoDisp

Set_Property(@WINDOW:'.CASS_NOS','DEFPROP',CassNoDisp)

RETURN

* * * * * * *
CassNoLF:
* * * * * * *



Return








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

RETURN


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


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

End_Dialog(@WINDOW,'Cancel')

RETURN



* * * * * * *
OK:
* * * * * * *

Ctrls  = @WINDOW:'.ORG_LOT_NO':@RM	; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.NEW_LOT_NO':@RM	; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.REASON':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.CASS_NOS'		; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

OrgLotNo	= Vals[1,@RM]
NewLotNo	= Vals[COL2()+1,@RM]
Reason		= Vals[COL2()+1,@RM]
CassNos		= Vals[COL2()+1,@RM]

Swap ', ' With @VM In CassNos


IF OrgLotNo = '' THEN
	ErrMsg('Original Lot Number is a required field and must be filled in.')
	Set_Property(@WINDOW,'FOCUS',@WINDOW:'.ORG_LOT_NO')
	RETURN
END

IF NewLotNo = '' THEN
	ErrMsg('New Lot Number is a required field and must be filled in.')
	Set_Property(@WINDOW,'FOCUS',@WINDOW:'.NEW_LOT_NO')
	RETURN
END

IF Reason = '' THEN
	ErrMsg('Reason is a required field and must be filled in.')
	Set_Property(@WINDOW,'FOCUS',@WINDOW:'.REVISION')
	RETURN
END


IF CassNos = '' THEN
	ErrMsg('CassNos is a required field and must be filled in.')
	Set_Property(@WINDOW,'FOCUS',@WINDOW:'.CASS_NOS')
	RETURN
END


Result		= OrgLotNo
Result<2>	= NewLotNo
Result<3>	= Reason
Result<4>	= CassNos

End_Dialog(@WINDOW,Result)

RETURN



