From 94db524a119ec021d4f28bdb0cf575b64bea7dfb Mon Sep 17 00:00:00 2001 From: mschill Date: Mon, 29 Jun 2026 09:51:48 -0400 Subject: [PATCH] =?UTF-8?q?B2026-057=20-=20Issue=20when=20ROs=20are=20out?= =?UTF-8?q?=20of=20date=20and=20swapping=20between=20sets=20=E2=80=93=20so?= =?UTF-8?q?metimes=20asked=20if=20want=20to=20update=20ROs=20twice=20if=20?= =?UTF-8?q?said=20no=20the=20first=20time.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PROMS/Volian.Controls.Library/DisplayRO.cs | 1976 ++++++++++---------- 1 file changed, 996 insertions(+), 980 deletions(-) diff --git a/PROMS/Volian.Controls.Library/DisplayRO.cs b/PROMS/Volian.Controls.Library/DisplayRO.cs index 35216fff..2252e704 100644 --- a/PROMS/Volian.Controls.Library/DisplayRO.cs +++ b/PROMS/Volian.Controls.Library/DisplayRO.cs @@ -2,13 +2,12 @@ using DevComponents.DotNetBar; using JR.Utils.GUI.Forms; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; -using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Windows.Forms; using VEPROMS.CSLA.Library; using Volian.Base.Library; @@ -16,47 +15,47 @@ using XYPlots; namespace Volian.Controls.Library { - public partial class DisplayRO : UserControl - { - #region Log4Net + public partial class DisplayRO : UserControl + { + #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 - #region Fields + #region Fields - private const string DummyNodeText = "VLN_DUMMY_NODE"; - private const int MaxNumSearchRecords = 1000; + private const string DummyNodeText = "VLN_DUMMY_NODE"; + private const int MaxNumSearchRecords = 1000; - // B2019-161 When tracking timing time this action - private static VolianTimer _timeActivity = new VolianTimer("DisplayRO MyRTB_SelectionChanged", 117); - private static Regex _regExGetNumber = new Regex(@"^ *[+-]?[.,0-9/]+(E[+-]?[0-9]+)?"); - private static UserInfo _myUserInfo = null; + // B2019-161 When tracking timing time this action + private static VolianTimer _timeActivity = new VolianTimer("DisplayRO MyRTB_SelectionChanged", 117); + private static Regex _regExGetNumber = new Regex(@"^ *[+-]?[.,0-9/]+(E[+-]?[0-9]+)?"); + private static UserInfo _myUserInfo = null; - private Timer _searchTimer = null; - private string _lastSearchValue = string.Empty; + private Timer _searchTimer = null; + private string _lastSearchValue = string.Empty; - private ProgressBarItem _progressBar; - private DisplayTabControl _tabControl; - private StepRTB _myRTB; - private string _selectedRoidBeforeRoEditor = null; + private ProgressBarItem _progressBar; + private DisplayTabControl _tabControl; + private StepRTB _myRTB; + private string _selectedRoidBeforeRoEditor = null; - private ROFstInfo _myROFST; - private DocVersionInfo _docVersionInfo; - private RoUsageInfo _savCurROLink; - private E_ROValueType _roTypeFilter = E_ROValueType.All; + private ROFstInfo _myROFST; + private DocVersionInfo _docVersionInfo; + private RoUsageInfo _savCurROLink; + private E_ROValueType _roTypeFilter = E_ROValueType.All; - //private ROFstInfo _curROFST = null; - private int? _currRofstID = null; - private int? _currDocVersionID = null; - - private RoUsageInfo _curROLink; - private E_ROValueType _curROTypeFilter = E_ROValueType.All; + //private ROFstInfo _curROFST = null; + private int? _currRofstID = null; + private int? _currDocVersionID = null; - private ROFSTLookup.rochild selectedChld; + private RoUsageInfo _curROLink; + private E_ROValueType _curROTypeFilter = E_ROValueType.All; - private DisplayTags displayTags; + private ROFSTLookup.rochild selectedChld; + + private DisplayTags displayTags; #endregion @@ -64,205 +63,210 @@ namespace Volian.Controls.Library #region Properties public ProgressBarItem ProgressBar - { - get { return _progressBar; } - set { _progressBar = value; } - } + { + get { return _progressBar; } + set { _progressBar = value; } + } - public DisplayTabControl TabControl - { - get { return _tabControl; } - set { _tabControl = value; } - } + public DisplayTabControl TabControl + { + get { return _tabControl; } + set { _tabControl = value; } + } - public bool IsRofstValid - { - get { return (_myROFST != null && _myROFST.ROFstAssociations != null && _myROFST.ROFstAssociationCount > 0); } - } + public bool IsRofstValid + { + get { return (_myROFST != null && _myROFST.ROFstAssociations != null && _myROFST.ROFstAssociationCount > 0); } + } - public bool RoTreeNeedsReloaded - { + public bool RoTreeNeedsReloaded + { get { return (MyROFST != null && _currRofstID != null && MyROFST.ROFstID != (int)_currRofstID) || - (MyDvi != null && _currDocVersionID != null && MyDvi.VersionID != (int)_currDocVersionID) || - // B2022-142 check if we went from a RO Table or RO Figure step type to a regular step type - // or if we went from a regular step type to a RO Table or RO Figure step type + (MyDvi != null && _currDocVersionID != null && MyDvi.VersionID != (int)_currDocVersionID) || + // B2022-142 check if we went from a RO Table or RO Figure step type to a regular step type + // or if we went from a regular step type to a RO Table or RO Figure step type (_myRTB != null && (_myRTB.IsRoTable != lastRTBwasROTable || _myRTB.IsRoFigure != lastRTBwasROFigure)); } - } + } - //This flag will be set when the docversion gets updated to let it know that the full tree needs a refresh - private bool changedDocVersion = false; + //This flag will be set when the docversion gets updated to let it know that the full tree needs a refresh + private bool changedDocVersion = false; + + //B2026-057 PROMS Crash when Closing Tabs + // this flag will prevent multiple asking in a row if should updste ROs + private static bool askedAboutchangedDocVersion = false; public ROFstInfo MyROFST - { - get { return _myROFST; } - set - { - // Define the tree nodes based on this rofst/docversion - // Rofst is required, DocVersion can be null. If Rofst is null then make DocVersion null - if (_myROFST != value) - { - if (value == null) - { - _myROFST = null; - MyDvi = null; - } - else - { - _myROFST = value; + { + get { return _myROFST; } + set + { + // Define the tree nodes based on this rofst/docversion + // Rofst is required, DocVersion can be null. If Rofst is null then make DocVersion null + if (_myROFST != value) + { + if (value == null) + { + _myROFST = null; + MyDvi = null; + } + else + { + _myROFST = value; - if (MyDvi == null) - { - MyDvi = (IsRofstValid) ? _myROFST.ROFstAssociations[0].MyDocVersion : null; - } - } + if (MyDvi == null) + { + MyDvi = (IsRofstValid) ? _myROFST.ROFstAssociations[0].MyDocVersion : null; + } + } - // B2022-123: RO Tab Treeview not showing correct RO values when switching between procedures. - _currRofstID = (IsRofstValid) ? (int?)_myROFST.ROFstID : null; - } - } - } + // B2022-123: RO Tab Treeview not showing correct RO values when switching between procedures. + _currRofstID = (IsRofstValid) ? (int?)_myROFST.ROFstID : null; + } + } + } - public DocVersionInfo MyDvi - { - // B2022-135 Submitted for Admin Tools (Check RO Links tool) - get { return (_myRTB != null) ? _myRTB.MyDVI : _docVersionInfo; } - set - { - // B2022-135 Submitted for Admin Tools (Check RO Links tool) - if (_docVersionInfo == null || _docVersionInfo != value || _docVersionInfo.VersionID != value.VersionID) - { - //Set flag for modified the docversion - should check for new ROs + public DocVersionInfo MyDvi + { + // B2022-135 Submitted for Admin Tools (Check RO Links tool) + get { return (_myRTB != null) ? _myRTB.MyDVI : _docVersionInfo; } + set + { + // B2022-135 Submitted for Admin Tools (Check RO Links tool) + if (_docVersionInfo == null || _docVersionInfo != value || _docVersionInfo.VersionID != value.VersionID) + { + //Set flag for modified the docversion - should check for new ROs if (_docVersionInfo?.VersionID != value?.VersionID) { changedDocVersion = true; + askedAboutchangedDocVersion = false; } _docVersionInfo = value; - if (_myRTB != null && (_docVersionInfo == null || _docVersionInfo.VersionID != _myRTB.MyDVI.VersionID)) - { - _docVersionInfo = _myRTB.MyDVI; - } + if (_myRTB != null && (_docVersionInfo == null || _docVersionInfo.VersionID != _myRTB.MyDVI.VersionID)) + { + _docVersionInfo = _myRTB.MyDVI; + } } // B2022-123: RO Tab Treeview not showing correct RO values when switching between procedures. _currDocVersionID = (_docVersionInfo != null) ? (int?)_docVersionInfo.VersionID : null; - } - } + } + } - public ROFSTLookup MyROFSTLookup - { + public ROFSTLookup MyROFSTLookup + { get { return (_myROFST != null) ? new ROFSTLookup(_myROFST.ROFstID, _docVersionInfo) : null;} - } + } - public E_ROValueType ROTypeFilter - { - get { return _roTypeFilter; } + public E_ROValueType ROTypeFilter + { + get { return _roTypeFilter; } set {_roTypeFilter = value; } - } + } - public RoUsageInfo CurROLink - { - get { return _curROLink; } - set - { - // Volian.Base.Library.vlnStackTrace.ShowStack("value={0} MyRTB={1}", value, ((MyRTB != null) ? MyRTB.SelectedText : "" )); + public RoUsageInfo CurROLink + { + get { return _curROLink; } + set + { + // Volian.Base.Library.vlnStackTrace.ShowStack("value={0} MyRTB={1}", value, ((MyRTB != null) ? MyRTB.SelectedText : "" )); - // modify - set the controls to the current ro - if (value != null) - { - if (_curROLink != value) - { - _curROLink = value; - _savCurROLink = _curROLink; + // modify - set the controls to the current ro + if (value != null) + { + if (_curROLink != value) + { + _curROLink = value; + _savCurROLink = _curROLink; - // B2022-088: [JPR] Find Doc Ro button not working in Word Sections - // B2022-098: [JPR] ROs not being resolved in Word Sections - string roid = ROFSTLookup.FormatRoidKey(_curROLink.ROID, true); - ExpandNode(roid); - } - } - else // if (_curROLink != null) // insert - clear out controls - { - _curROLink = value; - tvROFST.SelectedNode = null; - ResetSearch(); + // B2022-088: [JPR] Find Doc Ro button not working in Word Sections + // B2022-098: [JPR] ROs not being resolved in Word Sections + string roid = ROFSTLookup.FormatRoidKey(_curROLink.ROID, true); + ExpandNode(roid); + } + } + else // if (_curROLink != null) // insert - clear out controls + { + _curROLink = value; + tvROFST.SelectedNode = null; + ResetSearch(); - } - } - } + } + } + } - // B2022-142 added this local variables to keep flag if the last step type was a RO Table or a RO Figure - // this is used to determin if we need to re-load the RO tree - private bool lastRTBwasROTable = false; - private bool lastRTBwasROFigure = false; - public StepRTB MyRTB - { - get { return _myRTB; } - set - { - if (value == null) - { - _myRTB = value; - MyROFST = null; + // B2022-142 added this local variables to keep flag if the last step type was a RO Table or a RO Figure + // this is used to determin if we need to re-load the RO tree + private bool lastRTBwasROTable = false; + private bool lastRTBwasROFigure = false; + public StepRTB MyRTB + { + get { return _myRTB; } + set + { + if (value == null) + { + _myRTB = value; + MyROFST = null; - // B2022-088: [JPR] Find Doc Ro button not working in Word Sections - // B2022-098: [JPR] ROs not being resolved in Word Sections - CurROLink = null; - _savCurROLink = null; + // B2022-088: [JPR] Find Doc Ro button not working in Word Sections + // B2022-098: [JPR] ROs not being resolved in Word Sections + CurROLink = null; + _savCurROLink = null; //Clear flag for modified the docversion (if should check for new ROs) - //clearing this flag here prevents it from checking twice + //clearing this flag here prevents it from checking twice changedDocVersion = false; } else if(_myRTB != value) - { - if (_myRTB != null) - { - lastRTBwasROTable = _myRTB.IsRoTable; // B2022-141 save whether last RTB was a RO Table - lastRTBwasROFigure = _myRTB.IsRoFigure; // B2022-141 save whether last RTB was a RO Figure - } - _myRTB = value; + { + if (_myRTB != null) + { + lastRTBwasROTable = _myRTB.IsRoTable; // B2022-141 save whether last RTB was a RO Table + lastRTBwasROFigure = _myRTB.IsRoFigure; // B2022-141 save whether last RTB was a RO Figure + } + _myRTB = value; - MyRTB.LinkChanged -= new StepRTBLinkEvent(MyRTB_LinkChanged); - MyRTB.LinkChanged += new StepRTBLinkEvent(MyRTB_LinkChanged); - MyRTB.SelectionChanged -= new EventHandler(MyRTB_SelectionChanged); - MyRTB.SelectionChanged += new EventHandler(MyRTB_SelectionChanged); + MyRTB.LinkChanged -= new StepRTBLinkEvent(MyRTB_LinkChanged); + MyRTB.LinkChanged += new StepRTBLinkEvent(MyRTB_LinkChanged); + MyRTB.SelectionChanged -= new EventHandler(MyRTB_SelectionChanged); + MyRTB.SelectionChanged += new EventHandler(MyRTB_SelectionChanged); - if (string.IsNullOrEmpty(MyRTB.MyLinkText)) - { - CurROLink = null; - _savCurROLink = null; - } + if (string.IsNullOrEmpty(MyRTB.MyLinkText)) + { + CurROLink = null; + _savCurROLink = null; + } // B2023-004 assign the doc version info associated with the current RTB (rich text box) // this fixes an issue where unit designators could not be linked in the step edit (BNPP data) MyDvi = _myRTB.MyItemInfo.MyDocVersion; - MyROFST = (_myRTB.MyItemInfo.MyDocVersion.DocVersionAssociationCount > 0) ? _myRTB.MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst : null; - } - } - } + MyROFST = (_myRTB.MyItemInfo.MyDocVersion.DocVersionAssociationCount > 0) ? _myRTB.MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst : null; + } + } + } - public bool IsEnhancedStep - { - get { return (MyRTB != null && MyRTB.MyItemInfo != null && MyRTB.MyItemInfo.IsEnhancedStep); } - } + public bool IsEnhancedStep + { + get { return (MyRTB != null && MyRTB.MyItemInfo != null && MyRTB.MyItemInfo.IsEnhancedStep); } + } - public bool IsNotStep - { - get { return (MyRTB != null && MyRTB.MyItemInfo != null && (MyRTB.MyItemInfo.IsProcedure || MyRTB.MyItemInfo.IsSection)); } - } + public bool IsNotStep + { + get { return (MyRTB != null && MyRTB.MyItemInfo != null && (MyRTB.MyItemInfo.IsProcedure || MyRTB.MyItemInfo.IsSection)); } + } - public bool IsInWordDoc - { - get { return (TabControl != null && TabControl.SelectedDisplayTabItem != null && TabControl.SelectedDisplayTabItem.MyDSOTabPanel != null); } - } + public bool IsInWordDoc + { + get { return (TabControl != null && TabControl.SelectedDisplayTabItem != null && TabControl.SelectedDisplayTabItem.MyDSOTabPanel != null); } + } - public static UserInfo MyUserInfo - { - get { return _myUserInfo; } - set { _myUserInfo = value; } - } + public static UserInfo MyUserInfo + { + get { return _myUserInfo; } + set { _myUserInfo = value; } + } public SessionInfo MySessionInfo { get; set; } @@ -271,28 +275,28 @@ namespace Volian.Controls.Library #region Constructors public DisplayRO() - { - InitializeComponent(); + { + InitializeComponent(); - panelRoValue.BackColor = Color.Cornsilk; - panelValue.BackColor = Color.Cornsilk; + panelRoValue.BackColor = Color.Cornsilk; + panelValue.BackColor = Color.Cornsilk; - _currRofstID = null; - _currDocVersionID = null; + _currRofstID = null; + _currDocVersionID = null; - if (_searchTimer == null) - { - _searchTimer = new Timer(); - _searchTimer.Interval = 1000; - _searchTimer.Tick += new EventHandler(SelectionTimer_Tick); - _searchTimer.Stop(); - } + if (_searchTimer == null) + { + _searchTimer = new Timer(); + _searchTimer.Interval = 1000; + _searchTimer.Tick += new EventHandler(SelectionTimer_Tick); + _searchTimer.Stop(); + } - // Initialize the DisplayTags object - displayTags = new DisplayTags(); + // Initialize the DisplayTags object + displayTags = new DisplayTags(); - } + } #endregion #region Event Handlers @@ -348,251 +352,251 @@ namespace Volian.Controls.Library } public void MyRTB_LinkChanged(object sender, StepPanelLinkEventArgs args) - { - CurROLink = null; - if (MyRTB.MyLinkText != null) CurROLink = args.MyLinkText.MyRoUsageInfo; - } + { + CurROLink = null; + if (MyRTB.MyLinkText != null) CurROLink = args.MyLinkText.MyRoUsageInfo; + } - public void MyRTB_SelectionChanged(object sender, EventArgs e) - { - _timeActivity.Open(); + public void MyRTB_SelectionChanged(object sender, EventArgs e) + { + _timeActivity.Open(); - // B2022-088: [JPR] Find Doc Ro button not working in Word Sections - // B2022-098: [JPR] ROs not being resolved in Word Sections - // Need to call Stop then Start just in case the uses has changed their selection - // before the timer.Tick event fires. Calling Stop/Start is the same as Reset for the timer - _searchTimer.Stop(); - _searchTimer.Start(); + // B2022-088: [JPR] Find Doc Ro button not working in Word Sections + // B2022-098: [JPR] ROs not being resolved in Word Sections + // Need to call Stop then Start just in case the uses has changed their selection + // before the timer.Tick event fires. Calling Stop/Start is the same as Reset for the timer + _searchTimer.Stop(); + _searchTimer.Start(); - _timeActivity.Close(); - } + _timeActivity.Close(); + } - private void SelectionTimer_Tick(object sender, EventArgs e) - { - // Stop the timer - _searchTimer.Stop(); + private void SelectionTimer_Tick(object sender, EventArgs e) + { + // Stop the timer + _searchTimer.Stop(); - // Process RO Value Search - if (MyRTB != null && !MyRTB.IsDisposed) - { - ProcessSearch(MyRTB.SelectedText, (int)ROFSTLookup.SearchTypes.StartsWith); - } - } + // Process RO Value Search + if (MyRTB != null && !MyRTB.IsDisposed) + { + ProcessSearch(MyRTB.SelectedText, (int)ROFSTLookup.SearchTypes.StartsWith); + } + } - #endregion + #endregion - #region (Tree Node) + #region (Tree Node) - private void tvROFST_DoubleClick(object sender, EventArgs e) - { - // B2016-132: don't process a double click on an RO if on an enhanced step: - if (!IsEnhancedStep) - { - SaveRO(); - } - } + private void tvROFST_DoubleClick(object sender, EventArgs e) + { + // B2016-132: don't process a double click on an RO if on an enhanced step: + if (!IsEnhancedStep) + { + SaveRO(); + } + } - private void tvROFST_BeforeExpand(object sender, TreeViewCancelEventArgs e) - { - LoadChildren(e.Node); - } + private void tvROFST_BeforeExpand(object sender, TreeViewCancelEventArgs e) + { + LoadChildren(e.Node); + } - private void tvROFST_AfterSelect(object sender, TreeViewEventArgs e) - { - // B2022-088: [JPR] Find Doc Ro button not working in Word Sections - // B2022-098: [JPR] ROs not being resolved in Word Sections - if (e.Node.Tag is ROFSTLookup.rochild) - { - ROFSTLookup.rochild chld = (ROFSTLookup.rochild)e.Node.Tag; - selectedChld = chld; + private void tvROFST_AfterSelect(object sender, TreeViewEventArgs e) + { + // B2022-088: [JPR] Find Doc Ro button not working in Word Sections + // B2022-098: [JPR] ROs not being resolved in Word Sections + if (e.Node.Tag is ROFSTLookup.rochild) + { + ROFSTLookup.rochild chld = (ROFSTLookup.rochild)e.Node.Tag; + selectedChld = chld; - if (chld.value != null) - { - chld.value = Regex.Replace(chld.value, @"\\u([0-9]{1,4})\?", m => int.TryParse(m?.Groups[1]?.Value, out int result) ? Convert.ToChar(result).ToString() : ""); - RoUsageInfo SavROLink = null; - if (_savCurROLink != null) SavROLink = _savCurROLink; + if (chld.value != null) + { + chld.value = Regex.Replace(chld.value, @"\\u([0-9]{1,4})\?", m => int.TryParse(m?.Groups[1]?.Value, out int result) ? Convert.ToChar(result).ToString() : ""); + RoUsageInfo SavROLink = null; + if (_savCurROLink != null) SavROLink = _savCurROLink; - // Set the Display Text to the AccPageID - lbROId.Text = chld.appid; + // Set the Display Text to the AccPageID + lbROId.Text = chld.appid; - //B2017-245 Disable SaveRO button for Procedures and Sections - //B2020-049: Save button not enabled on Word docs, only if a procedure was opened first and immediately after the word document - // section is opened (added 'IsInWorDoc') - btnSaveRO.Enabled = (IsInWordDoc || (!IsNotStep && !IsEnhancedStep)) && UserInfo.CanEdit(MyUserInfo, MyDvi) && ((SavROLink == null) || !(chld.roid.Equals(SavROLink.ROID.ToUpper()))); //added security check (UserInfo.CanEdit) - btnCancelRO.Enabled = (_savCurROLink != null && (SavROLink != null && chld.roid != SavROLink.ROID.ToUpper())); - btnGoToRO.Enabled = UserInfo.CanEditROs(MyUserInfo, MyDvi); // Writers and Reviewers cannot edit ROs (run the RO Editor) + //B2017-245 Disable SaveRO button for Procedures and Sections + //B2020-049: Save button not enabled on Word docs, only if a procedure was opened first and immediately after the word document + // section is opened (added 'IsInWorDoc') + btnSaveRO.Enabled = (IsInWordDoc || (!IsNotStep && !IsEnhancedStep)) && UserInfo.CanEdit(MyUserInfo, MyDvi) && ((SavROLink == null) || !(chld.roid.Equals(SavROLink.ROID.ToUpper()))); //added security check (UserInfo.CanEdit) + btnCancelRO.Enabled = (_savCurROLink != null && (SavROLink != null && chld.roid != SavROLink.ROID.ToUpper())); + btnGoToRO.Enabled = UserInfo.CanEditROs(MyUserInfo, MyDvi); // Writers and Reviewers cannot edit ROs (run the RO Editor) - switch (chld.type) - { - case 1: // standard (regular) text RO type - tbROValue.Text = chld.value; - btnPreviewRO.Enabled = false; - if (chld.roid.StartsWith("FFFF")) btnGoToRO.Enabled = false; - break; + switch (chld.type) + { + case 1: // standard (regular) text RO type + tbROValue.Text = chld.value; + btnPreviewRO.Enabled = false; + if (chld.roid.StartsWith("FFFF")) btnGoToRO.Enabled = false; + break; - case 2: // Table RO type - case 3: // This is type 3 when part of a multiple return value - tbROValue.Text = "(Table)"; - btnPreviewRO.Enabled = true; - break; + case 2: // Table RO type + case 3: // This is type 3 when part of a multiple return value + tbROValue.Text = "(Table)"; + btnPreviewRO.Enabled = true; + break; - case 4: // X/Y Plot RO type - tbROValue.Text = "(Graph)"; - btnPreviewRO.Enabled = true; - break; + case 4: // X/Y Plot RO type + tbROValue.Text = "(Graph)"; + btnPreviewRO.Enabled = true; + break; - case 8: // Integrated Graphics RO type - tbROValue.Text = "(Image)"; - btnPreviewRO.Enabled = true; - break; - } - } - } - else - { - // B2022-088: [JPR] Find Doc Ro button not working in Word Sections - // B2022-098: [JPR] ROs not being resolved in Word Sections - ResetSearch(); - } - } + case 8: // Integrated Graphics RO type + tbROValue.Text = "(Image)"; + btnPreviewRO.Enabled = true; + break; + } + } + } + else + { + // B2022-088: [JPR] Find Doc Ro button not working in Word Sections + // B2022-098: [JPR] ROs not being resolved in Word Sections + ResetSearch(); + } + } - #endregion + #endregion - #region (Buttons) + #region (Buttons) - private void btnSaveRO_Click(object sender, EventArgs e) - { - SaveRO(); - } + private void btnSaveRO_Click(object sender, EventArgs e) + { + SaveRO(); + } - private void btnCancelRO_Click(object sender, EventArgs e) - { - _curROLink = _savCurROLink; - btnCancelRO.Enabled = false; + private void btnCancelRO_Click(object sender, EventArgs e) + { + _curROLink = _savCurROLink; + btnCancelRO.Enabled = false; - ExpandNode(_curROLink.ROID); - } + ExpandNode(_curROLink.ROID); + } - private void btnPreviewRO_Click(object sender, EventArgs e) - { - if (selectedChld.type == 8) // integrated graphic - { - string fname = selectedChld.value.Substring(0, selectedChld.value.IndexOf('\n')); - int thedot = fname.LastIndexOf('.'); - ROImageInfo tmp = null; + private void btnPreviewRO_Click(object sender, EventArgs e) + { + if (selectedChld.type == 8) // integrated graphic + { + string fname = selectedChld.value.Substring(0, selectedChld.value.IndexOf('\n')); + int thedot = fname.LastIndexOf('.'); + ROImageInfo tmp = null; - if (thedot == -1 || (thedot != (fname.Length - 4))) - { - tmp = ROImageInfo.GetByROFstID_FileName(MyROFST.ROFstID, fname); - fname += string.Format(".{0}", MyROFST.MyRODb.RODbConfig.GetDefaultGraphicExtension()); - } + if (thedot == -1 || (thedot != (fname.Length - 4))) + { + tmp = ROImageInfo.GetByROFstID_FileName(MyROFST.ROFstID, fname); + fname += string.Format(".{0}", MyROFST.MyRODb.RODbConfig.GetDefaultGraphicExtension()); + } - if (tmp == null) tmp = ROImageInfo.GetByROFstID_FileName(MyROFST.ROFstID, fname); - if (tmp == null) tmp = MyROFST.GetROImageByFilename(fname, null); + if (tmp == null) tmp = ROImageInfo.GetByROFstID_FileName(MyROFST.ROFstID, fname); + if (tmp == null) tmp = MyROFST.GetROImageByFilename(fname, null); - if (tmp != null) - { - ROImageConfig rc = new ROImageConfig(tmp); - int size = Convert.ToInt32(rc.Image_Size); - PreviewROImage pvROImg = new PreviewROImage(ROImageInfo.Decompress(tmp.Content, size), selectedChld.title); - pvROImg.ShowDialog(); - } - else - { - FlexibleMessageBox.Show(string.Format("Cannot Find Image Data: {0}, {1}", MyROFST.ROFstID, fname)); - } - } - else if (selectedChld.type == 2) // table - { - PreviewMultiLineRO pmlROTable = new PreviewMultiLineRO(selectedChld.value, selectedChld.title); - pmlROTable.ShowDialog(); - } - else if (selectedChld.type == 4) // x/y plot - { - frmXYPlot plot = new frmXYPlot(selectedChld.appid + " - " + selectedChld.title, selectedChld.value); - plot.Show(); - } - } + if (tmp != null) + { + ROImageConfig rc = new ROImageConfig(tmp); + int size = Convert.ToInt32(rc.Image_Size); + PreviewROImage pvROImg = new PreviewROImage(ROImageInfo.Decompress(tmp.Content, size), selectedChld.title); + pvROImg.ShowDialog(); + } + else + { + FlexibleMessageBox.Show(string.Format("Cannot Find Image Data: {0}, {1}", MyROFST.ROFstID, fname)); + } + } + else if (selectedChld.type == 2) // table + { + PreviewMultiLineRO pmlROTable = new PreviewMultiLineRO(selectedChld.value, selectedChld.title); + pmlROTable.ShowDialog(); + } + else if (selectedChld.type == 4) // x/y plot + { + frmXYPlot plot = new frmXYPlot(selectedChld.appid + " - " + selectedChld.title, selectedChld.value); + plot.Show(); + } + } - private void btnGoToRO_Click(object sender, EventArgs e) - { - if (tvROFST.SelectedNode == null) return; - RunRoEditor(); - } + private void btnGoToRO_Click(object sender, EventArgs e) + { + if (tvROFST.SelectedNode == null) return; + RunRoEditor(); + } - private void btnFindDocRO_Click(object sender, EventArgs e) - { - // C2016-044: support click of the 'Find Doc RO' button: - DisplayTabItem dti = (_tabControl == null) ? null : _tabControl.SelectedDisplayTabItem; + private void btnFindDocRO_Click(object sender, EventArgs e) + { + // C2016-044: support click of the 'Find Doc RO' button: + DisplayTabItem dti = (_tabControl == null) ? null : _tabControl.SelectedDisplayTabItem; - if (dti != null && dti.MyDSOTabPanel != null) - { - // the currently selected tab control is a word document - see if it has an - // active selection. If not, tell the user that text needs to be selected before the ro can be found. - string mytext = dti.MyDSOTabPanel.GetSelectedString(); + if (dti != null && dti.MyDSOTabPanel != null) + { + // the currently selected tab control is a word document - see if it has an + // active selection. If not, tell the user that text needs to be selected before the ro can be found. + string mytext = dti.MyDSOTabPanel.GetSelectedString(); - if (string.IsNullOrEmpty(mytext)) - { - FlexibleMessageBox.Show(this, "Text must be selected in the document in order for an RO find to be performed.", "Select Text", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } + if (string.IsNullOrEmpty(mytext)) + { + FlexibleMessageBox.Show(this, "Text must be selected in the document in order for an RO find to be performed.", "Select Text", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } - ProcessSearch(mytext, (int)ROFSTLookup.SearchTypes.StartsWith); - } - } + ProcessSearch(mytext, (int)ROFSTLookup.SearchTypes.StartsWith); + } + } - #endregion + #endregion - #region (Labels) + #region (Labels) - private void lbROId_DoubleClick(object sender, EventArgs e) - { - if (tvROFST.SelectedNode == null) - return; + private void lbROId_DoubleClick(object sender, EventArgs e) + { + if (tvROFST.SelectedNode == null) + return; - // do not allow writers and reviews to run the RO Editor - if (!UserInfo.CanEditROs(MyUserInfo, MyDvi)) - return; + // do not allow writers and reviews to run the RO Editor + if (!UserInfo.CanEditROs(MyUserInfo, MyDvi)) + return; - if (VlnSettings.ReleaseMode.Equals("DEMO")) - { - FlexibleMessageBox.Show("Referenced Object Editor not available in the Demo version.", "PROMS Demo Version"); - return; - } + if (VlnSettings.ReleaseMode.Equals("DEMO")) + { + FlexibleMessageBox.Show("Referenced Object Editor not available in the Demo version.", "PROMS Demo Version"); + return; + } - string roapp = Volian.Base.Library.ExeInfo.GetROEditorPath(); // get the path to the RO Editor Executable - object obj = tvROFST.SelectedNode.Tag; + string roapp = Volian.Base.Library.ExeInfo.GetROEditorPath(); // get the path to the RO Editor Executable + object obj = tvROFST.SelectedNode.Tag; - if (obj is ROFSTLookup.rochild) - { - ROFSTLookup.rochild roch = (ROFSTLookup.rochild)obj; + if (obj is ROFSTLookup.rochild) + { + ROFSTLookup.rochild roch = (ROFSTLookup.rochild)obj; - _selectedRoidBeforeRoEditor = roch.roid; + _selectedRoidBeforeRoEditor = roch.roid; string args = "\"" + MyROFST.MyRODb.FolderPath + "\" " + roch.roid.Substring(0,12).ToLower(); - // C2017-003: ro data in sql server, check for sql connection string - if (MyROFST.MyRODb.DBConnectionString != "cstring") args = args + " \"" + MyROFST.MyRODb.DBConnectionString + "\""; + // C2017-003: ro data in sql server, check for sql connection string + if (MyROFST.MyRODb.DBConnectionString != "cstring") args = args + " \"" + MyROFST.MyRODb.DBConnectionString + "\""; - // C2021-026 pass in Parent/Child information (list of the children) - // B2022-019 look at all DocVersions to find ParentChild information - // to ensure we pass in Parent/Child even when not coming from a Parent/Child procedure set - // B2022-073 Break out of the foreach when we find a set with parent/child information + // C2021-026 pass in Parent/Child information (list of the children) + // B2022-019 look at all DocVersions to find ParentChild information + // to ensure we pass in Parent/Child even when not coming from a Parent/Child procedure set + // B2022-073 Break out of the foreach when we find a set with parent/child information - DocVersionInfoList dvil = DocVersionInfoList.Get(); + DocVersionInfoList dvil = DocVersionInfoList.Get(); - foreach (DocVersionInfo dvi in dvil) - { - DocVersionConfig dvc = dvi.DocVersionConfig; - if (dvc != null && dvc.Unit_Name != "" && dvc.Unit_Count > 1) // B2021-089 only pass in applicability info if defined for more than one unit - { - args += " \"PC=" + dvc.Unit_Name + "\""; - break; - } - } + foreach (DocVersionInfo dvi in dvil) + { + DocVersionConfig dvc = dvi.DocVersionConfig; + if (dvc != null && dvc.Unit_Name != "" && dvc.Unit_Count > 1) // B2021-089 only pass in applicability info if defined for more than one unit + { + args += " \"PC=" + dvc.Unit_Name + "\""; + break; + } + } - System.Diagnostics.Process.Start(roapp, args); - } - } + System.Diagnostics.Process.Start(roapp, args); + } + } private void lbFound_SelectedValueChanged(object sender, EventArgs e) { @@ -619,52 +623,64 @@ namespace Volian.Controls.Library //C2026-008 Re-Architect RO.FST to include RO Modification date/time // changed to return true if the RO FST got updated public bool LoadTree(bool forceReload = false) - { - bool updatedROs = false; + { + bool updatedROs = false; - if (MyROFST == null) - { - tvROFST.Nodes.Clear(); - lbFound.Visible = false; - return updatedROs; - } + if (MyROFST == null) + { + tvROFST.Nodes.Clear(); + lbFound.Visible = false; + return updatedROs; + } - if (changedDocVersion || forceReload || RoTreeNeedsReloaded || tvROFST.Nodes == null || tvROFST.Nodes.Count <= 0) - { + if (changedDocVersion || forceReload || RoTreeNeedsReloaded || tvROFST.Nodes == null || tvROFST.Nodes.Count <= 0) + { //C2026-008 Re-Architect RO.FST to include RO Modification date/time - //check if newer data - if there is, check if user wants to update data + //check if newer data - if there is, check if user wants to update data int fstid = MyROFSTLookup.GetNewerFSTID(); - int origfstid = MyROFSTLookup.RofstID; + int origfstid = MyROFSTLookup.RofstID; if (_docVersionInfo != null && fstid != -1 && fstid != MyROFSTLookup.RofstID) - { + { string message = string.Empty; if (_progressBar?.Text != "Cannot check-out Working Draft" && !MySessionInfo.CanCheckOutItem(_docVersionInfo.VersionID, CheckOutType.DocVersion, ref message)) { FlexibleMessageBox.Show(this, message, "Working Draft Has Items Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning); FinalProgressBarMessage = "Cannot check-out Working Draft"; } - else if (!MySessionInfo.CanCheckOutItem(_docVersionInfo.VersionID, CheckOutType.DocVersion, ref message)) - { - //do nothing - is still checked out - } - else if (changedDocVersion && MessageBox.Show($"There exists a newer ROFST for this RO database that was loaded for other sets.\r\n\r\nDo you want to update this set's ROs to be consistent/use the latest loaded ROFST?", "Load ROs", MessageBoxButtons.YesNo) == DialogResult.Yes) - { + else if (!MySessionInfo.CanCheckOutItem(_docVersionInfo.VersionID, CheckOutType.DocVersion, ref message)) + { + //do nothing - is still checked out + } + else if (changedDocVersion && !askedAboutchangedDocVersion) + { + Task.Run(() => + { + if (MessageBox.Show($"There exists a newer ROFST for this RO database that was loaded for other sets.\r\n\r\nDo you want to update this set's ROs to be consistent/use the latest loaded ROFST?", "Load ROs", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + InitialProgressBarMessage = "Updating ROs"; - InitialProgressBarMessage = "Updating ROs"; + ROFstInfo roFstInfo = ROFstInfo.Get(fstid); + roFstInfo.ROTableUpdate += new ROFstInfoROTableUpdateEvent(roFstInfo_ROTableUpdate); + ROFstInfo.RefreshROFstAtItemLevel(_docVersionInfo, DoProgressBarRefresh, null, roFstInfo, origfstid, fstid); + roFstInfo.ROTableUpdate -= new ROFstInfoROTableUpdateEvent(roFstInfo_ROTableUpdate); - ROFstInfo roFstInfo = ROFstInfo.Get(fstid); - roFstInfo.ROTableUpdate += new ROFstInfoROTableUpdateEvent(roFstInfo_ROTableUpdate); - ROFstInfo.RefreshROFstAtItemLevel(_docVersionInfo, DoProgressBarRefresh, null, roFstInfo, origfstid, fstid); - roFstInfo.ROTableUpdate -= new ROFstInfoROTableUpdateEvent(roFstInfo_ROTableUpdate); + Application.DoEvents(); - Application.DoEvents(); + FinalProgressBarMessage = "ROs values updated"; + MyROFST = roFstInfo; - FinalProgressBarMessage = "ROs values updated"; - MyROFST = roFstInfo; + updatedROs = true; - updatedROs = true; - } + askedAboutchangedDocVersion = false; + } + else + { + askedAboutchangedDocVersion = true; + } + }); + + } } //B2025-008 @@ -674,15 +690,15 @@ namespace Volian.Controls.Library //so can go to it after the refresh string tmpROID = CurROLink?.ROID; - ROFSTLookup.rodbi[] dbs = MyROFSTLookup?.GetRODatabaseList(true); + ROFSTLookup.rodbi[] dbs = MyROFSTLookup?.GetRODatabaseList(true); - // B2022-123: RO Tab Treeview not showing correct RO values when switching between procedures. - // Added optional parameter "forceReload" and cleared out any existing nodes before reloading the tree - // the clear nodes code below has to be after the GetRODatabaseList database call because of races conditions in the code - tvROFST.Nodes.Clear(); - ResetSearch(); //B2023-050 need to reset the SaveRO, and any RO info that was selected last time the tree was loaded - if (dbs != null) - { + // B2022-123: RO Tab Treeview not showing correct RO values when switching between procedures. + // Added optional parameter "forceReload" and cleared out any existing nodes before reloading the tree + // the clear nodes code below has to be after the GetRODatabaseList database call because of races conditions in the code + tvROFST.Nodes.Clear(); + ResetSearch(); //B2023-050 need to reset the SaveRO, and any RO info that was selected last time the tree was loaded + if (dbs != null) + { for (int i = 0; i < dbs.Length; i++) { ROFSTLookup.rodbi db = dbs[i]; @@ -695,580 +711,580 @@ namespace Volian.Controls.Library } } - _currRofstID = (IsRofstValid) ? (int?)_myROFST.ROFstID : null; - _currDocVersionID = null; + _currRofstID = (IsRofstValid) ? (int?)_myROFST.ROFstID : null; + _currDocVersionID = null; if(_docVersionInfo != null) _currDocVersionID = (int?)_docVersionInfo.VersionID; - if (tmpROID != null) ExpandNode(ROFSTLookup.FormatRoidKey(tmpROID, true)); + if (tmpROID != null) ExpandNode(ROFSTLookup.FormatRoidKey(tmpROID, true)); - //doc version would have updated (if needed) so reset flag - if (_progressBar?.Text != "Cannot check-out Working Draft") + //doc version would have updated (if needed) so reset flag + if (_progressBar?.Text != "Cannot check-out Working Draft") { changedDocVersion = false; } } - var unitInfoNode = tvROFST.Nodes.Cast().Where(x => x.Text == "Unit Information").FirstOrDefault(); + var unitInfoNode = tvROFST.Nodes.Cast().Where(x => x.Text == "Unit Information").FirstOrDefault(); - if ((ROTypeFilter == E_ROValueType.Text || ROTypeFilter == E_ROValueType.All) && this.MyDvi != null && this.MyDvi.MultiUnitCount > 1) - { - // Add Unit Information Database if it doesn't exist - if (unitInfoNode == null && MyROFSTLookup != null) - { - TreeNode tnn = tvROFST.Nodes.Add("Unit Information"); - TreeNode cn = null; - - ROFSTLookup.rochild roc = MyROFSTLookup.GetRoChild("FFFF00000001"); - cn = tnn.Nodes.Add(roc.title); - cn.Tag = roc; + if ((ROTypeFilter == E_ROValueType.Text || ROTypeFilter == E_ROValueType.All) && this.MyDvi != null && this.MyDvi.MultiUnitCount > 1) + { + // Add Unit Information Database if it doesn't exist + if (unitInfoNode == null && MyROFSTLookup != null) + { + TreeNode tnn = tvROFST.Nodes.Add("Unit Information"); + TreeNode cn = null; - roc = MyROFSTLookup.GetRoChild("FFFF00000002"); - cn = tnn.Nodes.Add(roc.title); - cn.Tag = roc; + ROFSTLookup.rochild roc = MyROFSTLookup.GetRoChild("FFFF00000001"); + cn = tnn.Nodes.Add(roc.title); + cn.Tag = roc; - roc = MyROFSTLookup.GetRoChild("FFFF00000003"); - cn = tnn.Nodes.Add(roc.title); - cn.Tag = roc; + roc = MyROFSTLookup.GetRoChild("FFFF00000002"); + cn = tnn.Nodes.Add(roc.title); + cn.Tag = roc; - roc = MyROFSTLookup.GetRoChild("FFFF00000004"); - cn = tnn.Nodes.Add(roc.title); - cn.Tag = roc; + roc = MyROFSTLookup.GetRoChild("FFFF00000003"); + cn = tnn.Nodes.Add(roc.title); + cn.Tag = roc; - roc = MyROFSTLookup.GetRoChild("FFFF00000005"); - cn = tnn.Nodes.Add(roc.title); - cn.Tag = roc; + roc = MyROFSTLookup.GetRoChild("FFFF00000004"); + cn = tnn.Nodes.Add(roc.title); + cn.Tag = roc; - roc = MyROFSTLookup.GetRoChild("FFFF00000006"); - cn = tnn.Nodes.Add(roc.title); - cn.Tag = roc; + roc = MyROFSTLookup.GetRoChild("FFFF00000005"); + cn = tnn.Nodes.Add(roc.title); + cn.Tag = roc; - roc = MyROFSTLookup.GetRoChild("FFFF00000007"); - cn = tnn.Nodes.Add(roc.title); - cn.Tag = roc; + roc = MyROFSTLookup.GetRoChild("FFFF00000006"); + cn = tnn.Nodes.Add(roc.title); + cn.Tag = roc; - roc = MyROFSTLookup.GetRoChild("FFFF00000008"); - cn = tnn.Nodes.Add(roc.title); - cn.Tag = roc; - } - } - else if (unitInfoNode != null) // Add Unit Information Database if it doesn't exist [Not Multi-Unit DocVersion] - { - tvROFST.Nodes.Remove(unitInfoNode); - } + roc = MyROFSTLookup.GetRoChild("FFFF00000007"); + cn = tnn.Nodes.Add(roc.title); + cn.Tag = roc; - _curROTypeFilter = _roTypeFilter; + roc = MyROFSTLookup.GetRoChild("FFFF00000008"); + cn = tnn.Nodes.Add(roc.title); + cn.Tag = roc; + } + } + else if (unitInfoNode != null) // Add Unit Information Database if it doesn't exist [Not Multi-Unit DocVersion] + { + tvROFST.Nodes.Remove(unitInfoNode); + } + + _curROTypeFilter = _roTypeFilter; return updatedROs; } - public void SetFindDocROButton(bool enabled) - { - this.btnFindDocRO.Enabled = enabled; - } - - public static bool GreaterValue(string value1, string value2) - { - Match match1 = _regExGetNumber.Match(value1); - Match match2 = _regExGetNumber.Match(value2); - - if (match1.Success && !match1.Value.Contains("/") && match2.Success && !match2.Value.Contains("/")) // Compare the numeric value? - { - double dbl1; - double dbl2; - - //B2017-232 changed from Parse to TryParse. AEP had figure title that had a number containing two periods which caused Parse to error? - if (double.TryParse(match1.ToString(), out dbl1) && double.TryParse(match2.ToString(), out dbl2)) - { - if (dbl1 != dbl2) //B2021-144 if the numerical is identical default to the string comparison? - return dbl1 > dbl2; - } - } - - return string.Compare(value1, value2, true) > 0; - } - - #endregion - - #region Private Methods - - private void LoadChildren(TreeNode tn) - { - //Check if node has already been loaded - if (tn.FirstNode != null && tn.FirstNode.Text != DummyNodeText) return; - if (tn.FirstNode != null && tn.FirstNode.Text == DummyNodeText) tn.FirstNode.Remove(); - - //object tag = tn.Tag; - ROFSTLookup.rochild[] children = null; - - if (tn.Tag is ROFSTLookup.rodbi) - { - ROFSTLookup.rodbi db = (ROFSTLookup.rodbi)tn.Tag; - MyROFSTLookup.LoadChildren(ref db); - children = db.children; - } - else if (tn.Tag is ROFSTLookup.rochild) - { - ROFSTLookup.rochild ch = (ROFSTLookup.rochild)tn.Tag; - MyROFSTLookup.LoadChildren(ref ch); - children = ch.children; - } - - - // if children, add dummy node - if (children != null && children.Length > 0) - { - for (int i = 0; i < children.Length; i++) - { - TreeNode tmp = null; - ROFSTLookup.rochild roc = children[i]; - - // if this is a group, i.e. type 0, add a dummy node - if (roc.type == 0 && !MyROFSTLookup.HasChildren(ref roc)) - { - continue; // Ignore: Junk Scenario - } - else if (ROTypeFilter != E_ROValueType.All && (roc.type & (uint)ROTypeFilter) == 0) - { - continue; // Ignore: Filter Doesn't Match - } - else if (!string.IsNullOrEmpty(roc.appid)) - { - MyROFSTLookup.LoadChildren(ref roc); - - if (roc.children.Length == 1 && roc.children.First().roid.Length == 16) - { - roc.appid = roc.children.First().appid; - roc.roid = roc.children.First().roid; - roc.value = roc.children.First().value; - - roc.children = new List().ToArray(); - } - } - - if (roc.value == null) - { - tmp = new TreeNode(roc.title); - tmp.Tag = roc; - - int index = FindIndex(tn.Nodes, tmp.Text); - tn.Nodes.Insert(index, tmp); - - TreeNode sub = new TreeNode(DummyNodeText); - tmp.Nodes.Add(sub); - } - else - { - - tmp = new TreeNode(roc.title); - tmp.Tag = roc; - - if (tmp.Text.IndexOf("\\u") > -1) // RO Editor add symbols C2022 - 003 - { - tmp.Text = Regex.Replace(tmp.Text, @"\\u([0-9]{1,4})\?", m => Convert.ToChar(int.Parse(m.Groups[1].Value)).ToString()); - } - - if (roc.roid.Length == 16) - { - tn.Nodes.Add(tmp); - } - else - { - int index = FindIndex(tn.Nodes, tmp.Text); - tn.Nodes.Insert(index, tmp); - } - } - } - } - } - - private void AddDummyGroup(ROFSTLookup.rodbi rodbi, TreeNode tn) - { - if (IsRofstValid && MyROFSTLookup.HasChildren(ref rodbi)) - { - TreeNode tmp = new TreeNode(DummyNodeText); - tn.Nodes.Add(tmp); - } - } - - private void ExpandNode(string roid) - { - // Clean-up Roid if necessary - roid = ROFSTLookup.FormatRoidKey(roid); - - bool multValSel = (roid.Length == 16) ? true : false; - string db = roid.Substring(0, 4); - int dbiID = MyROFSTLookup.GetRODatabaseTitleIndex(roid); - - ROFSTLookup.rochild rochld = MyROFSTLookup.GetRoChild(roid.Substring(0, 12).ToUpper()); - - // use this to walk up tree until database - this is used to expand tree. - List path = new List(); - int myid = rochld.ID; - - while (myid >= 0) - { - path.Insert(0, myid); - myid = rochld.ParentID; - string pROID = string.Format("{0:X04}{1:X08}", db, myid); - rochld = MyROFSTLookup.GetRoChild(pROID); - - if (rochld.ID == -1) myid = -1; - } - - TreeNode tnExpand = null; - - - //Find Database Node First - TreeNode dbNode = null; - - if (roid.StartsWith("FFFF")) - dbNode = tvROFST.Nodes.Cast().Where(x => (x.Tag.Equals(null)) && (x.Text.Equals("Unit Information"))).FirstOrDefault(); - else - dbNode = tvROFST.Nodes.Cast().Where(x => (x.Tag is ROFSTLookup.rodbi) && ((ROFSTLookup.rodbi)x.Tag).dbiID == dbiID).FirstOrDefault(); - - if (dbNode != null) - { - LoadChildren(dbNode); - tnExpand = dbNode; - } - - if (tnExpand != null) - { - // use the path id list to load/find the treeview's nodes. - foreach (int citm in path) - { - LoadChildren(tnExpand); - tnExpand.Expand(); - - TreeNode chldNode = tnExpand.Nodes.Cast().Where(x => (x.Tag is ROFSTLookup.rochild) && ((ROFSTLookup.rochild)x.Tag).ID == citm).FirstOrDefault(); - if (chldNode != null) - { - tnExpand = chldNode; - } - } - } - - if (tnExpand != null) - { - // If a multiple return value, try to select the proper node - if (multValSel) - { - LoadChildren(tnExpand); - tnExpand.Expand(); - - TreeNode chldNode = tnExpand.Nodes.Cast().Where(x => ((ROFSTLookup.rochild)x.Tag).roid.ToUpper() == roid.ToUpper()).FirstOrDefault(); - if (chldNode != null) - { - tnExpand = chldNode; - } - } - } - - tvROFST.SelectedNode = tnExpand; - } - - private int FindIndex(TreeNodeCollection nodes, string value) - { - int index = 0; - - foreach (TreeNode node in nodes) - { - if (GreaterValue(node.Text, value)) return index; - index++; - } - - return index; - } - - private void SaveRO() - { - //Check if an RO Node is selected from the TreeView - if (string.IsNullOrEmpty(tbROValue.Text)) - { - FlexibleMessageBox.Show("Must select an RO Value from the tree."); - return; - } - - - Object obj = tvROFST.SelectedNode.Tag; - - if (obj is ROFSTLookup.rochild) - { - ROFSTLookup.rochild roc = (ROFSTLookup.rochild)obj; - DisplayTabItem dti = TabControl.SelectedDisplayTabItem; //.OpenItem(_ItemInfo); // open the corresponding procedure text - - if (dti.MyDSOTabPanel != null) // A Word Document tab is the active tab - { - string accPageID = string.Format("<{0}>", roc.appid.ToUpper()); - - // Insert the RO text at the current cursor position in the word document - // NOTE: assuming any type of RO can be put in an Accessory (MSWord) Document - if (dti.MyDSOTabPanel != null) - { - dti.MyDSOTabPanel.InsertText(accPageID); - } - } - else if (MyRTB != null) // a Procedure Steps section tab is active - { - if (CheckROSelection(roc)) // check for RO type is valid for this type of step/substep - { - // Pad to 16 to store in the RoUsage table. - string padroid = ROFSTLookup.FormatRoidKey(roc.roid, true); - string linktxt = string.Format(@"#Link:ReferencedObject: {0} {1}", padroid, MyROFST.RODbID); - - // Resolve symbols and scientific notation in the RO return value - string valtxt = MyROFSTLookup.GetTranslatedRoValue(padroid, MyRTB.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta, MyRTB.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.UseTildaPoundCharsForSuperSubScriptInROValues, false, MyRTB.MyItemInfo); - - MyRTB.OnRoInsert(this, new StepRTBRoEventArgs(valtxt, selectedChld.value, linktxt, padroid, MyROFST.RODbID)); - - } - } - - btnGoToRO.Enabled = false; - btnSaveRO.Enabled = false; - btnCancelRO.Enabled = false; - btnPreviewRO.Enabled = false; - - CurROLink = null; - _savCurROLink = null; - } - } - - private bool CheckROSelection(ROFSTLookup.rochild selectedRO) - { - bool goodToGo = true; - bool replacingRO = (_savCurROLink != null); - - string insrpl = (replacingRO) ? "Cannot Replace" : "Cannot Insert"; - string errormsg = string.Empty; - - switch (selectedRO.type) - { - case 1: // regular text RO - if (MyRTB.MyItemInfo.IsFigure) - { - errormsg = (replacingRO) ? "a Figure with a non-figure." : "a text RO in a Figure type."; - goodToGo = false; - } - break; - - case 2: // table RO - if (MyRTB.MyItemInfo.IsFigure) - { - errormsg = (replacingRO) ? "a Figure with a non-figure." : "a table into a Figure type."; - goodToGo = false; - } - else if (!MyRTB.MyItemInfo.IsTable) - { - errormsg = (replacingRO) ? "a non-table RO with a Table RO." : "a table into a non-table type."; - //TODO: Prompt user to insert a new Table substep type and place this RO into it - goodToGo = false; - } - break; - - case 4: // X/Y Plot RO type - if (!MyRTB.MyItemInfo.IsAccPages) - { - errormsg = (replacingRO) ? "a non-X/Y Plot RO with an X/Y Plot RO." : "an X/Y Plot RO in an non-Accessory Page type."; - //TODO: Prompt user to insert a new substep type that handles x/y Plots and place this RO into it - goodToGo = false; - } - break; - - case 8: // figure (intergrated graphics) - if (!MyRTB.MyItemInfo.IsFigure && !MyRTB.MyItemInfo.IsAccPages) - { - errormsg = (replacingRO) ? "a graphics RO with a non-graphcis RO." : "a Graphics RO in an non-Figure or a non-Accessory Page type."; - //TODO: Prompt user to insert a new substep type that handles x/y Plots and place this RO into it - goodToGo = false; - - - - } - break; - } - - if (!goodToGo) - { - FlexibleMessageBox.Show(string.Format("{0} {1}", insrpl, errormsg), (replacingRO) ? "Invalid RO Replacement" : "Invalid RO Insert"); - } - - return goodToGo; - } - - private void RunRoEditor() - { - if (VlnSettings.ReleaseMode.Equals("DEMO")) - { - FlexibleMessageBox.Show("Referenced Object Editor not available in the Demo version.", "PROMS Demo Version"); - return; - } - - - string roapp = Volian.Base.Library.ExeInfo.GetROEditorPath(); // get the path to the RO Editor Executable - Object obj = tvROFST.SelectedNode.Tag; - - if (obj is ROFSTLookup.rochild) - { - ROFSTLookup.rochild roc = (ROFSTLookup.rochild)obj; - _selectedRoidBeforeRoEditor = roc.roid; - - string args = "\"" + _myROFST.MyRODb.FolderPath + "\" " + roc.roid.ToLower(); - - if (!Directory.Exists(_myROFST.MyRODb.FolderPath)) - { - FlexibleMessageBox.Show(string.Format("RO Database directory does not exist: {0}", _myROFST.MyRODb.FolderPath)); - return; - } - - // C2017-003: ro data in sql server, check for sql connection string - if (_myROFST.MyRODb.DBConnectionString != "cstring") args = args + " \"" + _myROFST.MyRODb.DBConnectionString + "\""; - - // C2021-026 pass in Parent/Child information (list of the children) - // B2022-019 look at all DocVersions to find ParentChild information - // to ensure we pass in Parent/Child even when not coming from a Parent/Child procedure set - // B2022-073 Break out of the foreach when we find a set with parent/child information - DocVersionInfoList dvil = DocVersionInfoList.Get(); - - foreach (DocVersionInfo dvi in dvil) - { - DocVersionConfig jdvc = dvi.DocVersionConfig; - - if (jdvc != null && jdvc.Unit_Name != "" && jdvc.Unit_Count > 1) // B2021-089 only pass in applicability info if defined for more than one unit - { - args += " \"PC=" + jdvc.Unit_Name + "\""; - break; - } - } - - System.Diagnostics.Process.Start(roapp, args); - } - } - - private void ProcessSearch(string searchValue, int searchTypeID) - { - // Jake [2022.05.11]: Added try catch to prevent unhandled exception when the timer ticks and - // tries to process a search while the main tab/procedure is closing - try - { - // B2022-124: [JPR] Blank RO Values (All Spaces) printing as "?" - if (!string.IsNullOrEmpty(searchValue)) - { - searchValue = searchValue.Replace('\u2011', '-'); - searchValue = searchValue.Replace(@"\u9586?", @"\\"); - - if (searchValue.Replace(" ", string.Empty).Length > 0) - searchValue = searchValue.Trim(); - } - - if (this.Enabled && !string.IsNullOrEmpty(searchValue) && searchValue.Length >= 2 && !searchValue.Contains("#Link:Transition")) - { - Dictionary dicRoVals = new Dictionary(); - - // B2022-088: [JPR] Find Doc Ro button not working in Word Sections - // B2022-098: [JPR] ROs not being resolved in Word Sections - if (searchValue.StartsWith("<") && searchValue.EndsWith(">")) // RO Link (accPageID) - { - ROFSTLookup.rochild roc = MyROFSTLookup.GetROChildByAccPageID(searchValue); - - // If RO is valid then select node in tree view - if (roc.ID >= 0 && !string.IsNullOrEmpty(roc.value)) - { - ExpandNode(roc.roid); - } - - lbFound.DataSource = null; - lbFound.Visible = false; - - _lastSearchValue = searchValue; - } - else if (searchValue.Contains("#Link:ReferencedObject")) // RO Link (roid) - { - // we where only removing the END if the searchValue ended in "1[END>" - // but sometimes it ended in "2[END>" and cause a null reference error - // - was seen only running via Visual Studio debugger - // I cleaned up the code to remove in ether case so that we get the expected roid value - jsj 11-18-2024 - string substr = searchValue.Substring(searchValue.LastIndexOf(" ")); - if (substr.Contains("[END>")) - searchValue = searchValue.Substring(0, searchValue.Length - substr.Length); - string roid = ROFSTLookup.FormatRoidKey(searchValue.Substring(searchValue.LastIndexOf(" ")), true); - - if (roid != selectedChld.roid) - { - ROFSTLookup.rochild roc = MyROFSTLookup.GetRoChild(roid); - ExpandNode(roc.roid); - } - - lbFound.DataSource = null; - lbFound.Visible = false; - - _lastSearchValue = searchValue; - } - else // if (searchValue != _lastSearchValue) - { - dicRoVals = MyROFSTLookup.Search(searchValue, searchTypeID, false, MaxNumSearchRecords); - - if (dicRoVals.Count > 0) - { - lbFound.SelectedValueChanged -= new EventHandler(lbFound_SelectedValueChanged); - - lbFound.DataSource = new BindingSource(dicRoVals, null); - lbFound.ValueMember = "Key"; // roid - lbFound.DisplayMember = "Value"; // default value - - lbFound.SelectionMode = SelectionMode.One; - lbFound.SelectedIndex = -1; - lbFound.Visible = true; - - lbFound.SelectedValueChanged += new EventHandler(lbFound_SelectedValueChanged); - - if (lbFound.Items != null && lbFound.Items.Count == 1) - lbFound.SelectedIndex = 0; - } - else - { - lbFound.DataSource = null; - lbFound.Visible = false; - } - - _lastSearchValue = searchValue; - } - } - else - { - _lastSearchValue = string.Empty; - lbFound.DataSource = null; - lbFound.Visible = false; - } - - } - catch { } - } - - private void ResetSearch() - { - // Clear the Display/Info for Prev Selected RO Child - tbROValue.Text = null; - lbROId.Text = string.Empty; - - // Disable all buttons by default - btnSaveRO.Enabled = false; - btnCancelRO.Enabled = false; - btnPreviewRO.Enabled = false; + public void SetFindDocROButton(bool enabled) + { + this.btnFindDocRO.Enabled = enabled; + } + + public static bool GreaterValue(string value1, string value2) + { + Match match1 = _regExGetNumber.Match(value1); + Match match2 = _regExGetNumber.Match(value2); + + if (match1.Success && !match1.Value.Contains("/") && match2.Success && !match2.Value.Contains("/")) // Compare the numeric value? + { + double dbl1; + double dbl2; + + //B2017-232 changed from Parse to TryParse. AEP had figure title that had a number containing two periods which caused Parse to error? + if (double.TryParse(match1.ToString(), out dbl1) && double.TryParse(match2.ToString(), out dbl2)) + { + if (dbl1 != dbl2) //B2021-144 if the numerical is identical default to the string comparison? + return dbl1 > dbl2; + } + } + + return string.Compare(value1, value2, true) > 0; + } + + #endregion + + #region Private Methods + + private void LoadChildren(TreeNode tn) + { + //Check if node has already been loaded + if (tn.FirstNode != null && tn.FirstNode.Text != DummyNodeText) return; + if (tn.FirstNode != null && tn.FirstNode.Text == DummyNodeText) tn.FirstNode.Remove(); + + //object tag = tn.Tag; + ROFSTLookup.rochild[] children = null; + + if (tn.Tag is ROFSTLookup.rodbi) + { + ROFSTLookup.rodbi db = (ROFSTLookup.rodbi)tn.Tag; + MyROFSTLookup.LoadChildren(ref db); + children = db.children; + } + else if (tn.Tag is ROFSTLookup.rochild) + { + ROFSTLookup.rochild ch = (ROFSTLookup.rochild)tn.Tag; + MyROFSTLookup.LoadChildren(ref ch); + children = ch.children; + } + + + // if children, add dummy node + if (children != null && children.Length > 0) + { + for (int i = 0; i < children.Length; i++) + { + TreeNode tmp = null; + ROFSTLookup.rochild roc = children[i]; + + // if this is a group, i.e. type 0, add a dummy node + if (roc.type == 0 && !MyROFSTLookup.HasChildren(ref roc)) + { + continue; // Ignore: Junk Scenario + } + else if (ROTypeFilter != E_ROValueType.All && (roc.type & (uint)ROTypeFilter) == 0) + { + continue; // Ignore: Filter Doesn't Match + } + else if (!string.IsNullOrEmpty(roc.appid)) + { + MyROFSTLookup.LoadChildren(ref roc); + + if (roc.children.Length == 1 && roc.children.First().roid.Length == 16) + { + roc.appid = roc.children.First().appid; + roc.roid = roc.children.First().roid; + roc.value = roc.children.First().value; + + roc.children = new List().ToArray(); + } + } + + if (roc.value == null) + { + tmp = new TreeNode(roc.title); + tmp.Tag = roc; + + int index = FindIndex(tn.Nodes, tmp.Text); + tn.Nodes.Insert(index, tmp); + + TreeNode sub = new TreeNode(DummyNodeText); + tmp.Nodes.Add(sub); + } + else + { + + tmp = new TreeNode(roc.title); + tmp.Tag = roc; + + if (tmp.Text.IndexOf("\\u") > -1) // RO Editor add symbols C2022 - 003 + { + tmp.Text = Regex.Replace(tmp.Text, @"\\u([0-9]{1,4})\?", m => Convert.ToChar(int.Parse(m.Groups[1].Value)).ToString()); + } + + if (roc.roid.Length == 16) + { + tn.Nodes.Add(tmp); + } + else + { + int index = FindIndex(tn.Nodes, tmp.Text); + tn.Nodes.Insert(index, tmp); + } + } + } + } + } + + private void AddDummyGroup(ROFSTLookup.rodbi rodbi, TreeNode tn) + { + if (IsRofstValid && MyROFSTLookup.HasChildren(ref rodbi)) + { + TreeNode tmp = new TreeNode(DummyNodeText); + tn.Nodes.Add(tmp); + } + } + + private void ExpandNode(string roid) + { + // Clean-up Roid if necessary + roid = ROFSTLookup.FormatRoidKey(roid); + + bool multValSel = (roid.Length == 16) ? true : false; + string db = roid.Substring(0, 4); + int dbiID = MyROFSTLookup.GetRODatabaseTitleIndex(roid); + + ROFSTLookup.rochild rochld = MyROFSTLookup.GetRoChild(roid.Substring(0, 12).ToUpper()); + + // use this to walk up tree until database - this is used to expand tree. + List path = new List(); + int myid = rochld.ID; + + while (myid >= 0) + { + path.Insert(0, myid); + myid = rochld.ParentID; + string pROID = string.Format("{0:X04}{1:X08}", db, myid); + rochld = MyROFSTLookup.GetRoChild(pROID); + + if (rochld.ID == -1) myid = -1; + } + + TreeNode tnExpand = null; + + + //Find Database Node First + TreeNode dbNode = null; + + if (roid.StartsWith("FFFF")) + dbNode = tvROFST.Nodes.Cast().Where(x => (x.Tag.Equals(null)) && (x.Text.Equals("Unit Information"))).FirstOrDefault(); + else + dbNode = tvROFST.Nodes.Cast().Where(x => (x.Tag is ROFSTLookup.rodbi) && ((ROFSTLookup.rodbi)x.Tag).dbiID == dbiID).FirstOrDefault(); + + if (dbNode != null) + { + LoadChildren(dbNode); + tnExpand = dbNode; + } + + if (tnExpand != null) + { + // use the path id list to load/find the treeview's nodes. + foreach (int citm in path) + { + LoadChildren(tnExpand); + tnExpand.Expand(); + + TreeNode chldNode = tnExpand.Nodes.Cast().Where(x => (x.Tag is ROFSTLookup.rochild) && ((ROFSTLookup.rochild)x.Tag).ID == citm).FirstOrDefault(); + if (chldNode != null) + { + tnExpand = chldNode; + } + } + } + + if (tnExpand != null) + { + // If a multiple return value, try to select the proper node + if (multValSel) + { + LoadChildren(tnExpand); + tnExpand.Expand(); + + TreeNode chldNode = tnExpand.Nodes.Cast().Where(x => ((ROFSTLookup.rochild)x.Tag).roid.ToUpper() == roid.ToUpper()).FirstOrDefault(); + if (chldNode != null) + { + tnExpand = chldNode; + } + } + } + + tvROFST.SelectedNode = tnExpand; + } + + private int FindIndex(TreeNodeCollection nodes, string value) + { + int index = 0; + + foreach (TreeNode node in nodes) + { + if (GreaterValue(node.Text, value)) return index; + index++; + } + + return index; + } + + private void SaveRO() + { + //Check if an RO Node is selected from the TreeView + if (string.IsNullOrEmpty(tbROValue.Text)) + { + FlexibleMessageBox.Show("Must select an RO Value from the tree."); + return; + } + + + Object obj = tvROFST.SelectedNode.Tag; + + if (obj is ROFSTLookup.rochild) + { + ROFSTLookup.rochild roc = (ROFSTLookup.rochild)obj; + DisplayTabItem dti = TabControl.SelectedDisplayTabItem; //.OpenItem(_ItemInfo); // open the corresponding procedure text + + if (dti.MyDSOTabPanel != null) // A Word Document tab is the active tab + { + string accPageID = string.Format("<{0}>", roc.appid.ToUpper()); + + // Insert the RO text at the current cursor position in the word document + // NOTE: assuming any type of RO can be put in an Accessory (MSWord) Document + if (dti.MyDSOTabPanel != null) + { + dti.MyDSOTabPanel.InsertText(accPageID); + } + } + else if (MyRTB != null) // a Procedure Steps section tab is active + { + if (CheckROSelection(roc)) // check for RO type is valid for this type of step/substep + { + // Pad to 16 to store in the RoUsage table. + string padroid = ROFSTLookup.FormatRoidKey(roc.roid, true); + string linktxt = string.Format(@"#Link:ReferencedObject: {0} {1}", padroid, MyROFST.RODbID); + + // Resolve symbols and scientific notation in the RO return value + string valtxt = MyROFSTLookup.GetTranslatedRoValue(padroid, MyRTB.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta, MyRTB.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.UseTildaPoundCharsForSuperSubScriptInROValues, false, MyRTB.MyItemInfo); + + MyRTB.OnRoInsert(this, new StepRTBRoEventArgs(valtxt, selectedChld.value, linktxt, padroid, MyROFST.RODbID)); + + } + } + + btnGoToRO.Enabled = false; + btnSaveRO.Enabled = false; + btnCancelRO.Enabled = false; + btnPreviewRO.Enabled = false; + + CurROLink = null; + _savCurROLink = null; + } + } + + private bool CheckROSelection(ROFSTLookup.rochild selectedRO) + { + bool goodToGo = true; + bool replacingRO = (_savCurROLink != null); + + string insrpl = (replacingRO) ? "Cannot Replace" : "Cannot Insert"; + string errormsg = string.Empty; + + switch (selectedRO.type) + { + case 1: // regular text RO + if (MyRTB.MyItemInfo.IsFigure) + { + errormsg = (replacingRO) ? "a Figure with a non-figure." : "a text RO in a Figure type."; + goodToGo = false; + } + break; + + case 2: // table RO + if (MyRTB.MyItemInfo.IsFigure) + { + errormsg = (replacingRO) ? "a Figure with a non-figure." : "a table into a Figure type."; + goodToGo = false; + } + else if (!MyRTB.MyItemInfo.IsTable) + { + errormsg = (replacingRO) ? "a non-table RO with a Table RO." : "a table into a non-table type."; + //TODO: Prompt user to insert a new Table substep type and place this RO into it + goodToGo = false; + } + break; + + case 4: // X/Y Plot RO type + if (!MyRTB.MyItemInfo.IsAccPages) + { + errormsg = (replacingRO) ? "a non-X/Y Plot RO with an X/Y Plot RO." : "an X/Y Plot RO in an non-Accessory Page type."; + //TODO: Prompt user to insert a new substep type that handles x/y Plots and place this RO into it + goodToGo = false; + } + break; + + case 8: // figure (intergrated graphics) + if (!MyRTB.MyItemInfo.IsFigure && !MyRTB.MyItemInfo.IsAccPages) + { + errormsg = (replacingRO) ? "a graphics RO with a non-graphcis RO." : "a Graphics RO in an non-Figure or a non-Accessory Page type."; + //TODO: Prompt user to insert a new substep type that handles x/y Plots and place this RO into it + goodToGo = false; + + + + } + break; + } + + if (!goodToGo) + { + FlexibleMessageBox.Show(string.Format("{0} {1}", insrpl, errormsg), (replacingRO) ? "Invalid RO Replacement" : "Invalid RO Insert"); + } + + return goodToGo; + } + + private void RunRoEditor() + { + if (VlnSettings.ReleaseMode.Equals("DEMO")) + { + FlexibleMessageBox.Show("Referenced Object Editor not available in the Demo version.", "PROMS Demo Version"); + return; + } + + + string roapp = Volian.Base.Library.ExeInfo.GetROEditorPath(); // get the path to the RO Editor Executable + Object obj = tvROFST.SelectedNode.Tag; + + if (obj is ROFSTLookup.rochild) + { + ROFSTLookup.rochild roc = (ROFSTLookup.rochild)obj; + _selectedRoidBeforeRoEditor = roc.roid; + + string args = "\"" + _myROFST.MyRODb.FolderPath + "\" " + roc.roid.ToLower(); + + if (!Directory.Exists(_myROFST.MyRODb.FolderPath)) + { + FlexibleMessageBox.Show(string.Format("RO Database directory does not exist: {0}", _myROFST.MyRODb.FolderPath)); + return; + } + + // C2017-003: ro data in sql server, check for sql connection string + if (_myROFST.MyRODb.DBConnectionString != "cstring") args = args + " \"" + _myROFST.MyRODb.DBConnectionString + "\""; + + // C2021-026 pass in Parent/Child information (list of the children) + // B2022-019 look at all DocVersions to find ParentChild information + // to ensure we pass in Parent/Child even when not coming from a Parent/Child procedure set + // B2022-073 Break out of the foreach when we find a set with parent/child information + DocVersionInfoList dvil = DocVersionInfoList.Get(); + + foreach (DocVersionInfo dvi in dvil) + { + DocVersionConfig jdvc = dvi.DocVersionConfig; + + if (jdvc != null && jdvc.Unit_Name != "" && jdvc.Unit_Count > 1) // B2021-089 only pass in applicability info if defined for more than one unit + { + args += " \"PC=" + jdvc.Unit_Name + "\""; + break; + } + } + + System.Diagnostics.Process.Start(roapp, args); + } + } + + private void ProcessSearch(string searchValue, int searchTypeID) + { + // Jake [2022.05.11]: Added try catch to prevent unhandled exception when the timer ticks and + // tries to process a search while the main tab/procedure is closing + try + { + // B2022-124: [JPR] Blank RO Values (All Spaces) printing as "?" + if (!string.IsNullOrEmpty(searchValue)) + { + searchValue = searchValue.Replace('\u2011', '-'); + searchValue = searchValue.Replace(@"\u9586?", @"\\"); + + if (searchValue.Replace(" ", string.Empty).Length > 0) + searchValue = searchValue.Trim(); + } + + if (this.Enabled && !string.IsNullOrEmpty(searchValue) && searchValue.Length >= 2 && !searchValue.Contains("#Link:Transition")) + { + Dictionary dicRoVals = new Dictionary(); + + // B2022-088: [JPR] Find Doc Ro button not working in Word Sections + // B2022-098: [JPR] ROs not being resolved in Word Sections + if (searchValue.StartsWith("<") && searchValue.EndsWith(">")) // RO Link (accPageID) + { + ROFSTLookup.rochild roc = MyROFSTLookup.GetROChildByAccPageID(searchValue); + + // If RO is valid then select node in tree view + if (roc.ID >= 0 && !string.IsNullOrEmpty(roc.value)) + { + ExpandNode(roc.roid); + } + + lbFound.DataSource = null; + lbFound.Visible = false; + + _lastSearchValue = searchValue; + } + else if (searchValue.Contains("#Link:ReferencedObject")) // RO Link (roid) + { + // we where only removing the END if the searchValue ended in "1[END>" + // but sometimes it ended in "2[END>" and cause a null reference error + // - was seen only running via Visual Studio debugger + // I cleaned up the code to remove in ether case so that we get the expected roid value - jsj 11-18-2024 + string substr = searchValue.Substring(searchValue.LastIndexOf(" ")); + if (substr.Contains("[END>")) + searchValue = searchValue.Substring(0, searchValue.Length - substr.Length); + string roid = ROFSTLookup.FormatRoidKey(searchValue.Substring(searchValue.LastIndexOf(" ")), true); + + if (roid != selectedChld.roid) + { + ROFSTLookup.rochild roc = MyROFSTLookup.GetRoChild(roid); + ExpandNode(roc.roid); + } + + lbFound.DataSource = null; + lbFound.Visible = false; + + _lastSearchValue = searchValue; + } + else // if (searchValue != _lastSearchValue) + { + dicRoVals = MyROFSTLookup.Search(searchValue, searchTypeID, false, MaxNumSearchRecords); + + if (dicRoVals.Count > 0) + { + lbFound.SelectedValueChanged -= new EventHandler(lbFound_SelectedValueChanged); + + lbFound.DataSource = new BindingSource(dicRoVals, null); + lbFound.ValueMember = "Key"; // roid + lbFound.DisplayMember = "Value"; // default value + + lbFound.SelectionMode = SelectionMode.One; + lbFound.SelectedIndex = -1; + lbFound.Visible = true; + + lbFound.SelectedValueChanged += new EventHandler(lbFound_SelectedValueChanged); + + if (lbFound.Items != null && lbFound.Items.Count == 1) + lbFound.SelectedIndex = 0; + } + else + { + lbFound.DataSource = null; + lbFound.Visible = false; + } + + _lastSearchValue = searchValue; + } + } + else + { + _lastSearchValue = string.Empty; + lbFound.DataSource = null; + lbFound.Visible = false; + } + + } + catch { } + } + + private void ResetSearch() + { + // Clear the Display/Info for Prev Selected RO Child + tbROValue.Text = null; + lbROId.Text = string.Empty; + + // Disable all buttons by default + btnSaveRO.Enabled = false; + btnCancelRO.Enabled = false; + btnPreviewRO.Enabled = false; //B2026-030 GoTo sometimes requires being pressed twice if (MyUserInfo != null && MyDvi != null && selectedChld.value != null) { btnGoToRO.Enabled = UserInfo.CanEditROs(MyUserInfo, MyDvi); // Writers and Reviewers cannot edit ROs (run the RO Editor) } - else - { + else + { btnGoToRO.Enabled = false; } } - #endregion - } + #endregion + } }