SettingViewModel.cs 71 KB

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