123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using AGV_WPF_Global;
- using System.Threading;
- namespace AGV_WPF
- {
- public partial class SleepAndWakeUpForm : Form
- {
- private delegate void InvokeDelegate();
- List<int> listAll = new List<int>();
- int ActionCode = 0;
- Thread t; bool b = true;
- public SleepAndWakeUpForm()
- {
- InitializeComponent();
- for (int i = 1; i <= Convert.ToUInt32(System.Configuration.ConfigurationManager.AppSettings["AGVNUM_MAX"]); i++)
- {
- listAll.Add(i);
- }
- }
- private void SleepAndWakeUpForm_Load(object sender, EventArgs e)
- {
- if (GlobalPara.IsOneKeySleep)
- {
- label1.Text = label1.Text.Replace("key", "休眠");
- ActionCode = 0x20;
- }
- else
- {
- label1.Text = label1.Text.Replace("key", "唤醒");
- ActionCode = 0x30;
- }
- this.FormClosed += new FormClosedEventHandler(SleepAndWakeUpForm_FormClosed);
- //timer1.Interval = 200;
- //timer1.Tick += new EventHandler(timer1_Tick);
- //timer1.Enabled = true;
- //timer1.Start();
- t = new Thread(new ThreadStart(update));
- t.Start();
- }
- void SleepAndWakeUpForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- //throw new NotImplementedException();
- b = false;
- }
- void update()
- {
- try
- {
- while (b)
- {
- textBox1.Invoke(new InvokeDelegate(delegate
- {
- if (GlobalPara.IsOneKeySleep)
- {
- textBox1.Text = string.Join(",", listAll.Except(GlobalPara.SleepAGVNumList).ToArray());
- }
- else
- {
- textBox1.Text = string.Join(",", listAll.Except(GlobalPara.WakeUpAGVNumList).ToArray());
- }
- }
- ));
- Thread.Sleep(200);
- }
- }
- catch (Exception)
- {
- }
- }
- void timer1_Tick(object sender, EventArgs e)
- {
- //throw new NotImplementedException();
- // textBox1.Invoke(new InvokeDelegate(delegate
- {
- if (GlobalPara.IsOneKeySleep)
- {
- textBox1.Text = string.Join(",", listAll.Except(GlobalPara.SleepAGVNumList).ToArray());
- }
- else
- {
- textBox1.Text = string.Join(",", listAll.Except(GlobalPara.WakeUpAGVNumList).ToArray());
- }
- }
- // ));
- //if (GlobalPara.IsOneKeySleep)
- //{
- // if (GlobalPara.WakeUpAGVNumList.Count == 0)
- // {
- // MessageBox.Show("已休眠所有AGV");
- // this.timer1.Tick -= timer1_Tick;
- // this.timer1.Stop();
- // this.Close();
- // }
- //}
- //else
- //{
- // if (GlobalPara.SleepAGVNumList.Count == 0)
- // {
- // MessageBox.Show("已唤醒所有AGV");
- // this.timer1.Tick -= timer1_Tick;
- // this.timer1.Stop();
- // this.Close();
- // }
- //}
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox1.Text.Length > 0)
- {
- string[] text = textBox1.Text.Split(',');
- foreach (string str in text)
- {
- AGV_WPF.Tools.DispatcherTool.ControlAllAgv(ActionCode, 0, int.Parse(str), true);
- }
- }
- }
- }
- }
|