Exemplo n.º 1
0
        /// <summary>
        /// Imports item times from another item.
        /// </summary>
        private void ImportTimesMI_Click(object sender, System.EventArgs e)
        {
            try
            {
                // prompt user to select values from another item.
                TsCHdaItemValueCollection values = new ReadValuesDlg().ShowDialog(m_server, RequestType.ReadRaw, true);

                if (values == null)
                {
                    return;
                }

                // get the current selection.
                int index = 0;

                if (TimesLV.SelectedIndices.Count > 0)
                {
                    index = TimesLV.SelectedIndices[TimesLV.SelectedIndices.Count - 1];
                }

                // add new times to list.
                foreach (TsCHdaItemValue value in values)
                {
                    AddListItem(value.Timestamp, index++);
                }

                // adjust columns
                AdjustColumns();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        /// <summary>
        /// Initializes an item value collection by reading data from another item.
        /// </summary>
        private void CopyDataMI_Click(object sender, System.EventArgs e)
        {
            try
            {
                // check for valid selection.
                if (ItemsLV.SelectedItems.Count != 1)
                {
                    return;
                }

                // must be an item value collection.
                object item = ItemsLV.SelectedItems[0].Tag;

                if (!typeof(TsCHdaItemValueCollection).IsInstanceOfType(item))
                {
                    return;
                }

                // prompt user to select a collection to copy.
                TsCHdaItemValueCollection values = new ReadValuesDlg().ShowDialog(m_trend.Server, RequestType.ReadRaw, true);

                if (values != null)
                {
                    // replace item identifier information.
                    TsCHdaItemValueCollection existing = (TsCHdaItemValueCollection)item;

                    values.ItemName     = existing.ItemName;
                    values.ItemPath     = existing.ItemPath;
                    values.ServerHandle = existing.ServerHandle;
                    values.ClientHandle = existing.ClientHandle;

                    // update list item.
                    UpdateListItem(ItemsLV.SelectedItems[0], values);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }