HistoryDialog.cs 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using GWSocketClient.db;
  2. using GWSocketClient.model;
  3. using GWSocketClient.util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace GWSocketClient
  14. {
  15. public delegate void OnHistoryResult(string type, string result);
  16. public partial class HistoryDialog : Form
  17. {
  18. public event OnHistoryResult HistoryHandler;
  19. private string type;
  20. private string tableName;
  21. private List<HisBean> his = new List<HisBean>();
  22. public HistoryDialog(string type)
  23. {
  24. InitializeComponent();
  25. this.type = type;
  26. }
  27. private void HistoryDialog_Load(object sender, EventArgs e)
  28. {
  29. if ("labelCCIDHIS".Equals(type))
  30. {
  31. textBoxSourceCCID.Visible = true;
  32. labelCCIDLEN.Visible = true;
  33. buttonTransalteCCID.Visible = true;
  34. buttonRandom.Visible = true;
  35. this.Text = "CCID - 历史记录";
  36. his = AccessDbLoader.getInstance().getInputHistory(AccessDbLoader.CCID_HIS);
  37. tableName = AccessDbLoader.CCID_HIS;
  38. }
  39. else if ("labelAddHis".Equals(type))
  40. {
  41. buttonRandom.Visible = true;
  42. this.Text = "设备地址 - 历史记录";
  43. his = AccessDbLoader.getInstance().getInputHistory(AccessDbLoader.ADDR_HIS);
  44. tableName = AccessDbLoader.ADDR_HIS;
  45. }
  46. else if ("labelIPHIS".Equals(type))
  47. {
  48. this.Text = "IP - 历史记录";
  49. his = AccessDbLoader.getInstance().getInputHistory(AccessDbLoader.IP_HIS);
  50. tableName = AccessDbLoader.IP_HIS;
  51. }
  52. else if ("labelSendHIS".Equals(type))
  53. {
  54. this.Text = "发送指令 - 历史记录";
  55. his = AccessDbLoader.getInstance().getInputHistory(AccessDbLoader.SEND_HIS);
  56. tableName = AccessDbLoader.SEND_HIS;
  57. }
  58. listBoxHistory.Items.AddRange(his.ToArray());
  59. }
  60. private void buttonRandom_Click(object sender, EventArgs e)
  61. {
  62. if ("labelCCIDHIS".Equals(type))
  63. {
  64. HistoryHandler(type, randomCCID());
  65. this.Close();
  66. }
  67. else if ("labelAddHis".Equals(type))
  68. {
  69. string add = "00000";
  70. Random rd = new Random();
  71. for (int i = 0; i < 7; i++)
  72. {
  73. add += Utils.tenToHex(rd.Next(0, 16));
  74. }
  75. HistoryHandler(type, add);
  76. this.Close();
  77. }
  78. }
  79. private void textBoxSourceCCID_TextChanged(object sender, EventArgs e)
  80. {
  81. string tt = textBoxSourceCCID.Text.Trim();
  82. if (tt.Length > 0)
  83. {
  84. labelCCIDLEN.Text = tt.Length + "";
  85. }
  86. else
  87. {
  88. labelCCIDLEN.Text = "0";
  89. }
  90. }
  91. private void buttonTransalteCCID_Click(object sender, EventArgs e)
  92. {
  93. string result = "";
  94. string tt = textBoxSourceCCID.Text.Trim();
  95. if (tt.Length > 0)
  96. {
  97. try
  98. {
  99. result = Utils.transateCCID(tt);
  100. }
  101. catch (Exception ex)
  102. {
  103. MessageBox.Show(ex.Message);
  104. this.DialogResult = DialogResult.None;
  105. return;
  106. }
  107. }
  108. else
  109. {
  110. result = randomCCID();
  111. }
  112. HistoryHandler(this.type, result);
  113. }
  114. private string randomCCID()
  115. {
  116. string res = "";
  117. Random rd = new Random();
  118. for (int i = 0; i < 20; i++)
  119. {
  120. res += rd.Next(30, 40);
  121. }
  122. return res;
  123. }
  124. private void listBoxHistory_DoubleClick(object sender, EventArgs e)
  125. {
  126. int index = listBoxHistory.SelectedIndex;
  127. if (index >= 0 && index < listBoxHistory.Items.Count)
  128. {
  129. string info = listBoxHistory.SelectedItem.ToString();
  130. HistoryHandler(type, info);
  131. this.Close();
  132. }
  133. }
  134. //右键
  135. private void DelteToolStripMenuItem_Click(object sender, EventArgs e)
  136. {
  137. int index = listBoxHistory.SelectedIndex;
  138. if (index >= 0 && index < listBoxHistory.Items.Count)
  139. {
  140. HisBean hb = listBoxHistory.SelectedItem as HisBean;
  141. AccessDbLoader.getInstance().deleteByID(tableName, hb.ID);
  142. his.Clear();
  143. his = AccessDbLoader.getInstance().getInputHistory(AccessDbLoader.CCID_HIS);
  144. listBoxHistory.Items.Clear();
  145. listBoxHistory.Items.AddRange(his.ToArray());
  146. }
  147. }
  148. private void AllClearToolStripMenuItem_Click(object sender, EventArgs e)
  149. {
  150. AccessDbLoader.getInstance().deleteAllData(tableName);
  151. listBoxHistory.Items.Clear();
  152. }
  153. private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
  154. {
  155. int index = listBoxHistory.SelectedIndex;
  156. if (index >= 0 && index < listBoxHistory.Items.Count)
  157. {
  158. HisBean hb = listBoxHistory.SelectedItem as HisBean;
  159. Clipboard.SetDataObject(hb.data);
  160. }
  161. }
  162. }
  163. }