SettingViewModel.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  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. }
  1131. #endregion
  1132. private void OnLoad()
  1133. {
  1134. if (!File.Exists(FilePath.ScanRS232ConfigPath))
  1135. {
  1136. var scan = new ScanRs232ConfigModel();
  1137. FileHelper.WriteJsonFile(scan, FilePath.ScanRS232ConfigPath);
  1138. }
  1139. this.ScanConfig = FileHelper.ReadJsonFile<ScanRs232ConfigModel>(FilePath.ScanRS232ConfigPath);
  1140. }
  1141. private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  1142. {
  1143. switch (e.PropertyName)
  1144. {
  1145. case "Title1":
  1146. Application.Current.Resources["Font.Size.Title1"] = Title1;
  1147. break;
  1148. case "Title2":
  1149. Application.Current.Resources["Font.Size.Title2"] = Title2;
  1150. break;
  1151. case "Title3":
  1152. Application.Current.Resources["Font.Size.Title3"] = Title3;
  1153. break;
  1154. case "Title4":
  1155. Application.Current.Resources["Font.Size.Title4"] = Title4;
  1156. break;
  1157. case "Body1":
  1158. Application.Current.Resources["Font.Size.Body1"] = Body1;
  1159. break;
  1160. case "Body2":
  1161. Application.Current.Resources["Font.Size.Body2"] = Body2;
  1162. break;
  1163. case "Body3":
  1164. Application.Current.Resources["Font.Size.Body3"] = Body3;
  1165. break;
  1166. case "Body4":
  1167. Application.Current.Resources["Font.Size.Body4"] = Body4;
  1168. break;
  1169. case "Captions1":
  1170. Application.Current.Resources["Font.Size.Captions1"] = Captions1;
  1171. break;
  1172. case "Captions2":
  1173. Application.Current.Resources["Font.Size.Captions2"] = Captions2;
  1174. break;
  1175. case "Captions3":
  1176. Application.Current.Resources["Font.Size.Captions3"] = Captions3;
  1177. break;
  1178. case "Captions4":
  1179. Application.Current.Resources["Font.Size.Captions4"] = Captions4;
  1180. break;
  1181. default:
  1182. break;
  1183. }
  1184. }
  1185. private void ExecuteCheckStatusCommandCommand()
  1186. {
  1187. _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
  1188. }
  1189. #endregion
  1190. #region 继承
  1191. /// <summary>
  1192. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  1193. /// </summary>
  1194. /// <param name="navigationContext"></param>
  1195. /// <param name="continuationCallback"></param>
  1196. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  1197. {
  1198. continuationCallback(true);
  1199. }
  1200. /// <summary>
  1201. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  1202. /// </summary>
  1203. /// <param name="navigationContext"></param>
  1204. /// <exception cref="NotImplementedException"></exception>
  1205. public async void OnNavigatedTo(NavigationContext navigationContext)
  1206. {
  1207. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  1208. {
  1209. IsAllowEdit = false;
  1210. }
  1211. else
  1212. {
  1213. IsAllowEdit = true;
  1214. }
  1215. if (RobotList == null)
  1216. {
  1217. RobotList = new ObservableCollection<RobotInfo>();
  1218. var robots = _configService.GetAllRobots();
  1219. foreach (var robot in robots)
  1220. {
  1221. RobotList.Add(robot);
  1222. }
  1223. }
  1224. if (ScannerList == null)
  1225. {
  1226. ScannerList = new ObservableCollection<ScannerInfo>();
  1227. var scanners = _configService.GetAllScanners();
  1228. foreach (var scanner in scanners)
  1229. {
  1230. ScannerList.Add(scanner);
  1231. }
  1232. }
  1233. if (CameraList == null)
  1234. {
  1235. CameraList = new ObservableCollection<CameraInfo>();
  1236. var cameras = _configService.GetAllCameras();
  1237. foreach (var camera in cameras)
  1238. {
  1239. CameraList.Add(camera);
  1240. }
  1241. }
  1242. if (FeederList == null)
  1243. {
  1244. FeederList = new ObservableCollection<FeederInfo>();
  1245. var feeders = _configService.GetAllFeeders();
  1246. foreach (var feeder in feeders)
  1247. {
  1248. FeederList.Add(feeder);
  1249. }
  1250. }
  1251. if (PlcList == null)
  1252. {
  1253. PlcList = new ObservableCollection<PlcInfo>();
  1254. var plcs = _configService.GetAllPlcs();
  1255. foreach (var plc in plcs)
  1256. {
  1257. PlcList.Add(plc);
  1258. }
  1259. }
  1260. // load light controllers
  1261. if (LightControllerList == null)
  1262. {
  1263. LightControllerList = new ObservableCollection<LightControllerConfig>();
  1264. var controllers = _configService.GetAllLightControllers();
  1265. foreach (var ctrl in controllers)
  1266. {
  1267. LightControllerList.Add(ctrl);
  1268. }
  1269. }
  1270. if (BgTcp == null)
  1271. {
  1272. BgTcp = _configService.GetBgTcp();
  1273. }
  1274. if (BgModbus == null)
  1275. {
  1276. BgModbus = _configService.GetBgModbusTcp();
  1277. }
  1278. if (DeviceInfoList == null || DeviceInfoList.Count == 0)
  1279. {
  1280. // load device info list (支持多设备)
  1281. var devices = _configService.GetAllDeviceInfos();
  1282. DeviceInfoList = new ObservableCollection<DeviceInfo>(devices);
  1283. // 默认选中第一个设备
  1284. if (DeviceInfoList.Count > 0)
  1285. {
  1286. SelectDeviceInfo = DeviceInfoList[0];
  1287. }
  1288. }
  1289. if (CardReaderConfig == null)
  1290. {
  1291. // load card reader config
  1292. CardReaderConfig = _configService.GetCardReaderConfig();
  1293. }
  1294. CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
  1295. // load system parameters into UI
  1296. var sys = _configService.GetSystemConfiguration();
  1297. if (sys != null)
  1298. {
  1299. WorkMode = sys.WorkMode;
  1300. PickPointNum = sys.PickPointNum;
  1301. DowmCameraNum = sys.DowmCameraNum;
  1302. WorkMode = sys.WorkMode;
  1303. PickPointNum = sys.PickPointNum;
  1304. DowmCameraNum = sys.DowmCameraNum;
  1305. UpCameraPickNum = sys.UpCameraPickNum;
  1306. UpCameraPutNum = sys.UpCameraPutNum;
  1307. UPCameracheckNum = sys.UPCameracheckNum;
  1308. FixedCameraPickNum = sys.FixedCameraPickNum;
  1309. FixedCameraPutNum = sys.FixedCameraPutNum;
  1310. FixedCameracheckNum = sys.FixedCameracheckNum;
  1311. IsSaveScrewCurve = sys.IsSaveScrewCurve;
  1312. ScrewCurvePath = sys.ScrewCurvePath;
  1313. }
  1314. if (isFirstLoad)
  1315. {
  1316. Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
  1317. Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
  1318. Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
  1319. Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
  1320. Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
  1321. Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
  1322. Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
  1323. Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
  1324. Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
  1325. Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
  1326. Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
  1327. Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
  1328. this.PropertyChanged += OnPropertyChanged;
  1329. isFirstLoad = false;
  1330. }
  1331. try
  1332. {
  1333. ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
  1334. }
  1335. catch (Exception ex)
  1336. {
  1337. LogHelper.WriteLogError("加载产品列表时出错", ex);
  1338. }
  1339. }
  1340. /// <summary>
  1341. /// 是否允许导航到此视图模型。
  1342. /// </summary>
  1343. /// <param name="navigationContext"></param>
  1344. /// <returns></returns>
  1345. public bool IsNavigationTarget(NavigationContext navigationContext)
  1346. {
  1347. return true;
  1348. }
  1349. /// <summary>
  1350. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1351. /// </summary>
  1352. /// <param name="navigationContext"></param>
  1353. public void OnNavigatedFrom(NavigationContext navigationContext)
  1354. {
  1355. }
  1356. #endregion
  1357. private bool _IsAllowEdit = false;
  1358. public bool IsAllowEdit
  1359. {
  1360. get { return _IsAllowEdit; }
  1361. set { SetProperty(ref _IsAllowEdit, value); }
  1362. }
  1363. private void LoginChange(Models.User user)
  1364. {
  1365. if (user.userPart == Enums.UserPart.Operator)
  1366. {
  1367. IsAllowEdit = false;
  1368. }
  1369. else
  1370. {
  1371. IsAllowEdit = true;
  1372. }
  1373. }
  1374. #region 系统参数
  1375. private Int16 _WorkMode = 0;
  1376. /// <summary>
  1377. /// 工作模式 =1 拍1打1 =2 拍1打所有
  1378. /// </summary>
  1379. public Int16 WorkMode
  1380. {
  1381. get { return _WorkMode; }
  1382. set { SetProperty(ref _WorkMode, value); }
  1383. }
  1384. private Int16 _PickPointNum = 0;
  1385. /// <summary>
  1386. /// 取料位置 =0 不需要取料 =1 需要取料
  1387. /// </summary>
  1388. public Int16 PickPointNum
  1389. {
  1390. get { return _PickPointNum; }
  1391. set { SetProperty(ref _PickPointNum, value); }
  1392. }
  1393. private Int16 _DowmCameraNum = 0;
  1394. /// <summary>
  1395. /// 下相机拍照次数
  1396. /// </summary>
  1397. public Int16 DowmCameraNum
  1398. {
  1399. get => _DowmCameraNum;
  1400. set => SetProperty(ref _DowmCameraNum, value);
  1401. }
  1402. private Int16 _UpCameraPickNum = 0;
  1403. /// <summary>
  1404. /// 上相机取料拍照次数
  1405. /// </summary>
  1406. public Int16 UpCameraPickNum
  1407. {
  1408. get => _UpCameraPickNum;
  1409. set => SetProperty(ref _UpCameraPickNum, value);
  1410. }
  1411. private Int16 _UpCameraPutNum = 0;
  1412. /// <summary>
  1413. /// 上相机放料拍照次数
  1414. /// </summary>
  1415. public Int16 UpCameraPutNum
  1416. {
  1417. get => _UpCameraPutNum;
  1418. set => SetProperty(ref _UpCameraPutNum, value);
  1419. }
  1420. private Int16 _UPCameracheckNum = 0;
  1421. /// <summary>
  1422. /// 上相机锁附/组装次数
  1423. /// </summary>
  1424. public Int16 UPCameracheckNum
  1425. {
  1426. get => _UPCameracheckNum;
  1427. set => SetProperty(ref _UPCameracheckNum, value);
  1428. }
  1429. private Int16 _FixedCameraPickNum = 0;
  1430. /// <summary>
  1431. /// 取料固定位置拍产品相机数量
  1432. /// </summary>
  1433. public Int16 FixedCameraPickNum
  1434. {
  1435. get => _FixedCameraPickNum;
  1436. set => SetProperty(ref _FixedCameraPickNum, value);
  1437. }
  1438. private Int16 _FixedCameraPutNum = 0;
  1439. /// <summary>
  1440. /// 锁附/组装固定位置拍产品相机数量
  1441. /// </summary>
  1442. public Int16 FixedCameraPutNum
  1443. {
  1444. get => _FixedCameraPutNum;
  1445. set => SetProperty(ref _FixedCameraPutNum, value);
  1446. }
  1447. private Int16 _FixedCameracheckNum = 0;
  1448. /// <summary>
  1449. /// 固定相机检测锁附/组装次数
  1450. /// </summary>
  1451. public Int16 FixedCameracheckNum
  1452. {
  1453. get => _FixedCameracheckNum;
  1454. set => SetProperty(ref _FixedCameracheckNum, value);
  1455. }
  1456. async void ExecuteSaveSystemParametersCommand()
  1457. {
  1458. var view = new ShowMessage($"AAS", "是否保存系统参数?");
  1459. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1460. if (result != null && result is bool && (bool)result)
  1461. {
  1462. try
  1463. {
  1464. ExecuteSaveCardReaderConfigCommand();
  1465. FileHelper.WriteJsonFile(this.ScanConfig, FilePath.ScanRS232ConfigPath);
  1466. var sysConfig = _configService.GetSystemConfiguration();
  1467. sysConfig.WorkMode = WorkMode;
  1468. sysConfig.PickPointNum = PickPointNum;
  1469. sysConfig.DowmCameraNum = DowmCameraNum;
  1470. sysConfig.UpCameraPickNum = UpCameraPickNum;
  1471. sysConfig.UpCameraPutNum = UpCameraPutNum;
  1472. sysConfig.UPCameracheckNum = UPCameracheckNum;
  1473. sysConfig.FixedCameraPickNum = FixedCameraPickNum;
  1474. sysConfig.FixedCameraPutNum = FixedCameraPutNum;
  1475. sysConfig.FixedCameracheckNum = FixedCameracheckNum;
  1476. sysConfig.IsSaveScrewCurve = IsSaveScrewCurve;
  1477. sysConfig.ScrewCurvePath = ScrewCurvePath;
  1478. _configService.SaveSystemConfiguration(sysConfig);
  1479. await management.WriteSystemParameterToPlcAsync(sysConfig);
  1480. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1481. }
  1482. catch (Exception ex)
  1483. {
  1484. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1485. }
  1486. }
  1487. }
  1488. /// <summary>
  1489. /// 选择锁付曲线图保存路径
  1490. /// </summary>
  1491. void ExecuteBrowseScrewCurvePathCommand()
  1492. {
  1493. try
  1494. {
  1495. using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
  1496. {
  1497. dlg.Description = "选择锁付曲线图保存路径";
  1498. dlg.ShowNewFolderButton = true;
  1499. if (!string.IsNullOrEmpty(ScrewCurvePath)) dlg.SelectedPath = ScrewCurvePath;
  1500. var result = dlg.ShowDialog();
  1501. if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
  1502. {
  1503. ScrewCurvePath = dlg.SelectedPath;
  1504. }
  1505. }
  1506. }
  1507. catch (Exception ex)
  1508. {
  1509. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 2 });
  1510. }
  1511. }
  1512. /// <summary>
  1513. /// 保存读卡器配置
  1514. /// </summary>
  1515. void ExecuteSaveCardReaderConfigCommand()
  1516. {
  1517. try
  1518. {
  1519. _configService.SaveCardReaderConfig(CardReaderConfig);
  1520. }
  1521. catch (Exception ex)
  1522. {
  1523. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1524. }
  1525. }
  1526. #endregion
  1527. #region 设备信息
  1528. /// <summary>
  1529. /// 保存设备信息
  1530. /// </summary>
  1531. void ExecuteSaveDeviceInfoCommand()
  1532. {
  1533. try
  1534. {
  1535. if (DeviceInfoList != null && DeviceInfoList.Count > 0)
  1536. {
  1537. // 保存所有设备信息
  1538. _configService.SaveAllDeviceInfos(DeviceInfoList);
  1539. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1540. }
  1541. }
  1542. catch (Exception ex)
  1543. {
  1544. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1545. }
  1546. }
  1547. /// <summary>
  1548. /// 添加新设备
  1549. /// </summary>
  1550. void ExecuteAddDeviceInfoCommand()
  1551. {
  1552. try
  1553. {
  1554. var newDevice = _configService.AddDeviceInfo();
  1555. if (DeviceInfoList == null)
  1556. {
  1557. DeviceInfoList = new ObservableCollection<DeviceInfo>();
  1558. }
  1559. DeviceInfoList.Add(newDevice);
  1560. SelectDeviceInfo = newDevice;
  1561. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1562. }
  1563. catch (Exception ex)
  1564. {
  1565. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1566. }
  1567. }
  1568. /// <summary>
  1569. /// 删除当前选中的设备
  1570. /// </summary>
  1571. void ExecuteRemoveDeviceInfoCommand()
  1572. {
  1573. try
  1574. {
  1575. if (SelectDeviceInfo != null && DeviceInfoList != null && DeviceInfoList.Count > 1)
  1576. {
  1577. var deviceNo = SelectDeviceInfo.DeviceNo;
  1578. if (_configService.RemoveDeviceInfo(deviceNo))
  1579. {
  1580. DeviceInfoList.Remove(SelectDeviceInfo);
  1581. SelectDeviceInfo = DeviceInfoList.FirstOrDefault();
  1582. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1583. }
  1584. }
  1585. else
  1586. {
  1587. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "至少保留一个设备", Duration = 2 });
  1588. }
  1589. }
  1590. catch (Exception ex)
  1591. {
  1592. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1593. }
  1594. }
  1595. /// <summary>
  1596. /// 选择CSV存储路径
  1597. /// </summary>
  1598. void ExecuteSelectSaveImagePathCommand()
  1599. {
  1600. if (DeviceInfo == null)
  1601. {
  1602. return;
  1603. }
  1604. using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog())
  1605. {
  1606. // Optional: set the initial directory
  1607. //dialog.SelectedPath = @"C:\";
  1608. // Show the folder browser dialog
  1609. System.Windows.Forms.DialogResult result = dialog.ShowDialog();
  1610. if (result == System.Windows.Forms.DialogResult.OK)
  1611. {
  1612. DeviceInfo.SaveCsvPath = dialog.SelectedPath;
  1613. }
  1614. }
  1615. }
  1616. #endregion
  1617. #region 产品与mes绑定
  1618. private async void ExecuteGetProWithMesCommand()
  1619. {
  1620. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1621. if (v == null)
  1622. {
  1623. ProMesInfo.ProductCode = "";
  1624. ProMesInfo.ProductColor = "";
  1625. ProMesInfo.ProductKBSN = "";
  1626. ProMesInfo.ProductLoadMode = 0;
  1627. }
  1628. else
  1629. {
  1630. ProMesInfo.ProductCode = v.ProductCode;
  1631. ProMesInfo.ProductColor = v.ProductColor;
  1632. ProMesInfo.ProductKBSN = v.ProductKBSN;
  1633. ProMesInfo.ProductLoadMode = v.ProductLoadMode;
  1634. }
  1635. }
  1636. private async void ExecuteDeleteProWithMesCommand()
  1637. {
  1638. var v = await _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
  1639. if (v > 0)
  1640. {
  1641. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "删除成功", Duration = 1 });
  1642. var F = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1643. if (F == null)
  1644. {
  1645. ProMesInfo.ProductCode = "";
  1646. ProMesInfo.ProductColor = "";
  1647. ProMesInfo.ProductKBSN = "";
  1648. ProMesInfo.ProductLoadMode = 0;
  1649. }
  1650. }
  1651. }
  1652. private async void ExecuteSaveProWithMesCommandAsync()
  1653. {
  1654. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1655. if (v == null)
  1656. {
  1657. await _systemDatabaseService.InsertProWithMesAsync(ProMesInfo, SelectProduct);
  1658. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加成功", Duration = 1 });
  1659. }
  1660. else
  1661. {
  1662. var n = await _systemDatabaseService.UpdateProductWithMesAsync(ProMesInfo, SelectProduct);
  1663. if (n > 0)
  1664. {
  1665. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "更新成功", Duration = 1 });
  1666. }
  1667. }
  1668. }
  1669. #endregion
  1670. }
  1671. }