/// <summary>
        /// Edits items in the specified subscription.
        /// </summary>
        private void EditItem(TreeNode node, TsCDaSubscription subscription, TsCDaItem item)
        {
            try
            {
                // save existing item id.
                OpcItem itemId = new OpcItem(item);

                TsCDaItem[] items = new ItemListEditDlg().ShowDialog(new TsCDaItem[] { item }, false, false);

                if (items == null)
                {
                    return;
                }

                // modify an existing item.
                if (itemId.Key == items[0].Key)
                {
                    subscription.ModifyItems((int)TsCDaStateMask.All, items);
                }

                // add/remove item because the item id changed.
                else
                {
                    items = subscription.AddItems(items);
                    subscription.RemoveItems(new OpcItem[] { itemId });
                }

                node.Text = items[0].ItemName;
                node.Tag  = items[0];
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
コード例 #2
0
 /// <summary>
 /// Edits this instance.
 /// </summary>
 internal void Edit()
 {
     try
     {
         // save existing item id.
         OpcDa::Item[] modifiedItems;
         OpcDa.Item    itemID = Tag.GetItem;
         using (ItemListEditDlg dial = new ItemListEditDlg())
         {
             modifiedItems = dial.ShowDialog(new OpcDa.Item[] { itemID }, false, false);
             if (dial.DialogResult != DialogResult.OK || modifiedItems == null)
             {
                 return;
             }
         }
         // modify an existing item.
         OpcDa::ItemResult[] resItems;
         if (itemID.Key == modifiedItems[0].Key)
         {
             resItems = Parent.ModifyItems(OpcDa::StateMask.All, modifiedItems);
         }
         else // add/remove item because the item id changed.
         {
             Parent.RemoveItem(itemID);
             resItems = Parent.AddItems(modifiedItems);
         }
         Text = resItems[0].ItemName;
         Tag.SetItemResult = resItems[0];
     }
     catch (Exception exc)
     {
         MessageBox.Show(exc.Message);
     }
     AssignImageIndex();
 }
コード例 #3
0
 /// <summary>
 /// Open a dialog to display and edit a list of the subscription item objects.
 /// </summary>
 internal void EditItems()
 {
     try
     {
         SubscriptionItems myItems = new SubscriptionItems(this);
         // edit the items.
         OpcDa::Item[] modifiedItems;
         using (ItemListEditDlg dial = new ItemListEditDlg())
         {
             modifiedItems = dial.ShowDialog(myItems.Items, false, false);
             if (dial.DialogResult != DialogResult.OK || modifiedItems == null)
             {
                 return;
             }
         }
         if (Tag != null)
         {
             // separate the items in lists depending on whether item id changed.
             ArrayList insertItems = new ArrayList();
             ArrayList updateItems = new ArrayList();
             ArrayList deleteItems = new ArrayList();
             // save item ids to detect item id changes.
             Opc.ItemIdentifier[] itemIDs = myItems.CreateIdentifiers;
             for (int ii = 0; ii < itemIDs.Length; ii++)
             {
                 if (modifiedItems[ii].Key != itemIDs[ii].Key)
                 {
                     insertItems.Add(modifiedItems[ii]);
                     deleteItems.Add(itemIDs[ii]);
                 }
                 else
                 {
                     updateItems.Add(modifiedItems[ii]);
                 }
             }
             Tag.SetResultFilters((int)OpcDa.ResultFilter.All);
             // delete old items.
             if (deleteItems.Count > 0)
             {
                 Tag.RemoveItems((Opc.ItemIdentifier[])deleteItems.ToArray(typeof(Opc.ItemIdentifier)));
             }
             // update existing items.
             if (updateItems.Count > 0)
             {
                 myItems.MatchChildren(Tag.ModifyItems((int)OpcDa::StateMask.All, (OpcDa::Item[])updateItems.ToArray(typeof(OpcDa::Item))));
             }
             // insert new items.
             if (insertItems.Count > 0)
             {
                 myItems.MatchChildren(Tag.AddItems((OpcDa::Item[])insertItems.ToArray(typeof(OpcDa::Item))));
             }
         }
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message, "Edit Items", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        /// <summary>
        /// Edits items in the specified subscription.
        /// </summary>
        private void EditItems(TreeNode node, TsCDaSubscription subscription)
        {
            try
            {
                // save item ids to detect item id changes.
                OpcItem[] itemIDs = new OpcItem[subscription.Items.Length];

                for (int ii = 0; ii < itemIDs.Length; ii++)
                {
                    itemIDs[ii] = new OpcItem(subscription.Items[ii]);
                }

                // edit the items.
                TsCDaItem[] items = new ItemListEditDlg().ShowDialog(subscription.Items, false, false);

                if (items == null)
                {
                    return;
                }

                // separate the items in lists depending on whether item id changed.
                ArrayList insertItems = new ArrayList();
                ArrayList updateItems = new ArrayList();
                ArrayList deleteItems = new ArrayList();

                for (int ii = 0; ii < itemIDs.Length; ii++)
                {
                    if (items[ii].Key != itemIDs[ii].Key)
                    {
                        insertItems.Add(items[ii]);
                        deleteItems.Add(itemIDs[ii]);
                    }
                    else
                    {
                        updateItems.Add(items[ii]);
                    }
                }

                // update existing items.
                if (updateItems.Count > 0)
                {
                    subscription.ModifyItems((int)TsCDaStateMask.All, (TsCDaItem[])updateItems.ToArray(typeof(TsCDaItem)));
                }

                // insert new items.
                if (insertItems.Count > 0)
                {
                    subscription.AddItems((TsCDaItem[])insertItems.ToArray(typeof(TsCDaItem)));
                }

                // delete old items.
                if (deleteItems.Count > 0)
                {
                    subscription.RemoveItems((OpcItem[])deleteItems.ToArray(typeof(OpcItem)));
                }

                // update tree.
                node.Nodes.Clear();

                foreach (TsCDaItem item in subscription.Items)
                {
                    AddItem(node, item);
                }

                node.Expand();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }