SettingViewModel.cs 72 KB

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