|
|
@@ -21,6 +21,7 @@ using TeamAAS_VP.Interfaces;
|
|
|
using TeamAAS_VP.Models;
|
|
|
using TeamAAS_VP.Resources.Languages;
|
|
|
using TeamAAS_VP.Services;
|
|
|
+using TeamAAS_VP.ViewModels.Home;
|
|
|
using TouchSocket.Core;
|
|
|
|
|
|
namespace TeamAAS_VP.Views
|
|
|
@@ -28,31 +29,33 @@ namespace TeamAAS_VP.Views
|
|
|
/// <summary>
|
|
|
/// AddScrewView.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
- public partial class AddScrewView : Window
|
|
|
+ public partial class AddScrewView : UserControl
|
|
|
{
|
|
|
|
|
|
IConfigService _configService;
|
|
|
IEventAggregator _eventAggregator;
|
|
|
IPlcService _plcService;
|
|
|
public ICommand OkCommand { get; }
|
|
|
- public ICommand CancelCommand { get; }
|
|
|
+ //public ICommand CancelCommand { get; }
|
|
|
public string ScannedBarcode { get; private set; }
|
|
|
public AddScrewView(IConfigService configService, IEventAggregator eventAggregator, IPlcService plcService)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
- _configService = configService;
|
|
|
- _eventAggregator = eventAggregator;
|
|
|
- _plcService=plcService;
|
|
|
+ this.Width = 800;
|
|
|
+ this.Height = 500;
|
|
|
+ //_configService = configService;
|
|
|
+ //_eventAggregator = eventAggregator;
|
|
|
+ //_plcService=plcService;
|
|
|
|
|
|
- OkCommand = new RelayCommand(OkExecute);
|
|
|
- CancelCommand = new RelayCommand(CancelExecute);
|
|
|
+ //OkCommand = new RelayCommand(OkExecute);
|
|
|
+ //CancelCommand = new RelayCommand(CancelExecute);
|
|
|
|
|
|
this.Loaded += (s, e) => { BarcodeTextBox.Focus(); };
|
|
|
|
|
|
// 把Command赋值给DataContext,方便绑定
|
|
|
- DataContext = this;
|
|
|
+ //DataContext = this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
///// <summary>
|
|
|
///// PLC命令触发时
|
|
|
///// </summary>
|
|
|
@@ -115,55 +118,53 @@ namespace TeamAAS_VP.Views
|
|
|
//}
|
|
|
private async void OkExecute(object sender)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- var addressConfig = _configService.GetPlcAddresses();
|
|
|
-
|
|
|
- var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
|
|
|
-
|
|
|
- string a = "";
|
|
|
- var stationConfig = _configService.GetDeviceInfo(0);
|
|
|
- ScannedBarcode = BarcodeTextBox.Text;
|
|
|
- if (ScannedBarcode.Contains("|"))
|
|
|
- {
|
|
|
- string[] arr = ScannedBarcode.Split("|");
|
|
|
- for (int i = 0; i < 16; i++)
|
|
|
- {
|
|
|
- a += arr[i];
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- a = ScannedBarcode;
|
|
|
- }
|
|
|
- if (string.IsNullOrWhiteSpace(ScannedBarcode))
|
|
|
- {
|
|
|
- MessageBox.Show("请先扫描螺丝条码", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
- BarcodeTextBox.Focus(); // 重新聚焦
|
|
|
- return;
|
|
|
- }
|
|
|
- if (a == stationConfig.DataInfo.Screwsize1 || a == stationConfig.DataInfo.Screwsize2)
|
|
|
- {
|
|
|
- await plc.WriteNodeAsync<bool>(addressConfig.Out_PlcFail.Address, false);
|
|
|
- MessageBox.Show("螺丝型号匹配成功", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
- //SendTaskMessage($"螺丝型号匹配成功", MessageLevel.Info);
|
|
|
- ExportDataToCsv(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), a, stationConfig.DataInfo, true, @"D:\添加螺丝记录\螺丝上料Log.csv", appendMode: true);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- await plc.WriteNodeAsync<bool>(addressConfig.Out_PlcFail.Address, true);
|
|
|
- MessageBox.Show("螺丝型号匹配失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
-
|
|
|
- //SendTaskMessage($"螺丝型号匹配失败", MessageLevel.Error);
|
|
|
- ExportDataToCsv(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), a, stationConfig.DataInfo, false, @"D:\添加螺丝记录\螺丝上料Log.csv", appendMode: true);
|
|
|
- }
|
|
|
- DialogResult = true;
|
|
|
- Close();
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
+ //try
|
|
|
+ //{
|
|
|
+ // var addressConfig = _configService.GetPlcAddresses();
|
|
|
|
|
|
- }
|
|
|
+ // var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
|
|
|
+
|
|
|
+ // string a = "";
|
|
|
+ // var stationConfig = _configService.GetDeviceInfo(0);
|
|
|
+ // ScannedBarcode = BarcodeTextBox.Text;
|
|
|
+ // if (ScannedBarcode.Contains("|"))
|
|
|
+ // {
|
|
|
+ // string[] arr = ScannedBarcode.Split("|");
|
|
|
+ // for (int i = 0; i < 16; i++)
|
|
|
+ // {
|
|
|
+ // a += arr[i];
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // a = ScannedBarcode;
|
|
|
+ // }
|
|
|
+ // if (string.IsNullOrWhiteSpace(ScannedBarcode))
|
|
|
+ // {
|
|
|
+ // MessageBox.Show("请先扫描螺丝条码", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ // BarcodeTextBox.Focus(); // 重新聚焦
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // if (a == stationConfig.DataInfo.Screwsize1 || a == stationConfig.DataInfo.Screwsize2 || a == stationConfig.DataInfo.Screwsize3)
|
|
|
+ // {
|
|
|
+ // await plc.WriteNodeAsync<bool>(addressConfig.Out_PlcFail.Address, false);
|
|
|
+ // MessageBox.Show("螺丝型号匹配成功", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ // //SendTaskMessage($"螺丝型号匹配成功", MessageLevel.Info);
|
|
|
+ // ExportDataToCsv(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), a, stationConfig.DataInfo, true, @"D:\添加螺丝记录\螺丝上料Log.csv", appendMode: true);
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // await plc.WriteNodeAsync<bool>(addressConfig.Out_PlcFail.Address, true);
|
|
|
+ // MessageBox.Show("螺丝型号匹配失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+
|
|
|
+ // //SendTaskMessage($"螺丝型号匹配失败", MessageLevel.Error);
|
|
|
+ // ExportDataToCsv(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), a, stationConfig.DataInfo, false, @"D:\添加螺丝记录\螺丝上料Log.csv", appendMode: true);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //catch (Exception ex)
|
|
|
+ //{
|
|
|
+
|
|
|
+ //}
|
|
|
|
|
|
|
|
|
//PlcCommandTrigger(("AutoSensor", "", ""));
|
|
|
@@ -207,8 +208,7 @@ namespace TeamAAS_VP.Views
|
|
|
|
|
|
private void CancelExecute(object sender)
|
|
|
{
|
|
|
- DialogResult = false;
|
|
|
- Close();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//public void SendTaskMessage(string msg, MessageLevel level)
|
|
|
@@ -234,7 +234,7 @@ namespace TeamAAS_VP.Views
|
|
|
// 处理表头:仅当文件不存在/非追加模式时,才写入表头
|
|
|
if (!appendMode || !File.Exists(savePath))
|
|
|
{
|
|
|
- csvContent.AppendLine("日期时间,目标螺丝型号1,螺丝型号2,添加螺丝型号,是否匹配");
|
|
|
+ csvContent.AppendLine("日期时间,目标螺丝型号1,螺丝型号2,螺丝型号3,添加螺丝型号,是否匹配");
|
|
|
}
|
|
|
|
|
|
// 处理数据行
|
|
|
@@ -247,7 +247,7 @@ namespace TeamAAS_VP.Views
|
|
|
safeModel = $"\"{safeModel}\"";
|
|
|
}
|
|
|
|
|
|
- csvContent.AppendLine($"{dateTime},{DataInfo.Screwsize1},{DataInfo.Screwsize2},{model},{matchStr}");
|
|
|
+ csvContent.AppendLine($"{dateTime},{DataInfo.Screwsize1},{DataInfo.Screwsize2},{DataInfo.Screwsize3},{model},{matchStr}");
|
|
|
|
|
|
// 写入文件:UTF-8带BOM编码,Excel打开无乱码
|
|
|
if (appendMode && File.Exists(savePath))
|
|
|
@@ -263,26 +263,26 @@ namespace TeamAAS_VP.Views
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- public class RelayCommand : ICommand
|
|
|
- {
|
|
|
- private readonly Action<object> _execute;
|
|
|
- private readonly Func<object, bool> _canExecute;
|
|
|
+ //public class RelayCommand : ICommand
|
|
|
+ //{
|
|
|
+ // private readonly Action<object> _execute;
|
|
|
+ // private readonly Func<object, bool> _canExecute;
|
|
|
|
|
|
- public event EventHandler CanExecuteChanged
|
|
|
- {
|
|
|
- add { CommandManager.RequerySuggested += value; }
|
|
|
- remove { CommandManager.RequerySuggested -= value; }
|
|
|
- }
|
|
|
+ // public event EventHandler CanExecuteChanged
|
|
|
+ // {
|
|
|
+ // add { CommandManager.RequerySuggested += value; }
|
|
|
+ // remove { CommandManager.RequerySuggested -= value; }
|
|
|
+ // }
|
|
|
|
|
|
- public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
|
|
|
- {
|
|
|
- _execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
|
|
- _canExecute = canExecute;
|
|
|
- }
|
|
|
+ // public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
|
|
|
+ // {
|
|
|
+ // _execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
|
|
+ // _canExecute = canExecute;
|
|
|
+ // }
|
|
|
|
|
|
- public bool CanExecute(object parameter) => _canExecute == null || _canExecute(parameter);
|
|
|
+ // public bool CanExecute(object parameter) => _canExecute == null || _canExecute(parameter);
|
|
|
|
|
|
- public void Execute(object parameter) => _execute(parameter);
|
|
|
- }
|
|
|
+ // public void Execute(object parameter) => _execute(parameter);
|
|
|
+ //}
|
|
|
|
|
|
}
|