SettingViewModel.cs 75 KB

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