Files
Samuele E. Locatelli bdd7b413e8 Riaggiunto GMW_data
2016-11-22 17:58:00 +01:00

282 lines
7.2 KiB
Transact-SQL

set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
/***************************************
* STORED stp_spostaUdc
*
* sposta un UDC, salvandone la posizione precedente (se esiste) nella tab storica
*
* Steamware, S.E.L.
* mod: 2010.06.11
*
****************************************/
alter PROCEDURE stp_spostaUdc
(
@CodCS VARCHAR(2),
@UDC VARCHAR(50),
@IdxCellaTo INT,
@resetRLP BIT
)
AS
BEGIN TRAN
-- DICHIARAZIONI iniziali variabili
DECLARE @IdxCellaFrom INT
DECLARE @capienza INT
DECLARE @numUdc INT
-- controllo cella di partenza
SET @IdxCellaFrom = (SELECT IdxCella FROM PosizioneUdcCorrente WHERE UDC = @UDC)
SET @IdxCellaFrom = ISNULL(@IdxCellaFrom,0) -- controllo x cella null...
-- controllo se cella di destinazione e di partenza coincidono NON FACCIO NULLA... altrimenti procedo
IF (@IdxCellaTo <> @IdxCellaFrom)
BEGIN
-- controllo se la cella di partenza vada indicata come piena o meno
SET @capienza = (
SELECT tc.Capienza
FROM TipoCella TC INNER JOIN Celle c ON TC.IdxTipoCella=c.IdxTipoCella
WHERE c.IdxCella = @IdxCellaFrom
)
SET @numUdc = (SELECT COUNT(*) FROM PosizioneUdcCorrente WHERE IdxCella = @IdxCellaFrom)
-- se capienza cella di partenza NON raggiunta aggiorno NON Piena
IF(@numUdc -1 < @capienza)
BEGIN
EXEC stp_celle_updPiena @IdxCellaFrom, 0
END
-- cancello posizione occupata
DELETE
FROM PosizioneUdcCorrente
WHERE UDC = @UDC
-- SE RICHIESTO cancello eventuali righe liste di prelievo FUSI per l'UDC
IF(@resetRLP = 1)
BEGIN
DELETE FROM RigheListePrelievo
WHERE UDC = @UDC AND CodLista IN (
SELECT CodLista FROM ElencoListePrelievo
--WHERE CodTipoLista='01-PreFus'
WHERE CodStatoLista < 4
)
END
-- creo una nuova posizione per l'UDC
INSERT INTO PosizioneUdcCorrente(UDC, IdxCella, CodCS, DataRif)
VALUES(@UDC, @IdxCellaTo, @CodCS, GETDATE())
SET @numUdc = (SELECT COUNT(*) FROM PosizioneUdcCorrente WHERE IdxCella = @IdxCellaTo)
-- controllo se la cella di dest vada indicata come piena, altrimenti NON la indicherò (mai) come piena...
SET @capienza = (
SELECT CASE CheckPiena WHEN 1 THEN tc.Capienza ELSE @numUdc + 1 END
FROM TipoCella TC INNER JOIN Celle c ON TC.IdxTipoCella=c.IdxTipoCella
WHERE c.IdxCella = @IdxCellaTo
)
-- se capienza raggiunta aggiorno...
IF(@numUdc >= @capienza)
BEGIN
EXEC stp_celle_updPiena @IdxCellaTo, 1
END
END -- cellaFrom e cellaTo non coincidono...
COMMIT TRAN
RETURN
go
commit;
go
set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
alter VIEW v_righeListePrelievoPosizione
AS
SELECT dbo.RigheListePrelievo.CodLista, dbo.RigheListePrelievo.UDC, dbo.RigheListePrelievo.Qta, dbo.RigheListePrelievo.Proposto, dbo.RigheListePrelievo.Prelevato,
ISNULL(dbo.Celle.CodCella, N'') AS CodCella, ISNULL(dbo.Blocchi.CodMag, N'') AS CodMag, ISNULL(dbo.Blocchi.CodBlocco, N'') AS CodBlocco, ISNULL(dbo.Celle.X,
0) AS X, ISNULL(dbo.Celle.Y, 0) AS Y, ISNULL(dbo.Celle.Z, 0) AS Z
FROM dbo.Celle INNER JOIN
dbo.PosizioneUdcCorrente ON dbo.Celle.IdxCella = dbo.PosizioneUdcCorrente.IdxCella INNER JOIN
dbo.Blocchi ON dbo.Celle.IdxBlocco = dbo.Blocchi.IdxBlocco RIGHT OUTER JOIN
dbo.RigheListePrelievo ON dbo.PosizioneUdcCorrente.UDC = dbo.RigheListePrelievo.UDC
go
exec sp_updateextendedproperty '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 = "Celle"
Begin Extent =
Top = 6
Left = 621
Bottom = 235
Right = 791
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "PosizioneUdcCorrente"
Begin Extent =
Top = 18
Left = 377
Bottom = 183
Right = 547
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "Blocchi"
Begin Extent =
Top = 5
Left = 870
Bottom = 134
Right = 1040
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "RigheListePrelievo"
Begin Extent =
Top = 6
Left = 38
Bottom = 188
Right = 208
End
DisplayFlags = 280
TopColumn = 0
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 13
Width = 284
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
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
', 'SCHEMA', 'dbo', 'VIEW', 'v_righeListePrelievoPosizione';
go
commit;
go
-- registro versione...
INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(460, GETDATE())
GO