YardControl.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Text.RegularExpressions;
  10. namespace Core.LZMes.Client.UIM.comm
  11. {
  12. public partial class YardControl : UserControl
  13. {
  14. private const string _numPattern = @"^\d+$";
  15. private const string _layerPattern = @"^[ABCabc]?$";
  16. private const string _yardPattern = @"^[2-7]?$";//= @"^[3-5]?$"
  17. private bool _enabled = true;
  18. public new bool Enabled
  19. {
  20. get { return _enabled;}
  21. set
  22. {
  23. _enabled = value;
  24. uteYard.Enabled = _enabled;
  25. uteRow.Enabled = _enabled;
  26. uteFl.Enabled = _enabled;
  27. uteCol.Enabled = _enabled;
  28. }
  29. }
  30. public string Stock
  31. {
  32. get { return string.IsNullOrEmpty(uteYard.Text) ? "" : Convert.ToInt32(uteYard.Text,10).ToString(); }
  33. set
  34. {
  35. uteYard.Text = value;
  36. }
  37. }
  38. public string Row
  39. {
  40. get { return string.IsNullOrEmpty(uteRow.Text) ? "" : Convert.ToInt32(uteRow.Text, 10).ToString(); }
  41. set
  42. {
  43. uteRow.Text = value;
  44. }
  45. }
  46. public string Column
  47. {
  48. get { return string.IsNullOrEmpty(uteCol.Text) ? "" : Convert.ToInt32(uteCol.Text, 10).ToString(); }
  49. set
  50. {
  51. uteCol.Text = value;
  52. }
  53. }
  54. public string Layer
  55. {
  56. get { return string.IsNullOrEmpty(uteFl.Text) ? "" : uteFl.Text; }
  57. set
  58. {
  59. uteFl.Text = value;
  60. }
  61. }
  62. public YardControl()
  63. {
  64. InitializeComponent();
  65. }
  66. public string GetYardFlag()
  67. {
  68. string yardFlag = string.Empty;
  69. if (!string.IsNullOrEmpty(uteYard.Text) && !string.IsNullOrEmpty(uteRow.Text) && !string.IsNullOrEmpty(uteFl.Text) && !string.IsNullOrEmpty(uteCol.Text))
  70. {
  71. string rowStr = Convert.ToInt32(uteRow.Text,10).ToString(), colStr = Convert.ToInt32(uteCol.Text,10).ToString();
  72. if (colStr.Length < 2)
  73. {
  74. colStr = "0" + colStr;
  75. }
  76. while (rowStr.Length < 3)
  77. {
  78. rowStr = "0" + rowStr;
  79. }
  80. yardFlag = uteYard.Text + "-" + colStr + uteFl.Text + "-" + rowStr;
  81. }
  82. return yardFlag;
  83. }
  84. public string GetYardFlagZJ()
  85. {
  86. string yardFlag = string.Empty;
  87. if (!string.IsNullOrEmpty(uteYard.Text) && !string.IsNullOrEmpty(uteRow.Text) && !string.IsNullOrEmpty(uteFl.Text) && !string.IsNullOrEmpty(uteCol.Text))
  88. {
  89. string rowStr = Convert.ToInt32(uteRow.Text, 10).ToString(), colStr = Convert.ToInt32(uteCol.Text, 10).ToString();
  90. if (colStr.Length < 2)
  91. {
  92. colStr = "0" + colStr;
  93. }
  94. while (rowStr.Length < 2)
  95. {
  96. rowStr = "0" + rowStr;
  97. }
  98. yardFlag = uteYard.Text + "-" + colStr + uteFl.Text + "-" + rowStr;
  99. }
  100. return yardFlag;
  101. }
  102. public void SetYardFlag(string yardFlag)
  103. {
  104. try
  105. {
  106. if (string.IsNullOrEmpty(yardFlag))
  107. {
  108. uteYard.Text = string.Empty;
  109. uteRow.Text = string.Empty;
  110. uteFl.Text = string.Empty;
  111. uteCol.Text = string.Empty;
  112. }
  113. else
  114. {
  115. string[] flags = yardFlag.Split(new char[] { '-' });
  116. if (flags.Length == 3)
  117. {
  118. uteYard.Text = flags[0];
  119. uteCol.Text = flags[1].Substring(1, flags[1].Length - 2);
  120. uteFl.Text = flags[1].Substring(flags[1].Length - 1);
  121. uteRow.Text = flags[2];
  122. }
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. }
  128. }
  129. public new void Focus()
  130. {
  131. uteYard.Focus();
  132. }
  133. private void uteYard_KeyDown(object sender, KeyEventArgs e)
  134. {
  135. if (e.KeyValue == 39 || e.KeyValue == 40 || e.KeyValue == 13)
  136. {
  137. uteCol.Focus();
  138. }
  139. }
  140. private void uteYard_KeyPress(object sender, KeyPressEventArgs e)
  141. {
  142. if (!"2345".Contains(e.KeyChar) && (int)e.KeyChar != 8)
  143. {
  144. e.Handled = true;
  145. }
  146. e.KeyChar = char.ToUpper(e.KeyChar);
  147. }
  148. private void uteYard_TextChanged(object sender, EventArgs e)
  149. {
  150. Infragistics.Win.UltraWinEditors.UltraTextEditor te = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender;
  151. if (!Regex.IsMatch(te.Text, _yardPattern))
  152. {
  153. te.Text = string.Empty;
  154. }
  155. if (te.Text.Length > 0)
  156. {
  157. uteCol.Focus();
  158. uteCol.SelectAll();
  159. }
  160. }
  161. private void uteRow_KeyDown(object sender, KeyEventArgs e)
  162. {
  163. if (e.KeyValue == 37 || e.KeyValue == 38)
  164. {
  165. uteFl.Focus();
  166. uteFl.SelectAll();
  167. }
  168. }
  169. private void uteRow_KeyPress(object sender, KeyPressEventArgs e)
  170. {
  171. if (((((int)e.KeyChar) < 48 || ((int)e.KeyChar) > 57)) && (int)e.KeyChar != 8)
  172. {
  173. e.Handled = true;
  174. }
  175. if ((int)e.KeyChar == 8 && string.IsNullOrEmpty(uteRow.Text))
  176. {
  177. uteFl.Focus();
  178. uteFl.SelectAll();
  179. }
  180. }
  181. private void uteRow_TextChanged(object sender, EventArgs e)
  182. {
  183. Infragistics.Win.UltraWinEditors.UltraTextEditor te = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender;
  184. if (!Regex.IsMatch(te.Text, _numPattern))
  185. {
  186. te.Text = string.Empty;
  187. }
  188. }
  189. private void uteFl_KeyDown(object sender, KeyEventArgs e)
  190. {
  191. if (e.KeyValue == 39 || e.KeyValue == 40 || e.KeyValue == 13)
  192. {
  193. uteRow.Focus();
  194. uteRow.SelectAll();
  195. }
  196. else if (e.KeyValue == 37 || e.KeyValue == 38)
  197. {
  198. uteCol.Focus();
  199. uteCol.SelectAll();
  200. }
  201. }
  202. private void uteFl_KeyPress(object sender, KeyPressEventArgs e)
  203. {
  204. if (!"AaBbCc".Contains(e.KeyChar) && (int)e.KeyChar != 8)
  205. {
  206. e.Handled = true;
  207. }
  208. if ((int)e.KeyChar == 8 && string.IsNullOrEmpty(uteFl.Text))
  209. {
  210. uteCol.Focus();
  211. uteCol.SelectAll();
  212. }
  213. }
  214. private void uteFl_TextChanged(object sender, EventArgs e)
  215. {
  216. Infragistics.Win.UltraWinEditors.UltraTextEditor te = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender;
  217. if (!Regex.IsMatch(te.Text, _layerPattern))
  218. {
  219. te.Text = string.Empty;
  220. }
  221. else
  222. {
  223. te.Text = te.Text.ToUpper();
  224. }
  225. if (te.Text.Length > 0)
  226. {
  227. uteRow.Focus();
  228. uteRow.SelectAll();
  229. }
  230. }
  231. private void uteCol_KeyPress(object sender, KeyPressEventArgs e)
  232. {
  233. if (((((int)e.KeyChar) < 48 || ((int)e.KeyChar) > 57)) && (int)e.KeyChar != 8)
  234. {
  235. e.Handled = true;
  236. }
  237. if ((int)e.KeyChar == 8 && string.IsNullOrEmpty(uteCol.Text))
  238. {
  239. uteYard.Focus();
  240. uteYard.SelectAll();
  241. }
  242. }
  243. private void uteCol_KeyDown(object sender, KeyEventArgs e)
  244. {
  245. if (e.KeyValue == 39 || e.KeyValue == 40 || e.KeyValue == 13)
  246. {
  247. uteFl.Focus();
  248. uteFl.SelectAll();
  249. }
  250. else if (e.KeyValue == 37 || e.KeyValue == 38)
  251. {
  252. uteYard.Focus();
  253. uteYard.SelectAll();
  254. }
  255. }
  256. private void uteCol_TextChanged(object sender, EventArgs e)
  257. {
  258. Infragistics.Win.UltraWinEditors.UltraTextEditor te = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender;
  259. if (!Regex.IsMatch(te.Text, _numPattern))
  260. {
  261. te.Text = string.Empty;
  262. }
  263. if (te.Text.Length > 1)
  264. {
  265. uteFl.Focus();
  266. uteFl.SelectAll();
  267. }
  268. }
  269. }
  270. }