SettingViewModel.cs 63 KB

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