UCTimeLine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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.Windows.Forms;
  9. namespace HOZProject
  10. {
  11. /// <summary>
  12. /// Class UCTimeLine.
  13. /// Implements the <see cref="System.Windows.Forms.UserControl" />
  14. /// </summary>
  15. /// <seealso cref="System.Windows.Forms.UserControl" />
  16. public partial class UCTimeLine : UserControl
  17. {
  18. /// <summary>
  19. /// Timed flashing
  20. /// </summary>
  21. int count = 0;
  22. int min = 0;
  23. /// <summary>
  24. /// The line color
  25. /// </summary>
  26. private Color lineColor = TextColors.Light;
  27. /// <summary>
  28. /// Gets or sets the color of the line.
  29. /// </summary>
  30. /// <value>The color of the line.</value>
  31. [Description("连接线颜色"), Category("自定义")]
  32. public Color LineColor
  33. {
  34. get { return lineColor; }
  35. set
  36. {
  37. lineColor = value;
  38. Invalidate();
  39. }
  40. }
  41. /// <summary>
  42. /// The title font
  43. /// </summary>
  44. private Font titleFont = new Font("微软雅黑", 11f);
  45. /// <summary>
  46. /// Gets or sets the title font.
  47. /// </summary>
  48. /// <value>The title font.</value>
  49. [Description("标题字体"), Category("自定义")]
  50. public Font TitleFont
  51. {
  52. get { return titleFont; }
  53. set
  54. {
  55. titleFont = value;
  56. }
  57. }
  58. /// <summary>
  59. /// The title forcolor
  60. /// </summary>
  61. private Color titleForcolor = TextColors.Light;
  62. /// <summary>
  63. /// Gets or sets the title forcolor.
  64. /// </summary>
  65. /// <value>The title forcolor.</value>
  66. [Description("标题颜色"), Category("自定义")]
  67. public Color TitleForcolor
  68. {
  69. get { return titleForcolor; }
  70. set
  71. {
  72. titleForcolor = value;
  73. }
  74. }
  75. /// <summary>
  76. /// The details font
  77. /// </summary>
  78. private Font detailsFont = new Font("微软雅黑", 12);
  79. /// <summary>
  80. /// Gets or sets the details font.
  81. /// </summary>
  82. /// <value>The details font.</value>
  83. [Description("详情字体"), Category("自定义")]
  84. public Font DetailsFont
  85. {
  86. get { return detailsFont; }
  87. set
  88. {
  89. detailsFont = value;
  90. }
  91. }
  92. /// <summary>
  93. /// The details forcolor
  94. /// </summary>
  95. private Color detailsForcolor = TextColors.MoreDark;
  96. /// <summary>
  97. /// Gets or sets the details forcolor.
  98. /// </summary>
  99. /// <value>The details forcolor.</value>
  100. [Description("详情颜色"), Category("自定义")]
  101. public Color DetailsForcolor
  102. {
  103. get { return detailsForcolor; }
  104. set
  105. {
  106. detailsForcolor = value;
  107. }
  108. }
  109. /// <summary>
  110. /// The items
  111. /// </summary>
  112. public TimeLineItem[] items;
  113. /// <summary>
  114. /// Gets or sets the items.
  115. /// </summary>
  116. /// <value>The items.</value>
  117. [Description("项列表"), Category("自定义")]
  118. public TimeLineItem[] Items
  119. {
  120. get { return items; }
  121. set
  122. {
  123. items = value;
  124. }
  125. }
  126. /// <summary>
  127. /// Initializes a new instance of the <see cref="UCTimeLine"/> class.
  128. /// </summary>
  129. public UCTimeLine(TimeLineItem[] tlItem,int measureType)
  130. {
  131. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  132. this.SetStyle(ControlStyles.DoubleBuffer, true);
  133. this.SetStyle(ControlStyles.ResizeRedraw, true);
  134. this.SetStyle(ControlStyles.Selectable, true);
  135. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  136. this.SetStyle(ControlStyles.UserPaint, true);
  137. InitializeComponent();
  138. items = tlItem;
  139. //加载节点信息
  140. ReloadItems(measureType);
  141. }
  142. /// <summary>
  143. /// Reloads the items.
  144. /// </summary>
  145. public void ReloadItems(int measureType)
  146. {
  147. try
  148. {
  149. ControlHelper.FreezeControl(this, true);
  150. this.Controls.Clear();
  151. if (items != null)
  152. {
  153. foreach (var item in items)
  154. {
  155. switch (measureType)
  156. {
  157. case (int)MeasureMsgManage.measureType.Photo:
  158. if (item.Type.ToUpper() == "PT" || item.Type.ToUpper() == "FIB")
  159. {
  160. continue;
  161. }
  162. break;
  163. case (int)MeasureMsgManage.measureType.FIB:
  164. if (item.Type.ToUpper() == "PT")
  165. {
  166. continue;
  167. }
  168. break;
  169. //case (int)MeasureMsgManage.measureType.PT:
  170. // break;
  171. }
  172. FlowLayoutPanel panelTitle = new FlowLayoutPanel();
  173. panelTitle.Dock = DockStyle.Top;
  174. panelTitle.AutoScroll = false;
  175. panelTitle.Padding = new System.Windows.Forms.Padding(5);
  176. panelTitle.Name = "Code_" + item.Code;//+ Guid.NewGuid().ToString();
  177. panelTitle.Tag = item.Code;
  178. //panelTitle.BackColor = Color.Yellow;
  179. Label lblTitle = new Label();
  180. lblTitle.Dock = DockStyle.Top;
  181. lblTitle.AutoSize = true;
  182. lblTitle.Font = titleFont;
  183. lblTitle.ForeColor = titleForcolor;
  184. lblTitle.Text = item.Title;
  185. lblTitle.Tag = item.Code;
  186. lblTitle.Name = "lbl"+item.Code;
  187. lblTitle.SizeChanged += item_SizeChanged;
  188. panelTitle.Controls.Add(lblTitle);
  189. this.Controls.Add(panelTitle);
  190. panelTitle.BringToFront();
  191. FlowLayoutPanel panelDetails = new FlowLayoutPanel();
  192. panelDetails.Dock = DockStyle.Top;
  193. panelDetails.AutoScroll = false;
  194. panelDetails.Padding = new System.Windows.Forms.Padding(5);
  195. panelDetails.Name = "details_" + item.Code; //"details_" + Guid.NewGuid().ToString();
  196. panelDetails.BackColor = Color.White;
  197. Label lblDetails = new Label();
  198. lblDetails.AutoSize = true;
  199. lblDetails.Dock = DockStyle.Top;
  200. lblDetails.Font = detailsFont;
  201. lblDetails.ForeColor = titleForcolor;
  202. lblDetails.Text = item.Details;
  203. lblDetails.SizeChanged += item_SizeChanged;
  204. panelDetails.Controls.Add(lblDetails);
  205. this.Controls.Add(panelDetails);
  206. panelDetails.BringToFront();
  207. }
  208. }
  209. }
  210. finally
  211. {
  212. ControlHelper.FreezeControl(this, false);
  213. }
  214. }
  215. /// <summary>
  216. /// Handles the SizeChanged event of the item control.
  217. /// </summary>
  218. /// <param name="sender">The source of the event.</param>
  219. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  220. void item_SizeChanged(object sender, EventArgs e)
  221. {
  222. Label lbl = (Label)sender;
  223. lbl.Parent.Height = lbl.Height + 10;
  224. }
  225. /// <summary>
  226. /// 引发 <see cref="E:System.Windows.Forms.Control.Paint" /> 事件。
  227. /// </summary>
  228. /// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" />。</param>
  229. protected override void OnPaint(PaintEventArgs e)
  230. {
  231. bool twinkle = true;
  232. if (count <= 2)
  233. {
  234. count = count + 1;
  235. }
  236. else
  237. {
  238. count = 0;
  239. }
  240. base.OnPaint(e);
  241. var g = e.Graphics;
  242. g.SetGDIHigh();
  243. var lst = this.Controls.ToArray().Where(p => p.Name.StartsWith("Code_")).ToList();
  244. var lst1 = this.Controls.ToArray().Where(p => p.Name.StartsWith("details_")).ToList();
  245. for (int i = 0; i<lst.Count; i++)
  246. {
  247. Label label = (Label)lst[i].Controls[0];
  248. Label labeText = (Label)lst1[i].Controls[0];
  249. foreach (var item in items)
  250. {
  251. if (item.State!=1)
  252. {
  253. twinkle = true;
  254. }
  255. else
  256. {
  257. twinkle = false;
  258. }
  259. }
  260. foreach (var item in items)
  261. {
  262. //if (item.State==1)
  263. if(label.Tag.ToString() == item.Code)
  264. {
  265. #region State Int 判断方法
  266. switch (item.State)
  267. {
  268. //出错
  269. case 0:
  270. lineColor = Color.Red;
  271. //空心
  272. g.DrawEllipse(new Pen(new SolidBrush(Color.Red)), new Rectangle(7, lst[i].Location.Y + 10, 16, 16));
  273. //画实心圆
  274. g.FillEllipse(new SolidBrush(Color.Red), new Rectangle(7 + 5, lst[i].Location.Y + 16, 5, 5));
  275. label.ForeColor = Color.Red;
  276. labeText.ForeColor = Color.Red;
  277. FormHOZMain.ControlFlicker = false;
  278. break;
  279. //完成
  280. case 1:
  281. lineColor = Color.Lime;
  282. //画实心圆
  283. g.FillEllipse(new SolidBrush(Color.Lime), new Rectangle(7 + 5, lst[i].Location.Y + 16, 5, 5));
  284. //空心
  285. g.DrawEllipse(new Pen(new SolidBrush(Color.Lime)), new Rectangle(7, lst[i].Location.Y + 10, 16, 16));
  286. label.ForeColor = TextColors.Light;
  287. labeText.ForeColor = TextColors.Light;
  288. break;
  289. default:
  290. lineColor = TextColors.Light;
  291. if (min<=i)
  292. {
  293. min = i;
  294. }
  295. g.DrawEllipse(new Pen(new SolidBrush(lineColor)), new Rectangle(7, lst[i].Location.Y + 10, 16, 16));
  296. g.FillEllipse(new SolidBrush(lineColor), new Rectangle(7+5, lst[i].Location.Y + 16, 5, 5));
  297. break;
  298. }
  299. #endregion
  300. break;
  301. }
  302. }
  303. //划线
  304. if (i != lst.Count - 1)
  305. {
  306. g.DrawLine(new Pen(new SolidBrush(lineColor)), new Point(7 + 8, lst[i].Location.Y + 10 - 2), new Point(7 + 8, lst[i + 1].Location.Y + 10 + 16 + 2));
  307. }
  308. }
  309. if (FormHOZMain.ControlFlicker)
  310. {
  311. for (int i = 0; i < lst.Count; i++)
  312. {
  313. if(twinkle)
  314. {
  315. if (min >= 0)
  316. {
  317. if (count == 1)
  318. {
  319. //画空心圆
  320. g.DrawEllipse(new Pen(new SolidBrush(Color.DarkOrange)), new Rectangle(7, lst[min].Location.Y + 10, 16, 16));
  321. //画实心圆
  322. g.FillEllipse(new SolidBrush(Color.DarkOrange), new Rectangle(7 + 5, lst[min].Location.Y + 16, 5, 5));
  323. Label label = (Label)lst[min].Controls[0];
  324. Label labeText = (Label)lst1[min].Controls[0];
  325. label.ForeColor = Color.DarkOrange;
  326. labeText.ForeColor = Color.DarkOrange;
  327. }
  328. else
  329. if (count == 2)
  330. {
  331. //画空心圆
  332. g.DrawEllipse(new Pen(new SolidBrush(lineColor)), new Rectangle(7, lst[min].Location.Y + 10, 16, 16));
  333. //画实心圆
  334. g.FillEllipse(new SolidBrush(lineColor), new Rectangle(7 + 5, lst[min].Location.Y + 16, 5, 5));
  335. Label label = (Label)lst[min].Controls[0];
  336. Label labeText = (Label)lst1[min].Controls[0];
  337. label.ForeColor = TextColors.Light;
  338. labeText.ForeColor = TextColors.Light;
  339. }
  340. }
  341. }
  342. if (i == lst.Count - 1)
  343. {
  344. min = 0;
  345. }
  346. }
  347. }
  348. }
  349. private void UCTimeLine_Paint(object sender, PaintEventArgs e)
  350. {
  351. }
  352. }
  353. /// <summary>
  354. /// Class TimeLineItem.
  355. /// </summary>
  356. public class TimeLineItem
  357. {
  358. /// <summary>
  359. /// Gets or sets the title.
  360. /// </summary>
  361. /// <value>The title.</value>
  362. public string Title { get; set; }
  363. /// <summary>
  364. /// Gets or sets the details.
  365. /// </summary>
  366. /// <value>The details.</value>
  367. public string Details { get; set; }
  368. /// <summary>
  369. /// Gets or sets the Code.
  370. /// </summary>
  371. /// <value>The Code.</value>
  372. public string Code { get; set; }
  373. /// <summary>
  374. /// Gets or sets the State.
  375. /// </summary>
  376. /// <value>The State.</value>
  377. public int State { get; set; }
  378. /// <summary>
  379. /// Gets or sets the IsData.
  380. /// </summary>
  381. /// <value>The IsData.</value>
  382. public bool IsData { get; set; }
  383. /// <summary>
  384. /// Gets or sets the Type.
  385. /// </summary>
  386. /// <value>The Type.</value>
  387. public string Type { get; set; }
  388. /// <summary>
  389. /// Gets or sets the Show.
  390. /// </summary>
  391. /// <value>The Show.</value>
  392. public bool IsShow { get; set; }
  393. /// <summary>
  394. /// Gets or sets the Index.
  395. /// </summary>
  396. /// <value>The Index.</value>
  397. public int Index { get; set; }
  398. }
  399. }