コード例 #1
0
        /// <summary>
        /// Displays a dialog with more detailed view of the current selection.
        /// </summary>
        private void ViewMI_Click(object sender, System.EventArgs e)
        {
            try
            {
                // check for valid selection.
                if (AttributesLV.SelectedItems.Count != 1)
                {
                    return;
                }

                ListViewItem selection = AttributesLV.SelectedItems[0];

                // show values if an attribute collection.
                if (typeof(OpcClientSdk.Hda.TsCHdaAttributeValueCollection).IsInstanceOfType(selection.Tag))
                {
                    new AttributesViewDlg().ShowDialog(m_server, (OpcClientSdk.Hda.TsCHdaAttributeValueCollection)selection.Tag);
                }

                // show description of attribute.
                else if (typeof(OpcClientSdk.Hda.TsCHdaAttribute).IsInstanceOfType(selection.Tag))
                {
                    OpcClientSdk.Hda.TsCHdaAttribute attribute = (OpcClientSdk.Hda.TsCHdaAttribute)selection.Tag;
                    MessageBox.Show(attribute.Description, attribute.Name, MessageBoxButtons.OK);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Displays the dialog until the user enters valid data or clicks cancel.
        /// </summary>
        private TsCHdaBrowseFilter PromptUser()
        {
            while (ShowDialog() == DialogResult.OK)
            {
                try
                {
                    OpcClientSdk.Hda.TsCHdaAttribute attribute = (OpcClientSdk.Hda.TsCHdaAttribute)AttributeCB.SelectedItem;

                    if (attribute == null)
                    {
                        continue;
                    }

                    TsCHdaBrowseFilter filter = new TsCHdaBrowseFilter();

                    filter.AttributeID = attribute.ID;
                    filter.Operator    = (TsCHdaOperator)OperatorCTRL.Value;
                    filter.FilterValue = FilterValueCTRL.Value;

                    return(filter);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Edits an item from the list.
        /// </summary>
        private void ViewMI_Click(object sender, System.EventArgs e)
        {
            try
            {
                // check for valid selection.
                if (AttributesLV.SelectedItems.Count != 1)
                {
                    return;
                }

                OpcClientSdk.Hda.TsCHdaAttribute attribute = (OpcClientSdk.Hda.TsCHdaAttribute)AttributesLV.SelectedItems[0].Tag;

                // view an attribute.
                MessageBox.Show(attribute.Description, attribute.Name);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
コード例 #4
0
        /// <summary>
        /// Handles a change to the selected attribute.
        /// </summary>
        private void AttributeCB_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            try
            {
                // get current selection.
                OpcClientSdk.Hda.TsCHdaAttribute attribute = (OpcClientSdk.Hda.TsCHdaAttribute)AttributeCB.SelectedItem;

                if (attribute == null)
                {
                    DescriptionLB.Text = "";
                    return;
                }

                // convert filter value to correct data type.
                object value = FilterValueCTRL.Value;

                if (value == null || value.GetType() != attribute.DataType)
                {
                    try
                    {
                        FilterValueCTRL.Value = OpcClientSdk.OpcConvert.ChangeType(value, attribute.DataType);
                    }
                    catch
                    {
                        FilterValueCTRL.Value = OpcClientSdk.OpcConvert.ChangeType(null, attribute.DataType);
                    }
                }

                // update description.
                DescriptionLB.Text = attribute.Description;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
コード例 #5
0
        /// <summary>
        /// Returns the value of the specified field.
        /// </summary>
        private object GetFieldValue(object attribute, int fieldID)
        {
            // display result code.
            if (typeof(IOpcResult).IsInstanceOfType(attribute))
            {
                switch (fieldID)
                {
                case RESULT: { return(((OpcClientSdk.Hda.TsCHdaAttributeValueCollection)attribute).Result); }
                }
            }

            // displaying attribute descriptions.
            if (typeof(OpcClientSdk.Hda.TsCHdaAttribute).IsInstanceOfType(attribute))
            {
                if (AttributesLV.CheckBoxes)
                {
                    switch (fieldID)
                    {
                    case NAME: { return(((OpcClientSdk.Hda.TsCHdaAttribute)attribute).Name); }
                    }
                }
                else
                {
                    switch (fieldID)
                    {
                    case NAME:        { return(((OpcClientSdk.Hda.TsCHdaAttribute)attribute).Name); }

                    case DATA_TYPE:   { return(((OpcClientSdk.Hda.TsCHdaAttribute)attribute).DataType); }

                    case DESCRIPTION: { return(((OpcClientSdk.Hda.TsCHdaAttribute)attribute).Description); }
                    }
                }
            }

            // displaying attribute results.
            if (typeof(OpcClientSdk.Hda.TsCHdaAttributeValueCollection).IsInstanceOfType(attribute))
            {
                OpcClientSdk.Hda.TsCHdaAttributeValueCollection collection = (OpcClientSdk.Hda.TsCHdaAttributeValueCollection)attribute;

                switch (fieldID)
                {
                case NAME:
                {
                    OpcClientSdk.Hda.TsCHdaAttribute description = m_server.Attributes.Find(collection.AttributeID);

                    if (description != null)
                    {
                        return(description.Name);
                    }

                    return(null);
                }

                case NUM_VALUES:
                {
                    if (collection.Count > 1)
                    {
                        return(collection.Count);
                    }

                    return(null);
                }

                case VALUE:
                {
                    if (collection.Count == 1)
                    {
                        return(collection[0].Value);
                    }

                    return(null);
                }
                }
            }

            // displaying attribute values.
            if (typeof(OpcClientSdk.Hda.TsCHdaAttributeValue).IsInstanceOfType(attribute))
            {
                switch (fieldID)
                {
                case TIMESTAMP: { return(((OpcClientSdk.Hda.TsCHdaAttributeValue)attribute).Timestamp); }

                case VALUE:     { return(((OpcClientSdk.Hda.TsCHdaAttributeValue)attribute).Value); }
                }
            }

            return(null);
        }