/// <summary> /// Creates a new item. /// </summary> private void NewMI_Click(object sender, System.EventArgs e) { TsCDaItemValue template = null; // copy the current selection. if (ItemListLV.SelectedItems.Count > 0) { template = (TsCDaItemValue)((TsCDaItemValue)ItemListLV.SelectedItems[0].Tag).Clone(); } // prompt user to edit new item. TsCDaItemValue[] items = new ItemValueListEditDlg().ShowDialog(new TsCDaItemValue[] { template }, true); if (items == null) { return; } // add new items. foreach (TsCDaItemValue item in items) { AddItem(item); } // adjust columns to fit data. AdjustColumns(); }
/// <summary> /// Edits the item template. /// </summary> private void EditTemplate(TsCDaItemValue template) { // prompt user to edit the template. TsCDaItemValue[] templates = new ItemValueListEditDlg().ShowDialog(new TsCDaItemValue[] { template }, false); if (templates == null || templates.Length != 1) { return; } // get existing items without applying defaults. ArrayList items = new ArrayList(); foreach (ListViewItem item in ItemListLV.Items) { if (item.Tag != null && item.Tag.GetType() == typeof(TsCDaItemValue)) { if (item.Tag != m_template) { items.Add(item.Tag); } } } // re-initialize the list with the new template. Initialize(m_server, templates[0]); // add items back. foreach (TsCDaItemValue item in items) { AddItem(item); } }
/// <summary> /// Edits a group of items. /// </summary> private void EditMI_Click(object sender, System.EventArgs e) { // check if the template if being editied. if (ItemListLV.SelectedItems.Count == 1) { if (ItemListLV.SelectedItems[0].Tag == m_template) { EditTemplate(m_template); return; } } // build list of items to edit (exclude template). ArrayList itemList = new ArrayList(ItemListLV.SelectedItems.Count); foreach (ListViewItem item in ItemListLV.SelectedItems) { if (item.Tag != null && item.Tag.GetType() == typeof(TsCDaItemValue)) { if (item.Tag != m_template) { itemList.Add(item.Tag); } } } // prompt user to edit list of items. TsCDaItemValue[] items = new ItemValueListEditDlg().ShowDialog((TsCDaItemValue[])itemList.ToArray(typeof(TsCDaItemValue)), false); if (items == null) { return; } // remove changed items. RemoveMI_Click(sender, e); // add changed items. foreach (TsCDaItemValue item in items) { // clear values only flag if quality or timestamp specified. if (item.QualitySpecified || item.TimestampSpecified) { ValuesOnlyMI.Checked = false; } AddItem(item); } // adjust columns to fit data. AdjustColumns(); }