/// <summary> /// Add an event to our user space /// </summary> /// <param name="EventTime"></param> /// <param name="Elem"></param> /// <param name="Action"></param> /// <param name="NewValue"></param> /// <param name="OldValue"></param> public void AddEvent(DateTime EventTime, MM_Element Elem, String Action, String OldValue, String NewValue) { if (lvHistory.InvokeRequired) { lvHistory.Invoke(new SafeAddEvent(AddEvent), EventTime, Elem, Action, OldValue, NewValue); } else { lvHistory.Items.Add(new MM_UserInteraction(AssociatedEvent.EventTime = EventTime, Elem, Action, OldValue, NewValue)); lvHistory.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); AssociatedEvent.Text = (Elem.Substation == null ? "" : Elem.Substation.Name + " ") + Elem.ElemType.Name + " " + Name; AssociatedEvent.ViolatedElement.Substation = MM_Repository.Substations[Elem.Substation.Name]; if (PriorEvent) { Data_Integration.UpdateViolation(AssociatedEvent, AssociatedEvent.Text, EventTime); } //else // Data_Integration.RemoveViolation(AssociatedEvent); //AssociatedEvent.ViolatedElement.Substation = MM_Repository.Substations[Station]; //AssociatedEvent.ViolatedElement.Operator = AssociatedEvent.ViolatedElement.Substation.Operator; //AssociatedEvent.ViolatedElement.Owner= AssociatedEvent.ViolatedElement.Substation.Owner; Data_Integration.CheckAddViolation(AssociatedEvent); PriorEvent = true; } }
/// <summary> /// Initialize a new blacstart corridor element /// </summary> /// <param name="xElem"></param> /// <param name="Target"></param> public MM_Blackstart_Corridor_Element(XmlElement xElem, MM_Blackstart_Corridor_Target Target) : base(xElem, false) { this.Blackstart_Target = Target; if (xElem.HasAttribute("Substation")) { this.Substation = MM_Repository.TEIDs[Convert.ToInt32(xElem.Attributes["Substation"].Value)] as MM_Substation; } if (xElem.Name == "Breaker" || xElem.Name == "Switch") { this.AssociatedElement = Integration.Data_Integration.LocateElement(xElem, typeof(MM_Breaker_Switch), true); } else { this.AssociatedElement = Integration.Data_Integration.LocateElement(xElem, Type.GetType("MacomberMapClient.Data_Elements.Physical.MM_" + xElem.Name), true); } if (this.AssociatedElement is MM_Line) { (this.AssociatedElement as MM_Line).IsBlackstart = true; } else { this.AssociatedElement.Substation.IsBlackstart = true; } ElemType = MM_Repository.FindElementType("Blackstart_Corridor"); }
/// <summary> /// Execute the command within its own thread /// </summary> /// <param name="Elem"></param> /// public void Execute(MM_Element Elem) { //Thread.CurrentThread.SetApartmentState(ApartmentState.STA); String InCmd = Command; //Replace the {word} with the values for that element int Bracket = InCmd.IndexOf("{"); while (Bracket > -1) { String InWord = InCmd.Substring(Bracket + 1, InCmd.IndexOf("}", Bracket) - Bracket - 1); Object InValue = null; foreach (MemberInfo mI in Elem.GetType().GetMember(InWord)) { if (mI is FieldInfo) { InValue = (mI as FieldInfo).GetValue(Elem); } else if (mI is PropertyInfo) { InValue = (mI as PropertyInfo).GetValue(Elem, null); } } InCmd = InCmd.Substring(0, Bracket) + InValue.ToString() + InCmd.Substring(InCmd.IndexOf('}', Bracket) + 1); Bracket = InCmd.IndexOf("{"); } //Now, send our command if appropriate if (MM_Server_Interface.SendCommand(InCmd, "") == CheckState.Unchecked) { MessageBox.Show("Unable to send command. Please retry.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Create a new violation /// </summary> /// <param name="ViolatedElement"></param> /// <param name="ViolText"></param> /// <param name="ViolType"></param> /// <param name="EventTime"></param> /// <param name="New"></param> /// <param name="ViolatedCtg"></param> /// <param name="PostCtgValue"></param> /// <param name="PreCtgValue"></param> /// <returns></returns> public static MM_AlarmViolation CreateViolation(MM_Element ViolatedElement, string ViolText, MM_AlarmViolation_Type ViolType, DateTime EventTime, bool New, MM_Contingency ViolatedCtg, float PreCtgValue, float PostCtgValue) { MM_AlarmViolation NewViol = new MM_AlarmViolation(); NewViol.TEID = Integration.Data_Integration.GetTEID(); NewViol.ViolatedElement = ViolatedElement; if (ViolatedElement is MM_Transformer) { NewViol.KVLevel = (ViolatedElement as MM_Transformer).Winding1.KVLevel; } else { NewViol.KVLevel = ViolatedElement.KVLevel; } NewViol.ElemType = ViolatedElement.ElemType; NewViol.Owner = ViolatedElement.Owner; NewViol.Operator = ViolatedElement.Operator; NewViol.Contingency = ViolatedCtg; NewViol.New = New; NewViol.Text = ViolText; NewViol.Type = ViolType; NewViol.EventTime = EventTime; NewViol.PreCtgValue = PreCtgValue; NewViol.PostCtgValue = PostCtgValue; return(NewViol); }
/// <summary> /// Handle the right-click event on a cell /// </summary> /// <param name="e"></param> protected override void OnCellMouseClick(DataGridViewCellMouseEventArgs e) { if (e.RowIndex == -1 || e.ColumnIndex == -1) { return; } MM_Element Elem = Rows[e.RowIndex].Cells["TEID"].Value as MM_Element; SettingDataSource = true; this.CurrentCell = Rows[e.RowIndex].Cells[e.ColumnIndex]; if (MM_Server_Interface.Client != null) { AssociatedPropertyPage.SetElement(Elem); } SettingDataSource = false; if (e.Button == MouseButtons.Right) { RightClickMenu.Show(this, e.Location, Elem, true); } base.OnCellMouseClick(e); if (e.Button == MouseButtons.Left) { FindForm().Refresh(); } }
/// <summary> /// Initialize the note writer /// </summary> public MM_Note_Writer(MM_Element BaseElement) { InitializeComponent(); this.BaseElement = BaseElement; this.Text = " Note: " + BaseElement.ElemType.Name + " " + BaseElement.Name; txtAuthor.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name; txtNote.Focus(); }
/// <summary> /// Handle our click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridView_CellClick(object sender, DataGridViewCellMouseEventArgs e) { DataGridView Sender = (DataGridView)sender; if (e.RowIndex == -1) { return; } MM_Element SelectedObject = (MM_Element)Sender.Rows[e.RowIndex].DataBoundItem.GetType().GetProperties()[0].GetValue(Sender.Rows[e.RowIndex].DataBoundItem); MM_Element HighlightElement = SelectedObject is MM_Substation ? null : SelectedObject; if (SelectedObject is MM_Line) { SelectedObject = SelectedObject.Contingencies[0]; } else if (SelectedObject.Substation != null) { SelectedObject = SelectedObject.Substation; } Sender.UseWaitCursor = true; if (SelectedObject == olView.BaseElement) { olView.HighlightElement(HighlightElement); } else if (olView.DataSource == null) { olView.SetControls(SelectedObject, nMap, BaseData, null, Data_Integration.NetworkSource); olView.HighlightElement(HighlightElement); } else { olView.LoadOneLine(SelectedObject, HighlightElement); olView.HighlightElement(HighlightElement); } if (HighlightElement is MM_Unit) { if (HighlightElement != null && HighlightElement.ElemType.Configuration != null && HighlightElement.ElemType.Configuration["ControlPanel"] != null) { if (MM_Server_Interface.ClientAreas.ContainsKey("ERCOT") || MM_Server_Interface.ClientAreas.ContainsKey(HighlightElement.Operator.Alias)) { MM_OneLine_Element Unit = olView.ElementsByTEID[HighlightElement.TEID]; new OneLines.MM_ControlPanel(Unit, HighlightElement.ElemType.Configuration["ControlPanel"], olView) { StartPosition = FormStartPosition.Manual, Location = Cursor.Position }.Show(this); } else { MessageBox.Show("Control of " + (olView.BaseElement.Substation == null ? "" : olView.BaseElement.Substation.LongName) + " " + olView.BaseElement.ElemType.Name + " " + olView.BaseElement.Name + " is not permitted.\n(operated by " + olView.BaseElement.Operator.Name + " - " + olView.BaseElement.Operator.Alias + ").", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop); } } } Sender.UseWaitCursor = false; Sender.Invalidate(); }
/// <summary> /// Attempt to locate an element by its TEID /// </summary> /// <param name="TEID"></param> /// <returns></returns> public static MM_Element LocateElement(object TEID) { if (TEID is DBNull) { return(null); } MM_Element FoundElem = null; TEIDs.TryGetValue(Convert.ToInt32(TEID), out FoundElem); return(FoundElem); }
/// <summary> /// Add an event without updating the core system (just paste in display) /// </summary> /// <param name="EventTime"></param> /// <param name="Elem"></param> /// <param name="Action"></param> /// <param name="OldValue"></param> /// <param name="NewValue"></param> public void AddEventWithoutNotification(DateTime EventTime, MM_Element Elem, String Action, String OldValue, String NewValue) { if (lvHistory.InvokeRequired) { lvHistory.Invoke(new SafeAddEvent(AddEvent), EventTime, Elem, Action, OldValue, NewValue); } else { lvHistory.Items.Add(new MM_UserInteraction(AssociatedEvent.EventTime = EventTime, Elem, Action, OldValue, NewValue)); } }
/// <summary> /// Select an element after updating our search form /// </summary> /// <param name="SelectedElement"></param> public void SelectElement(MM_Element SelectedElement) { if (InvokeRequired) { BeginInvoke(new MM_Search_Results.ItemSelectionDelegate(SelectElement), SelectedElement); } else { srMain.SearchText = SelectedElement.TEID.ToString(); srMain.PerformSearch(false, false); } }
/// <summary> /// Dispose of the data set base /// </summary> public void Dispose() { foreach (DataTable tbl in Data.Tables) { tbl.Clear(); tbl.Dispose(); } Data.Tables.Clear(); Data.Dispose(); BaseElement = null; ElementsByTEID.Clear(); }
/// <summary> /// Create a new note, and if selected, upload it. /// </summary> /// <param name="NoteElement">The element about which the note is being written</param> public static void CreateNote(MM_Element NoteElement) { using (MM_Note_Writer NewNote = new MM_Note_Writer(NoteElement)) if (NewNote.ShowDialog() == DialogResult.OK) { MM_Note OutNote = NewNote.CreatedNote; if (MM_Server_Interface.Client != null) { OutNote.ID = MM_Server_Interface.Client.UploadNote(OutNote); } Data_Integration.HandleNoteEntry(OutNote); } }
/// <summary> /// Assign the controls to the one-line viewer /// </summary> /// <param name="BaseElement">The base element, from which the Data Integration layer should query for parameters</param> /// <param name="nMap">The network map</param> /// <param name="BaseData">The base data</param> /// <param name="ViolViewer">The violation viewer associated with the one-line</param> /// <param name="DataSource">The active data source</param> public void SetControls(MM_Element BaseElement, MM_Network_Map_DX nMap, MM_DataSet_Base BaseData, MM_Violation_Viewer ViolViewer, MM_Data_Source DataSource) { //Assign our data connectors this.DataSource = DataSource; this.BaseData = BaseData; this.nMap = nMap; this.ViolViewer = ViolViewer; LoadOneLine(BaseElement, null); //Assign our events tsMain.ItemClicked += new ToolStripItemClickedEventHandler(tsMain_ItemClicked); btnSwapDetails.Visible = this.Parent is SplitterPanel; }
/// <summary> /// Handle a value change of our element /// </summary> /// <param name="Element"></param> /// <param name="Property"></param> private void BaseElement_ValuesChanged(MM_Element Element, String Property) { if (PropertyChanged != null && OwningControl != null && OwningControl.Visible) { if (OwningControl.InvokeRequired) { OwningControl.BeginInvoke(new MM_Element.ValuesChangedDelegate(BaseElement_ValuesChanged), Element); } else { PropertyChanged(this, new PropertyChangedEventArgs(Property)); } } }
/// <summary> /// Update with our new violation viewer, and set everything up. /// </summary> /// <param name="ViolViewer">The violation viewer</param> public void SetViolationViews(MM_Violation_Viewer ViolViewer) { this.violView = ViolViewer; foreach (ListViewItem l in this.lvSearch.Items) { MM_Element Elem = l.Tag as MM_Element; //If we have a violation, let's add it in. MM_AlarmViolation_Type WorstViol = Elem.WorstVisibleViolation(violView.ShownViolations, this.Parent); if (WorstViol != null) { l.ImageIndex = WorstViol.ViolationIndex; } } }
/// <summary> /// Check to see whether an element meets the inclusion criteria /// </summary> /// <param name="Elem">The element to be checked </param> /// <param name="KVLevel">The KV Level to be used</param> /// <param name="ElemType">The Element type to be used</param> /// <param name="Words">The words to search for</param> /// <param name="ElementWords">The collection of words for an element, for testing</param> /// <returns>True if the element passes all criteria</returns> /// private bool CheckElement(MM_Element Elem, MM_KVLevel KVLevel, MM_Element_Type ElemType, List <String> Words, Dictionary <String, bool> ElementWords) { if ((KVLevel != null) && (Elem.KVLevel != KVLevel)) { return(false); } else if (ElemType != null) { if (ElemType.Name == "SeriesCompensator" && Elem is MM_Line && (Elem as MM_Line).IsSeriesCompensator) { } else if (Elem.ElemType != ElemType) { return(false); } } //Now build up our collection of words for this element BuildWords(Elem, ElementWords); //Now if we have any words, let's test them against this element. If all pass, then we're ok. //If a substation, check both name and long name foreach (String Word in Words) { if (Word.IndexOfAny(new char[] { '?', '*' }) == -1) { if (!ElementWords.ContainsKey(Word)) { return(false); } } else { Regex TestReg = new Regex("^" + Regex.Escape(Word).Replace("\\*", ".*").Replace("\\?", ".") + "$", RegexOptions.IgnoreCase); bool FoundMatch = false; foreach (String str in ElementWords.Keys) { if (!FoundMatch && TestReg.IsMatch(str)) { FoundMatch = true; } } if (!FoundMatch) { return(false); } } } return(true); }
/// <summary> /// Report a user interaction /// </summary> /// <param name="EventTime"></param>' /// <param name="Elem"></param> /// <param name="Action"></param> /// <param name="OldValue"></param> /// <param name="NewValue"></param> public MM_UserInteraction(DateTime EventTime, MM_Element Elem, String Action, String OldValue, String NewValue) { this.EventTime = EventTime; this.Elem = Elem; this.Action = Action; this.OldValue = OldValue; this.NewValue = NewValue; this.Text = EventTime.ToString(MILITARY_TIME_FORMAT); SubItems.Add(Elem.Substation == null ? "" : Elem.Substation.Name); SubItems.Add(Elem.ElemType.Name); SubItems.Add(Elem.Name); SubItems.Add(Action); SubItems.Add(OldValue); SubItems.Add(NewValue); }
/// <summary> /// Handle the right-click option on a note /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lvNotes_MouseClick(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right) { return; } ListViewHitTestInfo ht = lvNotes.HitTest(e.Location); if (ht.Item != null && ht.Item.Tag is MM_Note && (ht.Item.Tag as MM_Note).AssociatedElement != 0) { MM_Element AsssociatedElement = MM_Repository.TEIDs[(ht.Item.Tag as MM_Note).AssociatedElement]; RightClickMenu.Show(this, e.Location, AsssociatedElement, true); } }
/// <summary> /// Handle the modification of a note /// </summary> /// <param name="Note">The note to be handled</param> private void NoteModified(MM_Note Note) { if (InvokeRequired) { Invoke(new SafeNoteHandler(NoteModified), Note); } else { ListViewItem FoundItem = lvNotes.Items[Note.ID.ToString()]; FoundItem.SubItems[0].Text = "*"; FoundItem.SubItems[1].Text = Note.CreatedOn.ToString(); MM_Element AssociatedElement = MM_Repository.TEIDs[Note.AssociatedElement]; FoundItem.SubItems[2].Text = AssociatedElement.ElemType.Name; FoundItem.SubItems[3].Text = Note.Author; FoundItem.SubItems[4].Text = Note.Note; } }
/// <summary> /// Add an element to our collection list /// </summary> /// <param name="Title"></param> /// <param name="Elem"></param> private void AddElement(String Title, MM_Element Elem) { foreach (String Word in Title.Split(new char[] { ' ', '(', ')', '_', '#', '.' }, StringSplitOptions.RemoveEmptyEntries)) //When changing split chars, they need to be added to the series in UpdateSearchText too probably. { if (!String.IsNullOrEmpty(Word)) { if (!Elements.ContainsKey(Word)) { Elements.Add(Word, new MM_Element[] { Elem }); } else if (!Elements[Word].Contains(Elem)) { List <MM_Element> Elems = new List <MM_Element>(Elements[Word]); Elems.Add(Elem); Elements[Word] = Elems.ToArray(); } } } }
/// <summary> /// Handle our click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridView_CellClick(object sender, DataGridViewCellMouseEventArgs e) { DataGridView Sender = (DataGridView)sender; if (e.RowIndex == -1) { return; } MM_Element HighlightElement = (MM_Element)Sender.Rows[e.RowIndex].DataBoundItem.GetType().GetProperties()[0].GetValue(Sender.Rows[e.RowIndex].DataBoundItem); Sender.UseWaitCursor = true; if (HighlightElement != null && HighlightElement.ElemType.Configuration != null && HighlightElement.ElemType.Configuration["ControlPanel"] != null) { olView.LoadOneLine(HighlightElement.Substation, HighlightElement); //olView.BaseElement = HighlightElement; //olView.HighlightElement(HighlightElement); if (MM_Server_Interface.ClientAreas.ContainsKey("ERCOT") || MM_Server_Interface.ClientAreas.ContainsKey(HighlightElement.Operator.Alias)) { if (olView.ElementsByTEID.Count > 0) { MM_OneLine_Element Unit = olView.ElementsByTEID[HighlightElement.TEID]; new OneLines.MM_ControlPanel(Unit, HighlightElement.ElemType.Configuration["ControlPanel"], olView) { StartPosition = FormStartPosition.Manual, Location = Cursor.Position }.Show(this); } else { MessageBox.Show("unable to open Control Panel for " + (olView.BaseElement.Substation == null ? "" : olView.BaseElement.Substation.LongName) + " " + olView.BaseElement.ElemType.Name + " " + olView.BaseElement.Name + ".", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop); } } else { MessageBox.Show("Control of " + (olView.BaseElement.Substation == null ? "" : olView.BaseElement.Substation.LongName) + " " + olView.BaseElement.ElemType.Name + " " + olView.BaseElement.Name + " is not permitted.\n(operated by " + olView.BaseElement.Operator.Name + " - " + olView.BaseElement.Operator.Alias + ").", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop); } } Sender.UseWaitCursor = false; Sender.Invalidate(); }
/// <summary> /// Update our DC Tie data /// </summary> /// <param name="TieData"></param> public void UpdateTieData(MM_Tie_Data[] TieData) { MM_Tie FoundTie; MM_Element el = null; foreach (MM_Tie_Data TieDatum in TieData) { if (MM_Repository.Ties.TryGetValue(TieDatum.ID_TIE, out FoundTie)) { MM_Server_Interface.UpdateTieData(TieDatum, FoundTie, true); } else if (MM_Repository.TEIDs.TryGetValue(TieDatum.TEID_TIE, out el)) { MM_Server_Interface.UpdateTieData(TieDatum, el as MM_Tie, true); } } if (TieData.Length > 0) { MM_Server_Interface.UpdateTimestamp(typeof(MM_Tie_Data)); } }
/// <summary> /// Highlight a one-line element /// </summary> /// <param name="HighlightElem"></param> public void HighlightElement(MM_Element HighlightElem) { if (HighlightElem == null) { HighlightedElement = null; } else if (!ElementsByTEID.TryGetValue(HighlightElem.TEID, out HighlightedElement)) { HighlightedElement = null; } else if (!Rectangle.FromLTRB(-pnlElements.AutoScrollPosition.X, -pnlElements.AutoScrollPosition.Y, pnlElements.DisplayRectangle.Width, pnlElements.DisplayRectangle.Height).IntersectsWith(HighlightedElement.Bounds)) { Control ctl = new Control() { Bounds = HighlightedElement.Bounds }; pnlElements.Controls.Add(ctl); pnlElements.ScrollControlIntoView(ctl); pnlElements.Controls.Remove(ctl); } }
/// <summary> /// Initialize our coordinate suggestion /// </summary> /// <param name="BaseElement"></param> /// <param name="Coordinates"></param> public MM_Coordinate_Suggestion(MM_Element BaseElement, MM_Coordinates Coordinates) { this.BaseElement = BaseElement; if (BaseSubstation != null) { OriginalCoordinates = new PointF[] { BaseSubstation.LngLat }; SuggestedCoordinates = new PointF[] { BaseSubstation.LngLat }; SuggestedCoordinatesXY = new Point[] { MM_Coordinates.LngLatToXY(BaseSubstation.LngLat, Coordinates.ZoomLevel) }; } else if (BaseLine != null) { OriginalCoordinates = (PointF[])BaseLine.Coordinates.ToArray(); SuggestedCoordinates = BaseLine.Coordinates.ToArray(); List <Point> InflectionPoints = new List <Point>(); foreach (PointF pt in SuggestedCoordinates) { InflectionPoints.Add(MM_Coordinates.LngLatToXY(pt, Coordinates.ZoomLevel)); } SuggestedCoordinatesXY = InflectionPoints.ToArray(); } }
/// <summary> /// Handle an element value change /// </summary> /// <param name="Element"></param> /// <param name="Property"></param> private void ElemValueChange(MM_Element Element, string Property) { ValueChanges.Remove(Element); /* MM_OneLine_Element FoundElem; * if (DisplayElements.TryGetValue(Element, out FoundElem)) * { * pnlElements.Invalidate(FoundElem.Bounds); * if (FoundElem.Descriptor != null) * pnlElements.Invalidate(FoundElem.Descriptor.Bounds); * } * * MM_OneLine_Node FoundNode; * if (DisplayNodes.TryGetValue(Element, out FoundNode)) * { * if (FoundNode.Descriptor != null) * pnlElements.Invalidate(FoundNode.Descriptor.Bounds); * foreach (MM_OneLine_Node[] NodeTargets in FoundNode.NodeTargets.Values) * foreach (MM_OneLine_Node NodeTarget in NodeTargets) * if (NodeTarget.Descriptor != null) * pnlElements.Invalidate(NodeTarget.Descriptor.Bounds); * }*/ }
/// <summary> /// Handle the row post-paint, in order to show violations when they occur. /// </summary> /// <param name="e"></param> protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) { try { MM_Element ThisElem = (Rows[e.RowIndex].Cells["TEID"].Value as MM_Element); if (ThisElem == null) { return; } MM_AlarmViolation_Type ViolType = ThisElem.WorstVisibleViolation(violView.ShownViolations, this.Parent); if (ViolType != null) { e.Graphics.DrawImage(MM_Repository.ViolationImages.Images[ViolType.ViolationIndex], new Rectangle(e.RowBounds.Location, new Size(this.RowHeadersWidth, e.RowBounds.Height))); } else if (ThisElem.FindNotes().Length > 0) { e.Graphics.DrawImage(MM_Repository.ViolationImages.Images["Note"], new Rectangle(e.RowBounds.Location, new Size(this.RowHeadersWidth, e.RowBounds.Height))); } base.OnRowPostPaint(e); } catch (Exception) { } }
/// <summary> /// Update the status of our element /// </summary> /// <param name="SelectedElement"></param> public void UpdateElement(MM_Element SelectedElement) { //Show our element in our selection list lblElementValue.Text = SelectedElement.ToString(); if (SelectedElement is MM_Substation) { MM_Substation BaseSubstation = SelectedElement as MM_Substation; txtSubLatitude.Visible = txtSubLongitude.Visible = true; txtSubLongitude.Text = BaseSubstation.Longitude.ToString(); txtSubLatitude.Text = BaseSubstation.Latitude.ToString(); dgvLineLngLat.Visible = false; } else { MM_Line BaseLine = SelectedElement as MM_Line; txtSubLatitude.Visible = txtSubLongitude.Visible = false; dgvLineLngLat.Visible = true; LineCoordinates.Rows.Clear(); for (int a = 0; a < BaseLine.Coordinates.Count; a++) { LineCoordinates.Rows.Add(a, BaseLine.Coordinates[a].Y, BaseLine.Coordinates[a].X); } } }
/// <summary> /// Initialize a new bound element /// </summary> /// <param name="BaseElement"></param> /// <param name="OwningControl"></param> public MM_Bound_Element(MM_Element BaseElement, Control OwningControl) { this.OwningControl = OwningControl; this.BaseElement = BaseElement; //this.BaseElement.ValuesChanged += BaseElement_ValuesChanged; }
/// <summary> /// Asssign controls to the summary viewer /// </summary> /// <param name="BaseData">The base data for the display</param> public void SetControls(MM_DataSet_Base BaseData) { if (this.InvokeRequired) { this.BeginInvoke(new SafeSetControls(SetControls), BaseData); } else { //Assign our base table and integration layer this.BaseData = BaseData; //Go through the data tables, and tally up both total and by KV level into the columns this.Items.Clear(); foreach (DataTable dt in BaseData.Data.Tables) { if (dt.Rows.Count > 0) { ListViewItem ElementRow = this.Items.Add(dt.TableName); ElementRow.UseItemStyleForSubItems = false; ElementRow.SubItems.Add(dt.Rows.Count.ToString("#,##0")).ForeColor = Color.White; ElementRow.Tag = dt; Dictionary <MM_KVLevel, int> KVLevels = new Dictionary <MM_KVLevel, int>(MM_Repository.KVLevels.Count); foreach (MM_KVLevel KVLevel in MM_Repository.KVLevels.Values) { if (KVLevel.Permitted) { KVLevels.Add(KVLevel, 0); } } foreach (DataRow dr in dt.Rows) { MM_Element Elem = dr["TEID"] as MM_Element; if (Elem is MM_Substation) { foreach (MM_KVLevel KVLevel in (Elem as MM_Substation).KVLevels) { if (KVLevel.Permitted) { KVLevels[KVLevel]++; } } } else if (Elem is MM_Transformer) { foreach (MM_TransformerWinding Winding in (Elem as MM_Transformer).Windings) { if (Winding.KVLevel != null && Winding.KVLevel.Permitted) { KVLevels[Winding.KVLevel]++; } } } else if (Elem.KVLevel != null) { KVLevels[Elem.KVLevel]++; } } foreach (KeyValuePair <MM_KVLevel, int> KVLevel in KVLevels) { if (KVLevel.Value == 0) { ElementRow.SubItems.Add("").Tag = KVLevel; } else { ListViewItem.ListViewSubItem SubItem = ElementRow.SubItems.Add(KVLevel.Value.ToString("#,##0")); SubItem.ForeColor = KVLevel.Key.Energized.ForeColor; SubItem.Tag = KVLevel; } } } } this.Sorting = SortOrder.Ascending; this.Sort(); MM_Repository.ViewChanged += new MM_Repository.ViewChangedDelegate(MM_Repository_ViewChanged); } }
/// <summary> /// Determine whether a command applies to a particular element /// </summary> /// <param name="BaseElement"></param> /// <returns></returns> public bool Validate(MM_Element BaseElement) { return(ConnectorType == typeof(MM_Server_Interface) && MM_Server_Interface.Client != null); }