/// <summary> /// Add new capture object. /// </summary> private void ColumnAddBtn_Click(object sender, EventArgs e) { try { GXDLMSCompactData target = Target as GXDLMSCompactData; GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it = new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(); GXDLMSProfileGenericColumnDlg dlg = new GXDLMSProfileGenericColumnDlg(it, target.Parent as GXDLMSObjectCollection, "Compact data capture object"); if (dlg.ShowDialog(this) == DialogResult.OK) { it = dlg.GetTarget(); ListViewItem li = CaptureObjectsLv.Items.Add(it.Key.ObjectType.ToString()); li.SubItems.Add(it.Key.LogicalName); li.SubItems.Add(it.Value.AttributeIndex.ToString()); li.Tag = it; target.CaptureObjects.Add(it); errorProvider1.SetError(CaptureObjectsLv, Properties.Resources.ValueChangedTxt); Target.UpdateDirty(3, target.CaptureObjects); } } catch (Exception ex) { DialogResult = DialogResult.None; MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Edit capture object. /// </summary> private void ColumnEditBtn_Click(object sender, EventArgs e) { try { if (CaptureObjectsLv.SelectedItems.Count == 1) { GXDLMSProfileGeneric target = Target as GXDLMSProfileGeneric; ListViewItem li = CaptureObjectsLv.SelectedItems[0]; GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it = (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>)li.Tag; GXDLMSProfileGenericColumnDlg dlg = new GXDLMSProfileGenericColumnDlg(it, target.Parent as GXDLMSObjectCollection, null); if (dlg.ShowDialog(this) == DialogResult.OK) { //If user has change target object. if (it.Key != dlg.GetTarget().Key) { int pos = target.CaptureObjects.IndexOf(it); target.CaptureObjects.RemoveAt(pos); it = dlg.GetTarget(); target.CaptureObjects.Insert(pos, it); } else { it = dlg.GetTarget(); } li.SubItems[0].Text = it.Key.ObjectType.ToString(); li.SubItems[1].Text = it.Key.LogicalName; li.SubItems[2].Text = it.Value.AttributeIndex.ToString(); errorProvider1.SetError(CaptureObjectsLv, Properties.Resources.ValueChangedTxt); li.Tag = it; Target.UpdateDirty(3, target.CaptureObjects); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }