AddScrewView.xaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Prism.Events;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  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.Shapes;
  15. using TeamAAS_VP.Enums;
  16. using TeamAAS_VP.Events;
  17. using TeamAAS_VP.Interfaces;
  18. namespace TeamAAS_VP.Views
  19. {
  20. /// <summary>
  21. /// AddScrewView.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class AddScrewView : Window
  24. {
  25. IConfigService _configService;
  26. IEventAggregator _eventAggregator;
  27. public string ScannedBarcode { get; private set; }
  28. public AddScrewView()
  29. {
  30. InitializeComponent();
  31. // 窗口加载完成后,自动让输入框获得焦点
  32. this.Loaded += (s, e) =>
  33. {
  34. BarcodeTextBox.Focus();
  35. };
  36. }
  37. private void OkButton_Click(object sender, RoutedEventArgs e)
  38. {
  39. var stationConfig = _configService.GetDeviceInfo(0);
  40. ScannedBarcode = BarcodeTextBox.Text;
  41. if (string.IsNullOrWhiteSpace(ScannedBarcode))
  42. {
  43. MessageBox.Show("请先扫描螺丝条码", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
  44. BarcodeTextBox.Focus(); // 重新聚焦
  45. return;
  46. }
  47. if (ScannedBarcode == stationConfig.DataInfo.Screwsize1 || ScannedBarcode == stationConfig.DataInfo.Screwsize2)
  48. {
  49. MessageBox.Show("螺丝型号匹配成功", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
  50. SendTaskMessage($"螺丝型号匹配成功", MessageLevel.Info);
  51. }
  52. else
  53. {
  54. MessageBox.Show("螺丝型号匹配失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
  55. SendTaskMessage($"螺丝型号匹配失败", MessageLevel.Error);
  56. }
  57. DialogResult = true;
  58. Close();
  59. }
  60. private void CancelButton_Click(object sender, RoutedEventArgs e)
  61. {
  62. DialogResult = false;
  63. Close();
  64. }
  65. public void SendTaskMessage(string msg, MessageLevel level)
  66. {
  67. App.Current.Dispatcher.Invoke(() =>
  68. {
  69. _eventAggregator.GetEvent<TaskMessageNotification>().Publish(new Models.MessageStruct() { Message = msg, level = level });
  70. });
  71. }
  72. }
  73. }