COMPILE FUNCTION Comm_MFC(Instruction,Parm1,Parm2)

/*
	Commuter module for MFC (Mass Flow Controllers) window
	
	08/11/2006 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, Make.List
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window,  Create_Note
DECLARE SUBROUTINE obj_Order
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Center_Window, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, Msg, Security_Check, RowExists, NextKey, obj_Popup

$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT ASM_PART_EQUATES
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT NOTIFICATION_EQU

EQU CRLF$	TO \0D0A\

EQU COL$COLUMN_1		TO 1		;* Equates for  edit table.
EQU COL$COLUMN_2		TO 2
EQU COL$COLUMN_3		TO 3


ErrTitle = 'Error in Comm_MFC'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Instruction = 'Create' 			; GOSUB Create
	CASE Instruction = 'Refresh'			; GOSUB Refresh
	CASE Instruction = 'CheckDefault'		; GOSUB CheckDefault
	CASE Instruction = 'Read'				; GOSUB Read
	CASE Instruction = 'Write'				; GOSUB Write
	CASE Instruction = 'Clear'				; GOSUB Clear
	CASE Instruction = 'Delete'				; GOSUB Delete
	CASE Instruction = 'Page'				; GOSUB Page
	CASE Instruction = 'Close'				; GOSUB Close
	CASE Instruction = 'LUSerNo'			; GOSUB LUSerNo
	CASE Instruction = 'LUASM_MFC'			; GOSUB LUASM_MFC
	CASE Instruction = 'NewOrder'			; GOSUB NewOrder
	CASE Instruction = 'GasesDC'			; GOSUB GasesDC
	CASE Instruction = 'LU_DecomReason'		; GOSUB LU_DecomReason
	

	
	CASE 1
		ErrorMsg = 'Unknown Instruction ':QUOTE(Instruction):' passed to routine.'
		ErrMsg(ErrorMsg)
END CASE

RETURN Result



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


IF NOT(Security_Check('Mass Flow Controller',READ$)) THEN
	Security_Err_Msg('Mass Flow Controller',READ$)
	End_Window(@WINDOW)
	RETURN
END

obj_Appwindow('Create',@WINDOW)

IOOptions = Get_Property(@WINDOW,'IOOPTIONS')
IOOptions<11> = 1	;* Generate READ event on QBFLoad

Set_Property(@WINDOW,'IOOPTIONS',IOOptions)


GOSUB Refresh

RETURN


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

Send_Event(@WINDOW,'PAGE',1)

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


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

/*

* * * * *   Samples   * * * * * *

ACStatus = Get_Property(@WINDOW:'.AC_STATUS','TEXT')
IF ACStatus NE '' THEN
	IF  ACStatus[1,1] = 'C' THEN
		Set_Property(@WINDOW:'.AC_STATUS','BACKCOLOR',RED$)
	END ELSE
		Set_Property(@WINDOW:'.AC_STATUS','BACKCOLOR',GREEN$)
	END
END

Captive = Get_Property(@WINDOW:'.CAPTIVE','CHECK')
Consignment = Get_Property(@WINDOW:'.CONSIGNMENT','CHECK')

BEGIN CASE
	CASE Captive
		Set_Property(@WINDOW:'.ORD_TYPE','BACKCOLOR',LTBLUE$)
		
	CASE Consignment
		Set_Property(@WINDOW:'.ORD_TYPE','BACKCOLOR',YELLOW$)
		
	CASE 1
		Set_Property(@WINDOW:'.ORD_TYPE','BACKCOLOR',GREEN$)
		
END CASE


Ctrls  = @WINDOW:'.CHANGE_VISION_ORD_NO':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.CUST_BUTTON':@RM					; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.CONTACT_BUTTON':@RM				; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.CREATE_WO_BUTTON':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.VIEW_AC':@RM						; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.NEW_ITEM_BUTTON':@RM				; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.SHIP_TO_EDIT':@RM				; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.BILL_TO_EDIT':@RM				; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.LU_CUST_NO':@RM					; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.LU_COMP_CONTACT':@RM				; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.LU_AC'							; Props := 'ENABLED'

IF Get_Property(@WINDOW,'@READONLY') THEN
	Vals = STR('0':@RM,11)					;* ReadOnly mode - kill the buttons
END ELSE
	Vals = STR('1':@RM,11)					;* Normal mode - enable the buttons
END

Vals[-1,1] = ''

Set_Property(Ctrls,Props,Vals)		;* Kill the function buttons when in view only mode

*/
* * * * *   End of Samples   * * * * * *


* 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 I
NEXT I

RETURN


* * * * * * *
Page:
* * * * * * *

obj_Appwindow('Page')


RETURN


* * * * * * *
CheckDefault:
* * * * * * *

CtrlEntID	= Get_Property(@WINDOW,'FOCUS')
CtrlType	= Get_Property(CtrlEntID,'TYPE')
CurrText	= Get_Property(CtrlEntID,'DEFPROP')

IF CurrText<1,1> = '' AND CtrlType = 'EDITFIELD' THEN
	
	PrevRecord = Get_Property(@WINDOW,'@PREV_REC')
	IF PrevRecord NE '' THEN
		CtrlCol = Get_Property(CtrlEntID, 'POS')
		
		IF INDEX(CtrlCol,@SVM,1) THEN DEBUG
		
		DefaultText = PrevRecord<CtrlCol>
		IF DefaultText NE '' THEN
			Set_Property(CtrlEntID,'TEXT',DefaultText)
			Set_Property(CtrlEntID,'SELECTION',1:@FM:65534)
		END
	END
END

RETURN



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

/*

OrderNo = Get_Property(@WINDOW:'.ORD_NO','TEXT')

IF RowExists('ORDER',OrderNo) THEN
	IF NOT(Security_Check('Mass Flow Controller',EDIT$)) THEN
		obj_AppWindow('ReadOnly',@WINDOW)				;* disable all database controls
		Set_Property(@WINDOW,'@READONLY',1)
	END
END ELSE
	IF NOT(Security_Check('Mass Flow Controller',WRITE$)) THEN
		Send_Event(@WINDOW,'CLEAR')
		Security_Err_Msg('Mass Flow Controller',WRITE$)
		RETURN
	END
END

*/

GOSUB Refresh

RETURN


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

CurrID = Get_Property(@WINDOW,'ID')
CurrRec = Get_Property(@WINDOW,'ATRECORD')

IF CurrID NE '' THEN

	Set_Property(@WINDOW,'@PREV_ID',CurrID)
	Set_Property(@WINDOW,'@PREV_REC',CurrRec)
END

Result = 1

RETURN


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

/*
IF Security_Check('Mass Flow Controller',Delete$) THEN
	Result = 1		;* Proceed with delete
END ELSE
	Security_Err_Msg('Mass Flow Controller',Delete$)
	Result = 0		;* Stop event chain
END
*/

RETURN


* * * * * * *
LUSerNo:
* * * * * * * 

SerNos = Popup(@WINDOW,'','MASS_FLOW_CONTROLLERS')

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


obj_AppWindow('ViewRelated',@WINDOW:@RM:SerNos)		;* ViewRelated either does 'LoadFormKey' or creates a browse list for multiple keys


RETURN


* * * * * * *
LUASM_MFC:
* * * * * * *

IF NOT(ASSIGNED(Parm1)) THEN FocusControl = ''	ELSE FocusControl = Parm1
IF NOT(ASSIGNED(Parm2)) THEN FocusPos = ''		ELSE FocusPos = Parm2

TypeOver = ''
TypeOver<PSELECT$> = 1

Value = Popup(@WINDOW,TypeOver,'ASM_MFC')
IF Value NE '' THEN
	obj_Appwindow('LUValReturn',Value:@RM:FocusControl:@RM:FocusPos)
	
	ASMPartRec = XLATE('ASM_PART',Value,'','X')
	
	Range		= ASMPartRec<ASM_PART_RANGE$>
	Flow		= ASMPartRec<ASM_PART_FLOW$>
	Gas			= ASMPartRec<ASM_PART_GAS$>
	InletPress	= ASMPartRec<ASM_PART_INLET_PRESS$>
	OutletPress	= ASMPartRec<ASM_PART_OUTLET_PRESS$>
	
	Gases = Get_Property(@WINDOW:'.GAS','DEFPROP')
	
	Done = 0
	FOR I = 1 TO COUNT(Gases<1>,@VM) + (Gases<1> NE '')
		IF Gases<1,I> = '' THEN
			Gases<1,I> = Gas
			Done = 1
		END
	UNTIL DONE
	NEXT I 
	
	Ctrls  = @WINDOW:'.RANGE':@RM				; Props  = 'DEFPROP':@RM
	Ctrls := @WINDOW:'.FLOW':@RM				; Props := 'DEFPROP':@RM
	Ctrls := @WINDOW:'.INLET_PRESSURE':@RM		; Props := 'DEFPROP':@RM
	Ctrls := @WINDOW:'.OUTLET_PRESSURE':@RM		; Props := 'DEFPROP':@RM
	Ctrls := @WINDOW:'.GAS'						; Props := 'DEFPROP'
	
	Vals = Range:@RM:Flow:@RM:InletPress:@RM:OutletPress:@RM:Gases
	
	Set_Property(Ctrls,Props,Vals)
	
	Send_Event(@WINDOW:'.GAS','CALCULATE',2)
	
	GOSUB Refresh
	
END

RETURN


RETURN



* * * * * * *
NewOrder:
* * * * * * *
/*
OrderNo = Get_Property(@WINDOW,'ID')

IF NOT(Security_Check('WO Log',WRITE$)) THEN
	Security_Err_Msg('WO Log',WRITE$)
	RETURN
END


IF OrderNo = '' THEN
	NextOrderNo = NextKey('ORDER')
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:NextOrderNo)
END
*/

RETURN


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

obj_Appwindow('DetailReturn')

RETURN


* * * * * * *
NewItem:
* * * * * * * 

/*
CtrlEntID = @WINDOW:'.ORDER_DET'

OrderNo = Get_Property(@WINDOW,'ID')

IF OrderNo = '' THEN RETURN

DetItemNos = Get_Property(CtrlEntID,'ARRAY')<1>	;* Just need the first column

LastItemNo = 0

DetItemCnt = COUNT(DetItemNos,@VM) + (DetItemNos NE '')

FOR I = 1 TO DetItemCnt
	DetItemNo = DetItemNos<1,I>
	IF DetItemNo = '' THEN DetItemNo = 0
	IF DetItemNo > LastItemNo THEN LastItemNo = DetItemNo
NEXT I

Send_Event(@WINDOW,'WRITE')

OrderDetKey = OrderNo:'*':LastItemNo + 1


DetWindow	= 'ORDER_DET'
DetKeys		= OrderDetKey
DefaultRec	= ''
RetKey		= OrderNo
RetWin		= @WINDOW
RetPage		= 1
RetCtrl		= CtrlEntID
RetPos		= 1:@FM:LastItemNo + 1

obj_Appwindow('ViewNewDetail',DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos)

*/

RETURN


* * * * * * *
ItemPC:
* * * * * * * 

RETURN


* * * * * * * 
GasesDC:
* * * * * * *

CtrlEntID = @WINDOW:'.GAS'
CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CurrGases = Get_Property(CtrlEntID,'ARRAY')	;* Existing Gas codes in edit table
CurrGasesTrimmed = ''
FOR I = 1 TO COUNT(CurrGases,@VM) + (CurrGases NE '')
	IF CurrGases<1,I> NE '' THEN
		CurrGasesTrimmed<1,I> = CurrGases<1,I>
	END
NEXT I

CurrGases = CurrGasesTrimmed
CurrGasesPositions	= obj_Popup('CodePosition','REACTOR_GASES':@RM:CurrGases)

Gases = Popup(@WINDOW,'','REACTOR_GASES')

IF Gases = '' THEN RETURN


NewGasesPositions = obj_Popup('CodePosition','REACTOR_GASES':@RM:Gases)

FOR I = 1 TO COUNT(NewGasesPositions,@VM) + (NewGasesPositions NE '')
	NewGasesPosition = NewGasesPositions<1,I>
	Gas = Gases<1,I>
	LOCATE NewGasesPosition IN CurrGasesPositions  BY 'AR' USING @VM SETTING POS ELSE
		CurrGasesPositions	= INSERT(CurrGasesPositions,1,POS,0,NewGasesPosition)
		CurrGases			= INSERT(CurrGases,1,POS,0,Gas)
	END
NEXT I
Set_Property(@WINDOW:'.GAS','DEFPROP',CurrGases)
Send_Event(@WINDOW:'.GAS','CALCULATE',2)
	
GOSUB Refresh

RETURN


************************



OrderNo = Get_Property(@WINDOW,'ID')

CtrlEntID = @WINDOW:'.ORDER_DET'
CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

IF CurrCol = COL$ITEM_NO THEN
	ItemNo = Get_Property(CtrlEntID,'CELLPOS',COL$ITEM_NO:@FM:CurrRow)

	IF OrderNo NE '' AND ItemNo NE '' THEN
		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		
		DetWindow	= 'ORDER_DET'
		DetKeys		= OrderNo:'*':ItemNo
		DefaultRec	= ''
		RetKey		= OrderNo
		RetPage		= 1
		RetCtrl		= CtrlEntID
		RetPos		= CurrPos
		
		oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

		obj_AppWindow('ViewNewDetail',oAParms)
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
	END
END	;* End of ItemNo column

IF CurrCol = COL$QUOTE_NO THEN
	QuoteNo = Get_Property(CtrlEntID,'CELLPOS',COL$QUOTE_NO:@FM:CurrRow)

	IF OrderNo NE '' AND QuoteNo NE '' THEN
		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		
		DetWindow	= 'QUOTE2'
		DetKeys		= QuoteNo
		DefaultRec	= ''
		RetKey		= OrderNo
		RetPage		= 1
		RetCtrl		= CtrlEntID
		RetPos		= CurrPos
		
		oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

		obj_AppWindow('ViewNewDetail',oAParms)
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
	END
END	;* End of QuoteNo column

IF CurrCol = COL$WO_NO THEN
	WONo = Get_Property(CtrlEntID,'CELLPOS',COL$WO_NO:@FM:CurrRow)

	IF OrderNo NE '' AND WONo NE '' THEN
		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		
		NewForm = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
        If NewForm then
            Start_Window('NDW_WO_LOG', @Window, WONo)
        end else
            		
            DetWindow  = 'WO_LOG2'
            DetKeys    = WONo
            DefaultRec = ''
            RetKey     = OrderNo
            RetPage    = 1
            RetCtrl    = CtrlEntID
            RetPos     = CurrPos
            
            oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

            obj_AppWindow('ViewNewDetail',oAParms)
        end

		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
	END
END	;* End of WO column


IF CurrCol = COL$EPI_PN THEN
	EpiPN = Get_Property(CtrlEntID,'CELLPOS',COL$EPI_PN:@FM:CurrRow)
	
	IF OrderNo NE '' AND EpiPN NE '' THEN
		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		
		DetWindow	= 'EPI_PART'
		DetKeys		= EpiPN
		DefaultRec	= ''
		RetKey		= OrderNo
		RetPage		= 1
		RetCtrl		= CtrlEntID
		RetPos		= CurrPos
		
		oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

		obj_AppWindow('ViewNewDetail',oAParms)
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
	END
END	;* End of Epi Part Number column



*/
RETURN


* * * * * * *
CustChar:
* * * * * * *

CtrlName = @WINDOW:'.CUST_NO'

DataIn = Get_Property(CtrlName,'TEXT')

IF LEN(DataIn) > 2 THEN

	ReturnToCtrl = CtrlName

	IF NOT(NUM(DataIn)) THEN 
		Set_Property(CtrlName,'TEXT','')	;* Clear characters input
		Start_Window('COMP_LOOKUP',@WINDOW,DataIn:@VM:'C':@FM:ReturnToCtrl,'','')
	END
END

RETURN


* * * * * * *
LUCustNo:
* * * * * * *

IF NOT(ASSIGNED(Parm1)) THEN FocusControl = ''	ELSE FocusControl = Parm1
IF NOT(ASSIGNED(Parm2)) THEN FocusPos = ''		ELSE FocusPos = Parm2

TypeOver = ''
TypeOver<PSELECT$> = 1

CustNo = Popup(@WINDOW,TypeOver,'CUSTOMER')
IF CustNo NE '' THEN
	obj_Appwindow('LUValReturn',CustNo:@RM:FocusControl:@RM:FocusPos)
END

RETURN


* * * * * * *
LU_DecomReason:
* * * * * * *


IF NOT(ASSIGNED(Parm1)) THEN FocusControl = ''	ELSE FocusControl = Parm1
IF NOT(ASSIGNED(Parm2)) THEN FocusPos = ''		ELSE FocusPos = Parm2

TypeOver = ''
TypeOver<PSELECT$> = 1

DCReason = Popup(@WINDOW,TypeOver,'MFC_DECOMMISSION_CODE')
IF DCReason NE '' THEN
	obj_Appwindow('LUValReturn',DCReason:@RM:FocusControl:@RM:FocusPos)
END

RETURN





RETURN


* * * * * * *
ViewCust:
* * * * * * *

CustNo = Get_Property(@WINDOW:'.CUST_NO','TEXT')
IF CustNo NE '' THEN
	obj_Appwindow('ViewRelated','CUSTOMER_EPI':@RM:CustNo)
END

RETURN







* * * * * *
PrintTemplate:
* * * * * *

OrderNo = Get_Property(@WINDOW:'.ORD_NO','TEXT')

IF OrderNo = '' THEN RETURN

Send_Event(@WINDOW,'WRITE')

*Print_Order(OrderNo)

obj_AppWindow('LoadFormKeys',@WINDOW:@RM:OrderNo)

Set_Property('SYSTEM','FOCUS','VSPRINTER')

RETURN



