/// <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 != mTemplate_) { items.Add(item.Tag); } } } // re-initialize the list with the new template. Initialize(mServer_, 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 == mTemplate_) { EditTemplate(mTemplate_); 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 != mTemplate_) { 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(); }