UserControl5.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using IMCS.Config;
  2. using IMCS.DefaultList;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using YG;
  13. namespace IMCS.UControl
  14. {
  15. public partial class UserControl5 : UserControl
  16. {
  17. public System.ComponentModel.BindingList<WeiLiTaskDefaultList> CurrentTask = new BindingList<WeiLiTaskDefaultList>();
  18. bool Run = false;
  19. short StartIndex = 0;
  20. short EndIndex = 0;
  21. IMCS.Logic.WeiLiHandle weiLi;
  22. public UserControl5()
  23. {
  24. InitializeComponent();
  25. this.Load += (s, e) =>
  26. {
  27. Init();
  28. Label_SetColor(new int[] { 1, 4, 5, 20, 9 });
  29. //this.uctrl_Boot.Click += (t, k) => { };
  30. //this.uctl_agvh.Click += (t, k) => { };
  31. //this.uctl_agvl.Click += (t, k) => { };
  32. //this.uctl_clean.Click += (t, k) => { };
  33. //this.uctl_machine.Click += (t, k) => { };
  34. //this.uctl_print.Click += (t, k) => { };
  35. //this.uctrl_Boot.MouseDown += new MouseEventHandler(Uctrl_Boot_MouseDown);
  36. //this.uctrl_Boot.DragEnter += new DragEventHandler(Uctrl_Boot_DragEnter);
  37. //this.uctrl_Boot.DragDrop += new DragEventHandler(Uctrl_Boot_DragDrop);
  38. //this.uctl_agvh.MouseDown += new MouseEventHandler(Uctrl_Boot_MouseDown);
  39. //this.uctl_agvh.DragEnter += new DragEventHandler(Uctrl_Boot_DragEnter);
  40. //this.uctl_agvh.DragDrop += new DragEventHandler(Uctrl_Boot_DragDrop); ;
  41. //this.uctl_agvl.MouseDown += new MouseEventHandler(Uctrl_Boot_MouseDown);
  42. //this.uctl_agvl.DragEnter += new DragEventHandler(Uctrl_Boot_DragEnter);
  43. //this.uctl_agvl.DragDrop += new DragEventHandler(Uctrl_Boot_DragDrop);
  44. //this.uctl_clean.MouseDown += new MouseEventHandler(Uctrl_Boot_MouseDown);
  45. //this.uctl_clean.DragEnter += new DragEventHandler(Uctrl_Boot_DragEnter);
  46. //this.uctl_clean.DragDrop += new DragEventHandler(Uctrl_Boot_DragDrop);
  47. //this.uctl_machine.MouseDown += new MouseEventHandler(Uctrl_Boot_MouseDown);
  48. //this.uctl_machine.DragEnter += new DragEventHandler(Uctrl_Boot_DragEnter);
  49. //this.uctl_machine.DragDrop += new DragEventHandler(Uctrl_Boot_DragDrop); ;
  50. //this.uctl_print.MouseDown += new MouseEventHandler(Uctrl_Boot_MouseDown);
  51. //this.uctl_print.DragEnter += new DragEventHandler(Uctrl_Boot_DragEnter);
  52. //this.uctl_print.DragDrop += new DragEventHandler(Uctrl_Boot_DragDrop); ;
  53. //this.uctl_agvh.UserControlMouseDown += new UserControlBase.Delegate_MouseDownTag(Uctl_agvh_UserControlMouseDown);
  54. //this.uctrl_Boot.UserControlMouseDown += new UserControlBase.Delegate_MouseDownTag(Uctl_agvh_UserControlMouseDown);
  55. //this.uctl_print.UserControlMouseDown += new UserControlBase.Delegate_MouseDownTag(Uctl_agvh_UserControlMouseDown);
  56. //this.uctl_clean.UserControlMouseDown += new UserControlBase.Delegate_MouseDownTag(Uctl_agvh_UserControlMouseDown);
  57. //this.uctl_machine.UserControlMouseDown += new UserControlBase.Delegate_MouseDownTag(Uctl_agvh_UserControlMouseDown);
  58. this.SizeChanged += (t, k) =>
  59. {
  60. this.tableLayoutPanel3.SetRowSpan(this.uctrl_Boot, 5);
  61. var cc = (this.pan_botton.Width) - this.tableLayoutPanel1.Width;
  62. if (cc > 500)
  63. {
  64. this.tableLayoutPanel1.Width += 300;
  65. this.pan_botton.Padding = new Padding(0, 0, 100, 0);
  66. }
  67. else if (cc < 100)
  68. {
  69. this.tableLayoutPanel1.Width -= 300;
  70. this.pan_botton.Padding = new Padding(0, 0, 0, 0);
  71. }
  72. };
  73. };
  74. }
  75. private void Uctl_agvh_UserControlMouseDown(int value)
  76. {
  77. }
  78. private void Uctrl_Boot_MouseDown(object sender, MouseEventArgs e)
  79. {
  80. UserControlBase userControl = sender as UserControlBase;
  81. if ((e.Button == System.Windows.Forms.MouseButtons.Left))
  82. {
  83. System.Console.WriteLine($"Uctrl_Boot_MouseDown;=>{userControl.Tag}--->.{userControl.Name}");
  84. userControl.DoDragDrop(userControl, DragDropEffects.Copy | DragDropEffects.Move);
  85. //形成拖拽效果,移动+拷贝的组合效果
  86. }
  87. else if (e.Button.Equals(MouseButtons.Right))
  88. {
  89. Point pt = new Point();
  90. pt.Offset(e.Location.X, e.Location.Y);
  91. userControl.popupMenu1.ShowPopup(Control.MousePosition);
  92. }
  93. }
  94. private void Uctrl_Boot_DragDrop(object sender, DragEventArgs e)
  95. {
  96. UserControlBase userControl = sender as UserControlBase;
  97. UserControlBase userControl1 = e.Data as UserControlBase;
  98. System.Console.WriteLine($"EndIndex;=>{userControl.UserTag}--->{userControl.Name}");
  99. userControl.DoDragDrop(userControl, DragDropEffects.None);
  100. }
  101. private void Uctrl_Boot_DragEnter(object sender, DragEventArgs e)
  102. {
  103. UserControlBase userControl = sender as UserControlBase;
  104. StartIndex = userControl.UserTag;
  105. e.Effect = DragDropEffects.Copy;
  106. System.Console.WriteLine($"startindex;=>{StartIndex}");
  107. }
  108. private void Write_Plc(short taskid, short start, short end, short operatio)
  109. {
  110. weiLi.DeviceSend("DB200.44", taskid);
  111. weiLi.DeviceSend("DB200.46", start);
  112. weiLi.DeviceSend("DB200.48", end);
  113. weiLi.DeviceSend("DB200.50", operatio);
  114. }
  115. private void Label_DragDrop(object sender, DragEventArgs e)
  116. {
  117. Label lb = (Label)sender;
  118. EndIndex = (short)lb.Tag.ObjectToInt();
  119. var cc = (Label)e.Data.GetData(typeof(Label));
  120. StartIndex = cc.Tag.ObjectToShort();
  121. Run = false;
  122. int currentTaskCount = CurrentTask.Where(m => m.Task_StartIndex.Equals(StartIndex) && m.Task_EndIndex.Equals(EndIndex) && m.Task_GameOver).Count();
  123. if (currentTaskCount > 0)
  124. {
  125. System.Windows.Forms.MessageBox.Show("当前任务列表中存在和拖拽内容相似的任务,当前拖拽不执行");
  126. }
  127. else
  128. {
  129. short item = 0;
  130. if (StartIndex.Equals(124) || StartIndex.Equals(125))
  131. {
  132. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 7, Task_Type = TaskType.移动, Task_StartIndex = StartIndex });
  133. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_StartIndex = StartIndex, Task_Type = TaskType.取 });
  134. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 4, Task_StartIndex = StartIndex, Task_Type = TaskType.放 });
  135. }
  136. else if (EndIndex.Equals(124) || EndIndex.Equals(125))
  137. {
  138. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = StartIndex, Task_Operation = 7, Task_Type = TaskType.移动, Task_StartIndex = StartIndex });
  139. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_StartIndex = StartIndex, Task_Type = TaskType.取 });
  140. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 4, Task_StartIndex = StartIndex, Task_Type = TaskType.放 });
  141. }
  142. else
  143. {
  144. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = StartIndex, Task_Operation = 7, Task_Type = TaskType.移动, Task_StartIndex = StartIndex });
  145. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_StartIndex = StartIndex, Task_Type = TaskType.取 });
  146. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = 124, Task_Operation = 4, Task_StartIndex = StartIndex, Task_Type = TaskType.放 });
  147. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 7, Task_Type = TaskType.移动, Task_StartIndex = StartIndex });
  148. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 1, Task_StartIndex = 124, Task_Type = TaskType.取 });
  149. CurrentTask.Add(new WeiLiTaskDefaultList() { Task_Index = CurrentTask.Count + 1, Task_EndIndex = EndIndex, Task_Operation = 4, Task_StartIndex = StartIndex, Task_Type = TaskType.放 });
  150. }
  151. }
  152. }
  153. private void Init()
  154. {
  155. #region AGV接驳位H
  156. uctl_agvh.deviceStateDefaultList.Device_Name = "AGV接驳位-H";
  157. uctl_agvh.deviceStateDefaultList.Device_OnLine = true;
  158. uctl_agvh.deviceStateDefaultList.Device_ConnectionMes = true;
  159. uctl_agvh.deviceStateDefaultList.Device_Runing = DefaultList.EnumDeviceRunState.RunState_Run;
  160. uctl_agvh.deviceStateDefaultList.Device_Pan = DefaultList.EnumPlateNum.Plate_Zero;
  161. #endregion
  162. #region AGV接驳位-L
  163. uctl_agvl.deviceStateDefaultList.Device_Name = "AGV接驳位-L";
  164. uctl_agvl.deviceStateDefaultList.Device_OnLine = true;
  165. uctl_agvl.deviceStateDefaultList.Device_ConnectionMes = true;
  166. uctl_agvl.deviceStateDefaultList.Device_Runing = DefaultList.EnumDeviceRunState.RunState_Run;
  167. uctl_agvl.deviceStateDefaultList.Device_Pan = DefaultList.EnumPlateNum.Plate_One;
  168. #endregion
  169. #region 柔性线清洗机
  170. uctl_clean.deviceStateDefaultList.Device_Name = "柔性线清洗机";
  171. uctl_clean.deviceStateDefaultList.Device_Pan = DefaultList.EnumPlateNum.Plate_Zero;
  172. uctl_clean.deviceStateDefaultList.Device_OnLine = true;
  173. uctl_clean.deviceStateDefaultList.Device_ConnectionMes = true;
  174. uctl_clean.deviceStateDefaultList.Device_Runing = DefaultList.EnumDeviceRunState.RunState_Run;
  175. #endregion
  176. #region SMU50-5
  177. uctl_machine.deviceStateDefaultList.Device_Name = "SMU50-5";
  178. uctl_machine.deviceStateDefaultList.Device_OnLine = true;
  179. uctl_machine.deviceStateDefaultList.Device_ConnectionMes = true;
  180. uctl_machine.deviceStateDefaultList.Device_Runing = DefaultList.EnumDeviceRunState.RunState_Err;
  181. #endregion
  182. #region 柔性线打标机
  183. uctl_print.deviceStateDefaultList.Device_Name = "柔性线打标机";
  184. uctl_print.deviceStateDefaultList.Device_OnLine = true;
  185. uctl_print.deviceStateDefaultList.Device_ConnectionMes = true;
  186. uctl_print.deviceStateDefaultList.Device_Runing = DefaultList.EnumDeviceRunState.RunState_Run;
  187. #endregion
  188. #region 六轴机器人
  189. uctrl_Boot.deviceStateDefaultList.Device_Name = "六轴机器人";
  190. uctrl_Boot.deviceStateDefaultList.Device_OnLine = true;
  191. uctrl_Boot.deviceStateDefaultList.Device_ConnectionMes = true;
  192. uctrl_Boot.deviceStateDefaultList.Device_Runing = DefaultList.EnumDeviceRunState.RunState_Wait;
  193. #endregion
  194. }
  195. private void Label_SetColor(string tagvalue, bool isonine = true)
  196. {
  197. Control[] cls = this.tableLayoutPanel1.Controls.Find($"lb_{tagvalue}", true);
  198. if (cls.Length > 0)
  199. {
  200. if (isonine)
  201. cls[0].BackColor = System.Drawing.Color.FromArgb(51, 153, 204);
  202. else
  203. cls[0].BackColor = System.Drawing.Color.FromArgb(242, 242, 242);
  204. }
  205. }
  206. private void Label_SetColor(int[] vs, bool isonline = true)
  207. {
  208. foreach (var s in vs)
  209. {
  210. Label_SetColor(s.ToString(), isonline);
  211. }
  212. }
  213. private void uctl_agvl_UserControlMouseDown(int value)
  214. {
  215. System.Console.WriteLine($"---uctl_agvl_UserControlMouseDown--->{value}");
  216. }
  217. private void uctl_agvl_UserControlDragDropTag(int value)
  218. {
  219. }
  220. }
  221. }