| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858 |
- 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.Web;
- 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;
- /// <summary>
- /// 是否保存锁付曲线图
- /// </summary>
- 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<RobotInfo> _RobotList;
- public ObservableCollection<RobotInfo> RobotList
- {
- get { return _RobotList; }
- set { SetProperty(ref _RobotList, value); }
- }
- private ObservableCollection<ScannerInfo> _ScannerList;
- public ObservableCollection<ScannerInfo> ScannerList
- {
- get { return _ScannerList; }
- set { SetProperty(ref _ScannerList, value); }
- }
- private ObservableCollection<CameraInfo> _CameraList;
- public ObservableCollection<CameraInfo> CameraList
- {
- get { return _CameraList; }
- set { SetProperty(ref _CameraList, value); }
- }
- private ObservableCollection<FeederInfo> _FeederList;
- public ObservableCollection<FeederInfo> FeederList
- {
- get { return _FeederList; }
- set { SetProperty(ref _FeederList, value); }
- }
- private ObservableCollection<PlcInfo> _PlcList;
- public ObservableCollection<PlcInfo> 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;
- /// <summary>
- /// 选中的机器人
- /// </summary>
- 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;
- /// <summary>
- /// 选中的扫码枪
- /// </summary>
- public ScannerInfo SelectScanner
- {
- get { return _SelectScanner; }
- set
- {
- SetProperty(ref _SelectScanner, value);
- }
- }
- private FeederInfo _SelectFeeder;
- /// <summary>
- /// 选中的Feeder
- /// </summary>
- 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<ProductModel> _ProductList;
- public ObservableCollection<ProductModel> ProductList
- {
- get { return _ProductList; }
- set { SetProperty(ref _ProductList, value); }
- }
- private ObservableCollection<string> _ResultsValues = new ObservableCollection<string>();
- public ObservableCollection<string> ResultsValues { get => _ResultsValues; set => _ResultsValues = value; }
- private CameraInfo _SelectCamera;
- /// <summary>
- /// 选中的Camera
- /// </summary>
- 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<LightControllerConfig> _LightControllerList;
- public ObservableCollection<LightControllerConfig> 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;
- /// <summary>
- /// 锁付曲线图保存路径
- /// </summary>
- 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); }
- }
- private ProductWithMes _ProMesInfo = new ProductWithMes();
- public ProductWithMes ProMesInfo
- {
- get { return _ProMesInfo; }
- set { SetProperty(ref _ProMesInfo, value); }
- }
- private ProductModel _SelectProduct;
- public ProductModel SelectProduct
- {
- get { return _SelectProduct; }
- set { SetProperty(ref _SelectProduct, value); }
- }
- // 当前选中的设备信息
- private DeviceInfo _SelectDeviceInfo;
- public DeviceInfo SelectDeviceInfo
- {
- get { return _SelectDeviceInfo; }
- set { SetProperty(ref _SelectDeviceInfo, value); }
- }
- // 设备信息列表
- private ObservableCollection<DeviceInfo> _DeviceInfoList;
- public ObservableCollection<DeviceInfo> DeviceInfoList
- {
- get { return _DeviceInfoList; }
- set { SetProperty(ref _DeviceInfoList, 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<string> _SelectLanguageCommand;
- public DelegateCommand<string> SelectLanguageCommand =>
- _SelectLanguageCommand ?? (_SelectLanguageCommand = new DelegateCommand<string>(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<string> _SaveCommunicateCommand;
- public DelegateCommand<string> SaveCommunicateCommand =>
- _SaveCommunicateCommand ?? (_SaveCommunicateCommand = new DelegateCommand<string>(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));
- private DelegateCommand _GetProWithMesCommand;
- public DelegateCommand GetProWithMesCommand =>
- _GetProWithMesCommand ?? (_GetProWithMesCommand = new DelegateCommand(ExecuteGetProWithMesCommand));
- private DelegateCommand _DeleteProWithMesCommand;
- public DelegateCommand DeleteProWithMesCommand =>
- _DeleteProWithMesCommand ?? (_DeleteProWithMesCommand = new DelegateCommand(ExecuteDeleteProWithMesCommand));
- private DelegateCommand _SaveProWithMesCommand;
- public DelegateCommand SaveProWithMesCommand =>
- _SaveProWithMesCommand ?? (_SaveProWithMesCommand = new DelegateCommand(ExecuteSaveProWithMesCommandAsync));
- private DelegateCommand _CheckStatusCommand;
- public DelegateCommand CheckStatusCommand =>
- _CheckStatusCommand ?? (_CheckStatusCommand = new DelegateCommand(ExecuteCheckStatusCommandCommand));
- private DelegateCommand _AddDeviceInfoCommand;
- public DelegateCommand AddDeviceInfoCommand => _AddDeviceInfoCommand ?? (_AddDeviceInfoCommand = new DelegateCommand(ExecuteAddDeviceInfoCommand));
- private DelegateCommand _RemoveDeviceInfoCommand;
- public DelegateCommand RemoveDeviceInfoCommand => _RemoveDeviceInfoCommand ?? (_RemoveDeviceInfoCommand = new DelegateCommand(ExecuteRemoveDeviceInfoCommand));
-
- #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<Management>();
- LoadedCommand = new DelegateCommand(OnLoad);
- //订阅权限登录事件
- _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
- }
- #region 方法
- #region 扫码枪
- private void ExecuteAddScannerCommand()
- {
- _dialogService.ShowDialog("AddScanner", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<ScannerInfo>("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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<RobotInfo>("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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- #endregion
- #region 相机
- /// <summary>
- /// 保存所有相机
- /// </summary>
- 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<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 移除相机
- /// </summary>
- 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<CameraInfo>(root);
- foreach (var item in CameraList)
- {
- _cameraService.UpdateCameraNumber(item.Id, item.CameraNo);
- }
- //对所有产品也进行移除
- _productService.RemoveCameraFromProduct(cameraToRemove.Id);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 编辑相机
- /// </summary>
- 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>("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;
- case CameraBrand.SSZN:
- softwarename = "SSZN Camera Viewer";
- result = SSZNCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.IKap:
- softwarename = "Ikap Camera Viewer";
- result = IKapCamera.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<CameraInfo>("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<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- /// <summary>
- /// 增加相机
- /// </summary>
- 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>("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;
- case CameraBrand.SSZN:
- softwarename = "SSZN Camera Viewer";
- result = SSZNCamera.CheckSoftwareInstalled();
- break;
- case CameraBrand.IKap:
- softwarename = "IKap Camera Viewer";
- result = IKapCamera.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<CameraInfo>("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<SnackbarMessageNotification>().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<FeederInfo>("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<SnackbarMessageNotification>().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<FeederInfo>(root);
- foreach (var item in FeederList)
- {
- _feederService.UpdateFeederNo(item.Id, item.FeederNo);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().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<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- #endregion
- #region PLC
- /// <summary>
- /// 保存PLC
- /// </summary>
- 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<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 移除PLC
- /// </summary>
- 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<PlcInfo>(root);
- foreach (var item in PlcList)
- {
- _plcService.UpdatePlcNumber(item.Id, item.Index);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 增加PLC
- /// </summary>
- void ExecuteAddPlcCommand()
- {
- _dialogService.ShowDialog("AddPlc", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<PlcInfo>("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<SnackbarMessageNotification>().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<LightControllerConfig>("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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<SnackbarMessageNotification>().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<ScanRs232ConfigModel>(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;
- }
- }
- private void ExecuteCheckStatusCommandCommand()
- {
- _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
- }
- #endregion
- #region 继承
- /// <summary>
- /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <param name="continuationCallback"></param>
- public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
- {
- continuationCallback(true);
- }
- /// <summary>
- /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <exception cref="NotImplementedException"></exception>
- public async void OnNavigatedTo(NavigationContext navigationContext)
- {
- if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- if (RobotList == null)
- {
- RobotList = new ObservableCollection<RobotInfo>();
- var robots = _configService.GetAllRobots();
- foreach (var robot in robots)
- {
- RobotList.Add(robot);
- }
- }
- if (ScannerList == null)
- {
- ScannerList = new ObservableCollection<ScannerInfo>();
- var scanners = _configService.GetAllScanners();
- foreach (var scanner in scanners)
- {
- ScannerList.Add(scanner);
- }
- }
- if (CameraList == null)
- {
- CameraList = new ObservableCollection<CameraInfo>();
- var cameras = _configService.GetAllCameras();
- foreach (var camera in cameras)
- {
- CameraList.Add(camera);
- }
- }
- if (FeederList == null)
- {
- FeederList = new ObservableCollection<FeederInfo>();
- var feeders = _configService.GetAllFeeders();
- foreach (var feeder in feeders)
- {
- FeederList.Add(feeder);
- }
- }
- if (PlcList == null)
- {
- PlcList = new ObservableCollection<PlcInfo>();
- var plcs = _configService.GetAllPlcs();
- foreach (var plc in plcs)
- {
- PlcList.Add(plc);
- }
- }
- // load light controllers
- if (LightControllerList == null)
- {
- LightControllerList = new ObservableCollection<LightControllerConfig>();
- 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 (DeviceInfoList == null || DeviceInfoList.Count == 0)
- {
- // load device info list (支持多设备)
- var devices = _configService.GetAllDeviceInfos();
- DeviceInfoList = new ObservableCollection<DeviceInfo>(devices);
- // 默认选中第一个设备
- if (DeviceInfoList.Count > 0)
- {
- SelectDeviceInfo = DeviceInfoList[0];
- }
- }
- 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;
- }
- try
- {
- ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("加载产品列表时出错", ex);
- }
- }
- /// <summary>
- /// 是否允许导航到此视图模型。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <returns></returns>
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- /// <summary>
- /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
- /// </summary>
- /// <param name="navigationContext"></param>
- 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;
- /// <summary>
- /// 工作模式 =1 拍1打1 =2 拍1打所有
- /// </summary>
- public Int16 WorkMode
- {
- get { return _WorkMode; }
- set { SetProperty(ref _WorkMode, value); }
- }
- private Int16 _PickPointNum = 0;
- /// <summary>
- /// 取料位置 =0 不需要取料 =1 需要取料
- /// </summary>
- public Int16 PickPointNum
- {
- get { return _PickPointNum; }
- set { SetProperty(ref _PickPointNum, value); }
- }
- private Int16 _DowmCameraNum = 0;
- /// <summary>
- /// 下相机拍照次数
- /// </summary>
- public Int16 DowmCameraNum
- {
- get => _DowmCameraNum;
- set => SetProperty(ref _DowmCameraNum, value);
- }
- private Int16 _UpCameraPickNum = 0;
- /// <summary>
- /// 上相机取料拍照次数
- /// </summary>
- public Int16 UpCameraPickNum
- {
- get => _UpCameraPickNum;
- set => SetProperty(ref _UpCameraPickNum, value);
- }
- private Int16 _UpCameraPutNum = 0;
- /// <summary>
- /// 上相机放料拍照次数
- /// </summary>
- public Int16 UpCameraPutNum
- {
- get => _UpCameraPutNum;
- set => SetProperty(ref _UpCameraPutNum, value);
- }
- private Int16 _UPCameracheckNum = 0;
- /// <summary>
- /// 上相机锁附/组装次数
- /// </summary>
- public Int16 UPCameracheckNum
- {
- get => _UPCameracheckNum;
- set => SetProperty(ref _UPCameracheckNum, value);
- }
- private Int16 _FixedCameraPickNum = 0;
- /// <summary>
- /// 取料固定位置拍产品相机数量
- /// </summary>
- public Int16 FixedCameraPickNum
- {
- get => _FixedCameraPickNum;
- set => SetProperty(ref _FixedCameraPickNum, value);
- }
- private Int16 _FixedCameraPutNum = 0;
- /// <summary>
- /// 锁附/组装固定位置拍产品相机数量
- /// </summary>
- public Int16 FixedCameraPutNum
- {
- get => _FixedCameraPutNum;
- set => SetProperty(ref _FixedCameraPutNum, value);
- }
- private Int16 _FixedCameracheckNum = 0;
- /// <summary>
- /// 固定相机检测锁附/组装次数
- /// </summary>
- 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<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- }
- /// <summary>
- /// 选择锁付曲线图保存路径
- /// </summary>
- 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<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 2 });
- }
- }
- /// <summary>
- /// 保存读卡器配置
- /// </summary>
- void ExecuteSaveCardReaderConfigCommand()
- {
- try
- {
- _configService.SaveCardReaderConfig(CardReaderConfig);
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- #endregion
- #region 设备信息
- /// <summary>
- /// 保存设备信息
- /// </summary>
- void ExecuteSaveDeviceInfoCommand()
- {
- try
- {
- if (DeviceInfoList != null && DeviceInfoList.Count > 0)
- {
- // 保存所有设备信息
- _configService.SaveAllDeviceInfos(DeviceInfoList);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 添加新设备
- /// </summary>
- void ExecuteAddDeviceInfoCommand()
- {
- try
- {
- var newDevice = _configService.AddDeviceInfo();
- if (DeviceInfoList == null)
- {
- DeviceInfoList = new ObservableCollection<DeviceInfo>();
- }
- DeviceInfoList.Add(newDevice);
- SelectDeviceInfo = newDevice;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 删除当前选中的设备
- /// </summary>
- void ExecuteRemoveDeviceInfoCommand()
- {
- try
- {
- if (SelectDeviceInfo != null && DeviceInfoList != null && DeviceInfoList.Count > 1)
- {
- var deviceNo = SelectDeviceInfo.DeviceNo;
- if (_configService.RemoveDeviceInfo(deviceNo))
- {
- DeviceInfoList.Remove(SelectDeviceInfo);
- SelectDeviceInfo = DeviceInfoList.FirstOrDefault();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- else
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "至少保留一个设备", Duration = 2 });
- }
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 选择CSV存储路径
- /// </summary>
- 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
- #region 产品与mes绑定
- private async void ExecuteGetProWithMesCommand()
- {
- var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
- if (v == null)
- {
- ProMesInfo.ProductCode = "";
- ProMesInfo.ProductColor = "";
- ProMesInfo.ProductKBSN = "";
- ProMesInfo.ProductLoadMode = 0;
- }
- else
- {
- ProMesInfo.ProductCode = v.ProductCode;
- ProMesInfo.ProductColor = v.ProductColor;
- ProMesInfo.ProductKBSN = v.ProductKBSN;
- ProMesInfo.ProductLoadMode = v.ProductLoadMode;
- }
- }
- private async void ExecuteDeleteProWithMesCommand()
- {
- var v = await _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
- if (v > 0)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "删除成功", Duration = 1 });
- var F = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
- if (F == null)
- {
- ProMesInfo.ProductCode = "";
- ProMesInfo.ProductColor = "";
- ProMesInfo.ProductKBSN = "";
- ProMesInfo.ProductLoadMode = 0;
- }
- }
- }
- private async void ExecuteSaveProWithMesCommandAsync()
- {
- var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
- if (v == null)
- {
- await _systemDatabaseService.InsertProWithMesAsync(ProMesInfo, SelectProduct);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加成功", Duration = 1 });
- }
- else
- {
- var n = await _systemDatabaseService.UpdateProductWithMesAsync(ProMesInfo, SelectProduct);
- if (n > 0)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "更新成功", Duration = 1 });
- }
- }
- }
- #endregion
- }
- }
|