using ICSharpCode.AvalonEdit.Search;
using MaterialDesignThemes.Wpf;
using NPOI.SS.Formula.Functions;
using Opc.Ua;
using Prism.Commands;
using Prism.Events;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using Team.FFFeederService.Interfaces;
using TeamAAS_VP.Controls;
using TeamAAS_VP.Core;
using TeamAAS_VP.Core.Cameras;
using TeamAAS_VP.Core.Lights;
using TeamAAS_VP.Enums;
using TeamAAS_VP.Events;
using TeamAAS_VP.Interfaces;
using TeamAAS_VP.Models;
using TeamAAS_VP.Models.Lights;
using TeamAAS_VP.Models.Scanner;
using TeamAAS_VP.Resources.Languages;
using TeamAAS_VP.Services;
using TeamAAS_VP.ViewModels.User;
using TouchSocket.Core;
using WPFLocalizeExtension.Engine;
namespace TeamAAS_VP.ViewModels
{
public class SettingViewModel : BindableBase, IConfirmNavigationRequest
{
IRegionManager _regionManager;
IEventAggregator _eventAggregator;
IContainerProvider _container;
IDialogService _dialogService;
IConfigService _configService;
IRobotService _robotService;
IScannerService _scannerService;
ICameraService _cameraService;
IFeederService _feeder_service;
IFeederService _feederService;
IPlcService _plcService;
IProductService _productService;
ISystemDatabaseService _systemDatabaseService;
bool isFirstLoad = true;
#region 属性
private ScanRs232ConfigModel _ScanConfig;
public ScanRs232ConfigModel ScanConfig
{
get { return _ScanConfig; }
set { SetProperty(ref _ScanConfig, value); }
}
private bool _IsSaveScrewCurve;
///
/// 是否保存锁付曲线图
///
public bool IsSaveScrewCurve
{
get { return _IsSaveScrewCurve; }
set { SetProperty(ref _IsSaveScrewCurve, value); }
}
private Management _management;
public Management management
{
get { return _management; }
set { SetProperty(ref _management, value); }
}
private ObservableCollection _RobotList;
public ObservableCollection RobotList
{
get { return _RobotList; }
set { SetProperty(ref _RobotList, value); }
}
private ObservableCollection _ScannerList;
public ObservableCollection ScannerList
{
get { return _ScannerList; }
set { SetProperty(ref _ScannerList, value); }
}
private ObservableCollection _CameraList;
public ObservableCollection CameraList
{
get { return _CameraList; }
set { SetProperty(ref _CameraList, value); }
}
private ObservableCollection _FeederList;
public ObservableCollection FeederList
{
get { return _FeederList; }
set { SetProperty(ref _FeederList, value); }
}
private ObservableCollection _PlcList;
public ObservableCollection PlcList
{
get { return _PlcList; }
set { SetProperty(ref _PlcList, value); }
}
private Language _CurrentLanguage;
public Language CurrentLanguage
{
get { return _CurrentLanguage; }
set { SetProperty(ref _CurrentLanguage, value); }
}
private RobotInfo _SelectRobot;
///
/// 选中的机器人
///
public RobotInfo SelectRobot
{
get { return _SelectRobot; }
set
{
SetProperty(ref _SelectRobot, value);
if (value != null && (value.RobotBrand == RobotBrand.XYZ_Platform || value.RobotBrand == RobotBrand.XYZU_Platform))
{
RobotSelectedPlc = PlcList.FirstOrDefault(p => p.Id == value.PLC);
var root = _robotService.GetRobot(SelectRobot.Id);
if (root != null)
{
//ResultsValues.Clear();
//var res = root.GetNodesValue();
//for (int i = 0; i < res.Count; i++)
//{
// if (res[i].StatusCode.Code != 2150891520)
// {
// ResultsValues.Add(res[i].Value.ToString());
// }
// else
// {
// break;
// }
//}
}
}
}
}
private ScannerInfo _SelectScanner;
///
/// 选中的扫码枪
///
public ScannerInfo SelectScanner
{
get { return _SelectScanner; }
set
{
SetProperty(ref _SelectScanner, value);
}
}
private FeederInfo _SelectFeeder;
///
/// 选中的Feeder
///
public FeederInfo SelectFeeder
{
get { return _SelectFeeder; }
set { SetProperty(ref _SelectFeeder, value); }
}
private PlcInfo _SelectPlc;
public PlcInfo SelectPlc
{
get { return _SelectPlc; }
set { SetProperty(ref _SelectPlc, value); }
}
private ObservableCollection _ResultsValues = new ObservableCollection();
public ObservableCollection ResultsValues { get => _ResultsValues; set => _ResultsValues = value; }
private CameraInfo _SelectCamera;
///
/// 选中的Camera
///
public CameraInfo SelectCamera
{
get { return _SelectCamera; }
set { SetProperty(ref _SelectCamera, value); }
}
private double _Title1;
public double Title1
{
get { return _Title1; }
set { SetProperty(ref _Title1, value); }
}
private double _Title2;
public double Title2
{
get { return _Title2; }
set { SetProperty(ref _Title2, value); }
}
private double _Title3;
public double Title3
{
get { return _Title3; }
set { SetProperty(ref _Title3, value); }
}
private double _Title4;
public double Title4
{
get { return _Title4; }
set { SetProperty(ref _Title4, value); }
}
private double _Body1;
public double Body1
{
get { return _Body1; }
set { SetProperty(ref _Body1, value); }
}
private double _Body2;
public double Body2
{
get { return _Body2; }
set { SetProperty(ref _Body2, value); }
}
private double _Body3;
public double Body3
{
get { return _Body3; }
set { SetProperty(ref _Body3, value); }
}
private double _Body4;
public double Body4
{
get { return _Body4; }
set { SetProperty(ref _Body4, value); }
}
private double _Captions1;
public double Captions1
{
get { return _Captions1; }
set { SetProperty(ref _Captions1, value); }
}
private double _Captions2;
public double Captions2
{
get { return _Captions2; }
set { SetProperty(ref _Captions2, value); }
}
private double _Captions3;
public double Captions3
{
get { return _Captions3; }
set { SetProperty(ref _Captions3, value); }
}
private double _Captions4;
public double Captions4
{
get { return _Captions4; }
set { SetProperty(ref _Captions4, value); }
}
private PlcInfo _RobotSelectedPlc;
public PlcInfo RobotSelectedPlc
{
get { return _RobotSelectedPlc; }
set
{
SetProperty(ref _RobotSelectedPlc, value);
if (SelectRobot != null)
{
if (value != null)
{
SelectRobot.PLC = value.Id;
}
else
{
SelectRobot.PLC = Guid.Empty;
}
}
}
}
private BgModbusTcp _BgModbus;
public BgModbusTcp BgModbus
{
get { return _BgModbus; }
set { SetProperty(ref _BgModbus, value); }
}
private BgTcpIP _BgTcp;
public BgTcpIP BgTcp
{
get { return _BgTcp; }
set { SetProperty(ref _BgTcp, value); }
}
private ObservableCollection _LightControllerList;
public ObservableCollection LightControllerList
{
get { return _LightControllerList; }
set { SetProperty(ref _LightControllerList, value); }
}
private LightControllerConfig _SelectLightController;
public LightControllerConfig SelectLightController
{
get { return _SelectLightController; }
set { SetProperty(ref _SelectLightController, value); }
}
private string _ScrewCurvePath;
///
/// 锁付曲线图保存路径
///
public string ScrewCurvePath
{
get { return _ScrewCurvePath; }
set { SetProperty(ref _ScrewCurvePath, value); }
}
private DeviceInfo _DeviceInfo;
public DeviceInfo DeviceInfo
{
get { return _DeviceInfo; }
set { SetProperty(ref _DeviceInfo, value); }
}
private SerialPortConfig _CardReaderConfig;
public SerialPortConfig CardReaderConfig
{
get { return _CardReaderConfig; }
set { SetProperty(ref _CardReaderConfig, value); }
}
#endregion
#region 命令
public DelegateCommand LoadedCommand { get; set; }
private DelegateCommand _SaveSystemParametersCommand;
public DelegateCommand SaveSystemParametersCommand =>
_SaveSystemParametersCommand ?? (_SaveSystemParametersCommand = new DelegateCommand(ExecuteSaveSystemParametersCommand));
private DelegateCommand _AddRobotCommand;
public DelegateCommand AddRobotCommand =>
_AddRobotCommand ?? (_AddRobotCommand = new DelegateCommand(ExecuteAddRobotCommand));
private DelegateCommand _AddScannerCommand;
public DelegateCommand AddScannerCommand =>
_AddScannerCommand ?? (_AddScannerCommand = new DelegateCommand(ExecuteAddScannerCommand));
private DelegateCommand _RemoveCommand;
public DelegateCommand RemoveCommand =>
_RemoveCommand ?? (_RemoveCommand = new DelegateCommand(ExecuteRemoveCommand));
private DelegateCommand _RemoveScannerCommand;
public DelegateCommand RemoveScannerCommand =>
_RemoveScannerCommand ?? (_RemoveScannerCommand = new DelegateCommand(ExecuteRemoveScannerCommand));
private DelegateCommand _AddFeederCommand;
public DelegateCommand AddFeederCommand =>
_AddFeederCommand ?? (_AddFeederCommand = new DelegateCommand(ExecuteAddFeederCommand));
private DelegateCommand _RemoveFeederCommand;
public DelegateCommand RemoveFeederCommand =>
_RemoveFeederCommand ?? (_RemoveFeederCommand = new DelegateCommand(ExecuteRemoveFeederCommand));
private DelegateCommand _SelectLanguageCommand;
public DelegateCommand SelectLanguageCommand =>
_SelectLanguageCommand ?? (_SelectLanguageCommand = new DelegateCommand(ExecuteSelectLanguageCommand));
private DelegateCommand _SaveRobotsCommand;
public DelegateCommand SaveRobotsCommand =>
_SaveRobotsCommand ?? (_SaveRobotsCommand = new DelegateCommand(ExecuteSaveRobotsCommand));
private DelegateCommand _SaveScannerCommand;
public DelegateCommand SaveScannerCommand =>
_SaveScannerCommand ?? (_SaveScannerCommand = new DelegateCommand(ExecuteSaveScannersCommand));
private DelegateCommand _SaveFeedersCommand;
public DelegateCommand SaveFeedersCommand =>
_SaveFeedersCommand ?? (_SaveFeedersCommand = new DelegateCommand(ExecuteSaveFeedersCommand));
private DelegateCommand _SaveCommunicateCommand;
public DelegateCommand SaveCommunicateCommand =>
_SaveCommunicateCommand ?? (_SaveCommunicateCommand = new DelegateCommand(ExecuteSaveCommunicateCommand));
private DelegateCommand _AddCameraCommand;
public DelegateCommand AddCameraCommand =>
_AddCameraCommand ?? (_AddCameraCommand = new DelegateCommand(ExecuteAddCameraCommand));
private DelegateCommand _EditCameraCommand;
public DelegateCommand EditCameraCommand =>
_EditCameraCommand ?? (_EditCameraCommand = new DelegateCommand(ExecuteEditCameraCommand));
private DelegateCommand _RemoveCameraCommand;
public DelegateCommand RemoveCameraCommand =>
_RemoveCameraCommand ?? (_RemoveCameraCommand = new DelegateCommand(ExecuteRemoveCameraCommand));
private DelegateCommand _SaveCamerasCommand;
public DelegateCommand SaveCamerasCommand =>
_SaveCamerasCommand ?? (_SaveCamerasCommand = new DelegateCommand(ExecuteSaveCamerasCommand));
private DelegateCommand _AddPlcCommand;
public DelegateCommand AddPlcCommand =>
_AddPlcCommand ?? (_AddPlcCommand = new DelegateCommand(ExecuteAddPlcCommand));
private DelegateCommand _RemovePlcCommand;
public DelegateCommand RemovePlcCommand =>
_RemovePlcCommand ?? (_RemovePlcCommand = new DelegateCommand(ExecuteRemovePlcCommand));
private DelegateCommand _SavePlcsCommand;
public DelegateCommand SavePlcsCommand =>
_SavePlcsCommand ?? (_SavePlcsCommand = new DelegateCommand(ExecuteSavePlcsCommand));
private DelegateCommand _AddLightControllerCommand;
public DelegateCommand AddLightControllerCommand => _AddLightControllerCommand ?? (_AddLightControllerCommand = new DelegateCommand(ExecuteAddLightControllerCommand));
private DelegateCommand _RemoveLightControllerCommand;
public DelegateCommand RemoveLightControllerCommand => _RemoveLightControllerCommand ?? (_RemoveLightControllerCommand = new DelegateCommand(ExecuteRemoveLightControllerCommand));
private DelegateCommand _SaveLightControllersCommand;
public DelegateCommand SaveLightControllersCommand => _SaveLightControllersCommand ?? (_SaveLightControllersCommand = new DelegateCommand(ExecuteSaveLightControllersCommand));
private DelegateCommand _BrowseScrewCurvePathCommand;
public DelegateCommand BrowseScrewCurvePathCommand => _BrowseScrewCurvePathCommand ?? (_BrowseScrewCurvePathCommand = new DelegateCommand(ExecuteBrowseScrewCurvePathCommand));
private DelegateCommand _SaveDeviceInfoCommand;
public DelegateCommand SaveDeviceInfoCommand => _SaveDeviceInfoCommand ?? (_SaveDeviceInfoCommand = new DelegateCommand(ExecuteSaveDeviceInfoCommand));
private DelegateCommand _SelectSaveImagePathCommand;
public DelegateCommand SelectSaveImagePathCommand =>
_SelectSaveImagePathCommand ?? (_SelectSaveImagePathCommand = new DelegateCommand(ExecuteSelectSaveImagePathCommand));
private DelegateCommand _SaveCardReaderConfigCommand;
public DelegateCommand SaveCardReaderConfigCommand =>
_SaveCardReaderConfigCommand ?? (_SaveCardReaderConfigCommand = new DelegateCommand(ExecuteSaveCardReaderConfigCommand));
#endregion
#region 事件
#endregion
public SettingViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService,
IProductService productService, ISystemDatabaseService systemDatabaseService,IScannerService scannerService)
{
_regionManager = regionManager;
_eventAggregator = ea;
_container = container;
_dialogService = dialogService;
_configService = configService;
_robotService = robotService;
_cameraService = cameraService;
_feederService = feederService;
_plcService = plcService;
_productService = productService;
_scannerService = scannerService;
_systemDatabaseService = systemDatabaseService;
management = _container.Resolve();
LoadedCommand = new DelegateCommand(OnLoad);
//订阅权限登录事件
_eventAggregator.GetEvent().Subscribe(LoginChange);
}
#region 方法
#region 扫码枪
private void ExecuteAddScannerCommand()
{
_dialogService.ShowDialog("AddScanner", rst =>
{
//对话框关闭之后的回调函数,可以在这解析结果。
ButtonResult result1 = rst.Result;
if (result1 == ButtonResult.OK)
{
var param = rst.Parameters.GetValue("Scanner");
var scanner = new ScannerInfo()
{
Id = param.Id,
ScannerName = param.ScannerName,
ConnectType = param.ConnectType,
ScannerBrand = param.ScannerBrand,
IP = param.IP,
Port = param.Port,
Terminator = param.Terminator,
};
ScannerList.Add(scanner);
_configService.AddOrUpdateScanner(scanner);
_scannerService.CreateScanner(scanner.Id, scanner);
//对所有产品也进行添加
_productService.AddScannerPointToProduct(scanner.Id, scanner.ScannerName);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
}
});
}
void ExecuteRemoveScannerCommand()
{
if (MessageBox.Show(Lang.是否移除扫码枪, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
// 找到要删除的扫描枪
var scannerToRemove = ScannerList.FirstOrDefault(s => s.Id == SelectScanner.Id);
if (scannerToRemove != null)
{
ScannerList.Remove(scannerToRemove);
_configService.RemoveScanner(scannerToRemove.Id);
_scannerService.RemoveScanner(scannerToRemove.Id);
//对所有产品也进行移除
_productService.RemoveScannerPointFromProduct(scannerToRemove.Id);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
}
}
}
async void ExecuteSaveScannersCommand()
{
var view = new ShowMessage($"AAS", Lang.是否保存扫码枪);
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool)
{
if (((bool)result))
{
foreach (var item in ScannerList)
{
_configService.AddOrUpdateScanner(item);
}
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
}
#endregion
#region 机器人
private void ExecuteAddRobotCommand()
{
_dialogService.ShowDialog("AddRobot", rst =>
{
//对话框关闭之后的回调函数,可以在这解析结果。
ButtonResult result1 = rst.Result;
if (result1 == ButtonResult.OK)
{
var param = rst.Parameters.GetValue("Robot");
var robot = new RobotInfo()
{
Id = param.Id,
RobotName = param.RobotName,
ConnectType = param.ConnectType,
RobotBrand = param.RobotBrand,
IP = param.IP,
Port = param.Port,
Terminator = param.Terminator,
};
RobotList.Add(robot);
_configService.AddOrUpdateRobot(robot);
_robotService.CreateRobot(robot.Id, robot);
//对所有产品也进行添加
_productService.AddRobotPointToProduct(robot.Id, robot.RobotName);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
}
});
}
void ExecuteRemoveCommand()
{
if (MessageBox.Show(Lang.是否移除机器人, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
// 找到要删除的机器人
var robotToRemove = RobotList.FirstOrDefault(r => r.Id == SelectRobot.Id);
if (robotToRemove != null)
{
RobotList.Remove(robotToRemove);
_configService.RemoveRobot(robotToRemove.Id);
_robotService.RemoveRobot(robotToRemove.Id);
//对所有产品也进行移除
_productService.RemoveRobotPointFromProduct(robotToRemove.Id);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
}
}
}
async void ExecuteSaveRobotsCommand()
{
var view = new ShowMessage($"AAS", Lang.是否保存机器人);
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool)
{
if (((bool)result))
{
foreach (var item in RobotList)
{
_configService.AddOrUpdateRobot(item);
}
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
}
#endregion
#region 相机
///
/// 保存所有相机
///
async void ExecuteSaveCamerasCommand()
{
var view = new ShowMessage($"AAS", Lang.是否保存相机配置);
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool)
{
if (((bool)result))
{
//management.DeviceConfig.Cameras = DeviceConfig.Cameras;
//management.SaveCamerasDeviceConfig();
//management.DeviceConfig.Cameras = DeviceConfig.Cameras;
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
}
///
/// 移除相机
///
void ExecuteRemoveCameraCommand()
{
if (MessageBox.Show(Lang.是否移除相机, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
// 找到要删除的相机
var cameraToRemove = CameraList.FirstOrDefault(r => r.Id == SelectCamera.Id);
if (cameraToRemove != null)
{
_configService.RemoveCamera(cameraToRemove.Id);
_cameraService.RemoveCamera(cameraToRemove.Id);
var root = _configService.GetAllCameras();
CameraList = new ObservableCollection(root);
foreach (var item in CameraList)
{
_cameraService.UpdateCameraNumber(item.Id, item.CameraNo);
}
//对所有产品也进行移除
_productService.RemoveCameraFromProduct(cameraToRemove.Id);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
}
///
/// 编辑相机
///
void ExecuteEditCameraCommand()
{
if (SelectCamera == null) return;
bool isSelectedCameraBrandSucced = false;
CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
IDialogParameters parameters1 = new DialogParameters();
parameters1.Add("CameraBrand", SelectCamera.CameraBrand);
_dialogService.ShowDialog("SelectCameraBrand", parameters1, rst =>
{
if (rst.Result == ButtonResult.OK)
{
isSelectedCameraBrandSucced = true;
cameraBrand = rst.Parameters.GetValue("CameraBrand");
}
else
{
return;
}
});
if (!isSelectedCameraBrandSucced) { return; }
(bool isInstalled, string version) result = (false, "");
string softwarename = "";
switch (cameraBrand)
{
case CameraBrand.HikRobot_MVS:
softwarename = "MVS";
result = MvCamera.CheckSoftwareInstalled();
break;
case CameraBrand.Basler_Pylon:
softwarename = "Pylon 7";
result = BaslerCamera.CheckSoftwareInstalled();
break;
case CameraBrand.IRayple:
softwarename = "MV Viewer";
result = AHuaCamera.CheckSoftwareInstalled();
break;
case CameraBrand.Cognex:
softwarename = "Cognex VisionPro";
result = CognexCamera.CheckSoftwareInstalled();
break;
case CameraBrand.Galaxy:
softwarename = "Galaxy Viewer";
result = GalaxyCamera.CheckSoftwareInstalled();
break;
case CameraBrand.Opt:
softwarename = "OPT Camera Viewer";
result = OptCamera.CheckSoftwareInstalled();
break;
default:
break;
}
if (!result.isInstalled)
{
if (string.IsNullOrEmpty(result.version))
{
//未安装
MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
else
{
//版本较低
MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
return;
}
//编辑前的相机名称
string oldCameraName = SelectCamera.CameraName;
IDialogParameters parameters = new DialogParameters();
parameters.Add("CameraBrand", cameraBrand);
parameters.Add("Camera", SelectCamera.Copy());
_dialogService.ShowDialog("EditCamera", parameters, rst =>
{
//对话框关闭之后的回调函数,可以在这解析结果。
ButtonResult result1 = rst.Result;
if (result1 == ButtonResult.OK)
{
var param = rst.Parameters.GetValue("Camera");
SelectCamera.CameraName = param.CameraName;
SelectCamera.SerialNumber = param.SerialNumber;
SelectCamera.Model = param.Model;
SelectCamera.ManufacturerName = param.ManufacturerName;
SelectCamera.CameraType = param.CameraType;
SelectCamera.CameraBrand = param.CameraBrand;
SelectCamera.CameraIp = param.CameraIp;
_configService.AddOrUpdateCamera(SelectCamera);
if (oldCameraName != param.CameraName)
{
//对所有产品也进行修改
_productService.UpdateCameraNameInProduct(SelectCamera.Id, SelectCamera.CameraName);
}
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
});
}
///
/// 增加相机
///
void ExecuteAddCameraCommand()
{
bool isSelectedCameraBrandSucced = false;
CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
_dialogService.ShowDialog("SelectCameraBrand", rst =>
{
if (rst.Result == ButtonResult.OK)
{
isSelectedCameraBrandSucced = true;
cameraBrand = rst.Parameters.GetValue("CameraBrand");
}
else
{
return;
}
});
if (!isSelectedCameraBrandSucced) { return; }
;
(bool isInstalled, string version) result = (false, "");
string softwarename = "";
switch (cameraBrand)
{
case CameraBrand.HikRobot_MVS:
softwarename = "MVS";
result = MvCamera.CheckSoftwareInstalled();
break;
case CameraBrand.Basler_Pylon:
softwarename = "Pylon 7";
result = BaslerCamera.CheckSoftwareInstalled();
break;
case CameraBrand.IRayple:
softwarename = "MV Viewer";
result = AHuaCamera.CheckSoftwareInstalled();
break;
case CameraBrand.Cognex:
softwarename = "Cognex VisionPro";
result = CognexCamera.CheckSoftwareInstalled();
break;
case CameraBrand.Galaxy:
softwarename = "Galaxy Viewer";
result = GalaxyCamera.CheckSoftwareInstalled();
break;
case CameraBrand.Opt:
softwarename = "OPT Camera Viewer";
result = OptCamera.CheckSoftwareInstalled();
break;
default:
break;
}
if (!result.isInstalled)
{
if (string.IsNullOrEmpty(result.version))
{
//未安装
MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
else
{
//版本较低
MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
return;
}
IDialogParameters parameters = new DialogParameters();
parameters.Add("CameraBrand", cameraBrand);
_dialogService.ShowDialog("AddCamera", parameters, rst =>
{
//对话框关闭之后的回调函数,可以在这解析结果。
ButtonResult result1 = rst.Result;
if (result1 == ButtonResult.OK)
{
var param = rst.Parameters.GetValue("Camera");
var camera = new CameraInfo()
{
Id = param.Id,
CameraName = param.CameraName,
SerialNumber = param.SerialNumber,
Model = param.Model,
ManufacturerName = param.ManufacturerName,
CameraType = param.CameraType,
CameraBrand = param.CameraBrand,
CameraIp = param.CameraIp
};
CameraList.Add(camera);
_configService.AddOrUpdateCamera(camera);
_cameraService.CreateCamera(camera.Id, camera);
//对所有产品也进行添加
_productService.AddCameraToProduct(camera.Id, camera.CameraName);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
});
}
#endregion
#region Feeder
void ExecuteAddFeederCommand()
{
_dialogService.ShowDialog("AddFeeder", rst =>
{
//对话框关闭之后的回调函数,可以在这解析结果。
ButtonResult result1 = rst.Result;
if (result1 == ButtonResult.OK)
{
var param = rst.Parameters.GetValue("Feeder");
var feeder = new FeederInfo()
{
Id = param.Id,
FeederName = param.FeederName,
ConnectType = param.ConnectType,
FeederBrand = param.FeederBrand,
IP = param.IP,
Port = param.Port
};
FeederList.Add(feeder);
_configService.AddOrUpdateFeeder(feeder);
_feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
}
});
}
void ExecuteRemoveFeederCommand()
{
if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
// 找到要删除的机器人
var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
if (feederToRemove != null)
{
_configService.RemoveFeeder(feederToRemove.Id);
_feederService.RemoveFeeder(feederToRemove.Id);
var root = _configService.GetAllFeeders();
FeederList = new ObservableCollection(root);
foreach (var item in FeederList)
{
_feederService.UpdateFeederNo(item.Id, item.FeederNo);
}
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
}
}
}
async void ExecuteSaveFeedersCommand()
{
var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool)
{
if (((bool)result))
{
foreach (var item in FeederList)
{
_configService.AddOrUpdateFeeder(item);
}
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
}
#endregion
#region PLC
///
/// 保存PLC
///
async void ExecuteSavePlcsCommand()
{
var view = new ShowMessage($"AAS", Lang.是否保存PLC);
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool)
{
if (((bool)result))
{
foreach (var item in PlcList)
{
_configService.AddOrUpdatePlc(item);
}
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
}
///
/// 移除PLC
///
void ExecuteRemovePlcCommand()
{
if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
// 找到要删除的plc
var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
if (plcToRemove != null)
{
_configService.RemovePlc(plcToRemove.Id);
_plcService.RemovePlc(plcToRemove.Id);
var root = _configService.GetAllPlcs();
PlcList = new ObservableCollection(root);
foreach (var item in PlcList)
{
_plcService.UpdatePlcNumber(item.Id, item.Index);
}
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
}
}
}
///
/// 增加PLC
///
void ExecuteAddPlcCommand()
{
_dialogService.ShowDialog("AddPlc", rst =>
{
//对话框关闭之后的回调函数,可以在这解析结果。
ButtonResult result1 = rst.Result;
if (result1 == ButtonResult.OK)
{
var param = rst.Parameters.GetValue("PLC");
var plc = new PlcInfo()
{
Id = param.Id,
Name = param.Name,
CommunicationType = param.CommunicationType,
EndpointUrl = param.EndpointUrl,
};
PlcList.Add(plc);
_configService.AddOrUpdatePlc(plc);
_plcService.CreatePlc(plc.Id, plc);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
}
});
}
#endregion
#region Light handlers
void ExecuteAddLightControllerCommand()
{
// open dialog to add light controller (similar to robots)
_dialogService.ShowDialog("AddLightController", rst =>
{
if (rst.Result == ButtonResult.OK)
{
var param = rst.Parameters.GetValue("LightController");
// assign id and defaults if needed
if (param.Id == 0)
param.Id = (LightControllerList?.Count ?? 0) + 1;
LightControllerList.Add(param);
_configService.AddOrUpdateLightController(param);
SelectLightController = param;
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = "添加完成", Duration = 1 });
}
});
}
void ExecuteRemoveLightControllerCommand()
{
if (SelectLightController == null) return;
if (MessageBox.Show("是否移除光源控制器?", "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
_configService.RemoveLightController(SelectLightController.Id);
LightControllerList.Remove(SelectLightController);
SelectLightController = null;
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = "移除完成", Duration = 1 });
}
}
async void ExecuteSaveLightControllersCommand()
{
var view = new ShowMessage($"AAS", "是否保存光源控制器配置?");
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool && (bool)result)
{
foreach (var item in LightControllerList)
{
_configService.AddOrUpdateLightController(item);
}
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = "完成", Duration = 1 });
}
}
#endregion
#region 通讯
async void ExecuteSaveCommunicateCommand(string parm)
{
if (parm == "TCPIP")
{
var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool)
{
if (((bool)result))
{
_configService.SetBgTcp(BgTcp);
_configService.SaveBgTcp();
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
}
else if (parm == "ModbusTCP")
{
var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool)
{
if (((bool)result))
{
_configService.SetBgModbusTcp(BgModbus);
_configService.SaveBgModbusTcp();
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
}
else
{
return;
}
}
#endregion
#region 语言
void ExecuteSelectLanguageCommand(string language)
{
if (string.Equals(language, "ChineseSimplified"))
{
CurrentLanguage = Enums.Language.ChineseSimplified;
var sysConfig = _configService.GetSystemConfiguration();
sysConfig.CurrentLanguage = CurrentLanguage;
_configService.SaveSystemConfiguration(sysConfig);
var culture = new CultureInfo("zh-CN");
App.Current.Dispatcher.Thread.CurrentCulture = culture;
App.Current.Dispatcher.Thread.CurrentUICulture = culture;
LocalizeDictionary.Instance.Culture = culture;
Lang.Culture = culture;
Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
}
else if (string.Equals(language, "ChineseTraditional"))
{
CurrentLanguage = Enums.Language.ChineseTraditional;
var sysConfig = _configService.GetSystemConfiguration();
sysConfig.CurrentLanguage = CurrentLanguage;
_configService.SaveSystemConfiguration(sysConfig);
var culture = new CultureInfo("zh-TW");
App.Current.Dispatcher.Thread.CurrentCulture = culture;
App.Current.Dispatcher.Thread.CurrentUICulture = culture;
LocalizeDictionary.Instance.Culture = culture;
Lang.Culture = culture;
Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
}
else if (string.Equals(language, "English"))
{
CurrentLanguage = Enums.Language.English;
var sysConfig = _configService.GetSystemConfiguration();
sysConfig.CurrentLanguage = CurrentLanguage;
_configService.SaveSystemConfiguration(sysConfig);
var culture = new CultureInfo("en");
App.Current.Dispatcher.Thread.CurrentCulture = culture;
App.Current.Dispatcher.Thread.CurrentUICulture = culture;
LocalizeDictionary.Instance.Culture = culture;
Lang.Culture = culture;
Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
}
else if (string.Equals(language, "Japanese"))
{
CurrentLanguage = Enums.Language.Japanese;
var sysConfig = _configService.GetSystemConfiguration();
sysConfig.CurrentLanguage = CurrentLanguage;
_configService.SaveSystemConfiguration(sysConfig);
var culture = new CultureInfo("ja-JP");
App.Current.Dispatcher.Thread.CurrentCulture = culture;
App.Current.Dispatcher.Thread.CurrentUICulture = culture;
LocalizeDictionary.Instance.Culture = culture;
Lang.Culture = culture;
Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
}
}
#endregion
private void OnLoad()
{
if (!File.Exists(FilePath.ScanRS232ConfigPath))
{
var scan = new ScanRs232ConfigModel();
FileHelper.WriteJsonFile(scan, FilePath.ScanRS232ConfigPath);
}
this.ScanConfig = FileHelper.ReadJsonFile(FilePath.ScanRS232ConfigPath);
}
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "Title1":
Application.Current.Resources["Font.Size.Title1"] = Title1;
break;
case "Title2":
Application.Current.Resources["Font.Size.Title2"] = Title2;
break;
case "Title3":
Application.Current.Resources["Font.Size.Title3"] = Title3;
break;
case "Title4":
Application.Current.Resources["Font.Size.Title4"] = Title4;
break;
case "Body1":
Application.Current.Resources["Font.Size.Body1"] = Body1;
break;
case "Body2":
Application.Current.Resources["Font.Size.Body2"] = Body2;
break;
case "Body3":
Application.Current.Resources["Font.Size.Body3"] = Body3;
break;
case "Body4":
Application.Current.Resources["Font.Size.Body4"] = Body4;
break;
case "Captions1":
Application.Current.Resources["Font.Size.Captions1"] = Captions1;
break;
case "Captions2":
Application.Current.Resources["Font.Size.Captions2"] = Captions2;
break;
case "Captions3":
Application.Current.Resources["Font.Size.Captions3"] = Captions3;
break;
case "Captions4":
Application.Current.Resources["Font.Size.Captions4"] = Captions4;
break;
default:
break;
}
}
#endregion
#region 继承
///
/// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
///
///
///
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback)
{
continuationCallback(true);
}
///
/// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
///
///
///
public async void OnNavigatedTo(NavigationContext navigationContext)
{
if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
{
IsAllowEdit = false;
}
else
{
IsAllowEdit = true;
}
if (RobotList == null)
{
RobotList = new ObservableCollection();
var robots = _configService.GetAllRobots();
foreach (var robot in robots)
{
RobotList.Add(robot);
}
}
if (ScannerList == null)
{
ScannerList = new ObservableCollection();
var scanners = _configService.GetAllScanners();
foreach (var scanner in scanners)
{
ScannerList.Add(scanner);
}
}
if (CameraList == null)
{
CameraList = new ObservableCollection();
var cameras = _configService.GetAllCameras();
foreach (var camera in cameras)
{
CameraList.Add(camera);
}
}
if (FeederList == null)
{
FeederList = new ObservableCollection();
var feeders = _configService.GetAllFeeders();
foreach (var feeder in feeders)
{
FeederList.Add(feeder);
}
}
if (PlcList == null)
{
PlcList = new ObservableCollection();
var plcs = _configService.GetAllPlcs();
foreach (var plc in plcs)
{
PlcList.Add(plc);
}
}
// load light controllers
if (LightControllerList == null)
{
LightControllerList = new ObservableCollection();
var controllers = _configService.GetAllLightControllers();
foreach (var ctrl in controllers)
{
LightControllerList.Add(ctrl);
}
}
if (BgTcp == null)
{
BgTcp = _configService.GetBgTcp();
}
if (BgModbus == null)
{
BgModbus = _configService.GetBgModbusTcp();
}
if (DeviceInfo == null)
{
DeviceInfo = _configService.GetDeviceInfo();
}
if (CardReaderConfig == null)
{
// load card reader config
CardReaderConfig = _configService.GetCardReaderConfig();
}
CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
// load system parameters into UI
var sys = _configService.GetSystemConfiguration();
if (sys != null)
{
WorkMode = sys.WorkMode;
PickPointNum = sys.PickPointNum;
DowmCameraNum = sys.DowmCameraNum;
WorkMode = sys.WorkMode;
PickPointNum = sys.PickPointNum;
DowmCameraNum = sys.DowmCameraNum;
UpCameraPickNum = sys.UpCameraPickNum;
UpCameraPutNum = sys.UpCameraPutNum;
UPCameracheckNum = sys.UPCameracheckNum;
FixedCameraPickNum = sys.FixedCameraPickNum;
FixedCameraPutNum = sys.FixedCameraPutNum;
FixedCameracheckNum = sys.FixedCameracheckNum;
IsSaveScrewCurve = sys.IsSaveScrewCurve;
ScrewCurvePath = sys.ScrewCurvePath;
}
if (isFirstLoad)
{
Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
this.PropertyChanged += OnPropertyChanged;
isFirstLoad = false;
}
}
///
/// 是否允许导航到此视图模型。
///
///
///
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
///
/// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
///
///
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
#endregion
private bool _IsAllowEdit = false;
public bool IsAllowEdit
{
get { return _IsAllowEdit; }
set { SetProperty(ref _IsAllowEdit, value); }
}
private void LoginChange(Models.User user)
{
if (user.userPart == Enums.UserPart.Operator)
{
IsAllowEdit = false;
}
else
{
IsAllowEdit = true;
}
}
#region 系统参数
private Int16 _WorkMode = 0;
///
/// 工作模式 =1 拍1打1 =2 拍1打所有
///
public Int16 WorkMode
{
get { return _WorkMode; }
set { SetProperty(ref _WorkMode, value); }
}
private Int16 _PickPointNum = 0;
///
/// 取料位置 =0 不需要取料 =1 需要取料
///
public Int16 PickPointNum
{
get { return _PickPointNum; }
set { SetProperty(ref _PickPointNum, value); }
}
private Int16 _DowmCameraNum = 0;
///
/// 下相机拍照次数
///
public Int16 DowmCameraNum
{
get => _DowmCameraNum;
set => SetProperty(ref _DowmCameraNum, value);
}
private Int16 _UpCameraPickNum = 0;
///
/// 上相机取料拍照次数
///
public Int16 UpCameraPickNum
{
get => _UpCameraPickNum;
set => SetProperty(ref _UpCameraPickNum, value);
}
private Int16 _UpCameraPutNum = 0;
///
/// 上相机放料拍照次数
///
public Int16 UpCameraPutNum
{
get => _UpCameraPutNum;
set => SetProperty(ref _UpCameraPutNum, value);
}
private Int16 _UPCameracheckNum = 0;
///
/// 上相机锁附/组装次数
///
public Int16 UPCameracheckNum
{
get => _UPCameracheckNum;
set => SetProperty(ref _UPCameracheckNum, value);
}
private Int16 _FixedCameraPickNum = 0;
///
/// 取料固定位置拍产品相机数量
///
public Int16 FixedCameraPickNum
{
get => _FixedCameraPickNum;
set => SetProperty(ref _FixedCameraPickNum, value);
}
private Int16 _FixedCameraPutNum = 0;
///
/// 锁附/组装固定位置拍产品相机数量
///
public Int16 FixedCameraPutNum
{
get => _FixedCameraPutNum;
set => SetProperty(ref _FixedCameraPutNum, value);
}
private Int16 _FixedCameracheckNum = 0;
///
/// 固定相机检测锁附/组装次数
///
public Int16 FixedCameracheckNum
{
get => _FixedCameracheckNum;
set => SetProperty(ref _FixedCameracheckNum, value);
}
async void ExecuteSaveSystemParametersCommand()
{
var view = new ShowMessage($"AAS", "是否保存系统参数?");
var result = await DialogHost.Show(view, "RootDialog", null, null, null);
if (result != null && result is bool && (bool)result)
{
try
{
ExecuteSaveCardReaderConfigCommand();
FileHelper.WriteJsonFile(this.ScanConfig, FilePath.ScanRS232ConfigPath);
var sysConfig = _configService.GetSystemConfiguration();
sysConfig.WorkMode = WorkMode;
sysConfig.PickPointNum = PickPointNum;
sysConfig.DowmCameraNum = DowmCameraNum;
sysConfig.UpCameraPickNum = UpCameraPickNum;
sysConfig.UpCameraPutNum = UpCameraPutNum;
sysConfig.UPCameracheckNum = UPCameracheckNum;
sysConfig.FixedCameraPickNum = FixedCameraPickNum;
sysConfig.FixedCameraPutNum = FixedCameraPutNum;
sysConfig.FixedCameracheckNum = FixedCameracheckNum;
sysConfig.IsSaveScrewCurve = IsSaveScrewCurve;
sysConfig.ScrewCurvePath = ScrewCurvePath;
_configService.SaveSystemConfiguration(sysConfig);
await management.WriteSystemParameterToPlcAsync(sysConfig);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
catch (Exception ex)
{
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
}
}
}
///
/// 选择锁付曲线图保存路径
///
void ExecuteBrowseScrewCurvePathCommand()
{
try
{
using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
{
dlg.Description = "选择锁付曲线图保存路径";
dlg.ShowNewFolderButton = true;
if (!string.IsNullOrEmpty(ScrewCurvePath)) dlg.SelectedPath = ScrewCurvePath;
var result = dlg.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
{
ScrewCurvePath = dlg.SelectedPath;
}
}
}
catch (Exception ex)
{
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = ex.Message, Duration = 2 });
}
}
///
/// 保存读卡器配置
///
void ExecuteSaveCardReaderConfigCommand()
{
try
{
_configService.SaveCardReaderConfig(CardReaderConfig);
}
catch (Exception ex)
{
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
}
}
#endregion
#region 设备信息
///
/// 保存设备信息
///
void ExecuteSaveDeviceInfoCommand()
{
try
{
if (DeviceInfo != null)
{
_configService.SaveDeviceInfo(DeviceInfo);
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
}
}
catch (Exception ex)
{
_eventAggregator.GetEvent().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
}
}
///
/// 选择CSV存储路径
///
void ExecuteSelectSaveImagePathCommand()
{
if (DeviceInfo == null)
{
return;
}
using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog())
{
// Optional: set the initial directory
//dialog.SelectedPath = @"C:\";
// Show the folder browser dialog
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
DeviceInfo.SaveCsvPath = dialog.SelectedPath;
}
}
}
#endregion
}
}