Exemple #1
0
        /// <summary>
        /// Toggles the flag indicating whether to write only values.
        /// </summary>
        private void ValuesOnlyMI_Click(object sender, System.EventArgs e)
        {
            ValuesOnlyMI.Checked = !ValuesOnlyMI.Checked;

            // clear quality and timestamp.
            if (ValuesOnlyMI.Checked)
            {
                foreach (ListViewItem listItem in ItemListLV.Items)
                {
                    // get item.
                    OpcDa::ItemValue item = (OpcDa::ItemValue)listItem.Tag;

                    // disable quality/timestamp fields.
                    item.QualitySpecified   = false;
                    item.TimestampSpecified = false;

                    // clear columns in the list view.
                    listItem.SubItems[QUALITY_BITS].Text = "";
                    listItem.SubItems[LIMIT_BITS].Text   = "";
                    listItem.SubItems[VENDOR_BITS].Text  = "";
                    listItem.SubItems[TIMESTAMP].Text    = "";
                }

                AdjustColumns();
            }
        }
Exemple #2
0
        /// <summary>
        /// Edits the item template.
        /// </summary>
        private void EditTemplate(OpcDa::ItemValue template)
        {
            // prompt user to edit the template.
            OpcDa::ItemValue[] templates = new ItemValueListEditDlg().ShowDialog(new OpcDa::ItemValue[] { template }, false);

            if (templates == null || templates.Length != 1)
            {
                return;
            }

            // get existing items without applying defaults.
            ArrayList items = new ArrayList();

            foreach (ListViewItem item in ItemListLV.Items)
            {
                if (item.Tag != null && item.Tag.GetType() == typeof(OpcDa::ItemValue))
                {
                    if (item.Tag != m_template)
                    {
                        items.Add(item.Tag);
                    }
                }
            }

            // re-initialize the list with the new template.
            Initialize(m_server, templates[0]);

            // add items back.
            foreach (OpcDa::ItemValue item in items)
            {
                AddItem(item);
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a new item.
        /// </summary>
        private void NewMI_Click(object sender, System.EventArgs e)
        {
            OpcDa::ItemValue template = null;

            // copy the current selection.
            if (ItemListLV.SelectedItems.Count > 0)
            {
                template = (OpcDa::ItemValue)((OpcDa::ItemValue)ItemListLV.SelectedItems[0].Tag).Clone();
            }

            // prompt user to edit new item.
            OpcDa::ItemValue[] items = new ItemValueListEditDlg().ShowDialog(new OpcDa::ItemValue[] { template }, true);

            if (items == null)
            {
                return;
            }

            // add new items.
            foreach (OpcDa::ItemValue item in items)
            {
                AddItem(item);
            }

            // adjust columns to fit data.
            AdjustColumns();
        }
Exemple #4
0
        /// <summary>
        /// Adds an item to the list view.
        /// </summary>
        private void AddItem(OpcDa::ItemValue item)
        {
            // create list view item.
            ListViewItem listItem = new ListViewItem(item.ItemName, (int)ImageListLibrary.Icons.IMAGE_TAG);

            // add sub-items.
            listItem.SubItems.Add(Opc.Convert.ToString(GetFieldValue(item, ITEM_PATH)));
            listItem.SubItems.Add(Opc.Convert.ToString(GetFieldValue(item, VALUE)));
            listItem.SubItems.Add(Opc.Convert.ToString(GetFieldValue(item, VALUE_TYPE)));
            listItem.SubItems.Add(Opc.Convert.ToString(GetFieldValue(item, QUALITY_BITS)));
            listItem.SubItems.Add(Opc.Convert.ToString(GetFieldValue(item, LIMIT_BITS)));
            listItem.SubItems.Add(Opc.Convert.ToString(GetFieldValue(item, VENDOR_BITS)));
            listItem.SubItems.Add(Opc.Convert.ToString(GetFieldValue(item, TIMESTAMP)));

            // save item object as list view item tag.
            listItem.Tag = item;

            // insert/add item to list view.
            if (item == m_template)
            {
                ItemListLV.Items.Insert(0, listItem);
            }
            else
            {
                ItemListLV.Items.Add(listItem);
            }

            // adjust column widths.
            AdjustColumns();
        }
Exemple #5
0
        /// <summary>
        /// Initializes the control with the specified set of items.
        /// </summary>
        public void Initialize(Server server, OpcDa::ItemValue template)
        {
            // clear existing items.
            ItemListLV.Items.Clear();

            // save reference to server object.
            m_server = server;

            // disable init from properties if no server provided.
            InitMI.Enabled = m_server != null;

            // create template item.
            m_template          = (template != null) ? (OpcDa::ItemValue)template.Clone() : new OpcDa::ItemValue();
            m_template.ItemName = "<default>";

            // clear values only flag if quality or timestamp specified.
            if (m_template.QualitySpecified || m_template.TimestampSpecified)
            {
                ValuesOnlyMI.Checked = false;
            }

            // add template to list.
            AddItem(m_template);

            // adjust columns.
            AdjustColumns();
        }
Exemple #6
0
 /// <summary>
 /// Updates the specified list item.
 /// </summary>
 private void UpdateItem(ListViewItem listItem, OpcDa::ItemValue item)
 {
     listItem.SubItems[VALUE].Text        = Opc.Convert.ToString(GetFieldValue(item, VALUE));
     listItem.SubItems[VALUE_TYPE].Text   = Opc.Convert.ToString(GetFieldValue(item, VALUE_TYPE));
     listItem.SubItems[QUALITY_BITS].Text = Opc.Convert.ToString(GetFieldValue(item, QUALITY_BITS));
     listItem.SubItems[LIMIT_BITS].Text   = Opc.Convert.ToString(GetFieldValue(item, LIMIT_BITS));
     listItem.SubItems[VENDOR_BITS].Text  = Opc.Convert.ToString(GetFieldValue(item, VENDOR_BITS));
     listItem.SubItems[TIMESTAMP].Text    = Opc.Convert.ToString(GetFieldValue(item, TIMESTAMP));
 }
Exemple #7
0
        /// <summary>
        /// Initializes the control with the specified set of items.
        /// </summary>
        public void Initialize(Server server, OpcDa::ItemValue template, OpcDa::Item[] items)
        {
            Initialize(server, template);

            // add items.
            if (items != null)
            {
                foreach (OpcDa::Item item in items)
                {
                    AddItemWithDefaults(new OpcDa::ItemValue(item));
                }
            }

            // adjust columns.
            AdjustColumns();
        }
Exemple #8
0
        /// <summary>
        /// Returns the set of items in the control.
        /// </summary>
        public OpcDa::ItemValue[] GetItems()
        {
            ArrayList items = new ArrayList();

            foreach (ListViewItem listItem in ItemListLV.Items)
            {
                // skip template.
                if (listItem.Tag == m_template)
                {
                    continue;
                }

                object field = null;

                // create copy of item.
                OpcDa::ItemValue item = (OpcDa::ItemValue)((OpcDa::ItemValue)listItem.Tag).Clone();

                // Value
                field      = GetFieldValue(item, VALUE);
                item.Value = field;

                // Quality
                field                 = GetFieldValue(item, QUALITY);
                item.Quality          = (field != null) ? (OpcDa::Quality)field : OpcDa::Quality.Bad;
                item.QualitySpecified = field != null;

                // Timestamp
                field                   = GetFieldValue(item, TIMESTAMP);
                item.Timestamp          = (field != null) ? (DateTime)field : DateTime.MinValue;
                item.TimestampSpecified = field != null;

                // add item to list.
                items.Add(item);
            }

            //Opc.Convert to array of item objects.
            return((OpcDa::ItemValue[])items.ToArray(typeof(OpcDa::ItemValue)));
        }
Exemple #9
0
 /// <summary>
 /// Adds a items to the list view.
 /// </summary>
 public void AddItemWithDefaults(OpcDa::ItemValue item)
 {
     GetDefaultValues(new OpcDa::ItemValue[] { item }, ValuesOnlyMI.Checked);
     AddItem(item);
 }
Exemple #10
0
        /// <summary>
        /// Returns the value of the specified field.
        /// </summary>
        private object GetFieldValue(OpcDa::ItemValue item, int fieldID)
        {
            object fieldValue = null;

            switch (fieldID)
            {
            case ITEM_PATH:
            {
                fieldValue = item.ItemPath;
                break;
            }

            case VALUE:
            {
                fieldValue = item.Value;
                if (fieldValue == null)
                {
                    fieldValue = global::Opc.Convert.Clone(m_template.Value);
                }
                break;
            }

            case VALUE_TYPE:
            {
                fieldValue = (item.Value != null) ? item.Value.GetType() : null;
                if (fieldValue == null)
                {
                    fieldValue = (m_template.Value != null) ? m_template.Value.GetType() : null;
                }
                break;
            }

            case QUALITY_BITS:
            {
                fieldValue = (item.QualitySpecified) ? item.Quality.QualityBits : fieldValue;
                if (fieldValue == null)
                {
                    fieldValue = (m_template.QualitySpecified) ? m_template.Quality.QualityBits : fieldValue;
                }
                break;
            }

            case LIMIT_BITS:
            {
                fieldValue = (item.QualitySpecified) ? item.Quality.LimitBits : fieldValue;
                if (fieldValue == null)
                {
                    fieldValue = (m_template.QualitySpecified) ? m_template.Quality.LimitBits : fieldValue;
                }
                break;
            }

            case VENDOR_BITS:
            {
                fieldValue = (item.QualitySpecified) ? item.Quality.VendorBits : fieldValue;
                if (fieldValue == null)
                {
                    fieldValue = (m_template.QualitySpecified) ? m_template.Quality.VendorBits : fieldValue;
                }
                break;
            }

            case TIMESTAMP:
            {
                fieldValue = (item.TimestampSpecified) ? item.Timestamp : fieldValue;
                if (fieldValue == null)
                {
                    fieldValue = (m_template.TimestampSpecified) ? m_template.Timestamp : fieldValue;
                }
                break;
            }

            case QUALITY:
            {
                fieldValue = (item.QualitySpecified) ? item.Quality : fieldValue;
                if (fieldValue == null)
                {
                    fieldValue = (m_template.QualitySpecified) ? m_template.Quality : fieldValue;
                }
                break;
            }
            }
            return(fieldValue);
        }