SettingViewModel.cs 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872
  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. // 当前选中的设备信息
  341. private DeviceInfo _SelectDeviceInfo;
  342. public DeviceInfo SelectDeviceInfo
  343. {
  344. get { return _SelectDeviceInfo; }
  345. set { SetProperty(ref _SelectDeviceInfo, value); }
  346. }
  347. // 设备信息列表
  348. private ObservableCollection<DeviceInfo> _DeviceInfoList;
  349. public ObservableCollection<DeviceInfo> DeviceInfoList
  350. {
  351. get { return _DeviceInfoList; }
  352. set { SetProperty(ref _DeviceInfoList, value); }
  353. }
  354. #endregion
  355. #region 命令
  356. public DelegateCommand LoadedCommand { get; set; }
  357. private DelegateCommand _SaveSystemParametersCommand;
  358. public DelegateCommand SaveSystemParametersCommand =>
  359. _SaveSystemParametersCommand ?? (_SaveSystemParametersCommand = new DelegateCommand(ExecuteSaveSystemParametersCommand));
  360. private DelegateCommand _AddRobotCommand;
  361. public DelegateCommand AddRobotCommand =>
  362. _AddRobotCommand ?? (_AddRobotCommand = new DelegateCommand(ExecuteAddRobotCommand));
  363. private DelegateCommand _AddScannerCommand;
  364. public DelegateCommand AddScannerCommand =>
  365. _AddScannerCommand ?? (_AddScannerCommand = new DelegateCommand(ExecuteAddScannerCommand));
  366. private DelegateCommand _RemoveCommand;
  367. public DelegateCommand RemoveCommand =>
  368. _RemoveCommand ?? (_RemoveCommand = new DelegateCommand(ExecuteRemoveCommand));
  369. private DelegateCommand _RemoveScannerCommand;
  370. public DelegateCommand RemoveScannerCommand =>
  371. _RemoveScannerCommand ?? (_RemoveScannerCommand = new DelegateCommand(ExecuteRemoveScannerCommand));
  372. private DelegateCommand _AddFeederCommand;
  373. public DelegateCommand AddFeederCommand =>
  374. _AddFeederCommand ?? (_AddFeederCommand = new DelegateCommand(ExecuteAddFeederCommand));
  375. private DelegateCommand _RemoveFeederCommand;
  376. public DelegateCommand RemoveFeederCommand =>
  377. _RemoveFeederCommand ?? (_RemoveFeederCommand = new DelegateCommand(ExecuteRemoveFeederCommand));
  378. private DelegateCommand<string> _SelectLanguageCommand;
  379. public DelegateCommand<string> SelectLanguageCommand =>
  380. _SelectLanguageCommand ?? (_SelectLanguageCommand = new DelegateCommand<string>(ExecuteSelectLanguageCommand));
  381. private DelegateCommand _SaveRobotsCommand;
  382. public DelegateCommand SaveRobotsCommand =>
  383. _SaveRobotsCommand ?? (_SaveRobotsCommand = new DelegateCommand(ExecuteSaveRobotsCommand));
  384. private DelegateCommand _SaveScannerCommand;
  385. public DelegateCommand SaveScannerCommand =>
  386. _SaveScannerCommand ?? (_SaveScannerCommand = new DelegateCommand(ExecuteSaveScannersCommand));
  387. private DelegateCommand _SaveFeedersCommand;
  388. public DelegateCommand SaveFeedersCommand =>
  389. _SaveFeedersCommand ?? (_SaveFeedersCommand = new DelegateCommand(ExecuteSaveFeedersCommand));
  390. private DelegateCommand<string> _SaveCommunicateCommand;
  391. public DelegateCommand<string> SaveCommunicateCommand =>
  392. _SaveCommunicateCommand ?? (_SaveCommunicateCommand = new DelegateCommand<string>(ExecuteSaveCommunicateCommand));
  393. private DelegateCommand _AddCameraCommand;
  394. public DelegateCommand AddCameraCommand =>
  395. _AddCameraCommand ?? (_AddCameraCommand = new DelegateCommand(ExecuteAddCameraCommand));
  396. private DelegateCommand _EditCameraCommand;
  397. public DelegateCommand EditCameraCommand =>
  398. _EditCameraCommand ?? (_EditCameraCommand = new DelegateCommand(ExecuteEditCameraCommand));
  399. private DelegateCommand _RemoveCameraCommand;
  400. public DelegateCommand RemoveCameraCommand =>
  401. _RemoveCameraCommand ?? (_RemoveCameraCommand = new DelegateCommand(ExecuteRemoveCameraCommand));
  402. private DelegateCommand _SaveCamerasCommand;
  403. public DelegateCommand SaveCamerasCommand =>
  404. _SaveCamerasCommand ?? (_SaveCamerasCommand = new DelegateCommand(ExecuteSaveCamerasCommand));
  405. private DelegateCommand _AddPlcCommand;
  406. public DelegateCommand AddPlcCommand =>
  407. _AddPlcCommand ?? (_AddPlcCommand = new DelegateCommand(ExecuteAddPlcCommand));
  408. private DelegateCommand _RemovePlcCommand;
  409. public DelegateCommand RemovePlcCommand =>
  410. _RemovePlcCommand ?? (_RemovePlcCommand = new DelegateCommand(ExecuteRemovePlcCommand));
  411. private DelegateCommand _SavePlcsCommand;
  412. public DelegateCommand SavePlcsCommand =>
  413. _SavePlcsCommand ?? (_SavePlcsCommand = new DelegateCommand(ExecuteSavePlcsCommand));
  414. private DelegateCommand _AddLightControllerCommand;
  415. public DelegateCommand AddLightControllerCommand => _AddLightControllerCommand ?? (_AddLightControllerCommand = new DelegateCommand(ExecuteAddLightControllerCommand));
  416. private DelegateCommand _RemoveLightControllerCommand;
  417. public DelegateCommand RemoveLightControllerCommand => _RemoveLightControllerCommand ?? (_RemoveLightControllerCommand = new DelegateCommand(ExecuteRemoveLightControllerCommand));
  418. private DelegateCommand _SaveLightControllersCommand;
  419. public DelegateCommand SaveLightControllersCommand => _SaveLightControllersCommand ?? (_SaveLightControllersCommand = new DelegateCommand(ExecuteSaveLightControllersCommand));
  420. private DelegateCommand _BrowseScrewCurvePathCommand;
  421. public DelegateCommand BrowseScrewCurvePathCommand => _BrowseScrewCurvePathCommand ?? (_BrowseScrewCurvePathCommand = new DelegateCommand(ExecuteBrowseScrewCurvePathCommand));
  422. private DelegateCommand _SaveDeviceInfoCommand;
  423. public DelegateCommand SaveDeviceInfoCommand => _SaveDeviceInfoCommand ?? (_SaveDeviceInfoCommand = new DelegateCommand(ExecuteSaveDeviceInfoCommand));
  424. private DelegateCommand _SelectSaveImagePathCommand;
  425. public DelegateCommand SelectSaveImagePathCommand =>
  426. _SelectSaveImagePathCommand ?? (_SelectSaveImagePathCommand = new DelegateCommand(ExecuteSelectSaveImagePathCommand));
  427. private DelegateCommand _SaveCardReaderConfigCommand;
  428. public DelegateCommand SaveCardReaderConfigCommand =>
  429. _SaveCardReaderConfigCommand ?? (_SaveCardReaderConfigCommand = new DelegateCommand(ExecuteSaveCardReaderConfigCommand));
  430. private DelegateCommand _GetProWithMesCommand;
  431. public DelegateCommand GetProWithMesCommand =>
  432. _GetProWithMesCommand ?? (_GetProWithMesCommand = new DelegateCommand(ExecuteGetProWithMesCommand));
  433. private DelegateCommand _DeleteProWithMesCommand;
  434. public DelegateCommand DeleteProWithMesCommand =>
  435. _DeleteProWithMesCommand ?? (_DeleteProWithMesCommand = new DelegateCommand(ExecuteDeleteProWithMesCommand));
  436. private DelegateCommand _SaveProWithMesCommand;
  437. public DelegateCommand SaveProWithMesCommand =>
  438. _SaveProWithMesCommand ?? (_SaveProWithMesCommand = new DelegateCommand(ExecuteSaveProWithMesCommandAsync));
  439. private DelegateCommand _CheckStatusCommand;
  440. public DelegateCommand CheckStatusCommand =>
  441. _CheckStatusCommand ?? (_CheckStatusCommand = new DelegateCommand(ExecuteCheckStatusCommandCommand));
  442. private DelegateCommand _AddDeviceInfoCommand;
  443. public DelegateCommand AddDeviceInfoCommand => _AddDeviceInfoCommand ?? (_AddDeviceInfoCommand = new DelegateCommand(ExecuteAddDeviceInfoCommand));
  444. private DelegateCommand _RemoveDeviceInfoCommand;
  445. public DelegateCommand RemoveDeviceInfoCommand => _RemoveDeviceInfoCommand ?? (_RemoveDeviceInfoCommand = new DelegateCommand(ExecuteRemoveDeviceInfoCommand));
  446. #endregion
  447. #region 事件
  448. #endregion
  449. public SettingViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  450. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService,
  451. IProductService productService, ISystemDatabaseService systemDatabaseService,IScannerService scannerService)
  452. {
  453. _regionManager = regionManager;
  454. _eventAggregator = ea;
  455. _container = container;
  456. _dialogService = dialogService;
  457. _configService = configService;
  458. _robotService = robotService;
  459. _cameraService = cameraService;
  460. _feederService = feederService;
  461. _plcService = plcService;
  462. _productService = productService;
  463. _scannerService = scannerService;
  464. _systemDatabaseService = systemDatabaseService;
  465. management = _container.Resolve<Management>();
  466. LoadedCommand = new DelegateCommand(OnLoad);
  467. //订阅权限登录事件
  468. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  469. }
  470. #region 方法
  471. #region 扫码枪
  472. private void ExecuteAddScannerCommand()
  473. {
  474. _dialogService.ShowDialog("AddScanner", rst =>
  475. {
  476. //对话框关闭之后的回调函数,可以在这解析结果。
  477. ButtonResult result1 = rst.Result;
  478. if (result1 == ButtonResult.OK)
  479. {
  480. var param = rst.Parameters.GetValue<ScannerInfo>("Scanner");
  481. var scanner = new ScannerInfo()
  482. {
  483. Id = param.Id,
  484. ScannerName = param.ScannerName,
  485. ConnectType = param.ConnectType,
  486. ScannerBrand = param.ScannerBrand,
  487. IP = param.IP,
  488. Port = param.Port,
  489. Terminator = param.Terminator,
  490. };
  491. ScannerList.Add(scanner);
  492. _configService.AddOrUpdateScanner(scanner);
  493. _scannerService.CreateScanner(scanner.Id, scanner);
  494. //对所有产品也进行添加
  495. _productService.AddScannerPointToProduct(scanner.Id, scanner.ScannerName);
  496. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
  497. }
  498. });
  499. }
  500. void ExecuteRemoveScannerCommand()
  501. {
  502. if (MessageBox.Show(Lang.是否移除扫码枪, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  503. {
  504. // 找到要删除的扫描枪
  505. var scannerToRemove = ScannerList.FirstOrDefault(s => s.Id == SelectScanner.Id);
  506. if (scannerToRemove != null)
  507. {
  508. ScannerList.Remove(scannerToRemove);
  509. _configService.RemoveScanner(scannerToRemove.Id);
  510. _scannerService.RemoveScanner(scannerToRemove.Id);
  511. //对所有产品也进行移除
  512. _productService.RemoveScannerPointFromProduct(scannerToRemove.Id);
  513. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  514. }
  515. }
  516. }
  517. async void ExecuteSaveScannersCommand()
  518. {
  519. var view = new ShowMessage($"AAS", Lang.是否保存扫码枪);
  520. //show the dialog
  521. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  522. if (result != null && result is bool)
  523. {
  524. if (((bool)result))
  525. {
  526. foreach (var item in ScannerList)
  527. {
  528. _configService.AddOrUpdateScanner(item);
  529. }
  530. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  531. }
  532. }
  533. }
  534. #endregion
  535. #region 机器人
  536. private void ExecuteAddRobotCommand()
  537. {
  538. _dialogService.ShowDialog("AddRobot", rst =>
  539. {
  540. //对话框关闭之后的回调函数,可以在这解析结果。
  541. ButtonResult result1 = rst.Result;
  542. if (result1 == ButtonResult.OK)
  543. {
  544. var param = rst.Parameters.GetValue<RobotInfo>("Robot");
  545. var robot = new RobotInfo()
  546. {
  547. Id = param.Id,
  548. RobotName = param.RobotName,
  549. ConnectType = param.ConnectType,
  550. RobotBrand = param.RobotBrand,
  551. IP = param.IP,
  552. Port = param.Port,
  553. Terminator = param.Terminator,
  554. };
  555. RobotList.Add(robot);
  556. _configService.AddOrUpdateRobot(robot);
  557. _robotService.CreateRobot(robot.Id, robot);
  558. //对所有产品也进行添加
  559. _productService.AddRobotPointToProduct(robot.Id, robot.RobotName);
  560. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
  561. }
  562. });
  563. }
  564. void ExecuteRemoveCommand()
  565. {
  566. if (MessageBox.Show(Lang.是否移除机器人, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  567. {
  568. // 找到要删除的机器人
  569. var robotToRemove = RobotList.FirstOrDefault(r => r.Id == SelectRobot.Id);
  570. if (robotToRemove != null)
  571. {
  572. RobotList.Remove(robotToRemove);
  573. _configService.RemoveRobot(robotToRemove.Id);
  574. _robotService.RemoveRobot(robotToRemove.Id);
  575. //对所有产品也进行移除
  576. _productService.RemoveRobotPointFromProduct(robotToRemove.Id);
  577. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  578. }
  579. }
  580. }
  581. async void ExecuteSaveRobotsCommand()
  582. {
  583. var view = new ShowMessage($"AAS", Lang.是否保存机器人);
  584. //show the dialog
  585. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  586. if (result != null && result is bool)
  587. {
  588. if (((bool)result))
  589. {
  590. foreach (var item in RobotList)
  591. {
  592. _configService.AddOrUpdateRobot(item);
  593. }
  594. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  595. }
  596. }
  597. }
  598. #endregion
  599. #region 相机
  600. /// <summary>
  601. /// 保存所有相机
  602. /// </summary>
  603. async void ExecuteSaveCamerasCommand()
  604. {
  605. var view = new ShowMessage($"AAS", Lang.是否保存相机配置);
  606. //show the dialog
  607. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  608. if (result != null && result is bool)
  609. {
  610. if (((bool)result))
  611. {
  612. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  613. //management.SaveCamerasDeviceConfig();
  614. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  615. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  616. }
  617. }
  618. }
  619. /// <summary>
  620. /// 移除相机
  621. /// </summary>
  622. void ExecuteRemoveCameraCommand()
  623. {
  624. if (MessageBox.Show(Lang.是否移除相机, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  625. {
  626. // 找到要删除的相机
  627. var cameraToRemove = CameraList.FirstOrDefault(r => r.Id == SelectCamera.Id);
  628. if (cameraToRemove != null)
  629. {
  630. _configService.RemoveCamera(cameraToRemove.Id);
  631. _cameraService.RemoveCamera(cameraToRemove.Id);
  632. var root = _configService.GetAllCameras();
  633. CameraList = new ObservableCollection<CameraInfo>(root);
  634. foreach (var item in CameraList)
  635. {
  636. _cameraService.UpdateCameraNumber(item.Id, item.CameraNo);
  637. }
  638. //对所有产品也进行移除
  639. _productService.RemoveCameraFromProduct(cameraToRemove.Id);
  640. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  641. }
  642. }
  643. }
  644. /// <summary>
  645. /// 编辑相机
  646. /// </summary>
  647. void ExecuteEditCameraCommand()
  648. {
  649. if (SelectCamera == null) return;
  650. bool isSelectedCameraBrandSucced = false;
  651. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  652. IDialogParameters parameters1 = new DialogParameters();
  653. parameters1.Add("CameraBrand", SelectCamera.CameraBrand);
  654. _dialogService.ShowDialog("SelectCameraBrand", parameters1, rst =>
  655. {
  656. if (rst.Result == ButtonResult.OK)
  657. {
  658. isSelectedCameraBrandSucced = true;
  659. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  660. }
  661. else
  662. {
  663. return;
  664. }
  665. });
  666. if (!isSelectedCameraBrandSucced) { return; }
  667. (bool isInstalled, string version) result = (false, "");
  668. string softwarename = "";
  669. switch (cameraBrand)
  670. {
  671. case CameraBrand.HikRobot_MVS:
  672. softwarename = "MVS";
  673. result = MvCamera.CheckSoftwareInstalled();
  674. break;
  675. case CameraBrand.Basler_Pylon:
  676. softwarename = "Pylon 7";
  677. result = BaslerCamera.CheckSoftwareInstalled();
  678. break;
  679. case CameraBrand.IRayple:
  680. softwarename = "MV Viewer";
  681. result = AHuaCamera.CheckSoftwareInstalled();
  682. break;
  683. case CameraBrand.Cognex:
  684. softwarename = "Cognex VisionPro";
  685. result = CognexCamera.CheckSoftwareInstalled();
  686. break;
  687. case CameraBrand.Galaxy:
  688. softwarename = "Galaxy Viewer";
  689. result = GalaxyCamera.CheckSoftwareInstalled();
  690. break;
  691. case CameraBrand.Opt:
  692. softwarename = "OPT Camera Viewer";
  693. result = OptCamera.CheckSoftwareInstalled();
  694. break;
  695. case CameraBrand.SSZN:
  696. softwarename = "SSZN Camera Viewer";
  697. result = SSZNCamera.CheckSoftwareInstalled();
  698. break;
  699. case CameraBrand.IKap:
  700. softwarename = "Ikap Camera Viewer";
  701. result = IKapCamera.CheckSoftwareInstalled();
  702. break;
  703. default:
  704. break;
  705. }
  706. if (!result.isInstalled)
  707. {
  708. if (string.IsNullOrEmpty(result.version))
  709. {
  710. //未安装
  711. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  712. }
  713. else
  714. {
  715. //版本较低
  716. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  717. }
  718. return;
  719. }
  720. //编辑前的相机名称
  721. string oldCameraName = SelectCamera.CameraName;
  722. IDialogParameters parameters = new DialogParameters();
  723. parameters.Add("CameraBrand", cameraBrand);
  724. parameters.Add("Camera", SelectCamera.Copy());
  725. _dialogService.ShowDialog("EditCamera", parameters, rst =>
  726. {
  727. //对话框关闭之后的回调函数,可以在这解析结果。
  728. ButtonResult result1 = rst.Result;
  729. if (result1 == ButtonResult.OK)
  730. {
  731. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  732. SelectCamera.CameraName = param.CameraName;
  733. SelectCamera.SerialNumber = param.SerialNumber;
  734. SelectCamera.Model = param.Model;
  735. SelectCamera.ManufacturerName = param.ManufacturerName;
  736. SelectCamera.CameraType = param.CameraType;
  737. SelectCamera.CameraBrand = param.CameraBrand;
  738. SelectCamera.CameraIp = param.CameraIp;
  739. _configService.AddOrUpdateCamera(SelectCamera);
  740. if (oldCameraName != param.CameraName)
  741. {
  742. //对所有产品也进行修改
  743. _productService.UpdateCameraNameInProduct(SelectCamera.Id, SelectCamera.CameraName);
  744. }
  745. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  746. }
  747. });
  748. }
  749. /// <summary>
  750. /// 增加相机
  751. /// </summary>
  752. void ExecuteAddCameraCommand()
  753. {
  754. bool isSelectedCameraBrandSucced = false;
  755. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  756. _dialogService.ShowDialog("SelectCameraBrand", rst =>
  757. {
  758. if (rst.Result == ButtonResult.OK)
  759. {
  760. isSelectedCameraBrandSucced = true;
  761. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  762. }
  763. else
  764. {
  765. return;
  766. }
  767. });
  768. if (!isSelectedCameraBrandSucced) { return; }
  769. ;
  770. (bool isInstalled, string version) result = (false, "");
  771. string softwarename = "";
  772. switch (cameraBrand)
  773. {
  774. case CameraBrand.HikRobot_MVS:
  775. softwarename = "MVS";
  776. result = MvCamera.CheckSoftwareInstalled();
  777. break;
  778. case CameraBrand.Basler_Pylon:
  779. softwarename = "Pylon 7";
  780. result = BaslerCamera.CheckSoftwareInstalled();
  781. break;
  782. case CameraBrand.IRayple:
  783. softwarename = "MV Viewer";
  784. result = AHuaCamera.CheckSoftwareInstalled();
  785. break;
  786. case CameraBrand.Cognex:
  787. softwarename = "Cognex VisionPro";
  788. result = CognexCamera.CheckSoftwareInstalled();
  789. break;
  790. case CameraBrand.Galaxy:
  791. softwarename = "Galaxy Viewer";
  792. result = GalaxyCamera.CheckSoftwareInstalled();
  793. break;
  794. case CameraBrand.Opt:
  795. softwarename = "OPT Camera Viewer";
  796. result = OptCamera.CheckSoftwareInstalled();
  797. break;
  798. case CameraBrand.SSZN:
  799. softwarename = "SSZN Camera Viewer";
  800. result = SSZNCamera.CheckSoftwareInstalled();
  801. break;
  802. case CameraBrand.IKap:
  803. softwarename = "IKap Camera Viewer";
  804. result = IKapCamera.CheckSoftwareInstalled();
  805. break;
  806. default:
  807. break;
  808. }
  809. if (!result.isInstalled)
  810. {
  811. if (string.IsNullOrEmpty(result.version))
  812. {
  813. //未安装
  814. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  815. }
  816. else
  817. {
  818. //版本较低
  819. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  820. }
  821. return;
  822. }
  823. IDialogParameters parameters = new DialogParameters();
  824. parameters.Add("CameraBrand", cameraBrand);
  825. _dialogService.ShowDialog("AddCamera", parameters, rst =>
  826. {
  827. //对话框关闭之后的回调函数,可以在这解析结果。
  828. ButtonResult result1 = rst.Result;
  829. if (result1 == ButtonResult.OK)
  830. {
  831. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  832. var camera = new CameraInfo()
  833. {
  834. Id = param.Id,
  835. CameraName = param.CameraName,
  836. SerialNumber = param.SerialNumber,
  837. Model = param.Model,
  838. ManufacturerName = param.ManufacturerName,
  839. CameraType = param.CameraType,
  840. CameraBrand = param.CameraBrand,
  841. CameraIp = param.CameraIp
  842. };
  843. CameraList.Add(camera);
  844. _configService.AddOrUpdateCamera(camera);
  845. _cameraService.CreateCamera(camera.Id, camera);
  846. //对所有产品也进行添加
  847. _productService.AddCameraToProduct(camera.Id, camera.CameraName);
  848. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  849. }
  850. });
  851. }
  852. #endregion
  853. #region Feeder
  854. void ExecuteAddFeederCommand()
  855. {
  856. _dialogService.ShowDialog("AddFeeder", rst =>
  857. {
  858. //对话框关闭之后的回调函数,可以在这解析结果。
  859. ButtonResult result1 = rst.Result;
  860. if (result1 == ButtonResult.OK)
  861. {
  862. var param = rst.Parameters.GetValue<FeederInfo>("Feeder");
  863. var feeder = new FeederInfo()
  864. {
  865. Id = param.Id,
  866. FeederName = param.FeederName,
  867. ConnectType = param.ConnectType,
  868. FeederBrand = param.FeederBrand,
  869. IP = param.IP,
  870. Port = param.Port
  871. };
  872. FeederList.Add(feeder);
  873. _configService.AddOrUpdateFeeder(feeder);
  874. _feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
  875. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  876. }
  877. });
  878. }
  879. void ExecuteRemoveFeederCommand()
  880. {
  881. if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  882. {
  883. // 找到要删除的机器人
  884. var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
  885. if (feederToRemove != null)
  886. {
  887. _configService.RemoveFeeder(feederToRemove.Id);
  888. _feederService.RemoveFeeder(feederToRemove.Id);
  889. var root = _configService.GetAllFeeders();
  890. FeederList = new ObservableCollection<FeederInfo>(root);
  891. foreach (var item in FeederList)
  892. {
  893. _feederService.UpdateFeederNo(item.Id, item.FeederNo);
  894. }
  895. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  896. }
  897. }
  898. }
  899. async void ExecuteSaveFeedersCommand()
  900. {
  901. var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
  902. //show the dialog
  903. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  904. if (result != null && result is bool)
  905. {
  906. if (((bool)result))
  907. {
  908. foreach (var item in FeederList)
  909. {
  910. _configService.AddOrUpdateFeeder(item);
  911. }
  912. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  913. }
  914. }
  915. }
  916. #endregion
  917. #region PLC
  918. /// <summary>
  919. /// 保存PLC
  920. /// </summary>
  921. async void ExecuteSavePlcsCommand()
  922. {
  923. var view = new ShowMessage($"AAS", Lang.是否保存PLC);
  924. //show the dialog
  925. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  926. if (result != null && result is bool)
  927. {
  928. if (((bool)result))
  929. {
  930. foreach (var item in PlcList)
  931. {
  932. _configService.AddOrUpdatePlc(item);
  933. }
  934. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  935. }
  936. }
  937. }
  938. /// <summary>
  939. /// 移除PLC
  940. /// </summary>
  941. void ExecuteRemovePlcCommand()
  942. {
  943. if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  944. {
  945. // 找到要删除的plc
  946. var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
  947. if (plcToRemove != null)
  948. {
  949. _configService.RemovePlc(plcToRemove.Id);
  950. _plcService.RemovePlc(plcToRemove.Id);
  951. var root = _configService.GetAllPlcs();
  952. PlcList = new ObservableCollection<PlcInfo>(root);
  953. foreach (var item in PlcList)
  954. {
  955. _plcService.UpdatePlcNumber(item.Id, item.Index);
  956. }
  957. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  958. }
  959. }
  960. }
  961. /// <summary>
  962. /// 增加PLC
  963. /// </summary>
  964. void ExecuteAddPlcCommand()
  965. {
  966. _dialogService.ShowDialog("AddPlc", rst =>
  967. {
  968. //对话框关闭之后的回调函数,可以在这解析结果。
  969. ButtonResult result1 = rst.Result;
  970. if (result1 == ButtonResult.OK)
  971. {
  972. var param = rst.Parameters.GetValue<PlcInfo>("PLC");
  973. var plc = new PlcInfo()
  974. {
  975. Id = param.Id,
  976. Name = param.Name,
  977. CommunicationType = param.CommunicationType,
  978. EndpointUrl = param.EndpointUrl,
  979. };
  980. PlcList.Add(plc);
  981. _configService.AddOrUpdatePlc(plc);
  982. _plcService.CreatePlc(plc.Id, plc);
  983. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  984. }
  985. });
  986. }
  987. #endregion
  988. #region Light handlers
  989. void ExecuteAddLightControllerCommand()
  990. {
  991. // open dialog to add light controller (similar to robots)
  992. _dialogService.ShowDialog("AddLightController", rst =>
  993. {
  994. if (rst.Result == ButtonResult.OK)
  995. {
  996. var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
  997. // assign id and defaults if needed
  998. if (param.Id == 0)
  999. param.Id = (LightControllerList?.Count ?? 0) + 1;
  1000. LightControllerList.Add(param);
  1001. _configService.AddOrUpdateLightController(param);
  1002. SelectLightController = param;
  1003. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加完成", Duration = 1 });
  1004. }
  1005. });
  1006. }
  1007. void ExecuteRemoveLightControllerCommand()
  1008. {
  1009. if (SelectLightController == null) return;
  1010. if (MessageBox.Show("是否移除光源控制器?", "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  1011. {
  1012. _configService.RemoveLightController(SelectLightController.Id);
  1013. LightControllerList.Remove(SelectLightController);
  1014. SelectLightController = null;
  1015. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "移除完成", Duration = 1 });
  1016. }
  1017. }
  1018. async void ExecuteSaveLightControllersCommand()
  1019. {
  1020. var view = new ShowMessage($"AAS", "是否保存光源控制器配置?");
  1021. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1022. if (result != null && result is bool && (bool)result)
  1023. {
  1024. foreach (var item in LightControllerList)
  1025. {
  1026. _configService.AddOrUpdateLightController(item);
  1027. }
  1028. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成", Duration = 1 });
  1029. }
  1030. }
  1031. #endregion
  1032. #region 通讯
  1033. async void ExecuteSaveCommunicateCommand(string parm)
  1034. {
  1035. if (parm == "TCPIP")
  1036. {
  1037. var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
  1038. //show the dialog
  1039. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1040. if (result != null && result is bool)
  1041. {
  1042. if (((bool)result))
  1043. {
  1044. _configService.SetBgTcp(BgTcp);
  1045. _configService.SaveBgTcp();
  1046. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1047. }
  1048. }
  1049. }
  1050. else if (parm == "ModbusTCP")
  1051. {
  1052. var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
  1053. //show the dialog
  1054. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1055. if (result != null && result is bool)
  1056. {
  1057. if (((bool)result))
  1058. {
  1059. _configService.SetBgModbusTcp(BgModbus);
  1060. _configService.SaveBgModbusTcp();
  1061. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1062. }
  1063. }
  1064. }
  1065. else
  1066. {
  1067. return;
  1068. }
  1069. }
  1070. #endregion
  1071. #region 语言
  1072. void ExecuteSelectLanguageCommand(string language)
  1073. {
  1074. if (string.Equals(language, "ChineseSimplified"))
  1075. {
  1076. CurrentLanguage = Enums.Language.ChineseSimplified;
  1077. var sysConfig = _configService.GetSystemConfiguration();
  1078. sysConfig.CurrentLanguage = CurrentLanguage;
  1079. _configService.SaveSystemConfiguration(sysConfig);
  1080. var culture = new CultureInfo("zh-CN");
  1081. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1082. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1083. LocalizeDictionary.Instance.Culture = culture;
  1084. Lang.Culture = culture;
  1085. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  1086. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1087. }
  1088. else if (string.Equals(language, "ChineseTraditional"))
  1089. {
  1090. CurrentLanguage = Enums.Language.ChineseTraditional;
  1091. var sysConfig = _configService.GetSystemConfiguration();
  1092. sysConfig.CurrentLanguage = CurrentLanguage;
  1093. _configService.SaveSystemConfiguration(sysConfig);
  1094. var culture = new CultureInfo("zh-TW");
  1095. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1096. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1097. LocalizeDictionary.Instance.Culture = culture;
  1098. Lang.Culture = culture;
  1099. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
  1100. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1101. }
  1102. else if (string.Equals(language, "English"))
  1103. {
  1104. CurrentLanguage = Enums.Language.English;
  1105. var sysConfig = _configService.GetSystemConfiguration();
  1106. sysConfig.CurrentLanguage = CurrentLanguage;
  1107. _configService.SaveSystemConfiguration(sysConfig);
  1108. var culture = new CultureInfo("en");
  1109. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1110. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1111. LocalizeDictionary.Instance.Culture = culture;
  1112. Lang.Culture = culture;
  1113. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  1114. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1115. }
  1116. else if (string.Equals(language, "Japanese"))
  1117. {
  1118. CurrentLanguage = Enums.Language.Japanese;
  1119. var sysConfig = _configService.GetSystemConfiguration();
  1120. sysConfig.CurrentLanguage = CurrentLanguage;
  1121. _configService.SaveSystemConfiguration(sysConfig);
  1122. var culture = new CultureInfo("ja-JP");
  1123. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1124. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1125. LocalizeDictionary.Instance.Culture = culture;
  1126. Lang.Culture = culture;
  1127. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  1128. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1129. }
  1130. else if (string.Equals(language, "Vietnamese"))
  1131. {
  1132. CurrentLanguage = Enums.Language.Vietnamese;
  1133. var sysConfig = _configService.GetSystemConfiguration();
  1134. sysConfig.CurrentLanguage = CurrentLanguage;
  1135. _configService.SaveSystemConfiguration(sysConfig);
  1136. var culture = new CultureInfo("vi");
  1137. App.Current.Dispatcher.Thread.CurrentCulture = culture;
  1138. App.Current.Dispatcher.Thread.CurrentUICulture = culture;
  1139. LocalizeDictionary.Instance.Culture = culture;
  1140. Lang.Culture = culture;
  1141. Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
  1142. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1143. }
  1144. }
  1145. #endregion
  1146. private void OnLoad()
  1147. {
  1148. if (!File.Exists(FilePath.ScanRS232ConfigPath))
  1149. {
  1150. var scan = new ScanRs232ConfigModel();
  1151. FileHelper.WriteJsonFile(scan, FilePath.ScanRS232ConfigPath);
  1152. }
  1153. this.ScanConfig = FileHelper.ReadJsonFile<ScanRs232ConfigModel>(FilePath.ScanRS232ConfigPath);
  1154. }
  1155. private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  1156. {
  1157. switch (e.PropertyName)
  1158. {
  1159. case "Title1":
  1160. Application.Current.Resources["Font.Size.Title1"] = Title1;
  1161. break;
  1162. case "Title2":
  1163. Application.Current.Resources["Font.Size.Title2"] = Title2;
  1164. break;
  1165. case "Title3":
  1166. Application.Current.Resources["Font.Size.Title3"] = Title3;
  1167. break;
  1168. case "Title4":
  1169. Application.Current.Resources["Font.Size.Title4"] = Title4;
  1170. break;
  1171. case "Body1":
  1172. Application.Current.Resources["Font.Size.Body1"] = Body1;
  1173. break;
  1174. case "Body2":
  1175. Application.Current.Resources["Font.Size.Body2"] = Body2;
  1176. break;
  1177. case "Body3":
  1178. Application.Current.Resources["Font.Size.Body3"] = Body3;
  1179. break;
  1180. case "Body4":
  1181. Application.Current.Resources["Font.Size.Body4"] = Body4;
  1182. break;
  1183. case "Captions1":
  1184. Application.Current.Resources["Font.Size.Captions1"] = Captions1;
  1185. break;
  1186. case "Captions2":
  1187. Application.Current.Resources["Font.Size.Captions2"] = Captions2;
  1188. break;
  1189. case "Captions3":
  1190. Application.Current.Resources["Font.Size.Captions3"] = Captions3;
  1191. break;
  1192. case "Captions4":
  1193. Application.Current.Resources["Font.Size.Captions4"] = Captions4;
  1194. break;
  1195. default:
  1196. break;
  1197. }
  1198. }
  1199. private void ExecuteCheckStatusCommandCommand()
  1200. {
  1201. _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
  1202. }
  1203. #endregion
  1204. #region 继承
  1205. /// <summary>
  1206. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  1207. /// </summary>
  1208. /// <param name="navigationContext"></param>
  1209. /// <param name="continuationCallback"></param>
  1210. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  1211. {
  1212. continuationCallback(true);
  1213. }
  1214. /// <summary>
  1215. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  1216. /// </summary>
  1217. /// <param name="navigationContext"></param>
  1218. /// <exception cref="NotImplementedException"></exception>
  1219. public async void OnNavigatedTo(NavigationContext navigationContext)
  1220. {
  1221. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator|| _systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Engineer)
  1222. {
  1223. IsAllowEdit = false;
  1224. }
  1225. else
  1226. {
  1227. IsAllowEdit = true;
  1228. }
  1229. if (RobotList == null)
  1230. {
  1231. RobotList = new ObservableCollection<RobotInfo>();
  1232. var robots = _configService.GetAllRobots();
  1233. foreach (var robot in robots)
  1234. {
  1235. RobotList.Add(robot);
  1236. }
  1237. }
  1238. if (ScannerList == null)
  1239. {
  1240. ScannerList = new ObservableCollection<ScannerInfo>();
  1241. var scanners = _configService.GetAllScanners();
  1242. foreach (var scanner in scanners)
  1243. {
  1244. ScannerList.Add(scanner);
  1245. }
  1246. }
  1247. if (CameraList == null)
  1248. {
  1249. CameraList = new ObservableCollection<CameraInfo>();
  1250. var cameras = _configService.GetAllCameras();
  1251. foreach (var camera in cameras)
  1252. {
  1253. CameraList.Add(camera);
  1254. }
  1255. }
  1256. if (FeederList == null)
  1257. {
  1258. FeederList = new ObservableCollection<FeederInfo>();
  1259. var feeders = _configService.GetAllFeeders();
  1260. foreach (var feeder in feeders)
  1261. {
  1262. FeederList.Add(feeder);
  1263. }
  1264. }
  1265. if (PlcList == null)
  1266. {
  1267. PlcList = new ObservableCollection<PlcInfo>();
  1268. var plcs = _configService.GetAllPlcs();
  1269. foreach (var plc in plcs)
  1270. {
  1271. PlcList.Add(plc);
  1272. }
  1273. }
  1274. // load light controllers
  1275. if (LightControllerList == null)
  1276. {
  1277. LightControllerList = new ObservableCollection<LightControllerConfig>();
  1278. var controllers = _configService.GetAllLightControllers();
  1279. foreach (var ctrl in controllers)
  1280. {
  1281. LightControllerList.Add(ctrl);
  1282. }
  1283. }
  1284. if (BgTcp == null)
  1285. {
  1286. BgTcp = _configService.GetBgTcp();
  1287. }
  1288. if (BgModbus == null)
  1289. {
  1290. BgModbus = _configService.GetBgModbusTcp();
  1291. }
  1292. if (DeviceInfoList == null || DeviceInfoList.Count == 0)
  1293. {
  1294. // load device info list (支持多设备)
  1295. var devices = _configService.GetAllDeviceInfos();
  1296. DeviceInfoList = new ObservableCollection<DeviceInfo>(devices);
  1297. // 默认选中第一个设备
  1298. if (DeviceInfoList.Count > 0)
  1299. {
  1300. SelectDeviceInfo = DeviceInfoList[0];
  1301. }
  1302. }
  1303. if (CardReaderConfig == null)
  1304. {
  1305. // load card reader config
  1306. CardReaderConfig = _configService.GetCardReaderConfig();
  1307. }
  1308. CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
  1309. // load system parameters into UI
  1310. var sys = _configService.GetSystemConfiguration();
  1311. if (sys != null)
  1312. {
  1313. WorkMode = sys.WorkMode;
  1314. PickPointNum = sys.PickPointNum;
  1315. DowmCameraNum = sys.DowmCameraNum;
  1316. WorkMode = sys.WorkMode;
  1317. PickPointNum = sys.PickPointNum;
  1318. DowmCameraNum = sys.DowmCameraNum;
  1319. UpCameraPickNum = sys.UpCameraPickNum;
  1320. UpCameraPutNum = sys.UpCameraPutNum;
  1321. UPCameracheckNum = sys.UPCameracheckNum;
  1322. FixedCameraPickNum = sys.FixedCameraPickNum;
  1323. FixedCameraPutNum = sys.FixedCameraPutNum;
  1324. FixedCameracheckNum = sys.FixedCameracheckNum;
  1325. IsSaveScrewCurve = sys.IsSaveScrewCurve;
  1326. ScrewCurvePath = sys.ScrewCurvePath;
  1327. }
  1328. if (isFirstLoad)
  1329. {
  1330. Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
  1331. Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
  1332. Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
  1333. Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
  1334. Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
  1335. Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
  1336. Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
  1337. Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
  1338. Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
  1339. Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
  1340. Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
  1341. Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
  1342. this.PropertyChanged += OnPropertyChanged;
  1343. isFirstLoad = false;
  1344. }
  1345. try
  1346. {
  1347. ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
  1348. }
  1349. catch (Exception ex)
  1350. {
  1351. LogHelper.WriteLogError("加载产品列表时出错", ex);
  1352. }
  1353. }
  1354. /// <summary>
  1355. /// 是否允许导航到此视图模型。
  1356. /// </summary>
  1357. /// <param name="navigationContext"></param>
  1358. /// <returns></returns>
  1359. public bool IsNavigationTarget(NavigationContext navigationContext)
  1360. {
  1361. return true;
  1362. }
  1363. /// <summary>
  1364. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1365. /// </summary>
  1366. /// <param name="navigationContext"></param>
  1367. public void OnNavigatedFrom(NavigationContext navigationContext)
  1368. {
  1369. }
  1370. #endregion
  1371. private bool _IsAllowEdit = false;
  1372. public bool IsAllowEdit
  1373. {
  1374. get { return _IsAllowEdit; }
  1375. set { SetProperty(ref _IsAllowEdit, value); }
  1376. }
  1377. private void LoginChange(Models.User user)
  1378. {
  1379. if (user.userPart == Enums.UserPart.Operator)
  1380. {
  1381. IsAllowEdit = false;
  1382. }
  1383. else
  1384. {
  1385. IsAllowEdit = true;
  1386. }
  1387. }
  1388. #region 系统参数
  1389. private Int16 _WorkMode = 0;
  1390. /// <summary>
  1391. /// 工作模式 =1 拍1打1 =2 拍1打所有
  1392. /// </summary>
  1393. public Int16 WorkMode
  1394. {
  1395. get { return _WorkMode; }
  1396. set { SetProperty(ref _WorkMode, value); }
  1397. }
  1398. private Int16 _PickPointNum = 0;
  1399. /// <summary>
  1400. /// 取料位置 =0 不需要取料 =1 需要取料
  1401. /// </summary>
  1402. public Int16 PickPointNum
  1403. {
  1404. get { return _PickPointNum; }
  1405. set { SetProperty(ref _PickPointNum, value); }
  1406. }
  1407. private Int16 _DowmCameraNum = 0;
  1408. /// <summary>
  1409. /// 下相机拍照次数
  1410. /// </summary>
  1411. public Int16 DowmCameraNum
  1412. {
  1413. get => _DowmCameraNum;
  1414. set => SetProperty(ref _DowmCameraNum, value);
  1415. }
  1416. private Int16 _UpCameraPickNum = 0;
  1417. /// <summary>
  1418. /// 上相机取料拍照次数
  1419. /// </summary>
  1420. public Int16 UpCameraPickNum
  1421. {
  1422. get => _UpCameraPickNum;
  1423. set => SetProperty(ref _UpCameraPickNum, value);
  1424. }
  1425. private Int16 _UpCameraPutNum = 0;
  1426. /// <summary>
  1427. /// 上相机放料拍照次数
  1428. /// </summary>
  1429. public Int16 UpCameraPutNum
  1430. {
  1431. get => _UpCameraPutNum;
  1432. set => SetProperty(ref _UpCameraPutNum, value);
  1433. }
  1434. private Int16 _UPCameracheckNum = 0;
  1435. /// <summary>
  1436. /// 上相机锁附/组装次数
  1437. /// </summary>
  1438. public Int16 UPCameracheckNum
  1439. {
  1440. get => _UPCameracheckNum;
  1441. set => SetProperty(ref _UPCameracheckNum, value);
  1442. }
  1443. private Int16 _FixedCameraPickNum = 0;
  1444. /// <summary>
  1445. /// 取料固定位置拍产品相机数量
  1446. /// </summary>
  1447. public Int16 FixedCameraPickNum
  1448. {
  1449. get => _FixedCameraPickNum;
  1450. set => SetProperty(ref _FixedCameraPickNum, value);
  1451. }
  1452. private Int16 _FixedCameraPutNum = 0;
  1453. /// <summary>
  1454. /// 锁附/组装固定位置拍产品相机数量
  1455. /// </summary>
  1456. public Int16 FixedCameraPutNum
  1457. {
  1458. get => _FixedCameraPutNum;
  1459. set => SetProperty(ref _FixedCameraPutNum, value);
  1460. }
  1461. private Int16 _FixedCameracheckNum = 0;
  1462. /// <summary>
  1463. /// 固定相机检测锁附/组装次数
  1464. /// </summary>
  1465. public Int16 FixedCameracheckNum
  1466. {
  1467. get => _FixedCameracheckNum;
  1468. set => SetProperty(ref _FixedCameracheckNum, value);
  1469. }
  1470. async void ExecuteSaveSystemParametersCommand()
  1471. {
  1472. var view = new ShowMessage($"AAS", "是否保存系统参数?");
  1473. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1474. if (result != null && result is bool && (bool)result)
  1475. {
  1476. try
  1477. {
  1478. ExecuteSaveCardReaderConfigCommand();
  1479. FileHelper.WriteJsonFile(this.ScanConfig, FilePath.ScanRS232ConfigPath);
  1480. var sysConfig = _configService.GetSystemConfiguration();
  1481. sysConfig.WorkMode = WorkMode;
  1482. sysConfig.PickPointNum = PickPointNum;
  1483. sysConfig.DowmCameraNum = DowmCameraNum;
  1484. sysConfig.UpCameraPickNum = UpCameraPickNum;
  1485. sysConfig.UpCameraPutNum = UpCameraPutNum;
  1486. sysConfig.UPCameracheckNum = UPCameracheckNum;
  1487. sysConfig.FixedCameraPickNum = FixedCameraPickNum;
  1488. sysConfig.FixedCameraPutNum = FixedCameraPutNum;
  1489. sysConfig.FixedCameracheckNum = FixedCameracheckNum;
  1490. sysConfig.IsSaveScrewCurve = IsSaveScrewCurve;
  1491. sysConfig.ScrewCurvePath = ScrewCurvePath;
  1492. _configService.SaveSystemConfiguration(sysConfig);
  1493. await management.WriteSystemParameterToPlcAsync(sysConfig);
  1494. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1495. }
  1496. catch (Exception ex)
  1497. {
  1498. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1499. }
  1500. }
  1501. }
  1502. /// <summary>
  1503. /// 选择锁付曲线图保存路径
  1504. /// </summary>
  1505. void ExecuteBrowseScrewCurvePathCommand()
  1506. {
  1507. try
  1508. {
  1509. using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
  1510. {
  1511. dlg.Description = "选择锁付曲线图保存路径";
  1512. dlg.ShowNewFolderButton = true;
  1513. if (!string.IsNullOrEmpty(ScrewCurvePath)) dlg.SelectedPath = ScrewCurvePath;
  1514. var result = dlg.ShowDialog();
  1515. if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
  1516. {
  1517. ScrewCurvePath = dlg.SelectedPath;
  1518. }
  1519. }
  1520. }
  1521. catch (Exception ex)
  1522. {
  1523. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 2 });
  1524. }
  1525. }
  1526. /// <summary>
  1527. /// 保存读卡器配置
  1528. /// </summary>
  1529. void ExecuteSaveCardReaderConfigCommand()
  1530. {
  1531. try
  1532. {
  1533. _configService.SaveCardReaderConfig(CardReaderConfig);
  1534. }
  1535. catch (Exception ex)
  1536. {
  1537. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1538. }
  1539. }
  1540. #endregion
  1541. #region 设备信息
  1542. /// <summary>
  1543. /// 保存设备信息
  1544. /// </summary>
  1545. void ExecuteSaveDeviceInfoCommand()
  1546. {
  1547. try
  1548. {
  1549. if (DeviceInfoList != null && DeviceInfoList.Count > 0)
  1550. {
  1551. // 保存所有设备信息
  1552. _configService.SaveAllDeviceInfos(DeviceInfoList);
  1553. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1554. }
  1555. }
  1556. catch (Exception ex)
  1557. {
  1558. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1559. }
  1560. }
  1561. /// <summary>
  1562. /// 添加新设备
  1563. /// </summary>
  1564. void ExecuteAddDeviceInfoCommand()
  1565. {
  1566. try
  1567. {
  1568. var newDevice = _configService.AddDeviceInfo();
  1569. if (DeviceInfoList == null)
  1570. {
  1571. DeviceInfoList = new ObservableCollection<DeviceInfo>();
  1572. }
  1573. DeviceInfoList.Add(newDevice);
  1574. SelectDeviceInfo = newDevice;
  1575. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1576. }
  1577. catch (Exception ex)
  1578. {
  1579. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1580. }
  1581. }
  1582. /// <summary>
  1583. /// 删除当前选中的设备
  1584. /// </summary>
  1585. void ExecuteRemoveDeviceInfoCommand()
  1586. {
  1587. try
  1588. {
  1589. if (SelectDeviceInfo != null && DeviceInfoList != null && DeviceInfoList.Count > 1)
  1590. {
  1591. var deviceNo = SelectDeviceInfo.DeviceNo;
  1592. if (_configService.RemoveDeviceInfo(deviceNo))
  1593. {
  1594. DeviceInfoList.Remove(SelectDeviceInfo);
  1595. SelectDeviceInfo = DeviceInfoList.FirstOrDefault();
  1596. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1597. }
  1598. }
  1599. else
  1600. {
  1601. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "至少保留一个设备", Duration = 2 });
  1602. }
  1603. }
  1604. catch (Exception ex)
  1605. {
  1606. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1607. }
  1608. }
  1609. /// <summary>
  1610. /// 选择CSV存储路径
  1611. /// </summary>
  1612. void ExecuteSelectSaveImagePathCommand()
  1613. {
  1614. if (DeviceInfo == null)
  1615. {
  1616. return;
  1617. }
  1618. using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog())
  1619. {
  1620. // Optional: set the initial directory
  1621. //dialog.SelectedPath = @"C:\";
  1622. // Show the folder browser dialog
  1623. System.Windows.Forms.DialogResult result = dialog.ShowDialog();
  1624. if (result == System.Windows.Forms.DialogResult.OK)
  1625. {
  1626. DeviceInfo.SaveCsvPath = dialog.SelectedPath;
  1627. }
  1628. }
  1629. }
  1630. #endregion
  1631. #region 产品与mes绑定
  1632. private async void ExecuteGetProWithMesCommand()
  1633. {
  1634. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1635. if (v == null)
  1636. {
  1637. ProMesInfo.ProductCode = "";
  1638. ProMesInfo.ProductColor = "";
  1639. ProMesInfo.ProductKBSN = "";
  1640. ProMesInfo.ProductLoadMode = 0;
  1641. }
  1642. else
  1643. {
  1644. ProMesInfo.ProductCode = v.ProductCode;
  1645. ProMesInfo.ProductColor = v.ProductColor;
  1646. ProMesInfo.ProductKBSN = v.ProductKBSN;
  1647. ProMesInfo.ProductLoadMode = v.ProductLoadMode;
  1648. }
  1649. }
  1650. private async void ExecuteDeleteProWithMesCommand()
  1651. {
  1652. var v = await _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
  1653. if (v > 0)
  1654. {
  1655. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "删除成功", Duration = 1 });
  1656. var F = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1657. if (F == null)
  1658. {
  1659. ProMesInfo.ProductCode = "";
  1660. ProMesInfo.ProductColor = "";
  1661. ProMesInfo.ProductKBSN = "";
  1662. ProMesInfo.ProductLoadMode = 0;
  1663. }
  1664. }
  1665. }
  1666. private async void ExecuteSaveProWithMesCommandAsync()
  1667. {
  1668. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1669. if (v == null)
  1670. {
  1671. await _systemDatabaseService.InsertProWithMesAsync(ProMesInfo, SelectProduct);
  1672. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加成功", Duration = 1 });
  1673. }
  1674. else
  1675. {
  1676. var n = await _systemDatabaseService.UpdateProductWithMesAsync(ProMesInfo, SelectProduct);
  1677. if (n > 0)
  1678. {
  1679. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "更新成功", Duration = 1 });
  1680. }
  1681. }
  1682. }
  1683. #endregion
  1684. }
  1685. }