SettingViewModel.cs 71 KB

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