SettingViewModel.cs 68 KB

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