Пример #1
0
        /// <summary>
        /// Shows a detailed view for array values.
        /// </summary>
        private void ViewMI_Click(object sender, System.EventArgs e)
        {
            if (propertiesLv_.SelectedItems.Count > 0)
            {
                object tag = propertiesLv_.SelectedItems[0].Tag;

                if (tag != null && tag.GetType() == typeof(TsCDaItemProperty))
                {
                    TsCDaItemProperty property = (TsCDaItemProperty)tag;

                    if (property.Value != null)
                    {
                        if (property.ID == TsDaProperty.VALUE)
                        {
                            TsCCpxComplexItem complexItem = TsCCpxComplexTypeCache.GetComplexItem(mElement_);

                            if (complexItem != null)
                            {
                                new EditComplexValueDlg().ShowDialog(complexItem, property.Value, true, true);
                            }
                        }
                        else if (property.Value.GetType().IsArray)
                        {
                            new EditArrayDlg().ShowDialog(property.Value, true);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Shows a detailed view for array values.
        /// </summary>
        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(TsCDaItemValueResult))
                {
                    TsCDaItemValueResult item = (TsCDaItemValueResult)tag;

                    if (item.Value != null)
                    {
                        TsCCpxComplexItem complexItem = TsCCpxComplexTypeCache.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);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Updates the state of context menus based on the current selection.
        /// </summary>
        private void BrowseTV_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // ignore left button actions.
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            // selects the item that was right clicked on.
            TreeNode clickedNode = BrowseTV.GetNodeAt(e.X, e.Y);

            // no item clicked on - do nothing.
            if (clickedNode == null)
            {
                return;
            }

            // force selection to clicked node.
            BrowseTV.SelectedNode = clickedNode;

            // disable everything.
            PickMI.Enabled            = false;
            EditFiltersMI.Enabled     = false;
            RefreshMI.Enabled         = false;
            SetLoginMI.Enabled        = false;
            ConnectMI.Enabled         = false;
            DisconnectMI.Enabled      = false;
            ViewComplexTypeMI.Enabled = false;

            if (clickedNode == m_localNetwork || IsHostNode(clickedNode))
            {
                RefreshMI.Enabled  = true;
                SetLoginMI.Enabled = true;
                return;
            }

            if (IsServerNode(clickedNode))
            {
                PickMI.Enabled        = true;
                ConnectMI.Enabled     = !((TsCDaServer)clickedNode.Tag).IsConnected;
                DisconnectMI.Enabled  = ((TsCDaServer)clickedNode.Tag).IsConnected;
                EditFiltersMI.Enabled = true;
                RefreshMI.Enabled     = true;
                return;
            }

            if (IsBrowseElementNode(clickedNode))
            {
                PickMI.Enabled            = true;
                EditFiltersMI.Enabled     = true;
                RefreshMI.Enabled         = true;
                ViewComplexTypeMI.Enabled = (TsCCpxComplexTypeCache.GetComplexItem((TsCDaBrowseElement)clickedNode.Tag) != null);
                return;
            }
        }
        /// <summary>
        /// Displays a dialog with the complex type information.
        /// </summary>
        private void ViewComplexType(TreeNode node)
        {
            if (!IsBrowseElementNode(node))
            {
                return;
            }

            try
            {
                TsCCpxComplexItem complexItem = TsCCpxComplexTypeCache.GetComplexItem((TsCDaBrowseElement)node.Tag);

                if (complexItem != null)
                {
                    new EditComplexValueDlg().ShowDialog(complexItem, null, true, true);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Пример #5
0
        /// <summary>
        /// Called when the edit array button is clicked.
        /// </summary>
        private void EditBTN_Click(object sender, System.EventArgs e)
        {
            try
            {
                object            value       = null;
                TsCCpxComplexItem complexItem = TsCCpxComplexTypeCache.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 (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        /// <summary>
        /// Shows a detailed view for array values.
        /// </summary>
        private void ViewMI_Click(object sender, System.EventArgs e)
        {
            if (ItemListLV.SelectedItems.Count > 0)
            {
                ListViewItem listItem = ItemListLV.SelectedItems[0];

                object tag = listItem.Tag;

                if (tag != null && tag.GetType() == typeof(TsCDaItemValueResult))
                {
                    TsCDaItemValueResult item = (TsCDaItemValueResult)tag;

                    if (item.Value != null)
                    {
                        TsCCpxComplexItem complexItem = TsCCpxComplexTypeCache.GetComplexItem(item);

                        if (complexItem != null)
                        {
                            EditComplexValueDlg dialog = (EditComplexValueDlg)m_viewers[listItem];

                            if (dialog == null)
                            {
                                m_viewers[listItem] = dialog = new EditComplexValueDlg();
                                dialog.Disposed    += new EventHandler(OnViewerClosed);
                            }

                            dialog.ShowDialog(complexItem, item.Value, true, false);
                        }

                        else if (item.Value.GetType().IsArray)
                        {
                            new EditArrayDlg().ShowDialog(item.Value, true);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Enables/disables items in the popup menu before it is displayed.
        /// </summary>
        private void ItemListLV_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // ignore left button actions.
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            // disable everything.
            ViewMI.Enabled = false;

            // selects the item that was right clicked on.
            ListViewItem clickedItem = ItemListLV.GetItemAt(e.X, e.Y);

            // no item clicked on - do nothing.
            if (clickedItem == null)
            {
                return;
            }

            // force selection to clicked node.
            clickedItem.Selected = true;

            if (ItemListLV.SelectedItems.Count == 1)
            {
                if (clickedItem.Tag != null && clickedItem.Tag.GetType() == typeof(TsCDaItemValueResult))
                {
                    TsCDaItemValueResult item = (TsCDaItemValueResult)clickedItem.Tag;

                    if (item.Value != null)
                    {
                        ViewMI.Enabled = ((TsCCpxComplexTypeCache.GetComplexItem(item) != null) || (item.Value.GetType().IsArray));
                    }
                }
            }
        }
        /// <summary>
        /// Updates the complex data properties affected by the item.
        /// </summary>
        private void GetComplexItem(OpcItem itemId)
        {
            if (mItem_ == null)
            {
                return;
            }

            TsCCpxComplexItem item = mItem_;

            // clear any existing data filter.
            if (!dataFilterSpecifiedCb_.Checked || !dataFilterSpecifiedCb_.Enabled || dataFilterTb_.Text == "")
            {
                if (mItem_.UnfilteredItemID != null)
                {
                    mItem_.UpdateDataFilter(TsCCpxComplexTypeCache.Server, "");

                    if (mItem_.UnconvertedItemID != null)
                    {
                        item = TsCCpxComplexTypeCache.GetComplexItem(mItem_.UnconvertedItemID);
                    }
                    else
                    {
                        item = TsCCpxComplexTypeCache.GetComplexItem(mItem_.UnfilteredItemID);
                    }
                }
            }

            // clear any existing type conversion.
            if (!typeConversionSpecifiedCb_.Checked || typeConversionCb_.SelectedItem == null)
            {
                // check if type conversion removed.
                if (mItem_.UnconvertedItemID != null)
                {
                    item = TsCCpxComplexTypeCache.GetComplexItem(mItem_.UnconvertedItemID);
                }
            }
            else
            {
                // check if the type conversion changed.
                TsCCpxComplexItem conversion = (TsCCpxComplexItem)typeConversionCb_.SelectedItem;

                if (conversion.Key != item.Key)
                {
                    if (item.UnfilteredItemID == null || conversion.Key != item.UnfilteredItemID.Key)
                    {
                        item = conversion;
                    }
                }
            }

            // apply the new filter value.
            if (dataFilterSpecifiedCb_.Checked && dataFilterSpecifiedCb_.Enabled && dataFilterTb_.Text != "")
            {
                // update an existing data filter.
                if (item.UnfilteredItemID != null)
                {
                    item.UpdateDataFilter(TsCCpxComplexTypeCache.Server, dataFilterTb_.Text);
                }
                else
                {
                    // get the existing data filters.
                    TsCCpxComplexItem[] filters = item.GetDataFilters(TsCCpxComplexTypeCache.Server);

                    // assign a unique filter name.
                    int    ii         = 0;
                    string filterName = null;

                    do
                    {
                        filterName = String.Format("Filter{0:00}", ii++);

                        foreach (TsCCpxComplexItem filter in filters)
                        {
                            if (filter.Name == filterName)
                            {
                                filterName = null;
                                break;
                            }
                        }
                    }while (filterName == null);

                    // create the filter.
                    item = item.CreateDataFilter(TsCCpxComplexTypeCache.Server, filterName, dataFilterTb_.Text);
                }
            }

            // update the item id.
            if (item != null)
            {
                itemId.ItemPath = item.ItemPath;
                itemId.ItemName = item.ItemName;
            }
        }
        /// <summary>
        /// Initializes the control with information specified to a complex item.
        /// </summary>
        private void SetComplexItem(OpcItem itemId)
        {
            mItem_ = TsCCpxComplexTypeCache.GetComplexItem(itemId);

            // do nothing for items that are not complex.
            if (mItem_ == null)
            {
                reqTypePn_.Visible     = true;
                complexItemPn_.Visible = false;
                return;
            }

            // display complex item controls.
            reqTypePn_.Visible     = false;
            complexItemPn_.Visible = true;

            // initialize controls.
            typeConversionCb_.Items.Clear();
            typeConversionCb_.Text             = null;
            typeConversionSpecifiedCb_.Checked = false;

            dataFilterTb_.Text             = null;
            dataFilterSpecifiedCb_.Checked = false;

            // fetch the available type conversions.
            Technosoftware.DaAeHdaClient.Cpx.TsCCpxComplexItem[] conversions = mItem_.GetRootItem().GetTypeConversions(TsCCpxComplexTypeCache.Server);

            // no conversions available.
            if (conversions == null || conversions.Length == 0)
            {
                typeConversionSpecifiedCb_.Enabled = false;
            }

            // populate conversions drop down menu.
            else
            {
                Technosoftware.DaAeHdaClient.Cpx.TsCCpxComplexItem item = mItem_;

                if (item.UnfilteredItemID != null)
                {
                    item = TsCCpxComplexTypeCache.GetComplexItem(item.UnfilteredItemID);
                }

                foreach (TsCCpxComplexItem conversion in conversions)
                {
                    typeConversionCb_.Items.Add(conversion);

                    if (conversion.Key == item.Key)
                    {
                        typeConversionCb_.SelectedItem     = conversion;
                        typeConversionSpecifiedCb_.Checked = true;
                    }
                }

                if (typeConversionCb_.SelectedItem == null)
                {
                    typeConversionCb_.SelectedIndex = 0;
                }
            }

            // display the active data filter.
            if (mItem_.UnfilteredItemID != null)
            {
                dataFilterTb_.Text             = mItem_.DataFilterValue;
                dataFilterSpecifiedCb_.Checked = true;
            }
        }
        /// <summary>
        /// Initializes the control with information specified to a complex item.
        /// </summary>
        private void SetComplexItem(OpcItem itemID)
        {
            m_item = TsCCpxComplexTypeCache.GetComplexItem(itemID);

            // do nothing for items that are not complex.
            if (m_item == null)
            {
                ReqTypePN.Visible     = true;
                ComplexItemPN.Visible = false;
                return;
            }

            // display complex item controls.
            ReqTypePN.Visible     = false;
            ComplexItemPN.Visible = true;

            // initialize controls.
            TypeConversionCB.Items.Clear();
            TypeConversionCB.Text             = null;
            TypeConversionSpecifiedCB.Checked = false;

            DataFilterTB.Text             = null;
            DataFilterSpecifiedCB.Checked = false;

            // fetch the available type conversions.
            OpcClientSdk.Cpx.TsCCpxComplexItem[] conversions = m_item.GetRootItem().GetTypeConversions(TsCCpxComplexTypeCache.Server);

            // no conversions available.
            if (conversions == null || conversions.Length == 0)
            {
                TypeConversionSpecifiedCB.Enabled = false;
            }

            // populate conversions drop down menu.
            else
            {
                OpcClientSdk.Cpx.TsCCpxComplexItem item = m_item;

                if (item.UnfilteredItemID != null)
                {
                    item = TsCCpxComplexTypeCache.GetComplexItem(item.UnfilteredItemID);
                }

                foreach (TsCCpxComplexItem conversion in conversions)
                {
                    TypeConversionCB.Items.Add(conversion);

                    if (conversion.Key == item.Key)
                    {
                        TypeConversionCB.SelectedItem     = conversion;
                        TypeConversionSpecifiedCB.Checked = true;
                    }
                }

                if (TypeConversionCB.SelectedItem == null)
                {
                    TypeConversionCB.SelectedIndex = 0;
                }
            }

            // display the active data filter.
            if (m_item.UnfilteredItemID != null)
            {
                DataFilterTB.Text             = m_item.DataFilterValue;
                DataFilterSpecifiedCB.Checked = true;
            }
        }