UserOutCodeRegion.xaml.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using Prism.Ioc;
  17. using Prism.Regions;
  18. namespace PDF_Master.Views.Dialog.ServiceDialog
  19. {
  20. /// <summary>
  21. /// CodeRegion.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class UserOutCodeRegion : UserControl
  24. {
  25. public UserOutCodeRegion()
  26. {
  27. InitializeComponent();
  28. Loaded += Focus_Loaded;
  29. }
  30. private void Focus_Loaded(object sender, RoutedEventArgs e)
  31. {
  32. text_Code1.Focus();
  33. }
  34. private void Code_TextChanged(object sender, TextChangedEventArgs e)
  35. {
  36. Grid_UserCodemsgVis.Visibility = Visibility.Collapsed;
  37. text_Code1.Select(text_Code1.Text.Length, 0);
  38. if (text_Code1.Text.Length == 1)
  39. {
  40. text_Code2.Focus();
  41. }
  42. else if (text_Code1.Text.Length > 1)
  43. {
  44. string str = text_Code1.Text;
  45. text_Code1.Text = str.Substring(0, 1);
  46. str = str.Remove(0, 1);
  47. if (str.Length > 0)
  48. {
  49. text_Code2.Text = str;
  50. }
  51. }
  52. }
  53. private void text_Code2_TextChanged(object sender, TextChangedEventArgs e)
  54. {
  55. Grid_UserCodemsgVis.Visibility = Visibility.Collapsed;
  56. text_Code2.Select(text_Code2.Text.Length, 0);
  57. if (text_Code2.Text.Length == 1)
  58. {
  59. text_Code3.Focus();
  60. }
  61. else if (text_Code2.Text.Length > 1)
  62. {
  63. string str = text_Code2.Text;
  64. text_Code2.Text = str.Substring(0, 1);
  65. str = str.Remove(0, 1);
  66. if (str.Length > 0)
  67. {
  68. text_Code3.Text = str;
  69. }
  70. }
  71. }
  72. private void text_Code3_TextChanged(object sender, TextChangedEventArgs e)
  73. {
  74. Grid_UserCodemsgVis.Visibility = Visibility.Collapsed;
  75. text_Code3.Select(text_Code3.Text.Length, 0);
  76. if (text_Code3.Text.Length == 1)
  77. {
  78. text_Code4.Focus();
  79. }
  80. else if (text_Code3.Text.Length > 1)
  81. {
  82. string str = text_Code3.Text;
  83. text_Code3.Text = str.Substring(0, 1);
  84. str = str.Remove(0, 1);
  85. if (str.Length > 0)
  86. {
  87. text_Code4.Text = str;
  88. }
  89. }
  90. }
  91. private void text_Code4_TextChanged(object sender, TextChangedEventArgs e)
  92. {
  93. Grid_UserCodemsgVis.Visibility = Visibility.Collapsed;
  94. text_Code4.Select(text_Code4.Text.Length, 0);
  95. if (this.text_Code4.Text.Length == 1)
  96. {
  97. this.text_Code5.Focus();
  98. }
  99. else if (text_Code4.Text.Length > 1)
  100. {
  101. string str = text_Code4.Text;
  102. text_Code4.Text = str.Substring(0, 1);
  103. str = str.Remove(0, 1);
  104. if (str.Length > 0)
  105. {
  106. text_Code5.Text = str;
  107. }
  108. }
  109. }
  110. private void text_Code5_TextChanged(object sender, TextChangedEventArgs e)
  111. {
  112. Grid_UserCodemsgVis.Visibility = Visibility.Collapsed;
  113. text_Code5.Select(text_Code5.Text.Length, 0);
  114. if (this.text_Code5.Text.Length == 1)
  115. {
  116. this.text_Code6.Focus();
  117. }
  118. else if (text_Code5.Text.Length > 1)
  119. {
  120. string str = text_Code5.Text;
  121. text_Code5.Text = str.Substring(0, 1);
  122. str = str.Remove(0, 1);
  123. if (str.Length > 0)
  124. {
  125. text_Code6.Text = str;
  126. }
  127. }
  128. }
  129. private void text_Code6_TextChanged(object sender, TextChangedEventArgs e)
  130. {
  131. Grid_UserCodemsgVis.Visibility = Visibility.Collapsed;
  132. text_Code6.Select(text_Code6.Text.Length, 0);
  133. if (this.text_Code6.Text.Length == 1)
  134. {
  135. text_Code6.Focus();
  136. }
  137. else if (text_Code6.Text.Length > 1)
  138. {
  139. string str = text_Code6.Text;
  140. text_Code6.Focus();
  141. text_Code6.Text = str.Substring(0, 1);
  142. }
  143. }
  144. private void text_Code1_KeyUp(object sender, KeyEventArgs e)
  145. {
  146. if (e.Key == Key.Back)
  147. {
  148. text_Code1.Text = "";
  149. text_Code1.Focus();
  150. }
  151. }
  152. private void text_Code2_KeyUp(object sender, KeyEventArgs e)
  153. {
  154. if (e.Key == Key.Back)
  155. {
  156. text_Code2.Text = "";
  157. text_Code1.Focus();
  158. text_Code1.Select(text_Code1.Text.Length, 0);
  159. }
  160. }
  161. private void text_Code3_KeyUp(object sender, KeyEventArgs e)
  162. {
  163. if (e.Key == Key.Back)
  164. {
  165. text_Code3.Text = "";
  166. text_Code2.Focus();
  167. text_Code2.Select(text_Code2.Text.Length, 0);
  168. }
  169. }
  170. private void text_Code4_KeyUp(object sender, KeyEventArgs e)
  171. {
  172. if (e.Key == Key.Back)
  173. {
  174. text_Code4.Text = "";
  175. text_Code3.Focus();
  176. text_Code3.Select(text_Code3.Text.Length, 0);
  177. }
  178. }
  179. private void text_Code5_KeyUp(object sender, KeyEventArgs e)
  180. {
  181. if (e.Key == Key.Back)
  182. {
  183. text_Code5.Text = "";
  184. text_Code4.Focus();
  185. text_Code4.Select(text_Code4.Text.Length, 0);
  186. }
  187. }
  188. private void text_Code6_KeyUp(object sender, KeyEventArgs e)
  189. {
  190. if (e.Key == Key.Back)
  191. {
  192. text_Code6.Text = "";
  193. text_Code5.Focus();
  194. text_Code5.Select(text_Code5.Text.Length, 0);
  195. }
  196. }
  197. private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
  198. {
  199. e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
  200. }
  201. }
  202. }