void OnShowDialog(GXDLMSObject it, GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new ShowDialogEventHandler(OnShowDialog), it, arg).AsyncWaitHandle.WaitOne(); } else { ListViewItem li = null; bool remove = it == null; if (remove) { if (ObjectsView.SelectedItems.Count == 1) { li = ObjectsView.SelectedItems[0]; it = (GXDLMSObject)li.Tag; } else { arg.Handled = true; return; } } GXDLMSAssociationViewDlg dlg = new GXDLMSAssociationViewDlg(it, true, remove); if (dlg.ShowDialog(this) == DialogResult.OK) { GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName; if (remove) { arg.Value = target.RemoveObject(arg.Client, it); li.Remove(); } else { it = dlg.GetTarget(); li = ObjectsView.Items.Add(it.ObjectType.ToString()); li.SubItems.Add(it.Version.ToString()); li.SubItems.Add(it.LogicalName); li.SubItems.Add(""); li.SubItems.Add(""); li.Tag = it; target.ObjectList.Add(it); arg.Value = target.AddObject(arg.Client, it); } } else { arg.Handled = true; } } }
public void PreAction(GXActionArgs arg) { //Edit object in association view. if (arg.Action == ActionType.Action && arg.Index == -1) { if (arg.Tag == null) { OnShowDialog(null, arg); } else { GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName; arg.Value = target.AddObject(arg.Client, arg.Tag as GXDLMSObject); arg.Tag = null; } } //Add object to association view. else if (arg.Index == 3) { GXDLMSObject it = new GXDLMSData(); OnShowDialog(it, arg); } else if (arg.Index == 4) { // Remove object from association view. OnShowDialog(null, arg); } //Add user to user list. else if (arg.Index == 5) { OnShowDialog(true, arg); } else if (arg.Index == 6) { // Remove user from user list. OnShowDialog(false, arg); } if ((arg.Action == ActionType.Write && arg.Index == 7) || arg.Action == ActionType.Action && arg.Index == 2) { OnUpdatePassword(arg); } else if (arg.Action == ActionType.Write && arg.Index == 2) { //Skip write invoke. arg.Handled = true; } }