FetchingForm.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using System.Windows.Forms;
  5. using System.Reflection;
  6. using System.Runtime.InteropServices;
  7. using Message;
  8. using Sunny.UI;
  9. using tool;
  10. using chutian_parking_terminal.motion_executer;
  11. using System.Threading;
  12. namespace chutian_parking_terminal
  13. {
  14. public partial class FetchingForm : Form
  15. {
  16. //定义该接口后会自动打开扫描
  17. private ScannerServer scan;
  18. private int start = -1;//记录ScannerTextBox的光标位置
  19. private string license = "";
  20. public bool m_is_return;
  21. private Thread m_scan_thread;
  22. private bool m_scan_condition;
  23. public FetchingForm()
  24. {
  25. InitializeComponent();
  26. scan = new ScannerServer();
  27. m_scan_thread = new Thread(get_scan_license_thread);
  28. m_scan_thread.Start();
  29. m_scan_condition = true;
  30. }
  31. private void returnBtn_Click(object sender, EventArgs e)
  32. {
  33. m_is_return = true;
  34. this.Close();
  35. m_scan_condition = false;
  36. m_scan_thread.Abort();
  37. }
  38. private void FetchingForm_Load(object sender, EventArgs e)
  39. {
  40. ScannerTextBox.LostFocus += new EventHandler(ScannerTextBox_LostFocus);
  41. this.label6.Text = "智象泊车终端" + json_file_operation.Instance.read_json_string("ternimalNumber") + "号机";
  42. this.label7.Text = this.label7.Text + json_file_operation.Instance.read_json_string("ternimalNumber");
  43. }
  44. private void get_scan_license_thread()
  45. {
  46. while (m_scan_condition)
  47. {
  48. if (scan.GetInfo(out license))
  49. {
  50. if (license != "")
  51. {
  52. ScannerTextBox.Text = license;
  53. }
  54. }
  55. }
  56. }
  57. private void FetchingForm_FormClosing(object sender, FormClosingEventArgs e)
  58. {
  59. scan.Close();
  60. m_scan_condition = false;
  61. m_scan_thread.Abort();
  62. }
  63. /// <summary>
  64. /// 取消button按钮的焦点黑色边框
  65. /// </summary>
  66. /// <param name="需要取消黑色焦点边框的button"></param>
  67. private void SetButton(Button button)
  68. {
  69. MethodInfo methodinfo = button.GetType().GetMethod("SetStyle", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);
  70. methodinfo.Invoke(button, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, new object[] { ControlStyles.Selectable, false }, Application.CurrentCulture);
  71. }
  72. private void FetchingForm_Activated(object sender, EventArgs e)
  73. {
  74. ScannerTextBox.Focus();
  75. }
  76. private void ScannerTextBox_TextChanged(object sender, EventArgs e)
  77. {
  78. string str = ScannerTextBox.Text;
  79. }
  80. void ScannerTextBox_LostFocus(object sender, EventArgs e)
  81. {
  82. //记录textBox光标位置
  83. start = ScannerTextBox.SelectionStart;
  84. }
  85. /// <summary>
  86. /// 置为已提交车牌信息
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void OKBtn_Click(object sender, EventArgs e)
  91. {
  92. Exit_execute.Instance.set_pickup_license(ScannerTextBox.Text);
  93. m_is_return = false;
  94. this.Close();
  95. m_scan_condition = false;
  96. m_scan_thread.Abort();
  97. }
  98. /// <summary>
  99. /// 清空所有下拉框数据
  100. /// </summary>
  101. /// <param name="sender"></param>
  102. /// <param name="e"></param>
  103. private void clearBtn_Click(object sender, EventArgs e)
  104. {
  105. if (start > 0)
  106. {
  107. //删除光标前一位
  108. ScannerTextBox.Text = ScannerTextBox.Text.Remove(start - 1, 1);
  109. //光标行前移一位
  110. ScannerTextBox.Select(start - 1, 0);
  111. //textBox获取焦点
  112. ScannerTextBox.Select();
  113. }
  114. else if (start == 0)
  115. {
  116. ScannerTextBox.SelectionStart = 0;
  117. ScannerTextBox.Select(ScannerTextBox.Text.Length, 0);
  118. ScannerTextBox.Select();
  119. }
  120. }
  121. private void chinese_button_Click(object sender, EventArgs e)
  122. {
  123. this.panelscannerBox.Controls.Remove(this.english_panel);
  124. this.panelscannerBox.Controls.Add(this.chinese_panel);
  125. }
  126. private void return_button_Click(object sender, EventArgs e)
  127. {
  128. this.panelscannerBox.Controls.Remove(this.chinese_panel);
  129. this.panelscannerBox.Controls.Add(this.english_panel);
  130. }
  131. private static bool flag = true;
  132. private static object obj = new object();
  133. public void updateScannerText(string initString, ref UIComboBox uiComboBox)
  134. {
  135. lock (obj)
  136. {
  137. if (flag)
  138. {
  139. if (uiComboBox.Text != initString)
  140. {
  141. flag = false;
  142. this.ScannerTextBox.Text = this.ScannerTextBox.Text + uiComboBox.Text;
  143. }
  144. }
  145. else
  146. {
  147. flag = true;
  148. uiComboBox.SelectedIndex = 0;
  149. //uiComboBox.Text = initString;
  150. }
  151. }
  152. }
  153. private void uiComboBox11_SelectedIndexChanged(object sender, EventArgs e)
  154. {
  155. updateScannerText(" 01", ref uiComboBox11);
  156. }
  157. private void uiComboBox12_SelectedIndexChanged(object sender, EventArgs e)
  158. {
  159. updateScannerText(" 2ABC", ref uiComboBox12);
  160. }
  161. private void uiComboBox13_SelectedIndexChanged(object sender, EventArgs e)
  162. {
  163. updateScannerText(" 3DEF", ref uiComboBox13);
  164. }
  165. private void uiComboBox14_SelectedIndexChanged(object sender, EventArgs e)
  166. {
  167. updateScannerText(" 4GH", ref uiComboBox14);
  168. }
  169. private void uiComboBox15_SelectedIndexChanged(object sender, EventArgs e)
  170. {
  171. updateScannerText(" 5JKL", ref uiComboBox15);
  172. }
  173. private void uiComboBox16_SelectedIndexChanged(object sender, EventArgs e)
  174. {
  175. updateScannerText(" 6MN", ref uiComboBox16);
  176. }
  177. private void uiComboBox17_SelectedIndexChanged(object sender, EventArgs e)
  178. {
  179. updateScannerText("7PQRS", ref uiComboBox17);
  180. }
  181. private void uiComboBox18_SelectedIndexChanged(object sender, EventArgs e)
  182. {
  183. updateScannerText(" 8TUV", ref uiComboBox18);
  184. }
  185. private void uiComboBox19_SelectedIndexChanged(object sender, EventArgs e)
  186. {
  187. updateScannerText("9WXYZ", ref uiComboBox19);
  188. }
  189. private void uiComboBox21_SelectedIndexChanged(object sender, EventArgs e)
  190. {
  191. updateScannerText(" 鄂湘渝", ref uiComboBox21);
  192. }
  193. private void uiComboBox22_SelectedIndexChanged(object sender, EventArgs e)
  194. {
  195. updateScannerText(" 陕豫皖", ref uiComboBox22);
  196. }
  197. private void uiComboBox23_SelectedIndexChanged(object sender, EventArgs e)
  198. {
  199. updateScannerText(" 赣贵川", ref uiComboBox23);
  200. }
  201. private void uiComboBox24_SelectedIndexChanged(object sender, EventArgs e)
  202. {
  203. updateScannerText(" 桂粤闽", ref uiComboBox24);
  204. }
  205. private void uiComboBox25_SelectedIndexChanged(object sender, EventArgs e)
  206. {
  207. updateScannerText(" 浙沪苏", ref uiComboBox25);
  208. }
  209. private void uiComboBox26_SelectedIndexChanged(object sender, EventArgs e)
  210. {
  211. updateScannerText(" 鲁冀晋", ref uiComboBox26);
  212. }
  213. private void uiComboBox27_SelectedIndexChanged(object sender, EventArgs e)
  214. {
  215. updateScannerText(" 云宁甘", ref uiComboBox27);
  216. }
  217. private void uiComboBox28_SelectedIndexChanged(object sender, EventArgs e)
  218. {
  219. updateScannerText(" 藏新青", ref uiComboBox28);
  220. }
  221. private void uiComboBox29_SelectedIndexChanged(object sender, EventArgs e)
  222. {
  223. updateScannerText(" 蒙京津", ref uiComboBox29);
  224. }
  225. private void uiComboBox210_SelectedIndexChanged(object sender, EventArgs e)
  226. {
  227. updateScannerText(" 辽吉黑", ref uiComboBox210);
  228. }
  229. private void uiComboBox211_SelectedIndexChanged(object sender, EventArgs e)
  230. {
  231. updateScannerText("琼港澳台", ref uiComboBox211);
  232. }
  233. private void determine_button_Click(object sender, EventArgs e)
  234. {
  235. string t_license = uiComboBox1.Text +
  236. uiComboBox2.Text +
  237. uiComboBox3.Text +
  238. uiComboBox4.Text +
  239. uiComboBox5.Text +
  240. uiComboBox6.Text +
  241. uiComboBox7.Text +
  242. uiComboBox8.Text;
  243. this.ScannerTextBox.Text = t_license;
  244. }
  245. }
  246. }