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

/*
	Commuter module for DIALOG_REACT_MODE_HISTORY  window
	
	01/26/2010 - 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,SRP_EditTable_Manager 
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, Create_Note,Print_ReactModeLog

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI



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

$INSERT LOGICAL


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

EQU COL$REACT_NO		TO 1
EQU COL$MODE			TO 2
EQU COL$START_DTM		TO 3
EQU COL$START_USER		TO 4
EQU COL$START_RL_ID		TO 5
EQU COL$START_RU_ID		TO 6
EQU COL$STOP_DTM		TO 7
EQU COL$STOP_USER		TO 8
EQU COL$STOP_RL_ID		TO 9
EQU COL$STOP_RU_ID		TO 10


ErrTitle = 'Error in Dialog_React_Mode_History'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
			
		END CASE
		
	CASE EntID = @WINDOW:'.CLOSE_BUTTON' AND Event = 'CLICK' 	; GOSUB Close
	CASE EntID = @WINDOW:'.PRINT_BUTTON' AND Event = 'CLICK' 	; GOSUB Print
		
	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)

ReactNo = Parm1<1>
StopDt	= Parm1<2>


ReactNo = 21
IF NUM(StopDt) THEN
	StopDt = OCONV(StopDt,'D4')
END

Set_Property(@WINDOW,'@REACT_NO',ReactNo)

GOSUB Setup_OLE_EditTable

IF StopDt NE '' THEN
	Title = 'Reactor ':ReactNo:' Mode History Since ':StopDt
	SelectSent = 'SELECT REACT_MODE WITH REACT_NO = ':QUOTE(ReactNo):'AND WITH START_DT >= ':QUOTE(StopDt):' BY-DSND START_DTM'	
END ELSE
	Title = 'Reactor ':ReactNo:' Mode History'
	SelectSent = 'SELECT REACT_MODE WITH REACT_NO = ':QUOTE(ReactNo):' BY-DSND START_DTM'
END

Set_Property(@WINDOW,'TEXT',Title)

OPEN 'DICT.REACT_MODE' TO @DICT ELSE
	ErrMsg('Unable to open DICT.REACT_MODE for index lookup')
	RETURN
END

OPEN 'REACT_MODE' TO FileIn ELSE
	ErrMsg('Unable to open REACT_MODE for index lookup')
	RETURN
END

RList(SelectSent,5,'','','')

SelCnt = @RECCOUNT

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

RMKeys		= ''
Done		= 0
DispList	= ''
RecCnt 		= 0

Def = ""
Def<MCAPTION$> = "Loading Mode Changes..."
Def<MTYPE$ > = "GC"
Def<MEXTENT$> = SelCnt
Def<MTEXTWIDTH$> = 600

MsgUp = Msg(@WINDOW, Def)

LOOP
	READNEXT RMKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	READ RMRec FROM FileIn,RMKey THEN
		StartDTM = FIELD(RMKey,'*',2)
		
		DispLine  = RMKey[1,'*']
		DispLine<1,COL$MODE>		= OCONV(RMRec<REACT_MODE_MODE$>,'[REACT_MODE_CONV')
		DispLine<1,COL$START_DTM>	= OCONV(StartDTM,'DT4/^S')
		DispLine<1,COL$START_USER>	= RMRec<REACT_MODE_START_USER$>
		DispLine<1,COL$START_RL_ID>	= RMRec<REACT_MODE_START_RL_ID$>
		DispLine<1,COL$START_RU_ID>	= RMRec<REACT_MODE_START_RU_ID$>
		DispLine<1,COL$STOP_DTM>	= OCONV(RMRec<REACT_MODE_STOP_DTM$>,'DT4/^S')
		DispLine<1,COL$STOP_USER>	= RMRec<REACT_MODE_STOP_USER$>
		DispLine<1,COL$STOP_RL_ID>	= RMRec<REACT_MODE_STOP_RL_ID$>
		DispLine<1,COL$STOP_RU_ID>	= RMRec<REACT_MODE_STOP_RU_ID$>
		
		DispList<-1> = DispLine
	END
WHILE Msg(@WINDOW, MsgUp, RecCnt, MSGINSTUPDATE$)
REPEAT

dummy = Msg(@WINDOW, MsgUp) ;* take down the gauge

*Set_Property(@WINDOW:'.MODE_HIST','LIST',DispList)

Set_Property(@WINDOW:'.OLE_EDT_MODE_HISTORY','LIST',DispList)

ListCnt = COUNT(DispList,@FM) + (DispList NE '')

FOR I = 1 TO ListCnt
	IF Mod(I, 2) = 1 THEN
		stat = Send_Message(@WINDOW:'.MODE_HIST','COLOR_BY_POS',0,I,RCV_BLUE$)
	END ELSE
		stat = Send_Message(@WINDOW:'.MODE_HIST','COLOR_BY_POS',0,I,WHITE$)
	END
NEXT I

RETURN


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

End_Dialog(@WINDOW)

RETURN



* * * * * * *
Print:
* * * * * * *

ReactNo = Get_Property(@WINDOW,'@REACT_NO')

Print_ReactModeLog(ReactNo)

RETURN



* * * * * * *
Setup_OLE_EditTable:
* * * * * * *


Ctrl = @WINDOW:'.OLE_EDT_MODE_HISTORY'

ArrayDimension = 10

TitleList = ""								; ColWidths = ''			; ColAlignments = ''			; VirtualPos = ''
TitleList<1,1> = 'React No'					; ColWidths<1>	= 100		; ColAlignments<1> = 'C'		; VirtualPos<1> = 1
TitleList<1,2> = 'Mode'						; ColWidths<2>	= 150		; ColAlignments<2> = 'L'		; VirtualPos<2> = 2
TitleList<1,3> = "Start DTM"				; ColWidths<3>	= 150		; ColAlignments<3> = 'C'		; VirtualPos<3> = 3
TitleList<1,4> = "Start User"				; ColWidths<4>	= 100		; ColAlignments<4> = 'L'		; VirtualPos<4> = 4
TitleList<1,5> = 'React Log ID'				; ColWidths<5>	= 50		; ColAlignments<5> = 'C'		; VirtualPos<5> = 5
TitleList<1,6> = 'React Util ID'			; ColWidths<6>	= 50		; ColAlignments<6> = 'C'		; VirtualPos<6> = 6
TitleList<1,7> = "Stop DTM"					; ColWidths<7>	= 100		; ColAlignments<7> = 'C'		; VirtualPos<7> = 7
TitleList<1,8> = "Stop User"				; ColWidths<8>	= 100		; ColAlignments<8> = 'L'		; VirtualPos<8> = 8
TitleList<1,9> = "React Log ID"				; ColWidths<9>	= 50		; ColAlignments<9> = 'C'		; VirtualPos<9> = 9
TitleList<1,10> = "React Util ID"			; ColWidths<10>	= 50		; ColAlignments<10> = 'C'		; VirtualPos<10> = 10

Set_Property(Ctrl,'OLE.BorderType', 'XP Flat')
Set_Property(Ctrl,'OLE.WorkspaceBkColor','Window')
Set_Property(Ctrl,'OLE.Dimension',10:@FM:0)					;* changed
Set_Property(Ctrl,'OLE.RowsToRecords',1)					;* changed
Set_Property(Ctrl,'OLE.QuickTabOut',Yes$)
*Set_Property(Ctrl,'OLE.CellEditMode[All; All]','Edit')
Set_Property(Ctrl,'OLE.AutoColors','Row(Auto; Auto; Auto; 3DFace L=95; 1)')		;* Automatically alternate the color of every other row. This makes different rows easier to identify, especially since we have set 2 RowsToRecord.

Set_Property(Ctrl,'OLE.SelectionStyle',@VM:'S L=80':@FM:@VM:'S L=95')			;* Automatically highlight the current row with one color and highlight the current row with another color.
	
Set_Property(Ctrl,'OLE.TitleList',TitleList)
   
*Set_Property(Ctrl,'OLE.HeaderRow[1]', @FM:No$)									;* Hide the header row

Set_Property(Ctrl, "OLE.HeaderRow[All]", "19":@FM:"":@FM:Yes$)					;* Make all column header rows to be 19 pixels tall and unable to be resized.
Set_Property(Ctrl, "OLE.DataRow[All]", "19":@FM:"":@FM:No$)						;* Make all data rows to be 19 pixels tall and unable to be resized.

NumColumns = Count(ColWidths, @FM) + (ColWidths NE "")
CharPos = 1
FOR ColPos = 1 TO NumColumns
	ColWidth = ColWidths<ColPos>
	Begin Case
		Case Num(ColWidth)      ;   Set_Property(Ctrl, "OLE.DataColumn[":ColPos:"]", ColWidth)
		Case ColWidth EQ "A"    ;   Set_Property(Ctrl, "OLE.DataColumn[":ColPos:"]", @FM:@FM:@FM:Yes$) ;* Set column to autosized
	End Case
NEXT ColPos

Set_Property(Ctrl, "OLE.HeaderColumn[1]", "20":@FM:"":@FM:No$)                     ;* Make the row header column to be 20 pixels wide and unable to be resized.
Set_Property(Ctrl, "OLE.AutoNumbers", "I":@VM:1)                                   ;* Make the row header column auto number with an integer starting with 1.



NumColumns = Count(ColAlignments, @FM) + (ColAlignments NE "")
CharPos = 1
FOR ColPos = 1 TO NumColumns
	ColAlignment = ColAlignments<ColPos>
	IF Len(ColAlignment) THEN Set_Property(Ctrl, "OLE.CellAlignment[":ColPos:"; All]", @FM:ColAlignment)
NEXT ColPos

Set_Property(Ctrl, "@POS", VirtualPos)

Set_Property(Ctrl, "@CLEARFILL", 1)



CellConvInfo = "MD0":@FM:"MD0,":@FM:"'@DATA' is not a valid integer":@FM:@FM:@FM:Yes$
Set_Property(Ctrl, "OLE.CellConv[COL$REACT_NO; All]", CellConvInfo)

CellConvInfo = "":@FM:"[REACT_MODE_CONV]":@FM:@FM:@FM:@FM:Yes$
Set_Property(Ctrl, "OLE.CellConv[COL$MODE; All]", CellConvInfo)

CellConvInfo = "DT":@FM:"DT4/^S":@FM:"'@DATA' is not a valid Date-Time":@FM:@FM:@FM:Yes$
Set_Property(Ctrl, "OLE.CellConv[COL$START_DTM; All]", CellConvInfo)


CellConvInfo = "DT":@FM:"DT4/^S":@FM:"'@DATA' is not a valid Date-Time":@FM:@FM:@FM:Yes$
Set_Property(Ctrl, "OLE.CellConv[COL$STOP_DTM; All]", CellConvInfo)
/*
Qualify = ""
Qualify<1> = 1	; // Enable OLE event
Qualify<4> = 2	; // Synchronous event processing

Send_Message(Ctrl, "QUALIFY_EVENT", "ALL_OLES", Qualify)

*/
Send_Message(Ctrl, "OLE.Clear", 1)												; // Blank out edittable and fill up with empty rows.

RETURN



