FrmAlarmByObject.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. using EntityDataSet;
  2. using GDNXFD.Data;
  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.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using IntelligentControlForsx.ChildForms;
  14. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  15. using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc;
  16. using IntelligentControlForsx.Service;
  17. namespace IntelligentControlForsx
  18. {
  19. public partial class FrmAlarmByObject : Form
  20. {
  21. [DllImport("user32.dll")]
  22. public static extern bool ReleaseCapture();
  23. [DllImport("user32.dll")]
  24. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
  25. public const int WM_SYSCOMMAND = 0x0112;
  26. public const int SC_MOVE = 0xF010;
  27. public const int HTCAPTION = 0x0002;
  28. private bool isLoadding = false;
  29. private bool isReady = false;
  30. private string objectId;
  31. private AlertServiceClient asc = null;
  32. private BindingList<AlertSnap> bindings;
  33. public FrmAlarmByObject(string objectId)
  34. {
  35. InitializeComponent();
  36. this.dgvAlarm.AutoGenerateColumns = false;
  37. this.dgvAlarm.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  38. DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  39. dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleCenter;
  40. dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  41. this.dgvAlarm.DefaultCellStyle = dataGridViewCellStyle1;
  42. this.objectId = objectId;
  43. this.TopMost = true;
  44. //isReady = true;
  45. //LoadData();
  46. }
  47. private void dgvAlarm_CellContentClick(object sender, DataGridViewCellEventArgs e)
  48. {
  49. // MessageBox.Show(e.ColumnIndex + "");
  50. //MessageBox.Show("单元格的内容是:" + dgvAlarm.Rows[e.RowIndex].Cells[e.ColumnIndex+1].Value.ToString());
  51. if (e.ColumnIndex == 6)
  52. {
  53. string snapId = dgvAlarm.Rows[e.RowIndex].Cells[7].Value.ToString();
  54. MessageBox.Show(snapId);
  55. }
  56. string windturbineId = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString();
  57. string alertSnapIds = dgvAlarm.Rows[e.RowIndex].Cells["Column8"].Value.ToString().Trim();
  58. long alertSnapId;
  59. long.TryParse(alertSnapIds, out alertSnapId);
  60. if (dgvAlarm.Columns[e.ColumnIndex].Name == "Column_Confirm" && e.RowIndex >= 0)
  61. {
  62. //报警信息操作方法
  63. if (asc == null)
  64. asc = AlertServiceClientFactory.CreateAlertServiceClient();
  65. if (alertSnapId > 0)
  66. asc.ConfirmAlert(alertSnapId);
  67. MessageBox.Show("确认操作" + alertSnapId);
  68. }
  69. if (dgvAlarm.Columns[e.ColumnIndex].Name == "Column_Control" && e.RowIndex >= 0)
  70. {
  71. if (!string.IsNullOrEmpty(windturbineId))
  72. {
  73. if (windturbineId.Contains("SG01_") || windturbineId.Contains("MG01_") ||
  74. windturbineId.Contains("QG01_") || windturbineId.Contains("XG01_") ||
  75. windturbineId.Contains("NG01_"))
  76. {
  77. user userData = null;
  78. try
  79. {
  80. FingerCheck2 check = new FingerCheck2();
  81. check.ShowDialog();
  82. userData = FingerCheck2.checkSuccessUser;
  83. }
  84. catch (Exception ex)
  85. {
  86. }
  87. if (userData == null)
  88. {
  89. return;
  90. }
  91. IList<string> sendList = new List<string>();
  92. sendList.Add("windturbineId");
  93. string controlTypeString = dgvAlarm.Rows[e.RowIndex].Cells["Column_Control"].Value.ToString().Trim();
  94. string stationId = "";
  95. if (windturbineId.Contains("SG01_"))
  96. stationId = "SBQ_FDC";
  97. if (windturbineId.Contains("MG01_"))
  98. stationId = "MHS_FDC";
  99. if (windturbineId.Contains("NG01_"))
  100. stationId = "NSS_FDC";
  101. if (windturbineId.Contains("XG01_"))
  102. stationId = "XS_FDC";
  103. if (windturbineId.Contains("QG01_"))
  104. stationId = "QS_FDC";
  105. if (controlTypeString == "复位")
  106. TaskQueueSvc.QueueAdd(sendList, stationId, CmdType.Reset, userData);
  107. else if (controlTypeString == "停机")
  108. TaskQueueSvc.QueueAdd(sendList, stationId, CmdType.Stop, userData);
  109. //报警信息操作方法
  110. if (asc == null)
  111. asc = AlertServiceClientFactory.CreateAlertServiceClient();
  112. if (alertSnapId > 0)
  113. asc.ConfirmAlert(alertSnapId);
  114. MessageBox.Show(controlTypeString + "操作已完成");
  115. }
  116. }
  117. }
  118. }
  119. private void btnClose_Click(object sender, EventArgs e)
  120. {
  121. this.Hide();
  122. }
  123. private void btnMax_Click(object sender, EventArgs e)
  124. {
  125. if (this.WindowState == FormWindowState.Maximized)
  126. this.WindowState = FormWindowState.Normal;
  127. else
  128. this.WindowState = FormWindowState.Maximized;
  129. }
  130. private void panel1_MouseDown(object sender, MouseEventArgs e)
  131. {
  132. ReleaseCapture();
  133. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  134. }
  135. private void FrmAlarmByObject_Load(object sender, EventArgs e)
  136. {
  137. IList<AlertSnap> lstSnap = ClientCache.Instance.AlarmGroups[objectId].SnapList;
  138. bindings = new BindingList<AlertSnap>(lstSnap);
  139. this.dgvAlarm.DataSource = bindings;
  140. if (!objectId.Contains("SG01_") && !objectId.Contains("MG01_") && !
  141. objectId.Contains("QG01_") && !objectId.Contains("XG01_") && !
  142. objectId.Contains("NG01_"))
  143. {
  144. btnReset.Enabled = false;
  145. btnStop.Enabled = false;
  146. }
  147. else
  148. {
  149. btnReset.Enabled = true;
  150. btnStop.Enabled = true;
  151. }
  152. }
  153. public void ShowData(string objectId)
  154. {
  155. this.objectId = objectId;
  156. try
  157. {
  158. IList<AlertSnap> lstSnap = ClientCache.Instance.AlarmGroups[objectId].SnapList;//.AlertSnaps.Where(s => s.ObjectId == this.objectId).ToList();
  159. if (lstSnap == null || lstSnap.Count == 0)
  160. return;
  161. bindings = new BindingList<AlertSnap>(lstSnap);
  162. this.dgvAlarm.DataSource = bindings;
  163. if (this.dgvAlarm.RowCount > 1)
  164. this.Show();
  165. }
  166. catch { }
  167. if (!objectId.EndsWith("风机"))
  168. //.Contains("SG01_") && !objectId.Contains("MG01_") && !
  169. // objectId.Contains("QG01_") && !objectId.Contains("XG01_") && !
  170. // objectId.Contains("NG01_"))
  171. {
  172. btnReset.Enabled = false;
  173. btnStop.Enabled = false;
  174. }
  175. else
  176. {
  177. btnReset.Enabled = true;
  178. btnStop.Enabled = true;
  179. }
  180. }
  181. private void LoadData()
  182. {
  183. try
  184. {
  185. IList<AlertSnap> lstSnap = ClientCache.Instance.AlarmGroups[objectId].SnapList;//.AlertSnaps.Where(s => s.ObjectId == this.objectId).ToList();
  186. bindings = new BindingList<AlertSnap>(lstSnap);
  187. this.dgvAlarm.DataSource = bindings;
  188. }
  189. catch { }
  190. }
  191. private void btnStop_Click(object sender, EventArgs e)
  192. {
  193. string info = SubmitMethod(2);
  194. MessageBox.Show(info);
  195. this.Hide();
  196. }
  197. private void btnConfirm_Click(object sender, EventArgs e)
  198. {
  199. string info = SubmitMethod(3);
  200. MessageBox.Show(info);
  201. this.Hide();
  202. }
  203. private void btnReset_Click(object sender, EventArgs e)
  204. {
  205. string info = SubmitMethod(1);
  206. MessageBox.Show(info);
  207. this.Hide();
  208. }
  209. private void btnSend_Click(object sender, EventArgs e)
  210. {
  211. string info = SubmitMethod(4);
  212. MessageBox.Show(info);
  213. this.Hide();
  214. }
  215. public string SubmitMethod(int type)
  216. {
  217. string info = "";
  218. user userData = null;
  219. try
  220. {
  221. FingerCheck2 check = new FingerCheck2();
  222. check.ShowDialog();
  223. userData = FingerCheck2.checkSuccessUser;
  224. }
  225. catch (Exception ex)
  226. {
  227. return "获取用户失败";
  228. }
  229. if (userData == null)
  230. {
  231. return "找不到用户";
  232. }
  233. string objectId = "";
  234. if (bindings.Count > 0)
  235. objectId = bindings[0].ObjectId.Trim();
  236. if (string.IsNullOrEmpty(objectId))
  237. return "获取设备编号失败";
  238. string stationId = "";
  239. if (objectId.Contains("SG01_"))
  240. stationId = "SBQ_FDC";
  241. else if (objectId.Contains("MG01_"))
  242. stationId = "MHS_FDC";
  243. else if (objectId.Contains("XG01_"))
  244. stationId = "XS_FDC";
  245. else if (objectId.Contains("MN01_"))
  246. stationId = "NSS_FDC";
  247. else if (objectId.Contains("QG01_"))
  248. stationId = "QS_FDC";
  249. IList<string> windturbineIdList = new List<string>();
  250. windturbineIdList.Add(objectId);
  251. //复位
  252. if (type == 1)
  253. {
  254. TaskQueueSvc.QueueAdd(windturbineIdList, stationId, CmdType.Reset, userData);
  255. info = "复位命令已下达";
  256. }
  257. //停机
  258. else if (type == 2)
  259. {
  260. TaskQueueSvc.QueueAdd(windturbineIdList, stationId, CmdType.Stop, userData);
  261. info = "停机命令已下达";
  262. }
  263. //确认
  264. else if (type == 3)
  265. {
  266. info = "已确认";
  267. }
  268. //缺陷单
  269. else if (type == 4)
  270. {
  271. info = "缺陷单已发送";
  272. }
  273. else
  274. {
  275. return "未知操作";
  276. }
  277. if (asc == null)
  278. asc = AlertServiceClientFactory.CreateAlertServiceClient();
  279. for (int i = 0; i < bindings.Count; i++)
  280. {
  281. long alertSnapId = bindings[i].Id;
  282. if (alertSnapId > 0)
  283. asc.ConfirmAlert(alertSnapId);
  284. }
  285. return info;
  286. }
  287. private void dgvAlarm_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
  288. {
  289. if (e.RowIndex > -1)
  290. {
  291. try
  292. {
  293. string objectId = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString();
  294. if (objectId.IndexOf("01") > 0)
  295. {
  296. NavService.Instance.NavForWindturbine("pictureBoxParamters", objectId, getStationId2(objectId));
  297. }
  298. }
  299. catch { }
  300. }
  301. }
  302. private string getStationId2(string wtId)
  303. {
  304. if (wtId.StartsWith("MG"))
  305. return "MHS_FDC";
  306. if (wtId.StartsWith("NG"))
  307. return "NSS_FDC";
  308. if (wtId.StartsWith("SG"))
  309. return "SBQ_FDC";
  310. if (wtId.StartsWith("XG"))
  311. return "XS_FDC";
  312. if (wtId.StartsWith("QG"))
  313. return "QS_FDC";
  314. return "SBQ_FDC";
  315. }
  316. }
  317. }