SettingViewModel.cs 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  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. case CameraBrand.SSZN:
  770. softwarename = "SSZN Camera Viewer";
  771. result = OptCamera.CheckSoftwareInstalled();
  772. break;
  773. default:
  774. break;
  775. }
  776. if (!result.isInstalled)
  777. {
  778. if (string.IsNullOrEmpty(result.version))
  779. {
  780. //未安装
  781. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  782. }
  783. else
  784. {
  785. //版本较低
  786. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  787. }
  788. return;
  789. }
  790. IDialogParameters parameters = new DialogParameters();
  791. parameters.Add("CameraBrand", cameraBrand);
  792. _dialogService.ShowDialog("AddCamera", parameters, rst =>
  793. {
  794. //对话框关闭之后的回调函数,可以在这解析结果。
  795. ButtonResult result1 = rst.Result;
  796. if (result1 == ButtonResult.OK)
  797. {
  798. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  799. var camera = new CameraInfo()
  800. {
  801. Id = param.Id,
  802. CameraName = param.CameraName,
  803. SerialNumber = param.SerialNumber,
  804. Model = param.Model,
  805. ManufacturerName = param.ManufacturerName,
  806. CameraType = param.CameraType,
  807. CameraBrand = param.CameraBrand,
  808. CameraIp = param.CameraIp
  809. };
  810. CameraList.Add(camera);
  811. _configService.AddOrUpdateCamera(camera);
  812. _cameraService.CreateCamera(camera.Id, camera);
  813. //对所有产品也进行添加
  814. _productService.AddCameraToProduct(camera.Id, camera.CameraName);
  815. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  816. }
  817. });
  818. }
  819. #endregion
  820. #region Feeder
  821. void ExecuteAddFeederCommand()
  822. {
  823. _dialogService.ShowDialog("AddFeeder", rst =>
  824. {
  825. //对话框关闭之后的回调函数,可以在这解析结果。
  826. ButtonResult result1 = rst.Result;
  827. if (result1 == ButtonResult.OK)
  828. {
  829. var param = rst.Parameters.GetValue<FeederInfo>("Feeder");
  830. var feeder = new FeederInfo()
  831. {
  832. Id = param.Id,
  833. FeederName = param.FeederName,
  834. ConnectType = param.ConnectType,
  835. FeederBrand = param.FeederBrand,
  836. IP = param.IP,
  837. Port = param.Port
  838. };
  839. FeederList.Add(feeder);
  840. _configService.AddOrUpdateFeeder(feeder);
  841. _feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
  842. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  843. }
  844. });
  845. }
  846. void ExecuteRemoveFeederCommand()
  847. {
  848. if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  849. {
  850. // 找到要删除的机器人
  851. var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
  852. if (feederToRemove != null)
  853. {
  854. _configService.RemoveFeeder(feederToRemove.Id);
  855. _feederService.RemoveFeeder(feederToRemove.Id);
  856. var root = _configService.GetAllFeeders();
  857. FeederList = new ObservableCollection<FeederInfo>(root);
  858. foreach (var item in FeederList)
  859. {
  860. _feederService.UpdateFeederNo(item.Id, item.FeederNo);
  861. }
  862. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  863. }
  864. }
  865. }
  866. async void ExecuteSaveFeedersCommand()
  867. {
  868. var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
  869. //show the dialog
  870. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  871. if (result != null && result is bool)
  872. {
  873. if (((bool)result))
  874. {
  875. foreach (var item in FeederList)
  876. {
  877. _configService.AddOrUpdateFeeder(item);
  878. }
  879. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  880. }
  881. }
  882. }
  883. #endregion
  884. #region PLC
  885. /// <summary>
  886. /// 保存PLC
  887. /// </summary>
  888. async void ExecuteSavePlcsCommand()
  889. {
  890. var view = new ShowMessage($"AAS", Lang.是否保存PLC);
  891. //show the dialog
  892. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  893. if (result != null && result is bool)
  894. {
  895. if (((bool)result))
  896. {
  897. foreach (var item in PlcList)
  898. {
  899. _configService.AddOrUpdatePlc(item);
  900. }
  901. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  902. }
  903. }
  904. }
  905. /// <summary>
  906. /// 移除PLC
  907. /// </summary>
  908. void ExecuteRemovePlcCommand()
  909. {
  910. if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  911. {
  912. // 找到要删除的plc
  913. var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
  914. if (plcToRemove != null)
  915. {
  916. _configService.RemovePlc(plcToRemove.Id);
  917. _plcService.RemovePlc(plcToRemove.Id);
  918. var root = _configService.GetAllPlcs();
  919. PlcList = new ObservableCollection<PlcInfo>(root);
  920. foreach (var item in PlcList)
  921. {
  922. _plcService.UpdatePlcNumber(item.Id, item.Index);
  923. }
  924. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  925. }
  926. }
  927. }
  928. /// <summary>
  929. /// 增加PLC
  930. /// </summary>
  931. void ExecuteAddPlcCommand()
  932. {
  933. _dialogService.ShowDialog("AddPlc", rst =>
  934. {
  935. //对话框关闭之后的回调函数,可以在这解析结果。
  936. ButtonResult result1 = rst.Result;
  937. if (result1 == ButtonResult.OK)
  938. {
  939. var param = rst.Parameters.GetValue<PlcInfo>("PLC");
  940. var plc = new PlcInfo()
  941. {
  942. Id = param.Id,
  943. Name = param.Name,
  944. CommunicationType = param.CommunicationType,
  945. EndpointUrl = param.EndpointUrl,
  946. };
  947. PlcList.Add(plc);
  948. _configService.AddOrUpdatePlc(plc);
  949. _plcService.CreatePlc(plc.Id, plc);
  950. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  951. }
  952. });
  953. }
  954. #endregion
  955. #region Light handlers
  956. void ExecuteAddLightControllerCommand()
  957. {
  958. // open dialog to add light controller (similar to robots)
  959. _dialogService.ShowDialog("AddLightController", rst =>
  960. {
  961. if (rst.Result == ButtonResult.OK)
  962. {
  963. var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
  964. // assign id and defaults if needed
  965. if (param.Id == 0)
  966. param.Id = (LightControllerList?.Count ?? 0) + 1;
  967. LightControllerList.Add(param);
  968. _configService.AddOrUpdateLightController(param);
  969. SelectLightController = param;
  970. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加完成", Duration = 1 });
  971. }
  972. });
  973. }
  974. void ExecuteRemoveLightControllerCommand()
  975. {
  976. if (SelectLightController == null) return;
  977. if (MessageBox.Show("是否移除光源控制器?", "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  978. {
  979. _configService.RemoveLightController(SelectLightController.Id);
  980. LightControllerList.Remove(SelectLightController);
  981. SelectLightController = null;
  982. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "移除完成", Duration = 1 });
  983. }
  984. }
  985. async void ExecuteSaveLightControllersCommand()
  986. {
  987. var view = new ShowMessage($"AAS", "是否保存光源控制器配置?");
  988. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  989. if (result != null && result is bool && (bool)result)
  990. {
  991. foreach (var item in LightControllerList)
  992. {
  993. _configService.AddOrUpdateLightController(item);
  994. }
  995. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成", Duration = 1 });
  996. }
  997. }
  998. #endregion
  999. #region 通讯
  1000. async void ExecuteSaveCommunicateCommand(string parm)
  1001. {
  1002. if (parm == "TCPIP")
  1003. {
  1004. var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
  1005. //show the dialog
  1006. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1007. if (result != null && result is bool)
  1008. {
  1009. if (((bool)result))
  1010. {
  1011. _configService.SetBgTcp(BgTcp);
  1012. _configService.SaveBgTcp();
  1013. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1014. }
  1015. }
  1016. }
  1017. else if (parm == "ModbusTCP")
  1018. {
  1019. var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
  1020. //show the dialog
  1021. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1022. if (result != null && result is bool)
  1023. {
  1024. if (((bool)result))
  1025. {
  1026. _configService.SetBgModbusTcp(BgModbus);
  1027. _configService.SaveBgModbusTcp();
  1028. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1029. }
  1030. }
  1031. }
  1032. else
  1033. {
  1034. return;
  1035. }
  1036. }
  1037. #endregion
  1038. #region 语言
  1039. void ExecuteSelectLanguageCommand(string language)
  1040. {
  1041. if (string.Equals(language, "ChineseSimplified"))
  1042. {
  1043. CurrentLanguage = Enums.Language.ChineseSimplified;
  1044. var sysConfig = _configService.GetSystemConfiguration();
  1045. sysConfig.CurrentLanguage = CurrentLanguage;
  1046. _configService.SaveSystemConfiguration(sysConfig);
  1047. var culture = new CultureInfo("zh-CN");
  1048. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1049. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1050. LocalizeDictionary.Instance.Culture = culture;
  1051. Lang.Culture = culture;
  1052. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  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. var sysConfig = _configService.GetSystemConfiguration();
  1059. sysConfig.CurrentLanguage = CurrentLanguage;
  1060. _configService.SaveSystemConfiguration(sysConfig);
  1061. var culture = new CultureInfo("zh-TW");
  1062. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1063. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1064. LocalizeDictionary.Instance.Culture = culture;
  1065. Lang.Culture = culture;
  1066. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  1067. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1068. }
  1069. else if (string.Equals(language, "English"))
  1070. {
  1071. CurrentLanguage = Enums.Language.English;
  1072. var sysConfig = _configService.GetSystemConfiguration();
  1073. sysConfig.CurrentLanguage = CurrentLanguage;
  1074. _configService.SaveSystemConfiguration(sysConfig);
  1075. var culture = new CultureInfo("en");
  1076. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1077. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1078. LocalizeDictionary.Instance.Culture = culture;
  1079. Lang.Culture = culture;
  1080. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  1081. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1082. }
  1083. else if (string.Equals(language, "Japanese"))
  1084. {
  1085. CurrentLanguage = Enums.Language.Japanese;
  1086. var sysConfig = _configService.GetSystemConfiguration();
  1087. sysConfig.CurrentLanguage = CurrentLanguage;
  1088. _configService.SaveSystemConfiguration(sysConfig);
  1089. var culture = new CultureInfo("ja-JP");
  1090. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1091. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1092. LocalizeDictionary.Instance.Culture = culture;
  1093. Lang.Culture = culture;
  1094. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  1095. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1096. }
  1097. }
  1098. #endregion
  1099. private void OnLoad()
  1100. {
  1101. if (!File.Exists(FilePath.ScanRS232ConfigPath))
  1102. {
  1103. var scan = new ScanRs232ConfigModel();
  1104. FileHelper.WriteJsonFile(scan, FilePath.ScanRS232ConfigPath);
  1105. }
  1106. this.ScanConfig = FileHelper.ReadJsonFile<ScanRs232ConfigModel>(FilePath.ScanRS232ConfigPath);
  1107. }
  1108. private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  1109. {
  1110. switch (e.PropertyName)
  1111. {
  1112. case "Title1":
  1113. Application.Current.Resources["Font.Size.Title1"] = Title1;
  1114. break;
  1115. case "Title2":
  1116. Application.Current.Resources["Font.Size.Title2"] = Title2;
  1117. break;
  1118. case "Title3":
  1119. Application.Current.Resources["Font.Size.Title3"] = Title3;
  1120. break;
  1121. case "Title4":
  1122. Application.Current.Resources["Font.Size.Title4"] = Title4;
  1123. break;
  1124. case "Body1":
  1125. Application.Current.Resources["Font.Size.Body1"] = Body1;
  1126. break;
  1127. case "Body2":
  1128. Application.Current.Resources["Font.Size.Body2"] = Body2;
  1129. break;
  1130. case "Body3":
  1131. Application.Current.Resources["Font.Size.Body3"] = Body3;
  1132. break;
  1133. case "Body4":
  1134. Application.Current.Resources["Font.Size.Body4"] = Body4;
  1135. break;
  1136. case "Captions1":
  1137. Application.Current.Resources["Font.Size.Captions1"] = Captions1;
  1138. break;
  1139. case "Captions2":
  1140. Application.Current.Resources["Font.Size.Captions2"] = Captions2;
  1141. break;
  1142. case "Captions3":
  1143. Application.Current.Resources["Font.Size.Captions3"] = Captions3;
  1144. break;
  1145. case "Captions4":
  1146. Application.Current.Resources["Font.Size.Captions4"] = Captions4;
  1147. break;
  1148. default:
  1149. break;
  1150. }
  1151. }
  1152. #endregion
  1153. #region 继承
  1154. /// <summary>
  1155. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  1156. /// </summary>
  1157. /// <param name="navigationContext"></param>
  1158. /// <param name="continuationCallback"></param>
  1159. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  1160. {
  1161. continuationCallback(true);
  1162. }
  1163. /// <summary>
  1164. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  1165. /// </summary>
  1166. /// <param name="navigationContext"></param>
  1167. /// <exception cref="NotImplementedException"></exception>
  1168. public async void OnNavigatedTo(NavigationContext navigationContext)
  1169. {
  1170. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  1171. {
  1172. IsAllowEdit = false;
  1173. }
  1174. else
  1175. {
  1176. IsAllowEdit = true;
  1177. }
  1178. if (RobotList == null)
  1179. {
  1180. RobotList = new ObservableCollection<RobotInfo>();
  1181. var robots = _configService.GetAllRobots();
  1182. foreach (var robot in robots)
  1183. {
  1184. RobotList.Add(robot);
  1185. }
  1186. }
  1187. if (ScannerList == null)
  1188. {
  1189. ScannerList = new ObservableCollection<ScannerInfo>();
  1190. var scanners = _configService.GetAllScanners();
  1191. foreach (var scanner in scanners)
  1192. {
  1193. ScannerList.Add(scanner);
  1194. }
  1195. }
  1196. if (CameraList == null)
  1197. {
  1198. CameraList = new ObservableCollection<CameraInfo>();
  1199. var cameras = _configService.GetAllCameras();
  1200. foreach (var camera in cameras)
  1201. {
  1202. CameraList.Add(camera);
  1203. }
  1204. }
  1205. if (FeederList == null)
  1206. {
  1207. FeederList = new ObservableCollection<FeederInfo>();
  1208. var feeders = _configService.GetAllFeeders();
  1209. foreach (var feeder in feeders)
  1210. {
  1211. FeederList.Add(feeder);
  1212. }
  1213. }
  1214. if (PlcList == null)
  1215. {
  1216. PlcList = new ObservableCollection<PlcInfo>();
  1217. var plcs = _configService.GetAllPlcs();
  1218. foreach (var plc in plcs)
  1219. {
  1220. PlcList.Add(plc);
  1221. }
  1222. }
  1223. // load light controllers
  1224. if (LightControllerList == null)
  1225. {
  1226. LightControllerList = new ObservableCollection<LightControllerConfig>();
  1227. var controllers = _configService.GetAllLightControllers();
  1228. foreach (var ctrl in controllers)
  1229. {
  1230. LightControllerList.Add(ctrl);
  1231. }
  1232. }
  1233. if (BgTcp == null)
  1234. {
  1235. BgTcp = _configService.GetBgTcp();
  1236. }
  1237. if (BgModbus == null)
  1238. {
  1239. BgModbus = _configService.GetBgModbusTcp();
  1240. }
  1241. if (DeviceInfo == null)
  1242. {
  1243. DeviceInfo = _configService.GetDeviceInfo();
  1244. }
  1245. if (CardReaderConfig == null)
  1246. {
  1247. // load card reader config
  1248. CardReaderConfig = _configService.GetCardReaderConfig();
  1249. }
  1250. CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
  1251. // load system parameters into UI
  1252. var sys = _configService.GetSystemConfiguration();
  1253. if (sys != null)
  1254. {
  1255. WorkMode = sys.WorkMode;
  1256. PickPointNum = sys.PickPointNum;
  1257. DowmCameraNum = sys.DowmCameraNum;
  1258. WorkMode = sys.WorkMode;
  1259. PickPointNum = sys.PickPointNum;
  1260. DowmCameraNum = sys.DowmCameraNum;
  1261. UpCameraPickNum = sys.UpCameraPickNum;
  1262. UpCameraPutNum = sys.UpCameraPutNum;
  1263. UPCameracheckNum = sys.UPCameracheckNum;
  1264. FixedCameraPickNum = sys.FixedCameraPickNum;
  1265. FixedCameraPutNum = sys.FixedCameraPutNum;
  1266. FixedCameracheckNum = sys.FixedCameracheckNum;
  1267. IsSaveScrewCurve = sys.IsSaveScrewCurve;
  1268. ScrewCurvePath = sys.ScrewCurvePath;
  1269. }
  1270. if (isFirstLoad)
  1271. {
  1272. Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
  1273. Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
  1274. Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
  1275. Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
  1276. Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
  1277. Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
  1278. Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
  1279. Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
  1280. Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
  1281. Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
  1282. Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
  1283. Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
  1284. this.PropertyChanged += OnPropertyChanged;
  1285. isFirstLoad = false;
  1286. }
  1287. try
  1288. {
  1289. ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
  1290. }
  1291. catch (Exception ex)
  1292. {
  1293. LogHelper.WriteLogError("加载产品列表时出错", ex);
  1294. }
  1295. }
  1296. /// <summary>
  1297. /// 是否允许导航到此视图模型。
  1298. /// </summary>
  1299. /// <param name="navigationContext"></param>
  1300. /// <returns></returns>
  1301. public bool IsNavigationTarget(NavigationContext navigationContext)
  1302. {
  1303. return true;
  1304. }
  1305. /// <summary>
  1306. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1307. /// </summary>
  1308. /// <param name="navigationContext"></param>
  1309. public void OnNavigatedFrom(NavigationContext navigationContext)
  1310. {
  1311. }
  1312. #endregion
  1313. private bool _IsAllowEdit = false;
  1314. public bool IsAllowEdit
  1315. {
  1316. get { return _IsAllowEdit; }
  1317. set { SetProperty(ref _IsAllowEdit, value); }
  1318. }
  1319. private void LoginChange(Models.User user)
  1320. {
  1321. if (user.userPart == Enums.UserPart.Operator)
  1322. {
  1323. IsAllowEdit = false;
  1324. }
  1325. else
  1326. {
  1327. IsAllowEdit = true;
  1328. }
  1329. }
  1330. #region 系统参数
  1331. private Int16 _WorkMode = 0;
  1332. /// <summary>
  1333. /// 工作模式 =1 拍1打1 =2 拍1打所有
  1334. /// </summary>
  1335. public Int16 WorkMode
  1336. {
  1337. get { return _WorkMode; }
  1338. set { SetProperty(ref _WorkMode, value); }
  1339. }
  1340. private Int16 _PickPointNum = 0;
  1341. /// <summary>
  1342. /// 取料位置 =0 不需要取料 =1 需要取料
  1343. /// </summary>
  1344. public Int16 PickPointNum
  1345. {
  1346. get { return _PickPointNum; }
  1347. set { SetProperty(ref _PickPointNum, value); }
  1348. }
  1349. private Int16 _DowmCameraNum = 0;
  1350. /// <summary>
  1351. /// 下相机拍照次数
  1352. /// </summary>
  1353. public Int16 DowmCameraNum
  1354. {
  1355. get => _DowmCameraNum;
  1356. set => SetProperty(ref _DowmCameraNum, value);
  1357. }
  1358. private Int16 _UpCameraPickNum = 0;
  1359. /// <summary>
  1360. /// 上相机取料拍照次数
  1361. /// </summary>
  1362. public Int16 UpCameraPickNum
  1363. {
  1364. get => _UpCameraPickNum;
  1365. set => SetProperty(ref _UpCameraPickNum, value);
  1366. }
  1367. private Int16 _UpCameraPutNum = 0;
  1368. /// <summary>
  1369. /// 上相机放料拍照次数
  1370. /// </summary>
  1371. public Int16 UpCameraPutNum
  1372. {
  1373. get => _UpCameraPutNum;
  1374. set => SetProperty(ref _UpCameraPutNum, value);
  1375. }
  1376. private Int16 _UPCameracheckNum = 0;
  1377. /// <summary>
  1378. /// 上相机锁附/组装次数
  1379. /// </summary>
  1380. public Int16 UPCameracheckNum
  1381. {
  1382. get => _UPCameracheckNum;
  1383. set => SetProperty(ref _UPCameracheckNum, value);
  1384. }
  1385. private Int16 _FixedCameraPickNum = 0;
  1386. /// <summary>
  1387. /// 取料固定位置拍产品相机数量
  1388. /// </summary>
  1389. public Int16 FixedCameraPickNum
  1390. {
  1391. get => _FixedCameraPickNum;
  1392. set => SetProperty(ref _FixedCameraPickNum, value);
  1393. }
  1394. private Int16 _FixedCameraPutNum = 0;
  1395. /// <summary>
  1396. /// 锁附/组装固定位置拍产品相机数量
  1397. /// </summary>
  1398. public Int16 FixedCameraPutNum
  1399. {
  1400. get => _FixedCameraPutNum;
  1401. set => SetProperty(ref _FixedCameraPutNum, value);
  1402. }
  1403. private Int16 _FixedCameracheckNum = 0;
  1404. /// <summary>
  1405. /// 固定相机检测锁附/组装次数
  1406. /// </summary>
  1407. public Int16 FixedCameracheckNum
  1408. {
  1409. get => _FixedCameracheckNum;
  1410. set => SetProperty(ref _FixedCameracheckNum, value);
  1411. }
  1412. async void ExecuteSaveSystemParametersCommand()
  1413. {
  1414. var view = new ShowMessage($"AAS", "是否保存系统参数?");
  1415. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1416. if (result != null && result is bool && (bool)result)
  1417. {
  1418. try
  1419. {
  1420. ExecuteSaveCardReaderConfigCommand();
  1421. FileHelper.WriteJsonFile(this.ScanConfig, FilePath.ScanRS232ConfigPath);
  1422. var sysConfig = _configService.GetSystemConfiguration();
  1423. sysConfig.WorkMode = WorkMode;
  1424. sysConfig.PickPointNum = PickPointNum;
  1425. sysConfig.DowmCameraNum = DowmCameraNum;
  1426. sysConfig.UpCameraPickNum = UpCameraPickNum;
  1427. sysConfig.UpCameraPutNum = UpCameraPutNum;
  1428. sysConfig.UPCameracheckNum = UPCameracheckNum;
  1429. sysConfig.FixedCameraPickNum = FixedCameraPickNum;
  1430. sysConfig.FixedCameraPutNum = FixedCameraPutNum;
  1431. sysConfig.FixedCameracheckNum = FixedCameracheckNum;
  1432. sysConfig.IsSaveScrewCurve = IsSaveScrewCurve;
  1433. sysConfig.ScrewCurvePath = ScrewCurvePath;
  1434. _configService.SaveSystemConfiguration(sysConfig);
  1435. await management.WriteSystemParameterToPlcAsync(sysConfig);
  1436. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1437. }
  1438. catch (Exception ex)
  1439. {
  1440. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1441. }
  1442. }
  1443. }
  1444. /// <summary>
  1445. /// 选择锁付曲线图保存路径
  1446. /// </summary>
  1447. void ExecuteBrowseScrewCurvePathCommand()
  1448. {
  1449. try
  1450. {
  1451. using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
  1452. {
  1453. dlg.Description = "选择锁付曲线图保存路径";
  1454. dlg.ShowNewFolderButton = true;
  1455. if (!string.IsNullOrEmpty(ScrewCurvePath)) dlg.SelectedPath = ScrewCurvePath;
  1456. var result = dlg.ShowDialog();
  1457. if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
  1458. {
  1459. ScrewCurvePath = dlg.SelectedPath;
  1460. }
  1461. }
  1462. }
  1463. catch (Exception ex)
  1464. {
  1465. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 2 });
  1466. }
  1467. }
  1468. /// <summary>
  1469. /// 保存读卡器配置
  1470. /// </summary>
  1471. void ExecuteSaveCardReaderConfigCommand()
  1472. {
  1473. try
  1474. {
  1475. _configService.SaveCardReaderConfig(CardReaderConfig);
  1476. }
  1477. catch (Exception ex)
  1478. {
  1479. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1480. }
  1481. }
  1482. #endregion
  1483. #region 设备信息
  1484. /// <summary>
  1485. /// 保存设备信息
  1486. /// </summary>
  1487. void ExecuteSaveDeviceInfoCommand()
  1488. {
  1489. try
  1490. {
  1491. if (DeviceInfo != null)
  1492. {
  1493. _configService.SaveDeviceInfo(DeviceInfo);
  1494. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1495. }
  1496. }
  1497. catch (Exception ex)
  1498. {
  1499. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1500. }
  1501. }
  1502. /// <summary>
  1503. /// 选择CSV存储路径
  1504. /// </summary>
  1505. void ExecuteSelectSaveImagePathCommand()
  1506. {
  1507. if (DeviceInfo == null)
  1508. {
  1509. return;
  1510. }
  1511. using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog())
  1512. {
  1513. // Optional: set the initial directory
  1514. //dialog.SelectedPath = @"C:\";
  1515. // Show the folder browser dialog
  1516. System.Windows.Forms.DialogResult result = dialog.ShowDialog();
  1517. if (result == System.Windows.Forms.DialogResult.OK)
  1518. {
  1519. DeviceInfo.SaveCsvPath = dialog.SelectedPath;
  1520. }
  1521. }
  1522. }
  1523. #endregion
  1524. #region 产品与mes绑定
  1525. private async void ExecuteGetProWithMesCommand()
  1526. {
  1527. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1528. if (v == null)
  1529. {
  1530. ProMesInfo.ProductCode = "";
  1531. ProMesInfo.ProductColor = "";
  1532. ProMesInfo.ProductLoadMode = 0;
  1533. }
  1534. else
  1535. {
  1536. ProMesInfo.ProductCode = v.ProductCode;
  1537. ProMesInfo.ProductColor = v.ProductColor;
  1538. ProMesInfo.ProductLoadMode = v.ProductLoadMode;
  1539. }
  1540. }
  1541. private async void ExecuteDeleteProWithMesCommand()
  1542. {
  1543. var v = await _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
  1544. if (v > 0)
  1545. {
  1546. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "删除成功", Duration = 1 });
  1547. var F = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1548. if (F == null)
  1549. {
  1550. ProMesInfo.ProductCode = "";
  1551. ProMesInfo.ProductColor = "";
  1552. ProMesInfo.ProductLoadMode = 0;
  1553. }
  1554. }
  1555. }
  1556. private async void ExecuteSaveProWithMesCommandAsync()
  1557. {
  1558. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1559. if (v == null)
  1560. {
  1561. await _systemDatabaseService.InsertProWithMesAsync(ProMesInfo, SelectProduct);
  1562. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加成功", Duration = 1 });
  1563. }
  1564. else
  1565. {
  1566. var n = await _systemDatabaseService.UpdateProductWithMesAsync(ProMesInfo, SelectProduct);
  1567. if (n > 0)
  1568. {
  1569. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "更新成功", Duration = 1 });
  1570. }
  1571. }
  1572. }
  1573. #endregion
  1574. }
  1575. }