USP_DATAFORMTEMPLATE_EDIT_COPYPROGRAMDISCOUNT

The save procedure used by the edit dataform template "Copy Program Discounts 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.
@SOURCEPROGRAMID uniqueidentifier IN Copy from

Definition

Copy


                    CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_COPYPROGRAMDISCOUNT
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier = null,
                        @SOURCEPROGRAMID uniqueidentifier
                    )
                as
                begin

                    set nocount on;

                    begin try    

                        if @ID <> @SOURCEPROGRAMID
                        begin
                            declare @e int;
                            declare @contextCache varbinary(128);

                            set @contextCache = CONTEXT_INFO();

                            if not @CHANGEAGENTID is null
                              set CONTEXT_INFO @CHANGEAGENTID

                            delete from dbo.DISCOUNTGROUP
                            where ID in (    select DISCOUNTGROUP.ID
                                            from dbo.DISCOUNTGROUP
                                                inner join dbo.DISCOUNTGROUPDETAIL on DISCOUNTGROUPDETAIL.DISCOUNTGROUPID = DISCOUNTGROUP.ID
                                                inner join dbo.DISCOUNTGROUPDETAILPROGRAM on DISCOUNTGROUPDETAIL.ID = DISCOUNTGROUPDETAILPROGRAM.ID
                                            where
                                                DISCOUNTGROUPDETAILPROGRAM.PROGRAMID = @ID )

                            if not @contextCache is null
                                set CONTEXT_INFO @contextCache

                            select @e=@@error;

                            if @e<>0 return -456; --always return non-zero sp result if an error occurs


                            update dbo.[PROGRAM] with (rowlock)
                            set 
                                [DATECHANGED] = getdate(),
                                [CHANGEDBYID] = @CHANGEAGENTID
                            where [ID] = @ID

                            exec dbo.USP_PROGRAM_COPYDISCOUNTS @SOURCEPROGRAMID, @ID, @CHANGEAGENTID;
                        end
                    end try

                    begin catch
                        exec dbo.USP_RAISE_ERROR;
                        return 1;
                    end catch

                    return 0;
                end