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
{
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 partial class DisplayTabControlStatusEventArgs : EventArgs
{
@ -49,43 +49,47 @@ namespace Volian.Controls.Library
_Text = text;
}
}
public partial class DisplayTabControl : UserControl
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
private static bool _SyncronizeEnahnced = false;
public static bool SyncronizeEnhanced
{
get { return DisplayTabControl._SyncronizeEnahnced; }
set { DisplayTabControl._SyncronizeEnahnced = value; }
}
private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>();
private int _VersionID = 0;
// 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
private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>();
private int _VersionID = 0;
// 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
{
get { return _VersionID; }
set
set
{
if ((int)value != 0)
{
if (!_AllDTCs.ContainsKey((int)value))
{
_AllDTCs.Add((int)value, this);
if (_VersionID == 0)
_VersionID = value;
else
_MyLog.WarnFormat("VersionID tried to be Changed from {0} to {1}", _VersionID, value);
}
}
else
_VersionID = value;
if ((int)value != 0)
{
if (!_AllDTCs.ContainsKey((int)value))
{
_AllDTCs.Add((int)value, this);
if (_VersionID == 0)
_VersionID = value;
else
_MyLog.WarnFormat("VersionID tried to be Changed from {0} to {1}", _VersionID, value);
}
}
else
_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;
public bool SeparateWindows
{
@ -93,63 +97,63 @@ namespace Volian.Controls.Library
set { _SeparateWindows = value; }
}
// 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
// Also cleanup the _AllDTCs dictionary by removing the VersionID's (procedure sets) that are not opened
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)
// 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
// Also cleanup the _AllDTCs dictionary by removing the VersionID's (procedure sets) that are not opened
public bool MoreThanOneProcedureSetIsOpen
{
if (OpenInSeparateWindow != null)
OpenInSeparateWindow(this, args);
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)
OpenInSeparateWindow(this, args);
}
// C2020-033: Provide way to expand/fill in Search/Incoming Transition panel
public event DisplayTabControlEditorSearchIncTransEvent SearchIncTrans;
@ -172,21 +176,24 @@ namespace Volian.Controls.Library
public event DisplayTabControlEvent ToggleRibbonExpanded;
public void OnToggleRibbonExpanded(object sender, EventArgs args)
{
if (ToggleRibbonExpanded != null) ToggleRibbonExpanded(sender,args);
if (ToggleRibbonExpanded != null) ToggleRibbonExpanded(sender, args);
}
public event DisplayTabControlEvent SelectedDisplayTabItemChanged;
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
public event ItemChangedEventHandler CopyStepSelected;
public void OnCopyStepSelected(ItemChangedEventArgs args)
{
if (CopyStepSelected != null)
CopyStepSelected(this, args);
}
#region Private Fields
/// <summary>
/// This is a lookup table for all of the DisplayTabItems that are currently open
/// The key is:
@ -194,11 +201,13 @@ namespace Volian.Controls.Library
/// "Doc - " + DocumentID for Word Documents
/// </summary>
public Dictionary<string, DisplayTabItem> _MyDisplayTabItems;
/// <summary>
/// When a Tab is closed it is added to this list.
/// When another Tab is opened, any Tabs in this list are closed
/// </summary>
private List<DisplayTabItem> _RemovedDisplayTabItems = null;
/// <summary>
/// This stores a UniqueID for Bars as they are opened.
/// A bar is the docking location for the DisplayTabItems.
@ -222,7 +231,7 @@ namespace Volian.Controls.Library
set { _MyEditItem = value; }
}
private StepRTB _MyStepRTB = null;
private bool _RibbonExpanded=true;
private bool _RibbonExpanded = true;
public StepRTB MyStepRTB
{
get { return _MyStepRTB; }
@ -230,7 +239,7 @@ namespace Volian.Controls.Library
public bool RibbonExpanded
{
get { return _RibbonExpanded; }
set
set
{
_RibbonExpanded = value;
foreach (DisplayTabItem tabItem in _MyDisplayTabItems.Values)
@ -253,12 +262,12 @@ namespace Volian.Controls.Library
}
public bool EditorialChange
{
get
get
{
if (_ChgId == null) return true;
if (_ChgId == "") return true;
if (_ChgId.ToUpper() == "EC") return true;
return false;
return false;
}
}
#endregion
@ -367,7 +376,7 @@ namespace Volian.Controls.Library
if (_MyEditItem != null)
{
_MyStepRTB = _MyEditItem.MyStepRTB;
if(_MyStepRTB != null)
if (_MyStepRTB != null)
_MyStepRTB.Disposed += new EventHandler(_MyStepRTB_Disposed);
}
else
@ -381,47 +390,58 @@ namespace Volian.Controls.Library
}
if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args);
}
void _MyStepRTB_Disposed(object sender, EventArgs e)
{
_MyStepRTB = null;
}
public event StepPanelModeChangeEvent ModeChange;
internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
{
if (ModeChange != null) ModeChange(sender, args);
else FlexibleMessageBox.Show("Cannot change mode");
}
public event StepPanelTabDisplayEvent PanelTabDisplay;
internal void OnPanelTabDisplay(object sender, StepPanelTabDisplayEventArgs args)
{
if (PanelTabDisplay != null) PanelTabDisplay(sender, args);
else FlexibleMessageBox.Show("Cannot display information");
}
public event StepPanelWordSectionCloseEvent WordSectionClose;
internal void OnWordSectionClose(object sender, WordSectionEventArgs args)
{
if (WordSectionClose != null) WordSectionClose(sender, args);
else FlexibleMessageBox.Show("Cannot close associated Word section");
}
public event StepPanelWordSectionDeletedEvent WordSectionDeleted;
internal void OnWordSectionDeleted(object sender, WordSectionEventArgs args)
{
if (WordSectionDeleted != null) WordSectionDeleted(sender, args);
else FlexibleMessageBox.Show("Cannot delete associated Word section");
}
public event StepPanelItemPastedEvent ItemPaste;
internal void OnItemPaste(object sender, vlnTreeItemInfoPasteEventArgs args)
{
if (ItemPaste != null) ItemPaste(sender, args);
else FlexibleMessageBox.Show("Cannot adjust panels for pasted item");
}
#endregion
#region Contructor & Setup
public DisplayTabControl()
{
InitializeComponent();
SetUp();
}
private void SetUp()
{
ItemsChangeIds = new Dictionary<int, string>();
@ -531,18 +551,20 @@ namespace Volian.Controls.Library
{
DisplayTabItem pg = _MyDisplayTabItems[key];
if (pg.MyStepTabPanel.MyStepPanel._LookupEditItems.ContainsKey(myItemInfo.ItemID))
OpenItem(myItemInfo,false);
OpenItem(myItemInfo, false);
}
}
public DisplayTabItem OpenItem(ItemInfo myItemInfo2)
{
//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);
_MyLog.InfoFormat("OpenItem {0} seconds {1} {2}", TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds, myItemInfo2.ItemID, myItemInfo2.ShortPath);
return dti;
}
/// <summary>
/// <summary>
/// Open a Step Item or a Word Item
/// </summary>
/// <param name="myItemInfo"></param>
@ -550,11 +572,13 @@ namespace Volian.Controls.Library
public DisplayTabItem OpenItem(ItemInfo myItemInfo2, bool setFocus)
{
ItemInfo myItemInfo = myItemInfo2;
if (myItemInfo.MyDocVersion == null) // bug fix: B2016-108 disconnected data will not have a MyDocVersion
{
FlexibleMessageBox.Show(this, "Possible disconnected item", "Item Not Found");
return null;
}
string message = string.Empty;
//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);
return SelectedDisplayTabItem;
}
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.
libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo);
@ -611,6 +636,7 @@ namespace Volian.Controls.Library
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
}
}
if (VersionID != myItemInfo.MyDocVersion.VersionID && _AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
@ -621,11 +647,17 @@ namespace Volian.Controls.Library
VersionID = myItemInfo.MyDocVersion.VersionID; // add it to _AllDTCs
_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
{
return OpenStepTabPage(myItemInfo, setFocus);
}
else // Otherwise open it in the Word editor
{
return OpenDSOTabPage(myItemInfo);
}
}
public bool PasteRTBItem(ItemInfo myItemInfo, int copyStartID, ItemInfo.EAddpingPart pasteType, int type)
{
CleanUpClosedItems();
@ -635,7 +667,7 @@ namespace Volian.Controls.Library
if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it
{
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)
{
EditItem edtitm = pg.MyStepTabPanel.MyStepPanel._LookupEditItems[myItemInfo.ItemID];
@ -653,28 +685,29 @@ namespace Volian.Controls.Library
case ItemInfo.EAddpingPart.Replace:
EditItem ei = edtitm.PasteReplace(copyStartID);
if (ei == null) return false; //B2017-179 PasteReplace will return null if was aborted
if (ei.MyItemInfo.ItemID != edtitm.MyItemInfo.ItemID)
{
edtitm.Dispose();
MyCopyStep = ei.MyItemInfo;
}
if (ei.MyItemInfo.ItemID != edtitm.MyItemInfo.ItemID)
{
edtitm.Dispose();
MyCopyStep = ei.MyItemInfo;
}
break;
default:
return false; ;
return false;
}
return true;
}
}
return false;
}
public bool DeleteRTBItem(ItemInfo myItemInfo)
{
CleanUpClosedItems();
//removeitem!
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
string key = "Item - " + proc.ItemID.ToString();
if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it
{
DisplayTabItem pg = _MyDisplayTabItems[key];
@ -694,7 +727,8 @@ namespace Volian.Controls.Library
}
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();
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
@ -709,10 +743,10 @@ namespace Volian.Controls.Library
switch (insertType)
{
case E_InsertType.Before:
edtitm.AddSiblingBefore(text,updateSelection);
edtitm.AddSiblingBefore(text, updateSelection);
break;
case E_InsertType.After:
edtitm.AddSiblingAfter(text,updateSelection);
edtitm.AddSiblingAfter(text, updateSelection);
break;
case E_InsertType.Child:
edtitm.AddChild(text, fromType, type, null);
@ -723,8 +757,9 @@ namespace Volian.Controls.Library
return true;
}
}
return false;
return false;
}
private void CleanUpClosedItems()
{
while (_RemovedDisplayTabItems.Count > 0) // Clean-up any items that have been closed.
@ -734,17 +769,19 @@ namespace Volian.Controls.Library
RemoveItem(myTabItem);
}
}
public void CloseWordItem(ItemInfo myItemInfo)
{
CloseWordItem(myItemInfo, false);
}
public void CloseWordItem(ItemInfo myItemInfo, bool isBeingDeleted)
{
CleanUpClosedItems();
string key = "Doc - ";
// there is no entry if it is an auto table of contents:
if (myItemInfo.MyContent.MyEntry != null)
key = key + myItemInfo.MyContent.MyEntry.MyDocument.DocID.ToString();
key = key + myItemInfo.MyContent.MyEntry.MyDocument.DocID.ToString();
else
key = key + "0";
DisplayTabItem myTabItem = null;
@ -809,7 +846,7 @@ namespace Volian.Controls.Library
#endregion
#region Public Properties
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; }
set { _MyAnnotationDetails = value; }
@ -925,11 +962,11 @@ namespace Volian.Controls.Library
}
}
}
private DisplayTabItem _SelectedDisplayTabItem=null;
private DisplayTabItem _SelectedDisplayTabItem = null;
public DisplayTabItem 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 (_SelectedDisplayTabItem != value)
@ -958,7 +995,7 @@ namespace Volian.Controls.Library
foreach (object itm in b.Items)
{
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)
return b;
}
@ -1023,6 +1060,7 @@ namespace Volian.Controls.Library
}
}
}
public DisplayTabItem GetProcDisplayTabItem(ItemInfo myItemInfo)
{
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
@ -1059,6 +1097,7 @@ namespace Volian.Controls.Library
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
string key = "Item - " + proc.ItemID.ToString();
DisplayTabItem pg = null;
if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it
{
pg = _MyDisplayTabItems[key];
@ -1083,32 +1122,32 @@ namespace Volian.Controls.Library
// If this is an enhanced document, check for refresh of text items:
//if (myItemInfo.IsProcedure)
//{
// make the myiteminfo into a procedureinfo (depending on where this is called from, just
// casting it crashed:
ProcedureInfo pi = ProcedureInfo.Get(myItemInfo.MyProcedure.ItemID);
ItemInfoList iil = pi.FindEnhancedProcedureTextDifferences();
if (iil != null)
// make the myiteminfo into a procedureinfo (depending on where this is called from, just
// casting it crashed:
ProcedureInfo pi = ProcedureInfo.Get(myItemInfo.MyProcedure.ItemID);
ItemInfoList iil = pi.FindEnhancedProcedureTextDifferences();
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:
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);
}
pi.EnhancedProcedureRefreshTextDifferences(iil);
}
}
//}
}
pg.MyStepTabPanel.MyProcedureItemInfo = proc;
// 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 is to kludge the logic into sizing the ribbon control properly.
// 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
// 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();
pg.SelectedItemInfo = myItemInfo; // Select the item
@ -1155,38 +1194,43 @@ namespace Volian.Controls.Library
ChgId = chgid;
}
private bool LibDocAlreadyOpen(ItemInfo myItemInfo)
{
EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID;
DisplayTabItem pg = null;
return LibDocAlreadyOpen(myItemInfo, key, ref pg, false);
}
private bool LibDocAlreadyOpen(ItemInfo myItemInfo)
{
EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID;
DisplayTabItem pg = null;
return LibDocAlreadyOpen(myItemInfo, key, ref pg, false);
}
private bool LibDocAlreadyOpen(ItemInfo myItemInfo, string key, ref DisplayTabItem pg, bool displayMsg)
{
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)
{
DisplayTabControl dtc = _AllDTCs[k];
if (dtc._MyDisplayTabItems.ContainsKey(key))
{
pg = dtc._MyDisplayTabItems[key];
if (pg.MyItemInfo.ItemID != myItemInfo.ItemID)
{
if (displayMsg)
{
string msg = string.Format("{0} is already open", myItemInfo.MyContent.MyEntry.MyDocument.LibTitle);
FlexibleMessageBox.Show(msg, "Library Document is Already Open", MessageBoxButtons.OK);
}
libDocAlreadyOpen = true;
break;
}
}
}
return libDocAlreadyOpen;
}
private bool LibDocAlreadyOpen(ItemInfo myItemInfo, string key, ref DisplayTabItem pg, bool displayMsg)
{
bool libDocAlreadyOpen = false;
// C2015-022 part of separate windows logic, check all tabs in all windows to see if lib docs
if (_AllDTCs != null && _AllDTCs.Count > 0)
{
foreach (int k in _AllDTCs.Keys)
{
DisplayTabControl dtc = _AllDTCs[k];
if (dtc._MyDisplayTabItems.ContainsKey(key))
{
pg = dtc._MyDisplayTabItems[key];
if (pg.MyItemInfo.ItemID != myItemInfo.ItemID)
{
if (displayMsg)
{
string msg = string.Format("{0} is already open", myItemInfo.MyContent.MyEntry.MyDocument.LibTitle);
FlexibleMessageBox.Show(msg, "Library Document is Already Open", MessageBoxButtons.OK);
}
libDocAlreadyOpen = true;
break;
}
}
}
}
return libDocAlreadyOpen;
}
/// <summary>
/// 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.
@ -1196,9 +1240,9 @@ namespace Volian.Controls.Library
private DisplayTabItem OpenDSOTabPage(ItemInfo myItemInfo)
{
DisplayTabItem pg = null;
EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID;
bool libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo, key, ref pg, true);
EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID;
bool libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo, key, ref pg, true);
if (!libDocAlreadyOpen && pg == null)
{
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>
internal void RemoveItem(DisplayTabItem myDisplayTabItem)
{
_MyDisplayTabItems.Remove(myDisplayTabItem.MyKey);
// Dispose the Panel
if (myDisplayTabItem.MyStepTabPanel != null)
myDisplayTabItem.MyStepTabPanel.Dispose();
if (myDisplayTabItem.MyDSOTabPanel != null)
myDisplayTabItem.MyDSOTabPanel.CloseDSO();
components.Remove(myDisplayTabItem);
myDisplayTabItem.Dispose();
if (_MyDisplayTabItems.ContainsKey(myDisplayTabItem.MyKey))
{
try
{
_MyDisplayTabItems.Remove(myDisplayTabItem.MyKey);
// Dispose of the procedure tab panel
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
}