using Prism.Events; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using TeamAAS_VP.Enums; using TeamAAS_VP.Events; using TeamAAS_VP.Interfaces; namespace TeamAAS_VP.Views { /// /// AddScrewView.xaml 的交互逻辑 /// public partial class AddScrewView : Window { IConfigService _configService; IEventAggregator _eventAggregator; public string ScannedBarcode { get; private set; } public AddScrewView() { InitializeComponent(); // 窗口加载完成后,自动让输入框获得焦点 this.Loaded += (s, e) => { BarcodeTextBox.Focus(); }; } private void OkButton_Click(object sender, RoutedEventArgs e) { var stationConfig = _configService.GetDeviceInfo(0); ScannedBarcode = BarcodeTextBox.Text; if (string.IsNullOrWhiteSpace(ScannedBarcode)) { MessageBox.Show("请先扫描螺丝条码", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); BarcodeTextBox.Focus(); // 重新聚焦 return; } if (ScannedBarcode == stationConfig.DataInfo.Screwsize1 || ScannedBarcode == stationConfig.DataInfo.Screwsize2) { MessageBox.Show("螺丝型号匹配成功", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); SendTaskMessage($"螺丝型号匹配成功", MessageLevel.Info); } else { MessageBox.Show("螺丝型号匹配失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); SendTaskMessage($"螺丝型号匹配失败", MessageLevel.Error); } DialogResult = true; Close(); } private void CancelButton_Click(object sender, RoutedEventArgs e) { DialogResult = false; Close(); } public void SendTaskMessage(string msg, MessageLevel level) { App.Current.Dispatcher.Invoke(() => { _eventAggregator.GetEvent().Publish(new Models.MessageStruct() { Message = msg, level = level }); }); } } }