public GXGraphItemForm(GXGraphItemCollection items, List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > columns, GXDLMSDevice device) { InitializeComponent(); GraphItemEditor_SizeChanged(null, null); GraphItemList.OwnerDraw = true; Items = items; int pos = 0; List <string> colors = GetColors(); GXManufacturer man = device.Manufacturers.FindByIdentification(device.Manufacturer); foreach (var it in columns) { GXDLMSObject obj = it.Key; int index = it.Value.AttributeIndex; if (!GXHelpers.IsNumeric(obj.GetDataType(index)) || (index > 0 && ((index & 0x8) != 0 || (index & 0x10) != 0))) { continue; } GXGraphItem item = items.Find(obj.LogicalName, index); if (item == null) { item = new GXGraphItem(); item.LogicalName = obj.LogicalName; item.Color = Color.FromName(colors[pos++]); item.AttributeIndex = index; items.Add(item); } string desc = obj.Description; GXObisCode code = man.ObisCodes.FindByLN(obj.ObjectType, obj.LogicalName, null); if (code != null) { desc = code.Description; } ListViewItem tmp = GraphItemList.Items.Add(obj.LogicalName + " " + desc); tmp.Tag = item; } }
void OnUpdateTarget(GXDLMSObject value) { m_Target = (GXDLMSProfileGeneric)value; m_MyPane.GraphPane.CurveList.Clear(); GXDLMSObject obj; int index = 0; if (m_Target != null) { m_MyPane.GraphPane.Title.Text = m_Target.Description; DataTable table = ProfileGenericView.DataSource as DataTable; ProfileGenericView.DataSource = null; ProfileGenericView.Columns.Clear(); DataTable dt = new DataTable(); foreach (var it in m_Target.CaptureObjects) { DataColumn dc = dt.Columns.Add(index.ToString()); dc.Caption = it.Key.Description; int pos = ProfileGenericView.Columns.Add(index.ToString(), it.Key.Description); ProfileGenericView.Columns[pos].DataPropertyName = index.ToString(); ++index; } foreach (object[] it in m_Target.Buffer) { dt.LoadDataRow(it, true); } ProfileGenericView.DataSource = dt; if (m_Target.CaptureObjects.Count != 0 && m_Target.CaptureObjects[0].Value.AttributeIndex != 0) { //We can show graph only tables that are date based. if (m_Target.CaptureObjects[0].Key.GetUIDataType(m_Target.CaptureObjects[0].Value.AttributeIndex) == DataType.DateTime) { for (int col = 0; col < m_Target.CaptureObjects.Count; ++col) { //Do not shown Status' or Events index = m_Target.CaptureObjects[col].Value.AttributeIndex; if (index > 0 && ((index & 0x8) != 0 || (m_Target.CaptureObjects[col].Value.AttributeIndex & 0x10) != 0)) { continue; } obj = m_Target.CaptureObjects[col].Key; GXGraphItem item = GraphItems.Find(obj.LogicalName, index); if (item != null && item.Enabled && GXHelpers.IsNumeric(obj.GetUIDataType(index))) { ZedGraph.DataSourcePointList dspl = new ZedGraph.DataSourcePointList(); dspl.DataSource = m_Target.Buffer; dspl.XDataMember = m_Target.CaptureObjects[0].Key.Description; dspl.YDataMember = obj.Description; ZedGraph.LineItem myCurve = m_MyPane.GraphPane.AddCurve(obj.Description, dspl, item.Color); } } m_MyPane.GraphPane.XAxis.Title.Text = m_Target.CaptureObjects[0].Key.LogicalName; // Tell ZedGraph to refigure the axes since the data have changed m_MyPane.AxisChange(); } } } else { ProfileGenericView.DataSource = null; } //Set initial values... ReadFromRB.Enabled = ReadLastRB.Enabled = ReadEntryBtn.Enabled = m_Target.CaptureObjects.Count != 0; ReadFromRB.Checked = ReadLastRB.Checked = ReadEntryBtn.Checked = false; StartEntry.Value = 0; EndEntry.Value = 1; ReadLastTB.Value = 0; StartPick.Value = ToPick.Value = DateTime.Now; if (!ReadFromRB.Enabled) { return; } index = m_Target.CaptureObjects[0].Value.AttributeIndex; obj = m_Target.CaptureObjects[0].Key; if (index != 0 && obj.GetUIDataType(index) != DataType.DateTime) { ReadFromRB.Enabled = ReadLastRB.Enabled = false; m_Target.AccessSelector = AccessRange.Entry; m_Target.From = 0; m_Target.To = 1; } else { ReadFromRB.Enabled = ReadLastRB.Enabled = true; } if (m_Target.AccessSelector == AccessRange.Entry) { StartEntry.Value = Convert.ToInt32(m_Target.From); EndEntry.Value = Convert.ToInt32(m_Target.To); ReadEntryBtn.Checked = true; } else if (m_Target.AccessSelector == AccessRange.Last) { TimeSpan diff = (DateTime)m_Target.To - (DateTime)m_Target.From; ReadLastTB.Value = diff.Days - 1; ReadLastRB.Checked = true; } else { if ((DateTime)m_Target.From == DateTime.MinValue) { StartPick.Checked = false; } else { StartPick.Value = (DateTime)m_Target.From; } if ((DateTime)m_Target.To == DateTime.MaxValue) { ToPick.Checked = false; } else { ToPick.Value = (DateTime)m_Target.To; } ReadFromRB.Checked = true; } }