SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_dis_estadoEvento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_dis_estadoEvento]
GO
CREATE PROCEDURE [reg_dis_estadoEvento]
	@p_id INT
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[estadoEvento] AS [estadoEvento],
		[estadoEvento_codigo] AS [estadoEvento_codigo]
	FROM [dis_estadoEvento]
	WHERE	(id = @p_id)

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_dis_estadoEvento]')) DROP VIEW [dbo].[view_dis_estadoEvento]
GO
CREATE  VIEW [view_dis_estadoEvento] AS
SELECT 	[dis_estadoEvento].[id] AS [id],
		[dis_estadoEvento].[uid] AS [uid],
		[dis_estadoEvento].[eid] AS [eid],
		[dis_estadoEvento].[id_usuario_modifico] AS [id_usuario_modifico],
		[dis_estadoEvento].[id_usuario_creo] AS [id_usuario_creo],
		[dis_estadoEvento].[fechaModificacion] AS [fechaModificacion],
		[dis_estadoEvento].[fechaCreacion] AS [fechaCreacion],
		[dis_estadoEvento].[active] AS [active],
		[dis_estadoEvento].[estadoEvento] AS [estadoEvento],
		[dis_estadoEvento].[estadoEvento_codigo] AS [estadoEvento_codigo],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [dis_estadoEvento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[dis_estadoEvento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[dis_estadoEvento].[id_usuario_creo]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [dis_estadoEvento].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [dis_estadoEvento].active=1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_dis_estadoEventosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_dis_estadoEventosXusuario_modifico]
GO
CREATE PROCEDURE [sel_dis_estadoEventosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_dis_estadoEvento]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_dis_estadoEventosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_dis_estadoEventosXusuario_creo]
GO
CREATE PROCEDURE [sel_dis_estadoEventosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_dis_estadoEvento]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_dis_estadoEventos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_dis_estadoEventos]
GO
CREATE PROCEDURE [sel_dis_estadoEventos]
	
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_dis_estadoEvento]
WHERE (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_dis_estadoEventos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_dis_estadoEventos]
GO
CREATE PROCEDURE [lis_dis_estadoEventos]
	AS
BEGIN
	SELECT id AS id,
[estadoEvento] AS [dis_estadoEvento]
	FROM [dis_estadoEvento]
	WHERE active = 1
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[upd_dis_estadoEvento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_dis_estadoEvento]
GO
CREATE PROCEDURE [upd_dis_estadoEvento]
	@p_id int = null,
		@p_uid varchar(500) = null,
		@p_eid varchar(50) = null,
		@p_id_usuario_modifico int = null,
		@p_id_usuario_creo int = null,
		@p_fechaCreacion smalldatetime = null,
		@p_estadoEvento varchar(300) = null,
		@p_estadoEvento_codigo varchar(100) = null
AS
BEGIN
		UPDATE [dis_estadoEvento]
		SET	[uid] = isnull(@p_uid,[uid]),
			[eid] = isnull(@p_eid,[eid]),
			[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
			[id_usuario_creo] = isnull(@p_id_usuario_creo,[id_usuario_creo]),
			[fechaModificacion] = GETDATE(),
			[estadoEvento] = isnull(@p_estadoEvento,[estadoEvento]),
			[estadoEvento_codigo] = isnull(@p_estadoEvento_codigo,[estadoEvento_codigo])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ins_dis_estadoEvento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_dis_estadoEvento]
GO
CREATE PROCEDURE [ins_dis_estadoEvento]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_estadoEvento varchar(300),
		@p_estadoEvento_codigo varchar(100)
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [dis_estadoEvento]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[estadoEvento],
			[estadoEvento_codigo])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_estadoEvento,
			@p_estadoEvento_codigo)
		SET @v_id = scope_identity()
UPDATE [dis_estadoEvento] set [uid] = [uid] + '_' + convert(varchar(20),@v_id) where [id]=@v_id
SELECT @v_id as id
RETURN @v_id
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[act_dis_estadoEvento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_dis_estadoEvento]
GO
CREATE PROCEDURE [act_dis_estadoEvento]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [dis_estadoEvento]
	SET active=@p_active,
	[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
	[fechaModificacion] = GETDATE()
	WHERE	(id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_dis_estadoEvento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_dis_estadoEvento_m]
GO
CREATE PROCEDURE [reg_dis_estadoEvento_m]
	@p_id INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[estadoEvento] AS [estadoEvento],
		[estadoEvento_codigo] AS [estadoEvento_codigo]
	FROM [dis_estadoEvento]
	WHERE	(id = @p_id)
	AND	(eid LIKE @p_eid+'%')

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_dis_estadoEventosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_dis_estadoEventosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_dis_estadoEventosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_dis_estadoEvento]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_dis_estadoEventosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_dis_estadoEventosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_dis_estadoEventosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_dis_estadoEvento]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_dis_estadoEventos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_dis_estadoEventos_m]
GO
CREATE PROCEDURE [sel_dis_estadoEventos_m]
	@p_eid as varchar (50)='',
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_dis_estadoEvento]
WHERE  (eid like '''+@p_eid+'%'+''' ) AND (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_dis_estadoEventos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_dis_estadoEventos_m]
GO
CREATE PROCEDURE [lis_dis_estadoEventos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[estadoEvento] AS [dis_estadoEvento]
	FROM [dis_estadoEvento]
	WHERE active = 1
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[aud_dis_estadoEvento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_dis_estadoEvento]
GO
CREATE PROCEDURE [aud_dis_estadoEvento]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [dis_estadoEvento].id as id_tabla,
	[dis_estadoEvento].id_usuario_modifico as id_usuario_modifico,
	[dis_estadoEvento].id_usuario_creo as id_usuario_creo,
	[dis_estadoEvento].fechaModificacion as fechaModificacion,
	[dis_estadoEvento].fechaCreacion as fechaCreacion,
	[dis_estadoEvento].active as active,
	[dis_estadoEvento].[estadoEvento] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [dis_estadoEvento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[dis_estadoEvento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[dis_estadoEvento].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_dis_eventosXestadoEvento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_dis_eventosXestadoEvento]
GO
CREATE PROCEDURE [sel_dis_eventosXestadoEvento]
	@p_id_dis_estadoEvento INT
AS
BEGIN
	SELECT 	[dis_evento_estadoEvento].[id] AS [I_id],
		[dis_evento_estadoEvento].[uid] AS [I_uid],
		[dis_evento_estadoEvento].[eid] AS [I_eid],
		[dis_evento_estadoEvento].[fechaModificacion] AS [I_fechaModificacion],
		[dis_evento_estadoEvento].[fechaCreacion] AS [I_fechaCreacion],
		[dis_evento_estadoEvento].[active] AS [I_active],
		[dis_evento_estadoEvento].[evento_estadoEvento] AS [I_evento_estadoEvento],
		[dis_evento_estadoEvento].[fechaHoraRegistro_fh] AS [I_fechaHoraRegistro_fh]
	FROM dis_evento_estadoEvento INNER JOIN dis_evento
	 ON [dis_evento_estadoEvento].[id_evento] = [dis_evento].id
	WHERE	([dis_evento_estadoEvento].[id_estadoEvento]= @p_id_dis_estadoEvento)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ins_dis_evento_estadoEvento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_dis_evento_estadoEvento]
GO
CREATE PROCEDURE [ins_dis_evento_estadoEvento]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_evento_estadoEvento varchar(300),
		@p_id_evento int,
		@p_id_estadoEvento int,
		@p_fechaHoraRegistro_fh smalldatetime
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [dis_evento_estadoEvento]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[evento_estadoEvento],
			[id_evento],
			[id_estadoEvento],
			[fechaHoraRegistro_fh])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_evento_estadoEvento,
			@p_id_evento,
			@p_id_estadoEvento,
			@p_fechaHoraRegistro_fh)
		SET @v_id = scope_identity()
UPDATE [dis_evento_estadoEvento] set [uid] = [uid] + '_' + convert(varchar(20),@v_id) where [id]=@v_id
SELECT @v_id as id
RETURN @v_id
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[upd_dis_evento_estadoEvento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_dis_evento_estadoEvento]
GO
CREATE PROCEDURE [upd_dis_evento_estadoEvento]
	@p_id int = null,
		@p_uid varchar(500) = null,
		@p_eid varchar(50) = null,
		@p_id_usuario_modifico int = null,
		@p_id_usuario_creo int = null,
		@p_fechaCreacion smalldatetime = null,
		@p_evento_estadoEvento varchar(300) = null,
		@p_id_evento int = null,
		@p_id_estadoEvento int = null,
		@p_fechaHoraRegistro_fh smalldatetime = null
AS
BEGIN
		UPDATE [dis_evento_estadoEvento]
		SET	[uid] = isnull(@p_uid,[uid]),
			[eid] = isnull(@p_eid,[eid]),
			[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
			[id_usuario_creo] = isnull(@p_id_usuario_creo,[id_usuario_creo]),
			[fechaModificacion] = GETDATE(),
			[evento_estadoEvento] = isnull(@p_evento_estadoEvento,[evento_estadoEvento]),
			[id_evento] = isnull(@p_id_evento,[id_evento]),
			[id_estadoEvento] = isnull(@p_id_estadoEvento,[id_estadoEvento]),
			[fechaHoraRegistro_fh] = isnull(@p_fechaHoraRegistro_fh,[fechaHoraRegistro_fh])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'dis_estadoEvento'
-----------------------------------10/07/2012 11:27:12 a.m.