Пример #1
0
 /// <summary>
 /// Edit object in association view.
 /// </summary>
 private void ObjectEditBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (ObjectsView.SelectedItems.Count == 1)
         {
             GXDLMSAssociationShortName target = Target as GXDLMSAssociationShortName;
             ListViewItem             li       = ObjectsView.SelectedItems[0];
             GXDLMSObject             it       = (GXDLMSObject)li.Tag;
             GXDLMSAssociationViewDlg dlg      = new GXDLMSAssociationViewDlg(target, it, false, false);
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 it = dlg.GetTarget();
                 li.SubItems[0].Text = it.ShortName.ToString();
                 li.SubItems[1].Text = it.ObjectType.ToString();
                 li.SubItems[2].Text = it.Version.ToString();
                 li.SubItems[3].Text = it.LogicalName;
                 li.Tag = it;
                 errorProvider1.SetError(ObjectsView, Properties.Resources.ValueChangedTxt);
                 Target.UpdateDirty(2, target.ObjectList);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(Parent, ex.Message, "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 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;
         }
     }
 }