SleepAndWakeUpForm.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using AGV_WPF_Global;
  10. using System.Threading;
  11. namespace AGV_WPF
  12. {
  13. public partial class SleepAndWakeUpForm : Form
  14. {
  15. private delegate void InvokeDelegate();
  16. List<int> listAll = new List<int>();
  17. int ActionCode = 0;
  18. Thread t; bool b = true;
  19. public SleepAndWakeUpForm()
  20. {
  21. InitializeComponent();
  22. for (int i = 1; i <= Convert.ToUInt32(System.Configuration.ConfigurationManager.AppSettings["AGVNUM_MAX"]); i++)
  23. {
  24. listAll.Add(i);
  25. }
  26. }
  27. private void SleepAndWakeUpForm_Load(object sender, EventArgs e)
  28. {
  29. if (GlobalPara.IsOneKeySleep)
  30. {
  31. label1.Text = label1.Text.Replace("key", "休眠");
  32. ActionCode = 0x20;
  33. }
  34. else
  35. {
  36. label1.Text = label1.Text.Replace("key", "唤醒");
  37. ActionCode = 0x30;
  38. }
  39. this.FormClosed += new FormClosedEventHandler(SleepAndWakeUpForm_FormClosed);
  40. //timer1.Interval = 200;
  41. //timer1.Tick += new EventHandler(timer1_Tick);
  42. //timer1.Enabled = true;
  43. //timer1.Start();
  44. t = new Thread(new ThreadStart(update));
  45. t.Start();
  46. }
  47. void SleepAndWakeUpForm_FormClosed(object sender, FormClosedEventArgs e)
  48. {
  49. //throw new NotImplementedException();
  50. b = false;
  51. }
  52. void update()
  53. {
  54. try
  55. {
  56. while (b)
  57. {
  58. textBox1.Invoke(new InvokeDelegate(delegate
  59. {
  60. if (GlobalPara.IsOneKeySleep)
  61. {
  62. textBox1.Text = string.Join(",", listAll.Except(GlobalPara.SleepAGVNumList).ToArray());
  63. }
  64. else
  65. {
  66. textBox1.Text = string.Join(",", listAll.Except(GlobalPara.WakeUpAGVNumList).ToArray());
  67. }
  68. }
  69. ));
  70. Thread.Sleep(200);
  71. }
  72. }
  73. catch (Exception)
  74. {
  75. }
  76. }
  77. void timer1_Tick(object sender, EventArgs e)
  78. {
  79. //throw new NotImplementedException();
  80. // textBox1.Invoke(new InvokeDelegate(delegate
  81. {
  82. if (GlobalPara.IsOneKeySleep)
  83. {
  84. textBox1.Text = string.Join(",", listAll.Except(GlobalPara.SleepAGVNumList).ToArray());
  85. }
  86. else
  87. {
  88. textBox1.Text = string.Join(",", listAll.Except(GlobalPara.WakeUpAGVNumList).ToArray());
  89. }
  90. }
  91. // ));
  92. //if (GlobalPara.IsOneKeySleep)
  93. //{
  94. // if (GlobalPara.WakeUpAGVNumList.Count == 0)
  95. // {
  96. // MessageBox.Show("已休眠所有AGV");
  97. // this.timer1.Tick -= timer1_Tick;
  98. // this.timer1.Stop();
  99. // this.Close();
  100. // }
  101. //}
  102. //else
  103. //{
  104. // if (GlobalPara.SleepAGVNumList.Count == 0)
  105. // {
  106. // MessageBox.Show("已唤醒所有AGV");
  107. // this.timer1.Tick -= timer1_Tick;
  108. // this.timer1.Stop();
  109. // this.Close();
  110. // }
  111. //}
  112. }
  113. private void button1_Click(object sender, EventArgs e)
  114. {
  115. if (textBox1.Text.Length > 0)
  116. {
  117. string[] text = textBox1.Text.Split(',');
  118. foreach (string str in text)
  119. {
  120. AGV_WPF.Tools.DispatcherTool.ControlAllAgv(ActionCode, 0, int.Parse(str), true);
  121. }
  122. }
  123. }
  124. }
  125. }