/// <summary> /// Edit key table item. /// </summary> private void KeyTableEditBtn_Click(object sender, EventArgs e) { try { if (KeyTable.SelectedItems.Count != 0) { GXDLMSG3PlcMacSetup target = Target as GXDLMSG3PlcMacSetup; ListViewItem li = KeyTable.SelectedItems[0]; GXKeyValuePair <byte, byte[]> item = (GXKeyValuePair <byte, byte[]>)li.Tag; GXDLMSKeyTableDlg dlg = new GXDLMSKeyTableDlg(item); if (dlg.ShowDialog(this) == DialogResult.OK) { item.Key = dlg.id; item.Value = dlg.key; li.SubItems[0].Text = item.Key.ToString(); li.SubItems[1].Text = GXDLMSTranslator.ToHex(item.Value); Target.UpdateDirty(5, target.KeyTable); errorProvider1.SetError(KeyTable, Properties.Resources.ValueChangedTxt); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add new item to key table. /// </summary> private void KeyTableAddBtn_Click(object sender, EventArgs e) { try { GXKeyValuePair <byte, byte[]> item = new GXKeyValuePair <byte, byte[]>(); GXDLMSKeyTableDlg dlg = new GXDLMSKeyTableDlg(item); if (dlg.ShowDialog(this) == DialogResult.OK) { item.Key = dlg.id; item.Value = dlg.key; ListViewItem li = new ListViewItem(item.Key.ToString()); li.SubItems.Add(GXDLMSTranslator.ToHex(item.Value)); li.Tag = item; KeyTable.Items.Add(li); GXDLMSG3PlcMacSetup target = Target as GXDLMSG3PlcMacSetup; target.KeyTable.Add(item); errorProvider1.SetError(KeyTable, Properties.Resources.ValueChangedTxt); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }