SettingViewModel.cs 64 KB

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