SettingViewModel.cs 52 KB

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