SettingViewModel.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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 _SaveDeviceInfoCommand;
  350. public DelegateCommand SaveDeviceInfoCommand => _SaveDeviceInfoCommand ?? (_SaveDeviceInfoCommand = new DelegateCommand(ExecuteSaveDeviceInfoCommand));
  351. private DelegateCommand _BrowseScrewCurvePathCommand;
  352. public DelegateCommand BrowseScrewCurvePathCommand => _BrowseScrewCurvePathCommand ?? (_BrowseScrewCurvePathCommand = new DelegateCommand(ExecuteBrowseScrewCurvePathCommand));
  353. private DelegateCommand _AddScrewFeederCommand;
  354. public DelegateCommand AddScrewFeederCommand =>
  355. _AddScrewFeederCommand ?? (_AddScrewFeederCommand = new DelegateCommand(ExecuteAddScrewFeederCommand));
  356. private DelegateCommand _RemoveScrewFeederCommand;
  357. public DelegateCommand RemoveScrewFeederCommand =>
  358. _RemoveScrewFeederCommand ?? (_RemoveScrewFeederCommand = new DelegateCommand(ExecuteRemoveScrewFeederCommand));
  359. private DelegateCommand _SaveScrewFeedersCommand;
  360. public DelegateCommand SaveScrewFeedersCommand =>
  361. _SaveScrewFeedersCommand ?? (_SaveScrewFeedersCommand = new DelegateCommand(ExecuteSaveScrewFeedersCommand));
  362. private DelegateCommand<object> _LightModelChangedCommand;
  363. public DelegateCommand<object> LightModelChangedCommand =>
  364. _LightModelChangedCommand ?? (_LightModelChangedCommand = new DelegateCommand<object>(ExecuteLightModelChangedCommand));
  365. private DelegateCommand _SaveCardReaderConfigCommand;
  366. public DelegateCommand SaveCardReaderConfigCommand =>
  367. _SaveCardReaderConfigCommand ?? (_SaveCardReaderConfigCommand = new DelegateCommand(ExecuteSaveCardReaderConfigCommand));
  368. #endregion
  369. #region 事件
  370. #endregion
  371. public SettingViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  372. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService,
  373. IProductService productService, ISystemDatabaseService systemDatabaseService)
  374. {
  375. _regionManager = regionManager;
  376. _eventAggregator = ea;
  377. _container = container;
  378. _dialogService = dialogService;
  379. _configService = configService;
  380. _robotService = robotService;
  381. _cameraService = cameraService;
  382. _feederService = feederService;
  383. _plcService = plcService;
  384. _productService = productService;
  385. _systemDatabaseService = systemDatabaseService;
  386. management = _container.Resolve<Management>();
  387. LoadedCommand = new DelegateCommand(OnLoad);
  388. //订阅权限登录事件
  389. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  390. }
  391. #region 方法
  392. #region 机器人
  393. private void ExecuteAddRobotCommand()
  394. {
  395. _dialogService.ShowDialog("AddRobot", rst =>
  396. {
  397. //对话框关闭之后的回调函数,可以在这解析结果。
  398. ButtonResult result1 = rst.Result;
  399. if (result1 == ButtonResult.OK)
  400. {
  401. var param = rst.Parameters.GetValue<RobotInfo>("Robot");
  402. var robot = new RobotInfo()
  403. {
  404. Id = param.Id,
  405. RobotName = param.RobotName,
  406. ConnectType = param.ConnectType,
  407. RobotBrand = param.RobotBrand,
  408. IP = param.IP,
  409. Port = param.Port,
  410. Terminator = param.Terminator,
  411. };
  412. RobotList.Add(robot);
  413. _configService.AddOrUpdateRobot(robot);
  414. _robotService.CreateRobot(robot.Id, robot);
  415. //对所有产品也进行添加
  416. _productService.AddRobotPointToProduct(robot.Id, robot.RobotName);
  417. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
  418. }
  419. });
  420. }
  421. void ExecuteRemoveCommand()
  422. {
  423. if (MessageBox.Show(Lang.是否移除机器人, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  424. {
  425. // 找到要删除的机器人
  426. var robotToRemove = RobotList.FirstOrDefault(r => r.Id == SelectRobot.Id);
  427. if (robotToRemove != null)
  428. {
  429. RobotList.Remove(robotToRemove);
  430. _configService.RemoveRobot(robotToRemove.Id);
  431. _robotService.RemoveRobot(robotToRemove.Id);
  432. //对所有产品也进行移除
  433. _productService.RemoveRobotPointFromProduct(robotToRemove.Id);
  434. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  435. }
  436. }
  437. }
  438. async void ExecuteSaveRobotsCommand()
  439. {
  440. var view = new ShowMessage($"AAS", Lang.是否保存机器人);
  441. //show the dialog
  442. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  443. if (result != null && result is bool)
  444. {
  445. if (((bool)result))
  446. {
  447. foreach (var item in RobotList)
  448. {
  449. var robot = _robotService.GetRobot(item.Id);
  450. if (robot != null)
  451. {
  452. //更新连接参数
  453. robot.SafeZ = item.SafeZ;
  454. }
  455. _configService.AddOrUpdateRobot(item);
  456. }
  457. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  458. }
  459. }
  460. }
  461. #endregion
  462. #region 相机
  463. /// <summary>
  464. /// 保存所有相机
  465. /// </summary>
  466. async void ExecuteSaveCamerasCommand()
  467. {
  468. var view = new ShowMessage($"AAS", Lang.是否保存相机配置);
  469. //show the dialog
  470. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  471. if (result != null && result is bool)
  472. {
  473. if (((bool)result))
  474. {
  475. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  476. //management.SaveCamerasDeviceConfig();
  477. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  478. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  479. }
  480. }
  481. }
  482. /// <summary>
  483. /// 移除相机
  484. /// </summary>
  485. void ExecuteRemoveCameraCommand()
  486. {
  487. if (MessageBox.Show(Lang.是否移除相机, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  488. {
  489. // 找到要删除的相机
  490. var cameraToRemove = CameraList.FirstOrDefault(r => r.Id == SelectCamera.Id);
  491. if (cameraToRemove != null)
  492. {
  493. _configService.RemoveCamera(cameraToRemove.Id);
  494. _cameraService.RemoveCamera(cameraToRemove.Id);
  495. var root = _configService.GetAllCameras();
  496. CameraList = new ObservableCollection<CameraInfo>(root);
  497. foreach (var item in CameraList)
  498. {
  499. _cameraService.UpdateCameraNumber(item.Id, item.CameraNo);
  500. }
  501. //对所有产品也进行移除
  502. _productService.RemoveCameraFromProduct(cameraToRemove.Id);
  503. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  504. }
  505. }
  506. }
  507. /// <summary>
  508. /// 编辑相机
  509. /// </summary>
  510. void ExecuteEditCameraCommand()
  511. {
  512. if (SelectCamera == null) return;
  513. bool isSelectedCameraBrandSucced = false;
  514. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  515. IDialogParameters parameters1 = new DialogParameters();
  516. parameters1.Add("CameraBrand", SelectCamera.CameraBrand);
  517. _dialogService.ShowDialog("SelectCameraBrand", parameters1, rst =>
  518. {
  519. if (rst.Result == ButtonResult.OK)
  520. {
  521. isSelectedCameraBrandSucced = true;
  522. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  523. }
  524. else
  525. {
  526. return;
  527. }
  528. });
  529. if (!isSelectedCameraBrandSucced) { return; }
  530. (bool isInstalled, string version) result = (false, "");
  531. string softwarename = "";
  532. switch (cameraBrand)
  533. {
  534. case CameraBrand.HikRobot_MVS:
  535. softwarename = "MVS";
  536. result = MvCamera.CheckSoftwareInstalled();
  537. break;
  538. case CameraBrand.Basler_Pylon:
  539. softwarename = "Pylon 7";
  540. result = BaslerCamera.CheckSoftwareInstalled();
  541. break;
  542. case CameraBrand.IRayple:
  543. softwarename = "MV Viewer";
  544. result = AHuaCamera.CheckSoftwareInstalled();
  545. break;
  546. case CameraBrand.Cognex:
  547. softwarename = "Cognex VisionPro";
  548. result = CognexCamera.CheckSoftwareInstalled();
  549. break;
  550. case CameraBrand.Galaxy:
  551. softwarename = "Galaxy Viewer";
  552. result = GalaxyCamera.CheckSoftwareInstalled();
  553. break;
  554. case CameraBrand.Opt:
  555. softwarename = "OPT Camera Viewer";
  556. result = OptCamera.CheckSoftwareInstalled();
  557. break;
  558. default:
  559. break;
  560. }
  561. if (!result.isInstalled)
  562. {
  563. if (string.IsNullOrEmpty(result.version))
  564. {
  565. //未安装
  566. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  567. }
  568. else
  569. {
  570. //版本较低
  571. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  572. }
  573. return;
  574. }
  575. //编辑前的相机名称
  576. string oldCameraName = SelectCamera.CameraName;
  577. IDialogParameters parameters = new DialogParameters();
  578. parameters.Add("CameraBrand", cameraBrand);
  579. parameters.Add("Camera", SelectCamera.Copy());
  580. _dialogService.ShowDialog("EditCamera", parameters, rst =>
  581. {
  582. //对话框关闭之后的回调函数,可以在这解析结果。
  583. ButtonResult result1 = rst.Result;
  584. if (result1 == ButtonResult.OK)
  585. {
  586. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  587. SelectCamera.CameraName = param.CameraName;
  588. SelectCamera.SerialNumber = param.SerialNumber;
  589. SelectCamera.Model = param.Model;
  590. SelectCamera.ManufacturerName = param.ManufacturerName;
  591. SelectCamera.CameraType = param.CameraType;
  592. SelectCamera.CameraBrand = param.CameraBrand;
  593. SelectCamera.CameraIp = param.CameraIp;
  594. _configService.AddOrUpdateCamera(SelectCamera);
  595. if (oldCameraName != param.CameraName)
  596. {
  597. //对所有产品也进行修改
  598. _productService.UpdateCameraNameInProduct(SelectCamera.Id, SelectCamera.CameraName);
  599. }
  600. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  601. }
  602. });
  603. }
  604. /// <summary>
  605. /// 增加相机
  606. /// </summary>
  607. void ExecuteAddCameraCommand()
  608. {
  609. bool isSelectedCameraBrandSucced = false;
  610. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  611. _dialogService.ShowDialog("SelectCameraBrand", rst =>
  612. {
  613. if (rst.Result == ButtonResult.OK)
  614. {
  615. isSelectedCameraBrandSucced = true;
  616. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  617. }
  618. else
  619. {
  620. return;
  621. }
  622. });
  623. if (!isSelectedCameraBrandSucced) { return; }
  624. ;
  625. (bool isInstalled, string version) result = (false, "");
  626. string softwarename = "";
  627. switch (cameraBrand)
  628. {
  629. case CameraBrand.HikRobot_MVS:
  630. softwarename = "MVS";
  631. result = MvCamera.CheckSoftwareInstalled();
  632. break;
  633. case CameraBrand.Basler_Pylon:
  634. softwarename = "Pylon 7";
  635. result = BaslerCamera.CheckSoftwareInstalled();
  636. break;
  637. case CameraBrand.IRayple:
  638. softwarename = "MV Viewer";
  639. result = AHuaCamera.CheckSoftwareInstalled();
  640. break;
  641. case CameraBrand.Cognex:
  642. softwarename = "Cognex VisionPro";
  643. result = CognexCamera.CheckSoftwareInstalled();
  644. break;
  645. case CameraBrand.Galaxy:
  646. softwarename = "Galaxy Viewer";
  647. result = GalaxyCamera.CheckSoftwareInstalled();
  648. break;
  649. case CameraBrand.Opt:
  650. softwarename = "OPT Camera Viewer";
  651. result = OptCamera.CheckSoftwareInstalled();
  652. break;
  653. default:
  654. break;
  655. }
  656. if (!result.isInstalled)
  657. {
  658. if (string.IsNullOrEmpty(result.version))
  659. {
  660. //未安装
  661. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  662. }
  663. else
  664. {
  665. //版本较低
  666. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  667. }
  668. return;
  669. }
  670. IDialogParameters parameters = new DialogParameters();
  671. parameters.Add("CameraBrand", cameraBrand);
  672. _dialogService.ShowDialog("AddCamera", parameters, rst =>
  673. {
  674. //对话框关闭之后的回调函数,可以在这解析结果。
  675. ButtonResult result1 = rst.Result;
  676. if (result1 == ButtonResult.OK)
  677. {
  678. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  679. var camera = new CameraInfo()
  680. {
  681. Id = param.Id,
  682. CameraName = param.CameraName,
  683. SerialNumber = param.SerialNumber,
  684. Model = param.Model,
  685. ManufacturerName = param.ManufacturerName,
  686. CameraType = param.CameraType,
  687. CameraBrand = param.CameraBrand,
  688. CameraIp = param.CameraIp
  689. };
  690. CameraList.Add(camera);
  691. _configService.AddOrUpdateCamera(camera);
  692. _cameraService.CreateCamera(camera.Id, camera);
  693. //对所有产品也进行添加
  694. _productService.AddCameraToProduct(camera.Id, camera.CameraName);
  695. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  696. }
  697. });
  698. }
  699. #endregion
  700. #region Feeder
  701. void ExecuteAddFeederCommand()
  702. {
  703. _dialogService.ShowDialog("AddFeeder", rst =>
  704. {
  705. //对话框关闭之后的回调函数,可以在这解析结果。
  706. ButtonResult result1 = rst.Result;
  707. if (result1 == ButtonResult.OK)
  708. {
  709. var param = rst.Parameters.GetValue<FeederInfo>("Feeder");
  710. var feeder = new FeederInfo()
  711. {
  712. Id = param.Id,
  713. FeederName = param.FeederName,
  714. ConnectType = param.ConnectType,
  715. FeederBrand = param.FeederBrand,
  716. IP = param.IP,
  717. Port = param.Port
  718. };
  719. FeederList.Add(feeder);
  720. _configService.AddOrUpdateFeeder(feeder);
  721. _feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
  722. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  723. }
  724. });
  725. }
  726. void ExecuteRemoveFeederCommand()
  727. {
  728. if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  729. {
  730. // 找到要删除的机器人
  731. var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
  732. if (feederToRemove != null)
  733. {
  734. _configService.RemoveFeeder(feederToRemove.Id);
  735. _feederService.RemoveFeeder(feederToRemove.Id);
  736. var root = _configService.GetAllFeeders();
  737. FeederList = new ObservableCollection<FeederInfo>(root);
  738. foreach (var item in FeederList)
  739. {
  740. _feederService.UpdateFeederNo(item.Id, item.FeederNo);
  741. }
  742. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  743. }
  744. }
  745. }
  746. async void ExecuteSaveFeedersCommand()
  747. {
  748. var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
  749. //show the dialog
  750. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  751. if (result != null && result is bool)
  752. {
  753. if (((bool)result))
  754. {
  755. foreach (var item in FeederList)
  756. {
  757. _configService.AddOrUpdateFeeder(item);
  758. }
  759. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  760. }
  761. }
  762. }
  763. #endregion
  764. #region PLC
  765. /// <summary>
  766. /// 保存PLC
  767. /// </summary>
  768. async void ExecuteSavePlcsCommand()
  769. {
  770. var view = new ShowMessage($"AAS", Lang.是否保存PLC);
  771. //show the dialog
  772. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  773. if (result != null && result is bool)
  774. {
  775. if (((bool)result))
  776. {
  777. foreach (var item in PlcList)
  778. {
  779. _configService.AddOrUpdatePlc(item);
  780. }
  781. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  782. }
  783. }
  784. }
  785. /// <summary>
  786. /// 移除PLC
  787. /// </summary>
  788. void ExecuteRemovePlcCommand()
  789. {
  790. if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  791. {
  792. // 找到要删除的plc
  793. var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
  794. if (plcToRemove != null)
  795. {
  796. _configService.RemovePlc(plcToRemove.Id);
  797. _plcService.RemovePlc(plcToRemove.Id);
  798. var root = _configService.GetAllPlcs();
  799. PlcList = new ObservableCollection<PlcInfo>(root);
  800. foreach (var item in PlcList)
  801. {
  802. _plcService.UpdatePlcNumber(item.Id, item.Index);
  803. }
  804. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  805. }
  806. }
  807. }
  808. /// <summary>
  809. /// 增加PLC
  810. /// </summary>
  811. void ExecuteAddPlcCommand()
  812. {
  813. _dialogService.ShowDialog("AddPlc", rst =>
  814. {
  815. //对话框关闭之后的回调函数,可以在这解析结果。
  816. ButtonResult result1 = rst.Result;
  817. if (result1 == ButtonResult.OK)
  818. {
  819. var param = rst.Parameters.GetValue<PlcInfo>("PLC");
  820. var plc = new PlcInfo()
  821. {
  822. Id = param.Id,
  823. Name = param.Name,
  824. CommunicationType = param.CommunicationType,
  825. EndpointUrl = param.EndpointUrl,
  826. };
  827. PlcList.Add(plc);
  828. _configService.AddOrUpdatePlc(plc);
  829. _plcService.CreatePlc(plc.Id, plc);
  830. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  831. }
  832. });
  833. }
  834. #endregion
  835. #region Light handlers
  836. void ExecuteAddLightControllerCommand()
  837. {
  838. // open dialog to add light controller (similar to robots)
  839. _dialogService.ShowDialog("AddLightController", rst =>
  840. {
  841. if (rst.Result == ButtonResult.OK)
  842. {
  843. var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
  844. // assign id and defaults if needed
  845. if (param.Id == 0)
  846. param.Id = (LightControllerList?.Count ?? 0) + 1;
  847. LightControllerList.Add(param);
  848. _configService.AddOrUpdateLightController(param);
  849. SelectLightController = param;
  850. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  851. }
  852. });
  853. }
  854. void ExecuteRemoveLightControllerCommand()
  855. {
  856. if (SelectLightController == null) return;
  857. if (MessageBox.Show(Lang.是否移除光源控制器, "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  858. {
  859. _configService.RemoveLightController(SelectLightController.Id);
  860. LightControllerList.Remove(SelectLightController);
  861. SelectLightController = null;
  862. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  863. }
  864. }
  865. async void ExecuteSaveLightControllersCommand()
  866. {
  867. var view = new ShowMessage($"AAS", Lang.是否保存光源控制器配置);
  868. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  869. if (result != null && result is bool && (bool)result)
  870. {
  871. foreach (var item in LightControllerList)
  872. {
  873. _configService.AddOrUpdateLightController(item);
  874. }
  875. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  876. }
  877. }
  878. /// <summary>
  879. /// 光源型号改变
  880. /// </summary>
  881. void ExecuteLightModelChangedCommand(object obj)
  882. {
  883. try
  884. {
  885. if (obj == null)
  886. {
  887. return;
  888. }
  889. if (obj is LightControllerConfig lc)
  890. {
  891. lc.Init();
  892. }
  893. }
  894. catch (Exception)
  895. {
  896. }
  897. }
  898. #endregion
  899. #region 螺丝供料器
  900. /// <summary>
  901. /// 保存所有螺丝供料器
  902. /// </summary>
  903. async void ExecuteSaveScrewFeedersCommand()
  904. {
  905. var view = new ShowMessage($"AAS", Lang.是否保存螺丝供料器);
  906. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  907. if (result != null && result is bool && (bool)result)
  908. {
  909. if (ScrewFeederList != null)
  910. {
  911. foreach (var item in ScrewFeederList)
  912. {
  913. try
  914. {
  915. _configService.AddOrUpdateScrewFeeder(item);
  916. }
  917. catch (Exception ex)
  918. {
  919. // 记录或通知错误,但继续处理其它项
  920. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  921. }
  922. }
  923. }
  924. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  925. }
  926. }
  927. /// <summary>
  928. /// 移除螺丝供料器
  929. /// </summary>
  930. void ExecuteRemoveScrewFeederCommand()
  931. {
  932. if (SelectScrewFeeder == null) return;
  933. if (MessageBox.Show(Lang.是否移除螺丝供料器, "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  934. {
  935. try
  936. {
  937. var toRemove = ScrewFeederList?.FirstOrDefault(s => s.Id == SelectScrewFeeder.Id);
  938. if (toRemove != null)
  939. {
  940. _configService.RemoveScrewFeeder(toRemove.Id);
  941. // 重新加载列表以保持序号/配置一致(与其他类似实现一致)
  942. var root = _configService.GetAllScrewFeeders();
  943. ScrewFeederList = new ObservableCollection<ScrewFeederInfo>(root);
  944. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  945. }
  946. }
  947. catch (Exception ex)
  948. {
  949. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  950. }
  951. }
  952. }
  953. /// <summary>
  954. /// 添加螺丝供料器
  955. /// </summary>
  956. void ExecuteAddScrewFeederCommand()
  957. {
  958. _dialogService.ShowDialog("AddScrewFeeder", rst =>
  959. {
  960. ButtonResult result1 = rst.Result;
  961. if (result1 == ButtonResult.OK)
  962. {
  963. var param = rst.Parameters.GetValue<ScrewFeederInfo>("ScrewFeeder");
  964. if (param != null)
  965. {
  966. if (ScrewFeederList == null)
  967. {
  968. ScrewFeederList = new ObservableCollection<ScrewFeederInfo>();
  969. }
  970. try
  971. {
  972. param = _configService.AddOrUpdateScrewFeeder(param);
  973. // 直接添加对话框返回的对象(也可以根据需要映射字段)
  974. ScrewFeederList.Add(param);
  975. }
  976. catch (Exception ex)
  977. {
  978. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  979. }
  980. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  981. }
  982. }
  983. });
  984. }
  985. #endregion
  986. #region 通讯
  987. async void ExecuteSaveCommunicateCommand(string parm)
  988. {
  989. if (parm == "TCPIP")
  990. {
  991. var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
  992. //show the dialog
  993. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  994. if (result != null && result is bool)
  995. {
  996. if (((bool)result))
  997. {
  998. _configService.SetBgTcp(BgTcp);
  999. _configService.SaveBgTcp();
  1000. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1001. }
  1002. }
  1003. }
  1004. else if (parm == "ModbusTCP")
  1005. {
  1006. var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
  1007. //show the dialog
  1008. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1009. if (result != null && result is bool)
  1010. {
  1011. if (((bool)result))
  1012. {
  1013. _configService.SetBgModbusTcp(BgModbus);
  1014. _configService.SaveBgModbusTcp();
  1015. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1016. }
  1017. }
  1018. }
  1019. else
  1020. {
  1021. return;
  1022. }
  1023. }
  1024. #endregion
  1025. #region 语言
  1026. void ExecuteSelectLanguageCommand(string language)
  1027. {
  1028. if (string.Equals(language, "ChineseSimplified"))
  1029. {
  1030. CurrentLanguage = Enums.Language.ChineseSimplified;
  1031. _configService.SetCurrentLanguage(CurrentLanguage);
  1032. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1033. }
  1034. else if (string.Equals(language, "ChineseTraditional"))
  1035. {
  1036. CurrentLanguage = Enums.Language.ChineseTraditional;
  1037. _configService.SetCurrentLanguage(CurrentLanguage);
  1038. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1039. }
  1040. else if (string.Equals(language, "English"))
  1041. {
  1042. CurrentLanguage = Enums.Language.English;
  1043. _configService.SetCurrentLanguage(CurrentLanguage);
  1044. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1045. }
  1046. else if (string.Equals(language, "Japanese"))
  1047. {
  1048. CurrentLanguage = Enums.Language.Japanese;
  1049. _configService.SetCurrentLanguage(CurrentLanguage);
  1050. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1051. }
  1052. }
  1053. #endregion
  1054. private void OnLoad()
  1055. {
  1056. }
  1057. private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  1058. {
  1059. switch (e.PropertyName)
  1060. {
  1061. case "Title1":
  1062. Application.Current.Resources["Font.Size.Title1"] = Title1;
  1063. break;
  1064. case "Title2":
  1065. Application.Current.Resources["Font.Size.Title2"] = Title2;
  1066. break;
  1067. case "Title3":
  1068. Application.Current.Resources["Font.Size.Title3"] = Title3;
  1069. break;
  1070. case "Title4":
  1071. Application.Current.Resources["Font.Size.Title4"] = Title4;
  1072. break;
  1073. case "Body1":
  1074. Application.Current.Resources["Font.Size.Body1"] = Body1;
  1075. break;
  1076. case "Body2":
  1077. Application.Current.Resources["Font.Size.Body2"] = Body2;
  1078. break;
  1079. case "Body3":
  1080. Application.Current.Resources["Font.Size.Body3"] = Body3;
  1081. break;
  1082. case "Body4":
  1083. Application.Current.Resources["Font.Size.Body4"] = Body4;
  1084. break;
  1085. case "Captions1":
  1086. Application.Current.Resources["Font.Size.Captions1"] = Captions1;
  1087. break;
  1088. case "Captions2":
  1089. Application.Current.Resources["Font.Size.Captions2"] = Captions2;
  1090. break;
  1091. case "Captions3":
  1092. Application.Current.Resources["Font.Size.Captions3"] = Captions3;
  1093. break;
  1094. case "Captions4":
  1095. Application.Current.Resources["Font.Size.Captions4"] = Captions4;
  1096. break;
  1097. default:
  1098. break;
  1099. }
  1100. }
  1101. #endregion
  1102. #region 继承
  1103. /// <summary>
  1104. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  1105. /// </summary>
  1106. /// <param name="navigationContext"></param>
  1107. /// <param name="continuationCallback"></param>
  1108. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  1109. {
  1110. continuationCallback(true);
  1111. }
  1112. /// <summary>
  1113. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  1114. /// </summary>
  1115. /// <param name="navigationContext"></param>
  1116. /// <exception cref="NotImplementedException"></exception>
  1117. public async void OnNavigatedTo(NavigationContext navigationContext)
  1118. {
  1119. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  1120. {
  1121. IsAllowEdit = false;
  1122. }
  1123. else
  1124. {
  1125. IsAllowEdit = true;
  1126. }
  1127. if (RobotList == null)
  1128. {
  1129. RobotList = new ObservableCollection<RobotInfo>();
  1130. var robots = _configService.GetAllRobots();
  1131. foreach (var robot in robots)
  1132. {
  1133. RobotList.Add(robot);
  1134. }
  1135. }
  1136. if (CameraList == null)
  1137. {
  1138. CameraList = new ObservableCollection<CameraInfo>();
  1139. var cameras = _configService.GetAllCameras();
  1140. foreach (var camera in cameras)
  1141. {
  1142. CameraList.Add(camera);
  1143. }
  1144. }
  1145. if (FeederList == null)
  1146. {
  1147. FeederList = new ObservableCollection<FeederInfo>();
  1148. var feeders = _configService.GetAllFeeders();
  1149. foreach (var feeder in feeders)
  1150. {
  1151. FeederList.Add(feeder);
  1152. }
  1153. }
  1154. if (PlcList == null)
  1155. {
  1156. PlcList = new ObservableCollection<PlcInfo>();
  1157. var plcs = _configService.GetAllPlcs();
  1158. foreach (var plc in plcs)
  1159. {
  1160. PlcList.Add(plc);
  1161. }
  1162. }
  1163. // load light controllers
  1164. if (LightControllerList == null)
  1165. {
  1166. LightControllerList = new ObservableCollection<LightControllerConfig>();
  1167. var controllers = _configService.GetAllLightControllers();
  1168. foreach (var ctrl in controllers)
  1169. {
  1170. LightControllerList.Add(ctrl);
  1171. }
  1172. }
  1173. if (BgTcp == null)
  1174. {
  1175. BgTcp = _configService.GetBgTcp();
  1176. }
  1177. if (BgModbus == null)
  1178. {
  1179. BgModbus = _configService.GetBgModbusTcp();
  1180. }
  1181. if (DeviceInfo == null)
  1182. {
  1183. // load device info
  1184. DeviceInfo = _configService.GetDeviceInfo();
  1185. }
  1186. if (ScrewFeederList==null)
  1187. {
  1188. var screwFeeders = _configService.GetAllScrewFeeders();
  1189. ScrewFeederList = new ObservableCollection<ScrewFeederInfo>(screwFeeders);
  1190. }
  1191. if (CardReaderConfig == null)
  1192. {
  1193. // load card reader config
  1194. CardReaderConfig = _configService.GetCardReaderConfig();
  1195. }
  1196. CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
  1197. // load system parameters into UI
  1198. var sys = _configService.GetSystemConfiguration();
  1199. if (sys != null)
  1200. {
  1201. WorkMode = sys.WorkMode;
  1202. PickPointNum = sys.PickPointNum;
  1203. DowmCameraNum = sys.DowmCameraNum;
  1204. WorkMode = sys.WorkMode;
  1205. PickPointNum = sys.PickPointNum;
  1206. DowmCameraNum = sys.DowmCameraNum;
  1207. UpCameraPickNum = sys.UpCameraPickNum;
  1208. UpCameraPutNum = sys.UpCameraPutNum;
  1209. UPCameracheckNum = sys.UPCameracheckNum;
  1210. FixedCameraPickNum = sys.FixedCameraPickNum;
  1211. FixedCameraPutNum = sys.FixedCameraPutNum;
  1212. FixedCameracheckNum = sys.FixedCameracheckNum;
  1213. ScrewTeachNum = sys.ScrewTeachNum;
  1214. IsSaveScrewCurve= sys.IsSaveScrewCurve;
  1215. ScrewCurvePath= sys.ScrewCurvePath;
  1216. }
  1217. if (isFirstLoad)
  1218. {
  1219. Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
  1220. Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
  1221. Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
  1222. Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
  1223. Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
  1224. Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
  1225. Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
  1226. Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
  1227. Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
  1228. Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
  1229. Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
  1230. Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
  1231. this.PropertyChanged += OnPropertyChanged;
  1232. isFirstLoad = false;
  1233. }
  1234. }
  1235. /// <summary>
  1236. /// 是否允许导航到此视图模型。
  1237. /// </summary>
  1238. /// <param name="navigationContext"></param>
  1239. /// <returns></returns>
  1240. public bool IsNavigationTarget(NavigationContext navigationContext)
  1241. {
  1242. return true;
  1243. }
  1244. /// <summary>
  1245. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1246. /// </summary>
  1247. /// <param name="navigationContext"></param>
  1248. public void OnNavigatedFrom(NavigationContext navigationContext)
  1249. {
  1250. }
  1251. #endregion
  1252. private bool _IsAllowEdit = false;
  1253. public bool IsAllowEdit
  1254. {
  1255. get { return _IsAllowEdit; }
  1256. set { SetProperty(ref _IsAllowEdit, value); }
  1257. }
  1258. private void LoginChange(Models.User user)
  1259. {
  1260. if (user.userPart == Enums.UserPart.Operator)
  1261. {
  1262. IsAllowEdit = false;
  1263. }
  1264. else
  1265. {
  1266. IsAllowEdit = true;
  1267. }
  1268. }
  1269. #region 系统参数
  1270. private Int16 _WorkMode = 0;
  1271. /// <summary>
  1272. /// 工作模式 =1 拍1打1 =2 拍1打所有
  1273. /// </summary>
  1274. public Int16 WorkMode
  1275. {
  1276. get { return _WorkMode; }
  1277. set { SetProperty(ref _WorkMode, value); }
  1278. }
  1279. private Int16 _PickPointNum = 0;
  1280. /// <summary>
  1281. /// 取料位置 =0 不需要取料 =1 需要取料
  1282. /// </summary>
  1283. public Int16 PickPointNum
  1284. {
  1285. get { return _PickPointNum; }
  1286. set { SetProperty(ref _PickPointNum, value); }
  1287. }
  1288. private Int16 _DowmCameraNum = 0;
  1289. /// <summary>
  1290. /// 下相机拍照次数
  1291. /// </summary>
  1292. public Int16 DowmCameraNum
  1293. {
  1294. get => _DowmCameraNum;
  1295. set => SetProperty(ref _DowmCameraNum, value);
  1296. }
  1297. private Int16 _UpCameraPickNum = 0;
  1298. /// <summary>
  1299. /// 上相机取料拍照次数
  1300. /// </summary>
  1301. public Int16 UpCameraPickNum
  1302. {
  1303. get => _UpCameraPickNum;
  1304. set => SetProperty(ref _UpCameraPickNum, value);
  1305. }
  1306. private Int16 _UpCameraPutNum = 0;
  1307. /// <summary>
  1308. /// 上相机放料拍照次数
  1309. /// </summary>
  1310. public Int16 UpCameraPutNum
  1311. {
  1312. get => _UpCameraPutNum;
  1313. set => SetProperty(ref _UpCameraPutNum, value);
  1314. }
  1315. private Int16 _UPCameracheckNum = 0;
  1316. /// <summary>
  1317. /// 上相机锁附/组装次数
  1318. /// </summary>
  1319. public Int16 UPCameracheckNum
  1320. {
  1321. get => _UPCameracheckNum;
  1322. set => SetProperty(ref _UPCameracheckNum, value);
  1323. }
  1324. private Int16 _FixedCameraPickNum = 0;
  1325. /// <summary>
  1326. /// 取料固定位置拍产品相机数量
  1327. /// </summary>
  1328. public Int16 FixedCameraPickNum
  1329. {
  1330. get => _FixedCameraPickNum;
  1331. set => SetProperty(ref _FixedCameraPickNum, value);
  1332. }
  1333. private Int16 _FixedCameraPutNum = 0;
  1334. /// <summary>
  1335. /// 锁附/组装固定位置拍产品相机数量
  1336. /// </summary>
  1337. public Int16 FixedCameraPutNum
  1338. {
  1339. get => _FixedCameraPutNum;
  1340. set => SetProperty(ref _FixedCameraPutNum, value);
  1341. }
  1342. private Int16 _FixedCameracheckNum = 0;
  1343. /// <summary>
  1344. /// 固定相机检测锁附/组装次数
  1345. /// </summary>
  1346. public Int16 FixedCameracheckNum
  1347. {
  1348. get => _FixedCameracheckNum;
  1349. set => SetProperty(ref _FixedCameracheckNum, value);
  1350. }
  1351. private Int16 _ScrewTeachNum = 0;
  1352. /// <summary>
  1353. /// 披头矫正的模式,1:初始化时矫正,2:每个产品矫正一次,3:每颗螺丝矫正一次
  1354. /// </summary>
  1355. public Int16 ScrewTeachNum
  1356. {
  1357. get => _ScrewTeachNum;
  1358. set => SetProperty(ref _ScrewTeachNum, value);
  1359. }
  1360. private bool _IsSaveScrewCurve;
  1361. /// <summary>
  1362. /// 是否保存锁付曲线图
  1363. /// </summary>
  1364. public bool IsSaveScrewCurve
  1365. {
  1366. get { return _IsSaveScrewCurve; }
  1367. set { SetProperty(ref _IsSaveScrewCurve, value); }
  1368. }
  1369. private string _ScrewCurvePath;
  1370. /// <summary>
  1371. /// 锁付曲线图保存路径
  1372. /// </summary>
  1373. public string ScrewCurvePath
  1374. {
  1375. get { return _ScrewCurvePath; }
  1376. set { SetProperty(ref _ScrewCurvePath, value); }
  1377. }
  1378. /// <summary>
  1379. /// 选择锁付曲线图保存路径
  1380. /// </summary>
  1381. void ExecuteBrowseScrewCurvePathCommand()
  1382. {
  1383. try
  1384. {
  1385. using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
  1386. {
  1387. dlg.Description = "选择锁付曲线图保存路径";
  1388. dlg.ShowNewFolderButton = true;
  1389. if (!string.IsNullOrEmpty(ScrewCurvePath)) dlg.SelectedPath = ScrewCurvePath;
  1390. var result = dlg.ShowDialog();
  1391. if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
  1392. {
  1393. ScrewCurvePath = dlg.SelectedPath;
  1394. }
  1395. }
  1396. }
  1397. catch (Exception ex)
  1398. {
  1399. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 2 });
  1400. }
  1401. }
  1402. /// <summary>
  1403. /// 保存系统参数
  1404. /// </summary>
  1405. async void ExecuteSaveSystemParametersCommand()
  1406. {
  1407. var view = new ShowMessage($"AAS", Lang.是否保存系统参数);
  1408. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1409. if (result != null && result is bool && (bool)result)
  1410. {
  1411. try
  1412. {
  1413. var sysConfig = _configService.GetSystemConfiguration();
  1414. sysConfig.WorkMode = WorkMode;
  1415. sysConfig.PickPointNum = PickPointNum;
  1416. sysConfig.DowmCameraNum = DowmCameraNum;
  1417. sysConfig.UpCameraPickNum = UpCameraPickNum;
  1418. sysConfig.UpCameraPutNum = UpCameraPutNum;
  1419. sysConfig.UPCameracheckNum = UPCameracheckNum;
  1420. sysConfig.FixedCameraPickNum = FixedCameraPickNum;
  1421. sysConfig.FixedCameraPutNum = FixedCameraPutNum;
  1422. sysConfig.FixedCameracheckNum = FixedCameracheckNum;
  1423. sysConfig.ScrewTeachNum = ScrewTeachNum;
  1424. sysConfig.IsSaveScrewCurve = IsSaveScrewCurve;
  1425. sysConfig.ScrewCurvePath = ScrewCurvePath;
  1426. _configService.SaveSystemConfiguration(sysConfig);
  1427. await management.WriteSystemParameterToPlcAsync(sysConfig);
  1428. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1429. }
  1430. catch (Exception ex)
  1431. {
  1432. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1433. }
  1434. }
  1435. }
  1436. /// <summary>
  1437. /// 保存读卡器配置
  1438. /// </summary>
  1439. void ExecuteSaveCardReaderConfigCommand()
  1440. {
  1441. try
  1442. {
  1443. _configService.SaveCardReaderConfig(CardReaderConfig);
  1444. }
  1445. catch (Exception ex)
  1446. {
  1447. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1448. }
  1449. }
  1450. #endregion
  1451. #region 设备信息
  1452. /// <summary>
  1453. /// 保存设备信息
  1454. /// </summary>
  1455. void ExecuteSaveDeviceInfoCommand()
  1456. {
  1457. try
  1458. {
  1459. if (DeviceInfo != null)
  1460. {
  1461. _configService.SaveDeviceInfo(DeviceInfo);
  1462. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1463. }
  1464. }
  1465. catch (Exception ex)
  1466. {
  1467. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1468. }
  1469. }
  1470. #endregion
  1471. }
  1472. }