WDevice.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using IntelligentControlForsx.Common;
  11. using IntelligentControlForsx.Model;
  12. using IntelligentControlForsx.Service;
  13. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  14. namespace IntelligentControlForsx.MyControls
  15. {
  16. public partial class WDevice : UserControl
  17. {
  18. public WDevice()
  19. {
  20. InitializeComponent();
  21. }
  22. string deviceId;
  23. string deviceModel;
  24. string stationId;
  25. double status;
  26. [Browsable(true), Category("Data")]
  27. public double Status
  28. {
  29. get
  30. {
  31. return status;
  32. }
  33. set
  34. {
  35. status = value;
  36. this.BackColor = getBackColor(value);
  37. }
  38. }
  39. private CmdType cType;
  40. public CmdType CType
  41. {
  42. set { cType = value; }
  43. get { return cType; }
  44. }
  45. [Browsable(true), Category("Data")]
  46. public string DeviceId
  47. {
  48. get
  49. {
  50. return deviceId;
  51. }
  52. set
  53. {
  54. deviceId = value;
  55. lblDeviceId.Text = value;
  56. }
  57. }
  58. public string DeviceModel
  59. {
  60. get
  61. {
  62. return deviceModel;
  63. }
  64. set
  65. {
  66. deviceModel = value;
  67. }
  68. }
  69. public string StationId
  70. {
  71. get
  72. {
  73. return stationId;
  74. }
  75. set
  76. {
  77. stationId = value;
  78. }
  79. }
  80. private Color getBackColor(double status)
  81. {
  82. int st = Convert.ToInt32(status);
  83. switch (st)
  84. {
  85. //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  86. case 0: //停机状态
  87. return Color.FromArgb(176, 151, 63);
  88. case 1: //上电状态
  89. return Color.FromArgb(177, 14, 126);
  90. case 2: //待机状态
  91. return Color.FromArgb(15, 141, 106);
  92. case 3: //启动状态
  93. return Color.FromArgb(14, 72, 91);
  94. case 4: //并网状态
  95. return Color.FromArgb(15, 135, 170);
  96. case 5: //故障状态
  97. return Color.FromArgb(170, 15, 59);
  98. case 6: //维护状态
  99. return Color.FromArgb(204, 83, 51);
  100. case 7: //离线状态
  101. return Color.FromArgb(134, 150, 165);
  102. default:
  103. return Color.Black;
  104. }
  105. }
  106. private Rectangle dragBoxFromMouseDown;
  107. private void lblDeviceId_MouseDown(object sender, MouseEventArgs e)
  108. {
  109. //记录鼠标按下位置,DragSize获取以鼠标按钮的按下点为中心的矩形的宽度和高度,在该矩形内不会开始拖动操作。
  110. Size dragSize = SystemInformation.DragSize;
  111. //创建一个矩形区域(正方形)。以鼠标按下电为中心,以DragSize为高和宽的矩形。
  112. dragBoxFromMouseDown = new Rectangle(new System.Drawing.Point(e.X - (dragSize.Width / 2),
  113. e.Y - (dragSize.Height / 2)), dragSize);
  114. }
  115. private void lblDeviceId_MouseMove(object sender, MouseEventArgs e)
  116. {
  117. //如果鼠标位置在拖动矩形之外(就可以开始拖动了)
  118. if (dragBoxFromMouseDown != Rectangle.Empty &&
  119. !dragBoxFromMouseDown.Contains(e.X, e.Y))
  120. {
  121. //传递ListBox选中项并触发DoDragDrop事件(这里可以是ListDragSoure触发,也可以是ListDragTarget)
  122. //DoDragDrop 方法确定当前光标位置下的控件。然后它将检查该控件是否是有效的放置目标。
  123. DragDropEffects dropEffect = this.DoDragDrop(this.deviceId, DragDropEffects.All | DragDropEffects.Link);
  124. //if (dropEffect == DragDropEffects.Move)
  125. //{
  126. //}
  127. }
  128. }
  129. //protected override void WndProc(ref Message m)
  130. //{
  131. // if (m.Msg == 0x0014) // 禁掉清除背景消息
  132. // return;
  133. // base.WndProc(ref m);
  134. //}
  135. protected override CreateParams CreateParams
  136. {
  137. get
  138. {
  139. CreateParams cp = base.CreateParams;
  140. cp.ExStyle |= 0x02000000;
  141. return cp;
  142. }
  143. }
  144. public bool isSelect;
  145. public bool IsSelect
  146. {
  147. set
  148. {
  149. if (isSelect)
  150. {
  151. isSelect = false;
  152. if (MatrixPanel.lblList.Contains(this.DeviceId))
  153. MatrixPanel.lblList.Remove(this.DeviceId);
  154. }
  155. else
  156. {
  157. isSelect = true;
  158. if (MatrixPanel.lblList.Contains(this.DeviceId) == false)
  159. MatrixPanel.lblList.Add(this.DeviceId);
  160. }
  161. if (isSelect)
  162. {
  163. lblDeviceId.ForeColor = Color.Black;
  164. lblDeviceId.BackColor = Color.White;
  165. }
  166. else
  167. {
  168. lblDeviceId.ForeColor = Color.White;
  169. lblDeviceId.BackColor = Color.Transparent;
  170. }
  171. }
  172. get { return isSelect; }
  173. }
  174. private void lblDeviceId_Click(object sender, EventArgs e)
  175. {
  176. this.IsSelect = true;
  177. }
  178. public event EventHandler MyMouseDown;
  179. public event EventHandler MyMouseUp;
  180. private void WDevice_Click(object sender, EventArgs e)
  181. {
  182. this.IsSelect = true;
  183. }
  184. }
  185. }