COMPILE FUNCTION Comm_MES_Task(CtrlEntID,Event,Parm1, Parm2, Parm3, Parm4, Parm5)

/*
	Commuter module for MES_Task (Test Wafer Use) window
	
	12/12/2007 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, Forward_Event
DECLARE SUBROUTINE Send_Event, obj_TW_Use, Security_Err_Msg, Post_Event, Btree.Extract, ErrMsg, obj_WO_Mat
DECLARE SUBROUTINE Send_Message, obj_WM_IN, obj_Notes

DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, MemberOf, NextKey
DECLARE FUNCTION obj_Quote, Security_Check, obj_WO_Mat, obj_WM_In, Dialog_Box


$INSERT REACT_RUN_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT NOTIFICATION_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT LSL_USERS_EQU

$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT POPUP_EQUATES

EQU CRLF$	TO \0D0A\

ErrTitle = 'Error in Comm_TW_Use'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE CtrlEntID = @WINDOW AND Event = 'CREATE'			; GOSUB Create
	CASE CtrlEntID = @WINDOW AND Event = 'READ'				; GOSUB Read
	CASE CtrlEntID = @WINDOW AND Event = 'WRITE'			; GOSUB Write
	CASE CtrlEntID = @WINDOW AND Event = 'DELETE'			; GOSUB Delete
	CASE CtrlEntID = @WINDOW AND Event = 'CLEAR'			; GOSUB Refresh
	CASE CtrlEntID = @WINDOW AND Event = 'CLOSE'			; GOSUB Close
	CASE CtrlEntID = @WINDOW AND Event[1,3] = 'QBF'			; GOSUB Refresh
	
	CASE CtrlEntID = @WINDOW:'.NEW_BUTTON' AND Event = 'CLICK'		; GOSUB New
	CASE CtrlEntID = @WINDOW:'.LU_MES_TASK' AND Event = 'CLICK'		; GOSUB LUMesTask
	CASE CtrlEntID = @WINDOW:'.LU_PART_OF' AND Event = 'CLICK'		; GOSUB LUPartOf
	CASE CtrlEntID = @WINDOW:'.LU_REPORT_BY' AND Event = 'CLICK'	; GOSUB LUReportBy
	CASE CtrlEntID = @WINDOW:'.LU_DEPT' AND Event = 'CLICK'			; GOSUB LUDept
	CASE CtrlEntID = @WINDOW:'.LU_OFI_NO' AND Event = 'CLICK'		; GOSUB LUOFI
	CASE CtrlEntID = @WINDOW:'.VIEW_ICAR' AND Event = 'CLICK'		; GOSUB ViewOFI
	CASE CtrlEntID = @WINDOW:'.SIGN_COMP' AND Event = 'CLICK'		; GOSUB SignComp
	
	*CASE CtrlEntID = @WINDOW:'.WAFER_ID' AND Event = 'DELETEROW'	; *GOSUB DeleteWaferID
	*CASE CtrlEntID = @WINDOW:'.TW_QTY' AND Event = 'LOSTFOCUS'		; *GOSUB TWQtyLF
	
	
	CASE 1
	
		ErrorMsg = 'Unknown Instruction passed to routine':CRLF$:CtrlEntID:' - ':Event
END CASE

IF ErrorMsg NE '' THEN
	ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result


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

obj_Appwindow('Create',@WINDOW)

* Provides compatibility with the existing messaging attachment system

IOOptions = Get_Property(@WINDOW,'IOOPTIONS')
IOOptions<10> = 1	;* Check for required fields on WRITE event
IOOptions<11> = 1	;* Create READ event on QBF load

Set_Property(@WINDOW,'IOOPTIONS',IOOptions)

GOSUB Refresh

RETURN


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


EnterBy = Get_Property(@WINDOW:'.ENTER_BY','TEXT')
IF EnterBy = '' THEN
	CurrDate = OCONV(Date(),'D4/')
	CurrTime = OCONV(Time(),'MTH')
	CurrDTM = CurrDate:' ':CurrTime
	Set_Property(@WINDOW:'.ENTER_BY','TEXT',OCONV(@USER4,'[XLATE_CONV,LSL_USERS*FIRST_LAST]'))
	Set_Property(@WINDOW:'.ENTER_DTM','TEXT',CurrDTM)
END

GOSUB Refresh

RETURN


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

Forward_Event()

Post_Event(@WINDOW,'CLOSE')

Return


* * * * * * *
Clear:
* * * * * * *

obj_AppWindow('ReadOnly',@RM:1)			;* Reenables data bound controls
Set_Property(@WINDOW,'@READONLY',0)		;* Clear flag on window

GOTO Refresh

RETURN

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

obj_Appwindow('DetailReturn')

RETURN




* * * * * * *
Delete:
* * * * * * *


RETURN


Forward_Event()

Result = 0

Post_Event(@WINDOW,'CLOSE')

RETURN



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


IF Get_Property(@WINDOW:'.ENTER_BY','DEFPROP') NE '' THEN
	Set_Property(@WINDOW:'.ENTER_BY','BACKCOLOR',GREEN$)
	Set_Property(@WINDOW:'.ENTER_DTM','BACKCOLOR',GREEN$)
END



* QBF buttons

Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
END ELSE
	Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
END

Set_Property(Ctrls,Props,Vals)

* Turn edit table symbolic column backgrounds to green

ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow

ETCtrls	= ETSymbolics<1>
ETCols	= ETSymbolics<2>

FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
	ETCtrl	= ETCtrls<1,I>
	ETList = Get_Property(ETCtrl,'LIST')
	FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
		IF ETList<Line,1> NE '' THEN
			FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
				stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
			NEXT N
		END
	NEXT Line
NEXT I

RETURN


* * * * * * *
New:
* * * * * * *

MetTaskNo = Get_Property(@WINDOW:'.MT_NO','ID')

IF MetTaskNo = '' THEN
	NextMTNo = NextKey('MES_TASK')
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:NextMTNo)
END


RETURN



* * * * * * *
LUMesTask:
* * * * * * *

MESTaskNo = Get_Property(@WINDOW:'.MT_NO','ID')

IF MESTaskNo = '' THEN
	MTNo = Popup(@WINDOW,'','MES_TASK')
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:MTNo)
END

RETURN


* * * * * * *
LUPartOf:
* * * * * * *



RETURN



* * * * * * *
LUReportBy:
* * * * * * * 


ReportBy = Popup(@WINDOW,'','USER_ID')

IF ReportBy = CHAR(27) OR ReportBy = '' THEN RETURN

CurrDate = OCONV(Date(),'D4/')
CurrTime = OCONV(Time(),'MTH')
CurrDTM = CurrDate:' ':CurrTime

Set_Property(@WINDOW:'.REPORT_BY','TEXT',OCONV(ReportBy,'[XLATE_CONV,LSL_USERS*FIRST_LAST]'))
Set_Property(@WINDOW:'.REPORT_DTM','TEXT',CurrDTM)

GOSUB Refresh

RETURN


* * * * * * *
LUDept:
* * * * * * *

Dept = Popup(@WINDOW,'','DEPARTMENT')

IF Dept = '' THEN Return				;* Originally was IF Dept = '' OR Dept = CHAR(27) THEN RETURN -dkk 6/10/16

obj_AppWindow('LUValReturn',Dept:@RM:@WINDOW:'.DEPT')

RETURN


* * * * * * *
LUOFI:
* * * * * * *


ICarKeys = Dialog_Box( 'ICAR_QUERY', @WINDOW, '' )

CONVERT @FM TO @VM IN ICarKeys

IF ICarKeys NE '' THEN

	IF INDEX(ICarKeys,@VM,1) THEN

		TypeOver = ''
		TypeOver<PDISPLAY$> = ICarKeys
		TypeOver<PMODE$> = 'K'
		TypeOver<PSELECT$> = 1	;* Single Select

		ICarKey = Popup(@WINDOW,TypeOver,'ICAR_QUERY')
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
		
	END
	
	IF ICarKey = '' OR ICarKey = CHAR(27) THEN RETURN
	
	obj_AppWindow('LUValReturn',ICarKey:@RM:@WINDOW:'.ICAR_NO')
END
	
RETURN




* * * * * * *
ViewOFI:
* * * * * * *

ICarKey = Get_Property(@WINDOW:'.ICAR_NO','DEFPROP')

obj_Appwindow('ViewRelated','ICAR':@RM:ICarKey)		;* Loads form key or QBFList as required


RETURN



* * * * * * *
SignComp:
* * * * * * *


MTNo 		= Get_Property(@WINDOW:'.MT_NO','DEFPROP')
Desc 		= Get_Property(@WINDOW:'.BRIEF_DESC','DEFPROP')
ReportBy	= Get_Property(@WINDOW:'.REPORT_BY','DEFPROP')


CurrDate = OCONV(Date(),'D4/')
CurrTime = OCONV(Time(),'MTH')
CurrDTM = CurrDate:' ':CurrTime

UserName = @USER4

Set_Property(@WINDOW:'.COMP_BY','TEXT',OCONV(@USER4,'[XLATE_CONV,LSL_USERS*FIRST_LAST]'))
Set_Property(@WINDOW:'.COMP_DTM','TEXT',CurrDTM)

Recipients		= Xlate('SEC_GROUPS', 'OI_SUPERUSER', 'USER', 'X') : @VM : ReportBy	;
SentFrom		= "MES TaskCompleted"
Subject			= 'MES Task ':MTNo:' Signed Off'
Message			= 'MES Task ':Desc:' completed.'
AttachWindow	= 'MES_TASK'
AttachKey		= MTNo  
SendToGroup		= ''   

Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)


RETURN










