CREATE PROCEDURE [dbo].[PRPMO_DELETE_CONTROL](@pCONTROL_ID INT)
AS
BEGIN TRY
	DELETE FROM TBPMO_CONTROL_VALUE WHERE CONTROL_ID = @pCONTROL_ID
	DELETE FROM TBPMO_CONTROL_LANGUAGE WHERE CONTROL_SCREEN_ID IN (SELECT GUID FROM TBPMO_CONTROL_SCREEN WHERE CONTROL_ID = @pCONTROL_ID)
	DELETE FROM TBPMO_CONTROL_SCREEN WHERE CONTROL_ID = @pCONTROL_ID
	DELETE FROM TBPMO_FUNCTION_GENERAL WHERE CONTROL_ID = @pCONTROL_ID
	DELETE FROM TBPMO_CONTROL_IMAGE WHERE CONTROL_ID = @pCONTROL_ID
	DELETE FROM TBPMO_CONTROL WHERE GUID = @pCONTROL_ID
END TRY
BEGIN CATCH   
	PRINT 'FEHLER IN PROCEDURE: ' + CONVERT(VARCHAR(30),ERROR_PROCEDURE()) + ' - ZEILE: ' + CONVERT(VARCHAR(10),ERROR_LINE())
	+ ' - FEHLER-MESSAGE: ' 
    + CONVERT(VARCHAR(500),ERROR_MESSAGE())
END CATCH
GO
CREATE PROCEDURE [dbo].[PRPMO_RECORD_CREATE_WORKFLOWTASKS](@RECORD_ID INTEGER)
AS
BEGIN TRY
	DELETE FROM TBPMO_WORKFLOW_TASK WHERE RECORD_ID = @RECORD_ID
	INSERT INTO TBPMO_WORKFLOW_TASK (RECORD_ID,WF_ID,STATE_ID,ACTIVE) 
	SELECT @RECORD_ID, T.WF_ID,1,1 FROM TBPMO_WORKFLOW_FORM T, TBPMO_RECORD T1 WHERE T.FORM_ID = T1.FORM_ID AND T1.GUID = @RECORD_ID
END TRY
BEGIN CATCH   
	PRINT 'FEHLER IN PROCEDURE: ' + CONVERT(VARCHAR(30),ERROR_PROCEDURE()) + ' - ZEILE: ' + CONVERT(VARCHAR(10),ERROR_LINE())
	+ ' - FEHLER-MESSAGE: ' 
    + CONVERT(VARCHAR(500),ERROR_MESSAGE())
END CATCH
GO

