/// <summary>
        /// Handles the MouseDown event of the m_ItemListLV control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        private void m_ItemListLV_MouseDown(object sender, MouseEventArgs e)
        {
            // ignore left button actions.
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            // disable everything.
            m_CMS_View.Enabled = false;
            // selects the item that was right clicked on.
            ListViewItem clickedItem = m_ItemListLV.GetItemAt(e.X, e.Y);

            // no item clicked on - do nothing.
            if (clickedItem == null)
            {
                return;
            }
            // force selection to clicked node.
            clickedItem.Selected = true;
            return;

            //TODO implement complex data and remove above return
            if (m_ItemListLV.SelectedItems.Count == 1)
            {
                if (clickedItem.Tag != null && clickedItem.Tag.GetType() == typeof(OpcDa::ItemValueResult))
                {
                    OpcDa::ItemValueResult item = (OpcDa::ItemValueResult)clickedItem.Tag;
                    if (item.Value != null)
                    {
                        m_CMS_View.Enabled = ((ComplexTypeCache.GetComplexItem(item) != null) || (item.Value.GetType().IsArray));
                    }
                }
            }
        }
Esempio n. 2
0
 private void ViewMI_Click(object sender, System.EventArgs e)
 {
     if (this.PropertiesLV.SelectedItems.Count > 0)
     {
         object tag = this.PropertiesLV.SelectedItems[0].Tag;
         if (tag != null && tag.GetType() == typeof(ItemProperty))
         {
             ItemProperty itemProperty = (ItemProperty)tag;
             if (itemProperty.Value != null)
             {
                 if (itemProperty.ID == Property.VALUE)
                 {
                     ComplexItem complexItem = ComplexTypeCache.GetComplexItem(this.m_element);
                     if (complexItem != null)
                     {
                         new EditComplexValueDlg().ShowDialog(complexItem, itemProperty.Value, true, true);
                     }
                 }
                 else if (itemProperty.Value.GetType().IsArray)
                 {
                     new EditArrayDlg().ShowDialog(itemProperty.Value, true);
                 }
             }
         }
     }
 }
 /// <summary>
 /// Shows a detailed view for array values.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 //TODO make it visible after implementing complex values.
 private void m_CMS_View_Click(object sender, System.EventArgs e)
 {
     if (m_ItemListLV.SelectedItems.Count > 0)
     {
         ListViewItem listItem = m_ItemListLV.SelectedItems[0];
         object       tag      = listItem.Tag;
         if (tag != null && tag.GetType() == typeof(OpcDa::ItemValueResult))
         {
             OpcDa::ItemValueResult item = (OpcDa::ItemValueResult)tag;
             if (item.Value != null)
             {
                 ComplexItem complexItem = ComplexTypeCache.GetComplexItem(item);
                 if (complexItem != null)
                 {
                     EditComplexValueDlg dialog = (EditComplexValueDlg)m_viewers[listItem];
                     if (dialog == null)
                     {
                         m_viewers[listItem] = dialog = new EditComplexValueDlg();
                         dialog.Disposed    += new System.EventHandler(OnViewerClosed);
                     }
                     dialog.ShowDialog(complexItem, item.Value, true, false);
                 }
                 else if (item.Value.GetType().IsArray)
                 {
                     new EditArrayDlg().ShowDialog(item.Value, true);
                 }
             }
         }
     }
 }
Esempio n. 4
0
 private void ViewComplexType(System.Windows.Forms.TreeNode node)
 {
     if (this.IsBrowseElementNode(node))
     {
         try
         {
             ComplexItem complexItem = ComplexTypeCache.GetComplexItem((BrowseElement)node.Tag);
             if (complexItem != null)
             {
                 new EditComplexValueDlg().ShowDialog(complexItem, null, true, true);
             }
         }
         catch (System.Exception ex)
         {
             System.Windows.Forms.MessageBox.Show(ex.Message);
         }
     }
 }
 /// <summary>
 /// Shows a detailed view for array values.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void ViewMI_Click(object sender, System.EventArgs e)
 {
     if (ItemListLV.SelectedItems.Count > 0)
     {
         object tag = ItemListLV.SelectedItems[0].Tag;
         if (tag != null && tag.GetType() == typeof(OpcDa::ItemValueResult))
         {
             OpcDa::ItemValueResult item = (OpcDa::ItemValueResult)tag;
             if (item.Value != null)
             {
                 ComplexItem complexItem = ComplexTypeCache.GetComplexItem(item);
                 if (complexItem != null)
                 {
                     new EditComplexValueDlg().ShowDialog(complexItem, item.Value, true, true);
                 }
                 else if (item.Value.GetType().IsArray)
                 {
                     new EditArrayDlg().ShowDialog(item.Value, true);
                 }
             }
         }
     }
 }
Esempio n. 6
0
 private void BrowseTV_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Right)
     {
         System.Windows.Forms.TreeNode nodeAt = this.BrowseTV.GetNodeAt(e.X, e.Y);
         if (nodeAt != null)
         {
             this.PickMI.Enabled            = false;
             this.EditFiltersMI.Enabled     = false;
             this.RefreshMI.Enabled         = false;
             this.SetLoginMI.Enabled        = false;
             this.ConnectMI.Enabled         = false;
             this.DisconnectMI.Enabled      = false;
             this.ViewComplexTypeMI.Enabled = false;
             if (nodeAt == this.m_localNetwork || this.IsHostNode(nodeAt))
             {
                 this.RefreshMI.Enabled  = true;
                 this.SetLoginMI.Enabled = true;
             }
             else if (this.IsServerNode(nodeAt))
             {
                 this.PickMI.Enabled        = true;
                 this.ConnectMI.Enabled     = !((Opc.Da.Server)nodeAt.Tag).IsConnected;
                 this.DisconnectMI.Enabled  = ((Opc.Da.Server)nodeAt.Tag).IsConnected;
                 this.EditFiltersMI.Enabled = true;
                 this.RefreshMI.Enabled     = true;
             }
             else if (this.IsBrowseElementNode(nodeAt))
             {
                 this.PickMI.Enabled            = true;
                 this.EditFiltersMI.Enabled     = true;
                 this.RefreshMI.Enabled         = true;
                 this.ViewComplexTypeMI.Enabled = (ComplexTypeCache.GetComplexItem((BrowseElement)nodeAt.Tag) != null);
             }
         }
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Called when the edit array button is clicked.
        /// </summary>
        private void EditBTN_Click(object sender, System.EventArgs e)
        {
            try
            {
                object value = null;

                ComplexItem complexItem = ComplexTypeCache.GetComplexItem(m_itemID);

                if (complexItem != null)
                {
                    value = new EditComplexValueDlg().ShowDialog(complexItem, m_value, m_readOnly, true);
                }

                else if (m_value.GetType().IsArray)
                {
                    value = new EditArrayDlg().ShowDialog(m_value, m_readOnly);
                }

                if (m_readOnly || value == null)
                {
                    return;
                }

                // update the array.
                Set(value, m_readOnly);

                // send change notification.
                if (ValueChanged != null)
                {
                    ValueChanged(this, m_value);
                }
            }
            catch (System.Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        /// <summary>
        /// Displays the dialog with the specified complex item.
        /// </summary>
        public object ShowDialog(ComplexItem item, object rawValue, bool readOnly, bool modal)
        {
            if (item == null)
            {
                throw new System.ArgumentNullException("item");
            }

            try
            {
                m_readOnly = readOnly;
                m_item     = item;
                m_rawValue = rawValue;

                // fetch complex type information for the item.
                string dictionary = ComplexTypeCache.GetTypeDictionary(item);

                if (dictionary == null)
                {
                    return(null);
                }

                // initialize dialog controls.
                TypeTV.Nodes.Clear();
                FieldsLV.Items.Clear();
                RawTB.Text = null;

                // display the dictionary and type description.
                TypeDictionaryTB.Text  = FormatXml(dictionary);
                TypeDescriptionTB.Text = FormatXml(ComplexTypeCache.GetTypeDescription(item));

                if (rawValue == null)
                {
                    ViewMI_Click(TypeDictionaryMI, null);
                }
                else
                {
                    // parse binary value.
                    if (rawValue.GetType() == typeof(byte[]))
                    {
                        m_binaryValue = new BinaryValue();

                        try
                        {
                            m_complexValue = m_binaryValue.Init(rawValue, dictionary, item.TypeID);
                        }
                        catch (System.Exception e)
                        {
                            MessageBox.Show(e.Message);
                            m_complexValue = null;
                        }
                    }
                    else
                    {
                        m_binaryValue  = null;
                        m_complexValue = null;
                    }

                    UpdateView();

                    if (TypeTV.SelectedNode != null)
                    {
                        TypeTV.SelectedNode = TypeTV.Nodes[0];
                        TypeTV.SelectedNode.Expand();

                        ViewMI_Click(FormattedMI, null);
                    }
                    else
                    {
                        ViewMI_Click(RawMI, null);
                    }
                }

                if (modal)
                {
                    // show dialog.
                    if (ShowDialog() != DialogResult.OK)
                    {
                        return(null);
                    }

                    return(m_rawValue);
                }

                // display non-model window.
                Show();

                return(null);
            }

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