
/****** Object:  StoredProcedure [dbo].[AccordionUser]    Script Date: 05/17/2013 17:55:12 ******/
DROP PROCEDURE [dbo].[AccordionUser]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
==================================================
-- Autor:       Francis Antonio Bolaños Arias
-- Fecha:       27/02/2012 16:17:31
-- Descripción: Consultas de Cantones
-- @vOpcion: 0 = Todo,1 = Filtrado, 2 = Elemento, 
-- ===============================================
*/
CREATE PROCEDURE [dbo].[AccordionUser]
(
    @vIdUsuario INT,
    @vIdOpcion  INT,
    @vOrden     INT,
    @vActivar   BIT
)
AS

BEGIN

	DECLARE @Cont INT = 0

	IF @vActivar = 1
	BEGIN
		
		SELECT @Cont = COUNT(*)
		FROM   SECUACCU
		WHERE  IdOperador = @vIdUsuario AND
		       IdOpcion = @vIdOpcion
		
		IF @Cont = 0
		BEGIN
			
			INSERT INTO SECUACCU
			(
				IdOperador,
				IdOpcion,
				Orden
			)
			VALUES(@vIdUsuario, @vIdOpcion, @vOrden)
			
		END
		ELSE
		BEGIN
			
			UPDATE SECUACCU SET Orden = @vOrden WHERE IdOperador = @vIdUsuario AND IdOpcion = @vIdOpcion
			
		END
		
	END
	ELSE
	BEGIN
		
		DELETE FROM SECUACCU
		WHERE IdOperador = @vIdUsuario AND
		      IdOpcion   = @vIdOpcion
		
	END
	
	RETURN
    
END
