private UlEthernetClient GetEthernetClient(int index, int row) { UlEthernetClient client = null; switch (index) { case 0: client = Resource.Server.Devices.PowerMeter[row]; break; case 1: client = Resource.Server.Devices.Recorder[row]; break; case 2: client = Resource.Server.Devices.Controller[row]; break; case 3: client = Resource.Server.Devices.Plc[row]; break; } return(client); }
private void modifyButton_Click(object sender, EventArgs args) { if (Resource.Authority > EUserAuthority.Admin) { return; } int tag = int.Parse((sender as Button).Tag.ToString()); GridView view = GetGridView(tag); if (view.FocusedRowHandle < 0) { return; } UlEthernetClient client = GetEthernetClient(tag, view.FocusedRowHandle); FormDeviceEdit form = new FormDeviceEdit(); form.Text = $"{client.Name} Modify"; Resource.TLog.Log((int)ELogItem.Note, $"Clicked {form.Text} button."); form.linkCombo.SelectedIndex = (client.Connected == false) ? (int)EEthernetLink.Disconnect : (int)EEthernetLink.Connect; form.modeCombo.SelectedIndex = (int)client.Mode; if (form.ShowDialog() == DialogResult.OK) { bool link = (form.linkCombo.SelectedIndex == (int)EEthernetLink.Disconnect) ? false : true; if (client.Connected != link) { try { if (link == true) { Resource.TLog.Log((int)ELogItem.Note, $"Try to Connect TCP socket of {client.Name}"); client.Close(); client.Connect(); Resource.TLog.Log((int)ELogItem.Note, $"Connected TCP socket of {client.Name}"); } else { client.Close(); Resource.TLog.Log((int)ELogItem.Note, $"Disconnected TCP socket of {client.Name}"); } client.Mode = (EEthernetMode)form.modeCombo.SelectedIndex; Resource.TLog.Log((int)ELogItem.Note, $"Changed mode of {client.Name} to {client.Mode.ToString()}"); } catch (Exception e) { Resource.TLog.Log((int)ELogItem.Exception, e.ToString()); MessageBox.Show( $"Can't change mode of {client.Name}!\r\nPlease check this device and cabling.", Resource.Caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } view.RefreshData(); } }