C2026-043-Tech-Debt_v1 - Stash 1

This commit is contained in:
2026-07-21 06:49:28 -04:00
parent 0fed1acfd8
commit 9486b37300
70 changed files with 4222 additions and 10191 deletions
+26 -180
View File
@@ -1,12 +1,7 @@
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using VEPROMS.CSLA.Library;
using Volian.Controls.Library;
using System.Reflection;
using LBWordLibrary;
using JR.Utils.GUI.Forms;
@@ -17,7 +12,7 @@ namespace Volian.Controls.Library
public partial class DSOTabPanel : DevComponents.DotNetBar.PanelDockContainer
{
#region Private Fields
private DisplayTabControl _MyDisplayTabControl;
private readonly DisplayTabControl _MyDisplayTabControl;
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private AxEDWordLib.AxEDWord _MyEdWord; // B2017-133 Edraw DSO Framer Replacement
public AxEDWordLib.AxEDWord MyEdWord
@@ -26,9 +21,7 @@ namespace Volian.Controls.Library
set { _MyEdWord = value; }
}
private TransparentPanel _MyTransparentPanel;
private static int _Count = 0;
private DocumentInfo _MyDocumentInfo;
private int _MyCount;
private readonly DocumentInfo _MyDocumentInfo;
private DisplayTabItem _MyDisplayTabItem;
private DSOFile _DSOFile;
public static int MSWordLimit = 10;
@@ -43,11 +36,7 @@ namespace Volian.Controls.Library
/// <summary>
/// Count of DSO Pages open. Limited to 18 in DisplayTabControl
/// </summary>
public static int Count
{
get { return _Count; }
set { _Count = value; }
}
public static int Count { get; set; } = 0;
/// <summary>
/// Pointer to the related DisplayTabItem
/// </summary>
@@ -90,23 +79,17 @@ namespace Volian.Controls.Library
if (_MyEdWord == null) return false; // B2017-133 Edraw Is Dirty Property
// B2017-249 Recover Temporary File And AutoSave support for MSWord
return _MyEdWord.IsDirty() || MyDSOFile.ContentIsDirty;
//LBDocumentClass doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
//return !doc.Saved;
}
}
private bool _OverrideClose = false;
public bool OverrideClose
{
get { return _OverrideClose; }
set { _OverrideClose = value; }
}
public bool OverrideClose { get; set; } = false;
public E_ViewMode PanelViewEditMode = E_ViewMode.Edit;
#endregion
//private frmPG _frm = null;
#region Constructors
private Timer _RefreshTimer;
private ItemInfo _ItemInfo;
private bool _AllowedToEdit;
private readonly Timer _RefreshTimer;
private readonly ItemInfo _ItemInfo;
private readonly bool _AllowedToEdit;
public DSOTabPanel(DocumentInfo documentInfo, DisplayTabControl myDisplayTabControl, ItemInfo itemInfo, bool allowedToEdit)
{
_MyDisplayTabControl = myDisplayTabControl;
@@ -117,8 +100,10 @@ namespace Volian.Controls.Library
_MyDocumentInfo = documentInfo;
SetupDSO();
if (_MyEdWord == null) return; //B2017-219 could not open the word attachment so just return
_RefreshTimer = new Timer(); // Enabled is false and interval is 1/10th of second.
_RefreshTimer.Interval = 500;// B2017-133 Edraw
_RefreshTimer = new Timer
{
Interval = 500// B2017-133 Edraw
}; // Enabled is false and interval is 1/10th of second.
ClientSizeChanged += new EventHandler(DSOTabPanel_ClientSizeChanged);
_RefreshTimer.Tick += new EventHandler(_RefreshTimer_Tick);
// B2018-070 Activate MS Word Panel
@@ -145,21 +130,14 @@ namespace Volian.Controls.Library
_MyEdWord.DisablePrintHotKey(true);
}
// B2019-161 When tracking timing time this action
private static VolianTimer _TimeActivity = new VolianTimer("DSOTabPanel.cs _RefreshTimer_Tick", 148);
private static readonly VolianTimer _TimeActivity = new VolianTimer("DSOTabPanel.cs _RefreshTimer_Tick", 148);
void _RefreshTimer_Tick(object sender, EventArgs e)
{
_TimeActivity.Open();
_RefreshTimer.Enabled = false;
if (_MyEdWord != null)// B2017-133 Edraw
{
// B2018-070 Activate MS Word Panel
_MyEdWord.GotoItem(EDWordLib.WdGoToItem.wdGoToObject, EDWordLib.WdGoToDirection.wdGoToNext, 0, null);
}
//else
//{
// _MyDisplayTabControl.CloseTabItem(_MyDisplayTabItem);
//}
// B2018-070 Activate MS Word Panel
_MyEdWord?.GotoItem(EDWordLib.WdGoToItem.wdGoToObject, EDWordLib.WdGoToDirection.wdGoToNext, 0, null);
_TimeActivity.Close();
}
@@ -180,8 +158,7 @@ namespace Volian.Controls.Library
}
private void SetupDSO()
{
_Count++; // Increment the count of open Word documents (Limit = MSWordLimit)
_MyCount = _Count;
Count++; // Increment the count of open Word documents (Limit = MSWordLimit)
this._MyTransparentPanel = new TransparentPanel();
this._MyEdWord = new AxEDWordLib.AxEDWord();// B2017-133 Edraw
_MyEdWord.BeginInit();
@@ -195,14 +172,8 @@ namespace Volian.Controls.Library
this._MyTransparentPanel.Font = new System.Drawing.Font("Tahoma", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this._MyTransparentPanel.ForeColor = System.Drawing.Color.Brown; // This is the color used to show InActive on the right side on the Word
// document menu line.
//this._MyTransPanel.Location = new System.Drawing.Point(0, 0);
//this._MyTransPanel.Name = "transPanel1";
//this._MyTransPanel.Size = new System.Drawing.Size(370, 423);
//this._MyTransPanel.TabIndex = 1;
this._MyTransparentPanel.Click += new EventHandler(_MyTransparentPanel_Click);
this._MyEdWord.Dock = System.Windows.Forms.DockStyle.Fill;
//System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WordDSOTab));
//this._DSOFramer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("_FC.OcxState")));
_MyEdWord.EndInit();
LBDocumentClass doc;
try
@@ -215,18 +186,13 @@ namespace Volian.Controls.Library
this._MyEdWord.Open(MyDSOFile.MyFile.FullName);
doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
}
catch (Exception ex)
catch (Exception)
{
// B2017-137 Restore Previous valid version if the current version cannot be opened,
using (DocumentAuditInfoList dail = DocumentAuditInfoList.Get(MyDocumentInfo.DocID))
{
if (dail.Count > 0)
{
//DocumentAuditInfo dai = dail[0];
//foreach (DocumentAuditInfo tmpa in dail)
//{
// if (tmpa.DTS > dai.DTS) dai = tmpa;
//}
if (MessageBox.Show("Do you want to revert to a previous version?", "Error in MS Word section",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
@@ -242,12 +208,6 @@ namespace Volian.Controls.Library
MyDSOFile.SaveFile(0, "", _ItemInfo, false, StatusChanged); // B2017-219 save the restored document to database
this._MyEdWord = null; // B2017-219 Set MyEdWord to null - we will check for this in the calling functions
return;
//_MyDocumentInfo = DocumentInfo.Get(MyDocumentInfo.DocID);
//DocumentInfo.Refresh(myDoc);
////_DSOFile = null;
//this._MyEdWord.Open(MyDSOFile.MyFile.FullName);
//doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
//doc.Range(1, 1);
}
}
@@ -267,19 +227,16 @@ namespace Volian.Controls.Library
}
doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
//Console.WriteLine("Version {0}", doc.Application.Version);
float ver;
if (!float.TryParse(doc.Application.Version, out ver))
if (!float.TryParse(doc.Application.Version, out float ver))
ver = 12.0F;
this.Enter += new EventHandler(DSOTabPanel_Enter);
// B2018-070 Use InDSOTabPanel to determine if the word panel should be activated - Activate MS Word Panel
this.Leave += DSOTabPanel_Leave;
Application.DoEvents();
// The following line corrects Symbol characters in MSWord Sections
// CheckForSymbolCharacters(doc);
InitializeWordDocument(doc);
FindSearchString();
}
catch (Exception ex)
catch (Exception)
{
//string message = ShowException(ex);
//Console.WriteLine("\r\n-------------\r\n{0}{1}{2}\r\n-------------\r\n", MyDSOFile.MyFile.FullName, ex.GetType().Name, message);
@@ -301,8 +258,6 @@ namespace Volian.Controls.Library
DocStyle ds = MyDocumentInfo.DocumentEntries[0].MyContent.ContentItems[0].MyDocStyle;
// this will cause an error and goto the Catch if the family or size is null,
// Westinghouse needs it to to this - at least for now
//if (ds.Font.Family != null) doc.Application.Selection.Font.Name = ds.Font.Family;
//if (ds.Font.Size != null) doc.Application.Selection.Font.Size = (float)ds.Font.Size;
doc.Application.Selection.Font.Name = ds.Font.Family;
doc.Application.Selection.Font.Size = (float)ds.Font.Size;
doc.Application.Selection.ParagraphFormat.SpaceBefore = 0;
@@ -314,12 +269,12 @@ namespace Volian.Controls.Library
if (doc.ActiveWindow.ActivePane.View.Zoom.Percentage < 40)
doc.ActiveWindow.ActivePane.View.Zoom.Percentage = 100;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0059:Unnecessary assignment of a value", Justification = "found set for debugging purposes")]
public void FindSearchString()
{
if (SearchString == null) return;
// Get the Document
LBDocumentClass wordDoc = new LBDocumentClass(_MyEdWord.ActiveDocument());
//LBSelection sel = wordDoc.Application.Selection;
LBFind find = wordDoc.Application.Selection.Find;
find.ClearFormatting();
bool wildCards = SearchString.Contains("?") || SearchString.Contains("*");
@@ -350,51 +305,10 @@ namespace Volian.Controls.Library
if (sel.Start == sel.End) return null;
return sel.Text;
}
private string ShowException(Exception ex)
{
string sep = "\r\n ";
StringBuilder sb = new StringBuilder();
do
{
sb.Append(sep + ex.Message);
sep += " ";
ex = ex.InnerException;
} while (ex != null);
return sb.ToString();
}
//void _MyDSOFramer_Leave(object sender, EventArgs e)
//{
// vlnStackTrace.ShowStack("DSO Leave {0}", this.MyDocumentInfo.DocID);
//}
//void _MyDSOFramer_Enter(object sender, EventArgs e)
//{
// vlnStackTrace.ShowStack("DSO Enter {0}", this.MyDocumentInfo.DocID);
//}
//void _MyDSOFramer_GotFocus(object sender, EventArgs e)
//{
// vlnStackTrace.ShowStack("DSO Got Focus {0}",this.MyDocumentInfo.DocID);
//}
//void _MyDSOFramer_LostFocus(object sender, EventArgs e)
//{
// vlnStackTrace.ShowStack("DSO Lost Focus {0}", this.MyDocumentInfo.DocID);
//}
public void EnterPanel()
{
DSOTabPanel_Enter(this, new EventArgs());
}
//void DSOTabPanel_LostFocus(object sender, EventArgs e)
//{
// vlnStackTrace.ShowStack("DSOTabPanel_LostFocus {0} DocID {1} Index {2} {3}", _In_DSOTabPanel_Enter, this._MyDocumentInfo.DocID, _MyDisplayTabControl.MyBar.SelectedDockTab, sender.GetType().FullName);
//}
//void DSOTabPanel_GotFocus(object sender, EventArgs e)
//{
// vlnStackTrace.ShowStack("DSOTabPanel_GotFocus {0} DocID {1} Index {2} {3}", _In_DSOTabPanel_Enter, this._MyDocumentInfo.DocID, _MyDisplayTabControl.MyBar.SelectedDockTab, sender.GetType().FullName);
//}
#endregion
#region Event Handlers
/// <summary>
@@ -415,29 +329,16 @@ namespace Volian.Controls.Library
{
this.Select();
}
///// <summary>
///// If the user presses the save button, tell the file to save it's contents to the database
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//void _MyDSOFramer_OnSaveCompleted(object sender, AxDSOFramer._DFramerCtlEvents_OnSaveCompletedEvent e)
//{
// _MyLog.WarnFormat("_MyDSOFramer_OnSaveCompleted");
// Volian.Base.Library.vlnStackTrace.ShowStack("_MyDSOFramer_OnSaveCompleted");
// SaveDSO_Phase2();
//}
private void SaveDSO_Phase2()
{
// Unfortunately, the only way to handle view mode for DSO Framer is to not save.
if (PanelViewEditMode == E_ViewMode.View)
{
MessageBox.Show("Currently in VIEW mode,\r\n cannot Save " + _MyDisplayTabItem.Tooltip);
MessageBox.Show($"Currently in VIEW mode,\r\n cannot Save {_MyDisplayTabItem.Tooltip}");
return;
}
LBDocumentClass doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
//while (doc.Saved = false)
// Application.DoEvents();
string tmp = GetReflectiveProperty(_MyEdWord.ActiveDocument(), "FullName");
if (System.IO.File.Exists(tmp))
MyDSOFile.FullName = tmp;
@@ -451,10 +352,7 @@ namespace Volian.Controls.Library
if (myei != null && myei.MyDocument != null && myei.MyDocument.LibTitle != null && myei.MyDocument.LibTitle != "")
{
// C2019-033 - make save options more clear with respect to library documents
string msgstr = "Save to Library Document?" +
"\n\n YES - Save for all usages of this Library Document." +
"\n\n NO - Unlink this Section from the Library Document and Save in this Word Section.\n\n" +
_MyDocumentInfo.LibraryDocumentUsageAll;
string msgstr = $"Save to Library Document?\n\n YES - Save for all usages of this Library Document.\n\n NO - Unlink this Section from the Library Document and Save in this Word Section.\n\n{_MyDocumentInfo.LibraryDocumentUsageAll}";
DialogResult ans = FlexibleMessageBox.Show(msgstr, "Document Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (ans == DialogResult.No) cvtLibDoc = true;
}
@@ -475,16 +373,6 @@ namespace Volian.Controls.Library
tc.ONStatusChanged(this, new DisplayTabControlStatusEventArgs(type, count, text));
}
}
///// <summary>
///// Before a document closes check to see if it's contents should be saved.
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//void _MyDSOFramer_BeforeDocumentClosed(object sender, AxDSOFramer._DFramerCtlEvents_BeforeDocumentClosedEvent e)
//{
// SaveDSOPhase1();
//}
private void SaveDSO_Phase1()
{
try
@@ -494,7 +382,6 @@ namespace Volian.Controls.Library
this.Enter -= new EventHandler(DSOTabPanel_Enter);
// B2018-070 Use InDSOTabPanel to determine if the word panel should be activated - Activate MS Word Panel
this.Leave -= DSOTabPanel_Leave;
// SaveDirty(); // SaveDirty happens in CloseDSO(bool)
}
catch (Exception ex)
{
@@ -514,11 +401,6 @@ namespace Volian.Controls.Library
bool stat = _MyEdWord.Save();// B2017-133 Edraw
//Console.WriteLine("Save = {0}", stat);
SaveDSO_Phase2();
//_MyDSOFramer_OnSaveCompleted(this, null);
// These are handled in the method above
//LBDocumentClass doc = new LBDocumentClass(_MyDSOFramer.ActiveDocument);
//MyDSOFile.FullName = GetReflectiveProperty(_MyDSOFramer.ActiveDocument, "FullName");
//MyDSOFile.SaveFile(doc.Length, doc.Ascii);
}
catch (Exception ex)
{
@@ -543,13 +425,12 @@ namespace Volian.Controls.Library
// Unfortunately, the only way to handle view mode for DSO Framer is to not save.
if (PanelViewEditMode == E_ViewMode.View || !_AllowedToEdit)
{
MessageBox.Show("Currently in VIEW mode,\r\n cannot Save " + _MyDisplayTabItem.Tooltip);
MessageBox.Show($"Currently in VIEW mode,\r\n cannot Save {_MyDisplayTabItem.Tooltip}");
return false;
}
//if (MessageBox.Show("Save changes to " + _MyDisplayTabItem.MyItemInfo.TabTitle + "\r\n" + _MyDisplayTabItem.MyItemInfo.TabToolTip, "Document has Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
// B2017-249 Recover Temporary File And AutoSave support for MSWord
// C2019-033 - make save options more clear with respect to library documents second dialog will appear if Yes is selected and it's a library document
string msgstr = "Save changes to " + (MyDSOFile.MyDocument.ContentIsDirty ? "Recovered Version of " : "") + _MyDisplayTabItem.Text;
string msgstr = $"Save changes to {(MyDSOFile.MyDocument.ContentIsDirty ? "Recovered Version of " : "")}{_MyDisplayTabItem.Text}";
if (FlexibleMessageBox.Show(msgstr, (IsDirty ? "Document has Changed" : "Previous Changes were not Saved"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
return SaveDSO();
//Console.WriteLine("Delete {0}", MyDSOFile.MyFile.Name);
@@ -595,15 +476,6 @@ namespace Volian.Controls.Library
StepTabPanel stpanel = _MyDisplayTabControl.GetProcedureTabPanel(MyDisplayTabItem.MyItemInfo);
PanelViewEditMode = (stpanel == null) ? E_ViewMode.Edit : stpanel.MyStepPanel.VwMode;
}
try
{
//_MyDSOFramer.EventsEnabled = true;
//_MyEdWord.FrameHookPolicy = DSOFramer.dsoFrameHookPolicy.dsoResetNow;
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.ErrorFormat("DSOTabPage_Enter", ex);
}
if (_In_DSOTabPanel_Enter) return;
//vlnStackTrace.ShowStack("DSOTabPanel_Enter {0} DocID {1} Index {2} {3}",_In_DSOTabPanel_Enter, this._MyDocumentInfo.DocID, _MyDisplayTabControl.MyBar.SelectedDockTab, sender.GetType().FullName);
_In_DSOTabPanel_Enter = true;
@@ -628,15 +500,6 @@ namespace Volian.Controls.Library
/// </summary>
/// <returns></returns>
public bool CloseDSO()
{
return CloseDSO(false);
}
/// <summary>
/// Cleans-up the DSO Framer window
/// </summary>
/// <param name="force"></param>
/// <returns></returns>
public bool CloseDSO(bool force)
{
_MyLog.Debug("CloseDSO");
bool result = true;
@@ -652,38 +515,21 @@ namespace Volian.Controls.Library
_MyEdWord = null;
// B2017-249 Recover Temporary File And AutoSave support for MSWord
if (DeleteOnClose) MyDSOFile.MyFile.Delete();
_Count--;
Count--;
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("SaveDSO - " + this.Name, ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error($"SaveDSO - {this.Name}", ex);
result = false;
}
return result;
}
/// <summary>
/// Activates the current DSO Framer window (Word)
/// </summary>
public void Activate()
{
try
{
//this._MyEdWord.Activate();
//if (_MyCount <= MSWordLimit)
// this._MyEdWord.FrameHookPolicy = DSOFramer.dsoFrameHookPolicy.dsoResetNow;
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Activate", ex);
}
}
#endregion
#region DocumentProperties
private string GetReflectiveProperty(object objectToInspect, string propertyName)
{
string returnString = "";
//To use reflection on an object, you
// first need to get an instance
// of that object's type.