DispatchPackUI.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. using DbCommon.BusinessCore.BaseCore;
  2. using ProjectManagementSystem.Common.Core;
  3. using ProjectManagementSystem.Common.Logger;
  4. using ProjectManagementSystem.DispatchPack;
  5. using ProjectManagementSystem.DispatchPack.Entity;
  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 DispatchPackUI : UserControl, IDisplayUI
  18. {
  19. private StationInfoManager stationInfoManager = new StationInfoManager();
  20. public DispatchPackUI()
  21. {
  22. InitializeComponent();
  23. }
  24. public bool Init()
  25. {
  26. try
  27. {
  28. PackEngine.Instance.OnDisplayInfo += Instance_OnDisplayInfo;
  29. PackEngine.Instance.OnDisplayEntityInfo += Instance_OnDisplayEntityInfo;
  30. PackEngine.Instance.OnStart += Instance_OnStart;
  31. return true;
  32. }
  33. catch (Exception ex)
  34. {
  35. CLog.Instance.TaskLog.WriteException("UI", ex);
  36. }
  37. return false;
  38. }
  39. private void Instance_OnStart()
  40. {
  41. this.Invoke(new MethodInvoker(delegate
  42. {
  43. InitStationUI();
  44. }));
  45. }
  46. private void InitStationUI()
  47. {
  48. this.tabControl1.Controls.Clear();
  49. var entityList = PackEngine.Instance.EntityBaseList;
  50. for (int i = 0; i < entityList.Count; i++)
  51. {
  52. EntityBase entity = entityList[i];
  53. var tabPage = new System.Windows.Forms.TabPage();
  54. tabPage.Location = new System.Drawing.Point(8, 39);
  55. tabPage.Name = string.Format("tabPage{0}", i + 1);
  56. tabPage.Padding = new System.Windows.Forms.Padding(3);
  57. tabPage.Size = new System.Drawing.Size(1396, 474);
  58. tabPage.TabIndex = i;
  59. tabPage.Text = entity.LineInfo.Name;
  60. tabPage.UseVisualStyleBackColor = true;
  61. var flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
  62. flowLayoutPanel.Name = string.Format("flowLayoutPanel{0}", i + 1);
  63. flowLayoutPanel.Dock = DockStyle.Fill;
  64. flowLayoutPanel.AutoScroll = true;
  65. foreach (var item in entity.StationInfoList)
  66. {
  67. StationUI stationUI = new StationUI();
  68. stationUI.Init(item);
  69. stationUI.Display();
  70. flowLayoutPanel.Controls.Add(stationUI);
  71. PackEngine.Instance.StationUIList.Add(stationUI);
  72. }
  73. tabPage.Controls.Add(flowLayoutPanel);
  74. this.tabControl1.Controls.Add(tabPage);
  75. }
  76. }
  77. public void UpdateDisplay()
  78. {
  79. //if (!Visible) return;
  80. //var stationUIList = CoreEngine.Instance.StationUIList;
  81. //for (int i = 0; i < stationUIList.Count; i++)
  82. //{
  83. // var btn = stationUIList[i];
  84. // btn.BeginInvoke(new MethodInvoker(delegate
  85. // {
  86. // btn.Display();
  87. // }));
  88. //}
  89. }
  90. private void Instance_OnDisplayEntityInfo(EntityBase arg1, string arg2)
  91. {
  92. foreach (Control item in this.tabControl1.Controls)
  93. {
  94. if (item.TabIndex == arg1.Index)
  95. {
  96. this.BeginInvoke((Action)(() =>
  97. {
  98. item.Text = string.Format("{0}({1})", arg1.LineInfo.Name, arg2);
  99. }));
  100. break;
  101. }
  102. }
  103. }
  104. private void Instance_OnDisplayInfo(string obj)
  105. {
  106. this.BeginInvoke((Action)(() =>
  107. {
  108. label1.Text = obj;
  109. }));
  110. }
  111. private async Task RailAgvOperate(object sender, Action<int> action)
  112. {
  113. (sender as Control).Enabled = false;
  114. int agvMaxNum = PackEngine.Instance.AgvMaxNum;
  115. await Task.Factory.StartNew(() =>
  116. {
  117. for (int index = 0; index < 3; index++)
  118. {
  119. for (int i = 1; i <= agvMaxNum; i++)
  120. {
  121. action.Invoke(i);
  122. System.Threading.Thread.Sleep(20);
  123. }
  124. System.Threading.Thread.Sleep(100);
  125. }
  126. });
  127. (sender as Control).Enabled = true;
  128. (sender as Control).Focus();
  129. }
  130. private async void button1_Click(object sender, EventArgs e)
  131. {
  132. var speed = numericUpDown1.Value;
  133. await RailAgvOperate(sender, id => DeviceControl.Instance.RailAgv_SpeedChange(id, speed));
  134. }
  135. private async void button2_Click(object sender, EventArgs e)
  136. {
  137. await RailAgvOperate(sender, id => DeviceControl.Instance.RailAgv_StartButton(id));
  138. }
  139. private async void button3_Click(object sender, EventArgs e)
  140. {
  141. await RailAgvOperate(sender, id => DeviceControl.Instance.RailAgv_StopButton(id));
  142. }
  143. private void button4_Click(object sender, EventArgs e)
  144. {
  145. int interval = (int)numericUpDown2.Value;
  146. int alarm = (int)numericUpDown3.Value;
  147. CountDown(interval, alarm);
  148. }
  149. private void button5_Click(object sender, EventArgs e)
  150. {
  151. int interval = 0;
  152. int alarm = 0;
  153. CountDown(interval, alarm);
  154. }
  155. private void CountDown(int interval, int alarm)
  156. {
  157. var dataList = stationInfoManager.GetList();
  158. for (int i = 0; i < dataList.Count; i++)
  159. {
  160. dataList[i].CountInterval = interval;
  161. dataList[i].CountAlarm = alarm;
  162. }
  163. bool result = stationInfoManager.UpdateCountdown(dataList);
  164. if (result)
  165. {
  166. MessageBox.Show("操作成功");
  167. }
  168. else
  169. {
  170. MessageBox.Show("操作失败");
  171. }
  172. }
  173. }
  174. }