DebugIOUI.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using ProjectManagementSystem.Common.Core;
  2. using ProjectManagementSystem.Common.Logger;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace ProjectManagementSystem.UI
  13. {
  14. public partial class DebugIOUI : UserControl, IDisplayUI
  15. {
  16. public DebugIOUI()
  17. {
  18. InitializeComponent();
  19. }
  20. public bool Init()
  21. {
  22. dataGridUI1.dataGridView1.CellClick += DataGridView1_CellClick;
  23. return true;
  24. }
  25. private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  26. {
  27. textBox1.Text = dataGridUI1.GetCurrentColValue("DeviceId");
  28. foreach (var item in panel2.Controls)
  29. {
  30. var checkBox = item as CheckBox;
  31. if(checkBox != null)
  32. {
  33. checkBox.Checked = bool.Parse(dataGridUI1.GetCurrentColValue($"Y{checkBox.Text.Substring(1)}"));
  34. }
  35. }
  36. }
  37. public void UpdateDisplay()
  38. {
  39. if (!this.Visible) return;
  40. var dataList = DeviceControl.Instance.Communication.InfoIODictionary.Values.ToList();
  41. dataGridUI1.ShowDataGrid(dataList);
  42. }
  43. private void button1_Click(object sender, EventArgs e)
  44. {
  45. try
  46. {
  47. int deviceId = int.Parse(textBox1.Text);
  48. ushort newOutput = 0;
  49. foreach (var item in panel2.Controls)
  50. {
  51. var checkBox = item as CheckBox;
  52. if (checkBox != null)
  53. {
  54. int index = int.Parse(checkBox.Text.Substring(1)) - 1;
  55. if (checkBox.Checked)
  56. {
  57. newOutput = (ushort)(newOutput | (0x01 << index));
  58. }
  59. else
  60. {
  61. newOutput = (ushort)(newOutput & (ushort.MaxValue - (1 << index)));
  62. }
  63. }
  64. }
  65. DeviceControl.Instance.SetOutputIO(deviceId, newOutput);
  66. }
  67. catch (Exception ex)
  68. {
  69. CLog.Instance.SystemLog.WriteException("UI", ex);
  70. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  71. }
  72. }
  73. }
  74. }