DebugRailAgvUI.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using ProjectManagementSystem.Common.Core;
  2. using ProjectManagementSystem.Common.Extenions;
  3. using ProjectManagementSystem.Common.Logger;
  4. using ProjectManagementSystem.Device.CommandCallback;
  5. using ProjectManagementSystem.Device.Extenions;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace ProjectManagementSystem.UI
  16. {
  17. public partial class DebugRailAgvUI : UserControl, IDisplayUI
  18. {
  19. public DebugRailAgvUI()
  20. {
  21. InitializeComponent();
  22. }
  23. public bool Init()
  24. {
  25. dataGridUI1.dataGridView1.CellClick += DataGridView1_CellClick;
  26. this.comboBoxStatus.ValueMember = "Value";
  27. this.comboBoxStatus.DisplayMember = "Display";
  28. this.comboBoxStatus.DataSource = EnumInfoAgvStatus.None.EnumToDataTable("Value", "Display");
  29. return true;
  30. }
  31. private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  32. {
  33. textBox1.Text = dataGridUI1.GetCurrentColValue("Mark");
  34. textBox2.Text = dataGridUI1.GetCurrentColValue("Route");
  35. textBox3.Text = dataGridUI1.GetCurrentColValue("AgvId");
  36. comboBoxStatus.SelectedValue = int.Parse(dataGridUI1.GetCurrentColValue("Status"));
  37. }
  38. public void UpdateDisplay()
  39. {
  40. if (!this.Visible) return;
  41. var dataList = DeviceControl.Instance.Communication.InfoAgvDictionary.Values.OrderBy(d => d.AgvId).ToList();
  42. dataGridUI1.ShowDataGrid(dataList);
  43. }
  44. private void button1_Click(object sender, EventArgs e)
  45. {
  46. RailAgvOpereate(DeviceControl.Instance.ReleaseAgvOnStop);
  47. }
  48. private void button2_Click(object sender, EventArgs e)
  49. {
  50. RailAgvOpereate(DeviceControl.Instance.ReleaseAgvOnStandby);
  51. }
  52. private void RailAgvOpereate(Action<int, int, int> action)
  53. {
  54. try
  55. {
  56. int mark = int.Parse(textBox1.Text);
  57. int route = int.Parse(textBox2.Text);
  58. int agvId = int.Parse(textBox3.Text);
  59. action(mark, route, agvId);
  60. }
  61. catch (Exception ex)
  62. {
  63. CLog.Instance.SystemLog.WriteException("UI", ex);
  64. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  65. }
  66. }
  67. private void RailAgvSimulate(EnumInfoAgvStatus status)
  68. {
  69. try
  70. {
  71. int mark = int.Parse(textBox1.Text);
  72. int route = int.Parse(textBox2.Text);
  73. int agvId = int.Parse(textBox3.Text);
  74. comboBoxStatus.SelectedValue = status;
  75. RailAgvSimulate(agvId, mark, route, status);
  76. }
  77. catch (Exception ex)
  78. {
  79. CLog.Instance.SystemLog.WriteException("UI", ex);
  80. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  81. }
  82. }
  83. private void RailAgvSimulate(int agvId, int mark, int route, EnumInfoAgvStatus status)
  84. {
  85. try
  86. {
  87. bool isContainsKey = DeviceControl.Instance.Communication.InfoAgvDictionary.ContainsKey(agvId);
  88. var info = isContainsKey ? DeviceControl.Instance.Communication.InfoAgvDictionary[agvId] : new InfoAgv();
  89. info.AgvId = agvId;
  90. info.Mark = mark;
  91. info.Route = route;
  92. info.Status = (int)status;
  93. info.StatusText = info.Status.GetAgvStatusText();
  94. info.LastUpdateTime = DateTime.Now;
  95. DeviceControl.Instance.Communication.InfoAgvDictionary.AddOrUpdate(info.AgvId, info, (key, values) => info);
  96. }
  97. catch (Exception ex)
  98. {
  99. CLog.Instance.SystemLog.WriteException("UI", ex);
  100. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  101. }
  102. }
  103. private void button3_Click(object sender, EventArgs e)
  104. {
  105. RailAgvSimulate((EnumInfoAgvStatus)comboBoxStatus.SelectedValue);
  106. }
  107. private void button4_Click(object sender, EventArgs e)
  108. {
  109. RailAgvSimulate(EnumInfoAgvStatus.停止点);
  110. }
  111. private void button5_Click(object sender, EventArgs e)
  112. {
  113. RailAgvSimulate(EnumInfoAgvStatus.结束点);
  114. }
  115. private void button6_Click(object sender, EventArgs e)
  116. {
  117. RailAgvSimulate(EnumInfoAgvStatus.运行);
  118. }
  119. private void button7_Click(object sender, EventArgs e)
  120. {
  121. for (int i = 1; i <= 10; i++)
  122. {
  123. RailAgvSimulate(i, i, i, (EnumInfoAgvStatus)comboBoxStatus.SelectedValue);
  124. }
  125. }
  126. }
  127. }