SettingViewModel.cs 60 KB

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