| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998 |
- using ICSharpCode.AvalonEdit.Search;
- using log4net;
- 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 SqlSugar;
- 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.Reflection.Metadata;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- using System.Windows;
- using System.Windows.Controls;
- 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.Feeder;
- using TeamAAS_VP.Models.Lights;
- using TeamAAS_VP.Models.Torque;
- 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;
- ICameraService _cameraService;
- IFeederService _feeder_service;
- IFeederService _feederService;
- IPlcService _plcService;
- IProductService _productService;
- ISystemDatabaseService _systemDatabaseService;
- bool isFirstLoad = true;
- #region 属性
- 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<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 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<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 ObservableCollection<ScrewFeederInfo> _ScrewFeederList;
- /// <summary>
- /// 螺丝供料器列表
- /// </summary>
- public ObservableCollection<ScrewFeederInfo> ScrewFeederList
- {
- get { return _ScrewFeederList; }
- set { SetProperty(ref _ScrewFeederList, value); }
- }
- private ScrewFeederInfo _SelectScrewFeeder;
- public ScrewFeederInfo SelectScrewFeeder
- {
- get { return _SelectScrewFeeder; }
- set { SetProperty(ref _SelectScrewFeeder, 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 ObservableCollection<DeviceInfo> _DeviceInfoList;
- public ObservableCollection<DeviceInfo> DeviceInfoList
- {
- get { return _DeviceInfoList; }
- set { SetProperty(ref _DeviceInfoList, value); }
- }
- // 当前选中的设备信息
- private DeviceInfo _SelectDeviceInfo;
- public DeviceInfo SelectDeviceInfo
- {
- get { return _SelectDeviceInfo; }
- set { SetProperty(ref _SelectDeviceInfo, value); }
- }
- // 兼容旧代码,DeviceInfo 指向当前选中的设备或第一个设备
- public DeviceInfo DeviceInfo
- {
- get { return _SelectDeviceInfo ?? DeviceInfoList?.FirstOrDefault(); }
- set
- {
- if (value != null && DeviceInfoList != null)
- {
- var existing = DeviceInfoList.FirstOrDefault(d => d.DeviceNo == value.DeviceNo);
- if (existing != null)
- {
- var index = DeviceInfoList.IndexOf(existing);
- DeviceInfoList[index] = value;
- }
- }
- RaisePropertyChanged();
- }
- }
- private CTQ_Data _dataInfo;
- public CTQ_Data DataInfo
- {
- get { return _dataInfo; }
- set { SetProperty(ref _dataInfo, value); }
- }
- private SerialPortConfig _CardReaderConfig;
- public SerialPortConfig CardReaderConfig
- {
- get { return _CardReaderConfig; }
- set { SetProperty(ref _CardReaderConfig, value); }
- }
- private TorqueSerialPortConfig _TorqueReadConfig;
- public TorqueSerialPortConfig TorqueReadConfig
- {
- get { return _TorqueReadConfig; }
- set { SetProperty(ref _TorqueReadConfig, value); }
- }
- private WorkShift _WorkShift;
- public WorkShift WorkShifts
- {
- get { return _WorkShift; }
- set { SetProperty(ref _WorkShift, value); }
- }
- private ObservableCollection<ProductModel> _ProductList;
- public ObservableCollection<ProductModel> ProductList
- {
- get { return _ProductList; }
- set { SetProperty(ref _ProductList, 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); }
- }
- #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 _RemoveCommand;
- public DelegateCommand RemoveCommand =>
- _RemoveCommand ?? (_RemoveCommand = new DelegateCommand(ExecuteRemoveCommand));
- 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 _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 _SaveDeviceInfoCommand;
- public DelegateCommand SaveDeviceInfoCommand => _SaveDeviceInfoCommand ?? (_SaveDeviceInfoCommand = new DelegateCommand(ExecuteSaveDeviceInfoCommand));
- private DelegateCommand _AddDeviceInfoCommand;
- public DelegateCommand AddDeviceInfoCommand => _AddDeviceInfoCommand ?? (_AddDeviceInfoCommand = new DelegateCommand(ExecuteAddDeviceInfoCommand));
- private DelegateCommand _RemoveDeviceInfoCommand;
- public DelegateCommand RemoveDeviceInfoCommand => _RemoveDeviceInfoCommand ?? (_RemoveDeviceInfoCommand = new DelegateCommand(ExecuteRemoveDeviceInfoCommand));
- private DelegateCommand _BrowseScrewCurvePathCommand;
- public DelegateCommand BrowseScrewCurvePathCommand => _BrowseScrewCurvePathCommand ?? (_BrowseScrewCurvePathCommand = new DelegateCommand(ExecuteBrowseScrewCurvePathCommand));
- private DelegateCommand _AddScrewFeederCommand;
- public DelegateCommand AddScrewFeederCommand =>
- _AddScrewFeederCommand ?? (_AddScrewFeederCommand = new DelegateCommand(ExecuteAddScrewFeederCommand));
- private DelegateCommand _RemoveScrewFeederCommand;
- public DelegateCommand RemoveScrewFeederCommand =>
- _RemoveScrewFeederCommand ?? (_RemoveScrewFeederCommand = new DelegateCommand(ExecuteRemoveScrewFeederCommand));
- private DelegateCommand _SaveScrewFeedersCommand;
- public DelegateCommand SaveScrewFeedersCommand =>
- _SaveScrewFeedersCommand ?? (_SaveScrewFeedersCommand = new DelegateCommand(ExecuteSaveScrewFeedersCommand));
- private DelegateCommand<object> _LightModelChangedCommand;
- public DelegateCommand<object> LightModelChangedCommand =>
- _LightModelChangedCommand ?? (_LightModelChangedCommand = new DelegateCommand<object>(ExecuteLightModelChangedCommand));
- private DelegateCommand _SaveCardReaderConfigCommand;
- public DelegateCommand SaveCardReaderConfigCommand =>
- _SaveCardReaderConfigCommand ?? (_SaveCardReaderConfigCommand = new DelegateCommand(ExecuteSaveCardReaderConfigCommand));
- private DelegateCommand _SaveTorqueReaderConfigCommand;
- public DelegateCommand SaveTorqueReaderConfigCommand =>
- _SaveTorqueReaderConfigCommand ?? (_SaveTorqueReaderConfigCommand = new DelegateCommand(ExecuteSaveTorqueReaderConfigCommand));
- private DelegateCommand _SaveWorkShiftCommand;
- public DelegateCommand SaveWorkShiftCommand =>
- _SaveWorkShiftCommand ?? (_SaveWorkShiftCommand = new DelegateCommand(ExecuteSaveWorkShiftCommand));
- private DelegateCommand _SelectSaveImagePathCommand;
- public DelegateCommand SelectSaveImagePathCommand =>
- _SelectSaveImagePathCommand ?? (_SelectSaveImagePathCommand = new DelegateCommand(ExecuteSelectSaveImagePathCommand));
- 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));
- #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)
- {
- _regionManager = regionManager;
- _eventAggregator = ea;
- _container = container;
- _dialogService = dialogService;
- _configService = configService;
- _robotService = robotService;
- _cameraService = cameraService;
- _feederService = feederService;
- _plcService = plcService;
- _productService = productService;
- _systemDatabaseService = systemDatabaseService;
- management = _container.Resolve<Management>();
- LoadedCommand = new DelegateCommand(OnLoad);
- //订阅权限登录事件
- _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
- }
- #region 方法
- #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)
- {
- var robot = _robotService.GetRobot(item.Id);
- if (robot != null)
- {
- //更新连接参数
- robot.SafeZ = item.SafeZ;
- }
- _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;
- 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;
- 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 = Lang.添加完成, Duration = 1 });
- }
- });
- }
- void ExecuteRemoveLightControllerCommand()
- {
- if (SelectLightController == null) return;
- if (MessageBox.Show(Lang.是否移除光源控制器, "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- _configService.RemoveLightController(SelectLightController.Id);
- LightControllerList.Remove(SelectLightController);
- SelectLightController = null;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
- }
- }
- async void ExecuteSaveLightControllersCommand()
- {
- var view = new ShowMessage($"AAS", Lang.是否保存光源控制器配置);
- 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 = Lang.完成, Duration = 1 });
- }
- }
- /// <summary>
- /// 光源型号改变
- /// </summary>
- void ExecuteLightModelChangedCommand(object obj)
- {
- try
- {
- if (obj == null)
- {
- return;
- }
- if (obj is LightControllerConfig lc)
- {
- lc.Init();
- }
- }
- catch (Exception)
- {
- }
- }
- #endregion
- #region 螺丝供料器
- /// <summary>
- /// 保存所有螺丝供料器
- /// </summary>
- async void ExecuteSaveScrewFeedersCommand()
- {
- var view = new ShowMessage($"AAS", Lang.是否保存螺丝供料器);
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool && (bool)result)
- {
- if (ScrewFeederList != null)
- {
- foreach (var item in ScrewFeederList)
- {
- try
- {
- _configService.AddOrUpdateScrewFeeder(item);
- }
- catch (Exception ex)
- {
- // 记录或通知错误,但继续处理其它项
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- }
- /// <summary>
- /// 移除螺丝供料器
- /// </summary>
- void ExecuteRemoveScrewFeederCommand()
- {
- if (SelectScrewFeeder == null) return;
- if (MessageBox.Show(Lang.是否移除螺丝供料器, "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- try
- {
- var toRemove = ScrewFeederList?.FirstOrDefault(s => s.Id == SelectScrewFeeder.Id);
- if (toRemove != null)
- {
- _configService.RemoveScrewFeeder(toRemove.Id);
- // 重新加载列表以保持序号/配置一致(与其他类似实现一致)
- var root = _configService.GetAllScrewFeeders();
- ScrewFeederList = new ObservableCollection<ScrewFeederInfo>(root);
- _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 ExecuteAddScrewFeederCommand()
- {
- _dialogService.ShowDialog("AddScrewFeeder", rst =>
- {
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<ScrewFeederInfo>("ScrewFeeder");
- if (param != null)
- {
- if (ScrewFeederList == null)
- {
- ScrewFeederList = new ObservableCollection<ScrewFeederInfo>();
- }
- try
- {
- param = _configService.AddOrUpdateScrewFeeder(param);
- // 直接添加对话框返回的对象(也可以根据需要映射字段)
- ScrewFeederList.Add(param);
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, 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;
- _configService.SetCurrentLanguage(CurrentLanguage);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- else if (string.Equals(language, "ChineseTraditional"))
- {
- CurrentLanguage = Enums.Language.ChineseTraditional;
- _configService.SetCurrentLanguage(CurrentLanguage);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- else if (string.Equals(language, "English"))
- {
- CurrentLanguage = Enums.Language.English;
- _configService.SetCurrentLanguage(CurrentLanguage);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- else if (string.Equals(language, "Japanese"))
- {
- CurrentLanguage = Enums.Language.Japanese;
- _configService.SetCurrentLanguage(CurrentLanguage);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- else if (string.Equals(language, "Vietnamese"))
- {
- CurrentLanguage = Enums.Language.Vietnamese;
- _configService.SetCurrentLanguage(CurrentLanguage);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
- }
- }
- #endregion
- #region 生产排班
- private void ExecuteSaveWorkShiftCommand()
- {
- try
- {
- FileHelper.WriteJsonFile(WorkShifts, FilePath.WorkShiftParamPath);
- _eventAggregator.GetEvent<WorkShiftUpdateNotification>().Publish(WorkShifts);
- }
- catch (Exception)
- { }
- }
- #endregion
- private void OnLoad()
- {
- try
- {
- this.WorkShifts = FileHelper.ReadJsonFile<WorkShift>(FilePath.WorkShiftParamPath);
- }
- catch (Exception)
- {
- }
- }
- private void ExecuteCheckStatusCommandCommand()
- {
- _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
- }
- 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 继承
- /// <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 (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 (ScrewFeederList == null)
- {
- var screwFeeders = _configService.GetAllScrewFeeders();
- ScrewFeederList = new ObservableCollection<ScrewFeederInfo>(screwFeeders);
- }
- if (CardReaderConfig == null)
- {
- // load card reader config
- CardReaderConfig = _configService.GetCardReaderConfig();
- }
- if (TorqueReadConfig == null)
- {
- TorqueReadConfig = _configService.GetTorqueReaderConfig();
- }
- 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;
- ScrewTeachNum = sys.ScrewTeachNum;
- IsSaveScrewCurve = sys.IsSaveScrewCurve;
- ScrewCurvePath = sys.ScrewCurvePath;
- IsBasePartCodeGetSN = sys.IsBasePartCodeGetSN;
- IsBasePartCodeChooseScrew = sys.IsBasePartCodeChooseScrew;
- ChooseScrewModel = sys.ChooseScrewModel;
- }
- 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 bool _IsBasePartCodeGetSN;
- /// <summary>
- /// 是否基于零件码获取流程码
- /// </summary>
- public bool IsBasePartCodeGetSN
- {
- get { return _IsBasePartCodeGetSN; }
- set { SetProperty(ref _IsBasePartCodeGetSN, value); }
- }
- private bool _IsBasePartCodeChooseScrew;
- /// <summary>
- /// 是否通过零件码判断螺丝型号
- /// </summary>
- public bool IsBasePartCodeChooseScrew
- {
- get { return _IsBasePartCodeChooseScrew; }
- set { SetProperty(ref _IsBasePartCodeChooseScrew, value); }
- }
- private string _ChooseScrewModel;
- /// <summary>
- /// 螺丝型号判断,如******123**,*为忽略字符
- /// </summary>
- public string ChooseScrewModel
- {
- get { return _ChooseScrewModel; }
- set { SetProperty(ref _ChooseScrewModel, value); }
- }
- 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);
- }
- private Int16 _ScrewTeachNum = 0;
- /// <summary>
- /// 披头矫正的模式,1:初始化时矫正,2:每个产品矫正一次,3:每颗螺丝矫正一次
- /// </summary>
- public Int16 ScrewTeachNum
- {
- get => _ScrewTeachNum;
- set => SetProperty(ref _ScrewTeachNum, value);
- }
- private bool _IsSaveScrewCurve;
- /// <summary>
- /// 是否保存锁付曲线图
- /// </summary>
- public bool IsSaveScrewCurve
- {
- get { return _IsSaveScrewCurve; }
- set { SetProperty(ref _IsSaveScrewCurve, value); }
- }
- private string _ScrewCurvePath;
- /// <summary>
- /// 锁付曲线图保存路径
- /// </summary>
- public string ScrewCurvePath
- {
- get { return _ScrewCurvePath; }
- set { SetProperty(ref _ScrewCurvePath, value); }
- }
- /// <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>
- async void ExecuteSaveSystemParametersCommand()
- {
- var view = new ShowMessage($"AAS", Lang.是否保存系统参数);
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool && (bool)result)
- {
- try
- {
- 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.ScrewTeachNum = ScrewTeachNum;
- sysConfig.IsSaveScrewCurve = IsSaveScrewCurve;
- sysConfig.ScrewCurvePath = ScrewCurvePath;
- sysConfig.IsBasePartCodeGetSN = IsBasePartCodeGetSN;
- sysConfig.IsBasePartCodeChooseScrew = IsBasePartCodeChooseScrew;
- sysConfig.ChooseScrewModel = ChooseScrewModel;
- _configService.SaveSystemConfiguration(sysConfig);
- await management.WriteSystemParameterToPlcAsync(sysConfig);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
- }
- }
- }
- /// <summary>
- /// 保存读卡器配置
- /// </summary>
- void ExecuteSaveCardReaderConfigCommand()
- {
- try
- {
- _configService.SaveCardReaderConfig(CardReaderConfig);
- }
- catch (Exception ex)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- void ExecuteSaveTorqueReaderConfigCommand()
- {
- try
- {
- _configService.SaveTorqueReaderConfig(TorqueReadConfig);
- }
- 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 (SelectDeviceInfo == 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)
- {
- SelectDeviceInfo.SaveCsvPath = dialog.SelectedPath;
- }
- }
- }
- #endregion
- #region 产品与mes绑定
- private async void ExecuteGetProWithMesCommand()
- {
- var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
- if (v == null)
- {
- ProMesInfo.ProductCode = "";
- ProMesInfo.ProductColor = "";
- ProMesInfo.ProductLoadMode = 0;
- }
- else
- {
- ProMesInfo.ProductCode = v.ProductCode;
- ProMesInfo.ProductColor = v.ProductColor;
- 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.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
- private DelegateCommand _testCommand;
- public DelegateCommand testCommand =>
- _testCommand ?? (_testCommand = new DelegateCommand(Execute_testCommand));
-
- private async void Execute_testCommand()
- {
- }
- }
- }
|