ZTControl.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 System.Threading;
  11. using log4net;
  12. using WisdomClient.data;
  13. using WisdomClient;
  14. namespace IntelligentControlForsx.MyControls.syz
  15. {
  16. public partial class ZTControl : UserControl
  17. {
  18. private ILog logger = LogManager.GetLogger("AppInfoLog");
  19. private Dictionary<string, IPointData> dictPoint;
  20. public ZTControl()
  21. {
  22. InitializeComponent();
  23. }
  24. private void ZTControl_Load(object sender, EventArgs e)
  25. {
  26. dictPoint = new Dictionary<string, IPointData>();
  27. foreach (var p in this.pnlImage.Controls)
  28. {
  29. IPointData pd = p as IPointData;
  30. if (pd != null && String.IsNullOrWhiteSpace(pd.TagId) == false)
  31. {
  32. dictPoint.Add(pd.TagId, pd);
  33. }
  34. }
  35. }
  36. private void timer1_Tick(object sender, EventArgs e)
  37. {
  38. if (isLoadding == true)
  39. return;
  40. Thread ayscThread = new Thread(LoadData);
  41. ayscThread.IsBackground = true;
  42. ayscThread.Start();
  43. }
  44. public void DeActive()
  45. {
  46. timer1.Stop();
  47. this.Hide();
  48. }
  49. public void Active()
  50. {
  51. this.Show();
  52. Thread ayscThread = new Thread(LoadData);
  53. ayscThread.IsBackground = true;
  54. ayscThread.Start();
  55. timer1.Start();
  56. }
  57. private bool isLoadding = false;
  58. private void LoadData()
  59. {
  60. if (isLoadding == true)
  61. return;
  62. isLoadding = true;
  63. try
  64. {
  65. UpdatePnlImage();
  66. }
  67. catch (Exception ex)
  68. {
  69. logger.Info("读取实时数据失败!ex=" + ex.Message);
  70. }
  71. finally
  72. {
  73. isLoadding = false;
  74. }
  75. }
  76. private void UpdatePnlImage()
  77. {
  78. if (dictPoint == null || dictPoint.Count < 1)
  79. return;
  80. var points = dictPoint.Keys.ToArray();
  81. Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
  82. lock (this.pnlImage)
  83. {
  84. this.BeginInvoke(
  85. (Action)delegate
  86. {
  87. for (int i = 0; i < points.Length; i++)
  88. {
  89. String tagId = points[i];
  90. if (tagId == "NSSDQ.NX_GD_NSSF_DQ_P1_L1_001_DI0088")
  91. {
  92. TsData tt = dictResult[tagId];
  93. Console.WriteLine("123");
  94. }
  95. if (dictResult.ContainsKey(tagId) && dictPoint.ContainsKey(tagId))
  96. {
  97. TsData tsData = dictResult[tagId];
  98. IPointData pd = dictPoint[tagId];
  99. pd.TagData = tsData;
  100. }
  101. }
  102. });
  103. }
  104. }
  105. }
  106. }