USP_DATAFORMTEMPLATE_ADD_EVENTRESOURCE

The save procedure used by the add dataform template "Event Resource Add Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@EVENTID uniqueidentifier IN Input parameter indicating the context ID for the record being added.
@RESOURCEID uniqueidentifier IN Resource
@QUANTITYNEEDED int IN Quantity needed
@IGNORECONFLICTS bit IN Ignore conflicts when saving

Definition

Copy

                CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_EVENTRESOURCE
                (
                    @ID uniqueidentifier = null output,
                    @CHANGEAGENTID uniqueidentifier = null,
                    @EVENTID uniqueidentifier,
                    @RESOURCEID uniqueidentifier,
                    @QUANTITYNEEDED int = 0,
                    @IGNORECONFLICTS bit = 0
                )
                as

                set nocount on;

                if @ID is null
                    set @ID = newid()

                if @CHANGEAGENTID is null  
                    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

                declare @CURRENTDATE datetime
                set @CURRENTDATE = getdate()

                declare @PERTICKETQUANTITY int
                select @PERTICKETQUANTITY = PERTICKETQUANTITY
                from dbo.RESOURCE
                where ID = @RESOURCEID 

                declare
                    @STARTDATETIME datetime,
                    @ENDDATETIME datetime,
                    @EVENTRESOURCES xml;

                select
                    @STARTDATETIME = STARTDATETIME,
                    @ENDDATETIME = ENDDATETIME
                from dbo.EVENT
                where ID = @EVENTID

                set @EVENTRESOURCES = ( select @RESOURCEID RESOURCEID, @QUANTITYNEEDED QUANTITYNEEDED for xml raw('ITEM'), type, elements, root('RESOURCES'), binary base64 )

                begin try

                    if @IGNORECONFLICTS = 0
                    begin
                        if dbo.UFN_CONFLICTCHECK_CONFLICTSEXIST
                        (
                            @STARTDATETIME, @ENDDATETIME,
                            null, @EVENTRESOURCES, null,
                            null, @EVENTID, null,
                            0,
                            1,
                            0,
                            0
                        ) = 1
                        begin                    
                            raiserror('BBERR_CONFLICTSEXIST', 13, 1);
                            return 1;
                        end
                    end

                    -- handle inserting the data
                    insert into dbo.EVENTRESOURCE
                        (ID, EVENTID, RESOURCEID, QUANTITYNEEDED, PERTICKETQUANTITY, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
                    values
                        (@ID, @EVENTID, @RESOURCEID, @QUANTITYNEEDED, @PERTICKETQUANTITY, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)

                    update dbo.[RESOURCE] set
                        [QUANTITY] = dbo.[RESOURCE].[QUANTITY] - @QUANTITYNEEDED,
                        CHANGEDBYID = @CHANGEAGENTID,
                        DATECHANGED = @CURRENTDATE
                    from dbo.[RESOURCE]
                    where dbo.[RESOURCE].ID = @RESOURCEID
                        and dbo.[RESOURCE].ISPERTICKETITEM = 0
                        and dbo.[RESOURCE].TYPECODE = 1
                end try

                begin catch
                    exec dbo.USP_RAISE_ERROR
                    return 1
                end catch

                return 0