SettingViewModel.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  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. case CameraBrand.SSZN:
  506. softwarename = "OPT Camera Viewer";
  507. result = SSZNCamera.CheckSoftwareInstalled();
  508. break;
  509. default:
  510. break;
  511. }
  512. if (!result.isInstalled)
  513. {
  514. if (string.IsNullOrEmpty(result.version))
  515. {
  516. //未安装
  517. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  518. }
  519. else
  520. {
  521. //版本较低
  522. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  523. }
  524. return;
  525. }
  526. //编辑前的相机名称
  527. string oldCameraName = SelectCamera.CameraName;
  528. IDialogParameters parameters = new DialogParameters();
  529. parameters.Add("CameraBrand", cameraBrand);
  530. parameters.Add("Camera", SelectCamera.Copy());
  531. _dialogService.ShowDialog("EditCamera", parameters, rst =>
  532. {
  533. //对话框关闭之后的回调函数,可以在这解析结果。
  534. ButtonResult result1 = rst.Result;
  535. if (result1 == ButtonResult.OK)
  536. {
  537. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  538. SelectCamera.CameraName = param.CameraName;
  539. SelectCamera.SerialNumber = param.SerialNumber;
  540. SelectCamera.Model = param.Model;
  541. SelectCamera.ManufacturerName = param.ManufacturerName;
  542. SelectCamera.CameraType = param.CameraType;
  543. SelectCamera.CameraBrand = param.CameraBrand;
  544. SelectCamera.CameraIp = param.CameraIp;
  545. _configService.AddOrUpdateCamera(SelectCamera);
  546. if (oldCameraName != param.CameraName)
  547. {
  548. //对所有产品也进行修改
  549. _productService.UpdateCameraNameInProduct(SelectCamera.Id, SelectCamera.CameraName);
  550. }
  551. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  552. }
  553. });
  554. }
  555. /// <summary>
  556. /// 增加相机
  557. /// </summary>
  558. void ExecuteAddCameraCommand()
  559. {
  560. bool isSelectedCameraBrandSucced = false;
  561. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  562. _dialogService.ShowDialog("SelectCameraBrand", rst =>
  563. {
  564. if (rst.Result == ButtonResult.OK)
  565. {
  566. isSelectedCameraBrandSucced = true;
  567. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  568. }
  569. else
  570. {
  571. return;
  572. }
  573. });
  574. if (!isSelectedCameraBrandSucced) { return; }
  575. ;
  576. (bool isInstalled, string version) result = (false, "");
  577. string softwarename = "";
  578. switch (cameraBrand)
  579. {
  580. case CameraBrand.HikRobot_MVS:
  581. softwarename = "MVS";
  582. result = MvCamera.CheckSoftwareInstalled();
  583. break;
  584. case CameraBrand.Basler_Pylon:
  585. softwarename = "Pylon 7";
  586. result = BaslerCamera.CheckSoftwareInstalled();
  587. break;
  588. case CameraBrand.IRayple:
  589. softwarename = "MV Viewer";
  590. result = AHuaCamera.CheckSoftwareInstalled();
  591. break;
  592. case CameraBrand.Cognex:
  593. softwarename = "Cognex VisionPro";
  594. result = CognexCamera.CheckSoftwareInstalled();
  595. break;
  596. case CameraBrand.Galaxy:
  597. softwarename = "Galaxy Viewer";
  598. result = GalaxyCamera.CheckSoftwareInstalled();
  599. break;
  600. case CameraBrand.Opt:
  601. softwarename = "OPT Camera Viewer";
  602. result = OptCamera.CheckSoftwareInstalled();
  603. break;
  604. case CameraBrand.SSZN:
  605. softwarename = "OPT Camera Viewer";
  606. result = SSZNCamera.CheckSoftwareInstalled();
  607. break;
  608. default:
  609. break;
  610. }
  611. if (!result.isInstalled)
  612. {
  613. if (string.IsNullOrEmpty(result.version))
  614. {
  615. //未安装
  616. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  617. }
  618. else
  619. {
  620. //版本较低
  621. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  622. }
  623. return;
  624. }
  625. IDialogParameters parameters = new DialogParameters();
  626. parameters.Add("CameraBrand", cameraBrand);
  627. _dialogService.ShowDialog("AddCamera", parameters, rst =>
  628. {
  629. //对话框关闭之后的回调函数,可以在这解析结果。
  630. ButtonResult result1 = rst.Result;
  631. if (result1 == ButtonResult.OK)
  632. {
  633. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  634. var camera = new CameraInfo()
  635. {
  636. Id = param.Id,
  637. CameraName = param.CameraName,
  638. SerialNumber = param.SerialNumber,
  639. Model = param.Model,
  640. ManufacturerName = param.ManufacturerName,
  641. CameraType = param.CameraType,
  642. CameraBrand = param.CameraBrand,
  643. CameraIp = param.CameraIp
  644. };
  645. CameraList.Add(camera);
  646. _configService.AddOrUpdateCamera(camera);
  647. _cameraService.CreateCamera(camera.Id, camera);
  648. //对所有产品也进行添加
  649. _productService.AddCameraToProduct(camera.Id, camera.CameraName);
  650. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  651. }
  652. });
  653. }
  654. #endregion
  655. #region Feeder
  656. void ExecuteAddFeederCommand()
  657. {
  658. _dialogService.ShowDialog("AddFeeder", rst =>
  659. {
  660. //对话框关闭之后的回调函数,可以在这解析结果。
  661. ButtonResult result1 = rst.Result;
  662. if (result1 == ButtonResult.OK)
  663. {
  664. var param = rst.Parameters.GetValue<FeederInfo>("Feeder");
  665. var feeder = new FeederInfo()
  666. {
  667. Id = param.Id,
  668. FeederName = param.FeederName,
  669. ConnectType = param.ConnectType,
  670. FeederBrand = param.FeederBrand,
  671. IP = param.IP,
  672. Port = param.Port
  673. };
  674. FeederList.Add(feeder);
  675. _configService.AddOrUpdateFeeder(feeder);
  676. _feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
  677. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  678. }
  679. });
  680. }
  681. void ExecuteRemoveFeederCommand()
  682. {
  683. if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  684. {
  685. // 找到要删除的机器人
  686. var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
  687. if (feederToRemove != null)
  688. {
  689. _configService.RemoveFeeder(feederToRemove.Id);
  690. _feederService.RemoveFeeder(feederToRemove.Id);
  691. var root = _configService.GetAllFeeders();
  692. FeederList = new ObservableCollection<FeederInfo>(root);
  693. foreach (var item in FeederList)
  694. {
  695. _feederService.UpdateFeederNo(item.Id, item.FeederNo);
  696. }
  697. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  698. }
  699. }
  700. }
  701. async void ExecuteSaveFeedersCommand()
  702. {
  703. var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
  704. //show the dialog
  705. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  706. if (result != null && result is bool)
  707. {
  708. if (((bool)result))
  709. {
  710. foreach (var item in FeederList)
  711. {
  712. _configService.AddOrUpdateFeeder(item);
  713. }
  714. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  715. }
  716. }
  717. }
  718. #endregion
  719. #region PLC
  720. /// <summary>
  721. /// 保存PLC
  722. /// </summary>
  723. async void ExecuteSavePlcsCommand()
  724. {
  725. var view = new ShowMessage($"AAS", Lang.是否保存PLC);
  726. //show the dialog
  727. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  728. if (result != null && result is bool)
  729. {
  730. if (((bool)result))
  731. {
  732. foreach (var item in PlcList)
  733. {
  734. _configService.AddOrUpdatePlc(item);
  735. }
  736. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  737. }
  738. }
  739. }
  740. /// <summary>
  741. /// 移除PLC
  742. /// </summary>
  743. void ExecuteRemovePlcCommand()
  744. {
  745. if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  746. {
  747. // 找到要删除的plc
  748. var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
  749. if (plcToRemove != null)
  750. {
  751. _configService.RemovePlc(plcToRemove.Id);
  752. _plcService.RemovePlc(plcToRemove.Id);
  753. var root = _configService.GetAllPlcs();
  754. PlcList = new ObservableCollection<PlcInfo>(root);
  755. foreach (var item in PlcList)
  756. {
  757. _plcService.UpdatePlcNumber(item.Id, item.Index);
  758. }
  759. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  760. }
  761. }
  762. }
  763. /// <summary>
  764. /// 增加PLC
  765. /// </summary>
  766. void ExecuteAddPlcCommand()
  767. {
  768. _dialogService.ShowDialog("AddPlc", rst =>
  769. {
  770. //对话框关闭之后的回调函数,可以在这解析结果。
  771. ButtonResult result1 = rst.Result;
  772. if (result1 == ButtonResult.OK)
  773. {
  774. var param = rst.Parameters.GetValue<PlcInfo>("PLC");
  775. var plc = new PlcInfo()
  776. {
  777. Id = param.Id,
  778. Name = param.Name,
  779. CommunicationType = param.CommunicationType,
  780. EndpointUrl = param.EndpointUrl,
  781. };
  782. PlcList.Add(plc);
  783. _configService.AddOrUpdatePlc(plc);
  784. _plcService.CreatePlc(plc.Id, plc);
  785. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  786. }
  787. });
  788. }
  789. #endregion
  790. #region Light handlers
  791. void ExecuteAddLightControllerCommand()
  792. {
  793. // open dialog to add light controller (similar to robots)
  794. _dialogService.ShowDialog("AddLightController", rst =>
  795. {
  796. if (rst.Result == ButtonResult.OK)
  797. {
  798. var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
  799. // assign id and defaults if needed
  800. if (param.Id == 0)
  801. param.Id = (LightControllerList?.Count ?? 0) + 1;
  802. LightControllerList.Add(param);
  803. _configService.AddOrUpdateLightController(param);
  804. SelectLightController = param;
  805. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加完成", Duration = 1 });
  806. }
  807. });
  808. }
  809. void ExecuteRemoveLightControllerCommand()
  810. {
  811. if (SelectLightController == null) return;
  812. if (MessageBox.Show("是否移除光源控制器?", "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  813. {
  814. _configService.RemoveLightController(SelectLightController.Id);
  815. LightControllerList.Remove(SelectLightController);
  816. SelectLightController = null;
  817. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "移除完成", Duration = 1 });
  818. }
  819. }
  820. async void ExecuteSaveLightControllersCommand()
  821. {
  822. var view = new ShowMessage($"AAS", "是否保存光源控制器配置?");
  823. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  824. if (result != null && result is bool && (bool)result)
  825. {
  826. foreach (var item in LightControllerList)
  827. {
  828. _configService.AddOrUpdateLightController(item);
  829. }
  830. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成", Duration = 1 });
  831. }
  832. }
  833. #endregion
  834. #region 通讯
  835. async void ExecuteSaveCommunicateCommand(string parm)
  836. {
  837. if (parm == "TCPIP")
  838. {
  839. var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
  840. //show the dialog
  841. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  842. if (result != null && result is bool)
  843. {
  844. if (((bool)result))
  845. {
  846. _configService.SetBgTcp(BgTcp);
  847. _configService.SaveBgTcp();
  848. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  849. }
  850. }
  851. }
  852. else if (parm == "ModbusTCP")
  853. {
  854. var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
  855. //show the dialog
  856. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  857. if (result != null && result is bool)
  858. {
  859. if (((bool)result))
  860. {
  861. _configService.SetBgModbusTcp(BgModbus);
  862. _configService.SaveBgModbusTcp();
  863. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  864. }
  865. }
  866. }
  867. else
  868. {
  869. return;
  870. }
  871. }
  872. #endregion
  873. #region 语言
  874. void ExecuteSelectLanguageCommand(string language)
  875. {
  876. if (string.Equals(language, "ChineseSimplified"))
  877. {
  878. CurrentLanguage = Enums.Language.ChineseSimplified;
  879. var sysConfig = _configService.GetSystemConfiguration();
  880. sysConfig.CurrentLanguage = CurrentLanguage;
  881. _configService.SaveSystemConfiguration(sysConfig);
  882. var culture = new CultureInfo("zh-CN");
  883. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  884. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  885. LocalizeDictionary.Instance.Culture = culture;
  886. Lang.Culture = culture;
  887. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  888. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  889. }
  890. else if (string.Equals(language, "ChineseTraditional"))
  891. {
  892. CurrentLanguage = Enums.Language.ChineseTraditional;
  893. var sysConfig = _configService.GetSystemConfiguration();
  894. sysConfig.CurrentLanguage = CurrentLanguage;
  895. _configService.SaveSystemConfiguration(sysConfig);
  896. var culture = new CultureInfo("zh-TW");
  897. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  898. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  899. LocalizeDictionary.Instance.Culture = culture;
  900. Lang.Culture = culture;
  901. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  902. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  903. }
  904. else if (string.Equals(language, "English"))
  905. {
  906. CurrentLanguage = Enums.Language.English;
  907. var sysConfig = _configService.GetSystemConfiguration();
  908. sysConfig.CurrentLanguage = CurrentLanguage;
  909. _configService.SaveSystemConfiguration(sysConfig);
  910. var culture = new CultureInfo("en");
  911. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  912. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  913. LocalizeDictionary.Instance.Culture = culture;
  914. Lang.Culture = culture;
  915. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  916. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  917. }
  918. else if (string.Equals(language, "Japanese"))
  919. {
  920. CurrentLanguage = Enums.Language.Japanese;
  921. var sysConfig = _configService.GetSystemConfiguration();
  922. sysConfig.CurrentLanguage = CurrentLanguage;
  923. _configService.SaveSystemConfiguration(sysConfig);
  924. var culture = new CultureInfo("ja-JP");
  925. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  926. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  927. LocalizeDictionary.Instance.Culture = culture;
  928. Lang.Culture = culture;
  929. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  930. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  931. }
  932. }
  933. #endregion
  934. private void OnLoad()
  935. {
  936. }
  937. private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  938. {
  939. switch (e.PropertyName)
  940. {
  941. case "Title1":
  942. Application.Current.Resources["Font.Size.Title1"] = Title1;
  943. break;
  944. case "Title2":
  945. Application.Current.Resources["Font.Size.Title2"] = Title2;
  946. break;
  947. case "Title3":
  948. Application.Current.Resources["Font.Size.Title3"] = Title3;
  949. break;
  950. case "Title4":
  951. Application.Current.Resources["Font.Size.Title4"] = Title4;
  952. break;
  953. case "Body1":
  954. Application.Current.Resources["Font.Size.Body1"] = Body1;
  955. break;
  956. case "Body2":
  957. Application.Current.Resources["Font.Size.Body2"] = Body2;
  958. break;
  959. case "Body3":
  960. Application.Current.Resources["Font.Size.Body3"] = Body3;
  961. break;
  962. case "Body4":
  963. Application.Current.Resources["Font.Size.Body4"] = Body4;
  964. break;
  965. case "Captions1":
  966. Application.Current.Resources["Font.Size.Captions1"] = Captions1;
  967. break;
  968. case "Captions2":
  969. Application.Current.Resources["Font.Size.Captions2"] = Captions2;
  970. break;
  971. case "Captions3":
  972. Application.Current.Resources["Font.Size.Captions3"] = Captions3;
  973. break;
  974. case "Captions4":
  975. Application.Current.Resources["Font.Size.Captions4"] = Captions4;
  976. break;
  977. default:
  978. break;
  979. }
  980. }
  981. #endregion
  982. #region 继承
  983. /// <summary>
  984. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  985. /// </summary>
  986. /// <param name="navigationContext"></param>
  987. /// <param name="continuationCallback"></param>
  988. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  989. {
  990. continuationCallback(true);
  991. }
  992. /// <summary>
  993. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  994. /// </summary>
  995. /// <param name="navigationContext"></param>
  996. /// <exception cref="NotImplementedException"></exception>
  997. public async void OnNavigatedTo(NavigationContext navigationContext)
  998. {
  999. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  1000. {
  1001. IsAllowEdit = false;
  1002. }
  1003. else
  1004. {
  1005. IsAllowEdit = true;
  1006. }
  1007. if (RobotList == null)
  1008. {
  1009. RobotList = new ObservableCollection<RobotInfo>();
  1010. var robots = _configService.GetAllRobots();
  1011. foreach (var robot in robots)
  1012. {
  1013. RobotList.Add(robot);
  1014. }
  1015. }
  1016. if (CameraList == null)
  1017. {
  1018. CameraList = new ObservableCollection<CameraInfo>();
  1019. var cameras = _configService.GetAllCameras();
  1020. foreach (var camera in cameras)
  1021. {
  1022. CameraList.Add(camera);
  1023. }
  1024. }
  1025. if (FeederList == null)
  1026. {
  1027. FeederList = new ObservableCollection<FeederInfo>();
  1028. var feeders = _configService.GetAllFeeders();
  1029. foreach (var feeder in feeders)
  1030. {
  1031. FeederList.Add(feeder);
  1032. }
  1033. }
  1034. if (PlcList == null)
  1035. {
  1036. PlcList = new ObservableCollection<PlcInfo>();
  1037. var plcs = _configService.GetAllPlcs();
  1038. foreach (var plc in plcs)
  1039. {
  1040. PlcList.Add(plc);
  1041. }
  1042. }
  1043. // load light controllers
  1044. if (LightControllerList == null)
  1045. {
  1046. LightControllerList = new ObservableCollection<LightControllerConfig>();
  1047. var controllers = _configService.GetAllLightControllers();
  1048. foreach (var ctrl in controllers)
  1049. {
  1050. LightControllerList.Add(ctrl);
  1051. }
  1052. }
  1053. if (BgTcp == null)
  1054. {
  1055. BgTcp = _configService.GetBgTcp();
  1056. }
  1057. if (BgModbus == null)
  1058. {
  1059. BgModbus = _configService.GetBgModbusTcp();
  1060. }
  1061. CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
  1062. // load system parameters into UI
  1063. var sys = _configService.GetSystemConfiguration();
  1064. if (sys != null)
  1065. {
  1066. WorkMode = sys.WorkMode;
  1067. PickPointNum = sys.PickPointNum;
  1068. DowmCameraNum = sys.DowmCameraNum;
  1069. WorkMode = sys.WorkMode;
  1070. PickPointNum = sys.PickPointNum;
  1071. DowmCameraNum = sys.DowmCameraNum;
  1072. UpCameraPickNum = sys.UpCameraPickNum;
  1073. UpCameraPutNum = sys.UpCameraPutNum;
  1074. UPCameracheckNum = sys.UPCameracheckNum;
  1075. FixedCameraPickNum = sys.FixedCameraPickNum;
  1076. FixedCameraPutNum = sys.FixedCameraPutNum;
  1077. FixedCameracheckNum = sys.FixedCameracheckNum;
  1078. }
  1079. if (isFirstLoad)
  1080. {
  1081. Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
  1082. Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
  1083. Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
  1084. Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
  1085. Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
  1086. Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
  1087. Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
  1088. Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
  1089. Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
  1090. Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
  1091. Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
  1092. Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
  1093. this.PropertyChanged += OnPropertyChanged;
  1094. isFirstLoad = false;
  1095. }
  1096. }
  1097. /// <summary>
  1098. /// 是否允许导航到此视图模型。
  1099. /// </summary>
  1100. /// <param name="navigationContext"></param>
  1101. /// <returns></returns>
  1102. public bool IsNavigationTarget(NavigationContext navigationContext)
  1103. {
  1104. return true;
  1105. }
  1106. /// <summary>
  1107. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1108. /// </summary>
  1109. /// <param name="navigationContext"></param>
  1110. public void OnNavigatedFrom(NavigationContext navigationContext)
  1111. {
  1112. }
  1113. #endregion
  1114. private bool _IsAllowEdit = false;
  1115. public bool IsAllowEdit
  1116. {
  1117. get { return _IsAllowEdit; }
  1118. set { SetProperty(ref _IsAllowEdit, value); }
  1119. }
  1120. private void LoginChange(Models.User user)
  1121. {
  1122. if (user.userPart == Enums.UserPart.Operator)
  1123. {
  1124. IsAllowEdit = false;
  1125. }
  1126. else
  1127. {
  1128. IsAllowEdit = true;
  1129. }
  1130. }
  1131. #region 系统参数
  1132. private Int16 _WorkMode = 0;
  1133. /// <summary>
  1134. /// 工作模式 =1 拍1打1 =2 拍1打所有
  1135. /// </summary>
  1136. public Int16 WorkMode
  1137. {
  1138. get { return _WorkMode; }
  1139. set { SetProperty(ref _WorkMode, value); }
  1140. }
  1141. private Int16 _PickPointNum = 0;
  1142. /// <summary>
  1143. /// 取料位置 =0 不需要取料 =1 需要取料
  1144. /// </summary>
  1145. public Int16 PickPointNum
  1146. {
  1147. get { return _PickPointNum; }
  1148. set { SetProperty(ref _PickPointNum, value); }
  1149. }
  1150. private Int16 _DowmCameraNum = 0;
  1151. /// <summary>
  1152. /// 下相机拍照次数
  1153. /// </summary>
  1154. public Int16 DowmCameraNum
  1155. {
  1156. get => _DowmCameraNum;
  1157. set => SetProperty(ref _DowmCameraNum, value);
  1158. }
  1159. private Int16 _UpCameraPickNum = 0;
  1160. /// <summary>
  1161. /// 上相机取料拍照次数
  1162. /// </summary>
  1163. public Int16 UpCameraPickNum
  1164. {
  1165. get => _UpCameraPickNum;
  1166. set => SetProperty(ref _UpCameraPickNum, value);
  1167. }
  1168. private Int16 _UpCameraPutNum = 0;
  1169. /// <summary>
  1170. /// 上相机放料拍照次数
  1171. /// </summary>
  1172. public Int16 UpCameraPutNum
  1173. {
  1174. get => _UpCameraPutNum;
  1175. set => SetProperty(ref _UpCameraPutNum, value);
  1176. }
  1177. private Int16 _UPCameracheckNum = 0;
  1178. /// <summary>
  1179. /// 上相机锁附/组装次数
  1180. /// </summary>
  1181. public Int16 UPCameracheckNum
  1182. {
  1183. get => _UPCameracheckNum;
  1184. set => SetProperty(ref _UPCameracheckNum, value);
  1185. }
  1186. private Int16 _FixedCameraPickNum = 0;
  1187. /// <summary>
  1188. /// 取料固定位置拍产品相机数量
  1189. /// </summary>
  1190. public Int16 FixedCameraPickNum
  1191. {
  1192. get => _FixedCameraPickNum;
  1193. set => SetProperty(ref _FixedCameraPickNum, value);
  1194. }
  1195. private Int16 _FixedCameraPutNum = 0;
  1196. /// <summary>
  1197. /// 锁附/组装固定位置拍产品相机数量
  1198. /// </summary>
  1199. public Int16 FixedCameraPutNum
  1200. {
  1201. get => _FixedCameraPutNum;
  1202. set => SetProperty(ref _FixedCameraPutNum, value);
  1203. }
  1204. private Int16 _FixedCameracheckNum = 0;
  1205. /// <summary>
  1206. /// 固定相机检测锁附/组装次数
  1207. /// </summary>
  1208. public Int16 FixedCameracheckNum
  1209. {
  1210. get => _FixedCameracheckNum;
  1211. set => SetProperty(ref _FixedCameracheckNum, value);
  1212. }
  1213. async void ExecuteSaveSystemParametersCommand()
  1214. {
  1215. var view = new ShowMessage($"AAS", "是否保存系统参数?");
  1216. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1217. if (result != null && result is bool && (bool)result)
  1218. {
  1219. try
  1220. {
  1221. var sysConfig = _configService.GetSystemConfiguration();
  1222. sysConfig.WorkMode = WorkMode;
  1223. sysConfig.PickPointNum = PickPointNum;
  1224. sysConfig.DowmCameraNum = DowmCameraNum;
  1225. sysConfig.UpCameraPickNum = UpCameraPickNum;
  1226. sysConfig.UpCameraPutNum = UpCameraPutNum;
  1227. sysConfig.UPCameracheckNum = UPCameracheckNum;
  1228. sysConfig.FixedCameraPickNum = FixedCameraPickNum;
  1229. sysConfig.FixedCameraPutNum = FixedCameraPutNum;
  1230. sysConfig.FixedCameracheckNum = FixedCameracheckNum;
  1231. _configService.SaveSystemConfiguration(sysConfig);
  1232. await management.WriteSystemParameterToPlcAsync(sysConfig);
  1233. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1234. }
  1235. catch (Exception ex)
  1236. {
  1237. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg =ex.Message, Duration = 1 });
  1238. }
  1239. }
  1240. }
  1241. #endregion
  1242. }
  1243. }