SettingViewModel.cs 66 KB

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