/// <summary> /// Edit destination. /// </summary> private void DestinationEditBtn_Click(object sender, EventArgs e) { try { if (DestinationLv.SelectedItems.Count == 1) { GXDLMSAutoConnect target = Target as GXDLMSAutoConnect; List <string> entries = new List <string>(); if (target.Destinations != null) { entries.AddRange(target.Destinations); } ListViewItem li = DestinationLv.SelectedItems[0]; GXTextDlg dlg = new GXTextDlg("Destination", "Destination", li.Text); if (dlg.ShowDialog(this) == DialogResult.OK) { string tmp = dlg.GetValue(); int pos = DestinationLv.SelectedIndices[0]; li.SubItems[0].Text = tmp; entries.RemoveAt(pos); entries.Insert(pos, tmp); errorProvider1.SetError(DestinationLv, Properties.Resources.ValueChangedTxt); Target.UpdateDirty(6, target.Destinations); target.Destinations = entries.ToArray(); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Edit TAB(i). /// </summary> private void TabisEditBtn_Click(object sender, EventArgs e) { try { if (TabisList.SelectedItems.Count == 1) { GXDLMSIecTwistedPairSetup target = Target as GXDLMSIecTwistedPairSetup; List <sbyte> tabis = new List <sbyte>(); if (target.Tabis != null) { tabis.AddRange(target.Tabis); } ListViewItem li = TabisList.SelectedItems[0]; GXTextDlg dlg = new GXTextDlg("TAB(i)", "TAB(i)", li.Text, typeof(sbyte)); if (dlg.ShowDialog(this) == DialogResult.OK) { string tmp = dlg.GetValue(); int pos = TabisList.SelectedIndices[0]; li.SubItems[0].Text = tmp; tabis.RemoveAt(pos); tabis.Insert(pos, sbyte.Parse(tmp)); errorProvider1.SetError(TabisList, Properties.Resources.ValueChangedTxt); Target.UpdateDirty(5, target.Tabis); target.Tabis = tabis.ToArray(); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add destination. /// </summary> private void DestinationAddBtn_Click(object sender, EventArgs e) { try { GXDLMSAutoConnect target = Target as GXDLMSAutoConnect; List <string> entries = new List <string>(); if (target.Destinations != null) { entries.AddRange(target.Destinations); } GXTextDlg dlg = new GXTextDlg("Destination", "Destination", ""); if (dlg.ShowDialog(this) == DialogResult.OK) { string tmp = dlg.GetValue(); ListViewItem li = DestinationLv.Items.Add(tmp); entries.Add(tmp); errorProvider1.SetError(DestinationLv, Properties.Resources.ValueChangedTxt); target.Destinations = entries.ToArray(); Target.UpdateDirty(6, target.Destinations); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Edit description. /// </summary> private void DescriptionsEdit_Click(object sender, EventArgs e) { try { if (DescriptionsView.SelectedItems.Count == 1) { GXDLMSTokenGateway target = Target as GXDLMSTokenGateway; ListViewItem li = DescriptionsView.SelectedItems[0]; GXTextDlg dlg = new GXTextDlg("Edit description", "Description:", li.Text); if (dlg.ShowDialog(this) == DialogResult.OK) { target.Descriptions.Remove(li.Text); string desc = dlg.GetValue(); li.SubItems[0].Text = desc; target.Descriptions.Add(desc); errorProvider1.SetError(DescriptionsView, Properties.Resources.ValueChangedTxt); Target.UpdateDirty(4, target.Descriptions); } } } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add TAB(i). /// </summary> private void TabisAddBtn_Click(object sender, EventArgs e) { try { GXDLMSIecTwistedPairSetup target = Target as GXDLMSIecTwistedPairSetup; List <sbyte> tabis = new List <sbyte>(); if (target.Tabis != null) { tabis.AddRange(target.Tabis); } GXTextDlg dlg = new GXTextDlg("TAB(i)", "TAB(i)", "", typeof(sbyte)); if (dlg.ShowDialog(this) == DialogResult.OK) { string tmp = dlg.GetValue(); ListViewItem li = TabisList.Items.Add(tmp); tabis.Add(sbyte.Parse(tmp)); errorProvider1.SetError(TabisList, Properties.Resources.ValueChangedTxt); target.Tabis = tabis.ToArray(); Target.UpdateDirty(5, target.Tabis); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add primary addresses. /// </summary> private void PrimaryAddressesAddBtn_Click(object sender, EventArgs e) { try { GXDLMSIecTwistedPairSetup target = Target as GXDLMSIecTwistedPairSetup; List <byte> addresses = new List <byte>(); if (target.PrimaryAddresses != null) { addresses.AddRange(target.PrimaryAddresses); } GXTextDlg dlg = new GXTextDlg("Primary Address", "Primary Address", "", typeof(byte)); if (dlg.ShowDialog(this) == DialogResult.OK) { byte tmp = byte.Parse(dlg.GetValue()); ListViewItem li = PrimaryAddressesList.Items.Add(tmp.ToString()); addresses.Add(tmp); errorProvider1.SetError(PrimaryAddressesList, Properties.Resources.ValueChangedTxt); target.PrimaryAddresses = addresses.ToArray(); Target.UpdateDirty(4, target.PrimaryAddresses); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void OnShowDlg(GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new ShowDlgEventHandler(OnShowDlg), arg).AsyncWaitHandle.WaitOne(); } else { GXDLMSIp6Setup target = Target as GXDLMSIp6Setup; if (arg.Index == 5) { GXClockPresetTimeDlg dlg = new GXClockPresetTimeDlg(); if (dlg.ShowDialog(this) == DialogResult.OK) { GXByteBuffer bb = new GXByteBuffer(); bb.SetUInt8((byte)DataType.Structure); bb.SetUInt8(4); //Add data type and length. bb.SetUInt8((byte)DataType.OctetString); bb.SetUInt8(12); bb.Set(GXDLMSTranslator.HexToBytes(dlg.PresetTime.ToHex(false, GXDlmsUi.UseMeterTimeZone))); //Add data type and length. bb.SetUInt8((byte)DataType.OctetString); bb.SetUInt8(12); bb.Set(GXDLMSTranslator.HexToBytes(dlg.IntervalStart.ToHex(false, GXDlmsUi.UseMeterTimeZone))); //Add data type and length. bb.SetUInt8((byte)DataType.OctetString); bb.SetUInt8(12); bb.Set(GXDLMSTranslator.HexToBytes(dlg.IntervalEnd.ToHex(false, GXDlmsUi.UseMeterTimeZone))); arg.Value = bb.Array(); } else { arg.Handled = true; } } else if (arg.Index == 6) { GXTextDlg dlg = new GXTextDlg("Shift Time", "Shift Time (s):", "", typeof(Int16)); if (dlg.ShowDialog(this) == DialogResult.OK) { arg.Value = Int16.Parse(dlg.GetValue()); } else { arg.Handled = true; } } else { arg.Handled = true; } } }
void OnShowDlg(GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new ShowDlgEventHandler(OnShowDlg), arg).AsyncWaitHandle.WaitOne(); } else { GXDLMSIp6Setup target = Target as GXDLMSIp6Setup; if (arg.Index == 1) { GXTextDlg dlg = new GXTextDlg("Update Amount", "Amount:", "", typeof(Int32)); if (dlg.ShowDialog(this) == DialogResult.OK) { arg.Value = Int32.Parse(dlg.GetValue()); } else { arg.Handled = true; } } else if (arg.Index == 2) { GXTextDlg dlg = new GXTextDlg("Set Amount", "Amount:", "", typeof(Int32)); if (dlg.ShowDialog(this) == DialogResult.OK) { arg.Value = Int32.Parse(dlg.GetValue()); } else { arg.Handled = true; } } else if (arg.Index == 3) { GXTextDlg dlg = new GXTextDlg("Invoke Credit", "Value:", "", typeof(sbyte)); if (dlg.ShowDialog(this) == DialogResult.OK) { arg.Value = sbyte.Parse(dlg.GetValue()); } else { arg.Handled = true; } } else { arg.Handled = true; } } }
void OnUpdatePassword(GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new UpdatePasswordDialogEventHandler(OnUpdatePassword), arg).AsyncWaitHandle.WaitOne(); } else { //Update pw. GXTextDlg dlg; if (arg.Action == ActionType.Write) { dlg = new GXTextDlg("Update Low level password.", "Password", ""); } else { dlg = new GXTextDlg("Update High level password.", "Password", ""); } arg.Handled = dlg.ShowDialog(Parent) != DialogResult.OK; if (!arg.Handled) { byte[] value; if (!dlg.GetValue().StartsWith("0x")) { value = ASCIIEncoding.ASCII.GetBytes(dlg.GetValue()); } else { value = GXDLMSTranslator.HexToBytes(dlg.GetValue()); } GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName; if (arg.Action == ActionType.Write) { target.Secret = value; } else { GXByteBuffer bb = new GXByteBuffer(); bb.SetUInt8((byte)DataType.OctetString); bb.SetUInt8((byte)value.Length); bb.Set(value); arg.Value = bb.Array(); } } } }
/// <summary> /// Add description. /// </summary> private void DescriptionsAdd_Click(object sender, EventArgs e) { try { GXDLMSTokenGateway target = Target as GXDLMSTokenGateway; GXTextDlg dlg = new GXTextDlg("Add new description", "Description:", ""); if (dlg.ShowDialog(this) == DialogResult.OK) { string desc = dlg.GetValue(); target.Descriptions.Add(desc); ListViewItem li = DescriptionsView.Items.Add(desc); errorProvider1.SetError(DescriptionsView, Properties.Resources.ValueChangedTxt); Target.UpdateDirty(4, target.Descriptions); } } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void OnShowDialog(GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new ShowDialogEventHandler(OnShowDialog), arg).AsyncWaitHandle.WaitOne(); } else { GXTextDlg dlg = new GXTextDlg("Transfer token", "Token", "", typeof(byte[])); if (dlg.ShowDialog(this) == DialogResult.OK) { GXByteBuffer bb = new GXByteBuffer(); bb.SetUInt8((byte)DataType.OctetString); byte[] str = GXDLMSTranslator.HexToBytes(dlg.GetValue()); bb.SetUInt8((byte)str.Length); bb.Set(str); arg.Value = bb.Array(); } else { arg.Handled = true; } } }
void OnShowDlg(GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new ShowDlgEventHandler(OnShowDlg), arg).AsyncWaitHandle.WaitOne(); } else { GXTextDlg dlg; IPv6AddressType type; GXDLMSIp6Setup target = Target as GXDLMSIp6Setup; if (arg.Index == 1) { if (AddressTab.SelectedIndex == 0) { dlg = new GXTextDlg("Add Unicast Address", "Unicast address:", "", typeof(IPAddress)); type = IPv6AddressType.Unicast; } else if (AddressTab.SelectedIndex == 1) { dlg = new GXTextDlg("Add Multicast IP Address", "Multicast address:", "", typeof(IPAddress)); type = IPv6AddressType.Multicast; } else if (AddressTab.SelectedIndex == 2) { dlg = new GXTextDlg("Add Gateway IP Address", "Gateway address:", "", typeof(IPAddress)); type = IPv6AddressType.Gateway; } else { throw new ArgumentOutOfRangeException(); } if (dlg.ShowDialog(this) == DialogResult.OK) { IPAddress addr = IPAddress.Parse(dlg.GetValue()); arg.Value = target.AddAddress(arg.Client, type, addr); } else { arg.Handled = true; } } else if (arg.Index == 2) { if (AddressTab.SelectedIndex == 0 && UnicastAddressView.SelectedItems.Count != 0) { ListViewItem li = UnicastAddressView.SelectedItems[0]; IPAddress address = (IPAddress)li.Tag; UnicastAddressView.Items.Remove(li); arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Unicast, address); } else if (AddressTab.SelectedIndex == 1 && MulticastAddressView.SelectedItems.Count != 0) { ListViewItem li = MulticastAddressView.SelectedItems[0]; IPAddress address = (IPAddress)li.Tag; MulticastAddressView.Items.Remove(li); arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Multicast, address); } else if (AddressTab.SelectedIndex == 2 && GatewayAddressView.SelectedItems.Count != 0) { ListViewItem li = GatewayAddressView.SelectedItems[0]; IPAddress address = (IPAddress)li.Tag; GatewayAddressView.Items.Remove(li); arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Gateway, address); } else { throw new ArgumentOutOfRangeException(); } } else { arg.Handled = true; } } }
void OnShowDlg(GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new ShowDlgEventHandler(OnShowDlg), arg).AsyncWaitHandle.WaitOne(); } else { if (arg.Index == 1) { GXTextDlg dlg = new GXTextDlg(Properties.Resources.InstallMBusClient, Properties.Resources.Address, "0", typeof(sbyte)); if (dlg.ShowDialog(this) == DialogResult.OK) { arg.Value = sbyte.Parse(dlg.GetValue()); } else { arg.Handled = true; } } else if (arg.Index == 2) { GXTextDlg dlg = new GXTextDlg(Properties.Resources.DeInstallMBusClient, Properties.Resources.Address, "0", typeof(sbyte)); arg.Handled = dlg.ShowDialog(this) != DialogResult.OK; } else if (arg.Index == 6) { GXMBusClientData data = new GXMBusClientData(); GXDLMSMBusClientDataDlg dlg = new GXDLMSMBusClientDataDlg(data); if (dlg.ShowDialog(this) == DialogResult.OK) { GXMBusClientData[] arr = new GXMBusClientData[] { data }; GXDLMSMBusClient target = Target as GXDLMSMBusClient; arg.Value = target.SendData(arg.Client, arr); } else { arg.Handled = true; } } else if (arg.Index == 7) { GXTextDlg dlg = new GXTextDlg("Set encryption key.", "Key:", "", typeof(byte[])); if (dlg.ShowDialog(this) == DialogResult.OK) { GXDLMSMBusClient target = Target as GXDLMSMBusClient; arg.Value = target.SetEncryptionKey(arg.Client, GXDLMSTranslator.HexToBytes(dlg.GetValue())); } else { arg.Handled = true; } } else if (arg.Index == 8) { GXTextDlg dlg = new GXTextDlg("Transfer encryption key.", "Key:", "", typeof(byte[])); if (dlg.ShowDialog(this) == DialogResult.OK) { GXDLMSMBusClient target = Target as GXDLMSMBusClient; arg.Value = target.TransferKey(arg.Client, GXDLMSTranslator.HexToBytes(dlg.GetValue())); } else { arg.Handled = true; } } else { arg.Handled = true; } } }