| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 | using IMCS.DefaultList;using IMCS.Logic;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using YG;namespace IMCS.UControl{    public partial class UserControl3 : UserControl    {        private short taskRun = 0;        bool Run = false;        short StartIndex = 0;        short EndIndex = 0;        public System.ComponentModel.BindingList<WeiLiTaskDefaultList> CurrentTask = new BindingList<WeiLiTaskDefaultList>();        public UserControl3()        {            InitializeComponent();            this.Load += UserControl3_Load;        }        YG.Device.DeviceS7 s7;        ZhiLiangZhongXinHandle longHaiTe;        private void UserControl3_Load(object sender, EventArgs e)        {            longHaiTe = new ZhiLiangZhongXinHandle();            longHaiTe.DeviceInit();            longHaiTe.DeviceStart();            longHaiTe.Msg += LongHaiTe_Msg;            foreach (Control cc in this.tableLayoutPanel1.Controls)            {                if (cc is Label)                {                    Label lb = (Label)cc;                    if (!lb.Tag.Equals("999"))                    {                        lb.AllowDrop = true;                        lb.MouseMove += new MouseEventHandler(Lb_MouseDown1);                        lb.DragEnter += new DragEventHandler(Label_DragEnter);                        lb.DragDrop += new DragEventHandler(Label_DragDrop);                    }                    lb.BackColor = System.Drawing.Color.AliceBlue;                    lb.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;                    lb.AutoSize = false;                    lb.Width = 100;                    lb.Height = 45;                }            }            Task.Factory.StartNew(async () =>            {                while (true && !Run)                {                    await Task.Delay(100);                    if (CurrentTask.Where(m => !m.Task_GameOver).Count() > 0)                    {                        CurrentTask.Where(m => !m.Task_GameOver).FirstOrDefault().FirstOrDefaultYG((t) =>                        {                            if (!t.Task_Send)                            {                                Write_Plc((short)t.Task_Index, t.Task_StartIndex, t.Task_EndIndex, t.Task_Operation);                                t.Task_Send = true;                            }                        });                    }                }            });        }        private void Lb_MouseDown1(object sender, MouseEventArgs e)        {            Label startlable = sender as Label;            if ((e.Button == System.Windows.Forms.MouseButtons.Left))            {                startlable.DoDragDrop(startlable, DragDropEffects.Copy | DragDropEffects.Move);                //形成拖拽效果,移动+拷贝的组合效果                 }        }        private void Label_DragEnter(object sender, DragEventArgs e)        {            e.Effect = DragDropEffects.Copy;        }        private void Write_Plc(short title, short start, short end, short operatio)        {            lb_TaskId.Invoke(new Action(() => { lb_TaskId.Text = $"ID:{title}"; }));// .Text = $"执行任务ID{title}";            lb_StartPoint.Invoke(new Action(() => { lb_StartPoint.Text = $"起点:{start}"; }));//.Text = $"任务执行起点{start}";            lb_EndPoint.Invoke(new Action(() => { lb_EndPoint.Text = $"终点:{end}"; }));//.Text = $"任务结束点{end}";            lb_Run.Invoke(new Action(() => { lb_Run.Text = $"执行:{operatio}"; }));            taskRun = operatio;            longHaiTe.DeviceSend("DB200.44", title);            System.Threading.Thread.Sleep(500);            longHaiTe.DeviceSend("DB200.46", start);            System.Threading.Thread.Sleep(500);            longHaiTe.DeviceSend("DB200.48", end);            System.Threading.Thread.Sleep(500);            longHaiTe.DeviceSend("DB200.50", operatio);        }        private void Label_DragDrop(object sender, DragEventArgs e)        {            Label lb = (Label)sender;            EndIndex = (short)lb.Tag.ObjectToInt();            var cc = (Label)e.Data.GetData(typeof(Label));            StartIndex = cc.Tag.ObjectToShort();            Run = false;            {                CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_Type = TaskType.取, Task_StartIndex = StartIndex });                CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 4, Task_Type = TaskType.放, Task_StartIndex = StartIndex });            }        }        private void LongHaiTe_Msg(string obje1, string obje2, string obje3)        {            System.Console.WriteLine($"{obje1}-->>{obje2}-->{obje3}");            if (obje3.Length - obje3.Replace(",", "").Length != 1)            {                MessageBox.Show("接受到的值解析出现问题");                return;            }            string[] vs = obje3.Split(new string[] { "," }, StringSplitOptions.None);            short state = vs[1].ObjectToShort();            lb_RunState.Invoke(new Action(() => { lb_RunState.Text = "状态:" + state.ToString(); }));            CurrentTask.Where(m => m.Task_Index.Equals(vs[0].StringToInt())).FirstOrDefault().FirstOrDefaultYG((t) =>            {                if (t.Task_Type.Equals(TaskType.取) && state == 3)                {                    t.Task_GameOver = true;                }                else if (t.Task_Type.Equals(TaskType.放) && state == 6)                {                    t.Task_GameOver = true;                }                else if (t.Task_Type.Equals(TaskType.移动) && state == 8)                {                    t.Task_GameOver = true;                }                t.Task_RunState = state;            });        }    }}
 |