﻿DECLARE @TypeId int

DECLARE intezmenytanevekCursor CURSOR LOCAL FOR 
	SELECT C_INTEZMENYID, C_TANEVID
		FROM T_INTEZMENYADATOK

DECLARE @intezmenyId int, @tanevId int

OPEN intezmenytanevekCursor  
FETCH NEXT FROM intezmenytanevekCursor INTO @intezmenyId, @tanevId

WHILE @@FETCH_STATUS = 0 
BEGIN  
	PRINT N'INTÉZMÉNY ID: ' + CAST(@intezmenyId AS NVARCHAR(10)) + N', TANÉV ID: ' + CAST(@tanevId AS NVARCHAR(10))

	IF (@TypeId IS NULL) BEGIN
		SELECT @TypeId = ID
		FROM T_DICTIONARYTYPE
		WHERE C_CODENAME = N'EvfolyamTipus'
	END

	SET IDENTITY_INSERT [dbo].[T_DICTIONARYITEMBASE] ON

		INSERT INTO dbo.T_DICTIONARYITEMBASE (ID, C_NAME, C_NAME_1, C_NAME_2, C_NAME_3, C_NAME_4, C_TYPE, C_PROTECTED, C_VISIBLE, C_ORDER, C_CODE, C_VALUE, C_COLOR, C_DICTIONARYTYPEID, C_INTEZMENYID, C_TANEVID, TOROLT, SERIAL, LASTCHANGED, CREATED, MODIFIER, CREATOR)
		VALUES
		    (6908, N'Összevont 1-2', N'Összevont 1-2', NULL, NULL, NULL, N'EvfolyamTipus', N'F', N'T', 72, NULL, 69, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6909, N'Összevont 1-3', N'Összevont 1-3', NULL, NULL, NULL, N'EvfolyamTipus', N'F', N'T', 73, NULL, 70, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6910, N'Összevont 1-4', N'Összevont 1-4', NULL, NULL, NULL, N'EvfolyamTipus', N'F', N'T', 74, NULL, 71, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6911, N'Összevont 2-3', N'Összevont 2-3', NULL, NULL, NULL, N'EvfolyamTipus', N'F', N'T', 75, NULL, 72, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6912, N'Összevont 2-4', N'Összevont 2-4', NULL, NULL, NULL, N'EvfolyamTipus', N'F', N'T', 76, NULL, 73, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6913, N'Összevont 3-4', N'Összevont 3-4', NULL, NULL, NULL, N'EvfolyamTipus', N'F', N'T', 77, NULL, 74, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL)

    SET IDENTITY_INSERT [dbo].[T_DICTIONARYITEMBASE] OFF

		INSERT INTO [dbo].[T_EVFOLYAMTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID], C_ALAPORASZAM, C_MINIMUMORASZAM, C_VISZONYITASILETSZAM) VALUES
			(6908, @IntezmenyId, @TanevId, 52, 34, 27),
			(6909, @IntezmenyId, @TanevId, 52, 34, 27),
			(6910, @IntezmenyId, @TanevId, 55, 34, 27),
			(6911, @IntezmenyId, @TanevId, 52, 34, 27),
			(6912, @IntezmenyId, @TanevId, 55, 34, 27),
			(6913, @IntezmenyId, @TanevId, 55, 34, 27)

	FETCH NEXT FROM intezmenytanevekCursor INTO @intezmenyId, @tanevId
END  

CLOSE intezmenytanevekCursor  
DEALLOCATE intezmenytanevekCursor

GO

UPDATE dbo.T_DICTIONARYITEMBASE SET C_PROTECTED = 'T' WHERE C_TYPE = 'OktatasiNevelesiFeladat'

UPDATE dbo.T_DICTIONARYTYPE SET C_ISCUSTOMITEMALLOWED = 'T' WHERE C_CODENAME = 'OktatasiNevelesiFeladat'

GO
