SettingViewModel.cs 71 KB

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