------------------------------------------------------------------------------------------------------
-- Utenti
------------------------------------------------------------------------------------------------------
carlo.viviani@gmail.com	Viviani	Carlo	carlo.viviani@gmail.com	BM5U64BBGG4ULA08NL6X	1001	True	IT	False
ceo@steamware.net	 CEO	USER	ceo@steamware.net	BM5U64BBGG4ULA08NL6X	1001	True	IT	False
giancarlo@steamware.net	Rottoli	Giancarlo	giancarlo@steamware.net	BM5U64BBGG4ULA08NL6X	1001	True	IT	False
johnny.colleoni@cms.it	Colleoni	Johnny	johnny.colleoni@cms.it	3QZA06RKIH5A0WT7SPYD	1001	True	IT	False
marco.labaria@cms.it	Labaria	Marco	marco.labaria@cms.it	B2A3IZXOES1S503C4H7L	1001	True	IT	False
mario.volpi@cms.it	Volpi	Mario	mario.volpi@cms.it	1RZGII6IW2NJJF95KGN7	1001	True	IT	False
michele.zanchi@cms.it	Zanchi	Michele	michele.zanchi@cms.it	ES34RWTC5NZ0LYUVRKUL	1001	True	IT	False
piercarlo.moreschi@cms.it	Moreschi	Piercarlo	piercarlo.moreschi@cms.it	9M7A7RRUC85EUFXYAJVP	1001	True	IT	False
samuele@steamware.net	Locatelli	Samuele	samuele@steamware.net	BM5U64BBGG4ULA08NL6X	1001	True	IT	False
santo.benintendi@cms.it	Benintendi	Santo	santo.benintendi@cms.it	91OLLIZGKBUUPZL16ZRQ	1001	True	IT	False
simone.baroni@cms.it	Baroni	Simone	simone.baroni@cms.it	HLNOX02RAELTZKIGEZQE	1001	True	IT	False
valerio.benintendi@cms.it	Benintendi	Valerio	valerio.benintendi@cms.it	M0DIMN8SLHQ5AP3X48BT	1001	True	IT	False
vittorio.paninforni@cms.it	Paninforni	Vittorio	vittorio.paninforni@cms.it	57SF2P1GF7O2E7SQW0C7	1001	True	IT	False


------------------------------------------------------------------------------------------------------
-- Diritti
------------------------------------------------------------------------------------------------------
carlo.viviani@gmail.com	X999	CMS_SC	CapoGruppo	
carlo.viviani@gmail.com	X999	CMS_SC	CapoOfficina	
carlo.viviani@gmail.com	X999	CMS_SC	SuperAdmin	
carlo.viviani@gmail.com	X999	CMS_SC	User	
ceo@steamware.net	X999	CMS_SC	User	
giancarlo@steamware.net	X999	CMS_SC	CapoGruppo	
giancarlo@steamware.net	X999	CMS_SC	CapoOfficina	
giancarlo@steamware.net	X999	CMS_SC	SuperAdmin	
giancarlo@steamware.net	X999	CMS_SC	User	
johnny.colleoni@cms.it	X999	CMS_SC	User	
marco.labaria@cms.it	X999	CMS_SC	User	
mario.volpi@cms.it	X999	CMS_SC	CapoGruppo	
mario.volpi@cms.it	X999	CMS_SC	CapoOfficina	
mario.volpi@cms.it	X999	CMS_SC	CqSetSC	
mario.volpi@cms.it	X999	CMS_SC	User	
michele.zanchi@cms.it	X999	CMS_SC	User	
piercarlo.moreschi@cms.it	X999	CMS_SC	User	
samuele@steamware.net	X999	CMS_SC	CapoGruppo	
samuele@steamware.net	X999	CMS_SC	CapoOfficina	
samuele@steamware.net	X999	CMS_SC	CqSetSC	
samuele@steamware.net	X999	CMS_SC	SuperAdmin	
samuele@steamware.net	X999	CMS_SC	User	
santo.benintendi@cms.it	X999	CMS_SC	User	
simone.baroni@cms.it	X999	CMS_SC	User	
valerio.benintendi@cms.it	X999	CMS_SC	CapoGruppo	
valerio.benintendi@cms.it	X999	CMS_SC	CqSetSC	
valerio.benintendi@cms.it	X999	CMS_SC	User	
vittorio.paninforni@cms.it	X999	CMS_SC	User

------------------------------------------------------------------------------------------------------
-- Vocabolario
------------------------------------------------------------------------------------------------------
exec voc.stp_insNewLemma 'AuthUserBaseCollaudi','Accesso Utenti Collaudo'
exec voc.stp_insNewLemma 'AuthUserBaseTitle','Istruzioni'
exec voc.stp_insNewLemma 'AuthUserBaseInstr01','Inserendo Cognome e Nome gli utenti collaudatori registrati possono accedere alla funzionalità di inserimento dati di Collaudo'
exec voc.stp_insNewLemma 'btnAuthUserBase','Effettua Login'
exec voc.stp_insNewLemma 'ErrorEAK04','[ErrorEAK04] Attenzione: profilo utente non corretto per accesso Collaudatore'
exec voc.stp_insNewLemma 'ErrorEAK05','[ErrorEAK05] Attenzione:  email non trovata, prego contattare amministratore!'
exec voc.stp_insNewLemma 'UserData','Dati Utente'
exec voc.stp_insNewLemma 'UserRights','Permessi Utente'
exec voc.stp_insNewLemma 'DevicesList','Elenco Devices Autorizzati'
exec voc.stp_insNewLemma 'UserAuthOk','User'
exec voc.stp_insNewLemma 'Logout','Logout'




------------------------------------------------------------------------------------------------------
-- UserParam
------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[UserParam]    Script Date: 29/10/2015 17:24:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[UserParam](
	[Email] [nvarchar](250) NOT NULL,
	[ParName] [nvarchar](50) NOT NULL,
	[ParValue] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_UserParam] PRIMARY KEY CLUSTERED 
(
	[Email] ASC,
	[ParName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[UserParam] ADD  CONSTRAINT [DF_Table_1_email]  DEFAULT ('@') FOR [Email]
GO

ALTER TABLE [dbo].[UserParam] ADD  CONSTRAINT [DF_UserParam_ParValue]  DEFAULT ('') FOR [ParValue]
GO


------------------------------------------------------------------------------------------------------
-- stored!
------------------------------------------------------------------------------------------------------
-- =============================================
-- Author:		S.E. Locatelli
-- Create date: 2015.10.29
-- Description:	recupera parametro utente da key
-- =============================================
CREATE PROCEDURE [dbo].stp_UsrPar_getByKey
(
	@email nvarchar(250),
	@ParName nvarchar(50)
)
AS
	SET NOCOUNT ON;
SELECT	Email, ParName, ParValue 
FROM	dbo.UserParam
WHERE	Email = @email 
	AND ParName = @ParName
	
-- =============================================
-- Author:		S.E. Locatelli
-- Create date: 2015.10.29
-- Description:	upsert record parametro x utente
-- =============================================
CREATE PROCEDURE [dbo].[stp_UsrPar_upsert]
(
	@Email	 NVARCHAR(250),
	@ParName	 NVARCHAR(50),
	@ParValue	 NVARCHAR(MAX)
)
AS

BEGIN tran
	SET NOCOUNT OFF;

	-- SE NON HO un record lo inserisco altrimenti update...
	MERGE UserParam AS target
	   USING (SELECT @Email, @ParName, @ParValue) AS source (Email, ParName, ParValue)
	   ON (target.Email = source.Email AND target.ParName = source.ParName)
        WHEN MATCHED THEN 
            UPDATE SET ParValue = source.ParValue
	   WHEN NOT MATCHED THEN	
		   INSERT (Email, ParName, ParValue)
		   VALUES (source.Email, source.ParName, source.ParValue);

    -- Rileggo..
    SELECT Email, ParName, ParValue FROM UserParam WHERE (Email = @Email) AND (ParName = @ParName)

COMMIT tran	