示例#1
0
        private void afTreeView2_AfterSelect(object sender, TreeViewEventArgs e)
        {
            AFAttribute selectedAttribute = afTreeView2.AFSelection as AFAttribute;

            //Clear data items
            lbCurrentVal.Text = "";
            lbTagName.Text = "";
            lbTimestamp.Text = "";
            lbData.Items.Clear();
            cbUOM.Items.Clear();
            btnInspectTag.Hide();
            afDataChart.Series["dataSeries"].Points.Clear();

            //Set timerange to default value
            afStartDate.Text = "*-12h";
            afEndTime.Text = "*";


            if (selectedAttribute != null)
            {
                if (selectedAttribute.DefaultUOM != null)
                {
                    cbUOM.Text = null;

                    //Fill out the UoM drop-down list
                    UOMClass selectedUOMClass = selectedAttribute.DefaultUOM.Class;
                    cbUOM.Items.AddRange(selectedUOMClass.UOMs.ToArray());
                    cbUOM.SelectedItem = selectedAttribute.DefaultUOM;
                }

                lbAttribName.Text = selectedAttribute.ToString();
                
                if (selectedAttribute.GetValue() != null) //Check that an attribute has been selected
                {
                    //Set lbCurrentVal to hold the current attribute value and timestamp
                    lbCurrentVal.Text = selectedAttribute.GetValue().ToString();
                    lbTimestamp.Text = selectedAttribute.GetValue().Timestamp.ToString();
                }
                    
                try//Check attribute for association with a PI Tag
                {
                    lbTagName.Text = selectedAttribute.PIPoint.Name.ToString(); //Set lbTagName to hold associated PI tag name
                    btnInspectTag.Show();
                } catch (OSIsoft.AF.PI.PIPointInvalidException) { //No tag association exists
                    lbTagName.Text = "INVALID PI POINT";
                } catch (System.NullReferenceException)
                {
                    lbTagName.Text = "NO PI POINT";
                }

                bntShowTrend.PerformClick();
            }
        }