B2022-055 Fix to help prevent crashing when opening/closing/re-opening procedures.

This commit is contained in:
John Jenko 2022-05-16 13:54:46 +00:00
parent 4f987dc7fc
commit 4b6b9451df

View File

@ -14,7 +14,7 @@ using Volian.Base.Library;
namespace Volian.Controls.Library namespace Volian.Controls.Library
{ {
public delegate ItemInfo DisplayTabControlEditorSearchIncTransEvent(object sender, vlnTreeItemInfoEventArgs args); public delegate ItemInfo DisplayTabControlEditorSearchIncTransEvent(object sender, vlnTreeItemInfoEventArgs args);
public delegate void DisplayTabControlEvent(object sender,EventArgs args); public delegate void DisplayTabControlEvent(object sender, EventArgs args);
public delegate void DisplayTabControlStatusEvent(object sender, DisplayTabControlStatusEventArgs args); public delegate void DisplayTabControlStatusEvent(object sender, DisplayTabControlStatusEventArgs args);
public partial class DisplayTabControlStatusEventArgs : EventArgs public partial class DisplayTabControlStatusEventArgs : EventArgs
{ {
@ -49,43 +49,47 @@ namespace Volian.Controls.Library
_Text = text; _Text = text;
} }
} }
public partial class DisplayTabControl : UserControl public partial class DisplayTabControl : UserControl
{ {
#region Log4Net #region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
private static bool _SyncronizeEnahnced = false; private static bool _SyncronizeEnahnced = false;
public static bool SyncronizeEnhanced public static bool SyncronizeEnhanced
{ {
get { return DisplayTabControl._SyncronizeEnahnced; } get { return DisplayTabControl._SyncronizeEnahnced; }
set { DisplayTabControl._SyncronizeEnahnced = value; } set { DisplayTabControl._SyncronizeEnahnced = value; }
} }
private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>();
private int _VersionID = 0; private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>();
// zero tells us to PROMS just opened and no procedure was selected yet so use the main proms window private int _VersionID = 0;
// when the first procedure is opened, the VersionID is set and added to _AllDTCs // zero tells us to PROMS just opened and no procedure was selected yet so use the main proms window
// when the first procedure is opened, the VersionID is set and added to _AllDTCs
public int VersionID public int VersionID
{ {
get { return _VersionID; } get { return _VersionID; }
set set
{ {
if ((int)value != 0) if ((int)value != 0)
{ {
if (!_AllDTCs.ContainsKey((int)value)) if (!_AllDTCs.ContainsKey((int)value))
{ {
_AllDTCs.Add((int)value, this); _AllDTCs.Add((int)value, this);
if (_VersionID == 0) if (_VersionID == 0)
_VersionID = value; _VersionID = value;
else else
_MyLog.WarnFormat("VersionID tried to be Changed from {0} to {1}", _VersionID, value); _MyLog.WarnFormat("VersionID tried to be Changed from {0} to {1}", _VersionID, value);
} }
} }
else else
_VersionID = value; _VersionID = value;
} }
} }
// This tells the display tab control whether or not the Separate Windows setting was set // This tells the display tab control whether or not the Separate Windows setting was set
private bool _SeparateWindows = false; private bool _SeparateWindows = false;
public bool SeparateWindows public bool SeparateWindows
{ {
@ -93,63 +97,63 @@ namespace Volian.Controls.Library
set { _SeparateWindows = value; } set { _SeparateWindows = value; }
} }
// this gets called before displaying the PROMS Settings dialog (off of the V button) // this gets called before displaying the PROMS Settings dialog (off of the V button)
// return true if at least one procedure is one in more than one procedure set // return true if at least one procedure is one in more than one procedure set
// Also cleanup the _AllDTCs dictionary by removing the VersionID's (procedure sets) that are not opened // Also cleanup the _AllDTCs dictionary by removing the VersionID's (procedure sets) that are not opened
public bool MoreThanOneProcedureSetIsOpen public bool MoreThanOneProcedureSetIsOpen
{
get
{
List<int> verIdList = new List<int>(); // list of procedure sets being used
List<int> rmvList = new List<int>(); // list of procedure set no longer being used
if (_AllDTCs.Count > 0 && _AllDTCs.Keys.Count > 0)
{
foreach (int k in _AllDTCs.Keys)
{
DisplayTabControl dtc = _AllDTCs[k];
if (_AllDTCs.Count > 1 && dtc._MyDisplayTabItems.Count == 0)
{
if (!rmvList.Contains(k))
rmvList.Add(k);
}
else
{
int numKeysVersionID = 0;
foreach (string dtikey in dtc._MyDisplayTabItems.Keys)
{
DisplayTabItem dti = dtc._MyDisplayTabItems[dtikey];
if (dti.MyItemInfo.MyDocVersion.VersionID == k)
{
numKeysVersionID++;
if (!verIdList.Contains(dti.MyItemInfo.MyDocVersion.VersionID))
verIdList.Add(dti.MyItemInfo.MyDocVersion.VersionID);
}
}
if (numKeysVersionID == 0 && !rmvList.Contains(k))
rmvList.Add(k);
}
}
}
// remove the VersionID's that no not being used from the AllDTCs list
if (rmvList.Count > 0)
foreach (int i in rmvList)
_AllDTCs.Remove(i);
if (_AllDTCs.Count == 0)
_VersionID = 0;
return (verIdList.Count > 1);
}
}
//public event ItemSelectedChangedEvent OpenEnhancedDocument;
//public void OnOpenEnhancedDocument(ItemSelectedChangedEventArgs args)
//{
// if (OpenEnhancedDocument != null)
// OpenEnhancedDocument(this, args);
//}
public event ItemSelectedChangedEvent OpenInSeparateWindow;
public void OnOpenInSeparateWindow(ItemSelectedChangedEventArgs args)
{ {
if (OpenInSeparateWindow != null) get
OpenInSeparateWindow(this, args); {
List<int> verIdList = new List<int>(); // list of procedure sets being used
List<int> rmvList = new List<int>(); // list of procedure set no longer being used
if (_AllDTCs.Count > 0 && _AllDTCs.Keys.Count > 0)
{
foreach (int k in _AllDTCs.Keys)
{
DisplayTabControl dtc = _AllDTCs[k];
if (_AllDTCs.Count > 1 && dtc._MyDisplayTabItems.Count == 0)
{
if (!rmvList.Contains(k))
rmvList.Add(k);
}
else
{
int numKeysVersionID = 0;
foreach (string dtikey in dtc._MyDisplayTabItems.Keys)
{
DisplayTabItem dti = dtc._MyDisplayTabItems[dtikey];
if (dti.MyItemInfo.MyDocVersion.VersionID == k)
{
numKeysVersionID++;
if (!verIdList.Contains(dti.MyItemInfo.MyDocVersion.VersionID))
verIdList.Add(dti.MyItemInfo.MyDocVersion.VersionID);
}
}
if (numKeysVersionID == 0 && !rmvList.Contains(k))
rmvList.Add(k);
}
}
}
// remove the VersionID's that no not being used from the AllDTCs list
if (rmvList.Count > 0)
foreach (int i in rmvList)
_AllDTCs.Remove(i);
if (_AllDTCs.Count == 0)
_VersionID = 0;
return (verIdList.Count > 1);
}
}
//public event ItemSelectedChangedEvent OpenEnhancedDocument;
//public void OnOpenEnhancedDocument(ItemSelectedChangedEventArgs args)
//{
// if (OpenEnhancedDocument != null)
// OpenEnhancedDocument(this, args);
//}
public event ItemSelectedChangedEvent OpenInSeparateWindow;
public void OnOpenInSeparateWindow(ItemSelectedChangedEventArgs args)
{
if (OpenInSeparateWindow != null)
OpenInSeparateWindow(this, args);
} }
// C2020-033: Provide way to expand/fill in Search/Incoming Transition panel // C2020-033: Provide way to expand/fill in Search/Incoming Transition panel
public event DisplayTabControlEditorSearchIncTransEvent SearchIncTrans; public event DisplayTabControlEditorSearchIncTransEvent SearchIncTrans;
@ -172,21 +176,24 @@ namespace Volian.Controls.Library
public event DisplayTabControlEvent ToggleRibbonExpanded; public event DisplayTabControlEvent ToggleRibbonExpanded;
public void OnToggleRibbonExpanded(object sender, EventArgs args) public void OnToggleRibbonExpanded(object sender, EventArgs args)
{ {
if (ToggleRibbonExpanded != null) ToggleRibbonExpanded(sender,args); if (ToggleRibbonExpanded != null) ToggleRibbonExpanded(sender, args);
} }
public event DisplayTabControlEvent SelectedDisplayTabItemChanged; public event DisplayTabControlEvent SelectedDisplayTabItemChanged;
public void OnSelectedDisplayTabItemChanged(object sender, EventArgs args) public void OnSelectedDisplayTabItemChanged(object sender, EventArgs args)
{ {
if (SelectedDisplayTabItemChanged != null)SelectedDisplayTabItemChanged(sender, args); if (SelectedDisplayTabItemChanged != null) SelectedDisplayTabItemChanged(sender, args);
} }
// C2015-022 added copystep event to commuicate with child windows // C2015-022 added copystep event to commuicate with child windows
public event ItemChangedEventHandler CopyStepSelected; public event ItemChangedEventHandler CopyStepSelected;
public void OnCopyStepSelected(ItemChangedEventArgs args) public void OnCopyStepSelected(ItemChangedEventArgs args)
{ {
if (CopyStepSelected != null) if (CopyStepSelected != null)
CopyStepSelected(this, args); CopyStepSelected(this, args);
} }
#region Private Fields #region Private Fields
/// <summary> /// <summary>
/// This is a lookup table for all of the DisplayTabItems that are currently open /// This is a lookup table for all of the DisplayTabItems that are currently open
/// The key is: /// The key is:
@ -194,11 +201,13 @@ namespace Volian.Controls.Library
/// "Doc - " + DocumentID for Word Documents /// "Doc - " + DocumentID for Word Documents
/// </summary> /// </summary>
public Dictionary<string, DisplayTabItem> _MyDisplayTabItems; public Dictionary<string, DisplayTabItem> _MyDisplayTabItems;
/// <summary> /// <summary>
/// When a Tab is closed it is added to this list. /// When a Tab is closed it is added to this list.
/// When another Tab is opened, any Tabs in this list are closed /// When another Tab is opened, any Tabs in this list are closed
/// </summary> /// </summary>
private List<DisplayTabItem> _RemovedDisplayTabItems = null; private List<DisplayTabItem> _RemovedDisplayTabItems = null;
/// <summary> /// <summary>
/// This stores a UniqueID for Bars as they are opened. /// This stores a UniqueID for Bars as they are opened.
/// A bar is the docking location for the DisplayTabItems. /// A bar is the docking location for the DisplayTabItems.
@ -222,7 +231,7 @@ namespace Volian.Controls.Library
set { _MyEditItem = value; } set { _MyEditItem = value; }
} }
private StepRTB _MyStepRTB = null; private StepRTB _MyStepRTB = null;
private bool _RibbonExpanded=true; private bool _RibbonExpanded = true;
public StepRTB MyStepRTB public StepRTB MyStepRTB
{ {
get { return _MyStepRTB; } get { return _MyStepRTB; }
@ -230,7 +239,7 @@ namespace Volian.Controls.Library
public bool RibbonExpanded public bool RibbonExpanded
{ {
get { return _RibbonExpanded; } get { return _RibbonExpanded; }
set set
{ {
_RibbonExpanded = value; _RibbonExpanded = value;
foreach (DisplayTabItem tabItem in _MyDisplayTabItems.Values) foreach (DisplayTabItem tabItem in _MyDisplayTabItems.Values)
@ -253,12 +262,12 @@ namespace Volian.Controls.Library
} }
public bool EditorialChange public bool EditorialChange
{ {
get get
{ {
if (_ChgId == null) return true; if (_ChgId == null) return true;
if (_ChgId == "") return true; if (_ChgId == "") return true;
if (_ChgId.ToUpper() == "EC") return true; if (_ChgId.ToUpper() == "EC") return true;
return false; return false;
} }
} }
#endregion #endregion
@ -367,7 +376,7 @@ namespace Volian.Controls.Library
if (_MyEditItem != null) if (_MyEditItem != null)
{ {
_MyStepRTB = _MyEditItem.MyStepRTB; _MyStepRTB = _MyEditItem.MyStepRTB;
if(_MyStepRTB != null) if (_MyStepRTB != null)
_MyStepRTB.Disposed += new EventHandler(_MyStepRTB_Disposed); _MyStepRTB.Disposed += new EventHandler(_MyStepRTB_Disposed);
} }
else else
@ -381,47 +390,58 @@ namespace Volian.Controls.Library
} }
if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args); if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args);
} }
void _MyStepRTB_Disposed(object sender, EventArgs e) void _MyStepRTB_Disposed(object sender, EventArgs e)
{ {
_MyStepRTB = null; _MyStepRTB = null;
} }
public event StepPanelModeChangeEvent ModeChange; public event StepPanelModeChangeEvent ModeChange;
internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args) internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
{ {
if (ModeChange != null) ModeChange(sender, args); if (ModeChange != null) ModeChange(sender, args);
else FlexibleMessageBox.Show("Cannot change mode"); else FlexibleMessageBox.Show("Cannot change mode");
} }
public event StepPanelTabDisplayEvent PanelTabDisplay; public event StepPanelTabDisplayEvent PanelTabDisplay;
internal void OnPanelTabDisplay(object sender, StepPanelTabDisplayEventArgs args) internal void OnPanelTabDisplay(object sender, StepPanelTabDisplayEventArgs args)
{ {
if (PanelTabDisplay != null) PanelTabDisplay(sender, args); if (PanelTabDisplay != null) PanelTabDisplay(sender, args);
else FlexibleMessageBox.Show("Cannot display information"); else FlexibleMessageBox.Show("Cannot display information");
} }
public event StepPanelWordSectionCloseEvent WordSectionClose; public event StepPanelWordSectionCloseEvent WordSectionClose;
internal void OnWordSectionClose(object sender, WordSectionEventArgs args) internal void OnWordSectionClose(object sender, WordSectionEventArgs args)
{ {
if (WordSectionClose != null) WordSectionClose(sender, args); if (WordSectionClose != null) WordSectionClose(sender, args);
else FlexibleMessageBox.Show("Cannot close associated Word section"); else FlexibleMessageBox.Show("Cannot close associated Word section");
} }
public event StepPanelWordSectionDeletedEvent WordSectionDeleted; public event StepPanelWordSectionDeletedEvent WordSectionDeleted;
internal void OnWordSectionDeleted(object sender, WordSectionEventArgs args) internal void OnWordSectionDeleted(object sender, WordSectionEventArgs args)
{ {
if (WordSectionDeleted != null) WordSectionDeleted(sender, args); if (WordSectionDeleted != null) WordSectionDeleted(sender, args);
else FlexibleMessageBox.Show("Cannot delete associated Word section"); else FlexibleMessageBox.Show("Cannot delete associated Word section");
} }
public event StepPanelItemPastedEvent ItemPaste; public event StepPanelItemPastedEvent ItemPaste;
internal void OnItemPaste(object sender, vlnTreeItemInfoPasteEventArgs args) internal void OnItemPaste(object sender, vlnTreeItemInfoPasteEventArgs args)
{ {
if (ItemPaste != null) ItemPaste(sender, args); if (ItemPaste != null) ItemPaste(sender, args);
else FlexibleMessageBox.Show("Cannot adjust panels for pasted item"); else FlexibleMessageBox.Show("Cannot adjust panels for pasted item");
} }
#endregion #endregion
#region Contructor & Setup #region Contructor & Setup
public DisplayTabControl() public DisplayTabControl()
{ {
InitializeComponent(); InitializeComponent();
SetUp(); SetUp();
} }
private void SetUp() private void SetUp()
{ {
ItemsChangeIds = new Dictionary<int, string>(); ItemsChangeIds = new Dictionary<int, string>();
@ -531,18 +551,20 @@ namespace Volian.Controls.Library
{ {
DisplayTabItem pg = _MyDisplayTabItems[key]; DisplayTabItem pg = _MyDisplayTabItems[key];
if (pg.MyStepTabPanel.MyStepPanel._LookupEditItems.ContainsKey(myItemInfo.ItemID)) if (pg.MyStepTabPanel.MyStepPanel._LookupEditItems.ContainsKey(myItemInfo.ItemID))
OpenItem(myItemInfo,false); OpenItem(myItemInfo, false);
} }
} }
public DisplayTabItem OpenItem(ItemInfo myItemInfo2) public DisplayTabItem OpenItem(ItemInfo myItemInfo2)
{ {
//B2017-251 Added Error Log message for Open Step or MSWord section include time to do open //B2017-251 Added Error Log message for Open Step or MSWord section include time to do open
DateTime tStart = DateTime.Now; DateTime tStart = DateTime.Now;
DisplayTabItem dti = OpenItem(myItemInfo2, true); DisplayTabItem dti = OpenItem(myItemInfo2, true);
_MyLog.InfoFormat("OpenItem {0} seconds {1} {2}", TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds, myItemInfo2.ItemID, myItemInfo2.ShortPath); _MyLog.InfoFormat("OpenItem {0} seconds {1} {2}", TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds, myItemInfo2.ItemID, myItemInfo2.ShortPath);
return dti; return dti;
} }
/// <summary>
/// <summary>
/// Open a Step Item or a Word Item /// Open a Step Item or a Word Item
/// </summary> /// </summary>
/// <param name="myItemInfo"></param> /// <param name="myItemInfo"></param>
@ -550,11 +572,13 @@ namespace Volian.Controls.Library
public DisplayTabItem OpenItem(ItemInfo myItemInfo2, bool setFocus) public DisplayTabItem OpenItem(ItemInfo myItemInfo2, bool setFocus)
{ {
ItemInfo myItemInfo = myItemInfo2; ItemInfo myItemInfo = myItemInfo2;
if (myItemInfo.MyDocVersion == null) // bug fix: B2016-108 disconnected data will not have a MyDocVersion if (myItemInfo.MyDocVersion == null) // bug fix: B2016-108 disconnected data will not have a MyDocVersion
{ {
FlexibleMessageBox.Show(this, "Possible disconnected item", "Item Not Found"); FlexibleMessageBox.Show(this, "Possible disconnected item", "Item Not Found");
return null; return null;
} }
string message = string.Empty; string message = string.Empty;
//if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyDocVersion.VersionID, CheckOutType.DocVersion, ref message)) //if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyDocVersion.VersionID, CheckOutType.DocVersion, ref message))
//{ //{
@ -587,6 +611,7 @@ namespace Volian.Controls.Library
FlexibleMessageBox.Show("This is an automatically generated 'Table of Contents' section. It is not editable. It is generated during Print.", "Item not Editable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); FlexibleMessageBox.Show("This is an automatically generated 'Table of Contents' section. It is not editable. It is generated during Print.", "Item not Editable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return SelectedDisplayTabItem; return SelectedDisplayTabItem;
} }
bool libDocAlreadyOpen = false; bool libDocAlreadyOpen = false;
if (myItemInfo.MyContent.MyEntry != null) // Trying to open a Word document - see if it's a library document that is already opened. if (myItemInfo.MyContent.MyEntry != null) // Trying to open a Word document - see if it's a library document that is already opened.
libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo); libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo);
@ -611,6 +636,7 @@ namespace Volian.Controls.Library
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo); return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
} }
} }
if (VersionID != myItemInfo.MyDocVersion.VersionID && _AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID)) if (VersionID != myItemInfo.MyDocVersion.VersionID && _AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{ {
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo); return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
@ -621,11 +647,17 @@ namespace Volian.Controls.Library
VersionID = myItemInfo.MyDocVersion.VersionID; // add it to _AllDTCs VersionID = myItemInfo.MyDocVersion.VersionID; // add it to _AllDTCs
_MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item. _MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item.
if (myItemInfo.MyContent.MyEntry == null) // If it is not a Word document open in step editor if (myItemInfo.MyContent.MyEntry == null) // If it is not a Word document open in step editor
{
return OpenStepTabPage(myItemInfo, setFocus); return OpenStepTabPage(myItemInfo, setFocus);
}
else // Otherwise open it in the Word editor else // Otherwise open it in the Word editor
{
return OpenDSOTabPage(myItemInfo); return OpenDSOTabPage(myItemInfo);
}
} }
public bool PasteRTBItem(ItemInfo myItemInfo, int copyStartID, ItemInfo.EAddpingPart pasteType, int type) public bool PasteRTBItem(ItemInfo myItemInfo, int copyStartID, ItemInfo.EAddpingPart pasteType, int type)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
@ -635,7 +667,7 @@ namespace Volian.Controls.Library
if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it
{ {
DisplayTabItem pg = _MyDisplayTabItems[key]; DisplayTabItem pg = _MyDisplayTabItems[key];
if (pg.MyStepTabPanel.MyStepPanel._LookupEditItems.ContainsKey(myItemInfo.ItemID) && if (pg.MyStepTabPanel.MyStepPanel._LookupEditItems.ContainsKey(myItemInfo.ItemID) &&
pg.MyStepTabPanel.MyStepPanel._LookupEditItems[myItemInfo.ItemID].Expanded) pg.MyStepTabPanel.MyStepPanel._LookupEditItems[myItemInfo.ItemID].Expanded)
{ {
EditItem edtitm = pg.MyStepTabPanel.MyStepPanel._LookupEditItems[myItemInfo.ItemID]; EditItem edtitm = pg.MyStepTabPanel.MyStepPanel._LookupEditItems[myItemInfo.ItemID];
@ -653,28 +685,29 @@ namespace Volian.Controls.Library
case ItemInfo.EAddpingPart.Replace: case ItemInfo.EAddpingPart.Replace:
EditItem ei = edtitm.PasteReplace(copyStartID); EditItem ei = edtitm.PasteReplace(copyStartID);
if (ei == null) return false; //B2017-179 PasteReplace will return null if was aborted if (ei == null) return false; //B2017-179 PasteReplace will return null if was aborted
if (ei.MyItemInfo.ItemID != edtitm.MyItemInfo.ItemID) if (ei.MyItemInfo.ItemID != edtitm.MyItemInfo.ItemID)
{ {
edtitm.Dispose(); edtitm.Dispose();
MyCopyStep = ei.MyItemInfo; MyCopyStep = ei.MyItemInfo;
} }
break; break;
default: default:
return false; ; return false;
} }
return true; return true;
} }
} }
return false; return false;
} }
public bool DeleteRTBItem(ItemInfo myItemInfo) public bool DeleteRTBItem(ItemInfo myItemInfo)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
//removeitem! //removeitem!
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
string key = "Item - " + proc.ItemID.ToString(); string key = "Item - " + proc.ItemID.ToString();
if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it
{ {
DisplayTabItem pg = _MyDisplayTabItems[key]; DisplayTabItem pg = _MyDisplayTabItems[key];
@ -694,7 +727,8 @@ namespace Volian.Controls.Library
} }
return false; return false;
} }
public bool InsertRTBItem(ItemInfo myItemInfo, string text, E_InsertType insertType, E_FromType fromType, int type,bool updateSelection)
public bool InsertRTBItem(ItemInfo myItemInfo, string text, E_InsertType insertType, E_FromType fromType, int type, bool updateSelection)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
@ -709,10 +743,10 @@ namespace Volian.Controls.Library
switch (insertType) switch (insertType)
{ {
case E_InsertType.Before: case E_InsertType.Before:
edtitm.AddSiblingBefore(text,updateSelection); edtitm.AddSiblingBefore(text, updateSelection);
break; break;
case E_InsertType.After: case E_InsertType.After:
edtitm.AddSiblingAfter(text,updateSelection); edtitm.AddSiblingAfter(text, updateSelection);
break; break;
case E_InsertType.Child: case E_InsertType.Child:
edtitm.AddChild(text, fromType, type, null); edtitm.AddChild(text, fromType, type, null);
@ -723,8 +757,9 @@ namespace Volian.Controls.Library
return true; return true;
} }
} }
return false; return false;
} }
private void CleanUpClosedItems() private void CleanUpClosedItems()
{ {
while (_RemovedDisplayTabItems.Count > 0) // Clean-up any items that have been closed. while (_RemovedDisplayTabItems.Count > 0) // Clean-up any items that have been closed.
@ -734,17 +769,19 @@ namespace Volian.Controls.Library
RemoveItem(myTabItem); RemoveItem(myTabItem);
} }
} }
public void CloseWordItem(ItemInfo myItemInfo) public void CloseWordItem(ItemInfo myItemInfo)
{ {
CloseWordItem(myItemInfo, false); CloseWordItem(myItemInfo, false);
} }
public void CloseWordItem(ItemInfo myItemInfo, bool isBeingDeleted) public void CloseWordItem(ItemInfo myItemInfo, bool isBeingDeleted)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
string key = "Doc - "; string key = "Doc - ";
// there is no entry if it is an auto table of contents: // there is no entry if it is an auto table of contents:
if (myItemInfo.MyContent.MyEntry != null) if (myItemInfo.MyContent.MyEntry != null)
key = key + myItemInfo.MyContent.MyEntry.MyDocument.DocID.ToString(); key = key + myItemInfo.MyContent.MyEntry.MyDocument.DocID.ToString();
else else
key = key + "0"; key = key + "0";
DisplayTabItem myTabItem = null; DisplayTabItem myTabItem = null;
@ -809,7 +846,7 @@ namespace Volian.Controls.Library
#endregion #endregion
#region Public Properties #region Public Properties
private AnnotationDetails _MyAnnotationDetails; private AnnotationDetails _MyAnnotationDetails;
public AnnotationDetails MyAnnotationDetails // B2019-029: added to find annotation details for saving w/o btnsave click public AnnotationDetails MyAnnotationDetails // B2019-029: added to find annotation details for saving w/o btnsave click
{ {
get { return _MyAnnotationDetails; } get { return _MyAnnotationDetails; }
set { _MyAnnotationDetails = value; } set { _MyAnnotationDetails = value; }
@ -925,11 +962,11 @@ namespace Volian.Controls.Library
} }
} }
} }
private DisplayTabItem _SelectedDisplayTabItem=null; private DisplayTabItem _SelectedDisplayTabItem = null;
public DisplayTabItem SelectedDisplayTabItem public DisplayTabItem SelectedDisplayTabItem
{ {
get { return _SelectedDisplayTabItem; } get { return _SelectedDisplayTabItem; }
set set
{ {
if (DesignMode) return; // B2019-043 need to check if we are just saving changes to the user interface if (DesignMode) return; // B2019-043 need to check if we are just saving changes to the user interface
if (_SelectedDisplayTabItem != value) if (_SelectedDisplayTabItem != value)
@ -958,7 +995,7 @@ namespace Volian.Controls.Library
foreach (object itm in b.Items) foreach (object itm in b.Items)
{ {
DisplayTabItem myTabItem = itm as DisplayTabItem; DisplayTabItem myTabItem = itm as DisplayTabItem;
if (myTabItem != null && myTabItem.MyStepTabPanel != null && myItemInfo != null) if (myTabItem != null && myTabItem.MyStepTabPanel != null && myItemInfo != null)
if (myTabItem.MyStepTabPanel.MyProcedureItemInfo.ItemID == myItemInfo.MyProcedure.ItemID) if (myTabItem.MyStepTabPanel.MyProcedureItemInfo.ItemID == myItemInfo.MyProcedure.ItemID)
return b; return b;
} }
@ -1023,6 +1060,7 @@ namespace Volian.Controls.Library
} }
} }
} }
public DisplayTabItem GetProcDisplayTabItem(ItemInfo myItemInfo) public DisplayTabItem GetProcDisplayTabItem(ItemInfo myItemInfo)
{ {
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
@ -1059,6 +1097,7 @@ namespace Volian.Controls.Library
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
string key = "Item - " + proc.ItemID.ToString(); string key = "Item - " + proc.ItemID.ToString();
DisplayTabItem pg = null; DisplayTabItem pg = null;
if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it
{ {
pg = _MyDisplayTabItems[key]; pg = _MyDisplayTabItems[key];
@ -1083,32 +1122,32 @@ namespace Volian.Controls.Library
// If this is an enhanced document, check for refresh of text items: // If this is an enhanced document, check for refresh of text items:
//if (myItemInfo.IsProcedure) //if (myItemInfo.IsProcedure)
//{ //{
// make the myiteminfo into a procedureinfo (depending on where this is called from, just // make the myiteminfo into a procedureinfo (depending on where this is called from, just
// casting it crashed: // casting it crashed:
ProcedureInfo pi = ProcedureInfo.Get(myItemInfo.MyProcedure.ItemID); ProcedureInfo pi = ProcedureInfo.Get(myItemInfo.MyProcedure.ItemID);
ItemInfoList iil = pi.FindEnhancedProcedureTextDifferences(); ItemInfoList iil = pi.FindEnhancedProcedureTextDifferences();
if (iil != null) if (iil != null)
{
// C2019-045: See if this is a procedure & modifications are allowed, if that case, don't prompt:
bool doMsg = true;
if (iil.Count == 1 && iil[0].EnhAllowMod()) doMsg = false;
if (doMsg && FlexibleMessageBox.Show(this, "Text differences were found between this enhanced procedure and its source procedure. Do you want to refresh the text in this procedure?", "Confirm Text Refresh", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
// C2019-045: See if this is a procedure & modifications are allowed, if that case, don't prompt: pi.EnhancedProcedureRefreshTextDifferences(iil);
bool doMsg = true;
if (iil.Count == 1 && iil[0].EnhAllowMod()) doMsg = false;
if (doMsg && FlexibleMessageBox.Show(this, "Text differences were found between this enhanced procedure and its source procedure. Do you want to refresh the text in this procedure?", "Confirm Text Refresh", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
{
pi.EnhancedProcedureRefreshTextDifferences(iil);
}
} }
}
//} //}
} }
pg.MyStepTabPanel.MyProcedureItemInfo = proc; pg.MyStepTabPanel.MyProcedureItemInfo = proc;
// When more than one procedure is openned, the ribbon control cuts off the bottom of the buttons. // When more than one procedure is openned, the ribbon control cuts off the bottom of the buttons.
// This happened to all the procedure tabs after the first one. // This happened to all the procedure tabs after the first one.
// This is to kludge the logic into sizing the ribbon control properly. // This is to kludge the logic into sizing the ribbon control properly.
// This is done by toggling "pg.MyStepTabPanel.MyStepTabRibbon.Expanded" // This is done by toggling "pg.MyStepTabPanel.MyStepTabRibbon.Expanded"
// Note that we are doing the NOT of its current setting. This takes care of when the // Note that we are doing the NOT of its current setting. This takes care of when the
// ribbon bar is minimized and a new procedure tab is created // ribbon bar is minimized and a new procedure tab is created
pg.MyStepTabPanel.MyStepTabRibbon.Expanded = !pg.MyStepTabPanel.MyStepTabRibbon.Expanded; pg.MyStepTabPanel.MyStepTabRibbon.Expanded = !pg.MyStepTabPanel.MyStepTabRibbon.Expanded;
pg.MyStepTabPanel.MyStepTabRibbon.Expanded = !pg.MyStepTabPanel.MyStepTabRibbon.Expanded; pg.MyStepTabPanel.MyStepTabRibbon.Expanded = !pg.MyStepTabPanel.MyStepTabRibbon.Expanded;
} }
Application.DoEvents(); Application.DoEvents();
pg.SelectedItemInfo = myItemInfo; // Select the item pg.SelectedItemInfo = myItemInfo; // Select the item
@ -1155,38 +1194,43 @@ namespace Volian.Controls.Library
ChgId = chgid; ChgId = chgid;
} }
private bool LibDocAlreadyOpen(ItemInfo myItemInfo) private bool LibDocAlreadyOpen(ItemInfo myItemInfo)
{ {
EntryInfo myEntry = myItemInfo.MyContent.MyEntry; EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID; string key = "Doc - " + myEntry.DocID;
DisplayTabItem pg = null; DisplayTabItem pg = null;
return LibDocAlreadyOpen(myItemInfo, key, ref pg, false); return LibDocAlreadyOpen(myItemInfo, key, ref pg, false);
} }
private bool LibDocAlreadyOpen(ItemInfo myItemInfo, string key, ref DisplayTabItem pg, bool displayMsg) private bool LibDocAlreadyOpen(ItemInfo myItemInfo, string key, ref DisplayTabItem pg, bool displayMsg)
{ {
bool libDocAlreadyOpen = false; bool libDocAlreadyOpen = false;
// C2015-022 part of separate windows logic, check all tabs in all windows to see if lib docs
foreach (int k in _AllDTCs.Keys) // C2015-022 part of separate windows logic, check all tabs in all windows to see if lib docs
{ if (_AllDTCs != null && _AllDTCs.Count > 0)
DisplayTabControl dtc = _AllDTCs[k]; {
if (dtc._MyDisplayTabItems.ContainsKey(key)) foreach (int k in _AllDTCs.Keys)
{ {
pg = dtc._MyDisplayTabItems[key]; DisplayTabControl dtc = _AllDTCs[k];
if (pg.MyItemInfo.ItemID != myItemInfo.ItemID) if (dtc._MyDisplayTabItems.ContainsKey(key))
{ {
if (displayMsg) pg = dtc._MyDisplayTabItems[key];
{ if (pg.MyItemInfo.ItemID != myItemInfo.ItemID)
string msg = string.Format("{0} is already open", myItemInfo.MyContent.MyEntry.MyDocument.LibTitle); {
FlexibleMessageBox.Show(msg, "Library Document is Already Open", MessageBoxButtons.OK); if (displayMsg)
} {
libDocAlreadyOpen = true; string msg = string.Format("{0} is already open", myItemInfo.MyContent.MyEntry.MyDocument.LibTitle);
break; FlexibleMessageBox.Show(msg, "Library Document is Already Open", MessageBoxButtons.OK);
} }
} libDocAlreadyOpen = true;
} break;
return libDocAlreadyOpen; }
} }
}
}
return libDocAlreadyOpen;
}
/// <summary> /// <summary>
/// This opens a Word page based upon an itemInfo. Since a word document may be a library /// This opens a Word page based upon an itemInfo. Since a word document may be a library
/// document, the related DocID is used for the Word document. /// document, the related DocID is used for the Word document.
@ -1196,9 +1240,9 @@ namespace Volian.Controls.Library
private DisplayTabItem OpenDSOTabPage(ItemInfo myItemInfo) private DisplayTabItem OpenDSOTabPage(ItemInfo myItemInfo)
{ {
DisplayTabItem pg = null; DisplayTabItem pg = null;
EntryInfo myEntry = myItemInfo.MyContent.MyEntry; EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID; string key = "Doc - " + myEntry.DocID;
bool libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo, key, ref pg, true); bool libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo, key, ref pg, true);
if (!libDocAlreadyOpen && pg == null) if (!libDocAlreadyOpen && pg == null)
{ {
if (DSOTabPanel.Count >= DSOTabPanel.MSWordLimit) // Limit the number of open document pages to 18 if (DSOTabPanel.Count >= DSOTabPanel.MSWordLimit) // Limit the number of open document pages to 18
@ -1253,14 +1297,25 @@ namespace Volian.Controls.Library
/// <param name="myDisplayTabItem"></param> /// <param name="myDisplayTabItem"></param>
internal void RemoveItem(DisplayTabItem myDisplayTabItem) internal void RemoveItem(DisplayTabItem myDisplayTabItem)
{ {
_MyDisplayTabItems.Remove(myDisplayTabItem.MyKey); if (_MyDisplayTabItems.ContainsKey(myDisplayTabItem.MyKey))
// Dispose the Panel {
if (myDisplayTabItem.MyStepTabPanel != null) try
myDisplayTabItem.MyStepTabPanel.Dispose(); {
if (myDisplayTabItem.MyDSOTabPanel != null) _MyDisplayTabItems.Remove(myDisplayTabItem.MyKey);
myDisplayTabItem.MyDSOTabPanel.CloseDSO();
components.Remove(myDisplayTabItem); // Dispose of the procedure tab panel
myDisplayTabItem.Dispose(); if (myDisplayTabItem.MyStepTabPanel != null)
myDisplayTabItem.MyStepTabPanel.Dispose();
// Dispose of the MS Word Panel
if (myDisplayTabItem.MyDSOTabPanel != null)
myDisplayTabItem.MyDSOTabPanel.CloseDSO();
components.Remove(myDisplayTabItem);
myDisplayTabItem.Dispose();
}
catch { }
}
} }
#endregion #endregion
} }