COMPILE FUNCTION Comm_Dialog_RDS_Query(Method, Parm1)

/*
	Commuter module for Dialog_RDS_Query window.
	
	03/24/2005 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status, ErrMsg
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Msg, Btree.Extract, Comm_Dialog_Order_Find
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Popup, Utility, Key_Sort, Msg, Send_Message

EQU CRLF$	TO \0D0A\

$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT RDS_EQU
$INSERT APPCOLORS

ErrTitle = 'Error in Comm_Dialog_RDS_Query'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'				; GOSUB Create
	CASE Method = 'PerformQuery'		; GOSUB PerformQuery
	CASE Method = 'Cancel'				; GOSUB Cancel
	CASE Method = 'SelectStatusCodes'	; GOSUB SelectStatusCodes
	
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE


RETURN Result


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

obj_AppWindow('Create')

Set_Property(@WINDOW:'.USER_ID','INVALUE',@USER4)


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

* Turn edit table symbolic column backgrounds to green

stat = Send_Message(@WINDOW:'.CUST_INFO','COLOR_BY_POS',2,0,GREEN$)	;* Turn names column all rows green
stat = Send_Message(@WINDOW:'.CURR_STATUS','COLOR_BY_POS',2,0,GREEN$)	;* Turn names column all rows green

RETURN


* * * * * * *
SelectStatusCodes:
* * * * * * *

ReturnCtrl = @WINDOW:'.CURR_STATUS'

TypeOver = ''
TypeOver<PSELECT$> = 2	;* Multiple select

StatusCodes = Popup(@WINDOW,TypeOver,'RDS_CURR_STATUS')

IF StatusCodes NE '' THEN
	ExistingArray = ''
	FOR I = 1 TO COUNT(StatusCodes,@VM) + (StatusCodes NE '') + 1
		ExistingArray<1,I> = StatusCodes<1,I>
		ExistingArray<2,I> = OCONV(StatusCodes<1,I>,'[RDS_CURR_STATUS_CONV]')
	NEXT I
	
	Set_Property(@WINDOW:'.CURR_STATUS','DEFPROP',ExistingArray)
END

GOSUB Refresh

RETURN


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


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

End_Dialog(@WINDOW,'Cancel')

RETURN



* * * * * * *
PerformQuery:
* * * * * * *

OPEN 'DICT.RDS' TO DictRDSTable ELSE
   ErrMsg( 'Unable to open DICT.RDS...' )
   End_Dialog( @WINDOW,'')
END

WONos			= Get_Property(@WINDOW:'.WO','ARRAY')<1>
Reactors		= Get_Property(@WINDOW:'.REACTORS','ARRAY')<1>
PSNs			= Get_Property(@WINDOW:'.PSN_NOS','ARRAY')<1>
QuoteNos		= Get_Property(@WINDOW:'.QUOTE_NOS','ARRAY')<1>
PONos			= Get_Property(@WINDOW:'.PO','ARRAY')<1>
PartNos			= Get_Property(@WINDOW:'.PART_NUM','ARRAY')<1>
LotNos			= Get_Property(@WINDOW:'.LOT_NUM','ARRAY')<1>
CurrStatusCds	= Get_Property(@WINDOW:'.CURR_STATUS','ARRAY')<1>
CustIds			= Get_Property(@WINDOW:'.CUST_INFO','ARRAY')<1>

SWAP @VM:@VM WITH '' IN WONos			;	IF WONos[-1,1] = @VM			THEN WONos[-1,1] = ''
SWAP @VM:@VM WITH '' IN Reactors		;	IF Reactors[-1,1] = @VM			THEN Reactors[-1,1] = ''
SWAP @VM:@VM WITH '' IN PSNs			;	IF PSNs[-1,1] = @VM				THEN PSNs[-1,1] = ''
SWAP @VM:@VM WITH '' IN QuoteNos		;	IF QuoteNos[-1,1] = @VM			THEN QuoteNos[-1,1] = ''
SWAP @VM:@VM WITH '' IN PONos			;	IF PONos[-1,1] = @VM			THEN PONos[-1,1] = ''
SWAP @VM:@VM WITH '' IN PartNos			;	IF PartNos[-1,1] = @VM			THEN PartNos[-1,1] = ''
SWAP @VM:@VM WITH '' IN LotNos			;	IF LotNos[-1,1] = @VM			THEN LotNos[-1,1] = ''
SWAP @VM:@VM WITH '' IN CurrStatusCds	;	IF CurrStatusCds[-1,1] = @VM	THEN CurrStatusCds[-1,1] = ''
SWAP @VM:@VM WITH '' IN CustIDs			;	IF CustIDs[-1,1] = @VM			THEN CustIds[-1,1] = ''

DateInFrom		= Get_Property(@WINDOW:'.DATE_IN_FROM','TEXT')
DateInThru		= Get_Property(@WINDOW:'.DATE_IN_THRU','TEXT')
DateOutFrom		= Get_Property(@WINDOW:'.DATE_OUT_FROM','TEXT')
DateOutThru		= Get_Property(@WINDOW:'.DATE_OUT_THRU','TEXT')
TimeInFrom		= Get_Property(@WINDOW:'.TIME_IN_FROM','TEXT')
TimeInThru		= Get_Property(@WINDOW:'.TIME_IN_THRU','TEXT')
TimeOutFrom		= Get_Property(@WINDOW:'.TIME_OUT_FROM','TEXT')
TimeOutThru		= Get_Property(@WINDOW:'.TIME_OUT_THRU','TEXT')

SearchStr = ''

IF WONos			THEN SearchStr<-1> = 'WO':@VM:WONos
IF Reactors			THEN SearchStr<-1> = 'REACTOR':@VM:Reactors
IF PSNs				THEN SearchStr<-1> = 'PROD_SPEC_ID':@VM:PSNs
IF QuoteNos			THEN SearchStr<-1> = 'QUOTE_NO':@VM:QuoteNos
IF PONos			THEN SearchStr<-1> = 'PO':@VM:PONos
IF PartNos			THEN SearchStr<-1> = 'PART_NUM':@VM:PartNos
IF LotNos			THEN SearchStr<-1> = 'LOT_NUM':@VM:LotNos
IF CurrStatusCds	THEN SearchStr<-1> = 'CURR_STATUS':@VM:CurrStatusCds
IF CustIds			THEN SearchStr<-1> = 'CUST_NO':@VM:CustIds


IF DateInFrom AND DateInThru THEN
	SearchStr<-1> = 'DATE_IN':@VM:DateInFrom:'...':DateInThru
END ELSE
	IF DateInFrom THEN SearchStr<-1> = 'DATE_IN':@VM:'>=':DateInFrom
	IF DateInThru THEN SearchStr<-1> = 'DATE_IN':@VM:'<=':DateInThru
END

IF DateOutFrom and DateOutThru THEN
    SearchStr<-1> = 'DATE_OUT':@VM:DateOutFrom:'...':DateOutThru
END ELSE
	IF DateOutFrom THEN SearchStr<-1> = 'DATE_OUT':@VM:'>=':DateOutFrom
	IF DateOutThru THEN SearchStr<-1> = 'DATE_OUT':@VM:'<=':DateOutThru
END

IF TimeInFrom and TimeInThru THEN
    SearchStr<-1> = 'TIME_IN':@VM:TimeInFrom:'...':TimeInThru
END ELSE
	IF TimeInFrom THEN SearchStr<-1> = 'TIME_IN':@VM:'>=':TimeInFrom
	IF TimeInThru THEN SearchStr<-1> = 'TIME_IN':@VM:'<=':TimeInThru
END

IF TimeOutFrom and TimeOutThru THEN
    SearchStr<-1> = 'TIME_OUT':@VM:TimeOutFrom:'...':TimeOutThru
END ELSE
	IF TimeOutFrom THEN SearchStr<-1> = 'TIME_OUT':@VM:'>=':TimeOutFrom
	IF TimeOutThru THEN SearchStr<-1> = 'TIME_OUT':@VM:'<=':TimeOutThru
END

IF SearchStr THEN
    SearchStr := @FM
    Void = Utility( 'CURSOR', 'H' )
    * do a btree.extract
    Btree.Extract( SearchStr, 'RDS', DictRDSTable, RDSNos, '', Flag )
    IF Get_Status(errCode) THEN
    	ErrMsg(errCode)
    	End_Dialog( @WINDOW,'')
    END
    
    IF RDSNos THEN
       CONVERT @VM TO @FM IN RDSNos
       RDSNos = Key_Sort( RDSNos, 'RDS', 'CUST_NAME':@fm:'WO':@fm:'RUN_ORDER_NUM', 0 )
       End_Dialog( @WINDOW, RDSNos )
    END ELSE
       MsgInfo = ''
       MsgInfo<mtext$> = 'No records found meeting your criteria...' 
       MsgInfo<micon$> = '!'
       Void = msg( '', MsgInfo )
    END
    Void = utility( 'CURSOR', 'A' )
END ELSE
    MsgInfo = ''
    MsgInfo<mtext$> = 'You have not entered any search criteria...' 
    MsgInfo<micon$> = '!'
    Void = msg( '', MsgInfo )
END

RETURN


