USP_DATAFORMTEMPLATE_EDIT_EVENTRESOURCE_2
The save procedure used by the edit dataform template "Event Resource Edit Form".
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | IN | The input ID parameter indicating the ID of the record being edited. |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the procedure. |
@RESOURCEID | uniqueidentifier | IN | Resource |
@QUANTITYNEEDED | int | IN | Quantity needed |
@IGNORECONFLICTS | bit | IN | Ignore conflicts when saving |
Definition
Copy
CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_EVENTRESOURCE_2
(
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier = null,
@RESOURCEID uniqueidentifier,
@QUANTITYNEEDED int,
@IGNORECONFLICTS bit
)
as
set nocount on;
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
declare
@EVENTID uniqueidentifier,
@STARTDATETIME datetime,
@ENDDATETIME datetime,
@EVENTRESOURCES xml;
select @EVENTID = EVENTID from dbo.EVENTRESOURCE where ID = @ID
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
declare @PREVIOUSQUANTITY int;
declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()
select @PREVIOUSQUANTITY = [QUANTITYNEEDED]
from dbo.[EVENTRESOURCE]
where dbo.[EVENTRESOURCE].ID = @ID
declare @PERTICKETQUANTITY int
select @PERTICKETQUANTITY = PERTICKETQUANTITY
from dbo.RESOURCE
where ID = @RESOURCEID
-- handle updating the data
update dbo.EVENTRESOURCE set
RESOURCEID = @RESOURCEID,
QUANTITYNEEDED = @QUANTITYNEEDED,
PERTICKETQUANTITY = @PERTICKETQUANTITY,
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE
where ID = @ID
update dbo.[RESOURCE] set
[QUANTITY] = dbo.[RESOURCE].[QUANTITY] + @PREVIOUSQUANTITY - @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;