SettingViewModel.cs 62 KB

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