SettingViewModel.cs 64 KB

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