COMPILE FUNCTION GaN_Tool_Status(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for GAN_TOOL_STATUS  dialog window
	
	09/5/2016 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event, RList
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, obj_Tool_Log
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, Create_Note

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals, Admin_User, Printer_Select
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI, MemberOf, Get_Printer, obj_Install,Set_Printer


$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT TOOL_EQUATES
$INSERT TOOL_LOG_EQUATES
$INSERT POPUP_EQUATES
$INSERT RTI_STYLE_EQUATES

$INSERT RLIST_EQUATES
$INSERT OIPRINT_EQUATES

EQU COL$TOOL_CLASS		TO 1
EQU COL$TOOL_ID			TO 2
EQU COL$TOOL_DESC		TO 3
EQU COL$CURR_MODE		TO 4
EQU COL$CURR_MODE_HRS	TO 5
EQU COL$CHANGE_MODE		TO 6



ErrTitle = 'Error in Master_PM_List routine'
ErrorMsg = ''

Result = ''


BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
			
		END CASE
		
	CASE EntID = @WINDOW:'.TOOL_LIST' AND Event = 'DBLCLK'				; GOSUB ToolDC
	CASE EntID = @WINDOW:'.TOOL_LIST' AND Event = 'OPTIONS'				; GOSUB ToolOptions
	CASE EntID = @WINDOW:'.LIST_MODE' AND Event = 'CLICK'				; GOSUB ListMode
	
	
	*CASE EntID = @WINDOW:'.PRINT_EQUIP_LIST' AND Event = 'CLICK'	; *GOSUB PrintEquipment
	*CASE EntID = @WINDOW:'.NEW_EQUIPMENT' AND Event = 'CLICK'		; *GOSUB NewEquipment
	
	
	
	
	
	CASE 1
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
		
END CASE

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

RETURN Result



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


obj_Appwindow('Create',@WINDOW)

ToolStyles = Send_Message(@WINDOW:'.TOOL_LIST','COLSTYLE',0,'')

ToolStyles<COL$CHANGE_MODE>	= BitOr(ToolStyles<COL$CHANGE_MODE>,DTCS_OPTIONSBUTTON$)
ToolStyles<COL$CURR_MODE>	= BitOr(ToolStyles<COL$CURR_MODE>,DTCS_OPTIONSBUTTON$)

void = Send_Message(@WINDOW:'.TOOL_LIST','COLSTYLE',0,ToolStyles)


GOSUB Refresh

RETURN


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


End_Dialog(@WINDOW,'')

RETURN



* * * * * * *
ListMode:
* * * * * * *

ListMode = Get_Property(@WINDOW:'.LIST_MODE','TEXT')

IF ListMode = 'All Tools' THEN
	Set_Property(@WINDOW:'.LIST_MODE','TEXT','Tools In Maint')
END

IF ListMode = 'Tools In Maint' THEN
	Set_Property(@WINDOW:'.LIST_MODE','TEXT','All Tools')
END

GOSUB Refresh

RETURN


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

OPEN 'TOOL' TO ToolTable ELSE
	ErrorMsg = 'Unable to open "TOOL" table for read' 
	RETURN
END


SelectSent = 'SELECT TOOL WITH TOOL_PROC "G" AND WITH CLASS NE "G_REACT" BY TOOL_WH BY TOOL_TYPE'
RList(SelectSent,TARGET_ACTIVELIST$,'','','')

ListMode = Get_Property(@WINDOW:'.LIST_MODE','TEXT')

IF ListMode = 'All Tools' THEN
	SelectSent = "SELECT TOOL WITH CURR_MODE 'SCHED_MTC' 'UNSCHED_MTC' 'QUAL' 'EWORK' BY TOOL_WH BY TOOL_TYPE"
	RList(SelectSent,TARGET_ACTIVELIST$,'','','')
END
	
IF Get_Status(errCode) THEN
	DEBUG
	ErrMsg(errCode)
	RETURN
END

ToolList = ''

LineCnt = 0


Done = 0

LOOP
	READNEXT ToolID ELSE Done = 1
UNTIL Done

	READ ToolRec FROM ToolTable,ToolID THEN
		LineCnt += 1
		ToolList<LineCnt,COL$TOOL_CLASS>		= ToolRec<TOOL_TOOL_TYPE$>
		ToolList<LineCnt,COL$TOOL_ID>			= ToolID
		ToolList<LineCnt,COL$TOOL_DESC>			= ToolRec<TOOL_TOOL_DESC$>
		ToolList<LineCnt,COL$CURR_MODE>			= XLATE('TOOL',ToolID,'CURR_MODE','X')
		ToolList<LineCnt,COL$CURR_MODE_HRS>		= OCONV(XLATE('TOOL',TOOLID,'CURR_MODE_HRS','X'), 'MD2,')
	END
REPEAT

Set_Property(@WINDOW:'.TOOL_LIST','LIST',ToolList)

FOR I = 1 TO LineCnt
	CurrStat = ToolList<I,COL$CURR_MODE>
	
	BEGIN CASE 
		CASE CurrStat = 'PROD' OR CurrStat = 'LIM'		; LineColor = GREEN$
		CASE CurrStat = 'MTC'							; LineColor = ORANGE$
		CASE 1											; LineColor = RED$
	END CASE
			
	stat = Send_Message(@WINDOW:'.TOOL_LIST','COLOR_BY_POS',0,I,LineColor)

NEXT I

RETURN



* * * * * * *
ToolOptions:
* * * * * * *

CtrlEntID = @WINDOW:'.TOOL_LIST'

ToolList = Get_Property(CtrlEntID,'LIST')

CurrPos = Get_Property(CtrlEntID,'SELPOS')

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

ToolID = ToolList<CurrRow,COL$TOOL_ID>

CurrModeKey = ToolList<CurrRow,COL$CURR_MODE>


IF CurrCol = COL$CURR_MODE THEN

		
	OPEN "TOOL" TO hTable THEN
		DialogWin = "GAN_TOOL_STATUS"
		DialogKey = DialogWin:"*":ToolID
		
		LOCK hTable, DialogKey THEN
			ModeChangeParms = Dialog_Box("DIALOG_TOOL_MODE", @WINDOW, ToolID)
			Unlock hTable, DialogKey
		END ELSE
			Mtext = "Another user is currently updating this tool's status."
			Msg(@Window, "", "ERROR", "", "Update Tool Status" :@FM: Mtext)
			ModeChangeParms = "Cancel"
		END
	END

	* Cancel returned from dialog box

	IF ModeChangeParms = 'Cancel' THEN RETURN

	UserID	= ModeChangeParms[1,@FM]
	Reason	= ModeChangeParms[COL2()+1,@FM]
	NewMode = ModeChangeParms[COL2()+1,@FM]

	* Two users trying to update at same time leaves more than one current mode.  Take the first one.

	CurrModeDTM = XLATE('TOOL', ToolID, TOOL_CURR_MODE_KEY$, 'X')<1,1>	
	CurrModeDTM = FIELD(CurrModeDTM,'*',2)
	CurrModeDTM = OCONV(CurrModeDTM,'DT4/^S')

	Parms	 = ToolID:@RM
	Parms	:= CurrModeDTM:@RM
	Parms	:= NewMode:@RM
	Parms	:= Reason
		
	obj_Tool_Log('SetMode', Parms)

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

	GOSUB Refresh

END
	


RETURN


* * * * * * *
ToolDC:
* * * * * * *


CtrlEntId = @WINDOW:'.TOOL_LIST'

RowData = Get_Property(CtrlEntId,'ROWDATA')

ToolID = RowData<COL$TOOL_ID>


obj_AppWindow('ViewRelated','TOOL':@RM:ToolId)


GOSUB Refresh

RETURN


