You are on page 1of 6

--PROCEDURE FOR INSERT IN USER_LOGIN TABLE CREATE PROCEDURE SP_USER_LOGIN_INSERT ( @EMP_ID INT, @PASSWORD VARCHAR(15), @EMAIL_ID VARCHAR(MAX), @PRIVILAGE

INT, @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION INSERT INTO [Lab_Management].[dbo].[User_login] ([emp_id] ,[password] ,[email_id] ,[privilage]) VALUES (@EMP_ID ,@PASSWORD ,@EMAIL_ID ,@PRIVILAGE) COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END --PROCEDURE FOR UPDATE IN USER_LOGIN TABLE CREATE PROCEDURE SP_USER_LOGIN_UPDATE ( @EMP_ID INT, @PASSWORD VARCHAR(15), @PRIVILAGE INT, @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION UPDATE [Lab_Management].[dbo].[User_login] SET [password] = @PASSWORD, [privilage] = @PRIVILAGE WHERE [emp_id] = @EMP_ID COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END --PROCEDURE FOR DELETE IN USER_LOGIN TABLE

CREATE PROCEDURE SP_USER_LOGIN_DELETE ( @EMP_ID INT, @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION DELETE FROM [Lab_Management].[dbo].[User_login] WHERE [emp_id] = @EMP_ID COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END

--PROCEDURE FOR INSERT IN INVENTORY TABLE CREATE PROCEDURE SP_INVENTORY_INSERT ( @SERIAL_NO VARCHAR(MAX), @GRN_NO VARCHAR(MAX), @NAME VARCHAR(MAX), @STATUS INT, @REMARKS NTEXT, @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION INSERT INTO [Lab_Management].[dbo].[Inventory] ([serial_no] ,[grn_no] ,[name] ,[status] ,[remarks]) VALUES (@SERIAL_NO ,@GRN_NO ,@NAME ,@STATUS ,@REMARKS) COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END

--PROCEDURE FOR UPDATE IN INVENTORY TABLE CREATE PROCEDURE SP_INVENTORY_UPDATE ( @SERIAL_NO VARCHAR(MAX), @GRN_NO VARCHAR(MAX), @NAME VARCHAR(MAX), @STATUS INT, @REMARKS NTEXT, @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION UPDATE [Lab_Management].[dbo].[Inventory] SET [grn_no] = @GRN_NO ,[name] = @NAME ,[status] = @STATUS ,[remarks] = @REMARKS WHERE [serial_no] = @SERIAL_NO COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END --PROCEDURE FOR DELETE IN INVENTORY TABLE CREATE PROCEDURE SP_INVENTORY_DELETE ( @SERIAL_NO VARCHAR(MAX), @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION DELETE FROM [Lab_Management].[dbo].[Inventory] WHERE [serial_no] = @SERIAL_NO COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END

--PROCEDURE FOR INSERT IN User_transaction TABLE CREATE PROCEDURE SP_TRANSACTION_INSERT ( @CARD_USED_BY INT, @EAGLE_ID VARCHAR(MAX),

@SERIAL_NO VARCHAR(MAX), @CARD_TYPE VARCHAR(MAX), @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION INSERT INTO [Lab_Management].[dbo].[User_transaction] ([eagle_id] ,[card_type] ,[card_used_by] ,[serial_no]) VALUES (@EAGLE_ID ,@CARD_TYPE ,@CARD_USED_BY ,@SERIAL_NO) -UPDATE TO CHANGE STATUS OF CARD TO In-Use UPDATE [Lab_Management].[dbo].[Inventory] SET [status] = 1 WHERE [serial_no] = @SERIAL_NO

COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END --PROCEDURE FOR UPDATE IN User_transaction TABLE : NOT IN USE --CREATE PROCEDURE SP_TRANSACTION_UPDATE --( -- @CARD_USED_BY INT, -- @EAGLE_ID VARCHAR(MAX), -- @SERIAL_NO VARCHAR(MAX), -- @CARD_TYPE VARCHAR(MAX), -- @P_RETOUT NVARCHAR(100) OUTPUT --) --AS --BEGIN -- BEGIN TRY -- BEGIN TRANSACTION --- UPDATE [Lab_Management].[dbo].[User_transaction] -SET [eagle_id] = @EAGLE_ID -,[card_type] = @CARD_TYPE -,[card_used_by] = @CARD_USED_BY -,[serial_no] = @SERAIL_NO -WHERE [eagle_id] = @EAGLE_ID AND [serial_no] = @SERIAL_NO -- COMMIT TRANSACTION -- END TRY -- BEGIN CATCH -- SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() -- ROLLBACK TRANSACTION -- END CATCH --END

--PROCEDURE FOR DELETE IN User_transaction TABLE : NOT IN USE CREATE PROCEDURE SP_TRANSACTION_DELETE ( @EAGLE_ID VARCHAR(MAX), @SERIAL_NO VARCHAR(MAX), @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION DELETE FROM [Lab_Management].[dbo].[User_transaction] WHERE [eagle_id] = @EAGLE_ID AND [serial_no] = @SERIAL_NO -UPDATE TO CHANGE STATUS OF CARD TO Free UPDATE [Lab_Management].[dbo].[Inventory] SET [status] = 0 WHERE [serial_no] = @SERIAL_NO

COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END --PROCEDURE TO SEARCH & RETRIEVE USER DETAILS CREATE PROCEDURE SP_USER_LOGIN_SEARCH ( @EMP_ID INT, @EMAIL_ID VARCHAR(MAX), @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION SELECT [emp_id] ,[password] ,[email_id] ,[privilage] FROM [Lab_Management].[dbo].[User_login] WHERE [emp_id] = @EMP_ID OR [email_id] = @EMAIL_ID COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END

--PROCEDURE FOR SEARCH & RETRIEVE INVENTORY DETAILS CREATE PROCEDURE SP_INVENTORY_SEARCH ( @QUERY VARCHAR(MAX), @P_RETOUT NVARCHAR(100) OUTPUT ) AS BEGIN BEGIN TRY BEGIN TRANSACTION @QUERY COMMIT TRANSACTION END TRY BEGIN CATCH SELECT @P_RETOUT = ERROR_NUMBER() + '^' + ERROR_MESSAGE() ROLLBACK TRANSACTION END CATCH END