using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using VEPROMS.CSLA.Library; using DevComponents.DotNetBar; using DevComponents.AdvTree; namespace Volian.Controls.Library { public partial class DisplaySearch : UserControl { #region Properties private List lstCheckedDocVersions = new List(); private List lstCheckedStepTypes = new List(); private AnnotationDetails _AnnotationDetails = null; ItemInfo _ItemInfo = null; private DisplayTabControl _TabControl; private DocVersionInfo _MyDocVersion; private Color saveXpSetToSearchColor; private Color saveXpStepTypeTitleColor; private Color saveGpSrchAnnoTextColor; private Color saveGpSrchTextColor; private Color saveGpFindROsColor; private Color saveGrpPanSearchResults; private ItemInfoList _SearchResults; public ItemInfoList SearchResults { get { return _SearchResults; } set { _SearchResults = value; DisplayResults(); } } private string _DisplayMember = "SearchPath"; //public string Status //{ // get { return tsslStatus.Text; } // set { tsslStatus.Text = value; Application.DoEvents(); } //} private bool _OpenDocFromSearch; public bool OpenDocFromSearch { get { return _OpenDocFromSearch; } //set { _OpenDocFromSearch = value; } } public DocVersionInfo Mydocversion { get { return _MyDocVersion; } set { _MyDocVersion = value; if (_MyDocVersion != null) { if (_MyDocVersion.DocVersionAssociationCount > 0) { MyROFSTLookup = _MyDocVersion.DocVersionAssociations[0].MyROFst.ROFSTLookup; _MyRODbID = _MyDocVersion.DocVersionAssociations[0].MyROFst.RODbID; } } } } private ROFSTLookup _MyROFSTLookup; public ROFSTLookup MyROFSTLookup { get { return _MyROFSTLookup; } set { //if (!Visible) return; // don't reset anything if the form is invisible. _MyROFSTLookup = value; // define the tree nodes based on this rofst LoadROComboTree(); } } private bool _LoadingList = false; public bool LoadingList { get { return _LoadingList; } set { _LoadingList = value; } } private int LastResultsMouseOverIndex = -1; private ProgressBarItem _ProgressBar; public ProgressBarItem ProgressBar { get { return _ProgressBar; } set { _ProgressBar = value; } } #endregion #region setup public DisplaySearch() { InitializeComponent(); LoadSearchTextListBox(); saveXpSetToSearchColor = xpSetToSearch.TitleStyle.BackColor1.Color; saveXpStepTypeTitleColor = xpStepTypes.TitleStyle.BackColor1.Color; saveGpSrchAnnoTextColor = gpSrchAnnoText.Style.BackColor; saveGpSrchTextColor = gpSrchText.Style.BackColor; saveGpFindROsColor = gpFindROs.Style.BackColor; gpSrchText.Style.BackColor = Color.Yellow; saveGrpPanSearchResults = grpPanSearchResults.Style.BackColor; // start out with the procedure and type selection windows colasped xpSetToSearch.Expanded = false; xpStepTypes.Expanded = false; rbtnSrchTxt.Checked = true; gpSrchAnnoText.Enabled = true; cmbResultsStyle.Enabled = false; } private void LoadSearchTextListBox() { cbxTextSearchText.Items.Clear(); cbxTextSearchAnnotation.Items.Clear(); } public void advTreeStepTypesFillIn() { DevComponents.AdvTree.Node topnode = new DevComponents.AdvTree.Node(); advTreeStepTypes.Nodes.Clear(); lstCheckedStepTypes.Clear(); topnode.Text = "Types"; advTreeStepTypes.Nodes.Add(topnode); FormatData fmtdata = _MyDocVersion.ActiveFormat.PlantFormat.FormatData; List lstSrchStpTypes = fmtdata.GetSearchableSteps(); // list of searchable step types if (lstSrchStpTypes != null && lstSrchStpTypes.Count > 0) { DevComponents.AdvTree.Node newnode; advTreeStepTypes.Nodes.Clear(); // Add a dummy node for searching Accessory Sections (MS Word sections) newnode = new DevComponents.AdvTree.Node(); newnode.Text = "Accessory Sections"; newnode.Selectable = true; newnode.CheckBoxAlignment = DevComponents.AdvTree.eCellPartAlignment.NearCenter; newnode.CheckBoxStyle = eCheckBoxStyle.CheckBox; newnode.CheckBoxThreeState = false; newnode.CheckBoxVisible = true; advTreeStepTypes.Nodes.Add(newnode); foreach (StepDataRetval sdr in lstSrchStpTypes) { StepDataList sdl = fmtdata.StepDataList; ; StepData sd = sdl[sdr.Index]; // get the step type record string parentName = sd.ParentType; // this gets the parent of the this step/substep type newnode = new DevComponents.AdvTree.Node(); newnode.Text = sdr.Name; newnode.Name = sd.Type; // this needed for the FindNodeByName() function newnode.Tag = sd; newnode.Selectable = true; newnode.CheckBoxAlignment = DevComponents.AdvTree.eCellPartAlignment.NearCenter; newnode.CheckBoxStyle = eCheckBoxStyle.CheckBox; newnode.CheckBoxThreeState = false; newnode.CheckBoxVisible = true; // if the parent node exists in the tree, then add the new node to that parent // else, it is a parent node, so add it as a new parent DevComponents.AdvTree.Node parnode = advTreeStepTypes.FindNodeByName(parentName); // Group by High Level Steps, Substeps, Cautions, Notes, Figures, Tables while (!parentName.Equals("Base") && !parentName.Equals("Substep") && !parentName.Equals("High") && !parentName.Equals("Caution") && !parentName.Equals("Note") && !parentName.Equals("Table") && !parentName.Equals("Figure")) { StepData tmpsd = (StepData)parnode.Tag; parentName = tmpsd.ParentType; parnode = advTreeStepTypes.FindNodeByName(parentName); } if (parnode != null) { parnode.Nodes.Add(newnode); parnode.Nodes.Sort(); // sort the second level of the tree } else advTreeStepTypes.Nodes.Add(newnode); } advTreeStepTypes.Nodes.Sort(); // sort the first level of the tree } buildStepTypePannelTitle(); } public void advTreeProcSetsFillIn(bool blSeachTabClicked) { DevComponents.AdvTree.Node topnode = null; int cntnd = 0; VETreeNode vtn = VETreeNode.GetFolder(1); FolderInfo fi = vtn.VEObject as FolderInfo; int fiCount = fi.ChildFolderCount; advTreeProcSets.Nodes.Clear(); lstCheckedDocVersions.Clear(); foreach (FolderInfo fic in fi.ChildFolders) { DevComponents.AdvTree.Node newnode = new DevComponents.AdvTree.Node(); newnode.Text = fic.ToString(); newnode.Tag = fic; int tmp; if (topnode == null) { newnode.Text = "Available Procedure Sets"; tmp = advTreeProcSets.Nodes.Add(newnode); topnode = newnode; } else { newnode.Selectable = true; newnode.CheckBoxAlignment = DevComponents.AdvTree.eCellPartAlignment.NearCenter; newnode.CheckBoxStyle = eCheckBoxStyle.CheckBox; newnode.CheckBoxThreeState = false; newnode.CheckBoxVisible = true; tmp = topnode.Nodes.Add(newnode); } cntnd++; if (fic.ChildFolderCount > 0) // allow for '+' for tree expansion { DevComponents.AdvTree.Node tnt = new DevComponents.AdvTree.Node(); tnt.Text = "VLN_DUMMY"; newnode.Nodes.Add(tnt); } } // if nothing was added to the tree, just put in the node above the docversions... if (advTreeProcSets.Nodes.Count == 0) { cntnd++; fi = Mydocversion.MyFolder; topnode = new DevComponents.AdvTree.Node(); topnode.Text = fi.ToString(); advTreeProcSets.Nodes.Add(topnode); topnode.Tag = fi; } advTreeProcSets.BeforeExpand += new DevComponents.AdvTree.AdvTreeNodeCancelEventHandler(advTreeProcSets_BeforeExpand); // position to the procedure set in the tree if we have a procedure open if (Mydocversion != null) advTreeProcSetsPreSelect(); else advTreeProcSets.Nodes[0].SelectedCell = advTreeProcSets.Nodes[0].Cells[0]; // select the first node - fixes cosmetic problem if (blSeachTabClicked) cbxTextSearchText.Focus(); // set initial focus to enter search text } void advTreeProcSets_BeforeExpand(object sender, DevComponents.AdvTree.AdvTreeNodeCancelEventArgs e) { DevComponents.AdvTree.Node par = e.Node; // get first child's text, if it has one & if the text is VLN_DUMMY, load children DevComponents.AdvTree.Node tn = null; if (par.Nodes.Count > 0) tn = par.Nodes[0]; if (tn.Text == "VLN_DUMMY") // expand this { par.Nodes.Clear(); Object obj = par.Tag; if (!(obj is FolderInfo)) return; // should always be folderinfo on expand FolderInfo fi = (FolderInfo)obj; if (fi.ChildFolderCount > 0) { foreach (FolderInfo fic in fi.ChildFolders) { DevComponents.AdvTree.Node newnode = new DevComponents.AdvTree.Node(); newnode.Text = fic.ToString(); par.Nodes.Add(newnode); newnode.Tag = fic; if (fic.HasChildren) // allow for '+' for tree expansion { DevComponents.AdvTree.Node tnt = new DevComponents.AdvTree.Node(); tnt.Text = "VLN_DUMMY"; newnode.Nodes.Add(tnt); } } } else if (fi.FolderDocVersionCount > 0) { foreach (DocVersionInfo dv in fi.FolderDocVersions) { if ((VersionTypeEnum)dv.VersionType == VersionTypeEnum.WorkingDraft) { DevComponents.AdvTree.Node newnode = new DevComponents.AdvTree.Node(); newnode.Text = dv.ToString(); newnode.Tag = dv; newnode.Selectable = true; newnode.CheckBoxAlignment = DevComponents.AdvTree.eCellPartAlignment.NearCenter; newnode.CheckBoxStyle = eCheckBoxStyle.CheckBox; newnode.CheckBoxThreeState = false; newnode.CheckBoxVisible = true; par.Nodes.Add(newnode); } } } } } private Node LookInTree(NodeCollection monkeys, string bananna) { Node foundit = null; foreach(Node chimp in monkeys) { if (chimp.Text.Equals(bananna)) { foundit = chimp; // need to select the node (cell) for it to be checked chimp.SelectedCell = chimp.Cells[0]; if (chimp.Nodes.Count > 0) chimp.Expand(); break; } chimp.Collapse(); } return foundit; } private void advTreeProcSetsPreSelect() { bool keeplooking = true; //build a stack (bread crumb trail) of where is procedure set came from within the tree. Stack crumbs = new Stack(); crumbs.Push(Mydocversion.Name); // ex: "working draft" crumbs.Push(Mydocversion.MyFolder.Name); // ex: "Emergency Procedures" crumbs.Push(Mydocversion.MyFolder.MyParent.Name); // ex: "STPNOC-South Texas" crumbs.Push(advTreeProcSets.Nodes[0].Text); //top node of my tree // now walk the tree, looking for the node names we saved in the stack. NodeCollection monkeys = advTreeProcSets.Nodes; while (keeplooking) { Node climber = LookInTree(monkeys,crumbs.Pop()); keeplooking = (climber != null && crumbs.Count > 0); if (keeplooking) monkeys = climber.Nodes; if (!keeplooking && climber != null) { climber.Checked = true; } } } #endregion #region ROFST Combo Tree private void LoadROComboTree() { if (_MyROFSTLookup == null) return; cmboTreeROs.Nodes.Clear(); this.cmboTreeROs.AdvTree.BeforeExpand += new DevComponents.AdvTree.AdvTreeNodeCancelEventHandler(this.cmboTreeROs_BeforeSelectNode); for (int i = 0; i < _MyROFSTLookup.myHdr.myDbs.Length; i++) { DevComponents.AdvTree.Node tn = new DevComponents.AdvTree.Node(); tn.Text = _MyROFSTLookup.myHdr.myDbs[i].dbiTitle; tn.Tag = _MyROFSTLookup.myHdr.myDbs[i]; cmboTreeROs.Nodes.Add(tn); AddDummyGroup(_MyROFSTLookup.myHdr.myDbs[i], tn); } } private void AddDummyGroup(ROFSTLookup.rodbi rodbi, DevComponents.AdvTree.Node tn) { if (rodbi.children != null && rodbi.children.Length > 0) { DevComponents.AdvTree.Node tmp = new DevComponents.AdvTree.Node(); tmp.Text = "VLN_DUMMY_FOR_TREE"; tn.Nodes.Add(tmp); } } private void cmboTreeROs_BeforeSelectNode(object sender, DevComponents.AdvTree.AdvTreeNodeCancelEventArgs e) { LoadChildren(e.Node); } private void LoadChildren(DevComponents.AdvTree.Node tn) { object tag = tn.Tag; if (tn.HasChildNodes && tn.Nodes[0].Text != "VLN_DUMMY_FOR_TREE") return; // already loaded. if (tn.HasChildNodes && tn.Nodes[0].Text == "VLN_DUMMY_FOR_TREE") tn.Nodes[0].Remove(); 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; 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); DevComponents.AdvTree.Node 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 (chld[i].value == null) { tmp = new DevComponents.AdvTree.Node(); tmp.Text = chld[i].title; tmp.Tag = chld[i]; tn.Nodes.Add(tmp); DevComponents.AdvTree.Node sub = new DevComponents.AdvTree.Node(); sub.Text = "VLN_DUMMY_FOR_TREE"; tmp.Nodes.Add(sub); } else { tmp = new DevComponents.AdvTree.Node(); tmp.Text = chld[i].title; tmp.Tag = chld[i]; tn.Nodes.Add(tmp); } } } ProgressBar_Clear(); } private void cmboTreeROs_SelectedIndexChanged(object sender, EventArgs e) { if (cmboTreeROs.SelectedIndex == -1 || cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rodbi) cbxFndUnLnkROVals.Enabled = false; else if (cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rochild) { ROFSTLookup.rochild ro = (ROFSTLookup.rochild)cmboTreeROs.SelectedNode.Tag; cbxFndUnLnkROVals.Enabled = (ro.children == null); } if (!cbxFndUnLnkROVals.Enabled) cbxFndUnLnkROVals.Checked = false; } private void gpFindROs_EnabledChanged(object sender, EventArgs e) { if (gpFindROs.Enabled) gpFindROs.Style.BackColor = Color.Yellow; else gpFindROs.Style.BackColor = saveGpFindROsColor; } #endregion #region Annotation Search public void SetupAnnotationSearch(AnnotationDetails annotationDetails, DisplayTabControl tc) { _AnnotationDetails = annotationDetails; List annoTypes = new List(); annoTypes.Add(new AnnotationTypeSearch("All Annotations","")); AnnotationTypeInfoList annoList = AnnotationTypeInfoList.Get(); foreach (AnnotationTypeInfo ati in annoList) annoTypes.Add(new AnnotationTypeSearch(ati.Name, ati.TypeID.ToString())); cbxAnnoTypes.DisplayMember = "Name"; cbxAnnoTypes.DataSource = annoTypes; lbSrchResults.MouseMove += new MouseEventHandler(lbSrchResults_MouseMove); _TabControl = tc; } private void cbxTextSearchAnnotation_Leave(object sender, EventArgs e) { InsertAnnotationSearchCriteria(); } private void InsertAnnotationSearchCriteria() { if (!cbxTextSearchAnnotation.Text.Equals(string.Empty)) { string tstr = cbxTextSearchAnnotation.Text; if (!cbxTextSearchAnnotation.Items.Contains(tstr)) cbxTextSearchAnnotation.Items.Insert(0, tstr); } } private void gpSrchAnnoText_EnabledChanged(object sender, EventArgs e) { if (gpSrchAnnoText.Enabled) { gpSrchAnnoText.Style.BackColor = Color.Yellow; cbxTextSearchAnnotation.Focus(); } else gpSrchAnnoText.Style.BackColor = saveGpSrchAnnoTextColor; } #endregion #region ProgressBar 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 = ""; _ProgressBar.Maximum = 0; _ProgressBar.Value = 0; _ProgressBar.TextVisible = false; } } #endregion #region Search Results private void DisplayResults() { _LoadingList = true; lbSrchResults.DisplayMember = _DisplayMember; if (_SearchResults != null) { if (cbSorted.Checked) { Csla.SortedBindingList sortedResults = new Csla.SortedBindingList(_SearchResults); sortedResults.ApplySort(_DisplayMember, ListSortDirection.Ascending); lbSrchResults.DataSource = sortedResults; } else lbSrchResults.DataSource = _SearchResults; grpPanSearchResults.Text = string.Format("Search Results Found: {0}", _SearchResults.Count); grpPanSearchResults.Style.BackColor = Color.LightGreen;// Color.YellowGreen; Color.DarkSeaGreen; } else { grpPanSearchResults.Text = "Search Results"; grpPanSearchResults.Style.BackColor = saveGrpPanSearchResults; } // Turn Print and Results display style on/off based on whether there are search results if (lbSrchResults.Items.Count > 0) { btnPrnSrchRslts.Enabled = true; cmbResultsStyle.Enabled = true; } else { btnPrnSrchRslts.Enabled = false; cmbResultsStyle.Enabled = false; } lbSrchResults.SelectedIndex = -1; LastResultsMouseOverIndex = -1; _LoadingList = false; } //public void UpdateAnnotationSearchResults() //{ // //AnnotationTypeInfo ati = cbxAnnoTypes.SelectedValue as AnnotationTypeInfo; // //_LoadingList = true; // //lbSrchResults.DataSource = ati.AnnotationTypeAnnotations; // //lbSrchResults.SelectedIndex = -1; // //LastResultsMouseOverIndex = -1; // //if (lbSrchResults.Items.Count > 0) // // btnPrnSrchRslts.Enabled = true; // //else // // btnPrnSrchRslts.Enabled = false; // //_LoadingList = false; //} private void lbSrchResults_MouseMove(object sender, MouseEventArgs e) { int ResultsMouseOverIndex = lbSrchResults.IndexFromPoint(e.Location); if (ResultsMouseOverIndex != -1 && ResultsMouseOverIndex != LastResultsMouseOverIndex) { ItemInfo ii = lbSrchResults.Items[ResultsMouseOverIndex] as ItemInfo; if (cmbResultsStyle.Text == "Step Path") toolTip1.SetToolTip(lbSrchResults, ii.DisplayText); // display the text in a tooltip else toolTip1.SetToolTip(lbSrchResults, ii.Path); // display location of corresponding procedure text in a tooltip LastResultsMouseOverIndex = ResultsMouseOverIndex; } } private void lbSrchResults_SelectedValueChanged(object sender, EventArgs e) { if (!_LoadingList) { _ItemInfo = lbSrchResults.SelectedValue as ItemInfo; if ((tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[1]) && (_ItemInfo != null)) { _AnnotationDetails.CurrentAnnotation = AnnotationInfo.Get(_ItemInfo.SearchAnnotationID); if (_AnnotationDetails.CurrentAnnotation != null) _TabControl.OpenItem(_AnnotationDetails.CurrentAnnotation.MyItem); // open the corresponding procedure text _AnnotationDetails.FindCurrentAnnotation(); // position to corresponding row in annotation grid } else { if (_ItemInfo != null) { _OpenDocFromSearch = true; DisplayTabItem dti = _TabControl.OpenItem(_ItemInfo); // open the corresponding procedure text if (dti.MyDSOTabPanel != null) dti.MyDSOTabPanel.SearchString = this.cbxTextSearchText.Text; if (dti.MyStepTabPanel != null) dti.MyStepTabPanel.SearchString = this.cbxTextSearchText.Text; _OpenDocFromSearch = false; } } } } private void cmbResultsStyle_SelectedValueChanged(object sender, EventArgs e) { switch (cmbResultsStyle.Text) { case "Document Path": _DisplayMember = "SearchDVPath"; break; case "Step Path": _DisplayMember = "ShortSearchPath"; break; case "Annotation Text": _DisplayMember = "SearchAnnotationText"; break; case "Document Text": _DisplayMember = "DisplayText"; break; default: _DisplayMember = "SearchPath"; break; } DisplayResults(); } private void cbSorted_CheckedChanged(object sender, EventArgs e) { 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() { // the search query needs ',...',',...,','' 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 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; 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 ConvertSpecialChars(string str) { string rtnVal = str; rtnVal = rtnVal.Replace("\u00A0", @"\u160?"); //convert \u00A0 to a hard space (\u00A0 shows as a blank in the search text field) rtnVal = rtnVal.Replace("\n", ""); FormatData fmtdata = _MyDocVersion.ActiveFormat.PlantFormat.FormatData; SymbolList sl = fmtdata.SymbolList; if (sl != null) { foreach (Symbol sym in sl) { string rplace = string.Format(sym.Unicode < 256?@"\'{0:X2}" : @"\u{0}", sym.Unicode); rtnVal = rtnVal.Replace(((char)sym.Unicode).ToString(), rplace); } } return rtnVal; } private string GetROsToSearch(ROFSTLookup.rochild[] chld) { string rtnstr =""; if (chld == null) // get a single ROID { ROFSTLookup.rochild ro = (ROFSTLookup.rochild)cmboTreeROs.SelectedNode.Tag; rtnstr += string.Format("{0}", ro.roid); } else { // spin through the child list and get the ROIDs. // if the child has children, then call this function recursivly foreach (ROFSTLookup.rochild roc in chld) { if (roc.children != null) rtnstr += GetROsToSearch(roc.children); else rtnstr += string.Format("{0},", roc.roid); } } return rtnstr; } private void btnSearch_Click(object sender, EventArgs e) { #if DEBUG DateTime start = DateTime.Now; #endif 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; bool includeSpecialChars = true; if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[0]) // Text Search { if (cbxSrchTypeUsage.Checked) // find just the usage of the selected types { if (lstCheckedStepTypes.Count == 0) { MessageBox.Show("Please select one or more types then press the Search button", "No Types Selected"); xpStepTypes.Expanded = true; advTreeStepTypes.Focus(); xpStepTypes.TitleStyle.BackColor1.Color = Color.Crimson; } else { SearchResults = ItemInfoList.GetListFromTextSearch(strSearchText[0], strSearchText[1], "", 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); cmbResultsStyle.SelectedIndex = 3; // display step text in results } } } else if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[1]) // Annotation Search { //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); //UpdateAnnotationSearchResults(); cmbResultsStyle.SelectedIndex = 2; // display annotation text in results } else if (tabSearchTypes.SelectedTab == tabSearchTypes.Tabs[2]) // RO 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); cmbResultsStyle.SelectedIndex = 3; // display step text in results } else { SearchResults = ItemInfoList.GetListFromROSearch(strSearchText[0], strSearchText[1], strSearchText[2]); cmbResultsStyle.SelectedIndex = 3; // display step text in results } } DisplayResults(); if (SearchResults != null && SearchResults.Count == 0) { MessageBox.Show("No Matches Found.", "Search"); } } catch (Exception ex) { while (ex.InnerException != null) ex = ex.InnerException; MessageBox.Show(ex.Message, "Search Error: " + ex.GetType().Name); } finally { Cursor = savcursor; } #if DEBUG MessageBox.Show(string.Format("{0} Milliseconds", TimeSpan.FromTicks(DateTime.Now.Ticks - start.Ticks).TotalMilliseconds)); #endif } private void cbxTextSearchText_Leave(object sender, EventArgs e) { InsertSearchCriteria(); } private void InsertSearchCriteria() { if (!cbxTextSearchText.Text.Equals(string.Empty)) { string tstr = cbxTextSearchText.Text; if (!cbxTextSearchText.Items.Contains(tstr)) cbxTextSearchText.Items.Insert(0, tstr); } } private void cbxSrchTypeUsage_CheckedChanged(object sender, EventArgs e) { gpSrchText.Enabled = !cbxSrchTypeUsage.Checked; if (!cbxSrchTypeUsage.Checked) xpStepTypes.TitleStyle.BackColor1.Color = saveXpStepTypeTitleColor; else { xpStepTypes.Expanded = true; if (lstCheckedStepTypes.Count == 0) xpStepTypes.TitleStyle.BackColor1.Color = Color.Crimson; advTreeStepTypes.Focus(); } } private void rbtnSrchTxt_CheckedChanged(object sender, EventArgs e) { if (rbtnSrchTxt.Checked) cbxTextSearchText.Focus(); } private void gpSrchText_EnabledChanged(object sender, EventArgs e) { if (gpSrchText.Enabled) gpSrchText.Style.BackColor = cbxBooleanTxtSrch.Checked?Color.Orange: Color.Yellow; else gpSrchText.Style.BackColor = saveGpSrchTextColor; } private void tabStepTypeSearch_Click(object sender, EventArgs e) { if (rbtnSrchTxt.Checked) { cbxTextSearchText.Focus(); cbxBooleanTxtSrch_CheckedChanged(sender, e); } } private void ProcessEnterKey(object sender, KeyPressEventArgs e) { if (e.KeyChar == '\r') // enter key pressed { e.Handled = true; btnSearch_Click(sender, e); if (sender == cbxTextSearchText) InsertSearchCriteria(); else InsertAnnotationSearchCriteria(); } } #endregion #region ProcSetSelection private int _MyRODbID; private void advTreeProcSets_AfterCheck(object sender, DevComponents.AdvTree.AdvTreeCellEventArgs e) { DevComponents.AdvTree.Node n = advTreeProcSets.SelectedNode; if (n.Checked) { n.Style = DevComponents.AdvTree.NodeStyles.Apple; lstCheckedDocVersions.Add((DocVersionInfo) n.Tag); if (lstCheckedDocVersions.Count == 1)//Mydocversion == null) { Mydocversion = (DocVersionInfo)n.Tag; advTreeStepTypesFillIn(); } } else { n.Style = null; lstCheckedDocVersions.Remove((DocVersionInfo)n.Tag); if (lstCheckedDocVersions.Count == 1) { if (Mydocversion != lstCheckedDocVersions[0]) { Mydocversion = lstCheckedDocVersions[0]; advTreeStepTypesFillIn(); } } else { if (lstCheckedDocVersions.Count == 0) Mydocversion = null; // do this if either none, or more than one procedure set selected advTreeStepTypes.Nodes.Clear(); lstCheckedStepTypes.Clear(); Node newnode = new DevComponents.AdvTree.Node(); newnode.Text = "....select a procedure set for types to appear..."; advTreeStepTypes.Nodes.Add(newnode); buildStepTypePannelTitle(); } } //// Enable the RO combo list only if at least one procedure set node //// is selected //cmboTreeROs.Enabled = (lstCheckedDocVersions.Count > 0); //gpFindROs.Enabled = cmboTreeROs.Enabled; SetupContextMenu(); buildSetToSearchPanelTitle(); } private void xpSetToSearch_ExpandedChanged(object sender, ExpandedChangeEventArgs e) { buildSetToSearchPanelTitle(); } private void buildSetToSearchPanelTitle() { if (lstCheckedDocVersions.Count == 0) { xpSetToSearch.Expanded = true; xpSetToSearch.TitleStyle.BackColor1.Color = Color.Crimson; btnSearch.Enabled = false; tabSearchTypes.Enabled = false; // disable all the search tabs //if (xpSetToSearch.Expanded) xpSetToSearch.TitleText = "Select Procedure Sets to Search"; //else // xpSetToSearch.TitleText = "Click Here to Select Procedure Sets"; //xpSetToSearch.TitleStyle.BackColor1.Color = saveXpSetToSearchColor; } else //if (lstCheckedDocVersions.Count > 0) { // display the number of selected procedure sets whether pannel is expanded or not xpSetToSearch.TitleText = string.Format("{0} Procedure Sets Selected", lstCheckedDocVersions.Count); xpSetToSearch.TitleStyle.BackColor1.Color = Color.PapayaWhip; btnSearch.Enabled = true; tabSearchTypes.Enabled = true; // enable all the search tabs } } private void advTreeProcSets_AfterNodeSelect(object sender, AdvTreeNodeEventArgs e) { DevComponents.AdvTree.Node n = advTreeProcSets.SelectedNode; if (advTreeStepTypes.Nodes.Count == 1 && n.Checked) { Mydocversion = (DocVersionInfo)n.Tag; advTreeStepTypesFillIn(); } } #endregion #region StepTypeSelection private void advTreeStepTypes_AfterCheck(object sender, DevComponents.AdvTree.AdvTreeCellEventArgs e) { xpStepTypes.TitleStyle.BackColor1.Color = saveXpStepTypeTitleColor; DevComponents.AdvTree.Node n = advTreeStepTypes.SelectedNode; StepData sd = (StepData)n.Tag; if (n.Checked) { n.Style = DevComponents.AdvTree.NodeStyles.Apple; if (sd == null) lstCheckedStepTypes.Add(0); //use zero to identify attachment search else lstCheckedStepTypes.Add((int)sd.Index); } else { n.Style = null; if (sd == null) lstCheckedStepTypes.Remove(0); else lstCheckedStepTypes.Remove((int)sd.Index); } buildStepTypePannelTitle(); } private void xpStepTypes_ExpandedChanged(object sender, ExpandedChangeEventArgs e) { buildStepTypePannelTitle(); } private void buildStepTypePannelTitle() { if (lstCheckedStepTypes.Count == 0) { if (xpStepTypes.Expanded) { xpStepTypes.TitleText = "Select Types To Search"; advTreeStepTypes.Focus(); advTreeStepTypes.Nodes[0].SelectedCell = advTreeStepTypes.Nodes[0].Cells[0]; } else xpStepTypes.TitleText = "Click Here To Search By Types"; xpStepTypes.TitleStyle.BackColor1.Color = saveXpStepTypeTitleColor; } else //lstCheckedStepTypes.Count > 0 { // show how many selected whether pannel is expanded or not xpStepTypes.TitleText = string.Format("{0} Step Styles Selected", lstCheckedStepTypes.Count); xpStepTypes.TitleStyle.BackColor1.Color = Color.PapayaWhip; } } #endregion #region ContextMenu private void btnSym_Click(object sender, EventArgs e) { DevComponents.DotNetBar.ButtonItem b = (DevComponents.DotNetBar.ButtonItem)sender; if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = (string)b.Text; else if (cbxTextSearchText.Focused) cbxTextSearchText.SelectedText = (string)b.Text; } private void cmFndTxtInsHardSp_Click(object sender, EventArgs e) { // We use \u00A0 to represent a hard space because it show in the search text field as a blank // It will get translated to a real hard space character prior to searching if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = "\u00A0"; else if (cbxTextSearchText.Focused) cbxTextSearchText.SelectedText = "\u00A0"; } private void SetupContextMenu() { galSymbols.SubItems.Clear(); if (_MyDocVersion != null) { FormatData fmtdata = _MyDocVersion.ActiveFormat.PlantFormat.FormatData; SymbolList sl = fmtdata.SymbolList; if (sl == null || sl.Count <= 0) { MessageBox.Show("No symbols are available, check with administrator"); return; } foreach (Symbol sym in sl) { DevComponents.DotNetBar.ButtonItem btnCM = new DevComponents.DotNetBar.ButtonItem(); btnCM.Text = string.Format("{0}", (char)sym.Unicode); // to name button use unicode rather than desc, desc may have spaces or odd chars btnCM.Name = "btnCM" + sym.Unicode.ToString(); btnCM.Tooltip = sym.Desc; btnCM.Tag = string.Format(@"{0}", sym.Unicode); btnCM.FontBold = true; btnCM.Click += new System.EventHandler(btnSym_Click); galSymbols.SubItems.Add(btnCM); } } } private void cmFndTxtCut_Click(object sender, EventArgs e) { Clipboard.Clear(); DataObject myDO = new DataObject(DataFormats.Text, cbxTextSearchAnnotation.Focused? cbxTextSearchAnnotation.SelectedText : cbxTextSearchText.SelectedText); Clipboard.SetDataObject(myDO); // Need to check which combo box activated the context menu so that we know where to take/put selected text if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = ""; else if (cbxTextSearchText.Focused) cbxTextSearchText.SelectedText = ""; } private void cmFndTxtCopy_Click(object sender, EventArgs e) { // Need to check which combo box activated the context menu so that we know where to take/put selected text DataObject myDO = new DataObject(DataFormats.Text, cbxTextSearchAnnotation.Focused? cbxTextSearchAnnotation.SelectedText : cbxTextSearchText.SelectedText); if (cbxTextSearchText.Focused || cbxTextSearchAnnotation.Focused) { Clipboard.Clear(); Clipboard.SetDataObject(myDO); } } private void cmFndTxtPaste_Click(object sender, EventArgs e) { // Need to check which combo box activated the context menu so that we know where to take/put selected text IDataObject myDO = Clipboard.GetDataObject(); if (myDO.GetDataPresent(DataFormats.Rtf)) { StepRTB stpRTB = new StepRTB(); stpRTB.SelectedRtf = myDO.GetData(DataFormats.Rtf).ToString(); if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = stpRTB.Text; else if (cbxTextSearchText.Focused) cbxTextSearchText.SelectedText = stpRTB.Text;// .SelectedText;//myDO.GetData(DataFormats.Text,true).ToString(); } else if (myDO.GetDataPresent(DataFormats.Text)) if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = Clipboard.GetText(); else if (cbxTextSearchText.Focused) cbxTextSearchText.SelectedText = Clipboard.GetText();//myDO.GetData(DataFormats.Text).ToString(); } private void btnCMIFindText_PopupOpen(object sender, PopupOpenEventArgs e) { // the context menu is available with just a mouse hover, even if the combo box does not have focus // ... set the focus to which ever combo box initiated the context menu if (tabAnnotationSearch.IsSelected) { if (!cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.Focus(); } else if (tabStepTypeSearch.IsSelected) { if (!cbxTextSearchText.Focused) cbxTextSearchText.Focus(); } } #endregion private void buttonItem2_Click(object sender, EventArgs e) { if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = "*"; else if (cbxTextSearchText.Focused) cbxTextSearchText.SelectedText = "*"; } private void buttonItem3_Click(object sender, EventArgs e) { if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = "?"; else if (cbxTextSearchText.Focused) 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) { gpSrchText.Style.BackColor = Color.Orange; btnCMIFindText.SubItems[1].SubItems[2].Visible = false; btnCMIFindText.SubItems[1].SubItems[3].Visible = true; //cbxCaseSensitive.Checked = false; //cbxCaseSensitive.Enabled = false; //cbxIncROTextSrch.Checked = true; //cbxIncROTextSrch.Enabled = false; cbxCaseSensitive.Enabled = false; cbxIncROTextSrch.Enabled = false; } else { gpSrchText.Style.BackColor = Color.Yellow; btnCMIFindText.SubItems[1].SubItems[2].Visible = true; btnCMIFindText.SubItems[1].SubItems[3].Visible = false; //cbxCaseSensitive.Enabled = true; //cbxIncROTextSrch.Enabled = true; cbxCaseSensitive.Enabled = true; cbxIncROTextSrch.Enabled = true; } } private void cbxBooleanAnoTxtSrch_CheckedChanged(object sender, EventArgs e) { if (cbxBooleanAnoTxtSrch.Checked) { gpSrchAnnoText.Style.BackColor = Color.Orange; btnCMIFindText.SubItems[1].SubItems[2].Visible = false; btnCMIFindText.SubItems[1].SubItems[3].Visible = true; } else { gpSrchAnnoText.Style.BackColor = Color.Yellow; btnCMIFindText.SubItems[1].SubItems[2].Visible = true; btnCMIFindText.SubItems[1].SubItems[3].Visible = false; } } private void btnAND_Click(object sender, EventArgs e) { if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = " AND "; else if (cbxTextSearchText.Focused) cbxTextSearchText.SelectedText = " AND "; } private void btnOR_Click(object sender, EventArgs e) { if (cbxTextSearchAnnotation.Focused) cbxTextSearchAnnotation.SelectedText = " OR "; else if (cbxTextSearchText.Focused) 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); } } #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; } set { _ID = value; } } public AnnotationTypeSearch(string name, string id) { _Name = name; _ID = id; } } #endregion }