/// <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(mServer_, 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(mTrend_.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); } }