/// <summary> /// Edit key neighbour item. /// </summary> private void NeighbourTableEditBtn_Click(object sender, EventArgs e) { try { if (NeighbourTable.SelectedItems.Count != 0) { ListViewItem li = NeighbourTable.SelectedItems[0]; GXDLMSNeighbourTable item = (GXDLMSNeighbourTable)li.Tag; GXDLMSNeighbourTableDlg dlg = new GXDLMSNeighbourTableDlg(item); if (dlg.ShowDialog(this) == DialogResult.OK) { GXDLMSG3PlcMacSetup target = Target as GXDLMSG3PlcMacSetup; li.SubItems[0].Text = item.ShortAddress.ToString(); li.SubItems[1].Text = item.Enabled.ToString(); li.SubItems[2].Text = item.Modulation.ToString(); li.SubItems[3].Text = item.ToneMap; Target.UpdateDirty(11, target.NeighbourTable); errorProvider1.SetError(NeighbourTable, Properties.Resources.ValueChangedTxt); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add new item to neighbour table. /// </summary> private void NeighbourTableAddBtn_Click(object sender, EventArgs e) { try { GXDLMSNeighbourTable item = new GXDLMSNeighbourTable(); GXDLMSNeighbourTableDlg dlg = new GXDLMSNeighbourTableDlg(item); if (dlg.ShowDialog(this) == DialogResult.OK) { GXDLMSG3PlcMacSetup target = Target as GXDLMSG3PlcMacSetup; List <GXDLMSNeighbourTable> list = new List <GXDLMSNeighbourTable>(); if (target.NeighbourTable != null) { list.AddRange(target.NeighbourTable); } ListViewItem li = new ListViewItem(item.ShortAddress.ToString()); li.SubItems.Add(item.Enabled.ToString()); li.SubItems.Add(item.Modulation.ToString()); li.SubItems.Add(item.ToneMap); li.Tag = item; NeighbourTable.Items.Add(li); target.NeighbourTable = list.ToArray(); Target.UpdateDirty(11, target.NeighbourTable); errorProvider1.SetError(NeighbourTable, Properties.Resources.ValueChangedTxt); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <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> /// Remove item from key table. /// </summary> private void KeyTableRemoveBtn_Click(object sender, EventArgs e) { try { while (KeyTable.SelectedItems.Count != 0) { GXKeyValuePair <byte, byte[]> item = (GXKeyValuePair <byte, byte[]>)KeyTable.SelectedItems[0].Tag; KeyTable.Items.Remove(KeyTable.SelectedItems[0]); GXDLMSG3PlcMacSetup target = Target as GXDLMSG3PlcMacSetup; target.KeyTable.Remove(item); errorProvider1.SetError(KeyTable, Properties.Resources.ValueChangedTxt); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void OnValueChanged(int index, object value, bool user, bool connected) { if (index == 5) { GXDLMSG3PlcMacSetup target = Target as GXDLMSG3PlcMacSetup; KeyTable.Items.Clear(); if (target.KeyTable != null) { foreach (GXKeyValuePair <byte, byte[]> it in target.KeyTable) { ListViewItem li = new ListViewItem(it.Key.ToString()); li.SubItems.Add(GXDLMSTranslator.ToHex(it.Value)); li.Tag = it; KeyTable.Items.Add(li); } } } else if (index == 11) { GXDLMSG3PlcMacSetup target = Target as GXDLMSG3PlcMacSetup; NeighbourTable.Items.Clear(); if (target.NeighbourTable != null) { foreach (GXDLMSNeighbourTable it in target.NeighbourTable) { ListViewItem li = new ListViewItem(it.ShortAddress.ToString()); li.SubItems.Add(it.Enabled.ToString()); li.SubItems.Add(it.Modulation.ToString()); li.SubItems.Add(it.ToneMap); li.Tag = it; NeighbourTable.Items.Add(li); } } } else { throw new IndexOutOfRangeException("index"); } }
/// <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); } }
/// <summary> /// Remove item from neighbour table. /// </summary> private void NeighbourTableRemoveTbBtn_Click(object sender, EventArgs e) { try { GXDLMSG3PlcMacSetup target = Target as GXDLMSG3PlcMacSetup; List <GXDLMSNeighbourTable> list = new List <GXDLMSNeighbourTable>(); if (target.NeighbourTable != null) { list.AddRange(target.NeighbourTable); } while (NeighbourTable.SelectedItems.Count != 0) { list.Remove((GXDLMSNeighbourTable)NeighbourTable.SelectedItems[0].Tag); NeighbourTable.Items.Remove(NeighbourTable.SelectedItems[0]); errorProvider1.SetError(NeighbourTable, Properties.Resources.ValueChangedTxt); } target.NeighbourTable = list.ToArray(); Target.UpdateDirty(11, target.NeighbourTable); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }