SettingViewModel.cs 71 KB

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