/// <summary> /// Process the command /// </summary> /// <param name="InLine"></param> private static void ProcessCommand(String[] InLine) { MM_Element Element = null; if (InLine.Length == 3) { if (InLine[1].Equals("Substation", StringComparison.CurrentCultureIgnoreCase)) { MM_Substation FoundSub; if (MM_Repository.Substations.TryGetValue(InLine[2], out FoundSub)) { Element = FoundSub; } else { foreach (MM_Substation Sub in MM_Repository.Substations.Values) { if (Sub.LongName.Equals(InLine[2], StringComparison.CurrentCultureIgnoreCase)) { Element = Sub; break; } } } } else if (InLine[1].Equals("Line", StringComparison.CurrentCultureIgnoreCase)) { Element = MM_Repository.Lines[InLine[2]]; } else if (InLine[1].Equals("Contingency", StringComparison.CurrentCultureIgnoreCase)) { Element = MM_Repository.Contingencies[InLine[2]]; } else { Element = MM_Repository.LocateElement(InLine[2].Split('.')[0], InLine[2].Split('.')[1], InLine[1], ""); } } else if (InLine.Length == 2) { Int32 TryNum; if (!Int32.TryParse(InLine[1], out TryNum) || !MM_Repository.TEIDs.TryGetValue(TryNum, out Element)) { return; } } if (InLine[0].Equals("Search", StringComparison.CurrentCultureIgnoreCase)) { MM_Form_Builder.SearchDisplay(Map.ctlNetworkMap, InLine[1], false, false); } else if (InLine[0].Equals("Message", StringComparison.CurrentCultureIgnoreCase)) { MM_System_Interfaces.MessageBox("Message received: " + String.Join(" ", InLine, 1, InLine.Length - 1), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (InLine[0].Equals("Zoom", StringComparison.CurrentCultureIgnoreCase)) { if (Element is MM_AlarmViolation) { Element = (Element as MM_AlarmViolation).ViolatedElement; } if (Element is MM_Substation) { Map.ctlNetworkMap.Coordinates.Center = ((Element as MM_Substation).LngLat); Map.ctlNetworkMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); } else if (Element is MM_Line) { Map.ctlNetworkMap.Coordinates.Center = (((Element as MM_Line).Midpoint)); Map.ctlNetworkMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); } else if (Element.Substation != null) { Map.ctlNetworkMap.Coordinates.Center = (Element.Substation.LngLat); Map.ctlNetworkMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); } } else if (InLine[0].Equals("Property", StringComparison.CurrentCultureIgnoreCase)) { MM_Form_Builder.PropertyPage(Element, Map.ctlNetworkMap); } else if (InLine[0].Equals("OneLine", StringComparison.CurrentCultureIgnoreCase)) { MM_Form_Builder.OneLine_Display(Element, Map.ctlNetworkMap); } }
/// <summary> /// Perform the actual searching /// </summary> /// <param name="ControlPressed">Whether to return just substations with one item</param> /// <param name="AltPressed">Whether alt is pressed</param> /// <returns>True if a succesful match has been found</returns> public bool PerformSearch(bool ControlPressed, bool AltPressed) { picAbort.Visible = true; BaseData.Data.Tables.Clear(); this.lvSearch.Items.Clear(); this.Cursor = Cursors.WaitCursor; //First, see if the string is a TEID, and if so, just popup the property page. Int32 TEIDTest = 0; MM_Element FoundElem; if (ItemSelectionChanged == null && Int32.TryParse(SearchText.Trim(), out TEIDTest)) { if (MM_Repository.TEIDs.TryGetValue(TEIDTest, out FoundElem)) { if (ControlPressed) { if (FoundElem is MM_Substation) { nMap.Coordinates.Center = ((FoundElem as MM_Substation).LngLat); } else if (FoundElem is MM_Line) { nMap.Coordinates.Center = ((FoundElem as MM_Line).Midpoint); } else if (FoundElem.Substation != null) { nMap.Coordinates.Center = (FoundElem.Substation.LngLat); } else { MM_Form_Builder.PropertyPage(MM_Repository.TEIDs[TEIDTest], nMap); return(false); } nMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); } else { MM_Form_Builder.PropertyPage(MM_Repository.TEIDs[TEIDTest], nMap); } return(false); } else { return(FailError("Unable to find TEID #" + TEIDTest.ToString() + "!")); } } //Split apart the string List <String> Words = new List <string>(); //Define the parameters we might be looking for. MM_KVLevel KVLevel = null; MM_Element_Type ElemType = null; if (ItemSelectionChanged != null && int.TryParse(SearchText, out TEIDTest) && MM_Repository.TEIDs.TryGetValue(TEIDTest, out FoundElem)) { AddElement(FoundElem); } //Go through each word, and test it. foreach (String Word in SearchText.Split(new char[] { ' ', '\t', '_' }, StringSplitOptions.RemoveEmptyEntries)) { Object FoundWord = FindWord(Word); if (FoundWord == null) { Words.Add(Word); } else if (FoundWord is MM_KVLevel) { if (KVLevel != null) { return(FailError("Please only specify one KV Level in the search query.\nFound " + KVLevel.Name + " and " + (FoundWord as MM_KVLevel).Name)); } else { KVLevel = FoundWord as MM_KVLevel; } } else if (FoundWord is MM_Element_Type) { if (ElemType != null) { return(FailError("Please only specify one element type in the search query.\nFound " + ElemType.Name + " and " + (FoundWord as MM_Element_Type).Name)); } else { ElemType = FoundWord as MM_Element_Type; } } } //If we're doing a control, add 'substation' if (ElemType == null && (ControlPressed || AltPressed)) { ElemType = MM_Repository.FindElementType("Substation"); } //Now go through all elements, searching for results Dictionary <String, bool> ElementWords = new Dictionary <string, bool>(StringComparer.CurrentCultureIgnoreCase); //int tempref = 0; /////nataros this is for a catch test, to remove later foreach (MM_Element Elem in new List <MM_Element>(MM_Repository.TEIDs.Values)) { if (Elem.Name != null && Elem.TEID > 0) { if (Elem is MM_Blackstart_Corridor_Element == false) { if (Elem.Permitted && CheckElement(Elem, KVLevel, ElemType, Words, ElementWords) && Elem.ElemType != null) { AddElement(Elem); } if (AbortSearch) { AbortSearch = false; return(lvSearch.Items.Count > 0); } } else { //catch test, to remove this else case later, needed break pt and counter for test - nataros //tempref = tempref++; } } } this.lvSearch.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); this.Cursor = Cursors.Default; if (viewSummary != null) { viewSummary.SetControls(BaseData); } picAbort.Visible = false; if (lvSearch.Items.Count == 0) { return(FailError("No results found for: " + this.SearchText)); } else if (ControlPressed) { MM_Element SelectedElement = null; bool OnlyOneElement = lvSearch.Items.Count == 1; if (lvSearch.Items.Count == 1) { SelectedElement = lvSearch.Items[0].Tag as MM_Element; } else { foreach (ListViewItem lvi in lvSearch.Items) { if ((lvi.Tag as MM_Element).Name.Equals(SearchText.Trim(), StringComparison.CurrentCultureIgnoreCase)) { if (SelectedElement != null) { OnlyOneElement = false; } else if (SelectedElement == null) { SelectedElement = lvi.Tag as MM_Element; OnlyOneElement = true; } } } } if (OnlyOneElement) { if (SelectedElement is MM_Substation) { nMap.Coordinates.Center = ((SelectedElement as MM_Substation).LngLat); nMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); nMap.Coordinates.Center = ((SelectedElement as MM_Substation).LngLat); } else if (SelectedElement is MM_Line) { nMap.Coordinates.Center = (((SelectedElement as MM_Line).Midpoint)); nMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); nMap.Coordinates.Center = (((SelectedElement as MM_Line).Midpoint)); } else if (SelectedElement.Substation != null) { nMap.Coordinates.Center = (SelectedElement.Substation.LngLat); nMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); nMap.Coordinates.Center = (SelectedElement.Substation.LngLat); } return(false); } } else if (AltPressed) { MM_Element SelectedElement = null; bool OnlyOneElement = lvSearch.Items.Count == 1; if (lvSearch.Items.Count == 1) { SelectedElement = lvSearch.Items[0].Tag as MM_Element; } else { foreach (ListViewItem lvi in lvSearch.Items) { if ((lvi.Tag as MM_Element).Name.Equals(SearchText.Trim(), StringComparison.CurrentCultureIgnoreCase)) { if (SelectedElement != null) { OnlyOneElement = false; } else if (SelectedElement == null) { SelectedElement = lvi.Tag as MM_Element; OnlyOneElement = true; } } } } if (Data_Integration.Permissions.ShowOneLines == true && OnlyOneElement) { if (SelectedElement is MM_Substation) { MM_Form_Builder.OneLine_Display(SelectedElement, nMap); } else if (SelectedElement is MM_Line) { MM_Form_Builder.OneLine_Display(SelectedElement, nMap); } else if (SelectedElement.Substation != null) { MM_Form_Builder.OneLine_Display(SelectedElement.Substation, nMap); } return(false); } } //If we have results, select them if (ItemSelectionChanged != null && lvSearch.Items.Count > 0) { lvSearch.Items[0].Selected = true; } return(true); }