SettingViewModel.cs 70 KB

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