1143 lines
32 KiB
C#
1143 lines
32 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
using XYPlots;
|
|
using DevComponents.DotNetBar;
|
|
using System.Text.RegularExpressions;
|
|
using Volian.Base.Library;
|
|
using JR.Utils.GUI.Forms;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
public partial class DisplayRO : UserControl
|
|
{
|
|
#region Log4Net
|
|
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
#endregion
|
|
|
|
#region Fields
|
|
|
|
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;
|
|
|
|
private Timer _searchTimer;
|
|
private string _lastSearchValue = string.Empty;
|
|
|
|
private ProgressBarItem _progressBar;
|
|
private DisplayTabControl _tabControl;
|
|
private StepRTB _myRTB;
|
|
private string _selectedRoidBeforeRoEditor = null;
|
|
|
|
private ROFstInfo _myROFST;
|
|
private ROFSTLookup _myROFSTLookup;
|
|
private DocVersionInfo _docVersionInfo;
|
|
private RoUsageInfo _savCurROLink;
|
|
private E_ROValueType _roTypeFilter = E_ROValueType.All;
|
|
|
|
private ROFstInfo _curROFST = null;
|
|
private ROFSTLookup _curROFSTLookup = null;
|
|
private RoUsageInfo _curROLink;
|
|
private E_ROValueType _curROTypeFilter = E_ROValueType.All;
|
|
|
|
private ROFSTLookup.rochild selectedChld;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public ProgressBarItem ProgressBar
|
|
{
|
|
get { return _progressBar; }
|
|
set { _progressBar = value; }
|
|
}
|
|
|
|
public DisplayTabControl TabControl
|
|
{
|
|
get { return _tabControl; }
|
|
set { _tabControl = value; }
|
|
}
|
|
|
|
public ROFstInfo MyROFST
|
|
{
|
|
get { return _myROFST; }
|
|
set
|
|
{
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
|
|
// define the tree nodes based on this rofst
|
|
_myROFST = value;
|
|
|
|
if (_myROFST != null && _myROFST.ROFstAssociations != null && _myROFST.ROFstAssociationCount > 0)
|
|
{
|
|
_myROFSTLookup = new ROFSTLookup(_myROFST.ROFstID, _myROFST.ROFstAssociations[0].MyDocVersion);
|
|
}
|
|
|
|
//LoadTree();
|
|
}
|
|
}
|
|
|
|
public ROFSTLookup MyROFSTLookup
|
|
{
|
|
get { return _myROFSTLookup; }
|
|
set
|
|
{
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
|
|
_myROFSTLookup = value;
|
|
_docVersionInfo = (_myROFSTLookup != null) ? _myROFSTLookup.MyDocVersionInfo : null;
|
|
//LoadTree();
|
|
}
|
|
}
|
|
|
|
public E_ROValueType ROTypeFilter
|
|
{
|
|
get { return _roTypeFilter; }
|
|
set
|
|
{
|
|
_roTypeFilter = value;
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
|
|
//_roTypeFilter = value;
|
|
// LoadTree();
|
|
}
|
|
}
|
|
|
|
public DocVersionInfo MyDvi
|
|
{
|
|
get { return _docVersionInfo; }
|
|
}
|
|
|
|
public RoUsageInfo CurROLink
|
|
{
|
|
get { return _curROLink; }
|
|
set
|
|
{
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
|
|
if (value != null) // modify - set the controls to the current ro
|
|
{
|
|
if (_curROLink == value) return;
|
|
_curROLink = value;
|
|
_savCurROLink = _curROLink;
|
|
UpdateROTree();
|
|
}
|
|
else // insert - clear out controls
|
|
{
|
|
_curROLink = value;
|
|
tbROValue.Text = null;
|
|
lbROId.Text = "";
|
|
tvROFST.SelectedNode = null;
|
|
btnGoToRO.Enabled = btnSaveRO.Enabled = btnCancelRO.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public StepRTB MyRTB
|
|
{
|
|
get { return _myRTB; }
|
|
set
|
|
{
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
|
|
int origRoDbId = -1;
|
|
|
|
if (_myRTB != null)
|
|
{
|
|
_myRTB.LinkChanged -= new StepRTBLinkEvent(MyRTB_LinkChanged);
|
|
_myRTB.SelectionChanged -= new EventHandler(MyRTB_SelectionChanged);
|
|
|
|
if (_myRTB.MyItemInfo.MyDocVersion.DocVersionAssociationCount > 0)
|
|
{
|
|
origRoDbId = _myRTB.MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst.RODbID;
|
|
}
|
|
}
|
|
|
|
if (value == null) return;
|
|
|
|
_myRTB = value;
|
|
MyRTB.LinkChanged += new StepRTBLinkEvent(MyRTB_LinkChanged);
|
|
MyRTB.SelectionChanged+=new EventHandler(MyRTB_SelectionChanged);
|
|
|
|
if (MyRTB.MyLinkText == null)
|
|
{
|
|
CurROLink = null;
|
|
_savCurROLink = null;
|
|
}
|
|
|
|
// Test to see if this myrtf is using the same rofst as the previous. If
|
|
// not we may have to reset the ro.fst for the tree if the new working
|
|
// draft has a different ro.fst than the original:
|
|
if (_myRTB != null && _myRTB.MyItemInfo.MyDocVersion.DocVersionAssociationCount > 0)
|
|
{
|
|
if (origRoDbId != _myRTB.MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst.RODbID)
|
|
{
|
|
MyROFST = _myRTB.MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst;
|
|
LoadTree(); // B2022-026 RO Memory Reduction code
|
|
}
|
|
}
|
|
else if (_myRTB.MyItemInfo.MyDocVersion.DocVersionAssociationCount <= 0)
|
|
{
|
|
// This docversion doesn't have an rofst associated with it, clear the ro tree.
|
|
MyROFST = null;
|
|
LoadTree(); // B2022-026 RO Memory Reduction code
|
|
}
|
|
}
|
|
}
|
|
|
|
public static UserInfo MyUserInfo
|
|
{
|
|
get { return _myUserInfo; }
|
|
set { _myUserInfo = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public DisplayRO()
|
|
{
|
|
InitializeComponent();
|
|
|
|
panelRoValue.BackColor = Color.Cornsilk;
|
|
panelValue.BackColor = Color.Cornsilk;
|
|
|
|
if (_searchTimer == null)
|
|
{
|
|
_searchTimer = new Timer();
|
|
_searchTimer.Interval = 1000;
|
|
_searchTimer.Tick += new EventHandler(SelectionTimer_Tick);
|
|
_searchTimer.Stop();
|
|
}
|
|
|
|
_progressBar = null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Event Handlers
|
|
|
|
#region (Progress Bar)
|
|
|
|
private void ProgressBar_Initialize(int max, string desc)
|
|
{
|
|
if (_progressBar != null)
|
|
{
|
|
_progressBar.Maximum = max;
|
|
_progressBar.Text = desc;
|
|
_progressBar.TextVisible = true;
|
|
}
|
|
}
|
|
|
|
private void ProgressBar_SetValue(int curval)
|
|
{
|
|
if (_progressBar != null)
|
|
{
|
|
_progressBar.Value = curval;
|
|
}
|
|
}
|
|
|
|
private void ProgressBar_Clear()
|
|
{
|
|
if (_progressBar != null)
|
|
{
|
|
_progressBar.Text = string.Empty;
|
|
_progressBar.Maximum = 0;
|
|
_progressBar.Value = 0;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region (RTB)
|
|
|
|
public void MyRTB_LinkChanged(object sender, StepPanelLinkEventArgs args)
|
|
{
|
|
CurROLink = null;
|
|
if (MyRTB.MyLinkText != null) CurROLink = args.MyLinkText.MyRoUsageInfo;
|
|
}
|
|
|
|
public void MyRTB_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
_timeActivity.Open();
|
|
|
|
_searchTimer.Stop();
|
|
if (!string.IsNullOrEmpty(MyRTB.SelectedText))
|
|
{
|
|
_searchTimer.Start();
|
|
}
|
|
|
|
_timeActivity.Close();
|
|
}
|
|
|
|
private void SelectionTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
// Stop the timer
|
|
_searchTimer.Stop();
|
|
|
|
// 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
|
|
{
|
|
// Process RO Search
|
|
if (MyRTB != null)
|
|
{
|
|
ProcessSearch(MyRTB.SelectedText, (int)ROFSTLookup.SearchType.StartsWith);
|
|
}
|
|
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#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 (MyRTB != null && MyRTB.MyItemInfo != null && MyRTB.MyItemInfo.IsEnhancedStep)
|
|
return;
|
|
|
|
SaveRO();
|
|
}
|
|
|
|
private void tvROFST_BeforeExpand(object sender, TreeViewCancelEventArgs e)
|
|
{
|
|
LoadChildren(e.Node);
|
|
}
|
|
|
|
private void tvROFST_AfterSelect(object sender, TreeViewEventArgs e)
|
|
{
|
|
tbROValue.Text = null;
|
|
lbROId.Text = "";
|
|
btnCancelRO.Enabled = false;
|
|
btnSaveRO.Enabled = false;
|
|
btnPreviewRO.Enabled = false;
|
|
btnGoToRO.Enabled = false;
|
|
|
|
if (e.Node.Tag is ROFSTLookup.rochild)
|
|
{
|
|
ROFSTLookup.rochild chld = (ROFSTLookup.rochild)e.Node.Tag;
|
|
selectedChld = chld;
|
|
|
|
if (chld.value != null)
|
|
{
|
|
RoUsageInfo SavROLink = null;
|
|
if (_savCurROLink != null) SavROLink = _savCurROLink;
|
|
lbROId.Text = chld.appid;
|
|
|
|
// Allow the user to select a different return value.
|
|
//btnSaveRO.Enabled = ((_savCurROLink == null) || !(chld.roid.Substring(0, 12).ToLower().Equals(SavROLink.ROID.Substring(0, 12).ToLower())));
|
|
//btnCancelRO.Enabled = ((_savCurROLink != null) && chld.roid.Substring(0, 12).ToLower() != SavROLink.ROID.Substring(0, 12).ToLower());
|
|
string childroid = chld.roid.ToLower() + "0000";
|
|
childroid = childroid.Substring(0, 16);
|
|
bool isenh = MyRTB != null && MyRTB.MyItemInfo != null && MyRTB.MyItemInfo.IsEnhancedStep;
|
|
|
|
//B2017-245 Disable SAveRO button for Procedures and Sections
|
|
bool isNotStep = MyRTB != null && MyRTB.MyItemInfo != null && (MyRTB.MyItemInfo.IsProcedure || MyRTB.MyItemInfo.IsSection);
|
|
|
|
//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')
|
|
bool isInWordDoc = TabControl.SelectedDisplayTabItem.MyDSOTabPanel != null;
|
|
btnSaveRO.Enabled = (isInWordDoc || (!isNotStep && !isenh)) && UserInfo.CanEdit(MyUserInfo, MyDvi) && ((_savCurROLink == null) || !(childroid.Equals(SavROLink.ROID.ToLower()))); //added security check (UserInfo.CanEdit)
|
|
btnCancelRO.Enabled = ((_savCurROLink != null) && childroid != SavROLink.ROID.ToLower());
|
|
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
|
|
string roval = chld.value.Replace(@"\u160?", " ");
|
|
roval = GetPCDefaultValue(roval); // C2021-026 get the default RO value from P/C RO value information
|
|
tbROValue.Text = roval;
|
|
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 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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region (Buttons)
|
|
|
|
private void btnSaveRO_Click(object sender, EventArgs e)
|
|
{
|
|
SaveRO();
|
|
}
|
|
|
|
private void btnCancelRO_Click(object sender, EventArgs e)
|
|
{
|
|
_curROLink = _savCurROLink;
|
|
btnCancelRO.Enabled = false;
|
|
UpdateROTree();
|
|
}
|
|
|
|
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 (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();
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
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;
|
|
}
|
|
else
|
|
{
|
|
ProcessSearch(mytext, (int)ROFSTLookup.SearchType.StartsWith);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region (Labels)
|
|
|
|
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;
|
|
|
|
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 roch = (ROFSTLookup.rochild)obj;
|
|
|
|
_selectedRoidBeforeRoEditor = roch.roid;
|
|
string args = "\"" + MyROFST.MyRODb.FolderPath + "\" " + roch.roid.ToLower();
|
|
|
|
// 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
|
|
|
|
DocVersionInfoList dvil = DocVersionInfoList.Get();
|
|
|
|
foreach (DocVersionInfo dvi in dvil)
|
|
{
|
|
DocVersionConfig dvc = dvi.DocVersionConfig;
|
|
if (dvc != null && dvc.Unit_Name != "" && dvc.Unit_Name != "0")
|
|
{
|
|
args += " \"PC=" + dvc.Unit_Name + "\"";
|
|
}
|
|
break;
|
|
}
|
|
|
|
System.Diagnostics.Process.Start(roapp, args);
|
|
}
|
|
}
|
|
|
|
private void lbFound_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
if (lbFound.Visible && lbFound.SelectedIndex >= 0 && lbFound.SelectedValue != null)
|
|
{
|
|
ExpandNode(Convert.ToString(lbFound.SelectedValue));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Public Methods
|
|
|
|
public void RefreshRoTree()
|
|
{
|
|
_curROFST = null;
|
|
_curROFSTLookup = null;
|
|
|
|
LoadTree();
|
|
|
|
if (!string.IsNullOrEmpty(_selectedRoidBeforeRoEditor))
|
|
{
|
|
ExpandNode(_selectedRoidBeforeRoEditor);
|
|
_selectedRoidBeforeRoEditor = null;
|
|
}
|
|
}
|
|
|
|
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
|
|
|
|
public void LoadTree()
|
|
{
|
|
if (_myROFST == null)
|
|
{
|
|
tvROFST.Nodes.Clear();
|
|
_curROFST = null;
|
|
_curROFSTLookup = null;
|
|
return;
|
|
}
|
|
|
|
if (MyROFST ==_curROFST && ROTypeFilter == _curROTypeFilter && MyROFSTLookup == _curROFSTLookup)
|
|
return;
|
|
|
|
//_MyLog.WarnFormat("Load Tree \r\n_curROfst = {0}\r\n MyROFST {1}", _curROFST,MyROFST);
|
|
//_MyLog.WarnFormat("{0}", Volian.Base.Library.vlnStackTrace.StackToStringLocal(2, 3));
|
|
|
|
tvROFST.Nodes.Clear();
|
|
|
|
_myROFSTLookup = new ROFSTLookup(MyROFST.ROFstID, MyDvi);
|
|
|
|
_curROFST = _myROFST;
|
|
_curROFSTLookup = _myROFSTLookup;
|
|
_curROTypeFilter = _roTypeFilter;
|
|
|
|
ROFSTLookup.rodbi[] dbs = MyROFSTLookup.GetRODatabaseList(false);
|
|
|
|
for (int i = 0; i < dbs.Length; i++)
|
|
{
|
|
ROFSTLookup.rodbi db = dbs[i];
|
|
|
|
db.children = MyROFSTLookup.GetRoChildrenByID(db.ID, db.dbiID, true);
|
|
|
|
TreeNode tn = new TreeNode(db.dbiTitle);
|
|
tn.Tag = db;
|
|
tvROFST.Nodes.Add(tn);
|
|
|
|
AddDummyGroup(db, tn);
|
|
}
|
|
|
|
if ((ROTypeFilter == E_ROValueType.Text || ROTypeFilter == E_ROValueType.All) && this.MyDvi != null && this.MyDvi.MultiUnitCount > 1)
|
|
{
|
|
TreeNode tnn = tvROFST.Nodes.Add("Unit Information");
|
|
TreeNode cn = tnn.Nodes.Add("Number");
|
|
|
|
cn.Tag = MyROFSTLookup.GetRoChild("FFFF00000001");
|
|
cn = tnn.Nodes.Add("Other Number");
|
|
|
|
cn.Tag = MyROFSTLookup.GetRoChild("FFFF00000002");
|
|
cn = tnn.Nodes.Add("Text");
|
|
|
|
cn.Tag = MyROFSTLookup.GetRoChild("FFFF00000003");
|
|
cn = tnn.Nodes.Add("Other Text");
|
|
|
|
cn.Tag = MyROFSTLookup.GetRoChild("FFFF00000004");
|
|
cn = tnn.Nodes.Add("ID");
|
|
|
|
cn.Tag = MyROFSTLookup.GetRoChild("FFFF00000005");
|
|
cn = tnn.Nodes.Add("Other ID");
|
|
|
|
cn.Tag = MyROFSTLookup.GetRoChild("FFFF00000006");
|
|
cn = tnn.Nodes.Add("Name");
|
|
|
|
cn.Tag = MyROFSTLookup.GetRoChild("FFFF00000007");
|
|
cn = tnn.Nodes.Add("Other Name");
|
|
|
|
cn.Tag = MyROFSTLookup.GetRoChild("FFFF00000008");
|
|
}
|
|
//else
|
|
//{
|
|
// _MyLog.Warn("Unit Designtor not loaded");
|
|
// _MyLog.Warn(Volian.Base.Library.vlnStackTrace.StackToStringLocal(2,3));
|
|
//}
|
|
}
|
|
|
|
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[] chld = null;
|
|
|
|
if (tn.Tag is ROFSTLookup.rodbi)
|
|
{
|
|
ROFSTLookup.rodbi db = (ROFSTLookup.rodbi)tn.Tag;
|
|
chld = db.children;
|
|
}
|
|
else if (tn.Tag is ROFSTLookup.rochild)
|
|
{
|
|
ROFSTLookup.rochild ch = (ROFSTLookup.rochild)tn.Tag;
|
|
|
|
if (!string.IsNullOrEmpty(ch.appid))
|
|
{
|
|
ch = MyROFSTLookup.GetRoChild(ch.roid);
|
|
}
|
|
else if (ch.children == null || ch.children.Length <= 0)
|
|
{
|
|
ch.children = MyROFSTLookup.GetRoChildrenByRoid(ch.roid, true);
|
|
}
|
|
|
|
chld = ch.children;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("error - no type");
|
|
return;
|
|
}
|
|
|
|
// if children, add dummy node
|
|
if (chld != null && chld.Length > 0)
|
|
{
|
|
ProgressBar_Initialize(chld.Length, tn.Text);
|
|
|
|
for (int i = 0; i < chld.Length; i++)
|
|
{
|
|
ProgressBar_SetValue(i);
|
|
TreeNode tmp = null;
|
|
|
|
// if this is a group, i.e. type 0, add a dummy node
|
|
if (chld[i].type == 0 && chld[i].children == null)
|
|
{
|
|
//skip it.
|
|
// TODO: KBR how to handle this?
|
|
//Console.WriteLine("ro junk");
|
|
continue;
|
|
}
|
|
else if (ROTypeFilter != E_ROValueType.All && (chld[i].type & (uint)ROTypeFilter) == 0)
|
|
{
|
|
continue; // ignore if does not match filter
|
|
}
|
|
else if (chld[i].value == null)
|
|
{
|
|
if (!string.IsNullOrEmpty(chld[i].appid))
|
|
{
|
|
chld[i] = MyROFSTLookup.GetRoChild(chld[i].roid);
|
|
}
|
|
else if (chld[i].children == null || chld[i].children.Length <= 0)
|
|
{
|
|
chld[i].children = MyROFSTLookup.GetRoChildrenByRoid(chld[i].roid, true);
|
|
}
|
|
|
|
tmp = new TreeNode(chld[i].title);
|
|
tmp.Tag = chld[i];
|
|
//tn.Nodes.Add(tmp);
|
|
int index = FindIndex(tn.Nodes, tmp.Text);
|
|
tn.Nodes.Insert(index, tmp);
|
|
TreeNode sub = new TreeNode(DummyNodeText);
|
|
tmp.Nodes.Add(sub);
|
|
}
|
|
else
|
|
{
|
|
string ntitle = chld[i].title.Replace(@"\u160?", " ");
|
|
ntitle = GetPCDefaultValue(ntitle); // C2021-026 get the default RO value from P/C RO value information
|
|
tmp = new TreeNode(ntitle);
|
|
tmp.Tag = chld[i];
|
|
|
|
if (chld[i].roid.Length == 16)
|
|
{
|
|
tn.Nodes.Add(tmp);
|
|
}
|
|
else
|
|
{
|
|
int index = FindIndex(tn.Nodes, tmp.Text);
|
|
tn.Nodes.Insert(index, tmp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
ProgressBar_Clear();
|
|
}
|
|
|
|
private void AddDummyGroup(ROFSTLookup.rodbi rodbi, TreeNode tn)
|
|
{
|
|
if (rodbi.children != null && rodbi.children.Length > 0)
|
|
{
|
|
TreeNode tmp = new TreeNode(DummyNodeText);
|
|
tn.Nodes.Add(tmp);
|
|
}
|
|
}
|
|
|
|
private void ExpandNode(string roid)
|
|
{
|
|
string db = roid.Substring(0, 4);
|
|
bool multValSel = false;
|
|
|
|
if (roid.Length == 16)
|
|
multValSel = true;
|
|
|
|
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<int> path = new List<int>();
|
|
int myid = rochld.ID;
|
|
|
|
while (myid > 0)
|
|
{
|
|
path.Insert(0, myid);
|
|
myid = rochld.ParentID;
|
|
string pROID = string.Format("{0}{1:X08}", db, myid);
|
|
rochld = MyROFSTLookup.GetRoChild(pROID);
|
|
|
|
if (rochld.ID == -1) myid = -1;
|
|
}
|
|
|
|
TreeNode tnExpand = null;
|
|
int titm = System.Convert.ToInt32(db, 16); //(db);
|
|
|
|
// find database first
|
|
foreach (TreeNode tn in tvROFST.Nodes)
|
|
{
|
|
if (tn.Tag != null)
|
|
{
|
|
ROFSTLookup.rodbi thisdb = (ROFSTLookup.rodbi)tn.Tag;
|
|
|
|
if (thisdb.dbiID == titm)
|
|
{
|
|
LoadChildren(tn);
|
|
tnExpand = tn;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (tnExpand == null) return; // something went wrong?
|
|
|
|
// use the path id list to load/find the treeview's nodes.
|
|
foreach (int citm in path)
|
|
{
|
|
LoadChildren(tnExpand);
|
|
tnExpand.Expand();
|
|
|
|
foreach (TreeNode tn in tnExpand.Nodes)
|
|
{
|
|
ROFSTLookup.rochild chld = (ROFSTLookup.rochild)tn.Tag;
|
|
if (chld.ID == citm)
|
|
{
|
|
tnExpand = tn;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (tnExpand != null)
|
|
{
|
|
// If a multiple return value, try to select the proper node
|
|
if (multValSel)
|
|
{
|
|
LoadChildren(tnExpand);
|
|
tnExpand.Expand();
|
|
|
|
foreach (TreeNode tn in tnExpand.Nodes)
|
|
{
|
|
if (tn.Tag != null)
|
|
{
|
|
ROFSTLookup.rochild chld = (ROFSTLookup.rochild)tn.Tag;
|
|
|
|
if (chld.roid.ToUpper() == roid.ToUpper())
|
|
{
|
|
tnExpand = tn;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
tvROFST.SelectedNode = tnExpand;
|
|
}
|
|
}
|
|
|
|
private void UpdateROTree()
|
|
{
|
|
ExpandNode(_curROLink.ROID);
|
|
}
|
|
|
|
private string GetPCDefaultValue(string roval)
|
|
{
|
|
// C2021-026 Get the Parent (Default) RO value if the return value include P/C information
|
|
// otherwise return the RO value as is.
|
|
// This is used for the insert RO interface on the Step Properties panel
|
|
string rntval = roval;
|
|
|
|
while (rntval.Contains("<APL DefaultVal=")) // C2021-026 remove Parent/Child values for the menu item text
|
|
{
|
|
int startCVIdx = rntval.IndexOf("<APL DefaultVal=");
|
|
int EndCVidx = rntval.IndexOf(" /APL>", startCVIdx);
|
|
string aplicValues = rntval.Substring(startCVIdx, EndCVidx + 6 - startCVIdx);
|
|
int endDefIdx = rntval.IndexOf(",", startCVIdx);
|
|
|
|
// C2022-001 - handle if there is no child value in the RO FSt
|
|
// B2022-051 - was sometimes leaving "/APL>" when processing return value maded up from multiple RO (editor) fields
|
|
// added check to make where next found comma was within the current <APL ... /APL>
|
|
string defValue = rntval.Substring(startCVIdx + 16, ((endDefIdx > 0 && endDefIdx < EndCVidx) ? endDefIdx : EndCVidx) - (startCVIdx + 16));
|
|
rntval = rntval.Replace(aplicValues, defValue);
|
|
}
|
|
|
|
return rntval;
|
|
}
|
|
|
|
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 roch = (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
|
|
{
|
|
int dbiId = System.Convert.ToInt32(roch.roid.Substring(0, 4), 16);
|
|
ROFSTLookup.rodbi[] dbs = MyROFSTLookup.GetRODatabaseList(false);
|
|
bool dbFound = false;
|
|
ROFSTLookup.rodbi db = dbs[0];
|
|
|
|
foreach (ROFSTLookup.rodbi rodbi in dbs)
|
|
{
|
|
if (dbiId == rodbi.dbiID)
|
|
{
|
|
db = rodbi;
|
|
dbFound = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
string AccPageID;
|
|
|
|
if (!dbFound)
|
|
{
|
|
if (roch.roid.StartsWith("FFFF"))
|
|
{
|
|
AccPageID = "<" + roch.appid + ">";
|
|
}
|
|
else
|
|
{
|
|
FlexibleMessageBox.Show("Error occurred finding RO. Contact Volian");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string accPrefix = db.dbiAP.Replace(MyDvi.DocVersionConfig.RODefaults_graphicsprefix, "IG");
|
|
accPrefix = accPrefix.Replace(MyDvi.DocVersionConfig.RODefaults_setpointprefix, "SP");
|
|
// string accPrefix = (roch.type == 8) ? _Mydvi.DocVersionConfig.RODefaults_graphicsprefix : _Mydvi.DocVersionConfig.RODefaults_setpointprefix;
|
|
string suffix = (roch.roid.Length == 12 || roch.roid.Substring(12, 4) == "0041") ? "" : "." + ((char)Convert.ToInt32(roch.roid.Substring(12, 4), 16)).ToString();
|
|
AccPageID = string.Format("<{0}-{1}{2}>", accPrefix, roch.appid, suffix);// makes <SP1-A.1.B> for example
|
|
Console.WriteLine(AccPageID);
|
|
}
|
|
|
|
// 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(roch)) // check for RO type is valid for this type of step/substep
|
|
{
|
|
// the roid may be 12 or 16 chars long, with the last 4 set if there is unit specific
|
|
// menuing. Pad to 12 to store in the rousage table.
|
|
string padroid = (roch.roid.Length <= 12) ? roch.roid + "0000" : roch.roid;
|
|
string linktxt = string.Format(@"#Link:ReferencedObject:<NewID> {0} {1}", padroid, _myROFST.MyRODb.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); //ConvertSymbolsAndStuff(selectedChld.value);
|
|
MyRTB.OnRoInsert(this, new StepRTBRoEventArgs(valtxt, selectedChld.value, linktxt, padroid, _myROFST.MyRODb.RODbID));
|
|
}
|
|
|
|
btnGoToRO.Enabled = btnSaveRO.Enabled = btnCancelRO.Enabled = btnPreviewRO.Enabled = false;
|
|
_savCurROLink = null;
|
|
CurROLink = null;
|
|
}
|
|
}
|
|
|
|
ProcessSearch(string.Empty, (int)ROFSTLookup.SearchType.StartsWith);
|
|
}
|
|
|
|
private bool CheckROSelection(ROFSTLookup.rochild selectedRO)
|
|
{
|
|
bool goodToGo = true;
|
|
bool replacingRO = (_savCurROLink != null);
|
|
string insrpl = (replacingRO) ? "Cannot Replace" : "Cannot Insert";
|
|
string errormsg = "";
|
|
|
|
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 roch = (ROFSTLookup.rochild)obj;
|
|
_selectedRoidBeforeRoEditor = roch.roid;
|
|
string args = "\"" + _myROFST.MyRODb.FolderPath + "\" " + roch.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
|
|
|
|
DocVersionInfoList dvil = DocVersionInfoList.Get();
|
|
|
|
foreach (DocVersionInfo dvi in dvil)
|
|
{
|
|
DocVersionConfig jdvc = dvi.DocVersionConfig;
|
|
|
|
if (jdvc != null && jdvc.Unit_Name != "" && jdvc.Unit_Name != "0")
|
|
{
|
|
args += " \"PC=" + jdvc.Unit_Name + "\"";
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
System.Diagnostics.Process.Start(roapp, args);
|
|
}
|
|
}
|
|
|
|
private void ProcessSearch(string searchValue, int searchTypeID)
|
|
{
|
|
lbFound.SelectedValueChanged -= new EventHandler(lbFound_SelectedValueChanged);
|
|
|
|
if (!string.IsNullOrEmpty(searchValue))
|
|
{
|
|
Dictionary<string, string> dicRoVals = new Dictionary<string, string>();
|
|
|
|
searchValue = searchValue.Replace('\u2011', '-').Replace(@"\u9586?", @"\\");
|
|
|
|
if (MyROFST != null && searchValue.Length >= 2)
|
|
{
|
|
dicRoVals = new ROFSTLookup(MyROFST.ROFstID, MyDvi).Search(searchValue, searchTypeID, MaxNumSearchRecords);
|
|
}
|
|
|
|
if (dicRoVals != null && dicRoVals.Count > 0)
|
|
{
|
|
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;
|
|
}
|
|
else
|
|
{
|
|
lbFound.DataSource = null;
|
|
lbFound.Visible = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lbFound.DataSource = null;
|
|
lbFound.Visible = false;
|
|
}
|
|
|
|
lbFound.SelectedValueChanged += new EventHandler(lbFound_SelectedValueChanged);
|
|
|
|
if (lbFound.Items != null && lbFound.Items.Count == 1)
|
|
lbFound.SelectedIndex = 0;
|
|
|
|
_lastSearchValue = searchValue;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|