Fixed CopyItemAndChildren to support Grids, Images and DROUsages

Removed completed items from the ToDo List at the top of the file
This commit is contained in:
Rich 2011-02-10 22:22:11 +00:00
parent 41c8a90bdf
commit 0ad442ae19
2 changed files with 122 additions and 7 deletions

View File

@ -1972,7 +1972,14 @@ Join @Children NN on NN.NewContentID = CC.ContentID
Join Contents CC2 on NN.ContentID = CC2.ContentID
-- Contents are done
-- SELECT * From Contents where DTS = @DTS and UserID = @UserID
-- <<< Copy Items >>>
-- <<< 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
-- Create new item rows based upon the current item rows and the @Children table, with the NewContentIDs
INSERT INTO [Items] ([PreviousID],[ContentID],[DTS],[UserID])
SELECT II.[PreviousID], -- Leave the PreviousID as is for now
@ -2040,6 +2047,12 @@ 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 [VEPROMS].[dbo].[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
-- SELECT * From Entries EE JOIN Documents DD on ee.DocID = DD.DocID where EE.DTS = @DTS and EE.UserID = @UserID
-- <<< Copy RoUsages >>>
@ -2051,7 +2064,7 @@ DECLARE @RowsAffected int
SET @RowsAffected=1
WHILE @RowsAffected > 0
BEGIN
UPDATE CC SET [TEXT] = C2.NewText
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
@ -2060,6 +2073,19 @@ UPDATE CC SET [TEXT] = C2.NewText
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) G2 ON GG.ContentID = G2.ContentID
WHERE Cast([Data] as varchar(max)) <> cast(G2.NewData as varchar(max))
SET @RowsAffected = @@RowCount
END
UPDATE RON SET [ROID] = ROO.[ROID]
FROM RoUsages RON
JOIN @Children NN on RON.ContentID = NN.NewContentID
@ -2103,6 +2129,20 @@ UPDATE CC SET [TEXT] = C2.NewText
WHERE [TEXT] <> C2.NewText
SET @RowsAffected = @@RowCount
END
-- -- Update grid records for newly copied records to use correct TransitionIDs in the Transition tags
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 varchar(max)) <> CAST(G2.NewData as varchar(max))
SET @RowsAffected = @@RowCount
END
-- Add 'Verification Required' AnnotationType
DECLARE @typeID int
SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required'
@ -12729,6 +12769,30 @@ IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_FirstLink Succeeded'
ELSE PRINT 'ScalarFunction Creation: vefn_FirstLink Error on Creation'
GO
/****** Object: StoredProcedure [vefn_FixROData] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixROData]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
DROP FUNCTION [vefn_FixROData];
GO
Create FUNCTION [dbo].[vefn_FixROData]
(@data XML,@ROUsageID int,@NewROUsageID int)
RETURNS XML
WITH EXECUTE AS OWNER
AS
BEGIN
-- Build Search String and Replace String
DECLARE @lookFor varchar(MAX)
DECLARE @replaceWith varchar(MAX)
SET @lookFor = '#Link:ReferencedObject:' + ltrim(str(@ROUsageID)) + ' '
SET @replaceWith = '#Link:ReferencedObject:' + ltrim(str(@NewROUsageID)) + ' '
return CAST(replace(CAST(@data AS VarChar(max)),@lookFor,@replaceWith) AS XML)
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_FixROData Succeeded'
ELSE PRINT 'ScalarFunction Creation: vefn_FixROData Error on Creation'
GO
/****** Object: StoredProcedure [vefn_FixROText] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixROText]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
DROP FUNCTION [vefn_FixROText];
@ -12804,6 +12868,49 @@ IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_FixSearchString Succeeded'
ELSE PRINT 'ScalarFunction Creation: vefn_FixSearchString Error on Creation'
GO
/****** Object: StoredProcedure [vefn_FixTransitionDataForCopy] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixTransitionDataForCopy]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
DROP FUNCTION [vefn_FixTransitionDataForCopy];
GO
CREATE FUNCTION [dbo].[vefn_FixTransitionDataForCopy]
(@data XML,@TransitionID int,@TranType int,@OldToID int,@OldRangeID int, @NewID int, @NewToID int, @NewRangeID int, @NewTranType int)
RETURNS XML
WITH EXECUTE AS OWNER
AS
BEGIN
-- Build Search String and Replace String
DECLARE @offset int
DECLARE @lookFor varchar(MAX)
DECLARE @replaceWith varchar(MAX)
DECLARE @text varchar(MAX)
SET @text = Cast(@data as varchar(max))
SET @lookFor = '#Link:Transition:' + ltrim(str(@TranType)) + ' ' + ltrim(str(@TransitionID))
SET @offset = CHARINDEX(@lookFor,@text)
if(@offset = 0)
BEGIN
SET @lookFor = '#Link:TransitionRange:' + ltrim(str(@TranType)) + ' ' + ltrim(str(@TransitionID))
SET @offset = CHARINDEX(@lookFor,@text)
SET @replaceWith = '#Link:TransitionRange:' + ltrim(str(@NewTranType)) + ' ' + ltrim(str(@NewID))
+ ' ' + ltrim(str(@NewToID)) + ' ' + ltrim(str(@NewRangeID))
SET @lookFor = @lookFor + ' ' + ltrim(str(@OldToID)) + ' ' + ltrim(str(@OldRangeID))
END
ELSE
BEGIN
SET @replaceWith = '#Link:Transition:' + ltrim(str(@NewTranType)) + ' ' + ltrim(str(@NewID))
+ ' ' + ltrim(str(@NewToID))
SET @lookFor = @lookFor + ' ' + ltrim(str(@OldToID))
END
return Cast(replace(@text,@lookFor,@replaceWith) as XML)
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_FixTransitionDataForCopy Succeeded'
ELSE PRINT 'ScalarFunction Creation: vefn_FixTransitionDataForCopy Error on Creation'
GO
/****** Object: StoredProcedure [vefn_FixTransitionText] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixTransitionText]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
DROP FUNCTION [vefn_FixTransitionText];

View File

@ -29,8 +29,6 @@ namespace Volian.Controls.Library
* 4) KBR ContextMenu for table. May want it to function in a similar way to spellcheck, with
* the contentmenu to support table options and a last item that supports existing
* contextmenu
* 5) RHM Copy step - including modifying SQL code to copy grid/image data.
* The Grid includes links which also need to be updated.
* 6) RHM Selection is NOT selection, i.e. if merged cells, selection isn't selecting the 'merged'
* i.e. parent cell.
* 7) RHM Selecting a range can end up with uneven rows or uneven columns. We need to handle,
@ -39,7 +37,6 @@ namespace Volian.Controls.Library
* 8) KBR When data migration of tables, need to include the font if there is a symbol. Move
* AddFontTable from StepRTB.cs to a place accessible, such as volian.base. And then
* in data migration, will need to know if a font is fixed.
* 9) RHM Editting cell with Transition Panel enabled; click on Ro Panel and it is not enabled
*/
#region Fields
public VlnFlexGrid MyFlexGrid
@ -578,14 +575,25 @@ namespace Volian.Controls.Library
public override void IdentifyMe(bool highlight)
{
if (highlight)
MyFlexGrid.Styles["Alternate"].BackColor = MyFlexGrid.Styles["Normal"].BackColor = Color.Gray;
{
//for (int r = 0; r < MyFlexGrid.Rows.Count; r++)
// for (int c = 0; c < MyFlexGrid.Cols.Count; c++)
// {
// CellStyle cs = MyFlexGrid.GetCellStyle(r, c);
// CellRange cr = MyFlexGrid.GetCellRange(r, c);
// Console.WriteLine("Style[{0},{1}] = '{2}' {3} '{4}'", r,c,cs.Name,cs.BackColor,cr.StyleNew.Name);
// }
MyFlexGrid.Styles["Alternate"].BackColor =
MyFlexGrid.Styles["Normal"].BackColor = Color.Gray;
}
else
{
if (MyFlexGrid.Focused) // If active Set BackColor to the active color
SetActive();
else // Otherwise Set the BackColor to either the InactiveColor or the AnnotationColor
{
MyFlexGrid.Styles["Alternate"].BackColor = MyFlexGrid.Styles["Normal"].BackColor =
MyFlexGrid.Styles["Alternate"].BackColor =
MyFlexGrid.Styles["Normal"].BackColor =
MyItemInfo.ItemAnnotationCount == 0 ? MyStepPanel.InactiveColor : MyStepPanel.AnnotationColor;
// Turn-off Size adjustment
MyFlexGrid.Cols.Fixed = 0;