C2015-022 Separate Windows Upgrade – support CopyStep among child windows, manage dictionary of child windows, OpenItem will decide if need to open in a child window or main window, child windows support of library documents

This commit is contained in:
John Jenko 2018-03-12 14:36:44 +00:00
parent d00ebcc35d
commit 8ba6a5d64a
2 changed files with 203 additions and 81 deletions

View File

@ -23,6 +23,10 @@ namespace Volian.Controls.Library
components.Dispose();
}
base.Dispose(disposing);
// C2015-022 part of separate windows upgrade. Remove the tab from our dictionary of all tab controls
//if (_AllDTCs.Count > 0 && VersionID != null && _AllDTCs.ContainsKey((int)VersionID))
if (_AllDTCs.Count > 0 && _AllDTCs.ContainsKey((int)VersionID))
_AllDTCs.Remove((int)VersionID);
}
#region Component Designer generated code

View File

@ -58,25 +58,95 @@ namespace Volian.Controls.Library
set { DisplayTabControl._SyncronizeEnahnced = value; }
}
private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>();
private int? _VersionID = null;
public int? VersionID
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
{
if (_AllDTCs.ContainsKey((int)value))
_AllDTCs[(int)value] = this;
else
_AllDTCs.Add((int)value, this);
_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;
}
}
public event ItemSelectedChangedEvent OpenEnhancedDocument;
public void OnOpenEnhancedDocument(ItemSelectedChangedEventArgs args)
// This tells the display tab control whether or not the Separate Windows setting was set
private bool _SeparateWindows = false;
public bool SeparateWindows
{
if (OpenEnhancedDocument != null)
OpenEnhancedDocument(this, args);
get { return _SeparateWindows; }
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)
{
if (OpenInSeparateWindow != null)
OpenInSeparateWindow(this, args);
}
public event ItemSelectedChangedEvent RefreshEnhancedDocument;
public void OnRefreshEnhancedDocument(ItemSelectedChangedEventArgs args)
@ -99,6 +169,13 @@ namespace Volian.Controls.Library
{
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
@ -398,6 +475,8 @@ namespace Volian.Controls.Library
{
e.RemoveDockTab = true;
_RemovedDisplayTabItems.Add((DisplayTabItem)e.DockContainerItem);
if (_MyDisplayTabItems.ContainsKey(((DisplayTabItem)e.DockContainerItem).MyKey))
_MyDisplayTabItems.Remove(((DisplayTabItem)e.DockContainerItem).MyKey); // C2015-022 separate windows supporting logic
DisplayTabItem dti = e.DockContainerItem as DisplayTabItem;
if (dti != null && dti.MyStepTabPanel != null)
dti.MyStepTabPanel.MyStepPanel.Dispose();
@ -448,66 +527,80 @@ namespace Volian.Controls.Library
_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>
/// <returns></returns>
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
{
MessageBox.Show(this, "Possible disconnected item", "Item Not Found");
return null;
}
if(VersionID!=myItemInfo.MyDocVersion.VersionID)
{
if(_AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
}
if(VersionID != 0)
return _AllDTCs[0].OpenItem(myItemInfo);
}
string message = string.Empty;
if (myItemInfo.MyContent.MyEntry == null) //not a document
{
if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyProcedure.ItemID, CheckOutType.Procedure, ref message))
{
MessageBox.Show(this, message, "Procedure Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}
}
else
{
if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyContent.MyEntry.DocID, CheckOutType.Document, ref message))
{
MessageBox.Show(this, message, "Document Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}
}
//if (myItemInfo.IsProcedure)
//{
// DateTime start = DateTime.Now;
// myItemInfo = ProcedureInfo.GetItemAndChildrenByUnit(myItemInfo.ItemID, 0, 2);
// TimeSpan howlong = DateTime.Now - start;
// Console.WriteLine("Overall - " + howlong.ToString());
//}
CleanUpClosedItems();
if (myItemInfo == null) return null;
// if this is an auto table of contents section, don't edit it:
if (myItemInfo.IsAutoTOCSection)
{
MessageBox.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;
}
_MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item.
if (myItemInfo.MyContent.MyEntry == null) // If it is a Word document open in step editor
return OpenStepTabPage(myItemInfo,setFocus);
else // Otherwise open it in the Word editor
return OpenDSOTabPage(myItemInfo);
}
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
{
MessageBox.Show(this, "Possible disconnected item", "Item Not Found");
return null;
}
string message = string.Empty;
if (myItemInfo.MyContent.MyEntry == null) //not a document
{
if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyProcedure.ItemID, CheckOutType.Procedure, ref message))
{
MessageBox.Show(this, message, "Procedure Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}
}
else
{
if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyContent.MyEntry.DocID, CheckOutType.Document, ref message))
{
MessageBox.Show(this, message, "Document Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}
}
CleanUpClosedItems();
if (myItemInfo == null) return null;
// if this is an auto table of contents section, don't edit it:
if (myItemInfo.IsAutoTOCSection)
{
MessageBox.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);
// C2015-022 modified if statement logic to support separate windows
// if opening the first procedure in a set, and the main PROMS window has a procedure opened from a different set,
// then create a new child window. All other procedures from that same set will open in this child window.
// _AllDTCs is a dictionary of of all procedure sets opened along with their DisplayTabContol. The key to
// the dictioan is the set's VersionID
if (VersionID != 0)
{
if (SeparateWindows && !libDocAlreadyOpen)
{
if (!_AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{
OnOpenInSeparateWindow(new ItemSelectedChangedEventArgs(myItemInfo2)); // create a child (separate) PROMS window
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
}
}
if (VersionID != myItemInfo.MyDocVersion.VersionID && _AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
}
}
if (!libDocAlreadyOpen)
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();
@ -648,7 +741,7 @@ namespace Volian.Controls.Library
{
b.CloseDockTab(myTabItem);
//b.Items.Remove(myTabItem);
RemoveItem(myTabItem);
RemoveItem(myTabItem);
}
}
/// <summary>
@ -1021,6 +1114,39 @@ namespace Volian.Controls.Library
if (pg != null && pg.MyStepTabPanel != null) pg.MyStepTabPanel.MyStepTabRibbon.SetChangeId(chgid, ii);
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, 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);
MessageBox.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.
@ -1030,18 +1156,10 @@ namespace Volian.Controls.Library
private DisplayTabItem OpenDSOTabPage(ItemInfo myItemInfo)
{
DisplayTabItem pg = null;
EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID;
if (_MyDisplayTabItems.ContainsKey(key)) // If document page open use it
{
pg = _MyDisplayTabItems[key];
if (pg.MyItemInfo.ItemID != myItemInfo.ItemID)
{
string msg = string.Format("{0} is already open", myItemInfo.MyContent.MyEntry.MyDocument.LibTitle);
MessageBox.Show(msg, "Library Document is Already Open", MessageBoxButtons.OK);
}
}
else
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
{