SettingViewModel.cs 58 KB

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