
! script name: vprocesstable.d/moverow
! var_topic: move a row in the process table

!A
!A NAME:
!A
!A 	Modify Process Table: Move Row	VARIATIONAL
!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 Table$[256]
DIM Data_name1$[256],Work_zone1$[256]
DIM Data_name2$[256],Work_zone2$[256]

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave
DEG

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 ValidDependency(Table1) THEN Element_loop
IF NOT IsEntityDependent(Table1) THEN
	Stat= MessageFileBox("/usr/weber/database/messages/nonvdmprtbl","ERROR")
	GOTO Element_loop
END IF
Stat= EntityNameCheck(Table1,Table$)
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("Amo process table",R1,1,Data_name1$)
Stat= GetTableEntryStr("Amo process table",R1,2,Work_zone1$)

Pick_second:stat= SetInputFormat("n4a1",",E,")
Table2=PickEntity("INSERT BEFORE WHICH ROW, End ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="E" THEN
	Is_end= 1
ELSE
	Is_end= 0
	IF NOT ValidGeometry(Table2) THEN Pick_second
	Stat= EntityNameCheck(Table2,Table$)
	IF Table$<>"Amo process table" THEN Pick_second

	IF NOT AreEntitiesSame(Table1,Table2) THEN Pick_second

	T1= LastPickPara
	R2=TableParaRow(Table1,T1)
	IF R2=1 THEN Pick_second
	Stat= PlotDataTable(Table1,R2,0,Second_pen)
	Stat= GetTableEntryStr("Amo process table",R2,1,Data_name2$)
	Stat= GetTableEntryStr("Amo process table",R2,2,Work_zone2$)
	IF R1= R2 THEN Element_loop
	IF R1+1= R2 THEN Element_loop
END IF

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

Stat= EraseEntity("Amo process table")
RecordFunctionOn
Stat= RecordDescr("TABLE: Move process table row")
V1=StringConstant("Amo process table")
V2=StringConstant(Data_name1$)
V3=StringConstant(Work_zone1$)
IF NOT Is_end THEN
V4=StringConstant(Data_name2$)
V5=StringConstant(Work_zone2$)
END IF
E1= FindNamedEntity(V1)
V6= FreeParameter("First row",ProcessTableRow(E1,V2,V3))
IF Is_end THEN
V7= FreeParameter("Second row",-1)
ELSE
V7= FreeParameter("Second row",ProcessTableRow(E1,V4,V5))
END IF
Stat= MoveTableRow(E1,V6,V7)
RecordFunctionOn
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity("Amo process table")

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Element_loop

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