SettingViewModel.cs 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871
  1. using ICSharpCode.AvalonEdit.Search;
  2. using MaterialDesignThemes.Wpf;
  3. using NPOI.SS.Formula.Functions;
  4. using Opc.Ua;
  5. using Prism.Commands;
  6. using Prism.Events;
  7. using Prism.Ioc;
  8. using Prism.Mvvm;
  9. using Prism.Regions;
  10. using Prism.Services.Dialogs;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Collections.ObjectModel;
  14. using System.ComponentModel;
  15. using System.Drawing.Drawing2D;
  16. using System.Globalization;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Windows;
  21. using Team.FFFeederService.Interfaces;
  22. using TeamAAS_VP.Controls;
  23. using TeamAAS_VP.Core;
  24. using TeamAAS_VP.Core.Cameras;
  25. using TeamAAS_VP.Core.Lights;
  26. using TeamAAS_VP.Enums;
  27. using TeamAAS_VP.Events;
  28. using TeamAAS_VP.Interfaces;
  29. using TeamAAS_VP.Models;
  30. using TeamAAS_VP.Models.Feeder;
  31. using TeamAAS_VP.Models.Lights;
  32. using TeamAAS_VP.Resources.Languages;
  33. using TeamAAS_VP.Services;
  34. using TeamAAS_VP.ViewModels.User;
  35. using TouchSocket.Core;
  36. using WPFLocalizeExtension.Engine;
  37. using static TeamAAS_VP.Models.SystemConfiguration;
  38. namespace TeamAAS_VP.ViewModels
  39. {
  40. public class SettingViewModel : BindableBase, IConfirmNavigationRequest
  41. {
  42. IRegionManager _regionManager;
  43. IEventAggregator _eventAggregator;
  44. IContainerProvider _container;
  45. IDialogService _dialogService;
  46. IConfigService _configService;
  47. IRobotService _robotService;
  48. ICameraService _cameraService;
  49. IFeederService _feeder_service;
  50. IFeederService _feederService;
  51. IPlcService _plcService;
  52. IProductService _productService;
  53. ISystemDatabaseService _systemDatabaseService;
  54. bool isFirstLoad = true;
  55. #region 属性
  56. private Management _management;
  57. public Management management
  58. {
  59. get { return _management; }
  60. set { SetProperty(ref _management, value); }
  61. }
  62. private ObservableCollection<RobotInfo> _RobotList;
  63. public ObservableCollection<RobotInfo> RobotList
  64. {
  65. get { return _RobotList; }
  66. set { SetProperty(ref _RobotList, value); }
  67. }
  68. private ObservableCollection<CameraInfo> _CameraList;
  69. public ObservableCollection<CameraInfo> CameraList
  70. {
  71. get { return _CameraList; }
  72. set { SetProperty(ref _CameraList, value); }
  73. }
  74. private ObservableCollection<FeederInfo> _FeederList;
  75. public ObservableCollection<FeederInfo> FeederList
  76. {
  77. get { return _FeederList; }
  78. set { SetProperty(ref _FeederList, value); }
  79. }
  80. private ObservableCollection<PlcInfo> _PlcList;
  81. public ObservableCollection<PlcInfo> PlcList
  82. {
  83. get { return _PlcList; }
  84. set { SetProperty(ref _PlcList, value); }
  85. }
  86. private Language _CurrentLanguage;
  87. public Language CurrentLanguage
  88. {
  89. get { return _CurrentLanguage; }
  90. set { SetProperty(ref _CurrentLanguage, value); }
  91. }
  92. private RobotInfo _SelectRobot;
  93. /// <summary>
  94. /// 选中的机器人
  95. /// </summary>
  96. public RobotInfo SelectRobot
  97. {
  98. get { return _SelectRobot; }
  99. set
  100. {
  101. SetProperty(ref _SelectRobot, value);
  102. if (value != null && (value.RobotBrand == RobotBrand.XYZ_Platform || value.RobotBrand == RobotBrand.XYZU_Platform))
  103. {
  104. RobotSelectedPlc = PlcList.FirstOrDefault(p => p.Id == value.PLC);
  105. var root = _robotService.GetRobot(SelectRobot.Id);
  106. if (root != null)
  107. {
  108. //ResultsValues.Clear();
  109. //var res = root.GetNodesValue();
  110. //for (int i = 0; i < res.Count; i++)
  111. //{
  112. // if (res[i].StatusCode.Code != 2150891520)
  113. // {
  114. // ResultsValues.Add(res[i].Value.ToString());
  115. // }
  116. // else
  117. // {
  118. // break;
  119. // }
  120. //}
  121. }
  122. }
  123. }
  124. }
  125. private FeederInfo _SelectFeeder;
  126. /// <summary>
  127. /// 选中的Feeder
  128. /// </summary>
  129. public FeederInfo SelectFeeder
  130. {
  131. get { return _SelectFeeder; }
  132. set { SetProperty(ref _SelectFeeder, value); }
  133. }
  134. private PlcInfo _SelectPlc;
  135. public PlcInfo SelectPlc
  136. {
  137. get { return _SelectPlc; }
  138. set { SetProperty(ref _SelectPlc, value); }
  139. }
  140. private ObservableCollection<string> _ResultsValues = new ObservableCollection<string>();
  141. public ObservableCollection<string> ResultsValues { get => _ResultsValues; set => _ResultsValues = value; }
  142. private CameraInfo _SelectCamera;
  143. /// <summary>
  144. /// 选中的Camera
  145. /// </summary>
  146. public CameraInfo SelectCamera
  147. {
  148. get { return _SelectCamera; }
  149. set { SetProperty(ref _SelectCamera, value); }
  150. }
  151. private ObservableCollection<ScrewFeederInfo> _ScrewFeederList;
  152. /// <summary>
  153. /// 螺丝供料器列表
  154. /// </summary>
  155. public ObservableCollection<ScrewFeederInfo> ScrewFeederList
  156. {
  157. get { return _ScrewFeederList; }
  158. set { SetProperty(ref _ScrewFeederList, value); }
  159. }
  160. private ScrewFeederInfo _SelectScrewFeeder;
  161. public ScrewFeederInfo SelectScrewFeeder
  162. {
  163. get { return _SelectScrewFeeder; }
  164. set { SetProperty(ref _SelectScrewFeeder, value); }
  165. }
  166. private double _Title1;
  167. public double Title1
  168. {
  169. get { return _Title1; }
  170. set { SetProperty(ref _Title1, value); }
  171. }
  172. private double _Title2;
  173. public double Title2
  174. {
  175. get { return _Title2; }
  176. set { SetProperty(ref _Title2, value); }
  177. }
  178. private double _Title3;
  179. public double Title3
  180. {
  181. get { return _Title3; }
  182. set { SetProperty(ref _Title3, value); }
  183. }
  184. private double _Title4;
  185. public double Title4
  186. {
  187. get { return _Title4; }
  188. set { SetProperty(ref _Title4, value); }
  189. }
  190. private double _Body1;
  191. public double Body1
  192. {
  193. get { return _Body1; }
  194. set { SetProperty(ref _Body1, value); }
  195. }
  196. private double _Body2;
  197. public double Body2
  198. {
  199. get { return _Body2; }
  200. set { SetProperty(ref _Body2, value); }
  201. }
  202. private double _Body3;
  203. public double Body3
  204. {
  205. get { return _Body3; }
  206. set { SetProperty(ref _Body3, value); }
  207. }
  208. private double _Body4;
  209. public double Body4
  210. {
  211. get { return _Body4; }
  212. set { SetProperty(ref _Body4, value); }
  213. }
  214. private double _Captions1;
  215. public double Captions1
  216. {
  217. get { return _Captions1; }
  218. set { SetProperty(ref _Captions1, value); }
  219. }
  220. private double _Captions2;
  221. public double Captions2
  222. {
  223. get { return _Captions2; }
  224. set { SetProperty(ref _Captions2, value); }
  225. }
  226. private double _Captions3;
  227. public double Captions3
  228. {
  229. get { return _Captions3; }
  230. set { SetProperty(ref _Captions3, value); }
  231. }
  232. private double _Captions4;
  233. public double Captions4
  234. {
  235. get { return _Captions4; }
  236. set { SetProperty(ref _Captions4, value); }
  237. }
  238. private PlcInfo _RobotSelectedPlc;
  239. public PlcInfo RobotSelectedPlc
  240. {
  241. get { return _RobotSelectedPlc; }
  242. set
  243. {
  244. SetProperty(ref _RobotSelectedPlc, value);
  245. if (SelectRobot != null)
  246. {
  247. if (value != null)
  248. {
  249. SelectRobot.PLC = value.Id;
  250. }
  251. else
  252. {
  253. SelectRobot.PLC = Guid.Empty;
  254. }
  255. }
  256. }
  257. }
  258. private BgModbusTcp _BgModbus;
  259. public BgModbusTcp BgModbus
  260. {
  261. get { return _BgModbus; }
  262. set { SetProperty(ref _BgModbus, value); }
  263. }
  264. private BgTcpIP _BgTcp;
  265. public BgTcpIP BgTcp
  266. {
  267. get { return _BgTcp; }
  268. set { SetProperty(ref _BgTcp, value); }
  269. }
  270. private ObservableCollection<LightControllerConfig> _LightControllerList;
  271. public ObservableCollection<LightControllerConfig> LightControllerList
  272. {
  273. get { return _LightControllerList; }
  274. set { SetProperty(ref _LightControllerList, value); }
  275. }
  276. private LightControllerConfig _SelectLightController;
  277. public LightControllerConfig SelectLightController
  278. {
  279. get { return _SelectLightController; }
  280. set { SetProperty(ref _SelectLightController, value); }
  281. }
  282. // 设备信息列表
  283. private ObservableCollection<DeviceInfo> _DeviceInfoList;
  284. public ObservableCollection<DeviceInfo> DeviceInfoList
  285. {
  286. get { return _DeviceInfoList; }
  287. set { SetProperty(ref _DeviceInfoList, value); }
  288. }
  289. // 当前选中的设备信息
  290. private DeviceInfo _SelectDeviceInfo;
  291. public DeviceInfo SelectDeviceInfo
  292. {
  293. get { return _SelectDeviceInfo; }
  294. set { SetProperty(ref _SelectDeviceInfo, value); }
  295. }
  296. // 兼容旧代码,DeviceInfo 指向当前选中的设备或第一个设备
  297. public DeviceInfo DeviceInfo
  298. {
  299. get { return _SelectDeviceInfo ?? DeviceInfoList?.FirstOrDefault(); }
  300. set
  301. {
  302. if (value != null && DeviceInfoList != null)
  303. {
  304. var existing = DeviceInfoList.FirstOrDefault(d => d.DeviceNo == value.DeviceNo);
  305. if (existing != null)
  306. {
  307. var index = DeviceInfoList.IndexOf(existing);
  308. DeviceInfoList[index] = value;
  309. }
  310. }
  311. RaisePropertyChanged();
  312. }
  313. }
  314. private SerialPortConfig _CardReaderConfig;
  315. public SerialPortConfig CardReaderConfig
  316. {
  317. get { return _CardReaderConfig; }
  318. set { SetProperty(ref _CardReaderConfig, value); }
  319. }
  320. private PressureModel _AssemblyPressureConfig;
  321. public PressureModel AssemblyPressureConfig
  322. {
  323. get { return _AssemblyPressureConfig; }
  324. set { SetProperty(ref _AssemblyPressureConfig, value); }
  325. }
  326. private PressureModel _DownPressureConfig;
  327. public PressureModel DownPressureConfig
  328. {
  329. get { return _DownPressureConfig; }
  330. set { SetProperty(ref _DownPressureConfig, 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 = "完成", 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. try
  1132. {
  1133. if (!File.Exists(FilePath.PressureParamterConfigPath))
  1134. {
  1135. List<PressureModel> models = new List<PressureModel>();
  1136. models.Add(new PressureModel());
  1137. models.Add(new PressureModel());
  1138. models.Add(new PressureModel());
  1139. FileHelper.WriteJsonFile(models, FilePath.PressureParamterConfigPath);
  1140. }
  1141. var pressureParam = FileHelper.ReadJsonFile<List<PressureModel>>(FilePath.PressureParamterConfigPath);
  1142. this.AssemblyPressureConfig = pressureParam[0];
  1143. this.DownPressureConfig = pressureParam[1];
  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. /// <summary>
  1501. /// 选择压力曲线保存路径
  1502. /// </summary>
  1503. /// <param name="parameter"></param>
  1504. void ExecuteBrowsePressureCurvePathCommand(object parameter)
  1505. {
  1506. if (parameter is PressureSensorSettings sensorSettings)
  1507. {
  1508. var dialog = new System.Windows.Forms.FolderBrowserDialog();
  1509. System.Windows.Forms.DialogResult result = dialog.ShowDialog();
  1510. if (result == System.Windows.Forms.DialogResult.OK)
  1511. {
  1512. sensorSettings.PressureCurvePath = dialog.SelectedPath;
  1513. }
  1514. }
  1515. }
  1516. private void SavePressureConfig()
  1517. {
  1518. List<PressureModel> models = new List<PressureModel>();
  1519. models.Add(AssemblyPressureConfig);
  1520. models.Add(DownPressureConfig);
  1521. FileHelper.WriteJsonFile(models, FilePath.PressureParamterConfigPath);
  1522. }
  1523. /// <summary>
  1524. /// 保存读卡器配置
  1525. /// </summary>
  1526. void ExecuteSaveCardReaderConfigCommand()
  1527. {
  1528. try
  1529. {
  1530. _configService.SaveCardReaderConfig(CardReaderConfig);
  1531. }
  1532. catch (Exception ex)
  1533. {
  1534. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1535. }
  1536. }
  1537. #endregion
  1538. #region 设备信息
  1539. /// <summary>
  1540. /// 保存当前选中的设备信息
  1541. /// </summary>
  1542. void ExecuteSaveDeviceInfoCommand()
  1543. {
  1544. try
  1545. {
  1546. if (DeviceInfoList != null && DeviceInfoList.Count > 0)
  1547. {
  1548. // 保存所有设备信息
  1549. _configService.SaveAllDeviceInfos(DeviceInfoList);
  1550. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1551. }
  1552. }
  1553. catch (Exception ex)
  1554. {
  1555. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1556. }
  1557. }
  1558. /// <summary>
  1559. /// 添加新设备
  1560. /// </summary>
  1561. void ExecuteAddDeviceInfoCommand()
  1562. {
  1563. try
  1564. {
  1565. var newDevice = _configService.AddDeviceInfo();
  1566. if (DeviceInfoList == null)
  1567. {
  1568. DeviceInfoList = new ObservableCollection<DeviceInfo>();
  1569. }
  1570. DeviceInfoList.Add(newDevice);
  1571. SelectDeviceInfo = newDevice;
  1572. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1573. }
  1574. catch (Exception ex)
  1575. {
  1576. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1577. }
  1578. }
  1579. /// <summary>
  1580. /// 删除当前选中的设备
  1581. /// </summary>
  1582. void ExecuteRemoveDeviceInfoCommand()
  1583. {
  1584. try
  1585. {
  1586. if (SelectDeviceInfo != null && DeviceInfoList != null && DeviceInfoList.Count > 1)
  1587. {
  1588. var deviceNo = SelectDeviceInfo.DeviceNo;
  1589. if (_configService.RemoveDeviceInfo(deviceNo))
  1590. {
  1591. DeviceInfoList.Remove(SelectDeviceInfo);
  1592. SelectDeviceInfo = DeviceInfoList.FirstOrDefault();
  1593. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1594. }
  1595. }
  1596. else
  1597. {
  1598. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "至少保留一个设备", Duration = 2 });
  1599. }
  1600. }
  1601. catch (Exception ex)
  1602. {
  1603. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1604. }
  1605. }
  1606. /// <summary>
  1607. /// 选择CSV存储路径
  1608. /// </summary>
  1609. void ExecuteSelectSaveImagePathCommand()
  1610. {
  1611. if (SelectDeviceInfo == null)
  1612. {
  1613. return;
  1614. }
  1615. using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog())
  1616. {
  1617. // Optional: set the initial directory
  1618. //dialog.SelectedPath = @"C:\";
  1619. // Show the folder browser dialog
  1620. System.Windows.Forms.DialogResult result = dialog.ShowDialog();
  1621. if (result == System.Windows.Forms.DialogResult.OK)
  1622. {
  1623. SelectDeviceInfo.SaveCsvPath = dialog.SelectedPath;
  1624. }
  1625. }
  1626. }
  1627. #endregion
  1628. #region 产品与mes绑定
  1629. private async void ExecuteGetProWithMesCommand()
  1630. {
  1631. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1632. if (v == null)
  1633. {
  1634. ProMesInfo.ProductCode = "";
  1635. ProMesInfo.ProductColor = "";
  1636. }
  1637. else
  1638. {
  1639. ProMesInfo.ProductCode = v.ProductCode;
  1640. ProMesInfo.ProductColor = v.ProductColor;
  1641. }
  1642. }
  1643. private async void ExecuteDeleteProWithMesCommand()
  1644. {
  1645. var v = await _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
  1646. if (v > 0)
  1647. {
  1648. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "删除成功", Duration = 1 });
  1649. var F = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1650. if (F == null)
  1651. {
  1652. ProMesInfo.ProductCode = "";
  1653. ProMesInfo.ProductColor = "";
  1654. }
  1655. }
  1656. }
  1657. private async void ExecuteSaveProWithMesCommandAsync()
  1658. {
  1659. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1660. if (v == null)
  1661. {
  1662. await _systemDatabaseService.InsertProWithMesAsync(ProMesInfo, SelectProduct);
  1663. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加成功", Duration = 1 });
  1664. }
  1665. else
  1666. {
  1667. var n = await _systemDatabaseService.UpdateProductWithMesAsync(ProMesInfo, SelectProduct);
  1668. if (n > 0)
  1669. {
  1670. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "更新成功", Duration = 1 });
  1671. }
  1672. }
  1673. }
  1674. #endregion
  1675. }
  1676. }