From 47c5bb159a30eb2761b468727c4a742cc07b3c09 Mon Sep 17 00:00:00 2001 From: mschill Date: Wed, 2 Oct 2024 11:31:04 -0400 Subject: [PATCH] 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