Form1.cs 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.OleDb;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Runtime.Serialization.Json;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using GWSocketClient.db;
  16. using GWSocketClient.model;
  17. using GWSocketClient.util;
  18. using GWSocketClient.xml;
  19. using Newtonsoft.Json;
  20. using Newtonsoft.Json.Linq;
  21. using XuanJiSocket;
  22. namespace GWSocketClient
  23. {
  24. delegate void ThreadFormDelegate(object msg);
  25. public partial class Form1 : Form
  26. {
  27. #region 属性定义
  28. private string ip;
  29. private string port;
  30. private SocketHelper.TcpClients sockeTcpClients;
  31. private VcarecityPD vcarecityProtocolBean = null;
  32. private ThreadFormDelegate uiDelegate;
  33. #endregion
  34. #region Form 事件
  35. public Form1()
  36. {
  37. InitializeComponent();
  38. }
  39. private void Form1_Load(object sender, EventArgs e)
  40. {
  41. XmlLoader xmlLoader = new XmlLoader();
  42. vcarecityProtocolBean = xmlLoader.loadXml();
  43. if (vcarecityProtocolBean != null)
  44. {
  45. this.Text = vcarecityProtocolBean.ProtocolName + " - " + vcarecityProtocolBean.ProtocolNo + " - " +
  46. vcarecityProtocolBean.ProtocolStartSymbol;
  47. }
  48. SocketHelper.pushSockets = new SocketHelper.PushSockets(receiveData); //注册推送器
  49. sockeTcpClients = new SocketHelper.TcpClients();
  50. ip = tbIpaddress.Text.Trim();
  51. port = tbPort.Text.Trim();
  52. uiDelegate = addToListboxItem;
  53. timerHeartBeat.Enabled = ToolStripMenuItemHbStart.Checked;
  54. }
  55. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  56. {
  57. timerHeartBeat.Enabled = false;
  58. try
  59. {
  60. sockeTcpClients.Stop();
  61. }
  62. catch (Exception exception)
  63. {
  64. }
  65. finally
  66. {
  67. sockeTcpClients = null;
  68. }
  69. AccessDbLoader.getInstance().closeConnection();
  70. }
  71. #endregion
  72. #region 点击事件
  73. private void btnLogin_Click(object sender, EventArgs e)
  74. {
  75. try
  76. {
  77. if (!showTopForNoLoadXML())
  78. return;
  79. ip = tbIpaddress.Text.Trim();
  80. port = tbPort.Text.Trim();
  81. sockeTcpClients.InitSocket(ip, int.Parse(port));
  82. sockeTcpClients.Start();
  83. }
  84. catch (Exception ex)
  85. {
  86. // statuslist.Items.Add(string.Format("连接失败!原因:{0}", ex.Message
  87. Console.WriteLine(ex.Message);
  88. }
  89. }
  90. private void btnQuickLogout_Click(object sender, EventArgs e)
  91. {
  92. try
  93. {
  94. sockeTcpClients.Stop();
  95. }
  96. catch (Exception exception)
  97. {
  98. addToListboxItem("你还没有登录!!" + exception.Message);
  99. }
  100. }
  101. private void tsmiLoadXml_Click(object sender, EventArgs e)
  102. {
  103. OpenFileDialog ofd = new OpenFileDialog();
  104. ofd.Filter = "XML文件|*.xml|所有文件|*.*";
  105. ofd.InitialDirectory = Application.StartupPath;
  106. if (ofd.ShowDialog() == DialogResult.OK)
  107. {
  108. string xmlFilepath = ofd.FileName;
  109. vcarecityProtocolBean = new XmlLoader().load(xmlFilepath).getVcarecityPD();
  110. this.Text = vcarecityProtocolBean.ProtocolName + " - " + vcarecityProtocolBean.ProtocolNo + " - " +
  111. vcarecityProtocolBean.ProtocolStartSymbol;
  112. }
  113. }
  114. private void btnSendData_Click(object sender, EventArgs e)
  115. {
  116. string trim = tfTmpSendData.Text.Trim();
  117. trim = trim.Replace("\n", "").Replace("\r", "").Replace("\t", "").Replace(" ", "").Replace("-", "");
  118. try
  119. {
  120. if (!trim.Equals(""))
  121. {
  122. byte[] ts = HexUtil.hexToBytes(trim);
  123. AccessDbLoader.getInstance().addToHistory(AccessDbLoader.SEND_HIS, trim);
  124. addToListboxItem(string.Format("发送到服务端:[{0}]", trim));
  125. sockeTcpClients.SendData(ts);
  126. }
  127. }
  128. catch (Exception exception)
  129. {
  130. MessageBox.Show(exception.Message);
  131. }
  132. }
  133. /// <summary>
  134. /// 压力测试
  135. /// </summary>
  136. private void btnPressureTest_Click(object sender, EventArgs e)
  137. {
  138. ip = tbIpaddress.Text.Trim();
  139. port = tbPort.Text.Trim();
  140. int count = int.Parse(tbPresureTestCount.Text);
  141. ThreadPool.QueueUserWorkItem(o =>
  142. {
  143. for (int i = 1024; i < 1024 + count; i++)
  144. {
  145. SocketHelper.TcpClients clientx = new SocketHelper.TcpClients(); //初始化类库
  146. clientx.InitSocket(ip, int.Parse(port));
  147. clientx.Start();
  148. string loginCmd = "7e7e7e";
  149. loginCmd += "4442832e" + i;
  150. loginCmd += "820014383938363032423131393135353034373938" + i;
  151. loginCmd = Utils.calcCrcCode(loginCmd);
  152. sockeTcpClients.SendData(HexUtil.hexToBytes(loginCmd));
  153. Thread.Sleep(200);
  154. }
  155. });
  156. }
  157. private void buttonCmdManager_Click(object sender, EventArgs e)
  158. {
  159. InfoEditor ie = new InfoEditor();
  160. ie.ShowDialog();
  161. }
  162. private void btnTextCmd_Click(object sender, EventArgs e)
  163. {
  164. //beta test tool
  165. if (tfTmpSendData.Text.Trim().ToLower().Equals("pre"))
  166. {
  167. btnPressureTest.Visible = !btnPressureTest.Visible;
  168. tbPresureTestCount.Visible = !tbPresureTestCount.Visible;
  169. label4.Visible = !label4.Visible;
  170. }
  171. else
  172. {
  173. AccessDbLoader.getInstance().addToHistory(AccessDbLoader.SEND_HIS, "1234567890");
  174. }
  175. }
  176. private void toolStripMenuItemHBtime_Click(object sender, EventArgs e)
  177. {
  178. InputDialog id = new InputDialog();
  179. id.InputResult += (string topmost) =>
  180. {
  181. timerHeartBeat.Interval = int.Parse(topmost) * 1000;
  182. //5秒
  183. toolStripStatusLabelHbShow.Text = "心跳时间: " + topmost + "秒";
  184. };
  185. id.ShowDialog();
  186. }
  187. private void Id_InputResult(string topmost)
  188. {
  189. throw new NotImplementedException();
  190. }
  191. private void labelHis_Click(object sender, EventArgs e)
  192. {
  193. Label lab = sender as Label;
  194. HistoryDialog hd = new HistoryDialog(lab.Name);
  195. hd.HistoryHandler += Hd_HistoryHandler;
  196. hd.ShowDialog();
  197. }
  198. private void Hd_HistoryHandler(string type, string result)
  199. {
  200. if ("labelCCIDHIS".Equals(type))
  201. {
  202. tbCCID.Text = result;
  203. }
  204. else if ("labelAddHis".Equals(type))
  205. {
  206. tbEquipmentAddress.Text = result;
  207. }
  208. else if ("labelIPHIS".Equals(type))
  209. {
  210. tbIpaddress.Text = result;
  211. }
  212. else if ("labelSendHIS".Equals(type))
  213. {
  214. tfTmpSendData.Text = result;
  215. }
  216. }
  217. private void IPToolStripMenuItem_Click(object sender, EventArgs e)
  218. {
  219. HistoryDialog hd = new HistoryDialog("labelIPHIS");
  220. hd.HistoryHandler += Hd_HistoryHandler;
  221. hd.ShowDialog();
  222. }
  223. private void AddrToolStripMenuItem_Click(object sender, EventArgs e)
  224. {
  225. HistoryDialog hd = new HistoryDialog("labelAddHis");
  226. hd.HistoryHandler += Hd_HistoryHandler;
  227. hd.ShowDialog();
  228. }
  229. private void CCIDToolStripMenuItem_Click(object sender, EventArgs e)
  230. {
  231. HistoryDialog hd = new HistoryDialog("labelCCIDHIS");
  232. hd.HistoryHandler += Hd_HistoryHandler;
  233. hd.ShowDialog();
  234. }
  235. private void SendToolStripMenuItem_Click(object sender, EventArgs e)
  236. {
  237. HistoryDialog hd = new HistoryDialog("labelSendHIS");
  238. hd.HistoryHandler += Hd_HistoryHandler;
  239. hd.ShowDialog();
  240. }
  241. #endregion
  242. #region 处理心跳相关的
  243. private void timerHeartBeat_Tick(object sender, EventArgs e)
  244. {
  245. Thread thread = new Thread(heartBeatThread);
  246. thread.Start(this);
  247. }
  248. /*
  249. //开启心跳连接
  250. private void startHeartBeatThread()
  251. {
  252. }*/
  253. private void heartBeatThread(object o)
  254. {
  255. string hbCmd = vcarecityProtocolBean.ProtocolStartSymbol;
  256. hbCmd += tbEquipmentAddress.Text.Trim() + "840000";
  257. hbCmd = Utils.calcCrcCode(hbCmd);
  258. byte[] ts = HexUtil.hexToBytes(hbCmd);
  259. sockeTcpClients.SendData(ts);
  260. if (ToolStripMenuItemLogHb.Checked)
  261. {
  262. this.Invoke(this.uiDelegate, new object[] {string.Format("发送到服务端-心跳:[{0}]", hbCmd)});
  263. }
  264. }
  265. private void ToolStripMenuItemHbStart_CheckStateChanged(object sender, EventArgs e)
  266. {
  267. timerHeartBeat.Enabled = ToolStripMenuItemHbStart.Checked;
  268. }
  269. #endregion
  270. private bool showTopForNoLoadXML()
  271. {
  272. if (vcarecityProtocolBean == null)
  273. {
  274. MessageBox.Show("请先加载XML协议文件");
  275. return false;
  276. }
  277. return true;
  278. }
  279. private void receiveData(SocketHelper.Sockets sks)
  280. {
  281. this.Invoke(new ThreadStart(delegate
  282. {
  283. if (sks.ex != null)
  284. {
  285. switch (sks.ErrorCode)
  286. {
  287. case SocketHelper.Sockets.ErrorCodes.objectNull:
  288. addToListboxItem("状态信息:服务器连接已断开");
  289. checkLogin(false);
  290. break;
  291. case SocketHelper.Sockets.ErrorCodes.ConnectError:
  292. //连接不成功
  293. addToListboxItem("状态信息:连接服务器失败,可能是服务器未开启!");
  294. checkLogin(false);
  295. break;
  296. case SocketHelper.Sockets.ErrorCodes.ConnectSuccess:
  297. //连接成功
  298. addToListboxItem("状态信息:与服务器连接成功");
  299. addToListboxItem(string.Format("客户端信息{0}", sks.ex));
  300. sendLoginCmd();
  301. checkLogin(true);
  302. if (StripMenuItemLoSucHb.Checked)
  303. {
  304. ToolStripMenuItemHbStart.Checked = true;
  305. }
  306. break;
  307. case SocketHelper.Sockets.ErrorCodes.TrySendData:
  308. addToListboxItem("状态信息:ErrorCodes");
  309. checkLogin(false);
  310. break;
  311. default:
  312. addToListboxItem(string.Format("客户端信息{0}", sks.ex));
  313. break;
  314. }
  315. }
  316. else
  317. {
  318. byte[] buffer = new byte[sks.Offset];
  319. Array.Copy(sks.RecBuffer, buffer, sks.Offset);
  320. string byteToHexStr = HexUtil.byteToHexStr(buffer);
  321. if (!byteToHexStr.Equals(""))
  322. {
  323. handleResponse(sks, byteToHexStr);
  324. }
  325. else
  326. {
  327. addToListboxItem("状态信息:服务端主动关闭! position");
  328. sockeTcpClients.Stop();
  329. }
  330. // listBoxShow.Text += "\r\n";
  331. // listBoxShow.Text += string.Format("服务端{0}发来消息:{1}", sks.Ip, byteToHexStr);
  332. }
  333. }));
  334. }
  335. /// <summary>
  336. /// 处理回复信息
  337. /// </summary>
  338. /// <param name="sks">Socket对象</param>
  339. /// <param name="reqData">服务器发过来的信息</param>
  340. private void handleResponse(SocketHelper.Sockets sks, string reqData)
  341. {
  342. //取出原数据功能码
  343. string functionWord = reqData.Substring(18, 2);
  344. int funcode = Utils.hexToTen(functionWord);
  345. //处理心跳的回复
  346. if (funcode == 4)
  347. {
  348. string hbLen = reqData.Substring(20, 4);
  349. if (ToolStripMenuItemLogHb.Checked && hbLen.Equals("0000"))
  350. {
  351. addToListboxItem(string.Format("收到服务端{0}发来心跳funCode={2}:[{1}]", sks.Ip, reqData,
  352. reqData.Substring(18, 2)));
  353. }
  354. }
  355. else
  356. {
  357. addToListboxItem(string.Format("收到服务端{0}发来消息,funCode={2}:[{1}]", sks.Ip, reqData,
  358. reqData.Substring(18, 2)));
  359. }
  360. if (!(funcode == 16 || funcode == 32))
  361. {
  362. Console.WriteLine("功能码10进制=" + funcode + ",所以不用回复! data=" + reqData);
  363. return;
  364. }
  365. //16 表示要读数据,返回数据库中的数据
  366. //32 表示返回结果 成功:00 失败:01
  367. //数据长度
  368. int dataLen = Utils.hexToTen(reqData.Substring(20, 4)) * 2;
  369. string readlData = "";
  370. try
  371. {
  372. readlData = reqData.Substring(24, dataLen);
  373. }
  374. catch (Exception e)
  375. {
  376. Console.WriteLine(e.Message);
  377. addToListboxItem("数据长度与帧长度对不上!! 帧数据长度=" + (dataLen / 2) + " ,Error=" + e.Message);
  378. return;
  379. }
  380. //消息流水&测量点
  381. string flowPoint = readlData.Substring(0, 6);
  382. //ID
  383. string myId = readlData.Substring(6, 4);
  384. //对应信息
  385. string idInfo = readlData.Substring(10);
  386. //回复功能码
  387. int responceFunCode = funcode + 128;
  388. string cmd = reqData.Substring(0, 18); //前面的
  389. cmd += Utils.stringWith0(Utils.tenToHex(responceFunCode), 2); //回复功能码
  390. string body = flowPoint + myId;
  391. if (funcode == 32)
  392. {
  393. //设置数据
  394. int res = AccessDbLoader.getInstance().setReceiveData(myId, idInfo);
  395. //成功回复00 失败回复01
  396. if (res > 0)
  397. {
  398. addToListboxItem("设置成功,功能码(10)=" + funcode + " ; ID=" + myId + " ; Value=" + idInfo);
  399. body += "00";
  400. AccessDbLoader.getInstance().reloadAccessDb();
  401. }
  402. else
  403. {
  404. addToListboxItem("设置失败,功能码(10)=" + funcode + " ; ID=" + myId + " ; Value=" + idInfo);
  405. body += "01";
  406. }
  407. }
  408. else
  409. {
  410. //返回数据库的数据 OR 临时数据,如果临时数据有数据的话
  411. try
  412. {
  413. string responce = AccessDbLoader.getInstance().getUserIdInfo()[myId];
  414. if (!tfTmpResponse.Text.Trim().Equals(""))
  415. {
  416. string inputRespocse = tfTmpResponse.Text.Trim();
  417. responce = Utils.stringWith0(inputRespocse, responce.Length);
  418. }
  419. addToListboxItem("读取数据,功能码(10)=" + funcode + " ; ID=" + myId + " ; 回 复=" + responce);
  420. body += responce;
  421. }
  422. catch (Exception e)
  423. {
  424. Console.WriteLine(e);
  425. addToListboxItem("异常,没有这个ID=(" + myId + "),ERROR=" + e.Message);
  426. return;
  427. }
  428. }
  429. cmd += Utils.stringWith0(Utils.tenToHex(body.Length / 2), 4); //长度
  430. cmd += body; //消息体
  431. cmd = Utils.calcCrcCode(cmd); //计算检验码
  432. addToListboxItem(string.Format("回复服务端{0}回应消息:[{1}]", sks.Ip, cmd));
  433. byte[] ts = HexUtil.hexToBytes(cmd);
  434. sockeTcpClients.SendData(ts);
  435. }
  436. private void tbEquipmentAddress_TextChanged(object sender, EventArgs e)
  437. {
  438. string equipmentAddress = tbEquipmentAddress.Text.Trim();
  439. tsslEquipmentAddress.Text = equipmentAddress.Length / 2.0 + "";
  440. }
  441. private void sendLoginCmd()
  442. {
  443. // string loginCmd = "7e7e7e4442832e833c8200143839383630324231313931353530343739383737f7";
  444. string loginCmd = vcarecityProtocolBean.ProtocolStartSymbol;
  445. loginCmd += tbEquipmentAddress.Text.Trim() + "82";
  446. loginCmd += Utils.stringWith0(Utils.tenToHex(tbCCID.Text.Trim().Length / 2), 4);
  447. loginCmd += tbCCID.Text.Trim();
  448. loginCmd = Utils.calcCrcCode(loginCmd);
  449. //发送登录命令
  450. byte[] ts = HexUtil.hexToBytes(loginCmd);
  451. addToListboxItem(string.Format("发送到服务端,funCode={0} : [{1}]", loginCmd.Substring(18, 2), loginCmd));
  452. sockeTcpClients.SendData(ts);
  453. }
  454. private void tbCCID_TextChanged(object sender, EventArgs e)
  455. {
  456. string ccid = tbCCID.Text.Trim();
  457. tsslCCIDLEN.Text = ccid.Length / 2.0 + "";
  458. }
  459. #region ListBox相关
  460. /// <summary>
  461. /// ListBox右键菜单-点击复制
  462. /// </summary>
  463. /// <param name="sender"></param>
  464. /// <param name="e"></param>
  465. private void rightMenuCopyCmd_Click(object sender, EventArgs e)
  466. {
  467. int index = listBoxShow.SelectedIndex;
  468. if (index >= 0 && index < listBoxShow.Items.Count)
  469. {
  470. string info = listBoxShow.SelectedItem.ToString();
  471. if (!info.Equals(""))
  472. {
  473. if (info.Contains("[") || info.Contains("]"))
  474. {
  475. Regex reg = new Regex(@"\[\w+\]"); //注意里面的引号 要用双引号表示,而不是用反斜
  476. Match match = reg.Match(info);
  477. string ifs = match.ToString();
  478. ifs = ifs.Replace("[", "").Replace("]", "");
  479. if (!info.Equals(""))
  480. {
  481. Clipboard.SetDataObject(ifs);
  482. }
  483. else
  484. {
  485. Clipboard.SetDataObject(info);
  486. }
  487. }
  488. else
  489. {
  490. Clipboard.SetDataObject(info);
  491. }
  492. }
  493. }
  494. }
  495. private void addToListboxItem(object info)
  496. {
  497. if (listBoxShow.Items.Count > 1000)
  498. {
  499. listBoxShow.Items.Remove(0);
  500. // listBoxShow.Items.Clear();
  501. }
  502. Console.WriteLine(info);
  503. listBoxShow.Items.Add(info);
  504. listBoxShow.TopIndex = listBoxShow.Items.Count - 1;
  505. }
  506. private void rightMenuClearInfo_Click(object sender, EventArgs e)
  507. {
  508. listBoxShow.Items.Clear();
  509. }
  510. private void listBoxShow_DrawItem(object sender, DrawItemEventArgs e)
  511. {
  512. if (e.Index >= 0 && e.Index < listBoxShow.Items.Count)
  513. {
  514. e.DrawBackground();
  515. //
  516. string res = listBoxShow.Items[e.Index].ToString().ToLower();
  517. if (res.Contains("收到服务端"))
  518. {
  519. Font f = new Font("微软雅黑", e.Font.Size, FontStyle.Bold);
  520. e.Graphics.DrawString(((ListBox) sender).Items[e.Index].ToString(), f, new SolidBrush(Color.Blue),
  521. e.Bounds);
  522. }
  523. else if (res.Contains("发送到服务端") || res.Contains("回复"))
  524. {
  525. Font f = new Font("微软雅黑", e.Font.Size, FontStyle.Italic);
  526. e.Graphics.DrawString(((ListBox) sender).Items[e.Index].ToString(), f,
  527. new SolidBrush(Color.BlueViolet),
  528. e.Bounds);
  529. }
  530. else if (res.Contains("读取数据,") || res.Contains("设置失败,") || res.Contains("设置成功,"))
  531. {
  532. e.Graphics.DrawString(((ListBox) sender).Items[e.Index].ToString(), e.Font,
  533. new SolidBrush(Color.Red),
  534. e.Bounds);
  535. }
  536. else
  537. {
  538. e.Graphics.DrawString(((ListBox) sender).Items[e.Index].ToString(), e.Font,
  539. new SolidBrush(e.ForeColor),
  540. e.Bounds);
  541. }
  542. e.DrawFocusRectangle();
  543. }
  544. }
  545. private void listBoxShow_DoubleClick(object sender, EventArgs e)
  546. {
  547. int index = listBoxShow.SelectedIndex;
  548. if (index >= 0 && index < listBoxShow.Items.Count)
  549. {
  550. string info = listBoxShow.SelectedItem.ToString();
  551. if (!info.Equals(""))
  552. {
  553. if (info.Contains("[") || info.Contains("]"))
  554. {
  555. Regex reg = new Regex(@"\[\w+\]"); //注意里面的引号 要用双引号表示,而不是用反斜
  556. Match match = reg.Match(info);
  557. string ifs = match.ToString();
  558. ifs = ifs.Replace("[", "").Replace("]", "");
  559. if (!info.Equals(""))
  560. {
  561. // MessageBox.Show(ifs);
  562. AnaProtocol ap = new AnaProtocol(ifs);
  563. ap.ShowDialog();
  564. }
  565. }
  566. }
  567. }
  568. }
  569. #endregion
  570. #region 检验工具类
  571. private void toolStripTextBoxHbtime_KeyPress(object sender, KeyPressEventArgs e)
  572. {
  573. if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
  574. {
  575. e.Handled = true;
  576. }
  577. }
  578. private void checkLogin(bool isLogin)
  579. {
  580. if (isLogin)
  581. {
  582. btnLogin.Enabled = false;
  583. btnQuickLogout.Enabled = true;
  584. btnSendData.Enabled = true;
  585. ToolStripMenuItemHbStart.Enabled = true; //开启心中的点击选项
  586. if (StripMenuItemLoSucHb.Checked)
  587. {
  588. //如果勾选了登录成功并心跳
  589. timerHeartBeat.Enabled = true;
  590. }
  591. //ADD To History
  592. AccessDbLoader.getInstance().addToHistory(AccessDbLoader.IP_HIS, tbIpaddress.Text.Trim());
  593. AccessDbLoader.getInstance().addToHistory(AccessDbLoader.CCID_HIS, tbCCID.Text.Trim());
  594. AccessDbLoader.getInstance().addToHistory(AccessDbLoader.ADDR_HIS, tbEquipmentAddress.Text.Trim());
  595. }
  596. else
  597. {
  598. btnLogin.Enabled = true;
  599. btnQuickLogout.Enabled = false;
  600. btnSendData.Enabled = false;
  601. ToolStripMenuItemHbStart.Checked = false;
  602. ToolStripMenuItemHbStart.Enabled = false;
  603. timerHeartBeat.Enabled = false;
  604. }
  605. }
  606. #endregion
  607. private void ClearAllAllToolStripMenuItem_Click(object sender, EventArgs e)
  608. {
  609. AccessDbLoader.getInstance().deleteAllData(AccessDbLoader.IP_HIS);
  610. AccessDbLoader.getInstance().deleteAllData(AccessDbLoader.ADDR_HIS);
  611. AccessDbLoader.getInstance().deleteAllData(AccessDbLoader.SEND_HIS);
  612. AccessDbLoader.getInstance().deleteAllData(AccessDbLoader.CCID_HIS);
  613. }
  614. }
  615. }