COMPILE FUNCTION Comm_Dialog_WO_Cass_Qty(Method, Parm1, Parm2)

/*
	Commuter module for Dialog_WO_Cass_Qty window.
	
	08/20/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
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Send_Message

EQU CRLF$	TO \0D0A\

$INSERT APPCOLORS


ErrTitle = 'Error in Comm_Dialog_WO_Cass_Qty'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'OK'				; GOSUB OK
	CASE Method = 'Cancel'			; GOSUB Cancel
	CASE Method = 'Refresh'			; GOSUB Refresh
	CASE Method = 'Close'			; GOSUB Close
	CASE Method = 'InsertRow'		; GOSUB InsertRow
	CASE Method = 'DeleteRow'		; GOSUB DeleteRow
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE


RETURN Result


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

obj_AppWindow('Create')

Title 	= Parm1[1,@FM]
LotQty	= Parm1[COL2()+1,@FM]
CassCnt = Parm1[COL2()+1,@FM]
CassQty = Parm1[COL2()+1,@FM]

Set_Property(@WINDOW,'TEXT',Title)
Set_Property(@WINDOW:'.LOT_QTY','TEXT',LotQty)

IF CassQty = '' THEN
	Set_Property(@WINDOW:'.CASS_QTYS','ARRAY',STR(@VM,CassCnt-1))
END ELSE
	CONVERT @SVM TO @VM IN CassQty
	Set_Property(@WINDOW:'.CASS_QTYS','ARRAY',CassQty)
END


GOSUB Refresh

RETURN


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

LotQty		= Get_Property(@WINDOW:'.LOT_QTY','TEXT',LotQty)
CassQtys	= Get_Property(@WINDOW:'.CASS_QTYS','ARRAY')

LotQty = ICONV(LotQty,'MD0')
CassQtyTot = SUM(CassQtys)

Remainder = LotQty - CassQtyTot

Set_Property(@WINDOW:'.REMAINDER','TEXT',Remainder)

BEGIN CASE
	CASE Remainder > 0
		Set_Property(@WINDOW:'.REMAINDER','BACKCOLOR',YELLOW$)
		Set_Property(@WINDOW:'.OK_BUTTON','ENABLED',0)
		
	CASE Remainder = 0
		Set_Property(@WINDOW:'.REMAINDER','BACKCOLOR',GREEN$)
		Set_Property(@WINDOW:'.OK_BUTTON','ENABLED',1)
		
	CASE Remainder < 0
		Set_Property(@WINDOW:'.REMAINDER','BACKCOLOR',RED$)
		Set_Property(@WINDOW:'.OK_BUTTON','ENABLED',0)
		
END CASE


RETURN



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


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

End_Dialog(@WINDOW,'Cancel')

RETURN


* * * * * * * 
InsertRow:
* * * * * * *

CtrlEntID = @WINDOW:'.CASS_QTYS'
RowIndex = Parm1
Dummy  = Send_Message(CtrlEntID, "DELETE", RowIndex)

ErrMsg('Close this window and change the quantity in the Cass Cnt field to increase the number of cassettes.')

RETURN


* * * * * * *
DeleteRow:
* * * * * * *

CtrlEntID = @WINDOW:'.CASS_QTYS'
RowIndex = Parm1
DeletedRow = Parm2

Dummy = Send_Message(CtrlEntID, "INSERT", RowIndex, DeletedRow)

ErrMsg('Close this window and change the quantity in the Cass Cnt field to decrease the number of cassettes.')

RETURN



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

CassQtys = Get_Property(@WINDOW:'.CASS_QTYS','ARRAY',CassQty)

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

CONVERT @VM TO @SVM IN CassQtys

End_Dialog(@WINDOW,CassQtys)

RETURN


