From bb45e551a3711dffb0e95bd2da7d3024deb66802 Mon Sep 17 00:00:00 2001 From: mschill Date: Mon, 30 Sep 2024 15:02:35 -0400 Subject: [PATCH 1/2] C2017-031 Extend Copy / Paste Replace Functionality for Enhanced Background Steps --- PROMS/VEPROMS User Interface/PROMSFixes.Sql | 1099 +++++++++++------ .../Extension/ItemInsertExt.cs | 144 ++- PROMS/Volian.Controls.Library/EditItem.cs | 3 +- .../RTBItem.designer.cs | Bin 17380 -> 17810 bytes PROMS/Volian.Controls.Library/StepPanel.cs | 2 +- PROMS/Volian.Controls.Library/StepRTB.cs | 2 + .../Volian.Controls.Library/StepTabRibbon.cs | 17 +- 7 files changed, 857 insertions(+), 410 deletions(-) diff --git a/PROMS/VEPROMS User Interface/PROMSFixes.Sql b/PROMS/VEPROMS User Interface/PROMSFixes.Sql index b8e92a44..11f23950 100644 --- a/PROMS/VEPROMS User Interface/PROMSFixes.Sql +++ b/PROMS/VEPROMS User Interface/PROMSFixes.Sql @@ -19,191 +19,6 @@ end print 'Adding procedures and functions to ' + db_name() - -IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[PasteItemReplace]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) - DROP PROCEDURE [PasteItemReplace]; -GO -/****** Object: StoredProcedure [dbo].[PasteItemReplace] Script Date: 03/20/2012 16:02:54 ******/ -/* -declare @NewItemID int -declare @dts datetime -set @newitemid = 0 -set @dts = getdate() -exec PasteItemReplace 398,397,20014,@dts,'bodine',@NewItemID output -*/ --- ItemID is item to replace --- StartItemID is item to copy -/***************************************************************************** - Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE - Copyright 2012 - Volian Enterprises, Inc. All rights reserved. -*****************************************************************************/ -CREATE PROCEDURE [dbo].[PasteItemReplace] -( - @ItemID int=null, @StartItemID int=null, - @Type int=null, @DTS datetime, @UserID nvarchar(100), - @NewItemID int output -) -WITH EXECUTE AS OWNER -AS -BEGIN TRY -- Try Block - BEGIN TRANSACTION - DECLARE @ContentID AS INT - DECLARE @NextItemID AS INT - DECLARE @PreviousItemID AS INT - DECLARE @ExternalChildCount AS INT - DECLARE @ExternalCount AS INT - DECLARE @Path AS VARCHAR(MAX) - DECLARE @Children AS TABLE - ( - ItemID INT PRIMARY KEY, - ContentID INT - ) - - if exists (select * from tblitems where itemid = @ItemID and DeleteStatus !=0) - BEGIN - RAISERROR ('###Cannot Paste Step###This current step has been deleted in another session',16,1) - RETURN - END - -- First check if the replaced item can be deleted, i.e. it doesn't have transitions - -- pointing to it or children. - - DECLARE @ExternalTrans TABLE - ( - [FromItemID] int, - [TransitionID] [int] NOT NULL, - [FromID] [int] NOT NULL, - [ToID] [int] NOT NULL, - [RangeID] [int] NOT NULL, - [Config] [nvarchar](max) NULL - ) - SET NOCOUNT ON - DECLARE @DeleteID int - INSERT INTO DeleteLog (UserID) VALUES (@UserID) - SELECT @DeleteID = SCOPE_IDENTITY() - SELECT @ContentID = ContentID, @PreviousItemID = PreviousID FROM Items WHERE ItemID = @ItemID - SELECT @NextItemID = ItemID FROM Items WHERE PreviousID = @ItemID - --SELECT @ExternalCount = count(*) FROM vefn_FindExternalTransitions(@ItemID) - SELECT @ExternalChildCount = count(*) FROM vefn_FindExternalChildTransitions(@ItemID) - SET @Path = [dbo].[ve_GetShortPath](@ItemID) - - --IF @ExternalCount > 0 AND @NextItemID is null - --BEGIN - -- RAISERROR ('###Cannot Delete Item###Step %d has External Transitions and has no next step - (%s)',16,1,@ItemID,@Path) - -- RETURN - --END - - IF @ExternalChildCount > 0 - BEGIN - RAISERROR ('###Cannot Delete Item###Step %d has External Transitions to it''s children - (%s)',16,1,@ItemID,@Path) - RETURN - END - - -- Copy the item, 'NewItemID' represents the new item(s) - -- DestFormatID is the formatid for the destination parent's format - DECLARE @DestFormatID int - SET @DestFormatID = .dbo.vefn_GetInheritedFormat(@ItemID, 0) - EXECUTE CopyItemAndChildren @StartItemID, @DestFormatID, @UserID, @NewItemID OUTPUT - - -- Adjust the next/previous to point to the new item - - DECLARE @PreviousID int - SELECT @PreviousID = [PreviousID] - FROM [ITEMS] II - WHERE [ItemID]=@ItemID - UPDATE [ITEMS] SET [PreviousID]=@PreviousID where [ItemID]=@NewItemID - UPDATE [CONTENTS] SET [Type]=@Type - FROM [CONTENTS] CC JOIN [ITEMS] ii ON CC.[ContentID]=II.[ContentID] - WHERE [ItemID]=@NewItemID - UPDATE [ITEMS] SET [PreviousID]=@NewItemID where [PreviousID]=@ItemID - UPDATE [PARTS] SET [ItemID]=@NewItemID where [ItemID]=@ItemID - - -- UPDATE DocVersion if this was a procedure - UPDATE DocVersions SET ItemID=@NewItemID where ItemID = @ItemID - - -- If there were 'external transitions' that pointed to the original - -- top replaced step, adjust them to point to the new top. - INSERT INTO @ExternalTrans SELECT * FROM vefn_FindExternalTransitions(@ItemID) - OPTION (MAXRECURSION 10000) - IF (SELECT COUNT(*) from @ExternalTrans) > 0 - BEGIN - -- Update content records for the transitions - Update CC - Set Text = DBO.vefn_FixTransitionText(Text,TT.TransitionID,TT.TranType,TT.ToID,TT.RangeID,@ItemID,@NewItemID) - From CONTENTS CC - JOIN Transitions TT ON TT.FromID = CC.ContentID - WHERE TransitionID in(Select TransitionID from @ExternalTrans) - -- Update transitions that point to @ItemID to Point to @NextItemID - UPDATE TRANSITIONS - SET ToID = case when ToID = @ItemID then @NewItemID else ToID END, - RangeID = case when RangeID = @ItemID then @NewItemID else RangeID END - WHERE TransitionID in(Select TransitionID from @ExternalTrans) - - DECLARE @typeID int -- AnnotationType - SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required' - IF(@typeID IS NULL) - BEGIN - INSERT INTO [AnnotationTypes] ([Name],[UserID]) VALUES ('Verification Required','Volian') - SELECT @typeID = SCOPE_IDENTITY() - END - -- Add 'Verification Required' annotions for transtions that pointed to top step - -- and need to point to - INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID]) - SELECT ItemID, @typeID,'Verify Replaced Step Transition Destination',@UserID - FROM Items where ItemID in (SELECT FromItemID FROM @ExternalTrans) - - END - -- Remove the old one - - -- Get list of Children - INSERT INTO @Children SELECT * FROM vefn_ChildItems(@ItemID) - -- Delete Annotations for @ItemID and children - DELETE from Annotations where ItemID in(Select ItemID from @Children) - -- Delete Details associated with @ContentID and children - DELETE from Details where ContentID in(Select ContentID from @Children) - -- Delete Grids associated with @ContentID and children - DELETE from Grids where ContentID in(Select ContentID from @Children) - -- Delete Images associated with @ContentID and children - DELETE from Images where ContentID in(Select ContentID from @Children) - -- Delete Entries associated with @ContentID and children - DELETE from Entries where ContentID in(Select ContentID from @Children) - -- Delete ROUsages associated with @ContentID and children - DELETE from RoUsages where ContentID in(Select ContentID from @Children) - -- Delete ZTransitions records associated with @ContentID and children - DELETE FROM ZTransitions where TransitionID - in(SELECT TransitionID from Transitions where FromID in(SELECT ContentID FROM @Children) or FromID = @ContentID) - -- Delete Transitions associated with @ContentID and children - DELETE FROM Transitions where FromID in(SELECT ContentID FROM @Children) or FromID = @ContentID - -- Delete Parts associated with @ContentID and children - DELETE from Parts where ContentID in(Select ContentID from @Children) - -- Delete ZContents associated with @ContentID and children - DELETE from ZContents where ContentID in(Select ContentID from @Children) - -- Disconnect Items from Each Other - DELETE from Items where ItemID in(Select ItemID from @Children) and PreviousID Is Not Null - -- Disconnect Items to be deleted from each other - Update Items set PreviousID = null where ItemID in (Select ItemID from @Children) and PreviousID Is Not Null - -- Delete Item Records - DELETE from Items where ItemID in(Select ItemID from @Children) - -- DELETE Contents - DELETE from Contents where ContentID in(Select ContentID from @Children) ---delete from itemaudits where itemid = @newitemid -delete from itemaudits where itemid in (select itemid from vefn_ChildItems(@newitemid)) ---delete from contentaudits where contentid = (select contentid from items where itemid = @newitemid) -delete from contentaudits where contentid in (select contentid from vefn_ChildItems(@newitemid)) - DELETE from DeleteLog where DeleteID = @DeleteID - IF( @@TRANCOUNT > 0 ) COMMIT - EXECUTE GetItem @NewItemID -END TRY -BEGIN CATCH -- Catch Block - IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level - ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback - EXEC vlnErrorHandler -END CATCH -GO --- Display the status of Proc creation -IF (@@Error = 0) PRINT 'Procedure Creation: PasteItemReplace Succeeded' -ELSE PRINT 'Procedure Creation: PasteItemReplace Error on Creation' -GO - IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_ChronologyReport]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1) DROP FUNCTION [vefn_ChronologyReport]; /****** Object: UserDefinedFunction [dbo].[vefn_ChronologyReport] Script Date: 03/20/2012 17:50:44 ******/ @@ -22637,215 +22452,6 @@ BEGIN CATCH -- Catch Block END CATCH GO - - - - - - -IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[PasteItemReplace]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) - DROP PROCEDURE [PasteItemReplace]; -GO - - /***************************************************************************** - Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE - Copyright 2024 - Volian Enterprises, Inc. All rights reserved. - *****************************************************************************/ - /* - ========================================================================================================== - Author: Kevin Laskey - Create Date: 07/15/2024 - Description: B2024-041: "Copy of" is no longer being appended for paste before/after - ========================================================================================================== - */ - - -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -/****** Object: StoredProcedure [dbo].[PasteItemReplace] Script Date: 03/20/2012 16:02:54 ******/ -/* -declare @NewItemID int -declare @dts datetime -set @newitemid = 0 -set @dts = getdate() -exec PasteItemReplace 398,397,20014,@dts,'bodine',@NewItemID output -*/ --- ItemID is item to replace --- StartItemID is item to copy -/***************************************************************************** - Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE - Copyright 2012 - Volian Enterprises, Inc. All rights reserved. -*****************************************************************************/ -CREATE PROCEDURE [dbo].[PasteItemReplace] -( - @ItemID int=null, @StartItemID int=null, - @Type int=null, @DTS datetime, @UserID nvarchar(100), - @NewItemID int output -) -WITH EXECUTE AS OWNER -AS -BEGIN TRY -- Try Block - BEGIN TRANSACTION - DECLARE @ContentID AS INT - DECLARE @NextItemID AS INT - DECLARE @PreviousItemID AS INT - DECLARE @ExternalChildCount AS INT - DECLARE @ExternalCount AS INT - DECLARE @Path AS VARCHAR(MAX) - DECLARE @Children AS TABLE - ( - ItemID INT PRIMARY KEY, - ContentID INT - ) - - if exists (select * from tblitems where itemid = @ItemID and DeleteStatus !=0) - BEGIN - RAISERROR ('###Cannot Paste Step###This current step has been deleted in another session',16,1) - RETURN - END - -- First check if the replaced item can be deleted, i.e. it doesn't have transitions - -- pointing to it or children. - - DECLARE @ExternalTrans TABLE - ( - [FromItemID] int, - [TransitionID] [int] NOT NULL, - [FromID] [int] NOT NULL, - [ToID] [int] NOT NULL, - [RangeID] [int] NOT NULL, - [Config] [nvarchar](max) NULL - ) - SET NOCOUNT ON - DECLARE @DeleteID int - INSERT INTO DeleteLog (UserID) VALUES (@UserID) - SELECT @DeleteID = SCOPE_IDENTITY() - SELECT @ContentID = ContentID, @PreviousItemID = PreviousID FROM Items WHERE ItemID = @ItemID - SELECT @NextItemID = ItemID FROM Items WHERE PreviousID = @ItemID - --SELECT @ExternalCount = count(*) FROM vefn_FindExternalTransitions(@ItemID) - SELECT @ExternalChildCount = count(*) FROM vefn_FindExternalChildTransitions(@ItemID) - SET @Path = [dbo].[ve_GetShortPath](@ItemID) - - --IF @ExternalCount > 0 AND @NextItemID is null - --BEGIN - -- RAISERROR ('###Cannot Delete Item###Step %d has External Transitions and has no next step - (%s)',16,1,@ItemID,@Path) - -- RETURN - --END - - IF @ExternalChildCount > 0 - BEGIN - RAISERROR ('###Cannot Delete Item###Step %d has External Transitions to it''s children - (%s)',16,1,@ItemID,@Path) - RETURN - END - - -- Copy the item, 'NewItemID' represents the new item(s) - -- DestFormatID is the formatid for the destination parent's format - DECLARE @DestFormatID int - SET @DestFormatID = .dbo.vefn_GetInheritedFormat(@ItemID, 0) - EXECUTE ReplaceItemAndChildren @StartItemID, @DestFormatID, @UserID, @NewItemID OUTPUT - - -- Adjust the next/previous to point to the new item - - DECLARE @PreviousID int - SELECT @PreviousID = [PreviousID] - FROM [ITEMS] II - WHERE [ItemID]=@ItemID - UPDATE [ITEMS] SET [PreviousID]=@PreviousID where [ItemID]=@NewItemID - UPDATE [CONTENTS] SET [Type]=@Type - FROM [CONTENTS] CC JOIN [ITEMS] ii ON CC.[ContentID]=II.[ContentID] - WHERE [ItemID]=@NewItemID - UPDATE [ITEMS] SET [PreviousID]=@NewItemID where [PreviousID]=@ItemID - UPDATE [PARTS] SET [ItemID]=@NewItemID where [ItemID]=@ItemID - - -- UPDATE DocVersion if this was a procedure - UPDATE DocVersions SET ItemID=@NewItemID where ItemID = @ItemID - - -- If there were 'external transitions' that pointed to the original - -- top replaced step, adjust them to point to the new top. - INSERT INTO @ExternalTrans SELECT * FROM vefn_FindExternalTransitions(@ItemID) - OPTION (MAXRECURSION 10000) - IF (SELECT COUNT(*) from @ExternalTrans) > 0 - BEGIN - -- Update content records for the transitions - Update CC - Set Text = DBO.vefn_FixTransitionText(Text,TT.TransitionID,TT.TranType,TT.ToID,TT.RangeID,@ItemID,@NewItemID) - From CONTENTS CC - JOIN Transitions TT ON TT.FromID = CC.ContentID - WHERE TransitionID in(Select TransitionID from @ExternalTrans) - -- Update transitions that point to @ItemID to Point to @NextItemID - UPDATE TRANSITIONS - SET ToID = case when ToID = @ItemID then @NewItemID else ToID END, - RangeID = case when RangeID = @ItemID then @NewItemID else RangeID END - WHERE TransitionID in(Select TransitionID from @ExternalTrans) - - DECLARE @typeID int -- AnnotationType - SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required' - IF(@typeID IS NULL) - BEGIN - INSERT INTO [AnnotationTypes] ([Name],[UserID]) VALUES ('Verification Required','Volian') - SELECT @typeID = SCOPE_IDENTITY() - END - -- Add 'Verification Required' annotions for transtions that pointed to top step - -- and need to point to - INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID]) - SELECT ItemID, @typeID,'Verify Replaced Step Transition Destination',@UserID - FROM Items where ItemID in (SELECT FromItemID FROM @ExternalTrans) - - END - -- Remove the old one - - -- Get list of Children - INSERT INTO @Children SELECT * FROM vefn_ChildItems(@ItemID) - -- Delete Annotations for @ItemID and children - DELETE from Annotations where ItemID in(Select ItemID from @Children) - -- Delete Details associated with @ContentID and children - DELETE from Details where ContentID in(Select ContentID from @Children) - -- Delete Grids associated with @ContentID and children - DELETE from Grids where ContentID in(Select ContentID from @Children) - -- Delete Images associated with @ContentID and children - DELETE from Images where ContentID in(Select ContentID from @Children) - -- Delete Entries associated with @ContentID and children - DELETE from Entries where ContentID in(Select ContentID from @Children) - -- Delete ROUsages associated with @ContentID and children - DELETE from RoUsages where ContentID in(Select ContentID from @Children) - -- Delete ZTransitions records associated with @ContentID and children - DELETE FROM ZTransitions where TransitionID - in(SELECT TransitionID from Transitions where FromID in(SELECT ContentID FROM @Children) or FromID = @ContentID) - -- Delete Transitions associated with @ContentID and children - DELETE FROM Transitions where FromID in(SELECT ContentID FROM @Children) or FromID = @ContentID - -- Delete Parts associated with @ContentID and children - DELETE from Parts where ContentID in(Select ContentID from @Children) - -- Delete ZContents associated with @ContentID and children - DELETE from ZContents where ContentID in(Select ContentID from @Children) - -- Disconnect Items from Each Other - DELETE from Items where ItemID in(Select ItemID from @Children) and PreviousID Is Not Null - -- Disconnect Items to be deleted from each other - Update Items set PreviousID = null where ItemID in (Select ItemID from @Children) and PreviousID Is Not Null - -- Delete Item Records - DELETE from Items where ItemID in(Select ItemID from @Children) - -- DELETE Contents - DELETE from Contents where ContentID in(Select ContentID from @Children) ---delete from itemaudits where itemid = @newitemid -delete from itemaudits where itemid in (select itemid from vefn_ChildItems(@newitemid)) ---delete from contentaudits where contentid = (select contentid from items where itemid = @newitemid) -delete from contentaudits where contentid in (select contentid from vefn_ChildItems(@newitemid)) - DELETE from DeleteLog where DeleteID = @DeleteID - IF( @@TRANCOUNT > 0 ) COMMIT - EXECUTE GetItem @NewItemID -END TRY -BEGIN CATCH -- Catch Block - IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level - ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback - EXEC vlnErrorHandler -END CATCH -go - - - - - - IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[CopyItemAndChildren]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) DROP PROCEDURE [CopyItemAndChildren]; GO @@ -23603,6 +23209,707 @@ GO ========================================================================================================== */ +/* +========================================================================================================== + Start: C2017-031: SQL to allow copy/replace enhanced step +========================================================================================================== +*/ + +IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'PasteItemEnhancedReplace') +DROP PROCEDURE [dbo].PasteItemEnhancedReplace +GO + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2024 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +create PROCEDURE [dbo].[PasteItemEnhancedReplace] +( + @ItemID int=null, -- item to replace (keep this item, only copy over children) + @StartItemID int=null, -- item to copy (children only) + @Type int=null, @DTS datetime, @UserID nvarchar(100), + @NewItemID int output +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + DECLARE @ContentID AS INT + DECLARE @NextItemID AS INT + DECLARE @PreviousItemID AS INT + DECLARE @ExternalChildCount AS INT + DECLARE @ExternalCount AS INT + DECLARE @Path AS VARCHAR(MAX) + DECLARE @Children AS TABLE + ( + ItemID INT PRIMARY KEY, + ContentID INT + ) + + if exists (select * from tblitems where itemid = @StartItemID and DeleteStatus !=0) + BEGIN + RAISERROR ('###Cannot Paste Step###This current step has been deleted in another session',16,1) + RETURN + END + + -- First check if the replaced item can be deleted, i.e. it doesn't have transitions + -- pointing to it or children. + DECLARE @ExternalTrans TABLE + ( + [FromItemID] int, + [TransitionID] [int] NOT NULL, + [FromID] [int] NOT NULL, + [ToID] [int] NOT NULL, + [RangeID] [int] NOT NULL, + [Config] [nvarchar](max) NULL + ) + SET NOCOUNT ON + DECLARE @DeleteID int + INSERT INTO DeleteLog (UserID) VALUES (@UserID) + SELECT @DeleteID = SCOPE_IDENTITY() + SELECT @ContentID = ContentID, @PreviousItemID = PreviousID FROM Items WHERE ItemID = @StartItemID + SELECT @NextItemID = ItemID FROM Items WHERE PreviousID = @StartItemID + -- Need to delete children of the item being replaced, see if they can be deleted, i.e. no external transitions + SELECT @ExternalChildCount = count(*) FROM vefn_FindExternalChildTransitions(@ItemID) + SET @Path = [dbo].[ve_GetShortPath](@ItemID) + IF @ExternalChildCount > 0 + BEGIN + RAISERROR ('###Cannot Delete Item###Step %d has External Transitions to it''s children - (%s)',16,1,@ItemID,@Path) + RETURN + END + + -- Delete all children of this item that is being replaced, after the delete a query is run that will + -- copy the children to this + -- Get list of Children + INSERT INTO @Children SELECT * FROM vefn_ChildItems(@ItemID) + DELETE from @Children where ItemID = @ItemID + + -- Copy the children of the copied item below this enhanced item + -- DestFormatID is the formatid for the destination parent's format + DECLARE @DestFormatID int + SET @DestFormatID = .dbo.vefn_GetInheritedFormat(@StartItemID, 0) + --EXECUTE CopyChildrenEnhanced @ItemID, @StartItemID, 206, @UserID + EXECUTE CopyChildrenEnhanced @ItemID, @StartItemID, @DestFormatID, @UserID + Set @NewItemID = @ItemID + -- Delete Annotations for @ItemID and children + DELETE from Annotations where ItemID in(Select ItemID from @Children) + -- Delete Details associated with @ContentID and children + DELETE from Details where ContentID in(Select ContentID from @Children) + -- Delete Grids associated with @ContentID and children + DELETE from Grids where ContentID in(Select ContentID from @Children) + -- Delete Images associated with @ContentID and children + DELETE from Images where ContentID in(Select ContentID from @Children) + -- Delete Entries associated with @ContentID and children + DELETE from Entries where ContentID in(Select ContentID from @Children) + -- Delete ROUsages associated with @ContentID and children + DELETE from RoUsages where ContentID in(Select ContentID from @Children) + -- Delete ZTransitions records associated with @ContentID and children + DELETE FROM ZTransitions where TransitionID + in(SELECT TransitionID from Transitions where FromID in(SELECT ContentID FROM @Children) or FromID = @ContentID) + -- Delete Transitions associated with @ContentID and children + DELETE FROM Transitions where FromID in(SELECT ContentID FROM @Children) or FromID = @ContentID + -- Delete Parts associated with @ContentID and children + DELETE from Parts where ContentID in(Select ContentID from @Children) + -- Delete ZContents associated with @ContentID and children + DELETE from ZContents where ContentID in(Select ContentID from @Children) + -- Disconnect Items from Each Other + DELETE from Items where ItemID in(Select ItemID from @Children) and PreviousID Is Not Null + -- Disconnect Items to be deleted from each other + Update Items set PreviousID = null where ItemID in (Select ItemID from @Children) and PreviousID Is Not Null + -- Delete Item Records + DELETE from Items where ItemID in(Select ItemID from @Children) + -- DELETE Contents + DELETE from Contents where ContentID in(Select ContentID from @Children) + + DELETE from DeleteLog where DeleteID = @DeleteID + IF( @@TRANCOUNT > 0 ) COMMIT + EXECUTE GetItem @NewItemID +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH + +GO +IF (@@Error = 0) PRINT 'Procedure Creation: [PasteItemEnhancedReplace] Succeeded' +ELSE PRINT 'Procedure Creation: [PasteItemEnhancedReplace] Error on Creation' +GO + +IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'CopyChildrenEnhanced') +DROP PROCEDURE [dbo].CopyChildrenEnhanced +GO + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2024 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +create PROCEDURE [dbo].[CopyChildrenEnhanced] +( + @ItemID INT, -- item to replace children + @StartItemID INT, -- copy the children to ItemID + @DestFormatID INT, + @UserID NVARCHAR(100) +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + +--+-----------------------------------------------------------------+ +--& BEGIN TRANSACTION to make these changes temporary & +--+-----------------------------------------------------------------+ +BEGIN TRANSACTION + +DECLARE @Children AS TABLE +( + ItemID INT PRIMARY KEY, + NewItemID INT, + ContentID INT, + NewContentID INT, + FormatID INT, + NewFormatID INT +) +DECLARE @NewDocuments AS TABLE +( + DocID INT PRIMARY KEY, + NewDocID INT +) +-- Locals +DECLARE @DTS DATETIME -- DTS of all New Items +DECLARE @StartContentID INT +DECLARE @OrigContentID INT +Select @StartContentID = ContentID from Items where ItemID = @StartItemID +select @OrigContentID = ContentID from Items where ItemID= @ItemID +SET @DTS = GETDATE() -- Get the current Date and Time +-- Get a list of all of the Items to be copied based upon StartItemID and EndItemID +-- If the StartItemID = EndItemID then it is a single item and its children + +INSERT INTO @Children SELECT ItemID,ItemID,ContentID,ContentID,FormatID,FormatID FROM vefn_ChildItemsRange(@StartItemID,@StartItemID,null) + where ContentID != @StartContentID + +-- <<< Copy Contents >>> +-- Create new content rows to match the existing rows. Set the type to the Current ContentID temporarily +-- so that the new content rows can be associated with the existing content rows. +INSERT INTO Contents + ([Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID]) + select [Number],[Text],[ContentID],[FormatID],[Config],@DTS,@UserID + from Contents where (ContentID in(Select ContentID from @Children)) + +-- Update the @Children with the NewContentIDs +UPDATE NN set NN.NewContentID = CC.ContentID +From Contents CC +Join @Children NN on NN.ContentID = CC.Type AND CC.DTS = @DTS and CC.UserID = @UserID +-- Reset the Type column in the Contents table with the Type column from the original Records. +DECLARE @SourceType INT +Select @SourceType = Type from Contents where ContentID = @StartContentID +if @SourceType = 0 + BEGIN + UPDATE CC set CC.Type = CC2.Type, CC.DTS = CC2.DTS, CC.UserID = CC2.UserID + From Contents CC + Join @Children NN on NN.NewContentID = CC.ContentID + Join Contents CC2 on NN.ContentID = CC2.ContentID + END +else + BEGIN + UPDATE CC set CC.Type = CC2.Type + From Contents CC + Join @Children NN on NN.NewContentID = CC.ContentID + Join Contents CC2 on NN.ContentID = CC2.ContentID + END +-- Contents are done + +-- <<< Copy Grids >>> +INSERT INTO [Grids]([ContentID],[Data],[Config],[DTS],[UserID]) + SELECT NN.[NewContentID],[Data],[Config],@DTS,@UserID + FROM [Grids] GG Join @Children NN on GG.ContentID = NN.ContentID +-- <<< Copy Images >>> +INSERT INTO [Images]([ContentID],[ImageType],[FileName],[Data],[Config],[DTS],[UserID]) + SELECT NN.[NewContentID],[ImageType],[FileName],[Data],[Config],@DTS,@UserID + FROM [Images] II Join @Children NN on II.ContentID = NN.ContentID + +-- Copy (insert) the item records now +INSERT INTO [Items] ([PreviousID],[ContentID],[DTS],[UserID]) + SELECT II.[PreviousID], -- Leave the PreviousID as is for now + NN.NewContentID, @DTS, @UserID + from @Children NN + join Items II on II.ContentID = NN.ContentID + where ii.ItemID != @ItemID + +-- Update the @Children with the NewItemIDs +UPDATE NN set NN.NewItemID = II.ItemID + From Items II + Join @Children NN on NN.NewContentID = II.ContentID AND II.DTS = @DTS and II.UserID = @UserID + +DECLARE @NewItemID int +SELECT @NewItemID = NewItemID + FROM @Children + WHERE ItemID = @StartItemID + +UPDATE NN SET NN.[NewFormatID] = CC.[FormatID] + FROM @Children NN + Join vefn_ChildItemsRange(@NewItemID,@NewItemID,@DestFormatID) CC + ON NN.NewItemID = CC.ItemID +-- The @Children table is now complete + +-- Update the PreviousID in the new Item rows, to the new ItemIDs based upon the old ItemIDs +Update II Set II.[PreviousID] = NN.NewItemID +from Items II +Join @Children NN on NN.ItemID = II.PreviousID AND II.DTS = @DTS and II.UserID = @UserID +-- Items are done + +-- <<< Copy Parts >>> +UPDATE CC set CC.Type = CC2.Type + From Contents CC + Join @Children NN on NN.NewContentID = CC.ContentID + Join Contents CC2 on NN.ContentID = CC2.ContentID + +INSERT INTO [Parts] ([ContentID],[FromType],[ItemID],[DTS],[UserID]) +Select NNF.NewContentID,[FromType],NNT.NewItemID, @DTS, @UserID from Parts PP +JOIN @Children NNF on PP.ContentID = NNF.ContentID +JOIN @Children NNT on PP.ItemID = NNT.ItemID +where NNT.ItemID != @ItemID + +DECLARE @NewParts AS TABLE +( + ContentID INT, + FromType INT, + ItemID INT +) + +DECLARE @DeleteID int +INSERT INTO DeleteLog (UserID) VALUES (@UserID) +SELECT @DeleteID = SCOPE_IDENTITY() + +DELETE from tblParts where ContentID = @OrigContentID +INSERT into @NewParts SELECT ContentID, FromType, ItemID from Parts where ContentID = @StartContentID +UPDATE PP set PP.ItemID = NN.NewItemID, PP.ContentID = @OrigContentID +FROM @NewParts PP +join @Children NN on PP.ItemID = NN.ItemID + +INSERT INTO [Parts] ([ContentID],[FromType],[ItemID],[DTS],[UserID]) + Select ContentID,[FromType],ItemID, @DTS, @UserID from @NewParts + +-- <<< Copy Annotations >>> +INSERT INTO [Annotations] ([ItemID],[TypeID],[RtfText],[SearchText],[Config],[DTS],[UserID]) + Select NewItemID, TypeID, RtfText, SearchText, Config, @DTS, @UserID + from Annotations AA Join @Children NN on AA.ItemID = NN.ItemID +-- Annotations are done +-- <<< Copy Documents and Entries>>> +-- logic to create Entries for Library Documents +INSERT INTO [Entries] ([ContentID],[DocID],[DTS],[UserID]) + SELECT NN.[NewContentID],EE.[DocID],@DTS,@UserID + FROM [Entries] EE JOIN @Children NN on NN.ContentID = EE.ContentID + JOIN [Documents] DD on EE.[DocID] = DD.[DocID] and Isnull(LibTitle,'') <> '' +-- Logic to create new documents for any documents used that do not have libtitles +INSERT INTO [Documents] ([LibTitle],[DocContent],[DocAscii],[Config],[DTS],[UserID],[FileExtension]) + OUTPUT CAST(INSERTED.[LibTitle] as INT),INSERTED.[DocID] INTO @NewDocuments + SELECT str(DD.[DocID]),[DocContent],[DocAscii],[Config],@DTS,@UserID,[FileExtension] + FROM [Entries] EE JOIN @Children NN on NN.ContentID = EE.ContentID + JOIN [Documents] DD on EE.[DocID] = DD.[DocID] and Isnull(LibTitle,'') = '' +UPDATE DD SET LibTitle = '' + FROM Documents DD JOIN @NewDocuments ND on DD.[DocID] = ND.[NewDocID] + where DTS = @DTS and UserID = @UserID +-- Documents are Done + +-- Logic to create entries for these newly created documents +INSERT INTO [Entries] ([ContentID],[DocID],[DTS],[UserID]) + SELECT NN.[NewContentID],ND.[NewDocID],@DTS,@UserID + FROM [Entries] EE JOIN @Children NN on NN.ContentID = EE.ContentID + JOIN @NewDocuments ND on EE.[DocID] = ND.[DocID] +-- Logic to Create DROUsages for these newly created documents +INSERT INTO [DROUsages] ([DocID],[ROID],[Config],[DTS],[UserID],[RODbID]) + SELECT ND.[NewDocID],[ROID],[Config],@DTS,@UserID,[RODbID] + FROM [DROUsages] RR + JOIN @NewDocuments ND on RR.[DocID] = ND.[DocID] +-- Entries are done + +-- <<< Copy RoUsages >>> +INSERT INTO [RoUsages] ([ContentID],[ROID],[Config],[DTS],[UserID],[RODbID]) + SELECT NN.[NewContentID],CAST([ROUsageID] as nvarchar(16)),[Config],@DTS,@UserID,[RODbID] + FROM [RoUsages] RR Join @Children NN on RR.ContentID = NN.ContentID +-- Update content records for newly copied records to use correct RO usage ids in the RO tags +DECLARE @RowsAffected int +SET @RowsAffected=1 +WHILE @RowsAffected > 0 +BEGIN + UPDATE CC SET [TEXT] = C2.NewText + FROM CONTENTS CC + JOIN (SELECT C1.ContentID, .dbo.vefn_FixROText(C1.Text, CAST([ROID] as int), [ROUsageID]) NewText + FROM CONTENTS C1 + JOIN @Children NN on C1.ContentID = NN.NewContentID + JOIN RoUsages RO on NN.NewContentID = RO.ContentID where Len([ROID]) < 12) C2 ON CC.ContentID = C2.ContentID + WHERE [TEXT] <> C2.NewText + SET @RowsAffected = @@RowCount +END +-- Update grid records for newly copied records to use correct RO usage ids in the RO tags +SET @RowsAffected=1 +WHILE @RowsAffected > 0 +BEGIN + UPDATE GG SET [Data] = G2.NewData + FROM GRIDS GG + JOIN (SELECT G1.ContentID, .dbo.vefn_FixROData(G1.Data, CAST([ROID] as int), [ROUsageID]) NewData + FROM GRIDS G1 + JOIN @Children NN on G1.ContentID = NN.NewContentID + JOIN RoUsages RO on NN.NewContentID = RO.ContentID where Len([ROID]) < 12) G2 ON GG.ContentID = G2.ContentID + WHERE Cast([Data] as nvarchar(max)) <> cast(G2.NewData as nvarchar(max)) + SET @RowsAffected = @@RowCount +END +UPDATE RON SET [ROID] = ROO.[ROID] + FROM RoUsages RON + JOIN @Children NN on RON.ContentID = NN.NewContentID + JOIN RoUsages ROO on CAST(RON.ROID as int) = ROO.RoUsageID + where Len(RON.[ROID]) < 12 +-- RoUsages are done + +-- <<< Copy Transtions >>> +-- Note that the inserted record has the 'TranType' field set to old transitionid. This is done +-- so that the next step can replace the old transitionid with the new transitionid in the +-- content record's transition tokens. The TranType gets reset after the content records are +-- updated. +-- Also note that the 'toid/rangeid' may need converted to newly copied ids or may not. If it's +-- not a range, then it always is converted to new, if there is a new. If it's a range, both +-- the toid & the rangeid must be new in order for the conversion to be correct. You cannot +-- have part of the range pointing to the new and part of the range pointing to the original +-- locations. + +INSERT INTO .[dbo].[Transitions] ([FromID],[ToID],[RangeID],[IsRange],[TranType],[Config],[DTS],[UserID]) + SELECT NNF.[NewContentID], + -- if both toid & range are null, use the original toid & rangeid + CASE WHEN NNT.[NewItemID] is null or NNR.[NewItemID] is null THEN [ToID] ELSE NNT.[NewItemID] END, + CASE WHEN NNT.[NewItemID] is null or NNR.[NewItemID] is null THEN [RangeID] ELSE NNR.[NewItemID] END, + [IsRange],[TransitionID],[Config],@DTS,@UserID + FROM .[dbo].[Transitions] TT + JOIN @Children NNF on TT.[FromID] = NNF.[ContentID] + LEFT JOIN @Children NNT on TT.[ToID] = NNT.[ItemID] + LEFT JOIN @Children NNR on TT.[RangeID] = NNR.[ItemID] +-- -- Update content records for newly copied records to use correct TransitionIDs in the Transition tags +SET @RowsAffected=1 +WHILE @RowsAffected > 0 +BEGIN +UPDATE CC SET [TEXT] = C2.NewText + FROM CONTENTS CC + JOIN (SELECT C1.ContentID, .dbo.vefn_FixTransitionTextForCopy(C1.Text, TRO.TransitionID, TRO.TranType, TRO.[ToID], TRO.[RangeID],TR.[TransitionID], TR.[ToID], TR.[RangeID], .dbo.vefn_GetNewTranType(NN.FormatID, NN.NewFormatID, TRO.TranType)) NewText + FROM CONTENTS C1 + JOIN @Children NN on C1.ContentID = NN.NewContentID + JOIN Transitions TR on NN.NewContentID = TR.FromID + JOIN Transitions TRO on TR.TranType = TRO.TransitionID) C2 ON CC.ContentID = C2.ContentID + WHERE [TEXT] <> C2.NewText + SET @RowsAffected = @@RowCount +END +--set nocount off +-- -- Update grid records for newly copied records to use correct TransitionIDs in the Transition tags +declare @grids table +( +contentid int primary key, +data xml +) +insert into @grids select gg.contentid,gg.data from GRIDS GG + where gg.contentid in (select nn.newcontentid from + @Children NN + JOIN Transitions TR on NN.NewContentID = TR.FromID + JOIN Transitions TRO on TR.TranType = TRO.TransitionID) + +SET @RowsAffected=1 +WHILE @RowsAffected > 0 +BEGIN +UPDATE GG SET [DATA] = G2.NewData + FROM @GRIDS GG + JOIN (SELECT G1.ContentID, .dbo.vefn_FixTransitionDataForCopy(G1.Data, TRO.TransitionID, TRO.TranType, TRO.[ToID], TRO.[RangeID],TR.[TransitionID], TR.[ToID], TR.[RangeID], .dbo.vefn_GetNewTranType(NN.FormatID, NN.NewFormatID, TRO.TranType)) NewData + FROM @GRIDS G1 + JOIN @Children NN on G1.ContentID = NN.NewContentID + JOIN Transitions TR on NN.NewContentID = TR.FromID + JOIN Transitions TRO on TR.TranType = TRO.TransitionID) G2 ON GG.ContentID = G2.ContentID + WHERE Cast([DATA] as nvarchar(max)) <> CAST(G2.NewData as nvarchar(max)) + SET @RowsAffected = @@RowCount +END +update GG set data = g1.data from Grids gg join @grids g1 on gg.contentid = g1.contentid +-- Add 'Verification Required' AnnotationType + DECLARE @typeID int + SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required' + IF(@typeID IS NULL) + BEGIN + INSERT INTO [AnnotationTypes] ([Name],[UserID]) VALUES ('Verification Required','Volian') + SELECT @typeID = SCOPE_IDENTITY() + END + -- Add "Verification Required" Annotation for each Transition whose transition format changes +INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID]) + SELECT NN.NewItemID, @typeID,'Verify Transition Format',@UserID + FROM Transitions TR + JOIN @Children NN on TR.FromID = NN.NewContentID + JOIN Transitions TRO on TR.TranType = TRO.TransitionID + WHERE .dbo.vefn_CompareTranFormat(NN.FormatID, NN.NewFormatID, TRO.TranType) <> 0 + +UPDATE TR SET TR.[TranType] = .dbo.vefn_GetNewTranType(NN.FormatID, NN.NewFormatID, TRO.TranType) + FROM Transitions TR + JOIN @Children NN on TR.FromID = NN.NewContentID + JOIN Transitions TRO on TR.TranType = TRO.TransitionID +-- Transitions are done + + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH + +GO +IF (@@Error = 0) PRINT 'Procedure Creation: [CopyChildrenEnhanced] Succeeded' +ELSE PRINT 'Procedure Creation: [CopyChildrenEnhanced] Error on Creation' +GO + +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_RemoveEnhanced]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [vefn_RemoveEnhanced]; +GO +/****** Object: UserDefinedFunction [dbo].[vefn_RemoveEnhanced] Script Date: 09/26/2024 14:31:13 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +/* +C2017-031 Remove Enhanced Tag from Configuration + Used in cases where a Paste/Replace is done from an Enhanced item + over top of a non-enhanced item. + see PasteItemReplace for usage +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2024 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE function [dbo].[vefn_RemoveEnhanced](@config varchar(max)) +returns varchar(max) +begin + + DECLARE @xconfigNew XML = cast(@config as xml) + SET @xconfigNew.modify('delete //Enhanced[1]'); + return cast(@xconfigNew As nvarchar(max)) +end + +GO + +-- Display the status +IF (@@Error = 0) PRINT 'ScalerFunction [vefn_RemoveEnhanced] Succeeded' +ELSE PRINT 'ScalerFunction [vefn_RemoveEnhanced] Error on Creation' +go + +------------------------------------------------------------------------------ + +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[PasteItemReplace]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [PasteItemReplace]; +GO + + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/****** Object: StoredProcedure [dbo].[PasteItemReplace] Script Date: 03/20/2012 16:02:54 ******/ +/* +declare @NewItemID int +declare @dts datetime +set @newitemid = 0 +set @dts = getdate() +exec PasteItemReplace 398,397,20014,@dts,'bodine',@NewItemID output +*/ +-- ItemID is item to replace +-- StartItemID is item to copy +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2024 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE OR ALTER PROCEDURE [dbo].[PasteItemReplace] +( + @ItemID int=null, @StartItemID int=null, + @Type int=null, @DTS datetime, @UserID nvarchar(100), + @NewItemID int output +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + DECLARE @ContentID AS INT + DECLARE @NextItemID AS INT + DECLARE @PreviousItemID AS INT + DECLARE @ExternalChildCount AS INT + DECLARE @ExternalCount AS INT + DECLARE @Path AS VARCHAR(MAX) + DECLARE @Children AS TABLE + ( + ItemID INT PRIMARY KEY, + ContentID INT + ) + + if exists (select * from tblitems where itemid = @ItemID and DeleteStatus !=0) + BEGIN + RAISERROR ('###Cannot Paste Step###This current step has been deleted in another session',16,1) + RETURN + END + -- First check if the replaced item can be deleted, i.e. it doesn't have transitions + -- pointing to it or children. + + DECLARE @ExternalTrans TABLE + ( + [FromItemID] int, + [TransitionID] [int] NOT NULL, + [FromID] [int] NOT NULL, + [ToID] [int] NOT NULL, + [RangeID] [int] NOT NULL, + [Config] [nvarchar](max) NULL + ) + SET NOCOUNT ON + DECLARE @DeleteID int + INSERT INTO DeleteLog (UserID) VALUES (@UserID) + SELECT @DeleteID = SCOPE_IDENTITY() + SELECT @ContentID = ContentID, @PreviousItemID = PreviousID FROM Items WHERE ItemID = @ItemID + SELECT @NextItemID = ItemID FROM Items WHERE PreviousID = @ItemID + --SELECT @ExternalCount = count(*) FROM vefn_FindExternalTransitions(@ItemID) + SELECT @ExternalChildCount = count(*) FROM vefn_FindExternalChildTransitions(@ItemID) + SET @Path = [dbo].[ve_GetShortPath](@ItemID) + + --IF @ExternalCount > 0 AND @NextItemID is null + --BEGIN + -- RAISERROR ('###Cannot Delete Item###Step %d has External Transitions and has no next step - (%s)',16,1,@ItemID,@Path) + -- RETURN + --END + + IF @ExternalChildCount > 0 + BEGIN + RAISERROR ('###Cannot Delete Item###Step %d has External Transitions to it''s children - (%s)',16,1,@ItemID,@Path) + RETURN + END + + -- Copy the item, 'NewItemID' represents the new item(s) + -- DestFormatID is the formatid for the destination parent's format + DECLARE @DestFormatID int + SET @DestFormatID = .dbo.vefn_GetInheritedFormat(@ItemID, 0) + EXECUTE ReplaceItemAndChildren @StartItemID, @DestFormatID, @UserID, @NewItemID OUTPUT + + --CSM C2017-031 - If Paste/Replacing from Linked Step over top of a non-linked Step + --then remove the link from the copy + --if original item was not linked, update new items to not be linked + DECLARE @xconfig XML = (Select cast(config as xml) xconfig from Contents where ContentID = @ContentID); + IF @xconfig.exist('//Enhanced[1]') = 0 + BEGIN + UPDATE Contents SET Config = dbo.vefn_RemoveEnhanced(Contents.Config) + Where ContentID in (Select ContentID FROM vefn_ChildItems(@NewItemID)) + --Where ContentID in (Select ContentID FROM Items where ItemID = @NewItemID) + END + + -- Adjust the next/previous to point to the new item + + DECLARE @PreviousID int + SELECT @PreviousID = [PreviousID] + FROM [ITEMS] II + WHERE [ItemID]=@ItemID + UPDATE [ITEMS] SET [PreviousID]=@PreviousID where [ItemID]=@NewItemID + UPDATE [CONTENTS] SET [Type]=@Type + FROM [CONTENTS] CC JOIN [ITEMS] ii ON CC.[ContentID]=II.[ContentID] + WHERE [ItemID]=@NewItemID + UPDATE [ITEMS] SET [PreviousID]=@NewItemID where [PreviousID]=@ItemID + UPDATE [PARTS] SET [ItemID]=@NewItemID where [ItemID]=@ItemID + + -- UPDATE DocVersion if this was a procedure + UPDATE DocVersions SET ItemID=@NewItemID where ItemID = @ItemID + + -- If there were 'external transitions' that pointed to the original + -- top replaced step, adjust them to point to the new top. + INSERT INTO @ExternalTrans SELECT * FROM vefn_FindExternalTransitions(@ItemID) + OPTION (MAXRECURSION 10000) + IF (SELECT COUNT(*) from @ExternalTrans) > 0 + BEGIN + -- Update content records for the transitions + Update CC + Set Text = DBO.vefn_FixTransitionText(Text,TT.TransitionID,TT.TranType,TT.ToID,TT.RangeID,@ItemID,@NewItemID) + From CONTENTS CC + JOIN Transitions TT ON TT.FromID = CC.ContentID + WHERE TransitionID in(Select TransitionID from @ExternalTrans) + -- Update transitions that point to @ItemID to Point to @NextItemID + UPDATE TRANSITIONS + SET ToID = case when ToID = @ItemID then @NewItemID else ToID END, + RangeID = case when RangeID = @ItemID then @NewItemID else RangeID END + WHERE TransitionID in(Select TransitionID from @ExternalTrans) + + DECLARE @typeID int -- AnnotationType + SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required' + IF(@typeID IS NULL) + BEGIN + INSERT INTO [AnnotationTypes] ([Name],[UserID]) VALUES ('Verification Required','Volian') + SELECT @typeID = SCOPE_IDENTITY() + END + -- Add 'Verification Required' annotions for transtions that pointed to top step + -- and need to point to + INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID]) + SELECT ItemID, @typeID,'Verify Replaced Step Transition Destination',@UserID + FROM Items where ItemID in (SELECT FromItemID FROM @ExternalTrans) + + END + -- Remove the old one + + -- Get list of Children + INSERT INTO @Children SELECT * FROM vefn_ChildItems(@ItemID) + -- Delete Annotations for @ItemID and children + DELETE from Annotations where ItemID in(Select ItemID from @Children) + -- Delete Details associated with @ContentID and children + DELETE from Details where ContentID in(Select ContentID from @Children) + -- Delete Grids associated with @ContentID and children + DELETE from Grids where ContentID in(Select ContentID from @Children) + -- Delete Images associated with @ContentID and children + DELETE from Images where ContentID in(Select ContentID from @Children) + -- Delete Entries associated with @ContentID and children + DELETE from Entries where ContentID in(Select ContentID from @Children) + -- Delete ROUsages associated with @ContentID and children + DELETE from RoUsages where ContentID in(Select ContentID from @Children) + -- Delete ZTransitions records associated with @ContentID and children + DELETE FROM ZTransitions where TransitionID + in(SELECT TransitionID from Transitions where FromID in(SELECT ContentID FROM @Children) or FromID = @ContentID) + -- Delete Transitions associated with @ContentID and children + DELETE FROM Transitions where FromID in(SELECT ContentID FROM @Children) or FromID = @ContentID + -- Delete Parts associated with @ContentID and children + DELETE from Parts where ContentID in(Select ContentID from @Children) + -- Delete ZContents associated with @ContentID and children + DELETE from ZContents where ContentID in(Select ContentID from @Children) + -- Disconnect Items from Each Other + DELETE from Items where ItemID in(Select ItemID from @Children) and PreviousID Is Not Null + -- Disconnect Items to be deleted from each other + Update Items set PreviousID = null where ItemID in (Select ItemID from @Children) and PreviousID Is Not Null + -- Delete Item Records + DELETE from Items where ItemID in(Select ItemID from @Children) + -- DELETE Contents + DELETE from Contents where ContentID in(Select ContentID from @Children) +--delete from itemaudits where itemid = @newitemid +delete from itemaudits where itemid in (select itemid from vefn_ChildItems(@newitemid)) +--delete from contentaudits where contentid = (select contentid from items where itemid = @newitemid) +delete from contentaudits where contentid in (select contentid from vefn_ChildItems(@newitemid)) + DELETE from DeleteLog where DeleteID = @DeleteID + IF( @@TRANCOUNT > 0 ) COMMIT + EXECUTE GetItem @NewItemID +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO + +IF (@@Error = 0) PRINT 'Procedure Creation: [PasteItemReplace] Succeeded' +ELSE PRINT 'Procedure Creation: [PasteItemReplace] Error on Creation' +GO +/* +========================================================================================================== + End: C2017-031: SQL to allow copy/replace enhanced step +========================================================================================================== +*/ + /* --------------------------------------------------------------------------- | ADD New Code Before this Block | @@ -23636,8 +23943,8 @@ BEGIN TRY -- Try Block DECLARE @RevDate varchar(255) DECLARE @RevDescription varchar(255) - set @RevDate = '07/29/2024 11:24' - set @RevDescription = 'C2021-059 Add SQL for Admin tool delete folders.' + set @RevDate = '09/26/2024 11:24' + set @RevDescription = 'SQL to allow copy/replace enhanced step.' Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index 555dd6d3..ab53804d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -1942,16 +1942,63 @@ namespace VEPROMS.CSLA.Library using (Item ii = this.Get()) { ProcedureConfig sc = this.MyConfig as ProcedureConfig; - sc.AddEnhancedDocument(enhtype, enhii.ItemID); - sc.SaveEnhancedDocuments(); - ii.MyContent.Config = sc.ToString(); - ii.Save(); - RefreshConfig(); + sc.AddEnhancedDocument(enhtype, enhii.ItemID); + sc.SaveEnhancedDocuments(); + ii.MyContent.Config = sc.ToString(); + ii.Save(); + RefreshConfig(); } } } #endregion #region DataPortal + // C2017-031: Support for paste/replace an enhanced step + private void DataPortal_Fetch(PastingPartEnhancedCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + Csla.ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.Parameters.AddWithValue("@StartItemID", criteria.StartItemID); // copy children + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); //copy to + cm.Parameters.AddWithValue("@Type", criteria.Type); + cm.Parameters.AddWithValue("@DTS", criteria.DTS); + cm.Parameters.AddWithValue("@UserID", criteria.UserID); + SqlParameter param_ContentID = new SqlParameter("@NewItemID", SqlDbType.Int); + param_ContentID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ContentID); + cm.CommandText = "PasteItemEnhancedReplace"; + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (Csla.ApplicationContext.ExecutionLocation == Csla.ApplicationContext.ExecutionLocations.Client) + Csla.ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (!ex.Message.Contains("This step has been deleted") && !ex.Message.Contains("This current step has been deleted in another session")) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex); + } + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); + } + } private void DataPortal_Fetch(PastingPartCriteria criteria) { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode()); @@ -2073,9 +2120,72 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); } } + #endregion + #region PastingPartEnhancedCriteria + // C2017-031: Support for paste/replace an enhanced step + [Serializable()] + public class PastingPartEnhancedCriteria + { + #region Properties + private int _StartItemID; + public int StartItemID + { + get { return _StartItemID; } + set { _StartItemID = value; } + } + private int _ItemID; // paste relative to this itemid + public int ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + private EAddpingPart _AddType; + public EAddpingPart AddType + { + get { return _AddType; } + set { _AddType = value; } + } + private int? _FromType = null; + public int? FromType + { + get { return _FromType; } + set { _FromType = value; } + } + private int? _Type = null; + public int? Type + { + get { return _Type; } + set { _Type = value; } + } + private DateTime _DTS; + public DateTime DTS + { + get { return _DTS; } + set { _DTS = value; } + } + private string _UserID; + public string UserID + { + get { return _UserID; } + set { _UserID = value; } + } + #endregion + #region Constructor + public PastingPartEnhancedCriteria(int startItemid, int itemID, EAddpingPart addType, int? type, int? fromType, DateTime dts, string userID) + { + _StartItemID = startItemid; + _ItemID = itemID; + _AddType = addType; + _Type = type; + _FromType = fromType; + _DTS = dts; + _UserID = userID; + } #endregion - #region PastingPartCriteria - [Serializable()] + } + #endregion + #region PastingPartCriteria + [Serializable()] public class PastingPartCriteria { #region Properties @@ -2364,6 +2474,14 @@ namespace VEPROMS.CSLA.Library _MyPrevious = null; // Reset list so that the next line gets a new list if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value } + // C2017-031: Support for paste/replace an enhanced step + internal static ItemInfo CopyPasteReplaceEnhancedItemInfoFetch(int copyStartID, ItemInfo itemInfo) + { + ItemInfo tmp = null; + tmp = DataPortal.Fetch(new ItemInfo.PastingPartEnhancedCriteria(copyStartID, itemInfo.ItemID, ItemInfo.EAddpingPart.Replace, itemInfo.MyContent.Type, itemInfo.MyContent.Type, DateTime.Now, Volian.Base.Library.VlnSettings.UserID)); + AddToCache(tmp); + return tmp; + } internal static ItemInfo CopyPasteReplaceItemInfoFetch(int copyStartID, ItemInfo itemInfo) // int itemID, int? type, int? fromType) { ItemInfo tmp = null; @@ -2525,8 +2643,16 @@ namespace VEPROMS.CSLA.Library ItemInfo newItemInfo = null; try { - newItemInfo = ItemInfo.CopyPasteReplaceItemInfoFetch(copyStartID, itemInfo); //itemInfo.ItemID, itemInfo.MyContent.Type, itemInfo.MyContent.Type); - if (newItemInfo == null) return null; + // C2017-031: Support for paste/replace an enhanced step, if this is replacing enhanced, do a specific query + if (itemInfo.IsEnhancedStep) + { + newItemInfo = ItemInfo.CopyPasteReplaceEnhancedItemInfoFetch(copyStartID, itemInfo); + if (newItemInfo == null) return null; + } + else + { + newItemInfo = ItemInfo.CopyPasteReplaceItemInfoFetch(copyStartID, itemInfo); if (newItemInfo == null) return null; + } } catch (Exception ex1) { diff --git a/PROMS/Volian.Controls.Library/EditItem.cs b/PROMS/Volian.Controls.Library/EditItem.cs index dcc6b668..dd3cd75e 100644 --- a/PROMS/Volian.Controls.Library/EditItem.cs +++ b/PROMS/Volian.Controls.Library/EditItem.cs @@ -1944,7 +1944,8 @@ namespace Volian.Controls.Library sia.IdentifyChildren(highlight); } } - if (MyBeforeEditItems != null) + // C2017-031: Support for paste/replace an enhanced step: don't identify/copy before items, i.e. notes/cautions + if (MyBeforeEditItems != null && !MyItemInfo.IsEnhancedStep) { foreach (EditItem sib in MyBeforeEditItems) { diff --git a/PROMS/Volian.Controls.Library/RTBItem.designer.cs b/PROMS/Volian.Controls.Library/RTBItem.designer.cs index fe2d8268a02c27adf13c959606c973e18738e516..89321bc6093f638a336fd75617477ad828743661 100644 GIT binary patch delta 378 zcmYjM%}PRH5Iq<9ZYb(D2!bnuCge}G5W-ywwhMiN&|6;6+bzqTxHNEgrw4G|D(O9{ z2XNV{r|5hms0@5_=FB-W^Zm}9c;S5f82QS$vn!mVhBMSrX1*Z0gvaRO1rg%`Pk3g1 zr^q97i!m7=Rd#&VLoz)gk2&P)^BpL*Y@f_VAK{d^&p9EAI+OkxMkFR`_ce!XjVZLU z3{psHRJkt6&H#aS13h8HK~~#SwLQwZcdmeEdpJQ3O)3I*?{TyJK!^I{{rd|jP@dba zsmQlE%wKawi`M-=b#;A&67@Vy9uswGo2 DmxxH+ delta 34 pcmbQ#&G@99al-}H$z~i Date: Wed, 2 Oct 2024 11:31:04 -0400 Subject: [PATCH 2/2] B2024-075 Correct Linking and Numbering when utilizing Paste Before and Paste After with Enhanced Steps as well as some related UI refresh issues. --- .../Extension/ItemInsertExt.cs | 47 +++++--- PROMS/Volian.Controls.Library/EditItem.cs | 103 +++++++++++++++++- .../Volian.Controls.Library/StepTabRibbon.cs | 4 +- 3 files changed, 132 insertions(+), 22 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index ab53804d..9838ca98 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -1876,6 +1876,10 @@ namespace VEPROMS.CSLA.Library if (IsCaution) enhType = 20006; return enhType; } + + // B2024-075: Paste Before/After with Enhanced Documents is creating situation + //where Background item is linked to Source but Source is not linked to Background + //When Fixing the linking, need to not create a duplicate link if one already exists public void DoCreateLinksEnhancedSingleItem(ItemInfo enhii, int enhtype) { // Link the 2 items, srcII & enhii: @@ -1893,12 +1897,15 @@ namespace VEPROMS.CSLA.Library using (Item ei = Item.Get(enhii.ItemID)) { StepConfig sc = enhii.MyConfig as StepConfig; - sc.AddEnhancedDocument(0, this.ItemID); - sc.SaveEnhancedDocuments(); - ei.MyContent.Text = DisplayText; - ei.MyContent.Config = sc.ToString(); - ei.Save(); - enhii.RefreshConfig(); + if (!sc.MyEnhancedDocuments.Exists(x => x.Type == 0)) + { + sc.AddEnhancedDocument(0, this.ItemID); + sc.SaveEnhancedDocuments(); + ei.MyContent.Text = DisplayText; + ei.MyContent.Config = sc.ToString(); + ei.Save(); + enhii.RefreshConfig(); + } } } else if (IsSection) @@ -1916,12 +1923,15 @@ namespace VEPROMS.CSLA.Library using (Item ei = Item.Get(enhii.ItemID)) { SectionConfig sc = enhii.MyConfig as SectionConfig; - sc.AddEnhancedDocument(0, this.ItemID); - sc.SaveEnhancedDocuments(); - ei.MyContent.Text = DisplayText; - ei.MyContent.Config = sc.ToString(); - ei.Save(); - enhii.RefreshConfig(); + if (!sc.MyEnhancedDocuments.Exists(x => x.Type == 0)) + { + sc.AddEnhancedDocument(0, this.ItemID); + sc.SaveEnhancedDocuments(); + ei.MyContent.Text = DisplayText; + ei.MyContent.Config = sc.ToString(); + ei.Save(); + enhii.RefreshConfig(); + } } } else if (IsProcedure) @@ -1942,11 +1952,14 @@ namespace VEPROMS.CSLA.Library using (Item ii = this.Get()) { ProcedureConfig sc = this.MyConfig as ProcedureConfig; - sc.AddEnhancedDocument(enhtype, enhii.ItemID); - sc.SaveEnhancedDocuments(); - ii.MyContent.Config = sc.ToString(); - ii.Save(); - RefreshConfig(); + if (!sc.MyEnhancedDocuments.Exists(x => x.Type == 0)) + { + sc.AddEnhancedDocument(enhtype, enhii.ItemID); + sc.SaveEnhancedDocuments(); + ii.MyContent.Config = sc.ToString(); + ii.Save(); + RefreshConfig(); + } } } } diff --git a/PROMS/Volian.Controls.Library/EditItem.cs b/PROMS/Volian.Controls.Library/EditItem.cs index d722af27..27d89bd4 100644 --- a/PROMS/Volian.Controls.Library/EditItem.cs +++ b/PROMS/Volian.Controls.Library/EditItem.cs @@ -9,6 +9,7 @@ using System.Text.RegularExpressions; using VEPROMS.CSLA.Library; using Volian.Base.Library; using JR.Utils.GUI.Forms; +using System.Linq; namespace Volian.Controls.Library { @@ -893,6 +894,18 @@ namespace Volian.Controls.Library b4topadjust -= newFocus.Top; TopMostYBefore -= b4topadjust; + //B2024-075: If Deleting an item in a Source Document that is unlinked + //and the overall procedure has connected Background Documents + //and a window is open containing the background documents + //then need to force a refresh on that window as + //step numbering will shift + EnhancedDocuments ProcEnh = MyItemInfo.MyProcedure.GetMyEnhancedDocuments(); + if (ProcEnh.Count > 0) + { + DisplayTabItem wndowToRefresh = MyStepPanel.MyStepTabPanel.MyDisplayTabControl.MyBar.Items.Cast().FirstOrDefault(x => x.MyKey == $"Item - {ProcEnh[0].ItemID}"); + wndowToRefresh?.MyStepTabPanel.MyStepPanel.Reset(wndowToRefresh.MyItemInfo); + } + //_MyTimer.ActiveProcess = "Dispose"; Dispose(); //_MyTimer.ActiveProcess = "SetAllTabs"; @@ -1634,10 +1647,54 @@ namespace Volian.Controls.Library MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.Before, newItemInfo.MyContent.Type)); // MyItemInfo is the 'paste from' item, if it has enhanced need to copy and paste the steps in enhanced. - ItemInfo newEnh = newItemInfo.EnhancedPasteItem(copyStartID, MyItemInfo, ItemInfo.EAddpingPart.Before, GetChangeId(MyItemInfo)); + //if doing a paste before/after and item being copied is unlinked, item pasted should also be unlinked. + ItemInfo tmpCopyStartSourceItem = ItemInfo.Get(copyStartID); + ItemInfo newEnh = null; + if (tmpCopyStartSourceItem.GetMyEnhancedDocuments().Count > 0) + { + newEnh = newItemInfo.EnhancedPasteItem(copyStartID, MyItemInfo, ItemInfo.EAddpingPart.Before, GetChangeId(MyItemInfo)); + } + + //B2024-075: When doing Paste Before / After with Enhanced Documents only link from Background document to source was created + //since source is done first + //this is so that after the steps are created in the enhanced, go back and update the link in the source to point to the correct item + if (newEditItem != null && newEnh != null) + { + FixEnhanceLinkOnSource(newEditItem.MyItemInfo, newEnh, MyItemInfo.GetMyEnhancedDocuments()); + } + else if (newEnh == null && newEditItem != null && newEditItem.MyItemInfo.IsEnhancedStep) + { + UnlinkEnhanced(newEditItem); + } + else if (newEnh == null && newEditItem != null) + { + //if did a paste before/after in a source document that contains enhanced steps + //but step being pasted was non-enhanced (unlinked) + //then look to see if the background page is open + //and if it is, do a refresh so that step numbers update appropriately + //without having to close and re-open the background steps + foreach (EnhancedDocument edSource in MyItemInfo.GetMyEnhancedDocuments()) + { + ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); + DisplayTabItem wndowToRefresh = newEditItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.MyBar.Items.Cast().FirstOrDefault(x => x.MyKey == $"Item - {exEnh.MyProcedure.ItemID}"); + wndowToRefresh?.MyStepTabPanel.MyStepPanel.Reset(wndowToRefresh.MyItemInfo); + } + } + // if enhanced items were created, then see if they need displayed: if (newEnh != null) AddAllEnhancedItemsToDisplay(newItemInfo); } + + //B2024-075: When doing Paste Before / After with Enhanced Documents only link from Background document to source was created + //since source is done first + //this is so that after the steps are created in the enhanced, go back and update the link in the source to point to the correct item + //if enhanced document wasn't created then paste happened inside a enhanced Step/background step - so remove any links that shouldn't be there + //and don't have a corresponding spot in the Source + private void FixEnhanceLinkOnSource(ItemInfo SourceItem, ItemInfo newEnhItem, EnhancedDocuments enhancedDocuments) + { + if (enhancedDocuments.Count > 0) + CreateLinksEnhancedSingleItem(SourceItem, newEnhItem, enhancedDocuments[0].Type); + } private void AddAllEnhancedItemsToDisplay(ItemInfo newItemInfo) { EnhancedDocuments eds = newItemInfo.GetMyEnhancedDocuments(); @@ -1684,12 +1741,15 @@ namespace Volian.Controls.Library } } } - public void UnlinkEnhanced(ItemInfo enhII) + public void UnlinkEnhanced(EditItem enhII) { // B2022-049: Copy/paste of enhanced procedure and bad links between source and enhanced // Pass in to unlink as before this change - enhII.DoUnlinkEnhanced(enhII, 0, false); + // B2024 - 075: Change made to pass in an EditTem instead of a ItemInfo + //so can refresh the UI + enhII.MyItemInfo.DoUnlinkEnhanced(enhII.MyItemInfo, 0, false); SetFocus(); + enhII.MyStepPanel.Reset(enhII.MyItemInfo); //need to reset parts so refreshes display to show as unlinked } public ItemInfo AddMissingEnhancedStep(ItemInfo ii, int EnhType) { @@ -1753,7 +1813,42 @@ namespace Volian.Controls.Library MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.After, newItemInfo.MyContent.Type)); // MyItemInfo is the 'paste from' item, if it has enhanced need to copy and paste the steps in enhanced. - ItemInfo newEnh = newItemInfo.EnhancedPasteItem(copyStartID, MyItemInfo, ItemInfo.EAddpingPart.After, GetChangeId(MyItemInfo)); + //if doing a paste before/after and item being copied is unlinked, item pasted should also be unlinked. + ItemInfo tmpCopyStartSourceItem = ItemInfo.Get(copyStartID); + ItemInfo newEnh = null; + if (tmpCopyStartSourceItem.GetMyEnhancedDocuments().Count > 0) + { + newEnh = newItemInfo.EnhancedPasteItem(copyStartID, MyItemInfo, ItemInfo.EAddpingPart.After, GetChangeId(MyItemInfo)); + } + + //B2024-075: When doing Paste Before / After with Enhanced Documents only link from Background document to source was created + //since source is done first + //this is so that after the steps are created in the enhanced, go back and update the link in the source to point to the correct item + //if enhanced document wasn't created then paste happened inside a enhanced Step/background step - so remove any links that shouldn't be there + //and don't have a cooresponding spot in the Source + if (newEditItem != null && newEnh != null) + { + FixEnhanceLinkOnSource(newEditItem.MyItemInfo, newEnh, MyItemInfo.GetMyEnhancedDocuments()); + } + else if (newEnh == null && newEditItem != null && newEditItem.MyItemInfo.IsEnhancedStep) + { + UnlinkEnhanced(newEditItem); + } + else if (newEnh == null && newEditItem != null) + { + //if did a paste before/after in a source document that contains enhanced steps + //but step being pasted was non-enhanced (unlinked) + //then look to see if the background page is open + //and if it is, do a refresh so that step numbers update appropriately + //without having to close and re-open the background steps + foreach (EnhancedDocument edSource in MyItemInfo.GetMyEnhancedDocuments()) + { + ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); + DisplayTabItem wndowToRefresh = newEditItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.MyBar.Items.Cast().FirstOrDefault(x => x.MyKey == $"Item - {exEnh.MyProcedure.ItemID}"); + wndowToRefresh?.MyStepTabPanel.MyStepPanel.Reset(wndowToRefresh.MyItemInfo); + } + } + if (newEnh != null) AddAllEnhancedItemsToDisplay(newItemInfo); } public void PasteChild(int copyStartID) diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.cs index e60698c7..7a041db1 100644 --- a/PROMS/Volian.Controls.Library/StepTabRibbon.cs +++ b/PROMS/Volian.Controls.Library/StepTabRibbon.cs @@ -337,8 +337,10 @@ namespace Volian.Controls.Library else if (btn.Name.Contains("Unlink")) { // C2019=003: add a confirmation dialog before unlinking a step: + // B2024 - 075: Change made to pass in an EditTem instead of a ItemInfo + //so can refresh the UI if (FlexibleMessageBox.Show(this, "Do you want to unlink this step?", "Confirm Enhanced Step Unlink", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - MyEditItem.UnlinkEnhanced(MyEditItem.MyItemInfo); + MyEditItem.UnlinkEnhanced(MyEditItem); } } else -- 2.47.2