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 (m_Target.AccessSelector == AccessRange.Range)
            {
                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;
            }
            else //All is checked.
            {
                ReadAllRB.Checked = true;
            }
        }
Beispiel #2
0
        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;
            }
        }