SettingViewModel.cs 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  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. #endregion
  287. #region 命令
  288. public DelegateCommand LoadedCommand { get; set; }
  289. private DelegateCommand _SaveSystemParametersCommand;
  290. public DelegateCommand SaveSystemParametersCommand =>
  291. _SaveSystemParametersCommand ?? (_SaveSystemParametersCommand = new DelegateCommand(ExecuteSaveSystemParametersCommand));
  292. private DelegateCommand _AddRobotCommand;
  293. public DelegateCommand AddRobotCommand =>
  294. _AddRobotCommand ?? (_AddRobotCommand = new DelegateCommand(ExecuteAddRobotCommand));
  295. private DelegateCommand _RemoveCommand;
  296. public DelegateCommand RemoveCommand =>
  297. _RemoveCommand ?? (_RemoveCommand = new DelegateCommand(ExecuteRemoveCommand));
  298. private DelegateCommand _AddFeederCommand;
  299. public DelegateCommand AddFeederCommand =>
  300. _AddFeederCommand ?? (_AddFeederCommand = new DelegateCommand(ExecuteAddFeederCommand));
  301. private DelegateCommand _RemoveFeederCommand;
  302. public DelegateCommand RemoveFeederCommand =>
  303. _RemoveFeederCommand ?? (_RemoveFeederCommand = new DelegateCommand(ExecuteRemoveFeederCommand));
  304. private DelegateCommand<string> _SelectLanguageCommand;
  305. public DelegateCommand<string> SelectLanguageCommand =>
  306. _SelectLanguageCommand ?? (_SelectLanguageCommand = new DelegateCommand<string>(ExecuteSelectLanguageCommand));
  307. private DelegateCommand _SaveRobotsCommand;
  308. public DelegateCommand SaveRobotsCommand =>
  309. _SaveRobotsCommand ?? (_SaveRobotsCommand = new DelegateCommand(ExecuteSaveRobotsCommand));
  310. private DelegateCommand _SaveFeedersCommand;
  311. public DelegateCommand SaveFeedersCommand =>
  312. _SaveFeedersCommand ?? (_SaveFeedersCommand = new DelegateCommand(ExecuteSaveFeedersCommand));
  313. private DelegateCommand<string> _SaveCommunicateCommand;
  314. public DelegateCommand<string> SaveCommunicateCommand =>
  315. _SaveCommunicateCommand ?? (_SaveCommunicateCommand = new DelegateCommand<string>(ExecuteSaveCommunicateCommand));
  316. private DelegateCommand _AddCameraCommand;
  317. public DelegateCommand AddCameraCommand =>
  318. _AddCameraCommand ?? (_AddCameraCommand = new DelegateCommand(ExecuteAddCameraCommand));
  319. private DelegateCommand _EditCameraCommand;
  320. public DelegateCommand EditCameraCommand =>
  321. _EditCameraCommand ?? (_EditCameraCommand = new DelegateCommand(ExecuteEditCameraCommand));
  322. private DelegateCommand _RemoveCameraCommand;
  323. public DelegateCommand RemoveCameraCommand =>
  324. _RemoveCameraCommand ?? (_RemoveCameraCommand = new DelegateCommand(ExecuteRemoveCameraCommand));
  325. private DelegateCommand _SaveCamerasCommand;
  326. public DelegateCommand SaveCamerasCommand =>
  327. _SaveCamerasCommand ?? (_SaveCamerasCommand = new DelegateCommand(ExecuteSaveCamerasCommand));
  328. private DelegateCommand _AddPlcCommand;
  329. public DelegateCommand AddPlcCommand =>
  330. _AddPlcCommand ?? (_AddPlcCommand = new DelegateCommand(ExecuteAddPlcCommand));
  331. private DelegateCommand _RemovePlcCommand;
  332. public DelegateCommand RemovePlcCommand =>
  333. _RemovePlcCommand ?? (_RemovePlcCommand = new DelegateCommand(ExecuteRemovePlcCommand));
  334. private DelegateCommand _SavePlcsCommand;
  335. public DelegateCommand SavePlcsCommand =>
  336. _SavePlcsCommand ?? (_SavePlcsCommand = new DelegateCommand(ExecuteSavePlcsCommand));
  337. private DelegateCommand _AddLightControllerCommand;
  338. public DelegateCommand AddLightControllerCommand => _AddLightControllerCommand ?? (_AddLightControllerCommand = new DelegateCommand(ExecuteAddLightControllerCommand));
  339. private DelegateCommand _RemoveLightControllerCommand;
  340. public DelegateCommand RemoveLightControllerCommand => _RemoveLightControllerCommand ?? (_RemoveLightControllerCommand = new DelegateCommand(ExecuteRemoveLightControllerCommand));
  341. private DelegateCommand _SaveLightControllersCommand;
  342. public DelegateCommand SaveLightControllersCommand => _SaveLightControllersCommand ?? (_SaveLightControllersCommand = new DelegateCommand(ExecuteSaveLightControllersCommand));
  343. private DelegateCommand _SaveDeviceInfoCommand;
  344. public DelegateCommand SaveDeviceInfoCommand => _SaveDeviceInfoCommand ?? (_SaveDeviceInfoCommand = new DelegateCommand(ExecuteSaveDeviceInfoCommand));
  345. private DelegateCommand _AddScrewFeederCommand;
  346. public DelegateCommand AddScrewFeederCommand =>
  347. _AddScrewFeederCommand ?? (_AddScrewFeederCommand = new DelegateCommand(ExecuteAddScrewFeederCommand));
  348. private DelegateCommand _RemoveScrewFeederCommand;
  349. public DelegateCommand RemoveScrewFeederCommand =>
  350. _RemoveScrewFeederCommand ?? (_RemoveScrewFeederCommand = new DelegateCommand(ExecuteRemoveScrewFeederCommand));
  351. private DelegateCommand _SaveScrewFeedersCommand;
  352. public DelegateCommand SaveScrewFeedersCommand =>
  353. _SaveScrewFeedersCommand ?? (_SaveScrewFeedersCommand = new DelegateCommand(ExecuteSaveScrewFeedersCommand));
  354. #endregion
  355. #region 事件
  356. #endregion
  357. public SettingViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  358. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService,
  359. IProductService productService, ISystemDatabaseService systemDatabaseService)
  360. {
  361. _regionManager = regionManager;
  362. _eventAggregator = ea;
  363. _container = container;
  364. _dialogService = dialogService;
  365. _configService = configService;
  366. _robotService = robotService;
  367. _cameraService = cameraService;
  368. _feederService = feederService;
  369. _plcService = plcService;
  370. _productService = productService;
  371. _systemDatabaseService = systemDatabaseService;
  372. management = _container.Resolve<Management>();
  373. LoadedCommand = new DelegateCommand(OnLoad);
  374. //订阅权限登录事件
  375. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  376. }
  377. #region 方法
  378. #region 机器人
  379. private void ExecuteAddRobotCommand()
  380. {
  381. _dialogService.ShowDialog("AddRobot", rst =>
  382. {
  383. //对话框关闭之后的回调函数,可以在这解析结果。
  384. ButtonResult result1 = rst.Result;
  385. if (result1 == ButtonResult.OK)
  386. {
  387. var param = rst.Parameters.GetValue<RobotInfo>("Robot");
  388. var robot = new RobotInfo()
  389. {
  390. Id = param.Id,
  391. RobotName = param.RobotName,
  392. ConnectType = param.ConnectType,
  393. RobotBrand = param.RobotBrand,
  394. IP = param.IP,
  395. Port = param.Port,
  396. Terminator = param.Terminator,
  397. };
  398. RobotList.Add(robot);
  399. _configService.AddOrUpdateRobot(robot);
  400. _robotService.CreateRobot(robot.Id, robot);
  401. //对所有产品也进行添加
  402. _productService.AddRobotPointToProduct(robot.Id, robot.RobotName);
  403. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
  404. }
  405. });
  406. }
  407. void ExecuteRemoveCommand()
  408. {
  409. if (MessageBox.Show(Lang.是否移除机器人, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  410. {
  411. // 找到要删除的机器人
  412. var robotToRemove = RobotList.FirstOrDefault(r => r.Id == SelectRobot.Id);
  413. if (robotToRemove != null)
  414. {
  415. RobotList.Remove(robotToRemove);
  416. _configService.RemoveRobot(robotToRemove.Id);
  417. _robotService.RemoveRobot(robotToRemove.Id);
  418. //对所有产品也进行移除
  419. _productService.RemoveRobotPointFromProduct(robotToRemove.Id);
  420. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  421. }
  422. }
  423. }
  424. async void ExecuteSaveRobotsCommand()
  425. {
  426. var view = new ShowMessage($"AAS", Lang.是否保存机器人);
  427. //show the dialog
  428. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  429. if (result != null && result is bool)
  430. {
  431. if (((bool)result))
  432. {
  433. foreach (var item in RobotList)
  434. {
  435. var robot = _robotService.GetRobot(item.Id);
  436. if (robot != null)
  437. {
  438. //更新连接参数
  439. robot.SafeZ=item.SafeZ;
  440. }
  441. _configService.AddOrUpdateRobot(item);
  442. }
  443. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  444. }
  445. }
  446. }
  447. #endregion
  448. #region 相机
  449. /// <summary>
  450. /// 保存所有相机
  451. /// </summary>
  452. async void ExecuteSaveCamerasCommand()
  453. {
  454. var view = new ShowMessage($"AAS", Lang.是否保存相机配置);
  455. //show the dialog
  456. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  457. if (result != null && result is bool)
  458. {
  459. if (((bool)result))
  460. {
  461. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  462. //management.SaveCamerasDeviceConfig();
  463. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  464. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  465. }
  466. }
  467. }
  468. /// <summary>
  469. /// 移除相机
  470. /// </summary>
  471. void ExecuteRemoveCameraCommand()
  472. {
  473. if (MessageBox.Show(Lang.是否移除相机, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  474. {
  475. // 找到要删除的相机
  476. var cameraToRemove = CameraList.FirstOrDefault(r => r.Id == SelectCamera.Id);
  477. if (cameraToRemove != null)
  478. {
  479. _configService.RemoveCamera(cameraToRemove.Id);
  480. _cameraService.RemoveCamera(cameraToRemove.Id);
  481. var root = _configService.GetAllCameras();
  482. CameraList = new ObservableCollection<CameraInfo>(root);
  483. foreach (var item in CameraList)
  484. {
  485. _cameraService.UpdateCameraNumber(item.Id, item.CameraNo);
  486. }
  487. //对所有产品也进行移除
  488. _productService.RemoveCameraFromProduct(cameraToRemove.Id);
  489. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  490. }
  491. }
  492. }
  493. /// <summary>
  494. /// 编辑相机
  495. /// </summary>
  496. void ExecuteEditCameraCommand()
  497. {
  498. if (SelectCamera == null) return;
  499. bool isSelectedCameraBrandSucced = false;
  500. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  501. IDialogParameters parameters1 = new DialogParameters();
  502. parameters1.Add("CameraBrand", SelectCamera.CameraBrand);
  503. _dialogService.ShowDialog("SelectCameraBrand", parameters1, rst =>
  504. {
  505. if (rst.Result == ButtonResult.OK)
  506. {
  507. isSelectedCameraBrandSucced = true;
  508. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  509. }
  510. else
  511. {
  512. return;
  513. }
  514. });
  515. if (!isSelectedCameraBrandSucced) { return; }
  516. (bool isInstalled, string version) result = (false, "");
  517. string softwarename = "";
  518. switch (cameraBrand)
  519. {
  520. case CameraBrand.HikRobot_MVS:
  521. softwarename = "MVS";
  522. result = MvCamera.CheckSoftwareInstalled();
  523. break;
  524. case CameraBrand.Basler_Pylon:
  525. softwarename = "Pylon 7";
  526. result = BaslerCamera.CheckSoftwareInstalled();
  527. break;
  528. case CameraBrand.IRayple:
  529. softwarename = "MV Viewer";
  530. result = AHuaCamera.CheckSoftwareInstalled();
  531. break;
  532. case CameraBrand.Cognex:
  533. softwarename = "Cognex VisionPro";
  534. result = CognexCamera.CheckSoftwareInstalled();
  535. break;
  536. case CameraBrand.Galaxy:
  537. softwarename = "Galaxy Viewer";
  538. result = GalaxyCamera.CheckSoftwareInstalled();
  539. break;
  540. case CameraBrand.Opt:
  541. softwarename = "OPT Camera Viewer";
  542. result = OptCamera.CheckSoftwareInstalled();
  543. break;
  544. default:
  545. break;
  546. }
  547. if (!result.isInstalled)
  548. {
  549. if (string.IsNullOrEmpty(result.version))
  550. {
  551. //未安装
  552. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  553. }
  554. else
  555. {
  556. //版本较低
  557. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  558. }
  559. return;
  560. }
  561. //编辑前的相机名称
  562. string oldCameraName = SelectCamera.CameraName;
  563. IDialogParameters parameters = new DialogParameters();
  564. parameters.Add("CameraBrand", cameraBrand);
  565. parameters.Add("Camera", SelectCamera.Copy());
  566. _dialogService.ShowDialog("EditCamera", parameters, rst =>
  567. {
  568. //对话框关闭之后的回调函数,可以在这解析结果。
  569. ButtonResult result1 = rst.Result;
  570. if (result1 == ButtonResult.OK)
  571. {
  572. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  573. SelectCamera.CameraName = param.CameraName;
  574. SelectCamera.SerialNumber = param.SerialNumber;
  575. SelectCamera.Model = param.Model;
  576. SelectCamera.ManufacturerName = param.ManufacturerName;
  577. SelectCamera.CameraType = param.CameraType;
  578. SelectCamera.CameraBrand = param.CameraBrand;
  579. SelectCamera.CameraIp = param.CameraIp;
  580. _configService.AddOrUpdateCamera(SelectCamera);
  581. if (oldCameraName != param.CameraName)
  582. {
  583. //对所有产品也进行修改
  584. _productService.UpdateCameraNameInProduct(SelectCamera.Id, SelectCamera.CameraName);
  585. }
  586. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  587. }
  588. });
  589. }
  590. /// <summary>
  591. /// 增加相机
  592. /// </summary>
  593. void ExecuteAddCameraCommand()
  594. {
  595. bool isSelectedCameraBrandSucced = false;
  596. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  597. _dialogService.ShowDialog("SelectCameraBrand", rst =>
  598. {
  599. if (rst.Result == ButtonResult.OK)
  600. {
  601. isSelectedCameraBrandSucced = true;
  602. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  603. }
  604. else
  605. {
  606. return;
  607. }
  608. });
  609. if (!isSelectedCameraBrandSucced) { return; }
  610. ;
  611. (bool isInstalled, string version) result = (false, "");
  612. string softwarename = "";
  613. switch (cameraBrand)
  614. {
  615. case CameraBrand.HikRobot_MVS:
  616. softwarename = "MVS";
  617. result = MvCamera.CheckSoftwareInstalled();
  618. break;
  619. case CameraBrand.Basler_Pylon:
  620. softwarename = "Pylon 7";
  621. result = BaslerCamera.CheckSoftwareInstalled();
  622. break;
  623. case CameraBrand.IRayple:
  624. softwarename = "MV Viewer";
  625. result = AHuaCamera.CheckSoftwareInstalled();
  626. break;
  627. case CameraBrand.Cognex:
  628. softwarename = "Cognex VisionPro";
  629. result = CognexCamera.CheckSoftwareInstalled();
  630. break;
  631. case CameraBrand.Galaxy:
  632. softwarename = "Galaxy Viewer";
  633. result = GalaxyCamera.CheckSoftwareInstalled();
  634. break;
  635. case CameraBrand.Opt:
  636. softwarename = "OPT Camera Viewer";
  637. result = OptCamera.CheckSoftwareInstalled();
  638. break;
  639. default:
  640. break;
  641. }
  642. if (!result.isInstalled)
  643. {
  644. if (string.IsNullOrEmpty(result.version))
  645. {
  646. //未安装
  647. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  648. }
  649. else
  650. {
  651. //版本较低
  652. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  653. }
  654. return;
  655. }
  656. IDialogParameters parameters = new DialogParameters();
  657. parameters.Add("CameraBrand", cameraBrand);
  658. _dialogService.ShowDialog("AddCamera", parameters, rst =>
  659. {
  660. //对话框关闭之后的回调函数,可以在这解析结果。
  661. ButtonResult result1 = rst.Result;
  662. if (result1 == ButtonResult.OK)
  663. {
  664. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  665. var camera = new CameraInfo()
  666. {
  667. Id = param.Id,
  668. CameraName = param.CameraName,
  669. SerialNumber = param.SerialNumber,
  670. Model = param.Model,
  671. ManufacturerName = param.ManufacturerName,
  672. CameraType = param.CameraType,
  673. CameraBrand = param.CameraBrand,
  674. CameraIp = param.CameraIp
  675. };
  676. CameraList.Add(camera);
  677. _configService.AddOrUpdateCamera(camera);
  678. _cameraService.CreateCamera(camera.Id, camera);
  679. //对所有产品也进行添加
  680. _productService.AddCameraToProduct(camera.Id, camera.CameraName);
  681. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  682. }
  683. });
  684. }
  685. #endregion
  686. #region Feeder
  687. void ExecuteAddFeederCommand()
  688. {
  689. _dialogService.ShowDialog("AddFeeder", rst =>
  690. {
  691. //对话框关闭之后的回调函数,可以在这解析结果。
  692. ButtonResult result1 = rst.Result;
  693. if (result1 == ButtonResult.OK)
  694. {
  695. var param = rst.Parameters.GetValue<FeederInfo>("Feeder");
  696. var feeder = new FeederInfo()
  697. {
  698. Id = param.Id,
  699. FeederName = param.FeederName,
  700. ConnectType = param.ConnectType,
  701. FeederBrand = param.FeederBrand,
  702. IP = param.IP,
  703. Port = param.Port
  704. };
  705. FeederList.Add(feeder);
  706. _configService.AddOrUpdateFeeder(feeder);
  707. _feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
  708. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  709. }
  710. });
  711. }
  712. void ExecuteRemoveFeederCommand()
  713. {
  714. if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  715. {
  716. // 找到要删除的机器人
  717. var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
  718. if (feederToRemove != null)
  719. {
  720. _configService.RemoveFeeder(feederToRemove.Id);
  721. _feederService.RemoveFeeder(feederToRemove.Id);
  722. var root = _configService.GetAllFeeders();
  723. FeederList = new ObservableCollection<FeederInfo>(root);
  724. foreach (var item in FeederList)
  725. {
  726. _feederService.UpdateFeederNo(item.Id, item.FeederNo);
  727. }
  728. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  729. }
  730. }
  731. }
  732. async void ExecuteSaveFeedersCommand()
  733. {
  734. var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
  735. //show the dialog
  736. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  737. if (result != null && result is bool)
  738. {
  739. if (((bool)result))
  740. {
  741. foreach (var item in FeederList)
  742. {
  743. _configService.AddOrUpdateFeeder(item);
  744. }
  745. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  746. }
  747. }
  748. }
  749. #endregion
  750. #region PLC
  751. /// <summary>
  752. /// 保存PLC
  753. /// </summary>
  754. async void ExecuteSavePlcsCommand()
  755. {
  756. var view = new ShowMessage($"AAS", Lang.是否保存PLC);
  757. //show the dialog
  758. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  759. if (result != null && result is bool)
  760. {
  761. if (((bool)result))
  762. {
  763. foreach (var item in PlcList)
  764. {
  765. _configService.AddOrUpdatePlc(item);
  766. }
  767. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  768. }
  769. }
  770. }
  771. /// <summary>
  772. /// 移除PLC
  773. /// </summary>
  774. void ExecuteRemovePlcCommand()
  775. {
  776. if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  777. {
  778. // 找到要删除的plc
  779. var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
  780. if (plcToRemove != null)
  781. {
  782. _configService.RemovePlc(plcToRemove.Id);
  783. _plcService.RemovePlc(plcToRemove.Id);
  784. var root = _configService.GetAllPlcs();
  785. PlcList = new ObservableCollection<PlcInfo>(root);
  786. foreach (var item in PlcList)
  787. {
  788. _plcService.UpdatePlcNumber(item.Id, item.Index);
  789. }
  790. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  791. }
  792. }
  793. }
  794. /// <summary>
  795. /// 增加PLC
  796. /// </summary>
  797. void ExecuteAddPlcCommand()
  798. {
  799. _dialogService.ShowDialog("AddPlc", rst =>
  800. {
  801. //对话框关闭之后的回调函数,可以在这解析结果。
  802. ButtonResult result1 = rst.Result;
  803. if (result1 == ButtonResult.OK)
  804. {
  805. var param = rst.Parameters.GetValue<PlcInfo>("PLC");
  806. var plc = new PlcInfo()
  807. {
  808. Id = param.Id,
  809. Name = param.Name,
  810. CommunicationType = param.CommunicationType,
  811. EndpointUrl = param.EndpointUrl,
  812. };
  813. PlcList.Add(plc);
  814. _configService.AddOrUpdatePlc(plc);
  815. _plcService.CreatePlc(plc.Id, plc);
  816. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  817. }
  818. });
  819. }
  820. #endregion
  821. #region Light handlers
  822. void ExecuteAddLightControllerCommand()
  823. {
  824. // open dialog to add light controller (similar to robots)
  825. _dialogService.ShowDialog("AddLightController", rst =>
  826. {
  827. if (rst.Result == ButtonResult.OK)
  828. {
  829. var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
  830. // assign id and defaults if needed
  831. if (param.Id == 0)
  832. param.Id = (LightControllerList?.Count ?? 0) + 1;
  833. LightControllerList.Add(param);
  834. _configService.AddOrUpdateLightController(param);
  835. SelectLightController = param;
  836. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  837. }
  838. });
  839. }
  840. void ExecuteRemoveLightControllerCommand()
  841. {
  842. if (SelectLightController == null) return;
  843. if (MessageBox.Show(Lang.是否移除光源控制器, "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  844. {
  845. _configService.RemoveLightController(SelectLightController.Id);
  846. LightControllerList.Remove(SelectLightController);
  847. SelectLightController = null;
  848. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  849. }
  850. }
  851. async void ExecuteSaveLightControllersCommand()
  852. {
  853. var view = new ShowMessage($"AAS", Lang.是否保存光源控制器配置);
  854. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  855. if (result != null && result is bool && (bool)result)
  856. {
  857. foreach (var item in LightControllerList)
  858. {
  859. _configService.AddOrUpdateLightController(item);
  860. }
  861. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  862. }
  863. }
  864. #endregion
  865. #region 螺丝供料器
  866. /// <summary>
  867. /// 保存所有螺丝供料器
  868. /// </summary>
  869. async void ExecuteSaveScrewFeedersCommand()
  870. {
  871. var view = new ShowMessage($"AAS", Lang.是否保存螺丝供料器);
  872. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  873. if (result != null && result is bool && (bool)result)
  874. {
  875. if (ScrewFeederList != null)
  876. {
  877. foreach (var item in ScrewFeederList)
  878. {
  879. try
  880. {
  881. _configService.AddOrUpdateScrewFeeder(item);
  882. }
  883. catch (Exception ex)
  884. {
  885. // 记录或通知错误,但继续处理其它项
  886. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  887. }
  888. }
  889. }
  890. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  891. }
  892. }
  893. /// <summary>
  894. /// 移除螺丝供料器
  895. /// </summary>
  896. void ExecuteRemoveScrewFeederCommand()
  897. {
  898. if (SelectScrewFeeder == null) return;
  899. if (MessageBox.Show(Lang.是否移除螺丝供料器, "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  900. {
  901. try
  902. {
  903. var toRemove = ScrewFeederList?.FirstOrDefault(s => s.Id == SelectScrewFeeder.Id);
  904. if (toRemove != null)
  905. {
  906. _configService.RemoveScrewFeeder(toRemove.Id);
  907. // 重新加载列表以保持序号/配置一致(与其他类似实现一致)
  908. var root = _configService.GetAllScrewFeeders();
  909. ScrewFeederList = new ObservableCollection<ScrewFeederInfo>(root);
  910. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  911. }
  912. }
  913. catch (Exception ex)
  914. {
  915. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  916. }
  917. }
  918. }
  919. /// <summary>
  920. /// 添加螺丝供料器
  921. /// </summary>
  922. void ExecuteAddScrewFeederCommand()
  923. {
  924. _dialogService.ShowDialog("AddScrewFeeder", rst =>
  925. {
  926. ButtonResult result1 = rst.Result;
  927. if (result1 == ButtonResult.OK)
  928. {
  929. var param = rst.Parameters.GetValue<ScrewFeederInfo>("ScrewFeeder");
  930. if (param != null)
  931. {
  932. if (ScrewFeederList == null)
  933. {
  934. ScrewFeederList = new ObservableCollection<ScrewFeederInfo>();
  935. }
  936. try
  937. {
  938. param = _configService.AddOrUpdateScrewFeeder(param);
  939. // 直接添加对话框返回的对象(也可以根据需要映射字段)
  940. ScrewFeederList.Add(param);
  941. }
  942. catch (Exception ex)
  943. {
  944. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  945. }
  946. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  947. }
  948. }
  949. });
  950. }
  951. #endregion
  952. #region 通讯
  953. async void ExecuteSaveCommunicateCommand(string parm)
  954. {
  955. if (parm == "TCPIP")
  956. {
  957. var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
  958. //show the dialog
  959. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  960. if (result != null && result is bool)
  961. {
  962. if (((bool)result))
  963. {
  964. _configService.SetBgTcp(BgTcp);
  965. _configService.SaveBgTcp();
  966. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  967. }
  968. }
  969. }
  970. else if (parm == "ModbusTCP")
  971. {
  972. var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
  973. //show the dialog
  974. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  975. if (result != null && result is bool)
  976. {
  977. if (((bool)result))
  978. {
  979. _configService.SetBgModbusTcp(BgModbus);
  980. _configService.SaveBgModbusTcp();
  981. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  982. }
  983. }
  984. }
  985. else
  986. {
  987. return;
  988. }
  989. }
  990. #endregion
  991. #region 语言
  992. void ExecuteSelectLanguageCommand(string language)
  993. {
  994. if (string.Equals(language, "ChineseSimplified"))
  995. {
  996. CurrentLanguage = Enums.Language.ChineseSimplified;
  997. var sysConfig = _configService.GetSystemConfiguration();
  998. sysConfig.CurrentLanguage = CurrentLanguage;
  999. _configService.SaveSystemConfiguration(sysConfig);
  1000. var culture = new CultureInfo("zh-CN");
  1001. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1002. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1003. LocalizeDictionary.Instance.Culture = culture;
  1004. Lang.Culture = culture;
  1005. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  1006. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1007. }
  1008. else if (string.Equals(language, "ChineseTraditional"))
  1009. {
  1010. CurrentLanguage = Enums.Language.ChineseTraditional;
  1011. var sysConfig = _configService.GetSystemConfiguration();
  1012. sysConfig.CurrentLanguage = CurrentLanguage;
  1013. _configService.SaveSystemConfiguration(sysConfig);
  1014. var culture = new CultureInfo("zh-TW");
  1015. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1016. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1017. LocalizeDictionary.Instance.Culture = culture;
  1018. Lang.Culture = culture;
  1019. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  1020. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1021. }
  1022. else if (string.Equals(language, "English"))
  1023. {
  1024. CurrentLanguage = Enums.Language.English;
  1025. var sysConfig = _configService.GetSystemConfiguration();
  1026. sysConfig.CurrentLanguage = CurrentLanguage;
  1027. _configService.SaveSystemConfiguration(sysConfig);
  1028. var culture = new CultureInfo("en");
  1029. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1030. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1031. LocalizeDictionary.Instance.Culture = culture;
  1032. Lang.Culture = culture;
  1033. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  1034. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1035. }
  1036. else if (string.Equals(language, "Japanese"))
  1037. {
  1038. CurrentLanguage = Enums.Language.Japanese;
  1039. var sysConfig = _configService.GetSystemConfiguration();
  1040. sysConfig.CurrentLanguage = CurrentLanguage;
  1041. _configService.SaveSystemConfiguration(sysConfig);
  1042. var culture = new CultureInfo("ja-JP");
  1043. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1044. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1045. LocalizeDictionary.Instance.Culture = culture;
  1046. Lang.Culture = culture;
  1047. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  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. CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
  1185. // load system parameters into UI
  1186. var sys = _configService.GetSystemConfiguration();
  1187. if (sys != null)
  1188. {
  1189. WorkMode = sys.WorkMode;
  1190. PickPointNum = sys.PickPointNum;
  1191. DowmCameraNum = sys.DowmCameraNum;
  1192. WorkMode = sys.WorkMode;
  1193. PickPointNum = sys.PickPointNum;
  1194. DowmCameraNum = sys.DowmCameraNum;
  1195. UpCameraPickNum = sys.UpCameraPickNum;
  1196. UpCameraPutNum = sys.UpCameraPutNum;
  1197. UPCameracheckNum = sys.UPCameracheckNum;
  1198. FixedCameraPickNum = sys.FixedCameraPickNum;
  1199. FixedCameraPutNum = sys.FixedCameraPutNum;
  1200. FixedCameracheckNum = sys.FixedCameracheckNum;
  1201. ScrewTeachNum = sys.ScrewTeachNum;
  1202. }
  1203. if (isFirstLoad)
  1204. {
  1205. Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
  1206. Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
  1207. Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
  1208. Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
  1209. Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
  1210. Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
  1211. Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
  1212. Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
  1213. Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
  1214. Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
  1215. Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
  1216. Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
  1217. this.PropertyChanged += OnPropertyChanged;
  1218. isFirstLoad = false;
  1219. }
  1220. }
  1221. /// <summary>
  1222. /// 是否允许导航到此视图模型。
  1223. /// </summary>
  1224. /// <param name="navigationContext"></param>
  1225. /// <returns></returns>
  1226. public bool IsNavigationTarget(NavigationContext navigationContext)
  1227. {
  1228. return true;
  1229. }
  1230. /// <summary>
  1231. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1232. /// </summary>
  1233. /// <param name="navigationContext"></param>
  1234. public void OnNavigatedFrom(NavigationContext navigationContext)
  1235. {
  1236. }
  1237. #endregion
  1238. private bool _IsAllowEdit = false;
  1239. public bool IsAllowEdit
  1240. {
  1241. get { return _IsAllowEdit; }
  1242. set { SetProperty(ref _IsAllowEdit, value); }
  1243. }
  1244. private void LoginChange(Models.User user)
  1245. {
  1246. if (user.userPart == Enums.UserPart.Operator)
  1247. {
  1248. IsAllowEdit = false;
  1249. }
  1250. else
  1251. {
  1252. IsAllowEdit = true;
  1253. }
  1254. }
  1255. #region 系统参数
  1256. private Int16 _WorkMode = 0;
  1257. /// <summary>
  1258. /// 工作模式 =1 拍1打1 =2 拍1打所有
  1259. /// </summary>
  1260. public Int16 WorkMode
  1261. {
  1262. get { return _WorkMode; }
  1263. set { SetProperty(ref _WorkMode, value); }
  1264. }
  1265. private Int16 _PickPointNum = 0;
  1266. /// <summary>
  1267. /// 取料位置 =0 不需要取料 =1 需要取料
  1268. /// </summary>
  1269. public Int16 PickPointNum
  1270. {
  1271. get { return _PickPointNum; }
  1272. set { SetProperty(ref _PickPointNum, value); }
  1273. }
  1274. private Int16 _DowmCameraNum = 0;
  1275. /// <summary>
  1276. /// 下相机拍照次数
  1277. /// </summary>
  1278. public Int16 DowmCameraNum
  1279. {
  1280. get => _DowmCameraNum;
  1281. set => SetProperty(ref _DowmCameraNum, value);
  1282. }
  1283. private Int16 _UpCameraPickNum = 0;
  1284. /// <summary>
  1285. /// 上相机取料拍照次数
  1286. /// </summary>
  1287. public Int16 UpCameraPickNum
  1288. {
  1289. get => _UpCameraPickNum;
  1290. set => SetProperty(ref _UpCameraPickNum, value);
  1291. }
  1292. private Int16 _UpCameraPutNum = 0;
  1293. /// <summary>
  1294. /// 上相机放料拍照次数
  1295. /// </summary>
  1296. public Int16 UpCameraPutNum
  1297. {
  1298. get => _UpCameraPutNum;
  1299. set => SetProperty(ref _UpCameraPutNum, value);
  1300. }
  1301. private Int16 _UPCameracheckNum = 0;
  1302. /// <summary>
  1303. /// 上相机锁附/组装次数
  1304. /// </summary>
  1305. public Int16 UPCameracheckNum
  1306. {
  1307. get => _UPCameracheckNum;
  1308. set => SetProperty(ref _UPCameracheckNum, value);
  1309. }
  1310. private Int16 _FixedCameraPickNum = 0;
  1311. /// <summary>
  1312. /// 取料固定位置拍产品相机数量
  1313. /// </summary>
  1314. public Int16 FixedCameraPickNum
  1315. {
  1316. get => _FixedCameraPickNum;
  1317. set => SetProperty(ref _FixedCameraPickNum, value);
  1318. }
  1319. private Int16 _FixedCameraPutNum = 0;
  1320. /// <summary>
  1321. /// 锁附/组装固定位置拍产品相机数量
  1322. /// </summary>
  1323. public Int16 FixedCameraPutNum
  1324. {
  1325. get => _FixedCameraPutNum;
  1326. set => SetProperty(ref _FixedCameraPutNum, value);
  1327. }
  1328. private Int16 _FixedCameracheckNum = 0;
  1329. /// <summary>
  1330. /// 固定相机检测锁附/组装次数
  1331. /// </summary>
  1332. public Int16 FixedCameracheckNum
  1333. {
  1334. get => _FixedCameracheckNum;
  1335. set => SetProperty(ref _FixedCameracheckNum, value);
  1336. }
  1337. private Int16 _ScrewTeachNum = 0;
  1338. /// <summary>
  1339. /// 披头矫正的模式,1:初始化时矫正,2:每个产品矫正一次,3:每颗螺丝矫正一次
  1340. /// </summary>
  1341. public Int16 ScrewTeachNum
  1342. {
  1343. get => _ScrewTeachNum;
  1344. set => SetProperty(ref _ScrewTeachNum, value);
  1345. }
  1346. async void ExecuteSaveSystemParametersCommand()
  1347. {
  1348. var view = new ShowMessage($"AAS", Lang.是否保存系统参数);
  1349. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1350. if (result != null && result is bool && (bool)result)
  1351. {
  1352. try
  1353. {
  1354. var sysConfig = _configService.GetSystemConfiguration();
  1355. sysConfig.WorkMode = WorkMode;
  1356. sysConfig.PickPointNum = PickPointNum;
  1357. sysConfig.DowmCameraNum = DowmCameraNum;
  1358. sysConfig.UpCameraPickNum = UpCameraPickNum;
  1359. sysConfig.UpCameraPutNum = UpCameraPutNum;
  1360. sysConfig.UPCameracheckNum = UPCameracheckNum;
  1361. sysConfig.FixedCameraPickNum = FixedCameraPickNum;
  1362. sysConfig.FixedCameraPutNum = FixedCameraPutNum;
  1363. sysConfig.FixedCameracheckNum = FixedCameracheckNum;
  1364. sysConfig.ScrewTeachNum = ScrewTeachNum;
  1365. _configService.SaveSystemConfiguration(sysConfig);
  1366. await management.WriteSystemParameterToPlcAsync(sysConfig);
  1367. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1368. }
  1369. catch (Exception ex)
  1370. {
  1371. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1372. }
  1373. }
  1374. }
  1375. #endregion
  1376. #region 设备信息
  1377. /// <summary>
  1378. /// 保存设备信息
  1379. /// </summary>
  1380. void ExecuteSaveDeviceInfoCommand()
  1381. {
  1382. try
  1383. {
  1384. if (DeviceInfo != null)
  1385. {
  1386. _configService.SaveDeviceInfo(DeviceInfo);
  1387. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1388. }
  1389. }
  1390. catch (Exception ex)
  1391. {
  1392. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1393. }
  1394. }
  1395. #endregion
  1396. }
  1397. }