- Added Print Function (Event)

- Added code to Resize Tree as Tree Nodes are expanded and collapsed
- Sorts ROs by value
- Added button to Clear Search Results
- Added button to Copy Search Results to Clipboard
- Split BuildSearchString into separate Parameters
- Added Print Function
- Added button to Clear Search Results
- Added button to Copy Search Results to Clipboard
This commit is contained in:
Rich 2010-09-06 19:36:12 +00:00
parent d0ec2bab6f
commit cfedc831ba
2 changed files with 1436 additions and 1279 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9,13 +9,22 @@ using VEPROMS.CSLA.Library;
using DevComponents.DotNetBar;
using DevComponents.AdvTree;
using Volian.Base.Library;
using System.Text.RegularExpressions;
namespace Volian.Controls.Library
{
public partial class DisplaySearch : UserControl
{
#region Properties
private string _strSrchText = "";
{
#region Events
public event DisplaySearchEvent PrintRequest;
private void OnPrintRequest(DisplaySearchEventArgs args)
{
if (PrintRequest != null)
PrintRequest(this, args);
}
#endregion
#region Properties
private string _strSrchText = "";
private List<DocVersionInfo> lstCheckedDocVersions = new List<DocVersionInfo>();
private List<int> lstCheckedStepTypes = new List<int>();
@ -423,7 +432,9 @@ namespace Volian.Controls.Library
{
if (_MyROFSTLookup == null) return;
cmboTreeROs.Nodes.Clear();
this.cmboTreeROs.AdvTree.BeforeExpand += new DevComponents.AdvTree.AdvTreeNodeCancelEventHandler(this.cmboTreeROs_BeforeSelectNode);
this.cmboTreeROs.AdvTree.BeforeExpand += new DevComponents.AdvTree.AdvTreeNodeCancelEventHandler(this.cmboTreeROs_BeforeExpand);
cmboTreeROs.AdvTree.AfterExpand += new AdvTreeNodeEventHandler(AdvTree_AfterExpandorCollapse);
cmboTreeROs.AdvTree.AfterCollapse += new AdvTreeNodeEventHandler(AdvTree_AfterExpandorCollapse);
for (int i = 0; i < _MyROFSTLookup.myHdr.myDbs.Length; i++)
{
DevComponents.AdvTree.Node tn = new DevComponents.AdvTree.Node();
@ -433,7 +444,45 @@ namespace Volian.Controls.Library
AddDummyGroup(_MyROFSTLookup.myHdr.myDbs[i], tn);
}
}
void AdvTree_AfterExpandorCollapse(object sender, AdvTreeNodeEventArgs e)
{
Node bottomNode = BottomTreeNode(cmboTreeROs.AdvTree.Nodes);
Node lastNode = cmboTreeROs.AdvTree.Nodes[cmboTreeROs.AdvTree.Nodes.Count - 1];
int top = cmboTreeROs.AdvTree.Nodes[0].Bounds.Top;
int bottom = bottomNode.Bounds.Bottom + 5;
int hScrollBarHeight = cmboTreeROs.AdvTree.HScrollBar != null ? cmboTreeROs.AdvTree.HScrollBar.Height : 0;
bottom = bottomNode.Bounds.Bottom + 5;
cmboTreeROs.AdvTree.Size = new Size(cmboTreeROs.AdvTree.Size.Width, Math.Min(525, bottom - top + hScrollBarHeight));
if (cmboTreeROs.AdvTree.VScrollBar != null && bottom < cmboTreeROs.AdvTree.Size.Height)
{
int yLookFor = (bottom - cmboTreeROs.AdvTree.Size.Height) + 2 * hScrollBarHeight;
Node topNode = FindTreeNodeAt(cmboTreeROs.AdvTree.Nodes, yLookFor);
if (topNode != null)
topNode.EnsureVisible();
}
}
private Node FindTreeNodeAt(NodeCollection nodes, int y)
{
foreach (Node node in nodes)
{
if (node.Bounds.Top <= y && node.Bounds.Bottom >= y)
return node;
if (node.Bounds.Top > y)
{
if (node.PrevNode != null && node.PrevNode.Expanded)
return FindTreeNodeAt(node.PrevNode.Nodes, y);
return node;
}
}
return null;
}
private Node BottomTreeNode(NodeCollection nodes)
{
Node bottomNode = nodes[nodes.Count - 1]; // Return bottom node in collection
if (bottomNode.Expanded) // If expanded return bottom child
return BottomTreeNode(bottomNode.Nodes);
return bottomNode;
}
private void AddDummyGroup(ROFSTLookup.rodbi rodbi, DevComponents.AdvTree.Node tn)
{
if (rodbi.children != null && rodbi.children.Length > 0)
@ -443,11 +492,9 @@ namespace Volian.Controls.Library
tn.Nodes.Add(tmp);
}
}
private void cmboTreeROs_BeforeSelectNode(object sender, DevComponents.AdvTree.AdvTreeNodeCancelEventArgs e)
private void cmboTreeROs_BeforeExpand(object sender, DevComponents.AdvTree.AdvTreeNodeCancelEventArgs e)
{
LoadChildren(e.Node);
LoadChildren(e.Node);
}
private void LoadChildren(DevComponents.AdvTree.Node tn)
@ -501,13 +548,39 @@ namespace Volian.Controls.Library
tmp = new DevComponents.AdvTree.Node();
tmp.Text = chld[i].title;
tmp.Tag = chld[i];
tn.Nodes.Add(tmp);
int index = FindIndex(tn.Nodes, tmp.Text);
tn.Nodes.Insert(index,tmp);
//tn.Nodes.Add(tmp);
}
}
}
ProgressBar_Clear();
}
private int FindIndex(NodeCollection nodes, string value)
{
int index = 0;
foreach (Node node in nodes)
{
if (GreaterValue(node.Text, value)) return index;
index++;
}
return index;
}
private static Regex _RegExGetNumber = new Regex(@"^ *[+-]?[.,0-9]+(E[+-]?[0-9]+)?");
private bool GreaterValue(string value1, string value2)
{
Match match1 = _RegExGetNumber.Match(value1);
Match match2 = _RegExGetNumber.Match(value2);
if (match1.Success && match2.Success) // Compare the numeric value
{
double dbl1 = double.Parse(match1.ToString());
double dbl2 = double.Parse(match2.ToString());
return dbl1 > dbl2;
}
return String.Compare( value1,value2,true) > 0;
}
private void cmboTreeROs_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmboTreeROs.SelectedIndex == -1 || cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rodbi)
@ -633,12 +706,16 @@ namespace Volian.Controls.Library
if (lbSrchResults.Items.Count > 0)
{
btnPrnSrchRslts.Enabled = true;
btnClearSearchResults.Enabled = true;
btnCopySearchResults.Enabled = true;
cmbResultsStyle.Enabled = true;
}
else
{
btnPrnSrchRslts.Enabled = false;
cmbResultsStyle.Enabled = false;
btnClearSearchResults.Enabled = false;
btnCopySearchResults.Enabled = false;
cmbResultsStyle.Enabled = false;
}
lbSrchResults.SelectedIndex = -1;
@ -731,96 +808,106 @@ namespace Volian.Controls.Library
{
DisplayResults();
}
private void panSearchButtons_MouseDoubleClick(object sender, MouseEventArgs e)
{
DialogResult dr = MessageBox.Show("Michelle,\n\n Do you want to clear this Search List?", "For Michelle...", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
lbSrchResults.DataSource = null;
_SearchResults = null;
DisplayResults();
}
}
#endregion
#region Search
private string[] BuildSearchString()
{
_strSrchText = ""; // used when jumping to a section from the results window
// the search query needs '<DocVerID>,...<DocVerID>','<StepTypeID>,...,<StepTypeID>','<TextToSearch>'
string[] strRtnStr = { "", "", "" };
// append list of document versions to search
if (lstCheckedDocVersions.Count > 0)
{
// get list of doc versions to search
foreach (DocVersionInfo dvi in lstCheckedDocVersions)
{
strRtnStr[0] += string.Format("{0},", dvi.VersionID.ToString());
}
strRtnStr[0] = strRtnStr[0].Remove(strRtnStr[0].LastIndexOf(','), 1);
}
// append list of step types to search
if (lstCheckedStepTypes.Count > 0)
{
// get list of selected types
foreach (int typ in lstCheckedStepTypes)
{
int tmp = typ;
if (tmp == 0)
tmp = 10000; // this is the accessory page type
else
tmp += 20000; // step/substep types
strRtnStr[1] += string.Format("{0},", tmp);
}
strRtnStr[1] = strRtnStr[1].Remove(strRtnStr[1].LastIndexOf(','), 1);
}
if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[0])
{ // Text Search
_strSrchText = ConvertSpecialChars(cbxTextSearchText.Text);//string.Format("{0}", cbxTextSearchText.Text);
strRtnStr[2] += _strSrchText; // append text to search
//strRtnStr[2] += ConvertSpecialChars(cbxTextSearchText.Text);//string.Format("{0}", cbxTextSearchText.Text); // append text to search
}
else if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[1])
{ // Annotation Search
strRtnStr[2] += ((AnnotationTypeSearch)cbxAnnoTypes.SelectedValue).ID;
}
else if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[2])
{ // RO Search
ROFSTLookup.rochild[] chld = null;
ROFSTLookup.rochild ch;
if (cmboTreeROs.SelectedNode != null)
{
if (cbxFndUnLnkROVals.Enabled && cbxFndUnLnkROVals.Checked)
{
ch = (ROFSTLookup.rochild)cmboTreeROs.SelectedNode.Tag;
_strSrchText = string.Format("{0}", ch.value);
strRtnStr[2] += _strSrchText; // append RO Value text to search
//strRtnStr[2] += string.Format("{0}", ch.value); // append RO Value text to search
}
else
{
if (cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rodbi)
{
ROFSTLookup.rodbi db = (ROFSTLookup.rodbi)cmboTreeROs.SelectedNode.Tag;
strRtnStr[2] += _MyRODbID.ToString() + ":" + string.Format("{0}", db.dbiID.ToString("D4"));
}
else if (cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rochild)
{
ch = (ROFSTLookup.rochild)cmboTreeROs.SelectedNode.Tag;
chld = ch.children;
// build a list of ROs to search
strRtnStr[2] += _MyRODbID.ToString() + ":" + GetROsToSearch(chld);
if (strRtnStr[2].EndsWith(","))
strRtnStr[2] = strRtnStr[2].Substring(0, strRtnStr[2].Length - 1);
}
}
}
}
return strRtnStr;
}
private string DVISearchList
{
get
{
// append list of document versions to search
if (lstCheckedDocVersions.Count > 0)
{
string strRtnStr = "";
// get list of doc versions to search
foreach (DocVersionInfo dvi in lstCheckedDocVersions)
{
strRtnStr += string.Format(",{0}", dvi.VersionID.ToString());
}
return strRtnStr.Substring(1);
}
return "";
}
}
private string TypeSearchList
{
get
{
// append list of step types to search
if (lstCheckedStepTypes.Count > 0)
{
string strRtnStr = "";
// get list of selected types
foreach (int typ in lstCheckedStepTypes)
{
int tmp = typ;
if (tmp == 0)
tmp = 10000; // this is the accessory page type
else
tmp += 20000; // step/substep types
strRtnStr += string.Format(",{0}", tmp);
}
return strRtnStr.Substring(1);
}
return "";
}
}
private string TextSearchString
{
get
{
if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[0])
return ConvertSpecialChars(cbxTextSearchText.Text);//string.Format("{0}", cbxTextSearchText.Text);
return "";
}
}
private string AnnotationSearchType
{
get
{
if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[1])
return ((AnnotationTypeSearch)cbxAnnoTypes.SelectedValue).ID;
return "";
}
}
private string ROSearchList
{
get
{
if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[2])
{ // RO Search
ROFSTLookup.rochild[] chld = null;
ROFSTLookup.rochild ch;
if (cmboTreeROs.SelectedNode != null)
{
if (cbxFndUnLnkROVals.Enabled && cbxFndUnLnkROVals.Checked)
{
ch = (ROFSTLookup.rochild)cmboTreeROs.SelectedNode.Tag;
_strSrchText = string.Format("{0}", ch.value);
return _strSrchText; // append RO Value text to search
}
else
{
if (cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rodbi)
{
ROFSTLookup.rodbi db = (ROFSTLookup.rodbi)cmboTreeROs.SelectedNode.Tag;
return _MyRODbID.ToString() + ":" + string.Format("{0}", db.dbiID.ToString("D4"));
}
else if (cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rochild)
{
ch = (ROFSTLookup.rochild)cmboTreeROs.SelectedNode.Tag;
chld = ch.children;
// build a list of ROs to search
return _MyRODbID.ToString() + ":" + GetROsToSearch(chld);
//if (strRtnStr.EndsWith(","))
// strRtnStr = strRtnStr.Substring(0, strRtnStr.Length - 1);
}
}
}
}
return "";
}
}
private string ConvertSpecialChars(string str)
{
@ -868,12 +955,9 @@ namespace Volian.Controls.Library
Cursor savcursor = Cursor;
try
{
string[] strSearchText = null;
lbSrchResults.DataSource = null;
lbSrchResults.Items.Clear();
toolTip1.SetToolTip(lbSrchResults, null);
strSearchText = BuildSearchString();
Cursor = Cursors.WaitCursor;
SearchResults = null;
bool includeRTFformat = false;
@ -891,43 +975,51 @@ namespace Volian.Controls.Library
}
else
{
SearchResults = ItemInfoList.GetListFromTextSearch(strSearchText[0], strSearchText[1], "", cbxBooleanTxtSrch.Checked ? 2 : cbxCaseSensitive.Checked ? 1 : 0, ItemSearchIncludeLinks.Value, includeRTFformat, includeSpecialChars);
ReportTitle = "PROMS2010 - Search by Type";
SearchString = null;
SearchResults = ItemInfoList.GetListFromTextSearch(DVISearchList, TypeSearchList, "", cbxBooleanTxtSrch.Checked ? 2 : cbxCaseSensitive.Checked ? 1 : 0, ItemSearchIncludeLinks.Value, includeRTFformat, includeSpecialChars);
cmbResultsStyle.SelectedIndex = 1; //display step locations in results
}
}
else
{
if (strSearchText[2].Equals(""))
{
MessageBox.Show("Please enter some search text, then click the Search button", "No Search Text");
cbxTextSearchText.Focus();
}
else
{
SearchResults = ItemInfoList.GetListFromTextSearch(strSearchText[0], strSearchText[1], strSearchText[2], cbxBooleanTxtSrch.Checked ? 2 : cbxCaseSensitive.Checked ? 1 : 0, cbxIncROTextSrch.Checked ? ItemSearchIncludeLinks.Value : ItemSearchIncludeLinks.Nothing, includeRTFformat, includeSpecialChars);
//if (textSearchString.Equals(""))
//{
// MessageBox.Show("Please enter some search text, then click the Search button", "No Search Text");
// cbxTextSearchText.Focus();
//}
//else
//{
ReportTitle = string.Format("PROMS2010 - {0} Search for '{1}'",cbxBooleanTxtSrch.Checked ? "Boolean" : "Text", TextSearchString);
SearchString = TextSearchString;
SearchResults = ItemInfoList.GetListFromTextSearch(DVISearchList, TypeSearchList, TextSearchString, cbxBooleanTxtSrch.Checked ? 2 : cbxCaseSensitive.Checked ? 1 : 0, cbxIncROTextSrch.Checked ? ItemSearchIncludeLinks.Value : ItemSearchIncludeLinks.Nothing, includeRTFformat, includeSpecialChars);
cmbResultsStyle.SelectedIndex = 3; // display step text in results
}
//}
}
}
else if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[1]) // Annotation Search
{
SearchString = null;
ReportTitle = string.Format("PROMS2010 - Annotation Search for '{0}'", cbxTextSearchAnnotation.Text);
//string srchStr = ConvertSpecialChars(cbxTextSearchAnnotation.Text);//cbxTextSearchAnnotation.Text;
//SearchResults = ItemInfoList.GetListFromAnnotationSearch(strSearchText[0], strSearchText[1], strSearchText[2], srchStr, cbxCaseSensitiveAnnoText.Checked);
SearchResults = ItemInfoList.GetListFromAnnotationSearch(strSearchText[0], strSearchText[1], strSearchText[2], cbxTextSearchAnnotation.Text, cbxCaseSensitiveAnnoText.Checked);
//SearchResults = ItemInfoList.GetListFromAnnotationSearch(dviSearchList, typeSearchList, textSearchString, srchStr, cbxCaseSensitiveAnnoText.Checked);
SearchResults = ItemInfoList.GetListFromAnnotationSearch(DVISearchList, TypeSearchList, AnnotationSearchType, cbxTextSearchAnnotation.Text, cbxCaseSensitiveAnnoText.Checked);
//UpdateAnnotationSearchResults();
cmbResultsStyle.SelectedIndex = 2; // display annotation text in results
}
else if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[2]) // RO Search
{
SearchString = null;
ReportTitle = "PROMS2010 - Referenced Object Search";
if (cbxFndUnLnkROVals.Enabled && cbxFndUnLnkROVals.Checked)
{
SearchResults = ItemInfoList.GetListFromTextSearch(strSearchText[0], strSearchText[1], strSearchText[2], cbxBooleanTxtSrch.Checked ? 2 : cbxCaseSensitive.Checked ? 1 : 0, ItemSearchIncludeLinks.Nothing, includeRTFformat, includeSpecialChars);
SearchResults = ItemInfoList.GetListFromTextSearch(DVISearchList, TypeSearchList, ROSearchList, cbxBooleanTxtSrch.Checked ? 2 : cbxCaseSensitive.Checked ? 1 : 0, ItemSearchIncludeLinks.Nothing, includeRTFformat, includeSpecialChars);
cmbResultsStyle.SelectedIndex = 3; // display step text in results
}
else
{
SearchResults = ItemInfoList.GetListFromROSearch(strSearchText[0], strSearchText[1], strSearchText[2]);
SearchResults = ItemInfoList.GetListFromROSearch(DVISearchList, TypeSearchList, ROSearchList);
cmbResultsStyle.SelectedIndex = 3; // display step text in results
}
}
@ -1286,7 +1378,6 @@ namespace Volian.Controls.Library
}
}
#endregion
private void buttonItem2_Click(object sender, EventArgs e)
{
if (cbxTextSearchAnnotation.Focused)
@ -1295,7 +1386,6 @@ namespace Volian.Controls.Library
cbxTextSearchText.SelectedText = "*";
}
private void buttonItem3_Click(object sender, EventArgs e)
{
if (cbxTextSearchAnnotation.Focused)
@ -1304,16 +1394,13 @@ namespace Volian.Controls.Library
cbxTextSearchText.SelectedText = "?";
}
private void buttonItem4_Click(object sender, EventArgs e)
{
if (cbxTextSearchAnnotation.Focused)
cbxTextSearchAnnotation.SelectedText = "?*";
else if (cbxTextSearchText.Focused)
cbxTextSearchText.SelectedText = "?*";
}
private void cbxBooleanTxtSrch_CheckedChanged(object sender, EventArgs e)
{
if (cbxBooleanTxtSrch.Checked)
@ -1339,7 +1426,6 @@ namespace Volian.Controls.Library
cbxIncROTextSrch.Enabled = true;
}
}
private void cbxBooleanAnoTxtSrch_CheckedChanged(object sender, EventArgs e)
{
if (cbxBooleanAnoTxtSrch.Checked)
@ -1355,8 +1441,6 @@ namespace Volian.Controls.Library
btnCMIFindText.SubItems[1].SubItems[3].Visible = false;
}
}
private void btnAND_Click(object sender, EventArgs e)
{
if (cbxTextSearchAnnotation.Focused)
@ -1365,7 +1449,6 @@ namespace Volian.Controls.Library
cbxTextSearchText.SelectedText = " AND ";
}
private void btnOR_Click(object sender, EventArgs e)
{
if (cbxTextSearchAnnotation.Focused)
@ -1374,38 +1457,70 @@ namespace Volian.Controls.Library
cbxTextSearchText.SelectedText = " OR ";
}
private void btnNOT_Click(object sender, EventArgs e)
{
if (cbxTextSearchAnnotation.Focused)
cbxTextSearchAnnotation.SelectedText = " NOT ";
else if (cbxTextSearchText.Focused)
cbxTextSearchText.SelectedText = " NOT ";
}
private void tabAnnotationSearch_Click(object sender, EventArgs e)
{
cbxAnnoTypes.Focus();
cbxBooleanAnoTxtSrch_CheckedChanged(sender, e);
}
private void btnClearSearchResults_Click(object sender, EventArgs e)
{
lbSrchResults.DataSource = null;
_SearchResults = null;
DisplayResults();
}
private void btnCopySearchResults_Click(object sender, EventArgs e)
{
ICollection<ItemInfo> myList = lbSrchResults.DataSource as ICollection<ItemInfo>;
StringBuilder sb = new StringBuilder();
sb.Append("\"Location\"\t\"Type\"\t\"Text\"\t\"High-Level\"\t\"Annotations\"");
foreach (ItemInfo myItem in myList)
{
sb.Append(string.Format("\r\n\"{0}\"\t\"{1}\"\t\"{2}\"\t\"{3}\"", myItem.ShortPath, myItem.ToolTip,
myItem.DisplayText, !myItem.IsSection && !myItem.IsHigh ? myItem.MyHLS.DisplayText : ""));
if(myItem.ItemAnnotationCount > 0)
foreach(AnnotationInfo myAnnotation in myItem.ItemAnnotations)
sb.Append(string.Format("\t\"{0}\"",myAnnotation.SearchText));
}
Clipboard.Clear();
Clipboard.SetText(sb.ToString());
MessageBox.Show("Results Copied to Clipboard","Copy Results", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private string _ReportTitle;
public string ReportTitle
{
get { return _ReportTitle; }
set { _ReportTitle = value; }
}
private string _SearchString=null;
public string SearchString
{
get { return _SearchString; }
set { _SearchString = value; }
}
private void btnPrnSrchRslts_Click(object sender, EventArgs e)
{
OnPrintRequest(new DisplaySearchEventArgs(ReportTitle,SearchString,lbSrchResults.DataSource as ICollection<ItemInfo>));
}
}
#region Annoation Search Type Class
// this class is used to generate the list of annotations to search.
// this also allow us to add a dummy type which is used to search for all annotations
public class AnnotationTypeSearch
{
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
private string _ID;
public string ID
{
get { return _ID; }
@ -1416,6 +1531,35 @@ namespace Volian.Controls.Library
_Name = name;
_ID = id;
}
}
#endregion
public class DisplaySearchEventArgs
{
private string _ReportTitle;
public string ReportTitle
{
get { return _ReportTitle; }
set { _ReportTitle = value; }
}
private string _SearchString = null;
public string SearchString
{
get { return _SearchString; }
set { _SearchString = value; }
}
private ICollection<ItemInfo> _MyItemInfoList;
public ICollection<ItemInfo> MyItemInfoList
{
get { return _MyItemInfoList; }
set { _MyItemInfoList = value; }
}
public DisplaySearchEventArgs(string reportTitle, string searchString, ICollection<ItemInfo> myItemInfoList)
{
_ReportTitle = reportTitle;
_MyItemInfoList = myItemInfoList;
_SearchString = searchString;
}
}
public delegate void DisplaySearchEvent(object sender, DisplaySearchEventArgs args);
}