UCStationMain.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using MeterVision.Dlg;
  2. using MeterVision.model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace MeterVision.Station
  20. {
  21. /// <summary>
  22. /// UCStationMain.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class UCStationMain : UserControl, INotifyPropertyChanged
  25. {
  26. public event PropertyChangedEventHandler PropertyChanged;
  27. protected void OnPropertyChanged(string propertyName)
  28. {
  29. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  30. }
  31. private string _findStationId;
  32. public string FindStationId
  33. {
  34. get => _findStationId;
  35. set
  36. {
  37. if(_findStationId != value)
  38. {
  39. _findStationId = value;
  40. OnPropertyChanged(nameof(FindStationId));
  41. //ucStationGrid.ChangeFindStationId(FindStationId);
  42. }
  43. }
  44. }
  45. public UCStationMain()
  46. {
  47. InitializeComponent();
  48. txtFindStationId.Text = "";
  49. FindStationId = "";
  50. this.DataContext = this;
  51. }
  52. private void BtnQuery_Click(object sender, RoutedEventArgs e)
  53. {
  54. FindStationId = txtFindStationId.Text.Trim();
  55. }
  56. private void BtnClearAll_Click(object sender, RoutedEventArgs e)
  57. {
  58. ucStationGrid.ClearAllStation();
  59. }
  60. private void BtnAddStation_Click(object sender, RoutedEventArgs e)
  61. {
  62. ////StationItem newItem = new StationItem();
  63. //EditStationDlg2 dialog = new EditStationDlg2(null)
  64. //{
  65. // Owner = Application.Current.MainWindow,
  66. // WindowStartupLocation = WindowStartupLocation.CenterOwner
  67. //};
  68. //if(dialog.ShowDialog() == true)
  69. //{
  70. // //ucStationGrid.ChangeFindStationId(null);
  71. // //ucStationGrid.ChangeFindStationId(FindStationId);
  72. //}
  73. }
  74. private void BtnRefresh_Click(object sender, RoutedEventArgs e)
  75. {
  76. //ucStationGrid.ChangeFindStationId(null);
  77. //ucStationGrid.ChangeFindStationId(FindStationId);
  78. }
  79. private async void BtnStationFirstPage_Click(object sender, RoutedEventArgs e)
  80. {
  81. await ucStationGrid.FirstPage();
  82. }
  83. private async void BtnStationPrePage_Click(object sender, RoutedEventArgs e)
  84. {
  85. await ucStationGrid.PrePage();
  86. }
  87. private async void BtnStationNextPage_Click(object sender, RoutedEventArgs e)
  88. {
  89. await ucStationGrid.NextPage();
  90. }
  91. private async void BtnStationLastPage_Click(object sender, RoutedEventArgs e)
  92. {
  93. await ucStationGrid.LastPage();
  94. }
  95. private async void BtnStationSpeciPage_Click(object sender, RoutedEventArgs e)
  96. {
  97. try
  98. {
  99. int pageNumber = int.Parse(txtStationPageNumber.Text.ToString());
  100. await ucStationGrid.SpeciPage(pageNumber);
  101. }
  102. catch
  103. {
  104. }
  105. }
  106. private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
  107. {
  108. // 只允许数字输入
  109. e.Handled = !Regex.IsMatch(e.Text, @"^\d$");
  110. }
  111. private bool IsDigit(string text)
  112. {
  113. // 返回输入的字符是否为数字
  114. return text.All(char.IsDigit);
  115. }
  116. private void TxtFindStationId_PreviewTextInput(object sender, TextCompositionEventArgs e)
  117. {
  118. // 使用正则表达式检查输入的字符是否是数字
  119. e.Handled = !IsDigit(e.Text);
  120. }
  121. //------------------------------------------------------------------------------
  122. }
  123. }