
! script name: processtable.d/insertevent
! topic: insert event into process table

!A
!A NAME:
!A
!A 	Insert Event into Process Table
!A
!A DESCRIPTION:
!A
!A	Place an event into the process table.
!A
!B INSTRUCTIONS:
!B
!B	CHOOSE EVENT TO BE INSERTED: Pick the event to insert.
!B
!B	INSERT BEFORE WHICH ROW, End, New:  Choose the row that
!B		will be after the event.  Choose end to append
!B		the event.  Choose new to pick another event.
!B
!# see also - htdocs/help.d/datatables.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: insert rows ")

DIM Answer$[256]
DIM A$[256]
DIM Destination$[256]
DIM Name$[256],Name2$[256]
DIM Data_name1$[256],Work_zone1$[256]
DIM A$[256]

IF NOT ValidGeometry("Amo process table") THEN Leave
IF IsEntityDependent("Amo process table") THEN Leave

WsEventData= 12345
Start:!
Stat=UserSelectBox("EVENTS","SELECTED EVENT",WsEventData,WsUserSelect)
IF Stat=1 THEN Leave

Stat=SetInputFormat("a99","")
Stat=GetValue("CHOOSE EVENT TO BE INSERTED",Name$)
IF (ExitScript(Destination$)) THEN Leave
IF Name$= "CANCEL" THEN Leave

Event=FindUserData(Name$,WsEventData)
IF NOT ValidGeometry(Event) THEN Start

ActivateUndo
Element_loop:!
Stat= SetInputFormat("a1",",E,N,")
Table1=PickEntity("INSERT BEFORE WHICH ROW, End, New ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN Start
Is_end= (Answer$="E")
IF NOT Is_end THEN
	IF NOT ValidGeometry(Table1) THEN Element_loop
	IF NOT AreEntitiesSame(Table1,"Amo process table") THEN Element_loop
	IF IsEntityDependent(Table1) THEN
		Stat= MessageFileBox("/usr/weber/database/messages/vdmprtbl","ERROR")
		GOTO Element_loop
	END IF

	T1= LastPickPara
	R1=TableParaRow(Table1,T1)
	IF R1=1 THEN Element_loop

	Stat= GetTableEntryStr(Table1,R1,1,Data_name1$)
	Stat= GetTableEntryStr(Table1,R1,2,Work_zone1$)
ELSE
	Table1= FindNamedEntity("Amo process table")
END IF

High_val= 0
Num_rows= NumberTableRows(Table1)
FOR J= 2 TO Num_rows
	EntData= AmoTaskTableEvent(Table1,J)
	IF ValidGeometry(EntData) THEN
		IF AreEntitiesSame(EntData,Event) THEN
			Stat= GetTableEntryStr(Table1,J,2,Answer$)
			K= POS(Answer$,"#")
			IF K THEN
				Curr_val= VAL(Answer$[K+1])
				IF Curr_val> High_val THEN High_val= Curr_val
			END IF
		END IF
	END IF
NEXT J
Inst_name$= "Instance #"&VAL$(High_val+1)

ActivateUndo
Stat= AdvanceUndoNumber("insert event")
Stat= AddItemToUndo(WsUBModifyMode,Table1)

Stat= EraseEntity(Table1)
IF Is_end THEN
Stat= ReDimTableRows(Table1,1,1)
Row= NumberTableRows(Table1)
ELSE
Row=ProcessTableRow(Table1,Data_name1$,Work_zone1$)
Stat=InsertTableRows(Table1,Row,1)
END IF

Stat=InsertIntoTable(Table1,Name$,Row,1)
Stat=InsertIntoTable(Table1,Inst_name$,Row,2)
Stat= PlotEntity(Table1)

IF Is_end THEN Start
GOTO Element_loop

Leave:!
Stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
