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

/*
	Commuter module for CUST_PART (Customer Part Window)
	
	07/27/2010 - 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, 
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
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI, Select_Into



$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU

$INSERT POPUP_EQUATES
$INSERT RTI_STYLE_EQUATES


EQU CRLF$	TO \0D0A\
EQU TAB$	TO \09\


EQU COL$PART_NO			TO 1
EQU COL$PART_DESC		TO 2
EQU COL$PART_PSN		TO 3
EQU COL$PART_REACT_TYPE	TO 4
EQU COL$PART_OLD_DATA	TO 5


ErrTitle = 'Error in Cust_Part Commuter Module(CUST_PART)'
ErrorMsg = ''

Result = ''


BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CLEAR'			; GOSUB Clear
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
			CASE Event = 'READ'				; GOSUB Read
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
	
	CASE EntID = @WINDOW:'.TAB_CONTROL' AND Event = 'CLICK'	; GOSUB TabClick
	
	CASE EntID = @WINDOW:'.LU_CUST_NO' AND Event = 'CLICK'	 		; GOSUB LUCustNo
	*CASE EntID = @WINDOW:'.LU_REACT_TYPE' AND Event = 'CLICK'		; GOSUB LUReactType
	
	
	CASE EntID = @WINDOW:'.CUST_NO' AND Event = 'LOSTFOCUS'			; GOSUB CustNoLF
	
	CASE EntID = @WINDOW:'.PART_NO'
		BEGIN CASE 
			CASE Event = 'POSCHANGED'		; GOSUB PartPC
			CASE Event = 'DBLCLK'			; GOSUB PartDC
		END CASE
		
	
	*CASE EntID = @WINDOW:'.SEND_SPC' AND Event = 'CLICK' 	; GOSUB SendSPC
	
	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)


GOSUB Refresh

RETURN


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


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

GOSUB Refresh

RETURN



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

* 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



* * * * * * *
TabClick:
* * * * * * *

IF Parm1 NE '' THEN
	Page = Parm1
END ELSE
	Page = Get_Property(@WINDOW:'.TAB_CONTROL','VALUE')
END

Set_Property(@WINDOW,'VPOSITION',Page)

RETURN


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

CustNo = Popup(@WINDOW,'','CUSTOMER')

IF CustNo NE '' THEN
	SearchString = 'CUST_NO':@VM:CustNo:@FM
	OPEN 'DICT.CUST_PART' TO DictVar ELSE
		ErrMsg('Unable to open DICT.CUST_PART for index lookup.')
		RETURN
	END
	
	Options = ''
	Flag = ''
	
	BTREE.EXTRACT(SearchString, 'CUST_PART', DictVar, CustPartKeys, Options, flag)
    errCode = ''
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END
	
	IF CustPartKeys = '' THEN
		ErrMsg('No Part Numbers on file for Customer ':QUOTE(CustNo):'.')
		RETURN
	END
	
	TypeOver = ''
	TypeOver<PDISPLAY$> = CustPartKeys
	
	CustPartKeys = Popup(@WINDOW,TypeOver,'CUST_PART')
	
	IF Get_Status(errCode) THEN ErrMsg(errCode)
	
	IF CustPartKeys NE '' THEN
	
		IF INDEX(CustPartKeys,@VM,1) THEN
			Send_Event(@WINDOW,'QBFINIT')
			Set_Property(@WINDOW,'QBFLIST',CustPartKeys)
			Send_Event(@WINDOW,'QBFFIRST')
		END ELSE
			obj_Appwindow('LoadFormKey',@WINDOW:@RM:CustPartKeys)
		END
	END
END



RETURN



* * * * * * *
CustNoLF:
* * * * * * *

CustNo		= Get_Property(@WINDOW:'.CUST_NO','DEFPROP')
CustPartNo	= Get_Property(@WINDOW:'.CUST_PART_NO','DEFPROP')

IF CustNo = ''		THEN RETURN
IF CustPartNo NE '' THEN RETURN

SearchString = 'CUST_NO':@VM:CustNo:@FM
OPEN 'DICT.CUST_PART' TO DictVar ELSE
	ErrMsg('Unable to open DICT.CUST_PART for index lookup.')
	RETURN
END

Options = ''
Flag = ''

BTREE.EXTRACT(SearchString, 'CUST_PART', DictVar, CustPartKeys, Options, flag)

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

IF CustPartKeys = '' THEN
	ErrMsg('No Part Numbers on file for Customer ':QUOTE(CustNo):'.')
	RETURN
END

TypeOver = ''
TypeOver<PDISPLAY$> = CustPartKeys

CustPartKeys = Popup(@WINDOW,TypeOver,'CUST_PART')

IF Get_Status(errCode) THEN ErrMsg(errCode)

IF CustPartKeys NE '' THEN

	IF INDEX(CustPartKeys,@VM,1) THEN
		Send_Event(@WINDOW,'QBFINIT')
		Set_Property(@WINDOW,'QBFLIST',CustPartKeys)
		Send_Event(@WINDOW,'QBFFIRST')
	END ELSE
		obj_Appwindow('LoadFormKeys',@WINDOW:@RM:CustPartKeys)
	END
END


RETURN




* * * * * * *
LUPart:
* * * * * * *

PartNos = Popup(@WINDOW,'','PART')

IF PartNos NE '' THEN
	IF INDEX(PartNos,@VM,1) THEN
		Send_Event(@WINDOW,'QBFINIT')
		Set_Property(@WINDOW,'QBFLIST',PartNos)
		Send_Event(@WINDOW,'QBFFIRST')
	END ELSE
		obj_AppWindow('LoadFormKey',@WINDOW:@RM:PartNos)
	END
END

RETURN


* * * * * * *
LUReactType:
* * * * * * *


ReactType = Popup(@WINDOW,TypeOver,'REACTOR_TYPE')

IF ReactType NE '' THEN
	obj_Appwindow('LUValReturn',ReactType:@RM:@WINDOW:'.REACT_TYPE':@RM:'')
END

RETURN



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

RETURN

* * * * * * *
PartPC:
* * * * * * *

RETURN


* * * * * * *
PartDC:
* * * * * * *

CustNo		= Get_Property(@WINDOW:'.CUST_NO','DEFPROP')
CustPartNo	= Get_Property(@WINDOW:'.CUST_PART_NO','DEFPROP')

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

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

	IF CustNo NE '' AND CustPartNo NE '' THEN
		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		
		DetWindow	= 'PART'
		DetKeys		= PartNo
		DefaultRec	= ''
		RetKey		= CustNo:'*':CustPartNo
		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


RETURN
RETURN

