SettingViewModel.cs 75 KB

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