UserControl1.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using IMCS.DefaultList;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using YG;
  12. namespace IMCS.UControl
  13. {
  14. public partial class UserControl1 : UserControl
  15. {
  16. bool Run = false;
  17. short StartIndex = 0;
  18. short EndIndex = 0;
  19. IMCS.Logic.WeiLiHandle weiLi;
  20. public System.ComponentModel.BindingList<WeiLiTaskDefaultList> CurrentTask = new BindingList<WeiLiTaskDefaultList>();
  21. public UserControl1()
  22. {
  23. InitializeComponent();
  24. this.Load += UserControl1_Load;
  25. }
  26. bool isRun = false;
  27. private void UserControl1_Load(object sender, EventArgs e)
  28. {
  29. //weiLi = new Logic.WeiLiHandle();
  30. //weiLi.DeviceInit();
  31. //weiLi.DeviceStart();
  32. // weiLi.Msg += WeiLi_Msg;
  33. // CurrentTask = DeviceConfig.Instance.WeiLiTask;
  34. //foreach (control cc in this.tablelayoutpanel1.controls)
  35. //{
  36. // if (cc is label)
  37. // {
  38. // label lb = (label)cc;
  39. // if (!lb.text.equals("控制机柜"))
  40. // {
  41. // lb.allowdrop = true;
  42. // lb.mousedown += new mouseeventhandler(lb_mousedown1);
  43. // lb.dragenter += new drageventhandler(label_dragenter);
  44. // lb.dragdrop += new drageventhandler(label_dragdrop);
  45. // lb.backcolor = system.drawing.color.aliceblue;
  46. // lb.textalign = system.drawing.contentalignment.middlecenter;
  47. // lb.autosize = false;
  48. // lb.width = 60;
  49. // lb.height = 60;
  50. // }
  51. // }
  52. //}
  53. //task.factory.startnew(async () =>
  54. //{
  55. // while (true && !isrun)
  56. // {
  57. // await task.delay(100);
  58. // if (currenttask.where(m => !m.task_gameover).count() > 0)
  59. // {
  60. // currenttask.where(m => !m.task_gameover).firstordefault().firstordefaultyg((t) =>
  61. // {
  62. // if (!t.task_send)
  63. // {
  64. // write_plc((short)t.task_index, t.task_startindex, t.task_endindex, t.task_operation);
  65. // t.task_send = true;
  66. // }
  67. // });
  68. // }
  69. // }
  70. //});
  71. }
  72. private void WeiLi_Msg(string obje1, string obje2, string obje3)
  73. {
  74. System.Console.WriteLine($"{obje1}-->>{obje2}-->{obje3}");
  75. if (obje3.Length - obje3.Replace(",", "").Length != 1)
  76. {
  77. MessageBox.Show("接受到的值解析出现问题");
  78. return;
  79. }
  80. string[] vs = obje3.Split(new string[] { "," }, StringSplitOptions.None);
  81. short state = vs[1].ObjectToShort();
  82. CurrentTask.Where(m => m.Task_Index.Equals(vs[0].StringToInt())).FirstOrDefault().FirstOrDefaultYG((t) =>
  83. {
  84. if (t.Task_Type.Equals(TaskType.取) && state == 3)
  85. {
  86. t.Task_GameOver = true;
  87. }
  88. else if (t.Task_Type.Equals(TaskType.放) && state == 6)
  89. {
  90. t.Task_GameOver = true;
  91. }
  92. else if (t.Task_Type.Equals(TaskType.移动) && state == 8)
  93. {
  94. t.Task_GameOver = true;
  95. }
  96. t.Task_RunState = state;
  97. });
  98. }
  99. private void Lb_MouseDown1(object sender, MouseEventArgs e)
  100. {
  101. Label startlable = sender as Label;
  102. if ((e.Button == System.Windows.Forms.MouseButtons.Left))
  103. {
  104. startlable.DoDragDrop(startlable, DragDropEffects.Copy | DragDropEffects.Move);
  105. //形成拖拽效果,移动+拷贝的组合效果
  106. }
  107. }
  108. private void Label_DragEnter(object sender, DragEventArgs e)
  109. {
  110. e.Effect = DragDropEffects.Copy;
  111. }
  112. private void Write_Plc(short taskid, short start, short end, short operatio)
  113. {
  114. weiLi.DeviceSend("DB200.44", taskid);
  115. weiLi.DeviceSend("DB200.46", start);
  116. weiLi.DeviceSend("DB200.48", end);
  117. weiLi.DeviceSend("DB200.50", operatio);
  118. }
  119. private void Label_DragDrop(object sender, DragEventArgs e)
  120. {
  121. Label lb = (Label)sender;
  122. EndIndex = (short)lb.Tag.ObjectToInt();
  123. var cc = (Label)e.Data.GetData(typeof(Label));
  124. StartIndex = cc.Tag.ObjectToShort();
  125. Run = false;
  126. int currentTaskCount = CurrentTask.Where(m => m.Task_StartIndex.Equals(StartIndex) && m.Task_EndIndex.Equals(EndIndex) && m.Task_GameOver).Count();
  127. if (currentTaskCount > 0)
  128. {
  129. System.Windows.Forms.MessageBox.Show("当前任务列表中存在和拖拽内容相似的任务,当前拖拽不执行");
  130. }
  131. else
  132. {
  133. short item = 0;
  134. if (StartIndex.Equals(124) || StartIndex.Equals(125))
  135. {
  136. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 7, Task_Type = TaskType.移动, Task_StartIndex = StartIndex });
  137. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_StartIndex = StartIndex, Task_Type = TaskType.取 });
  138. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 4, Task_StartIndex = StartIndex, Task_Type = TaskType.放 });
  139. }
  140. else if (EndIndex.Equals(124) || EndIndex.Equals(125))
  141. {
  142. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = StartIndex, Task_Operation = 7, Task_Type = TaskType.移动, Task_StartIndex = StartIndex });
  143. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_StartIndex = StartIndex, Task_Type = TaskType.取 });
  144. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 4, Task_StartIndex = StartIndex, Task_Type = TaskType.放 });
  145. }
  146. else
  147. {
  148. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = StartIndex, Task_Operation = 7, Task_Type = TaskType.移动, Task_StartIndex = StartIndex });
  149. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_StartIndex = StartIndex, Task_Type = TaskType.取 });
  150. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = 124, Task_Operation = 4, Task_StartIndex = StartIndex, Task_Type = TaskType.放 });
  151. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 7, Task_Type = TaskType.移动, Task_StartIndex = StartIndex });
  152. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_StartIndex = 124, Task_Type = TaskType.取 });
  153. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 4, Task_StartIndex = StartIndex, Task_Type = TaskType.放 });
  154. }
  155. }
  156. }
  157. }
  158. }