SettingViewModel.cs 71 KB

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