SettingViewModel.cs 63 KB

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