B2024-075 Correct Linking and Numbering when utilizing Paste Before and Paste After with Enhanced Steps as well as some related UI refresh issues.

This commit is contained in:
Matthew Schill 2024-10-02 11:31:04 -04:00
parent 610b2d178c
commit 47c5bb159a
3 changed files with 132 additions and 22 deletions

View File

@ -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,6 +1897,8 @@ namespace VEPROMS.CSLA.Library
using (Item ei = Item.Get(enhii.ItemID))
{
StepConfig sc = enhii.MyConfig as StepConfig;
if (!sc.MyEnhancedDocuments.Exists(x => x.Type == 0))
{
sc.AddEnhancedDocument(0, this.ItemID);
sc.SaveEnhancedDocuments();
ei.MyContent.Text = DisplayText;
@ -1901,6 +1907,7 @@ namespace VEPROMS.CSLA.Library
enhii.RefreshConfig();
}
}
}
else if (IsSection)
{
using (Item ii = this.Get())
@ -1916,6 +1923,8 @@ namespace VEPROMS.CSLA.Library
using (Item ei = Item.Get(enhii.ItemID))
{
SectionConfig sc = enhii.MyConfig as SectionConfig;
if (!sc.MyEnhancedDocuments.Exists(x => x.Type == 0))
{
sc.AddEnhancedDocument(0, this.ItemID);
sc.SaveEnhancedDocuments();
ei.MyContent.Text = DisplayText;
@ -1924,6 +1933,7 @@ namespace VEPROMS.CSLA.Library
enhii.RefreshConfig();
}
}
}
else if (IsProcedure)
{
// To fix B2017-268 the order of the following 2 'usings' had to be changed and the
@ -1942,6 +1952,8 @@ namespace VEPROMS.CSLA.Library
using (Item ii = this.Get())
{
ProcedureConfig sc = this.MyConfig as ProcedureConfig;
if (!sc.MyEnhancedDocuments.Exists(x => x.Type == 0))
{
sc.AddEnhancedDocument(enhtype, enhii.ItemID);
sc.SaveEnhancedDocuments();
ii.MyContent.Config = sc.ToString();
@ -1950,6 +1962,7 @@ namespace VEPROMS.CSLA.Library
}
}
}
}
#endregion
#region DataPortal
// C2017-031: Support for paste/replace an enhanced step

View File

@ -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<DisplayTabItem>().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<DisplayTabItem>().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<DisplayTabItem>().FirstOrDefault(x => x.MyKey == $"Item - {exEnh.MyProcedure.ItemID}");
wndowToRefresh?.MyStepTabPanel.MyStepPanel.Reset(wndowToRefresh.MyItemInfo);
}
}
if (newEnh != null) AddAllEnhancedItemsToDisplay(newItemInfo);
}
public void PasteChild(int copyStartID)

View File

@ -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