SettingViewModel.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. using ICSharpCode.AvalonEdit.Search;
  2. using MaterialDesignThemes.Wpf;
  3. using NPOI.SS.Formula.Functions;
  4. using Opc.Ua;
  5. using Prism.Commands;
  6. using Prism.Events;
  7. using Prism.Ioc;
  8. using Prism.Mvvm;
  9. using Prism.Regions;
  10. using Prism.Services.Dialogs;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Collections.ObjectModel;
  14. using System.ComponentModel;
  15. using System.Globalization;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Windows;
  19. using Team.FFFeederService.Interfaces;
  20. using TeamAAS_VP.Controls;
  21. using TeamAAS_VP.Core;
  22. using TeamAAS_VP.Core.Cameras;
  23. using TeamAAS_VP.Core.Lights;
  24. using TeamAAS_VP.Enums;
  25. using TeamAAS_VP.Events;
  26. using TeamAAS_VP.Interfaces;
  27. using TeamAAS_VP.Models;
  28. using TeamAAS_VP.Models.Lights;
  29. using TeamAAS_VP.Resources.Languages;
  30. using TeamAAS_VP.Services;
  31. using TeamAAS_VP.ViewModels.User;
  32. using TouchSocket.Core;
  33. using WPFLocalizeExtension.Engine;
  34. namespace TeamAAS_VP.ViewModels
  35. {
  36. public class SettingViewModel : BindableBase, IConfirmNavigationRequest
  37. {
  38. IRegionManager _regionManager;
  39. IEventAggregator _eventAggregator;
  40. IContainerProvider _container;
  41. IDialogService _dialogService;
  42. IConfigService _configService;
  43. IRobotService _robotService;
  44. ICameraService _cameraService;
  45. IFeederService _feeder_service;
  46. IFeederService _feederService;
  47. IPlcService _plcService;
  48. IProductService _productService;
  49. ISystemDatabaseService _systemDatabaseService;
  50. bool isFirstLoad = true;
  51. #region 属性
  52. private Management _management;
  53. public Management management
  54. {
  55. get { return _management; }
  56. set { SetProperty(ref _management, value); }
  57. }
  58. private ObservableCollection<RobotInfo> _RobotList;
  59. public ObservableCollection<RobotInfo> RobotList
  60. {
  61. get { return _RobotList; }
  62. set { SetProperty(ref _RobotList, value); }
  63. }
  64. private ObservableCollection<CameraInfo> _CameraList;
  65. public ObservableCollection<CameraInfo> CameraList
  66. {
  67. get { return _CameraList; }
  68. set { SetProperty(ref _CameraList, value); }
  69. }
  70. private ObservableCollection<FeederInfo> _FeederList;
  71. public ObservableCollection<FeederInfo> FeederList
  72. {
  73. get { return _FeederList; }
  74. set { SetProperty(ref _FeederList, value); }
  75. }
  76. private ObservableCollection<PlcInfo> _PlcList;
  77. public ObservableCollection<PlcInfo> PlcList
  78. {
  79. get { return _PlcList; }
  80. set { SetProperty(ref _PlcList, value); }
  81. }
  82. private Language _CurrentLanguage;
  83. public Language CurrentLanguage
  84. {
  85. get { return _CurrentLanguage; }
  86. set { SetProperty(ref _CurrentLanguage, value); }
  87. }
  88. private RobotInfo _SelectRobot;
  89. /// <summary>
  90. /// 选中的机器人
  91. /// </summary>
  92. public RobotInfo SelectRobot
  93. {
  94. get { return _SelectRobot; }
  95. set
  96. {
  97. SetProperty(ref _SelectRobot, value);
  98. if (value != null && (value.RobotBrand == RobotBrand.XYZ_Platform || value.RobotBrand == RobotBrand.XYZU_Platform))
  99. {
  100. RobotSelectedPlc = PlcList.FirstOrDefault(p => p.Id == value.PLC);
  101. var root = _robotService.GetRobot(SelectRobot.Id);
  102. if (root != null)
  103. {
  104. //ResultsValues.Clear();
  105. //var res = root.GetNodesValue();
  106. //for (int i = 0; i < res.Count; i++)
  107. //{
  108. // if (res[i].StatusCode.Code != 2150891520)
  109. // {
  110. // ResultsValues.Add(res[i].Value.ToString());
  111. // }
  112. // else
  113. // {
  114. // break;
  115. // }
  116. //}
  117. }
  118. }
  119. }
  120. }
  121. private FeederInfo _SelectFeeder;
  122. /// <summary>
  123. /// 选中的Feeder
  124. /// </summary>
  125. public FeederInfo SelectFeeder
  126. {
  127. get { return _SelectFeeder; }
  128. set { SetProperty(ref _SelectFeeder, value); }
  129. }
  130. private PlcInfo _SelectPlc;
  131. public PlcInfo SelectPlc
  132. {
  133. get { return _SelectPlc; }
  134. set { SetProperty(ref _SelectPlc, value); }
  135. }
  136. private ObservableCollection<string> _ResultsValues = new ObservableCollection<string>();
  137. public ObservableCollection<string> ResultsValues { get => _ResultsValues; set => _ResultsValues = value; }
  138. private CameraInfo _SelectCamera;
  139. /// <summary>
  140. /// 选中的Camera
  141. /// </summary>
  142. public CameraInfo SelectCamera
  143. {
  144. get { return _SelectCamera; }
  145. set { SetProperty(ref _SelectCamera, value); }
  146. }
  147. private double _Title1;
  148. public double Title1
  149. {
  150. get { return _Title1; }
  151. set { SetProperty(ref _Title1, value); }
  152. }
  153. private double _Title2;
  154. public double Title2
  155. {
  156. get { return _Title2; }
  157. set { SetProperty(ref _Title2, value); }
  158. }
  159. private double _Title3;
  160. public double Title3
  161. {
  162. get { return _Title3; }
  163. set { SetProperty(ref _Title3, value); }
  164. }
  165. private double _Title4;
  166. public double Title4
  167. {
  168. get { return _Title4; }
  169. set { SetProperty(ref _Title4, value); }
  170. }
  171. private double _Body1;
  172. public double Body1
  173. {
  174. get { return _Body1; }
  175. set { SetProperty(ref _Body1, value); }
  176. }
  177. private double _Body2;
  178. public double Body2
  179. {
  180. get { return _Body2; }
  181. set { SetProperty(ref _Body2, value); }
  182. }
  183. private double _Body3;
  184. public double Body3
  185. {
  186. get { return _Body3; }
  187. set { SetProperty(ref _Body3, value); }
  188. }
  189. private double _Body4;
  190. public double Body4
  191. {
  192. get { return _Body4; }
  193. set { SetProperty(ref _Body4, value); }
  194. }
  195. private double _Captions1;
  196. public double Captions1
  197. {
  198. get { return _Captions1; }
  199. set { SetProperty(ref _Captions1, value); }
  200. }
  201. private double _Captions2;
  202. public double Captions2
  203. {
  204. get { return _Captions2; }
  205. set { SetProperty(ref _Captions2, value); }
  206. }
  207. private double _Captions3;
  208. public double Captions3
  209. {
  210. get { return _Captions3; }
  211. set { SetProperty(ref _Captions3, value); }
  212. }
  213. private double _Captions4;
  214. public double Captions4
  215. {
  216. get { return _Captions4; }
  217. set { SetProperty(ref _Captions4, value); }
  218. }
  219. private PlcInfo _RobotSelectedPlc;
  220. public PlcInfo RobotSelectedPlc
  221. {
  222. get { return _RobotSelectedPlc; }
  223. set
  224. {
  225. SetProperty(ref _RobotSelectedPlc, value);
  226. if (SelectRobot != null)
  227. {
  228. if (value != null)
  229. {
  230. SelectRobot.PLC = value.Id;
  231. }
  232. else
  233. {
  234. SelectRobot.PLC = Guid.Empty;
  235. }
  236. }
  237. }
  238. }
  239. private BgModbusTcp _BgModbus;
  240. public BgModbusTcp BgModbus
  241. {
  242. get { return _BgModbus; }
  243. set { SetProperty(ref _BgModbus, value); }
  244. }
  245. private BgTcpIP _BgTcp;
  246. public BgTcpIP BgTcp
  247. {
  248. get { return _BgTcp; }
  249. set { SetProperty(ref _BgTcp, value); }
  250. }
  251. private ObservableCollection<LightControllerConfig> _LightControllerList;
  252. public ObservableCollection<LightControllerConfig> LightControllerList
  253. {
  254. get { return _LightControllerList; }
  255. set { SetProperty(ref _LightControllerList, value); }
  256. }
  257. private LightControllerConfig _SelectLightController;
  258. public LightControllerConfig SelectLightController
  259. {
  260. get { return _SelectLightController; }
  261. set { SetProperty(ref _SelectLightController, value); }
  262. }
  263. #endregion
  264. #region 命令
  265. public DelegateCommand LoadedCommand { get; set; }
  266. private DelegateCommand _SaveSystemParametersCommand;
  267. public DelegateCommand SaveSystemParametersCommand =>
  268. _SaveSystemParametersCommand ?? (_SaveSystemParametersCommand = new DelegateCommand(ExecuteSaveSystemParametersCommand));
  269. private DelegateCommand _AddRobotCommand;
  270. public DelegateCommand AddRobotCommand =>
  271. _AddRobotCommand ?? (_AddRobotCommand = new DelegateCommand(ExecuteAddRobotCommand));
  272. private DelegateCommand _RemoveCommand;
  273. public DelegateCommand RemoveCommand =>
  274. _RemoveCommand ?? (_RemoveCommand = new DelegateCommand(ExecuteRemoveCommand));
  275. private DelegateCommand _AddFeederCommand;
  276. public DelegateCommand AddFeederCommand =>
  277. _AddFeederCommand ?? (_AddFeederCommand = new DelegateCommand(ExecuteAddFeederCommand));
  278. private DelegateCommand _RemoveFeederCommand;
  279. public DelegateCommand RemoveFeederCommand =>
  280. _RemoveFeederCommand ?? (_RemoveFeederCommand = new DelegateCommand(ExecuteRemoveFeederCommand));
  281. private DelegateCommand<string> _SelectLanguageCommand;
  282. public DelegateCommand<string> SelectLanguageCommand =>
  283. _SelectLanguageCommand ?? (_SelectLanguageCommand = new DelegateCommand<string>(ExecuteSelectLanguageCommand));
  284. private DelegateCommand _SaveRobotsCommand;
  285. public DelegateCommand SaveRobotsCommand =>
  286. _SaveRobotsCommand ?? (_SaveRobotsCommand = new DelegateCommand(ExecuteSaveRobotsCommand));
  287. private DelegateCommand _SaveFeedersCommand;
  288. public DelegateCommand SaveFeedersCommand =>
  289. _SaveFeedersCommand ?? (_SaveFeedersCommand = new DelegateCommand(ExecuteSaveFeedersCommand));
  290. private DelegateCommand<string> _SaveCommunicateCommand;
  291. public DelegateCommand<string> SaveCommunicateCommand =>
  292. _SaveCommunicateCommand ?? (_SaveCommunicateCommand = new DelegateCommand<string>(ExecuteSaveCommunicateCommand));
  293. private DelegateCommand _AddCameraCommand;
  294. public DelegateCommand AddCameraCommand =>
  295. _AddCameraCommand ?? (_AddCameraCommand = new DelegateCommand(ExecuteAddCameraCommand));
  296. private DelegateCommand _EditCameraCommand;
  297. public DelegateCommand EditCameraCommand =>
  298. _EditCameraCommand ?? (_EditCameraCommand = new DelegateCommand(ExecuteEditCameraCommand));
  299. private DelegateCommand _RemoveCameraCommand;
  300. public DelegateCommand RemoveCameraCommand =>
  301. _RemoveCameraCommand ?? (_RemoveCameraCommand = new DelegateCommand(ExecuteRemoveCameraCommand));
  302. private DelegateCommand _SaveCamerasCommand;
  303. public DelegateCommand SaveCamerasCommand =>
  304. _SaveCamerasCommand ?? (_SaveCamerasCommand = new DelegateCommand(ExecuteSaveCamerasCommand));
  305. private DelegateCommand _AddPlcCommand;
  306. public DelegateCommand AddPlcCommand =>
  307. _AddPlcCommand ?? (_AddPlcCommand = new DelegateCommand(ExecuteAddPlcCommand));
  308. private DelegateCommand _RemovePlcCommand;
  309. public DelegateCommand RemovePlcCommand =>
  310. _RemovePlcCommand ?? (_RemovePlcCommand = new DelegateCommand(ExecuteRemovePlcCommand));
  311. private DelegateCommand _SavePlcsCommand;
  312. public DelegateCommand SavePlcsCommand =>
  313. _SavePlcsCommand ?? (_SavePlcsCommand = new DelegateCommand(ExecuteSavePlcsCommand));
  314. private DelegateCommand _AddLightControllerCommand;
  315. public DelegateCommand AddLightControllerCommand => _AddLightControllerCommand ?? (_AddLightControllerCommand = new DelegateCommand(ExecuteAddLightControllerCommand));
  316. private DelegateCommand _RemoveLightControllerCommand;
  317. public DelegateCommand RemoveLightControllerCommand => _RemoveLightControllerCommand ?? (_RemoveLightControllerCommand = new DelegateCommand(ExecuteRemoveLightControllerCommand));
  318. private DelegateCommand _SaveLightControllersCommand;
  319. public DelegateCommand SaveLightControllersCommand => _SaveLightControllersCommand ?? (_SaveLightControllersCommand = new DelegateCommand(ExecuteSaveLightControllersCommand));
  320. #endregion
  321. #region 事件
  322. #endregion
  323. public SettingViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  324. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService,
  325. IProductService productService, ISystemDatabaseService systemDatabaseService)
  326. {
  327. _regionManager = regionManager;
  328. _eventAggregator = ea;
  329. _container = container;
  330. _dialogService = dialogService;
  331. _configService = configService;
  332. _robotService = robotService;
  333. _cameraService = cameraService;
  334. _feederService = feederService;
  335. _plcService = plcService;
  336. _productService = productService;
  337. _systemDatabaseService = systemDatabaseService;
  338. management = _container.Resolve<Management>();
  339. LoadedCommand = new DelegateCommand(OnLoad);
  340. //订阅权限登录事件
  341. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  342. }
  343. #region 方法
  344. #region 机器人
  345. private void ExecuteAddRobotCommand()
  346. {
  347. _dialogService.ShowDialog("AddRobot", rst =>
  348. {
  349. //对话框关闭之后的回调函数,可以在这解析结果。
  350. ButtonResult result1 = rst.Result;
  351. if (result1 == ButtonResult.OK)
  352. {
  353. var param = rst.Parameters.GetValue<RobotInfo>("Robot");
  354. var robot = new RobotInfo()
  355. {
  356. Id = param.Id,
  357. RobotName = param.RobotName,
  358. ConnectType = param.ConnectType,
  359. RobotBrand = param.RobotBrand,
  360. IP = param.IP,
  361. Port = param.Port,
  362. Terminator = param.Terminator,
  363. };
  364. RobotList.Add(robot);
  365. _configService.AddOrUpdateRobot(robot);
  366. _robotService.CreateRobot(robot.Id, robot);
  367. //对所有产品也进行添加
  368. _productService.AddRobotPointToProduct(robot.Id, robot.RobotName);
  369. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
  370. }
  371. });
  372. }
  373. void ExecuteRemoveCommand()
  374. {
  375. if (MessageBox.Show(Lang.是否移除机器人, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  376. {
  377. // 找到要删除的机器人
  378. var robotToRemove = RobotList.FirstOrDefault(r => r.Id == SelectRobot.Id);
  379. if (robotToRemove != null)
  380. {
  381. RobotList.Remove(robotToRemove);
  382. _configService.RemoveRobot(robotToRemove.Id);
  383. _robotService.RemoveRobot(robotToRemove.Id);
  384. //对所有产品也进行移除
  385. _productService.RemoveRobotPointFromProduct(robotToRemove.Id);
  386. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  387. }
  388. }
  389. }
  390. async void ExecuteSaveRobotsCommand()
  391. {
  392. var view = new ShowMessage($"AAS", Lang.是否保存机器人);
  393. //show the dialog
  394. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  395. if (result != null && result is bool)
  396. {
  397. if (((bool)result))
  398. {
  399. foreach (var item in RobotList)
  400. {
  401. _configService.AddOrUpdateRobot(item);
  402. }
  403. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  404. }
  405. }
  406. }
  407. #endregion
  408. #region 相机
  409. /// <summary>
  410. /// 保存所有相机
  411. /// </summary>
  412. async void ExecuteSaveCamerasCommand()
  413. {
  414. var view = new ShowMessage($"AAS", Lang.是否保存相机配置);
  415. //show the dialog
  416. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  417. if (result != null && result is bool)
  418. {
  419. if (((bool)result))
  420. {
  421. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  422. //management.SaveCamerasDeviceConfig();
  423. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  424. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  425. }
  426. }
  427. }
  428. /// <summary>
  429. /// 移除相机
  430. /// </summary>
  431. void ExecuteRemoveCameraCommand()
  432. {
  433. if (MessageBox.Show(Lang.是否移除相机, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  434. {
  435. // 找到要删除的相机
  436. var cameraToRemove = CameraList.FirstOrDefault(r => r.Id == SelectCamera.Id);
  437. if (cameraToRemove != null)
  438. {
  439. _configService.RemoveCamera(cameraToRemove.Id);
  440. _cameraService.RemoveCamera(cameraToRemove.Id);
  441. var root = _configService.GetAllCameras();
  442. CameraList = new ObservableCollection<CameraInfo>(root);
  443. foreach (var item in CameraList)
  444. {
  445. _cameraService.UpdateCameraNumber(item.Id, item.CameraNo);
  446. }
  447. //对所有产品也进行移除
  448. _productService.RemoveCameraFromProduct(cameraToRemove.Id);
  449. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  450. }
  451. }
  452. }
  453. /// <summary>
  454. /// 编辑相机
  455. /// </summary>
  456. void ExecuteEditCameraCommand()
  457. {
  458. if (SelectCamera == null) return;
  459. bool isSelectedCameraBrandSucced = false;
  460. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  461. IDialogParameters parameters1 = new DialogParameters();
  462. parameters1.Add("CameraBrand", SelectCamera.CameraBrand);
  463. _dialogService.ShowDialog("SelectCameraBrand", parameters1, rst =>
  464. {
  465. if (rst.Result == ButtonResult.OK)
  466. {
  467. isSelectedCameraBrandSucced = true;
  468. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  469. }
  470. else
  471. {
  472. return;
  473. }
  474. });
  475. if (!isSelectedCameraBrandSucced) { return; }
  476. (bool isInstalled, string version) result = (false, "");
  477. string softwarename = "";
  478. switch (cameraBrand)
  479. {
  480. case CameraBrand.HikRobot_MVS:
  481. softwarename = "MVS";
  482. result = MvCamera.CheckSoftwareInstalled();
  483. break;
  484. case CameraBrand.Basler_Pylon:
  485. softwarename = "Pylon 7";
  486. result = BaslerCamera.CheckSoftwareInstalled();
  487. break;
  488. case CameraBrand.IRayple:
  489. softwarename = "MV Viewer";
  490. result = AHuaCamera.CheckSoftwareInstalled();
  491. break;
  492. case CameraBrand.Cognex:
  493. softwarename = "Cognex VisionPro";
  494. result = CognexCamera.CheckSoftwareInstalled();
  495. break;
  496. case CameraBrand.Galaxy:
  497. softwarename = "Galaxy Viewer";
  498. result = GalaxyCamera.CheckSoftwareInstalled();
  499. break;
  500. default:
  501. break;
  502. }
  503. if (!result.isInstalled)
  504. {
  505. if (string.IsNullOrEmpty(result.version))
  506. {
  507. //未安装
  508. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  509. }
  510. else
  511. {
  512. //版本较低
  513. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  514. }
  515. return;
  516. }
  517. //编辑前的相机名称
  518. string oldCameraName = SelectCamera.CameraName;
  519. IDialogParameters parameters = new DialogParameters();
  520. parameters.Add("CameraBrand", cameraBrand);
  521. parameters.Add("Camera", SelectCamera.Copy());
  522. _dialogService.ShowDialog("EditCamera", parameters, rst =>
  523. {
  524. //对话框关闭之后的回调函数,可以在这解析结果。
  525. ButtonResult result1 = rst.Result;
  526. if (result1 == ButtonResult.OK)
  527. {
  528. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  529. SelectCamera.CameraName = param.CameraName;
  530. SelectCamera.SerialNumber = param.SerialNumber;
  531. SelectCamera.Model = param.Model;
  532. SelectCamera.ManufacturerName = param.ManufacturerName;
  533. SelectCamera.CameraType = param.CameraType;
  534. SelectCamera.CameraBrand = param.CameraBrand;
  535. SelectCamera.CameraIp = param.CameraIp;
  536. _configService.AddOrUpdateCamera(SelectCamera);
  537. if (oldCameraName != param.CameraName)
  538. {
  539. //对所有产品也进行修改
  540. _productService.UpdateCameraNameInProduct(SelectCamera.Id, SelectCamera.CameraName);
  541. }
  542. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  543. }
  544. });
  545. }
  546. /// <summary>
  547. /// 增加相机
  548. /// </summary>
  549. void ExecuteAddCameraCommand()
  550. {
  551. bool isSelectedCameraBrandSucced = false;
  552. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  553. _dialogService.ShowDialog("SelectCameraBrand", rst =>
  554. {
  555. if (rst.Result == ButtonResult.OK)
  556. {
  557. isSelectedCameraBrandSucced = true;
  558. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  559. }
  560. else
  561. {
  562. return;
  563. }
  564. });
  565. if (!isSelectedCameraBrandSucced) { return; }
  566. ;
  567. (bool isInstalled, string version) result = (false, "");
  568. string softwarename = "";
  569. switch (cameraBrand)
  570. {
  571. case CameraBrand.HikRobot_MVS:
  572. softwarename = "MVS";
  573. result = MvCamera.CheckSoftwareInstalled();
  574. break;
  575. case CameraBrand.Basler_Pylon:
  576. softwarename = "Pylon 7";
  577. result = BaslerCamera.CheckSoftwareInstalled();
  578. break;
  579. case CameraBrand.IRayple:
  580. softwarename = "MV Viewer";
  581. result = AHuaCamera.CheckSoftwareInstalled();
  582. break;
  583. case CameraBrand.Cognex:
  584. softwarename = "Cognex VisionPro";
  585. result = CognexCamera.CheckSoftwareInstalled();
  586. break;
  587. case CameraBrand.Galaxy:
  588. softwarename = "Galaxy Viewer";
  589. result = GalaxyCamera.CheckSoftwareInstalled();
  590. break;
  591. default:
  592. break;
  593. }
  594. if (!result.isInstalled)
  595. {
  596. if (string.IsNullOrEmpty(result.version))
  597. {
  598. //未安装
  599. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  600. }
  601. else
  602. {
  603. //版本较低
  604. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  605. }
  606. return;
  607. }
  608. IDialogParameters parameters = new DialogParameters();
  609. parameters.Add("CameraBrand", cameraBrand);
  610. _dialogService.ShowDialog("AddCamera", parameters, rst =>
  611. {
  612. //对话框关闭之后的回调函数,可以在这解析结果。
  613. ButtonResult result1 = rst.Result;
  614. if (result1 == ButtonResult.OK)
  615. {
  616. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  617. var camera = new CameraInfo()
  618. {
  619. Id = param.Id,
  620. CameraName = param.CameraName,
  621. SerialNumber = param.SerialNumber,
  622. Model = param.Model,
  623. ManufacturerName = param.ManufacturerName,
  624. CameraType = param.CameraType,
  625. CameraBrand = param.CameraBrand,
  626. CameraIp = param.CameraIp
  627. };
  628. CameraList.Add(camera);
  629. _configService.AddOrUpdateCamera(camera);
  630. _cameraService.CreateCamera(camera.Id, camera);
  631. //对所有产品也进行添加
  632. _productService.AddCameraToProduct(camera.Id, camera.CameraName);
  633. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  634. }
  635. });
  636. }
  637. #endregion
  638. #region Feeder
  639. void ExecuteAddFeederCommand()
  640. {
  641. _dialogService.ShowDialog("AddFeeder", rst =>
  642. {
  643. //对话框关闭之后的回调函数,可以在这解析结果。
  644. ButtonResult result1 = rst.Result;
  645. if (result1 == ButtonResult.OK)
  646. {
  647. var param = rst.Parameters.GetValue<FeederInfo>("Feeder");
  648. var feeder = new FeederInfo()
  649. {
  650. Id = param.Id,
  651. FeederName = param.FeederName,
  652. ConnectType = param.ConnectType,
  653. FeederBrand = param.FeederBrand,
  654. IP = param.IP,
  655. Port = param.Port
  656. };
  657. FeederList.Add(feeder);
  658. _configService.AddOrUpdateFeeder(feeder);
  659. _feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
  660. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  661. }
  662. });
  663. }
  664. void ExecuteRemoveFeederCommand()
  665. {
  666. if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  667. {
  668. // 找到要删除的机器人
  669. var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
  670. if (feederToRemove != null)
  671. {
  672. _configService.RemoveFeeder(feederToRemove.Id);
  673. _feederService.RemoveFeeder(feederToRemove.Id);
  674. var root = _configService.GetAllFeeders();
  675. FeederList = new ObservableCollection<FeederInfo>(root);
  676. foreach (var item in FeederList)
  677. {
  678. _feederService.UpdateFeederNo(item.Id, item.FeederNo);
  679. }
  680. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  681. }
  682. }
  683. }
  684. async void ExecuteSaveFeedersCommand()
  685. {
  686. var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
  687. //show the dialog
  688. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  689. if (result != null && result is bool)
  690. {
  691. if (((bool)result))
  692. {
  693. foreach (var item in FeederList)
  694. {
  695. _configService.AddOrUpdateFeeder(item);
  696. }
  697. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  698. }
  699. }
  700. }
  701. #endregion
  702. #region PLC
  703. /// <summary>
  704. /// 保存PLC
  705. /// </summary>
  706. async void ExecuteSavePlcsCommand()
  707. {
  708. var view = new ShowMessage($"AAS", Lang.是否保存PLC);
  709. //show the dialog
  710. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  711. if (result != null && result is bool)
  712. {
  713. if (((bool)result))
  714. {
  715. foreach (var item in PlcList)
  716. {
  717. _configService.AddOrUpdatePlc(item);
  718. }
  719. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  720. }
  721. }
  722. }
  723. /// <summary>
  724. /// 移除PLC
  725. /// </summary>
  726. void ExecuteRemovePlcCommand()
  727. {
  728. if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  729. {
  730. // 找到要删除的plc
  731. var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
  732. if (plcToRemove != null)
  733. {
  734. _configService.RemovePlc(plcToRemove.Id);
  735. _plcService.RemovePlc(plcToRemove.Id);
  736. var root = _configService.GetAllPlcs();
  737. PlcList = new ObservableCollection<PlcInfo>(root);
  738. foreach (var item in PlcList)
  739. {
  740. _plcService.UpdatePlcNumber(item.Id, item.Index);
  741. }
  742. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  743. }
  744. }
  745. }
  746. /// <summary>
  747. /// 增加PLC
  748. /// </summary>
  749. void ExecuteAddPlcCommand()
  750. {
  751. _dialogService.ShowDialog("AddPlc", rst =>
  752. {
  753. //对话框关闭之后的回调函数,可以在这解析结果。
  754. ButtonResult result1 = rst.Result;
  755. if (result1 == ButtonResult.OK)
  756. {
  757. var param = rst.Parameters.GetValue<PlcInfo>("PLC");
  758. var plc = new PlcInfo()
  759. {
  760. Id = param.Id,
  761. Name = param.Name,
  762. CommunicationType = param.CommunicationType,
  763. EndpointUrl = param.EndpointUrl,
  764. };
  765. PlcList.Add(plc);
  766. _configService.AddOrUpdatePlc(plc);
  767. _plcService.CreatePlc(plc.Id, plc);
  768. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  769. }
  770. });
  771. }
  772. #endregion
  773. #region Light handlers
  774. void ExecuteAddLightControllerCommand()
  775. {
  776. // open dialog to add light controller (similar to robots)
  777. _dialogService.ShowDialog("AddLightController", rst =>
  778. {
  779. if (rst.Result == ButtonResult.OK)
  780. {
  781. var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
  782. // assign id and defaults if needed
  783. if (param.Id == 0)
  784. param.Id = (LightControllerList?.Count ?? 0) + 1;
  785. LightControllerList.Add(param);
  786. _configService.AddOrUpdateLightController(param);
  787. SelectLightController = param;
  788. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加完成", Duration = 1 });
  789. }
  790. });
  791. }
  792. void ExecuteRemoveLightControllerCommand()
  793. {
  794. if (SelectLightController == null) return;
  795. if (MessageBox.Show("是否移除光源控制器?", "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  796. {
  797. _configService.RemoveLightController(SelectLightController.Id);
  798. LightControllerList.Remove(SelectLightController);
  799. SelectLightController = null;
  800. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "移除完成", Duration = 1 });
  801. }
  802. }
  803. async void ExecuteSaveLightControllersCommand()
  804. {
  805. var view = new ShowMessage($"AAS", "是否保存光源控制器配置?");
  806. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  807. if (result != null && result is bool && (bool)result)
  808. {
  809. foreach (var item in LightControllerList)
  810. {
  811. _configService.AddOrUpdateLightController(item);
  812. }
  813. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成", Duration = 1 });
  814. }
  815. }
  816. #endregion
  817. #region 通讯
  818. async void ExecuteSaveCommunicateCommand(string parm)
  819. {
  820. if (parm == "TCPIP")
  821. {
  822. var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
  823. //show the dialog
  824. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  825. if (result != null && result is bool)
  826. {
  827. if (((bool)result))
  828. {
  829. _configService.SetBgTcp(BgTcp);
  830. _configService.SaveBgTcp();
  831. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  832. }
  833. }
  834. }
  835. else if (parm == "ModbusTCP")
  836. {
  837. var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
  838. //show the dialog
  839. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  840. if (result != null && result is bool)
  841. {
  842. if (((bool)result))
  843. {
  844. _configService.SetBgModbusTcp(BgModbus);
  845. _configService.SaveBgModbusTcp();
  846. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  847. }
  848. }
  849. }
  850. else
  851. {
  852. return;
  853. }
  854. }
  855. #endregion
  856. #region 语言
  857. void ExecuteSelectLanguageCommand(string language)
  858. {
  859. if (string.Equals(language, "ChineseSimplified"))
  860. {
  861. CurrentLanguage = Enums.Language.ChineseSimplified;
  862. var sysConfig = _configService.GetSystemConfiguration();
  863. sysConfig.CurrentLanguage = CurrentLanguage;
  864. _configService.SaveSystemConfiguration(sysConfig);
  865. var culture = new CultureInfo("zh-CN");
  866. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  867. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  868. LocalizeDictionary.Instance.Culture = culture;
  869. Lang.Culture = culture;
  870. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  871. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  872. }
  873. else if (string.Equals(language, "ChineseTraditional"))
  874. {
  875. CurrentLanguage = Enums.Language.ChineseTraditional;
  876. var sysConfig = _configService.GetSystemConfiguration();
  877. sysConfig.CurrentLanguage = CurrentLanguage;
  878. _configService.SaveSystemConfiguration(sysConfig);
  879. var culture = new CultureInfo("zh-TW");
  880. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  881. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  882. LocalizeDictionary.Instance.Culture = culture;
  883. Lang.Culture = culture;
  884. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  885. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  886. }
  887. else if (string.Equals(language, "English"))
  888. {
  889. CurrentLanguage = Enums.Language.English;
  890. var sysConfig = _configService.GetSystemConfiguration();
  891. sysConfig.CurrentLanguage = CurrentLanguage;
  892. _configService.SaveSystemConfiguration(sysConfig);
  893. var culture = new CultureInfo("en");
  894. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  895. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  896. LocalizeDictionary.Instance.Culture = culture;
  897. Lang.Culture = culture;
  898. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  899. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  900. }
  901. else if (string.Equals(language, "Japanese"))
  902. {
  903. CurrentLanguage = Enums.Language.Japanese;
  904. var sysConfig = _configService.GetSystemConfiguration();
  905. sysConfig.CurrentLanguage = CurrentLanguage;
  906. _configService.SaveSystemConfiguration(sysConfig);
  907. var culture = new CultureInfo("ja-JP");
  908. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  909. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  910. LocalizeDictionary.Instance.Culture = culture;
  911. Lang.Culture = culture;
  912. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  913. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  914. }
  915. }
  916. #endregion
  917. private void OnLoad()
  918. {
  919. }
  920. private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  921. {
  922. switch (e.PropertyName)
  923. {
  924. case "Title1":
  925. Application.Current.Resources["Font.Size.Title1"] = Title1;
  926. break;
  927. case "Title2":
  928. Application.Current.Resources["Font.Size.Title2"] = Title2;
  929. break;
  930. case "Title3":
  931. Application.Current.Resources["Font.Size.Title3"] = Title3;
  932. break;
  933. case "Title4":
  934. Application.Current.Resources["Font.Size.Title4"] = Title4;
  935. break;
  936. case "Body1":
  937. Application.Current.Resources["Font.Size.Body1"] = Body1;
  938. break;
  939. case "Body2":
  940. Application.Current.Resources["Font.Size.Body2"] = Body2;
  941. break;
  942. case "Body3":
  943. Application.Current.Resources["Font.Size.Body3"] = Body3;
  944. break;
  945. case "Body4":
  946. Application.Current.Resources["Font.Size.Body4"] = Body4;
  947. break;
  948. case "Captions1":
  949. Application.Current.Resources["Font.Size.Captions1"] = Captions1;
  950. break;
  951. case "Captions2":
  952. Application.Current.Resources["Font.Size.Captions2"] = Captions2;
  953. break;
  954. case "Captions3":
  955. Application.Current.Resources["Font.Size.Captions3"] = Captions3;
  956. break;
  957. case "Captions4":
  958. Application.Current.Resources["Font.Size.Captions4"] = Captions4;
  959. break;
  960. default:
  961. break;
  962. }
  963. }
  964. #endregion
  965. #region 继承
  966. /// <summary>
  967. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  968. /// </summary>
  969. /// <param name="navigationContext"></param>
  970. /// <param name="continuationCallback"></param>
  971. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  972. {
  973. continuationCallback(true);
  974. }
  975. /// <summary>
  976. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  977. /// </summary>
  978. /// <param name="navigationContext"></param>
  979. /// <exception cref="NotImplementedException"></exception>
  980. public async void OnNavigatedTo(NavigationContext navigationContext)
  981. {
  982. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  983. {
  984. IsAllowEdit = false;
  985. }
  986. else
  987. {
  988. IsAllowEdit = true;
  989. }
  990. if (RobotList == null)
  991. {
  992. RobotList = new ObservableCollection<RobotInfo>();
  993. var robots = _configService.GetAllRobots();
  994. foreach (var robot in robots)
  995. {
  996. RobotList.Add(robot);
  997. }
  998. }
  999. if (CameraList == null)
  1000. {
  1001. CameraList = new ObservableCollection<CameraInfo>();
  1002. var cameras = _configService.GetAllCameras();
  1003. foreach (var camera in cameras)
  1004. {
  1005. CameraList.Add(camera);
  1006. }
  1007. }
  1008. if (FeederList == null)
  1009. {
  1010. FeederList = new ObservableCollection<FeederInfo>();
  1011. var feeders = _configService.GetAllFeeders();
  1012. foreach (var feeder in feeders)
  1013. {
  1014. FeederList.Add(feeder);
  1015. }
  1016. }
  1017. if (PlcList == null)
  1018. {
  1019. PlcList = new ObservableCollection<PlcInfo>();
  1020. var plcs = _configService.GetAllPlcs();
  1021. foreach (var plc in plcs)
  1022. {
  1023. PlcList.Add(plc);
  1024. }
  1025. }
  1026. // load light controllers
  1027. if (LightControllerList == null)
  1028. {
  1029. LightControllerList = new ObservableCollection<LightControllerConfig>();
  1030. var controllers = _configService.GetAllLightControllers();
  1031. foreach (var ctrl in controllers)
  1032. {
  1033. LightControllerList.Add(ctrl);
  1034. }
  1035. }
  1036. if (BgTcp == null)
  1037. {
  1038. BgTcp = _configService.GetBgTcp();
  1039. }
  1040. if (BgModbus == null)
  1041. {
  1042. BgModbus = _configService.GetBgModbusTcp();
  1043. }
  1044. CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
  1045. // load system parameters into UI
  1046. var sys = _configService.GetSystemConfiguration();
  1047. if (sys != null)
  1048. {
  1049. CameraShotCount = sys.CameraShotCount;
  1050. UpperCameraPickShotCount = sys.UpperCameraPickShotCount;
  1051. UpperCameraPlaceShotCount = sys.UpperCameraPlaceShotCount;
  1052. UpperCameraLockAssembleCount = sys.UpperCameraLockAssembleCount;
  1053. FixedPickCameraCount = sys.PickFixedPositionProductCameraCount;
  1054. FixedLockAssembleCameraCount = sys.LockFixedPositionProductCameraCount;
  1055. FixedCameraDetectLockAssembleCount = sys.FixedCameraDetectLockAssembleCount;
  1056. }
  1057. if (isFirstLoad)
  1058. {
  1059. Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
  1060. Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
  1061. Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
  1062. Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
  1063. Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
  1064. Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
  1065. Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
  1066. Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
  1067. Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
  1068. Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
  1069. Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
  1070. Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
  1071. this.PropertyChanged += OnPropertyChanged;
  1072. isFirstLoad = false;
  1073. }
  1074. }
  1075. /// <summary>
  1076. /// 是否允许导航到此视图模型。
  1077. /// </summary>
  1078. /// <param name="navigationContext"></param>
  1079. /// <returns></returns>
  1080. public bool IsNavigationTarget(NavigationContext navigationContext)
  1081. {
  1082. return true;
  1083. }
  1084. /// <summary>
  1085. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1086. /// </summary>
  1087. /// <param name="navigationContext"></param>
  1088. public void OnNavigatedFrom(NavigationContext navigationContext)
  1089. {
  1090. }
  1091. #endregion
  1092. private bool _IsAllowEdit = false;
  1093. public bool IsAllowEdit
  1094. {
  1095. get { return _IsAllowEdit; }
  1096. set { SetProperty(ref _IsAllowEdit, value); }
  1097. }
  1098. private void LoginChange(Models.User user)
  1099. {
  1100. if (user.userPart == Enums.UserPart.Operator)
  1101. {
  1102. IsAllowEdit = false;
  1103. }
  1104. else
  1105. {
  1106. IsAllowEdit = true;
  1107. }
  1108. }
  1109. #region 系统参数
  1110. private int _CameraShotCount;
  1111. public int CameraShotCount { get => _CameraShotCount; set => SetProperty(ref _CameraShotCount, value); }
  1112. private int _UpperCameraPickShotCount;
  1113. public int UpperCameraPickShotCount { get => _UpperCameraPickShotCount; set => SetProperty(ref _UpperCameraPickShotCount, value); }
  1114. private int _UpperCameraPlaceShotCount;
  1115. public int UpperCameraPlaceShotCount { get => _UpperCameraPlaceShotCount; set => SetProperty(ref _UpperCameraPlaceShotCount, value); }
  1116. private int _UpperCameraLockAssembleCount;
  1117. public int UpperCameraLockAssembleCount { get => _UpperCameraLockAssembleCount; set => SetProperty(ref _UpperCameraLockAssembleCount, value); }
  1118. private int _FixedPickCameraCount;
  1119. public int FixedPickCameraCount { get => _FixedPickCameraCount; set => SetProperty(ref _FixedPickCameraCount, value); }
  1120. private int _FixedLockAssembleCameraCount;
  1121. public int FixedLockAssembleCameraCount { get => _FixedLockAssembleCameraCount; set => SetProperty(ref _FixedLockAssembleCameraCount, value); }
  1122. private int _FixedCameraDetectLockAssembleCount;
  1123. public int FixedCameraDetectLockAssembleCount { get => _FixedCameraDetectLockAssembleCount; set => SetProperty(ref _FixedCameraDetectLockAssembleCount, value); }
  1124. async void ExecuteSaveSystemParametersCommand()
  1125. {
  1126. var view = new ShowMessage($"AAS", "是否保存系统参数?");
  1127. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1128. if (result != null && result is bool && (bool)result)
  1129. {
  1130. var sysConfig = _configService.GetSystemConfiguration();
  1131. sysConfig.CameraShotCount = CameraShotCount;
  1132. sysConfig.UpperCameraPickShotCount = UpperCameraPickShotCount;
  1133. sysConfig.UpperCameraPlaceShotCount = UpperCameraPlaceShotCount;
  1134. sysConfig.UpperCameraLockAssembleCount = UpperCameraLockAssembleCount;
  1135. sysConfig.PickFixedPositionProductCameraCount = FixedPickCameraCount;
  1136. sysConfig.LockFixedPositionProductCameraCount = FixedLockAssembleCameraCount;
  1137. sysConfig.FixedCameraDetectLockAssembleCount = FixedCameraDetectLockAssembleCount;
  1138. _configService.SaveSystemConfiguration(sysConfig);
  1139. await management. WriteSystemParameterToPlcAsync(sysConfig);
  1140. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1141. }
  1142. }
  1143. #endregion
  1144. }
  1145. }