SettingViewModel.cs 76 KB

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