SettingViewModel.cs 71 KB

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