ParameterForm.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using IntelligentControlForsx.Service.Control.FormInfo;
  13. using IntelligentControlForsx.Service.ParameterFormInfo;
  14. using IntelligentControlForsx.Service.ParameterFormInfo.Domain;
  15. using IntelligentControlForsx.Template;
  16. using log4net.Util;
  17. using StatInfo = IntelligentControlForsx.Service.Control.FormInfo.StatInfo;
  18. namespace IntelligentControlForsx.ChildForms
  19. {
  20. public partial class ParameterForm : TemplateForm
  21. {
  22. public bool firstLoad = true;
  23. public bool IsFirstGridViewLoad = true;
  24. private int selectRow = 0;
  25. private bool isUpdateFormOver = true;
  26. private bool isUpdateDataOver = true;
  27. private string station = "SBQ_FDC";
  28. public ParameterForm()
  29. {
  30. InitializeComponent();
  31. }
  32. public override void Active()
  33. {
  34. this.Show();
  35. //timer1.Enabled = true;
  36. }
  37. public override void DeActive()
  38. {
  39. this.Hide();
  40. timer1.Enabled = false;
  41. }
  42. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  43. {
  44. }
  45. private void timer1_Tick(object sender, EventArgs e)
  46. {
  47. if (isUpdateFormOver)
  48. {
  49. if (firstLoad)
  50. {
  51. ParameterFormInfoSvc.Instance.RefreshDataList("SBQ_FDC");
  52. firstLoad = false;
  53. }
  54. else
  55. {
  56. Thread updateDataThread =
  57. new Thread(new ParameterizedThreadStart(ParameterFormInfoSvc.Instance.RefreshDataList));//绑定数据线程
  58. updateDataThread.Start("SBQ_FDC");
  59. }
  60. isUpdateFormOver = false;
  61. Thread updateFormThread = new Thread(UpdateThread);//绑定数据线程
  62. updateFormThread.Start();
  63. }
  64. }
  65. private delegate void UpdateFormDataDelegate();
  66. private void UpdateThread()
  67. {
  68. UpdateFormDataDelegate del = new UpdateFormDataDelegate(UpdateFormData);
  69. this.BeginInvoke(del);
  70. }
  71. private void UpdateFormData()
  72. {
  73. #region
  74. if (IsFirstGridViewLoad)
  75. {
  76. try
  77. {
  78. ParameterFormInfoSvc svc = ParameterFormInfoSvc.Instance;
  79. DataTable dataTable = svc.GetDataTable(station);
  80. //控制光标选中行
  81. gvWindturbine.DataSource = dataTable;
  82. gvWindturbine.Rows[0].Selected = false;
  83. if (gvWindturbine.RowCount > 0 && gvWindturbine.RowCount >= selectRow)
  84. {
  85. gvWindturbine.CurrentCell = gvWindturbine[0, selectRow];
  86. gvWindturbine.Rows[selectRow].Selected = true;
  87. }
  88. UpdateFormStat();
  89. isUpdateFormOver = true;
  90. }
  91. catch (Exception e)
  92. {
  93. MessageBox.Show("数据更新失败,请检查网络或联系维护人员");
  94. }
  95. IsFirstGridViewLoad = false;
  96. }
  97. #endregion
  98. else
  99. {
  100. //DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
  101. //long tt = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
  102. ParameterFormInfoSvc svc = ParameterFormInfoSvc.Instance;
  103. #region
  104. //DataTable dataTable = svc.GetDataTable(station);
  105. ////目前双重循环效率低(约为2s),可以考虑改为list进行绑定
  106. //// 经过测试绑定效率并没有显著提高
  107. //for (int i = 0; i < gvWindturbine.RowCount; i++)
  108. //{
  109. // DataGridViewRow row = gvWindturbine.Rows[i];
  110. // string windturbineId = row.Cells[0].Value.ToString();
  111. // for (int j = 0; j < dataTable.Rows.Count; j++)
  112. // {
  113. // if (dataTable.Rows[j]["风机名称"].ToString() == windturbineId)
  114. // {
  115. // row.Cells[1].Value = dataTable.Rows[j]["冷却风温度"].ToString();
  116. // row.Cells[2].Value = dataTable.Rows[j]["有功功率"].ToString();
  117. // row.Cells[3].Value = dataTable.Rows[j]["液压油温度"].ToString();
  118. // row.Cells[4].Value = dataTable.Rows[j]["U1绕组温度"].ToString();
  119. // row.Cells[5].Value = dataTable.Rows[j]["U2绕组温度"].ToString();
  120. // row.Cells[6].Value = dataTable.Rows[j]["V1绕组温度"].ToString();
  121. // row.Cells[7].Value = dataTable.Rows[j]["V2绕组温度"].ToString();
  122. // row.Cells[8].Value = dataTable.Rows[j]["W1绕组温度"].ToString();
  123. // row.Cells[9].Value = dataTable.Rows[j]["W2绕组温度"].ToString();
  124. // row.Cells[10].Value = dataTable.Rows[j]["轴承A温度"].ToString();
  125. // row.Cells[11].Value = dataTable.Rows[j]["轴承B温度"].ToString();
  126. // row.Cells[12].Value = dataTable.Rows[j]["齿轮箱温度"].ToString();
  127. // row.Cells[13].Value = dataTable.Rows[j]["齿轮箱轴1温度"].ToString();
  128. // row.Cells[14].Value = dataTable.Rows[j]["齿轮箱轴2温度"].ToString();
  129. // row.Cells[15].Value = dataTable.Rows[j]["机舱温度"].ToString();
  130. // row.Cells[16].Value = dataTable.Rows[j]["环境温度"].ToString();
  131. // }
  132. // }
  133. //}
  134. IList<GridViewData> dataList = svc.GetInfoData(station).OrderBy(s => Convert.ToInt32(Regex.Replace(s.WindturbineId, "[a-zA-Z]", "").Replace("_", ""))).ToList();
  135. for (int i = 0; i < gvWindturbine.RowCount; i++)
  136. {
  137. DataGridViewRow row = gvWindturbine.Rows[i];
  138. string windturbineId = row.Cells[0].Value.ToString();
  139. GridViewData data = dataList.Where(s => s.WindturbineId == windturbineId).FirstOrDefault();
  140. if (data != null)
  141. {
  142. row.Cells[1].Value = data.ColdWindTemperature.ToString("f2");
  143. row.Cells[2].Value = data.Power.ToString("f2");//"有功功率"
  144. row.Cells[3].Value = data.OilTemperature.ToString("f2");//"液压油温度"
  145. row.Cells[4].Value = data.U1CirclingTemperature.ToString("f2");//"U1绕组温度"
  146. row.Cells[5].Value = data.U2CirclingTemperature.ToString("f2");//"U2绕组温度"
  147. row.Cells[6].Value = data.V1CirclingTemperature.ToString("f2");//"V1绕组温度"
  148. row.Cells[7].Value = data.V2CirclingTemperature.ToString("f2");//"V2绕组温度"
  149. row.Cells[8].Value = data.W1CirclingTemperature.ToString("f2");//"W1绕组温度"
  150. row.Cells[9].Value = data.W2CirclingTemperature.ToString("f2");//"W2绕组温度"
  151. row.Cells[10].Value = data.AxisATemperature.ToString("f2");//"轴承A温度"
  152. row.Cells[11].Value = data.AxisBTemperature.ToString("f2");//"轴承B温度"
  153. row.Cells[12].Value = data.GearBoxTemperature.ToString("f2");//"齿轮箱温度"
  154. row.Cells[13].Value = data.GearAxis1Temperature.ToString("f2");//"齿轮箱轴1温度"
  155. row.Cells[14].Value = data.GearAxis2Temperature.ToString("f2");//"齿轮箱轴2温度"
  156. row.Cells[15].Value = data.RoomTemperature.ToString("f2");//"机舱温度"
  157. row.Cells[16].Value = data.RoundTemperature.ToString("f2"); //"环境温度"
  158. }
  159. }
  160. #endregion
  161. isUpdateFormOver = true;
  162. //long ee = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
  163. //long re = ee - tt;
  164. //MessageBox.Show("时间差:" + re);
  165. }
  166. }
  167. private void UpdateFormStat()
  168. {
  169. StatInfo info = StatInfoSvc.Instance.GetStatInfoByStation(station);
  170. //prTop.AllCount = info.LinkCount.ToString();
  171. //prTop.OnlineCount = info.OnlineCount.ToString();
  172. //prTop.StandByCount = info.StandByCount.ToString();
  173. //prTop.FaultCount = info.FaultCount.ToString();
  174. //prTop.MaintainCount = info.MaintainCount.ToString();
  175. //prTop.StartCount = info.StartCount.ToString();
  176. //prTop.OfflineCount = info.OfflineCount.ToString();
  177. //prTop.StopCount = info.StopCount.ToString();
  178. //prTop.OnPowerCount = info.OnPowerCount.ToString();
  179. //prTop.PowerSum = info.PowerAll.ToString();
  180. //prTop.PowerSumYear = info.PowerByYear.ToString();
  181. //prTop.PowerSumMonth = info.PowerByMonth.ToString();
  182. //prTop.PowerSumDay = info.PowerByDay.ToString();
  183. //prTop.Power = info.Power.ToString();
  184. //prTop.Speed = info.Speed.ToString();
  185. info.StationName = "石板泉风电场";
  186. prTop.BindData(info);
  187. }
  188. private void gvWindturbine_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  189. {
  190. selectRow = e.RowIndex;
  191. }
  192. public DataTable GetDataTable(string stationName)
  193. {
  194. DataTable resultTable = GetDataTableHeaders();
  195. for (int i = 0; i < 120; i++)
  196. {
  197. #region 生成GridView信息
  198. DataRow row = resultTable.NewRow();
  199. row["风机名称"] = i.ToString();
  200. row["冷却风温度"] = i.ToString();
  201. row["有功功率"] = i.ToString();
  202. row["液压油温度"] = i.ToString();
  203. row["U1绕组温度"] = i.ToString();
  204. row["U2绕组温度"] = i.ToString();
  205. row["V1绕组温度"] = i.ToString();
  206. row["V2绕组温度"] = i.ToString();
  207. row["W1绕组温度"] = i.ToString();
  208. row["W2绕组温度"] = i.ToString();
  209. row["轴承A温度"] = i.ToString();
  210. row["轴承B温度"] = i.ToString();
  211. row["齿轮箱温度"] = i.ToString();
  212. row["齿轮箱轴1温度"] = i.ToString();
  213. row["齿轮箱轴2温度"] = i.ToString();
  214. row["机舱温度"] = i.ToString();
  215. row["环境温度"] = i.ToString();
  216. resultTable.Rows.Add(row);
  217. #endregion
  218. }
  219. return resultTable;
  220. }
  221. public DataTable GetDataTableHeaders()
  222. {
  223. DataTable dataTable = new DataTable();
  224. dataTable.Columns.Add("风机名称");
  225. dataTable.Columns.Add("冷却风温度");
  226. dataTable.Columns.Add("有功功率");
  227. dataTable.Columns.Add("液压油温度");
  228. dataTable.Columns.Add("U1绕组温度");
  229. dataTable.Columns.Add("U2绕组温度");
  230. dataTable.Columns.Add("V1绕组温度");
  231. dataTable.Columns.Add("V2绕组温度");
  232. dataTable.Columns.Add("W1绕组温度");
  233. dataTable.Columns.Add("W2绕组温度");
  234. dataTable.Columns.Add("轴承A温度");
  235. dataTable.Columns.Add("轴承B温度");
  236. dataTable.Columns.Add("齿轮箱温度");
  237. dataTable.Columns.Add("齿轮箱轴1温度");
  238. dataTable.Columns.Add("齿轮箱轴2温度");
  239. dataTable.Columns.Add("机舱温度");
  240. dataTable.Columns.Add("环境温度");
  241. return dataTable;
  242. }
  243. }
  244. }