SettingViewModel.cs 64 KB

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