SettingViewModel.cs 53 KB

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