
! script name: processtable.d/moverow
! topic: move a row in the process table

!A
!A NAME:
!A
!A 	Process Table Move Row
!A
!A DESCRIPTION:
!A
!A 	This script moves a row in the process table.
!A
!B INSTRUCTIONS:
!B
!B	PICK ROW TO BE MOVED: Pick the row to be moved.
!B
!B	INSERT BEFORE WHICH ROW, End: Pick the row that will be after
!B 		the moved row.  Choose End to append the row.
!B
!# see also - htdocs/help.d/datatables.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: move process table row ")

DIM Answer$[256],Destination$[256]
DIM A$[256]
DIM Data_name1$[256],Work_zone1$[256]
DIM Data_name2$[256],Work_zone2$[256]

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

First_pen=3
Second_pen=4
ActivateUndo

Element_loop:!
Stat= SetInputFormat("n4","")
Table1=PickEntity("PICK ROW TO BE MOVED")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Table1) THEN Element_loop
IF IsEntityDependent(Table1) THEN
	Stat= MessageFileBox("/usr/weber/database/messages/vdmprtbl","ERROR")
	GOTO Element_loop
END IF
IF NOT AreEntitiesSame(Table1,"Amo process table") THEN Element_loop

T1= LastPickPara
R1=TableParaRow(Table1,T1)
IF R1=1 THEN Element_loop
Stat= PlotDataTable(Table1,R1,0,First_pen)

Stat= GetTableEntryStr(Table1,R1,1,Data_name1$)
Stat= GetTableEntryStr(Table1,R1,2,Work_zone1$)

Pick_second:stat= SetInputFormat("n4a1",",E,")
Table2=PickEntity("INSERT BEFORE WHICH ROW, End ",Answer$)
IF ExitScript(Destination$) THEN Leave
Is_end= (Answer$="E")
IF NOT Is_end THEN
	IF NOT ValidGeometry(Table2) THEN Pick_second
	IF IsEntityDependent(Table2) THEN Pick_second
	IF NOT AreEntitiesSame(Table1,Table2) THEN Pick_second

	T1= LastPickPara
	R2=TableParaRow(Table1,T1)
	IF R2=1 THEN Pick_second
	IF R1=R2 OR R1+1=R2 THEN
		GOTO Element_loop
		Stat= PlotEntity(Table1)
	END IF

	Stat= PlotDataTable(Table1,R2,0,Second_pen)
	Stat= GetTableEntryStr(Table1,R2,1,Data_name2$)
	Stat= GetTableEntryStr(Table1,R2,2,Work_zone2$)
ELSE
	Table1= FindNamedEntity("Amo process table")
END IF

ActivateUndo
Stat= AdvanceUndoNumber("move row")
Stat= AddItemToUndo(WsUBModifyMode,Table1)
Stat= AddItemToUndo(WsUBModifyMode,Table2)

Stat= EraseEntity(Table1)
Row1= ProcessTableRow(Table1,Data_name1$,Work_zone1$)
IF Is_end THEN
	Row2= -1
ELSE
	Row2= ProcessTableRow(Table1,Data_name2$,Work_zone2$)
END IF
Stat= MoveTableRow(Table1,Row1,Row2)
Stat= PlotEntity(Table1)

GOTO Element_loop

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