create table AnagAzioniUtente( codAzione nvarchar(10) not null constraint PK_AnagAzioniUtente primary key, descrAzione nvarchar(50) ); go set xact_abort on go begin transaction go INSERT INTO dbo.AnagAzioniUtente VALUES (N'consumaUDC', N'consuma UDC') INSERT INTO dbo.AnagAzioniUtente VALUES (N'creaUDC', N'creazione nuovo UDC') INSERT INTO dbo.AnagAzioniUtente VALUES (N'eliminaUDC', N'elimina UDC') INSERT INTO dbo.AnagAzioniUtente VALUES (N'stampaUDC', N'stampa UDC') go commit transaction go set xact_abort on; go begin transaction; go create table StoricoAzioniOperatore( idxEvento int not null identity constraint PK_StoricoAzioniOperatore primary key, DataOra datetime not null, CodSoggetto nchar(17) not null, codPostazione nvarchar(250), UDC nvarchar(50), Particolare nvarchar(15), codAzione nvarchar(10), descrizione nvarchar(50) ); go alter table StoricoAzioniOperatore add constraint FK_StoricoAzioniOperatore_AnagAzioniUtente foreign key(codAzione) references AnagAzioniUtente(codAzione) on update cascade; go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go /*************************************** * STORED stp_SAO_insert * * effettua ricerca nello Storico Azioni Operatore * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ create PROCEDURE stp_SAO_getBySearch ( @DataOraFrom DATETIME, @DataOraTo DATETIME, @CodSoggetto NVARCHAR(17)='', @codPostazione NVARCHAR(250)='', @UDC NVARCHAR(50)='', @Particolare NVARCHAR(15)='', @codAzione NVARCHAR(10)='' ) AS SELECT * FROM StoricoAzioni WHERE DataOra BETWEEN @DataOraFrom AND @DataOraTo AND CodSoggetto = CASE WHEN @CodSoggetto = '' THEN CodSoggetto ELSE @CodSoggetto END AND codPostazione = CASE WHEN @codPostazione = '' THEN codPostazione ELSE @codPostazione END AND UDC = CASE WHEN @UDC = '' THEN UDC ELSE @UDC END AND Particolare = CASE WHEN @Particolare = '' THEN Particolare ELSE @Particolare END AND codAzione = CASE WHEN @codAzione = '' THEN codAzione ELSE @codAzione END COMMIT tran RETURN go /*************************************** * STORED stp_SAO_insert * * inserisce nuova riga nello Storico Azioni Operatore * * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ create PROCEDURE stp_SAO_insert ( @DataOra DATETIME, @CodSoggetto NVARCHAR(17), @codPostazione NVARCHAR(250), @UDC NVARCHAR(50), @Particolare NVARCHAR(15), @codAzione NVARCHAR(10), @descrizione NVARCHAR(50) ) AS BEGIN tran -- inserisco nuovo record storico azioni operatore INSERT INTO StoricoAzioni(DataOra, CodSoggetto, codPostazione, UDC, Particolare, codAzione, descrizione) VALUES (@DataOra, @CodSoggetto, @codPostazione, @UDC, @Particolare, @codAzione, @descrizione) COMMIT tran RETURN go commit; go set xact_abort on; go begin transaction; go drop table StoricoAzioniOperatore; go create table StoricoAzioniOperatore( idxEvento int not null identity constraint PK_StoricoAzioniOperatore primary key, DataOra datetime not null, CodSoggetto nchar(17) not null, codPostazione nvarchar(250), clientIP nvarchar(250), UDC nvarchar(50), Particolare nvarchar(15), codAzione nvarchar(10), descrizione nvarchar(50) ); go alter table StoricoAzioniOperatore add constraint FK_StoricoAzioniOperatore_AnagAzioniUtente foreign key(codAzione) references AnagAzioniUtente(codAzione) on update cascade; go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go /*************************************** * STORED stp_SAO_insert * * effettua ricerca nello Storico Azioni Operatore * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ alter PROCEDURE stp_SAO_getBySearch ( @DataOraFrom DATETIME, @DataOraTo DATETIME, @CodSoggetto NVARCHAR(17)='', @codPostazione NVARCHAR(250)='', @clientIp NVARCHAR(250)='', @UDC NVARCHAR(50)='', @Particolare NVARCHAR(15)='', @codAzione NVARCHAR(10)='' ) AS SELECT * FROM StoricoAzioni WHERE DataOra BETWEEN @DataOraFrom AND @DataOraTo AND CodSoggetto = CASE WHEN @CodSoggetto = '' THEN CodSoggetto ELSE @CodSoggetto END AND codPostazione = CASE WHEN @codPostazione = '' THEN codPostazione ELSE @codPostazione END AND clientIp = CASE WHEN @clientIp = '' THEN clientIp ELSE @clientIp END AND UDC = CASE WHEN @UDC = '' THEN UDC ELSE @UDC END AND Particolare = CASE WHEN @Particolare = '' THEN Particolare ELSE @Particolare END AND codAzione = CASE WHEN @codAzione = '' THEN codAzione ELSE @codAzione END COMMIT tran RETURN go /*************************************** * STORED stp_SAO_insert * * inserisce nuova riga nello Storico Azioni Operatore * * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ alter PROCEDURE stp_SAO_insert ( @DataOra DATETIME, @CodSoggetto NVARCHAR(17), @codPostazione NVARCHAR(250), @clientIp NVARCHAR(250)='', @UDC NVARCHAR(50), @Particolare NVARCHAR(15), @codAzione NVARCHAR(10), @descrizione NVARCHAR(50) ) AS BEGIN tran -- inserisco nuovo record storico azioni operatore INSERT INTO StoricoAzioni(DataOra, CodSoggetto, codPostazione, clientIp, UDC, Particolare, codAzione, descrizione) VALUES (@DataOra, @CodSoggetto, @codPostazione, @clientIp, @UDC, @Particolare, @codAzione, @descrizione) COMMIT tran RETURN go commit; go set xact_abort on; go begin transaction; go alter table StoricoAzioniOperatore alter column descrizione nvarchar(500); go set ANSI_NULLS on; go /*************************************** * STORED stp_SAO_insert * * inserisce nuova riga nello Storico Azioni Operatore * * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ alter PROCEDURE stp_SAO_insert ( @DataOra DATETIME, @CodSoggetto NVARCHAR(17), @codPostazione NVARCHAR(250), @clientIp NVARCHAR(250)='', @UDC NVARCHAR(50), @Particolare NVARCHAR(15), @codAzione NVARCHAR(10), @descrizione NVARCHAR(500) ) AS BEGIN tran -- inserisco nuovo record storico azioni operatore INSERT INTO StoricoAzioniOperatore(DataOra, CodSoggetto, codPostazione, clientIp, UDC, Particolare, codAzione, descrizione) VALUES (@DataOra, @CodSoggetto, @codPostazione, @clientIp, @UDC, @Particolare, @codAzione, @descrizione) COMMIT tran RETURN go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go /*************************************** * STORED stp_SAO_getBySearch * * effettua ricerca nello Storico Azioni Operatore * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ alter PROCEDURE stp_SAO_getBySearch ( @DataOraFrom DATETIME, @DataOraTo DATETIME, @CodSoggetto NVARCHAR(17)='', @codPostazione NVARCHAR(250)='', @clientIp NVARCHAR(250)='', @UDC NVARCHAR(50)='', @Particolare NVARCHAR(15)='', @codAzione NVARCHAR(10)='' ) AS SELECT * FROM StoricoAzioniOperatore WHERE DataOra BETWEEN @DataOraFrom AND @DataOraTo AND CodSoggetto = CASE WHEN @CodSoggetto = '' THEN CodSoggetto ELSE @CodSoggetto END AND codPostazione = CASE WHEN @codPostazione = '' THEN codPostazione ELSE @codPostazione END AND clientIp = CASE WHEN @clientIp = '' THEN clientIp ELSE @clientIp END AND UDC = CASE WHEN @UDC = '' THEN UDC ELSE @UDC END AND Particolare = CASE WHEN @Particolare = '' THEN Particolare ELSE @Particolare END AND codAzione = CASE WHEN @codAzione = '' THEN codAzione ELSE @codAzione END RETURN go /*************************************** * STORED stp_SAO_getLastPostazione * * ultimi record SAO x postazione * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ create PROCEDURE stp_SAO_getLastPostazione ( @DataOraFrom DATETIME, @DataOraTo DATETIME, @codPostazione NVARCHAR(250)='' ) AS SELECT * FROM StoricoAzioniOperatore WHERE DataOra BETWEEN @DataOraFrom AND @DataOraTo AND codPostazione = @codPostazione ORDER BY DataOra DESC RETURN go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go create VIEW v_selPostazioni AS SELECT codPostazione AS value, codPostazione AS label FROM dbo.ElencoPostazioni go exec sp_addextendedproperty 'MS_DiagramPane1', '[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00] Begin DesignProperties = Begin PaneConfigurations = Begin PaneConfiguration = 0 NumPanes = 4 Configuration = "(H (1[40] 4[20] 2[20] 3) )" End Begin PaneConfiguration = 1 NumPanes = 3 Configuration = "(H (1 [50] 4 [25] 3))" End Begin PaneConfiguration = 2 NumPanes = 3 Configuration = "(H (1 [50] 2 [25] 3))" End Begin PaneConfiguration = 3 NumPanes = 3 Configuration = "(H (4 [30] 2 [40] 3))" End Begin PaneConfiguration = 4 NumPanes = 2 Configuration = "(H (1 [56] 3))" End Begin PaneConfiguration = 5 NumPanes = 2 Configuration = "(H (2 [66] 3))" End Begin PaneConfiguration = 6 NumPanes = 2 Configuration = "(H (4 [50] 3))" End Begin PaneConfiguration = 7 NumPanes = 1 Configuration = "(V (3))" End Begin PaneConfiguration = 8 NumPanes = 3 Configuration = "(H (1[56] 4[18] 2) )" End Begin PaneConfiguration = 9 NumPanes = 2 Configuration = "(H (1 [75] 4))" End Begin PaneConfiguration = 10 NumPanes = 2 Configuration = "(H (1[66] 2) )" End Begin PaneConfiguration = 11 NumPanes = 2 Configuration = "(H (4 [60] 2))" End Begin PaneConfiguration = 12 NumPanes = 1 Configuration = "(H (1) )" End Begin PaneConfiguration = 13 NumPanes = 1 Configuration = "(V (4))" End Begin PaneConfiguration = 14 NumPanes = 1 Configuration = "(V (2))" End ActivePaneConfig = 0 End Begin DiagramPane = Begin Origin = Top = 0 Left = 0 End Begin Tables = Begin Table = "ElencoPostazioni" Begin Extent = Top = 6 Left = 38 Bottom = 102 Right = 208 End DisplayFlags = 280 TopColumn = 0 End End End Begin SQLPane = End Begin DataPane = Begin ParameterDefaults = "" End Begin ColumnWidths = 9 Width = 284 Width = 2205 Width = 6885 Width = 1500 Width = 1500 Width = 1500 Width = 1500 Width = 1500 Width = 1500 End End Begin CriteriaPane = Begin ColumnWidths = 11 Column = 1440 Alias = 900 Table = 1170 Output = 720 Append = 1400 NewValue = 1170 SortType = 1350 SortOrder = 1410 GroupBy = 1350 Filter = 1350 Or = 1350 Or = 1350 Or = 1350 End End End ', 'SCHEMA', 'dbo', 'VIEW', 'v_selPostazioni'; go exec sp_addextendedproperty 'MS_DiagramPaneCount', 1, 'SCHEMA', 'dbo', 'VIEW', 'v_selPostazioni'; go commit; go set xact_abort on; go begin transaction; go set ANSI_NULLS on; go /*stp_SAO_getByIdxEv * STORED stp_SAO_getBySearch * * cerca riga in Storico Azioni Operatore * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ create PROCEDURE stp_SAO_getByIdxEv ( @idxEvento INT=0 ) AS SELECT * FROM StoricoAzioniOperatore WHERE idxEvento = @idxEvento RETURN go /*************************************** * STORED stp_UDC_delete * * elimina un dato UDC * * Steamware, S.E.L. * mod: 2012.09.25 * ****************************************/ create PROCEDURE stp_UDC_delete ( @UDC NVARCHAR(50) ) AS BEGIN tran -- annullo cella piena UPDATE dbo.Celle SET Piena = 0 FROM PosizioneUdcCorrente p INNER JOIN dbo.Celle c ON p.IdxCella = c.IdxCella WHERE c.Piena = 1 AND p.UDC = @UDC -- cancello posizione DELETE FROM PosizioneUdcCorrente WHERE UDC = @UDC -- cancello UDC DELETE FROM ElencoCartellini WHERE UDC = @UDC COMMIT tran RETURN go commit; go -- registro versione... INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(495, GETDATE()) GO