Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

909 rindas
34 KiB

  1. using Glorysoft.SECS.EQP;
  2. using Glorysoft.SECS.EQP.Common;
  3. using Glorysoft.SECS.EQP.Utilities;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Windows.Forms;
  9. using Glorysoft.EAP.Core.Constant;
  10. using ARI.EAP.HOST.SRD;
  11. using Glorysoft.SECS.EQP.Commands;
  12. using Glorysoft.SECS.EQP.Message;
  13. using ARI.EAP.HOST.Common;
  14. using System.Threading.Tasks;
  15. using ARI.EAP.HOST.Utilities;
  16. using ARI.EAP.HOST.MQ;
  17. using Glorysoft.SECSwell;
  18. using System.Data;
  19. using ExcelDataReader;
  20. using System.Threading;
  21. namespace ARI.EAP.HOST
  22. {
  23. public partial class MainForm : Form
  24. {
  25. public static List<SECSContext> eqpContexts;
  26. public static Scenario scenario;
  27. public static Mq mq;
  28. private string previousEditValue;
  29. public MainForm()
  30. {
  31. InitializeComponent();
  32. Configurations.conf = XmlSerializeUtil.Deserialize<Configurations>(File.ReadAllText(Constants.configuerPath));
  33. eqpContexts = new List<SECSContext>();
  34. mq = new Mq();
  35. Global.MF = this;
  36. }
  37. private void MainForm_Load(object sender, EventArgs e)
  38. {
  39. this.ConnectStatus.Text = EquipmentStatus.EqConnectState;
  40. this.MQStatus.Text = EquipmentStatus.MQstate;
  41. this.Text = Configurations.conf.connectSetting.equipmentName1;
  42. this.editIPaddress.Text = Configurations.conf.connectSetting.remoteIp;
  43. this.editDeviceID.Text = Configurations.conf.connectSetting.deviceId;
  44. this.editPort.Text = Configurations.conf.connectSetting.remotePort;
  45. VIDLoad();
  46. EquipmentStatus.EapState = RunState.Run;
  47. this.Connect.PerformClick();
  48. }
  49. #region IP等设置输入相关验证
  50. private void editIPaddress_KeyPress(object sender, KeyPressEventArgs e)
  51. {
  52. int kc = (int)e.KeyChar;
  53. if ((kc < 48 || kc > 57) && kc != 8 && kc != 46)
  54. {
  55. e.Handled = true;
  56. }
  57. }
  58. private void editDeviceID_KeyPress(object sender, KeyPressEventArgs e)
  59. {
  60. int kc = (int)e.KeyChar;
  61. if ((kc < 48 || kc > 57) && kc != 8)
  62. {
  63. e.Handled = true;
  64. }
  65. }
  66. private void editPort_KeyPress(object sender, KeyPressEventArgs e)
  67. {
  68. int kc = (int)e.KeyChar;
  69. if ((kc < 48 || kc > 57) && kc != 8)
  70. {
  71. e.Handled = true;
  72. }
  73. }
  74. private void editIPaddress_Leave(object sender, EventArgs e)
  75. {
  76. if (JudgeIPFormat(editIPaddress.Text) == true)
  77. {
  78. IPError.Visible = false;
  79. }
  80. else
  81. {
  82. IPError.Visible = true;
  83. }
  84. }
  85. private void editDeviceID_Leave(object sender, EventArgs e)
  86. {
  87. if (JudgePortFormat(editDeviceID.Text) == true)
  88. {
  89. ErrorDeviceID.Visible = false;
  90. }
  91. else
  92. {
  93. ErrorDeviceID.Visible = true;
  94. }
  95. }
  96. private void editPort_Leave(object sender, EventArgs e)
  97. {
  98. if (JudgePortFormat(editPort.Text) == true)
  99. {
  100. ErrorPort.Visible = false;
  101. }
  102. else
  103. {
  104. ErrorPort.Visible = true;
  105. }
  106. }
  107. //IP地址合法性检测
  108. public static bool JudgeIPFormat(string strJudgeString)
  109. {
  110. bool blnTest;
  111. bool _Result = true;
  112. System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$");
  113. blnTest = regex.IsMatch(strJudgeString);
  114. if (blnTest == true)
  115. {
  116. string[] strTemp = strJudgeString.Split(new char[] { '.' }); // textBox1.Text.Split(new char[] { ‘.’ });
  117. int nDotCount = strTemp.Length - 1; //字符串中.的数量,若.的数量小于3,则是非法的ip地址
  118. if (3 == nDotCount)//判断字符串中.的数量
  119. {
  120. for (int i = 0; i < strTemp.Length; i++)
  121. {
  122. if (Convert.ToInt32(strTemp[i]) > 255)
  123. { //大于255则提示,不符合IP格式
  124. _Result = false;
  125. }
  126. }
  127. }
  128. else
  129. {
  130. _Result = false;
  131. }
  132. }
  133. else
  134. {//输入非数字则提示,不符合IP格式
  135. _Result = false;
  136. }
  137. return _Result;
  138. }
  139. //deviceID 和 Port 合法性检测
  140. public static bool JudgePortFormat(string strJudgeString)
  141. {
  142. bool blnTest;
  143. System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[0-9]{1,5}$");
  144. blnTest = regex.IsMatch(strJudgeString);
  145. return blnTest;
  146. }
  147. #endregion
  148. #region IP配置保存和取消
  149. private void Save_Click(object sender, EventArgs e)
  150. {
  151. //配置出错时不进行保存
  152. if (IPError.Visible == true || ErrorPort.Visible == true || ErrorDeviceID.Visible == true)
  153. {
  154. MessageBox.Show("Please check configuration", "NOTICE");
  155. return;
  156. }
  157. Configurations.conf.connectSetting.deviceId = editDeviceID.Text;
  158. Configurations.conf.connectSetting.remoteIp = editIPaddress.Text;
  159. Configurations.conf.connectSetting.remotePort = editPort.Text;
  160. XmlSerializeUtil.Serializer<Configurations>(Configurations.conf);
  161. MessageBox.Show("Save Successful", "NOTICE");
  162. }
  163. private void Cancle_Click(object sender, EventArgs e)
  164. {
  165. this.editIPaddress.Text = Configurations.conf.connectSetting.remoteIp;
  166. this.editDeviceID.Text = Configurations.conf.connectSetting.deviceId;
  167. this.editPort.Text = Configurations.conf.connectSetting.remotePort;
  168. IPError.Visible = false;
  169. ErrorDeviceID.Visible = false;
  170. ErrorPort.Visible = false;
  171. }
  172. #endregion
  173. #region 连接和断开连接点击事件
  174. private void Connect_Click(object sender, EventArgs e)
  175. {
  176. try
  177. {
  178. EquipmentStatus.initStatus = false;
  179. if (SimulatorInfo.Instance.Context != null && SimulatorInfo.Instance.Context.IsConnected)
  180. {
  181. SimulatorInfo.Instance.Context.Close();
  182. }
  183. EquipmentStatus.EqConnectState = ConnectState.connecting;
  184. ConnectThread();
  185. }
  186. catch(Exception ee)
  187. {
  188. MessageBox.Show(ee.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  189. LoggerService.SYSLogger.Error(ee);
  190. }
  191. }
  192. private void Disconnect_Click(object sender, EventArgs e)
  193. {
  194. try
  195. {
  196. if (SimulatorInfo.Instance.Context != null && SimulatorInfo.Instance.Context.IsConnected)
  197. {
  198. SimulatorInfo.Instance.Context.Close();
  199. }
  200. }
  201. catch (Exception ee)
  202. {
  203. MessageBox.Show(ee.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  204. LoggerService.SYSLogger.Error(ee);
  205. }
  206. }
  207. #endregion
  208. #region 指令点击事件
  209. private void S1F3Request_Click(object sender, EventArgs e)
  210. {
  211. if (this.ConnectStatus.Text != ConnectState.connected)
  212. {
  213. return;
  214. }
  215. Command.S1F3Command(null);
  216. }
  217. private void S5F3_Click(object sender, EventArgs e)
  218. {
  219. if (this.ConnectStatus.Text != ConnectState.connected)
  220. {
  221. return;
  222. }
  223. S5F3Item item = new S5F3Item();
  224. if (EquipmentStatus.S5F3 == "AlarmDisable")
  225. {
  226. item.ALED = 128;
  227. item.ALID = 0;
  228. Command.S5F3Command(item, null);
  229. }
  230. else
  231. {
  232. item.ALED = 0;
  233. item.ALID = 0;
  234. Command.S5F3Command(item, null);
  235. }
  236. }
  237. public void S5F3BottonUpdate(string name)
  238. {
  239. if (this.ConnectStatus.Text != ConnectState.connected)
  240. {
  241. return;
  242. }
  243. Action act = delegate
  244. {
  245. this.S5F3.Text = name;
  246. };
  247. this.BeginInvoke(act);
  248. }
  249. private void S5F5_Click(object sender, EventArgs e)
  250. {
  251. if (this.ConnectStatus.Text != ConnectState.connected)
  252. {
  253. return;
  254. }
  255. Command.S5F5Command();
  256. }
  257. private void S7F19_Click(object sender, EventArgs e)
  258. {
  259. if (this.ConnectStatus.Text != ConnectState.connected)
  260. {
  261. return;
  262. }
  263. Command.S7F19Command();
  264. }
  265. private void S2F13_Click(object sender, EventArgs e)
  266. {
  267. if (this.ConnectStatus.Text != ConnectState.connected)
  268. {
  269. return;
  270. }
  271. Command.S2F13Command();
  272. }
  273. private void Local_Click(object sender, EventArgs e)
  274. {
  275. if (this.ConnectStatus.Text != ConnectState.connected)
  276. {
  277. return;
  278. }
  279. try
  280. {
  281. S2F15Item item = new S2F15Item();
  282. var content = Configurations.conf.commandContentCollection.findContent("S2F15_ControlState").content;
  283. foreach (string value in content)
  284. {
  285. EC ec = new EC();
  286. var ecv = Configurations.conf.sRDConfiguration.findEC(value);
  287. ec.ECID = ecv.ecid;
  288. item.ECs.Add(ec);
  289. }
  290. item.ECs[0].ECV = 4;
  291. item.ECs[1].ECV = 4;
  292. int tag = 1;
  293. Command.S2F15Command(item, tag);
  294. }
  295. catch (Exception ex)
  296. {
  297. MessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  298. LoggerService.SYSLogger.Error(ex.Message);
  299. }
  300. }
  301. private void Remote_Click(object sender, EventArgs e)
  302. {
  303. if (this.ConnectStatus.Text != ConnectState.connected)
  304. {
  305. return;
  306. }
  307. try
  308. {
  309. S2F15Item item = new S2F15Item();
  310. var content = Configurations.conf.commandContentCollection.findContent("S2F15_ControlState").content;
  311. foreach (string value in content)
  312. {
  313. EC ec = new EC();
  314. var ecv = Configurations.conf.sRDConfiguration.findEC(value);
  315. ec.ECID = ecv.ecid;
  316. item.ECs.Add(ec);
  317. }
  318. item.ECs[0].ECV = 5;
  319. item.ECs[1].ECV = 5;
  320. int tag = 1;
  321. Command.S2F15Command(item, tag);
  322. }
  323. catch (Exception ex)
  324. {
  325. MessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  326. LoggerService.SYSLogger.Error(ex.Message);
  327. }
  328. }
  329. #endregion
  330. #region 窗口关闭事件
  331. private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
  332. {
  333. if (EquipmentStatus.EqConnectState.Equals(ConnectState.connected))
  334. {
  335. SimulatorInfo.Instance.Context.Close();
  336. }
  337. mq.Close();
  338. EquipmentStatus.socketClient.Disconnected();
  339. EquipmentStatus.EapState = RunState.Stop;
  340. }
  341. #endregion
  342. #region log详细内容展示
  343. private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  344. {
  345. string eventName, eventContent;
  346. eventName = dataGridView1.CurrentRow.Cells[3].Value.ToString();
  347. eventContent = dataGridView1.CurrentRow.Cells[4].Value.ToString();
  348. LogForm LF = new LogForm(eventName, eventContent);
  349. Task.Run(() =>
  350. {
  351. try
  352. {
  353. LF.ShowDialog();
  354. }
  355. finally
  356. {
  357. LF.Dispose();
  358. }
  359. });
  360. }
  361. private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  362. {
  363. string eventContent, eventName;
  364. eventContent = dataGridView2.CurrentRow.Cells[3].Value.ToString();
  365. eventName = dataGridView2.CurrentRow.Cells[2].Value.ToString();
  366. LogForm LF = new LogForm(eventName, eventContent);
  367. Task.Run(() =>
  368. {
  369. try
  370. {
  371. LF.ShowDialog();
  372. }
  373. finally
  374. {
  375. LF.Dispose();
  376. }
  377. });
  378. }
  379. #endregion
  380. #region 设备连接初始化
  381. public void ConnectThread()
  382. {
  383. try
  384. {
  385. AppSettingsConf.Conf = JsonConvert.DeserializeObject<AppSettingsConf>(File.ReadAllText(ReCache.EapSettingsFilePath),
  386. new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii });
  387. SimulatorInfo.Instance.Scenarios = Configurations.conf.scenarioCollection;
  388. var eqpid = Configurations.conf.connectSetting.name;
  389. SimulatorInfo.Instance.Context = new SECSContext(eqpid, (short)Convert.ToInt32(Configurations.conf.connectSetting.deviceId), Configurations.conf.connectSetting.remoteIp, Convert.ToInt32(Configurations.conf.connectSetting.remotePort));
  390. SimulatorInfo.Instance.Context.Open();
  391. }
  392. catch (Exception ee)
  393. {
  394. LoggerService.SECSLogger.Error($"程序错误:{ee.Message}");
  395. }
  396. }
  397. #endregion
  398. #region 界面log显示
  399. /// <summary>
  400. /// addlog 的摘要说明
  401. /// {transfer:Receive or Send;
  402. /// commandName:消息名称;
  403. /// type: 0为Primary消息,1为Secondary消息}
  404. /// </summary>
  405. public void addlog(SECSTransaction trans, string transfer, string commandName,int type)
  406. {
  407. string time = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  408. string SxFy = (type == 0 ? $"S{trans.Primary.Stream}F{trans.Primary.Function}" : $"S{trans.Secondary.Stream}F{trans.Secondary.Function}");
  409. Action act = delegate
  410. {
  411. int index = this.dataGridView1.Rows.Add();
  412. this.dataGridView1.Rows[index].Cells[0].Value = time;
  413. this.dataGridView1.Rows[index].Cells[1].Value = SxFy;
  414. this.dataGridView1.Rows[index].Cells[2].Value = transfer;
  415. this.dataGridView1.Rows[index].Cells[3].Value = commandName;
  416. this.dataGridView1.Rows[index].Cells[4].Value = (type == 0 ? trans.Primary : trans.Secondary);
  417. this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView1.Rows.Count - 1;
  418. //界面日志只保留一千行
  419. if(this.dataGridView1.Rows.Count > 1000)
  420. {
  421. this.dataGridView1.Rows.RemoveAt(0);
  422. }
  423. };
  424. this.BeginInvoke(act);
  425. }
  426. public void addMQlog(string time, string trans, string name,string content)
  427. {
  428. Action act = delegate
  429. {
  430. int index = this.dataGridView2.Rows.Add();
  431. this.dataGridView2.Rows[index].Cells[0].Value = time;
  432. this.dataGridView2.Rows[index].Cells[1].Value = trans;
  433. this.dataGridView2.Rows[index].Cells[2].Value = name;
  434. this.dataGridView2.Rows[index].Cells[3].Value = content;
  435. this.dataGridView2.FirstDisplayedScrollingRowIndex = this.dataGridView2.Rows.Count - 1;
  436. //界面日志只保留一千行
  437. if (this.dataGridView2.Rows.Count > 1000)
  438. {
  439. this.dataGridView2.Rows.RemoveAt(0);
  440. }
  441. };
  442. this.BeginInvoke(act);
  443. }
  444. #endregion
  445. #region 界面连接状态显示
  446. public void ConnectStatusSet(string value)
  447. {
  448. Action act = delegate
  449. {
  450. this.ConnectStatus.Text = value;
  451. };
  452. this.BeginInvoke(act);
  453. }
  454. #endregion
  455. #region MQ界面连接状态显示
  456. public void MQConnectStatusSet(string value)
  457. {
  458. Action act = delegate
  459. {
  460. this.MQStatus.Text = value;
  461. };
  462. this.BeginInvoke(act);
  463. }
  464. #endregion
  465. #region 外部调用EAP界面各按钮接口
  466. public void pushBotton(string buttonName)
  467. {
  468. try
  469. {
  470. ToolStripButton toolStripButton = null;
  471. ToolStripMenuItem toolStripMenuItem = null;
  472. if (buttonName.Equals("Connect"))
  473. {
  474. toolStripButton = (ToolStripButton)toolStrip1.Items.Find(buttonName, true)[0];
  475. }
  476. else
  477. {
  478. toolStripMenuItem = (ToolStripMenuItem)toolStrip1.Items.Find(buttonName, true)[0];
  479. }
  480. Action act = delegate
  481. {
  482. if (toolStripButton != null)
  483. toolStripButton.PerformClick();
  484. if (toolStripMenuItem != null)
  485. toolStripMenuItem.PerformClick();
  486. };
  487. this.BeginInvoke(act);
  488. }
  489. catch(Exception e)
  490. {
  491. LoggerService.SYSLogger.Error(e);
  492. }
  493. }
  494. #endregion
  495. #region VID加载与保存
  496. public void VIDLoad()
  497. {
  498. foreach(SV sv in Configurations.conf.sRDConfiguration.svs)
  499. {
  500. int index = this.dgv_sv.Rows.Add();
  501. this.dgv_sv.Rows[index].Cells[0].Value = sv.svid;
  502. this.dgv_sv.Rows[index].Cells[1].Value = sv.name;
  503. this.dgv_sv.Rows[index].Cells[2].Value = sv.format;
  504. this.dgv_sv.Rows[index].Cells[3].Value = sv.min;
  505. this.dgv_sv.Rows[index].Cells[4].Value = sv.max;
  506. this.dgv_sv.Rows[index].Cells[5].Value = sv.defaultValue;
  507. this.dgv_sv.Rows[index].Cells[6].Value = sv.description;
  508. }
  509. foreach (DV dv in Configurations.conf.sRDConfiguration.dvs)
  510. {
  511. int index = this.dgv_dv.Rows.Add();
  512. this.dgv_dv.Rows[index].Cells[0].Value = dv.dvid;
  513. this.dgv_dv.Rows[index].Cells[1].Value = dv.name;
  514. this.dgv_dv.Rows[index].Cells[2].Value = dv.format;
  515. this.dgv_dv.Rows[index].Cells[3].Value = dv.min;
  516. this.dgv_dv.Rows[index].Cells[4].Value = dv.max;
  517. this.dgv_dv.Rows[index].Cells[5].Value = dv.defaultValue;
  518. this.dgv_dv.Rows[index].Cells[6].Value = dv.description;
  519. }
  520. foreach (ECV ecv in Configurations.conf.sRDConfiguration.ecvs)
  521. {
  522. int index = this.dgv_ec.Rows.Add();
  523. this.dgv_ec.Rows[index].Cells[0].Value = ecv.ecid;
  524. this.dgv_ec.Rows[index].Cells[1].Value = ecv.name;
  525. this.dgv_ec.Rows[index].Cells[2].Value = ecv.format;
  526. this.dgv_ec.Rows[index].Cells[3].Value = ecv.min;
  527. this.dgv_ec.Rows[index].Cells[4].Value = ecv.max;
  528. this.dgv_ec.Rows[index].Cells[5].Value = ecv.defaultValue;
  529. this.dgv_ec.Rows[index].Cells[6].Value = ecv.description;
  530. }
  531. }
  532. private void saveToolStripMenuItem_Click(object sender, EventArgs e)
  533. {
  534. var svs = new List<SV>();
  535. var dvs = new List<DV>();
  536. var ecvs = new List<ECV>();
  537. foreach(DataGridViewRow row in dgv_sv.Rows)
  538. {
  539. SV sv = new SV();
  540. if (row.Cells[0].Value != null)
  541. sv.svid = uint.Parse(row.Cells[0].Value.ToString());
  542. if (row.Cells[1].Value != null)
  543. sv.name = row.Cells[1].Value.ToString();
  544. if (row.Cells[2].Value != null)
  545. sv.format = row.Cells[2].Value.ToString();
  546. if (row.Cells[3].Value != null)
  547. sv.min = row.Cells[3].Value.ToString();
  548. if (row.Cells[4].Value != null)
  549. sv.max = row.Cells[4].Value.ToString();
  550. if (row.Cells[5].Value != null)
  551. sv.defaultValue = row.Cells[5].Value.ToString();
  552. if (row.Cells[6].Value != null)
  553. sv.description = row.Cells[6].Value.ToString();
  554. svs.Add(sv);
  555. }
  556. foreach (DataGridViewRow row in dgv_dv.Rows)
  557. {
  558. DV dv = new DV();
  559. if (row.Cells[0].Value != null)
  560. dv.dvid = uint.Parse(row.Cells[0].Value.ToString());
  561. if (row.Cells[1].Value != null)
  562. dv.name = row.Cells[1].Value.ToString();
  563. if (row.Cells[2].Value != null)
  564. dv.format = row.Cells[2].Value.ToString();
  565. if (row.Cells[3].Value != null)
  566. dv.min = row.Cells[3].Value.ToString();
  567. if (row.Cells[4].Value != null)
  568. dv.max = row.Cells[4].Value.ToString();
  569. if (row.Cells[5].Value != null)
  570. dv.defaultValue = row.Cells[5].Value.ToString();
  571. if (row.Cells[6].Value != null)
  572. dv.description = row.Cells[6].Value.ToString();
  573. dvs.Add(dv);
  574. }
  575. foreach (DataGridViewRow row in dgv_ec.Rows)
  576. {
  577. ECV ecv = new ECV();
  578. if (row.Cells[0].Value != null)
  579. ecv.ecid = uint.Parse(row.Cells[0].Value.ToString());
  580. if (row.Cells[1].Value != null)
  581. ecv.name = row.Cells[1].Value.ToString();
  582. if (row.Cells[2].Value != null)
  583. ecv.format = row.Cells[2].Value.ToString();
  584. if (row.Cells[3].Value != null)
  585. ecv.min = row.Cells[3].Value.ToString();
  586. if (row.Cells[4].Value != null)
  587. ecv.max = row.Cells[4].Value.ToString();
  588. if (row.Cells[5].Value != null)
  589. ecv.defaultValue = row.Cells[5].Value.ToString();
  590. if (row.Cells[6].Value != null)
  591. ecv.description = row.Cells[6].Value.ToString();
  592. ecvs.Add(ecv);
  593. }
  594. Configurations.conf.sRDConfiguration.svs = svs;
  595. Configurations.conf.sRDConfiguration.dvs = dvs;
  596. Configurations.conf.sRDConfiguration.ecvs = ecvs;
  597. XmlSerializeUtil.Serializer<Configurations>(Configurations.conf);
  598. MessageBox.Show("Save Successful", "NOTICE");
  599. }
  600. private void createSVToolStripMenuItem_Click(object sender, EventArgs e)
  601. {
  602. int index = this.dgv_sv.Rows.Add();
  603. dgv_sv.FirstDisplayedScrollingRowIndex = index;
  604. }
  605. private void createDVToolStripMenuItem_Click(object sender, EventArgs e)
  606. {
  607. int index = this.dgv_dv.Rows.Add();
  608. dgv_dv.FirstDisplayedScrollingRowIndex = index;
  609. }
  610. private void createECToolStripMenuItem_Click(object sender, EventArgs e)
  611. {
  612. int index = this.dgv_ec.Rows.Add();
  613. dgv_ec.FirstDisplayedScrollingRowIndex = index;
  614. }
  615. private void dgv_sv_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  616. {
  617. previousEditValue = "";
  618. if (this.dgv_sv.CurrentCell.Value != null)
  619. {
  620. previousEditValue = this.dgv_sv.CurrentCell.Value.ToString();
  621. }
  622. }
  623. private void dgv_dv_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  624. {
  625. previousEditValue = "";
  626. if (this.dgv_dv.CurrentCell.Value != null)
  627. {
  628. previousEditValue = this.dgv_dv.CurrentCell.Value.ToString();
  629. }
  630. }
  631. private void dgv_ec_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  632. {
  633. previousEditValue = "";
  634. if (this.dgv_ec.CurrentCell.Value != null)
  635. {
  636. previousEditValue = this.dgv_ec.CurrentCell.Value.ToString();
  637. }
  638. }
  639. private void dgv_sv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  640. {
  641. if (this.dgv_sv.CurrentCell.ColumnIndex == 0)
  642. {
  643. if(this.dgv_sv.CurrentCell.Value == null || dgv_sv.CurrentCell.Value.ToString() == "")
  644. {
  645. this.dgv_sv.CurrentCell.Value = previousEditValue;
  646. dgv_sv.CancelEdit();
  647. return;
  648. }
  649. foreach (DataGridViewRow row in dgv_sv.Rows)
  650. {
  651. if (row.Index == this.dgv_sv.CurrentCell.RowIndex)
  652. continue;
  653. if (row.Cells[0].Value.ToString() == this.dgv_sv.CurrentCell.Value.ToString())
  654. {
  655. MessageBox.Show("VID重复");
  656. this.dgv_sv.CurrentCell.Value = previousEditValue;
  657. dgv_sv.CancelEdit();
  658. return;
  659. }
  660. }
  661. foreach (DataGridViewRow row in dgv_dv.Rows)
  662. {
  663. if (row.Cells[0].Value.ToString() == this.dgv_sv.CurrentCell.Value.ToString())
  664. {
  665. MessageBox.Show("VID重复");
  666. this.dgv_sv.CurrentCell.Value = previousEditValue;
  667. dgv_sv.CancelEdit();
  668. return;
  669. }
  670. }
  671. foreach (DataGridViewRow row in dgv_ec.Rows)
  672. {
  673. if (row.Cells[0].Value.ToString() == this.dgv_sv.CurrentCell.Value.ToString())
  674. {
  675. MessageBox.Show("VID重复");
  676. this.dgv_sv.CurrentCell.Value = previousEditValue;
  677. dgv_sv.CancelEdit();
  678. return;
  679. }
  680. }
  681. }
  682. }
  683. private void dgv_dv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  684. {
  685. if (this.dgv_dv.CurrentCell.ColumnIndex == 0)
  686. {
  687. if (this.dgv_dv.CurrentCell.Value == null || dgv_dv.CurrentCell.Value.ToString() == "")
  688. {
  689. this.dgv_dv.CurrentCell.Value = previousEditValue;
  690. dgv_dv.CancelEdit();
  691. return;
  692. }
  693. foreach (DataGridViewRow row in dgv_sv.Rows)
  694. {
  695. if (row.Cells[0].Value.ToString() == this.dgv_dv.CurrentCell.Value.ToString())
  696. {
  697. MessageBox.Show("VID重复");
  698. this.dgv_dv.CurrentCell.Value = previousEditValue;
  699. dgv_dv.CancelEdit();
  700. return;
  701. }
  702. }
  703. foreach (DataGridViewRow row in dgv_dv.Rows)
  704. {
  705. if (row.Index == this.dgv_dv.CurrentCell.RowIndex)
  706. continue;
  707. if (row.Cells[0].Value.ToString() == this.dgv_dv.CurrentCell.Value.ToString())
  708. {
  709. MessageBox.Show("VID重复");
  710. this.dgv_dv.CurrentCell.Value = previousEditValue;
  711. dgv_dv.CancelEdit();
  712. return;
  713. }
  714. }
  715. foreach (DataGridViewRow row in dgv_ec.Rows)
  716. {
  717. if (row.Cells[0].Value.ToString() == this.dgv_dv.CurrentCell.Value.ToString())
  718. {
  719. MessageBox.Show("VID重复");
  720. this.dgv_dv.CurrentCell.Value = previousEditValue;
  721. dgv_dv.CancelEdit();
  722. return;
  723. }
  724. }
  725. }
  726. }
  727. private void dgv_ec_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  728. {
  729. if (this.dgv_ec.CurrentCell.ColumnIndex == 0)
  730. {
  731. if (this.dgv_ec.CurrentCell.Value == null || dgv_ec.CurrentCell.Value.ToString() == "")
  732. {
  733. this.dgv_ec.CurrentCell.Value = previousEditValue;
  734. dgv_ec.CancelEdit();
  735. return;
  736. }
  737. foreach (DataGridViewRow row in dgv_sv.Rows)
  738. {
  739. if (row.Cells[0].Value.ToString() == this.dgv_ec.CurrentCell.Value.ToString())
  740. {
  741. MessageBox.Show("VID重复");
  742. this.dgv_ec.CurrentCell.Value = previousEditValue;
  743. dgv_ec.CancelEdit();
  744. return;
  745. }
  746. }
  747. foreach (DataGridViewRow row in dgv_dv.Rows)
  748. {
  749. if (row.Cells[0].Value.ToString() == this.dgv_ec.CurrentCell.Value.ToString())
  750. {
  751. MessageBox.Show("VID重复");
  752. this.dgv_ec.CurrentCell.Value = previousEditValue;
  753. dgv_ec.CancelEdit();
  754. return;
  755. }
  756. }
  757. foreach (DataGridViewRow row in dgv_ec.Rows)
  758. {
  759. if (row.Index == this.dgv_ec.CurrentCell.RowIndex)
  760. continue;
  761. if (row.Cells[0].Value.ToString() == this.dgv_ec.CurrentCell.Value.ToString())
  762. {
  763. MessageBox.Show("VID重复");
  764. this.dgv_ec.CurrentCell.Value = previousEditValue;
  765. dgv_ec.CancelEdit();
  766. return;
  767. }
  768. }
  769. }
  770. }
  771. #endregion
  772. private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
  773. {
  774. if(this.TabControl1.SelectedIndex == 1)
  775. {
  776. this.editIPaddress.Text = Configurations.conf.connectSetting.remoteIp;
  777. this.editDeviceID.Text = Configurations.conf.connectSetting.deviceId;
  778. this.editPort.Text = Configurations.conf.connectSetting.remotePort;
  779. IPError.Visible = false;
  780. ErrorDeviceID.Visible = false;
  781. ErrorPort.Visible = false;
  782. }
  783. else if(this.TabControl1.SelectedIndex == 2)
  784. {
  785. this.dgv_sv.Rows.Clear();
  786. this.dgv_dv.Rows.Clear();
  787. this.dgv_ec.Rows.Clear();
  788. VIDLoad();
  789. }
  790. }
  791. #region VID删除
  792. private void deleteSVToolStripMenuItem1_Click(object sender, EventArgs e)
  793. {
  794. this.dgv_sv.Rows.Remove(this.dgv_sv.CurrentRow);
  795. }
  796. private void deleteDVToolStripMenuItem_Click(object sender, EventArgs e)
  797. {
  798. this.dgv_dv.Rows.Remove(this.dgv_dv.CurrentRow);
  799. }
  800. private void deleteECVToolStripMenuItem_Click(object sender, EventArgs e)
  801. {
  802. this.dgv_ec.Rows.Remove(this.dgv_ec.CurrentRow);
  803. }
  804. #endregion
  805. private void s1F1ToolStripMenuItem_Click(object sender, EventArgs e)
  806. {
  807. if (this.s1F1ToolStripMenuItem.Checked)
  808. {
  809. EquipmentStatus.S1F1FuntionStatus = true;
  810. }
  811. else
  812. {
  813. EquipmentStatus.S1F1FuntionStatus = false;
  814. }
  815. }
  816. private void importDVListToolStripMenuItem_Click(object sender, EventArgs e)
  817. {
  818. using (var openFileDialog = new OpenFileDialog { Filter = @"Excel表格|*.xlsx|Excel|*.xls" })
  819. {
  820. if (openFileDialog.ShowDialog() == DialogResult.OK)
  821. {
  822. using (var stream = File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
  823. {
  824. using (var reader = ExcelReaderFactory.CreateReader(stream))
  825. {
  826. DataSet result = reader.AsDataSet();
  827. DataTable dt = result.Tables[0];
  828. foreach(DataRow row in dt.Rows)
  829. {
  830. int index = this.dgv_dv.Rows.Add();
  831. this.dgv_dv.Rows[index].Cells[0].Value = row[0];
  832. this.dgv_dv.Rows[index].Cells[1].Value = row[1];
  833. this.dgv_dv.Rows[index].Cells[2].Value = row[2];
  834. this.dgv_dv.Rows[index].Cells[3].Value = row[3];
  835. this.dgv_dv.Rows[index].Cells[4].Value = row[4];
  836. this.dgv_dv.Rows[index].Cells[5].Value = row[5];
  837. this.dgv_dv.Rows[index].Cells[6].Value = row[6];
  838. }
  839. }
  840. }
  841. }
  842. }
  843. }
  844. }
  845. public static class Global
  846. {
  847. public static MainForm MF{get;set;}
  848. }
  849. }