DebugRollerUI.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 DebugRollerUI : UserControl,IDisplayUI
  15. {
  16. public DebugRollerUI()
  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. }
  29. public void UpdateDisplay()
  30. {
  31. if (!this.Visible) return;
  32. var dataList = DeviceControl.Instance.Communication.InfoRollerDictionary.Values.ToList();
  33. dataGridUI1.ShowDataGrid(dataList);
  34. }
  35. private void button1_Click(object sender, EventArgs e)
  36. {
  37. try
  38. {
  39. int deviceId = int.Parse(textBox1.Text);
  40. //if (!DeviceControl.Instance.Communication.InfoRollerDictionary.ContainsKey(deviceId))
  41. //{
  42. // MessageBox.Show($"当前没有设备ID{deviceId}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  43. // return;
  44. //}
  45. button2_Click(null, null);
  46. ushort code = ushort.Parse(comboBox2.Text);
  47. DeviceControl.Instance.RollerOperate(deviceId, code);
  48. }
  49. catch (Exception ex)
  50. {
  51. CLog.Instance.SystemLog.WriteException("UI", ex);
  52. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  53. }
  54. }
  55. private void button3_Click(object sender, EventArgs e)
  56. {
  57. int deviceId = int.Parse(textBox1.Text);
  58. //if (!DeviceControl.Instance.Communication.InfoRollerDictionary.ContainsKey(deviceId))
  59. //{
  60. // MessageBox.Show($"当前没有设备ID{deviceId}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  61. // return;
  62. //}
  63. DeviceControl.Instance.RollerOperateClear(deviceId);
  64. }
  65. private void button2_Click(object sender, EventArgs e)
  66. {
  67. ushort newOutput = 0;
  68. foreach (var item in panel2.Controls)
  69. {
  70. var checkBox = item as CheckBox;
  71. if (checkBox != null)
  72. {
  73. int index = int.Parse(checkBox.Text.Substring(7));
  74. if (checkBox.Checked)
  75. {
  76. newOutput = (ushort)(newOutput | (0x01 << index));
  77. }
  78. else
  79. {
  80. newOutput = (ushort)(newOutput & (ushort.MaxValue - (1 << index)));
  81. }
  82. }
  83. }
  84. comboBox2.Text = newOutput.ToString();
  85. }
  86. }
  87. }