SettingViewModel.cs 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034
  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. private DelegateCommand _CheckStatusCommand;
  461. public DelegateCommand CheckStatusCommand =>
  462. _CheckStatusCommand ?? (_CheckStatusCommand = new DelegateCommand(ExecuteCheckStatusCommandCommand));
  463. #endregion
  464. #region 事件
  465. #endregion
  466. public SettingViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  467. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService,
  468. IProductService productService, ISystemDatabaseService systemDatabaseService)
  469. {
  470. _regionManager = regionManager;
  471. _eventAggregator = ea;
  472. _container = container;
  473. _dialogService = dialogService;
  474. _configService = configService;
  475. _robotService = robotService;
  476. _cameraService = cameraService;
  477. _feederService = feederService;
  478. _plcService = plcService;
  479. _productService = productService;
  480. _systemDatabaseService = systemDatabaseService;
  481. management = _container.Resolve<Management>();
  482. LoadedCommand = new DelegateCommand(OnLoad);
  483. //订阅权限登录事件
  484. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  485. }
  486. #region 方法
  487. #region 机器人
  488. private void ExecuteAddRobotCommand()
  489. {
  490. _dialogService.ShowDialog("AddRobot", rst =>
  491. {
  492. //对话框关闭之后的回调函数,可以在这解析结果。
  493. ButtonResult result1 = rst.Result;
  494. if (result1 == ButtonResult.OK)
  495. {
  496. var param = rst.Parameters.GetValue<RobotInfo>("Robot");
  497. var robot = new RobotInfo()
  498. {
  499. Id = param.Id,
  500. RobotName = param.RobotName,
  501. ConnectType = param.ConnectType,
  502. RobotBrand = param.RobotBrand,
  503. IP = param.IP,
  504. Port = param.Port,
  505. Terminator = param.Terminator,
  506. };
  507. RobotList.Add(robot);
  508. _configService.AddOrUpdateRobot(robot);
  509. _robotService.CreateRobot(robot.Id, robot);
  510. //对所有产品也进行添加
  511. _productService.AddRobotPointToProduct(robot.Id, robot.RobotName);
  512. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.添加完成}", Duration = 1 });
  513. }
  514. });
  515. }
  516. void ExecuteRemoveCommand()
  517. {
  518. if (MessageBox.Show(Lang.是否移除机器人, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  519. {
  520. // 找到要删除的机器人
  521. var robotToRemove = RobotList.FirstOrDefault(r => r.Id == SelectRobot.Id);
  522. if (robotToRemove != null)
  523. {
  524. RobotList.Remove(robotToRemove);
  525. _configService.RemoveRobot(robotToRemove.Id);
  526. _robotService.RemoveRobot(robotToRemove.Id);
  527. //对所有产品也进行移除
  528. _productService.RemoveRobotPointFromProduct(robotToRemove.Id);
  529. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  530. }
  531. }
  532. }
  533. async void ExecuteSaveRobotsCommand()
  534. {
  535. var view = new ShowMessage($"AAS", Lang.是否保存机器人);
  536. //show the dialog
  537. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  538. if (result != null && result is bool)
  539. {
  540. if (((bool)result))
  541. {
  542. foreach (var item in RobotList)
  543. {
  544. var robot = _robotService.GetRobot(item.Id);
  545. if (robot != null)
  546. {
  547. //更新连接参数
  548. robot.SafeZ = item.SafeZ;
  549. }
  550. _configService.AddOrUpdateRobot(item);
  551. }
  552. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  553. }
  554. }
  555. }
  556. #endregion
  557. #region 相机
  558. /// <summary>
  559. /// 保存所有相机
  560. /// </summary>
  561. async void ExecuteSaveCamerasCommand()
  562. {
  563. var view = new ShowMessage($"AAS", Lang.是否保存相机配置);
  564. //show the dialog
  565. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  566. if (result != null && result is bool)
  567. {
  568. if (((bool)result))
  569. {
  570. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  571. //management.SaveCamerasDeviceConfig();
  572. //management.DeviceConfig.Cameras = DeviceConfig.Cameras;
  573. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  574. }
  575. }
  576. }
  577. /// <summary>
  578. /// 移除相机
  579. /// </summary>
  580. void ExecuteRemoveCameraCommand()
  581. {
  582. if (MessageBox.Show(Lang.是否移除相机, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  583. {
  584. // 找到要删除的相机
  585. var cameraToRemove = CameraList.FirstOrDefault(r => r.Id == SelectCamera.Id);
  586. if (cameraToRemove != null)
  587. {
  588. _configService.RemoveCamera(cameraToRemove.Id);
  589. _cameraService.RemoveCamera(cameraToRemove.Id);
  590. var root = _configService.GetAllCameras();
  591. CameraList = new ObservableCollection<CameraInfo>(root);
  592. foreach (var item in CameraList)
  593. {
  594. _cameraService.UpdateCameraNumber(item.Id, item.CameraNo);
  595. }
  596. //对所有产品也进行移除
  597. _productService.RemoveCameraFromProduct(cameraToRemove.Id);
  598. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  599. }
  600. }
  601. }
  602. /// <summary>
  603. /// 编辑相机
  604. /// </summary>
  605. void ExecuteEditCameraCommand()
  606. {
  607. if (SelectCamera == null) return;
  608. bool isSelectedCameraBrandSucced = false;
  609. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  610. IDialogParameters parameters1 = new DialogParameters();
  611. parameters1.Add("CameraBrand", SelectCamera.CameraBrand);
  612. _dialogService.ShowDialog("SelectCameraBrand", parameters1, rst =>
  613. {
  614. if (rst.Result == ButtonResult.OK)
  615. {
  616. isSelectedCameraBrandSucced = true;
  617. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  618. }
  619. else
  620. {
  621. return;
  622. }
  623. });
  624. if (!isSelectedCameraBrandSucced) { return; }
  625. (bool isInstalled, string version) result = (false, "");
  626. string softwarename = "";
  627. switch (cameraBrand)
  628. {
  629. case CameraBrand.HikRobot_MVS:
  630. softwarename = "MVS";
  631. result = MvCamera.CheckSoftwareInstalled();
  632. break;
  633. case CameraBrand.Basler_Pylon:
  634. softwarename = "Pylon 7";
  635. result = BaslerCamera.CheckSoftwareInstalled();
  636. break;
  637. case CameraBrand.IRayple:
  638. softwarename = "MV Viewer";
  639. result = AHuaCamera.CheckSoftwareInstalled();
  640. break;
  641. case CameraBrand.Cognex:
  642. softwarename = "Cognex VisionPro";
  643. result = CognexCamera.CheckSoftwareInstalled();
  644. break;
  645. case CameraBrand.Galaxy:
  646. softwarename = "Galaxy Viewer";
  647. result = GalaxyCamera.CheckSoftwareInstalled();
  648. break;
  649. case CameraBrand.Opt:
  650. softwarename = "OPT Camera Viewer";
  651. result = OptCamera.CheckSoftwareInstalled();
  652. break;
  653. default:
  654. break;
  655. }
  656. if (!result.isInstalled)
  657. {
  658. if (string.IsNullOrEmpty(result.version))
  659. {
  660. //未安装
  661. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  662. }
  663. else
  664. {
  665. //版本较低
  666. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  667. }
  668. return;
  669. }
  670. //编辑前的相机名称
  671. string oldCameraName = SelectCamera.CameraName;
  672. IDialogParameters parameters = new DialogParameters();
  673. parameters.Add("CameraBrand", cameraBrand);
  674. parameters.Add("Camera", SelectCamera.Copy());
  675. _dialogService.ShowDialog("EditCamera", parameters, rst =>
  676. {
  677. //对话框关闭之后的回调函数,可以在这解析结果。
  678. ButtonResult result1 = rst.Result;
  679. if (result1 == ButtonResult.OK)
  680. {
  681. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  682. SelectCamera.CameraName = param.CameraName;
  683. SelectCamera.SerialNumber = param.SerialNumber;
  684. SelectCamera.Model = param.Model;
  685. SelectCamera.ManufacturerName = param.ManufacturerName;
  686. SelectCamera.CameraType = param.CameraType;
  687. SelectCamera.CameraBrand = param.CameraBrand;
  688. SelectCamera.CameraIp = param.CameraIp;
  689. _configService.AddOrUpdateCamera(SelectCamera);
  690. if (oldCameraName != param.CameraName)
  691. {
  692. //对所有产品也进行修改
  693. _productService.UpdateCameraNameInProduct(SelectCamera.Id, SelectCamera.CameraName);
  694. }
  695. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  696. }
  697. });
  698. }
  699. /// <summary>
  700. /// 增加相机
  701. /// </summary>
  702. void ExecuteAddCameraCommand()
  703. {
  704. bool isSelectedCameraBrandSucced = false;
  705. CameraBrand cameraBrand = CameraBrand.HikRobot_MVS;
  706. _dialogService.ShowDialog("SelectCameraBrand", rst =>
  707. {
  708. if (rst.Result == ButtonResult.OK)
  709. {
  710. isSelectedCameraBrandSucced = true;
  711. cameraBrand = rst.Parameters.GetValue<CameraBrand>("CameraBrand");
  712. }
  713. else
  714. {
  715. return;
  716. }
  717. });
  718. if (!isSelectedCameraBrandSucced) { return; }
  719. ;
  720. (bool isInstalled, string version) result = (false, "");
  721. string softwarename = "";
  722. switch (cameraBrand)
  723. {
  724. case CameraBrand.HikRobot_MVS:
  725. softwarename = "MVS";
  726. result = MvCamera.CheckSoftwareInstalled();
  727. break;
  728. case CameraBrand.Basler_Pylon:
  729. softwarename = "Pylon 7";
  730. result = BaslerCamera.CheckSoftwareInstalled();
  731. break;
  732. case CameraBrand.IRayple:
  733. softwarename = "MV Viewer";
  734. result = AHuaCamera.CheckSoftwareInstalled();
  735. break;
  736. case CameraBrand.Cognex:
  737. softwarename = "Cognex VisionPro";
  738. result = CognexCamera.CheckSoftwareInstalled();
  739. break;
  740. case CameraBrand.Galaxy:
  741. softwarename = "Galaxy Viewer";
  742. result = GalaxyCamera.CheckSoftwareInstalled();
  743. break;
  744. case CameraBrand.Opt:
  745. softwarename = "OPT Camera Viewer";
  746. result = OptCamera.CheckSoftwareInstalled();
  747. break;
  748. default:
  749. break;
  750. }
  751. if (!result.isInstalled)
  752. {
  753. if (string.IsNullOrEmpty(result.version))
  754. {
  755. //未安装
  756. MessageBox.Show(Lang.CameraSDKCheck_Message1.Replace("{name}", softwarename), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  757. }
  758. else
  759. {
  760. //版本较低
  761. MessageBox.Show(Lang.CameraSDKCheck_Message2.Replace("{name}", softwarename).Replace("{version}", result.version).Replace("\\n", Environment.NewLine), "AAS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  762. }
  763. return;
  764. }
  765. IDialogParameters parameters = new DialogParameters();
  766. parameters.Add("CameraBrand", cameraBrand);
  767. _dialogService.ShowDialog("AddCamera", parameters, rst =>
  768. {
  769. //对话框关闭之后的回调函数,可以在这解析结果。
  770. ButtonResult result1 = rst.Result;
  771. if (result1 == ButtonResult.OK)
  772. {
  773. var param = rst.Parameters.GetValue<CameraInfo>("Camera");
  774. var camera = new CameraInfo()
  775. {
  776. Id = param.Id,
  777. CameraName = param.CameraName,
  778. SerialNumber = param.SerialNumber,
  779. Model = param.Model,
  780. ManufacturerName = param.ManufacturerName,
  781. CameraType = param.CameraType,
  782. CameraBrand = param.CameraBrand,
  783. CameraIp = param.CameraIp
  784. };
  785. CameraList.Add(camera);
  786. _configService.AddOrUpdateCamera(camera);
  787. _cameraService.CreateCamera(camera.Id, camera);
  788. //对所有产品也进行添加
  789. _productService.AddCameraToProduct(camera.Id, camera.CameraName);
  790. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  791. }
  792. });
  793. }
  794. #endregion
  795. #region Feeder
  796. void ExecuteAddFeederCommand()
  797. {
  798. _dialogService.ShowDialog("AddFeeder", rst =>
  799. {
  800. //对话框关闭之后的回调函数,可以在这解析结果。
  801. ButtonResult result1 = rst.Result;
  802. if (result1 == ButtonResult.OK)
  803. {
  804. var param = rst.Parameters.GetValue<FeederInfo>("Feeder");
  805. var feeder = new FeederInfo()
  806. {
  807. Id = param.Id,
  808. FeederName = param.FeederName,
  809. ConnectType = param.ConnectType,
  810. FeederBrand = param.FeederBrand,
  811. IP = param.IP,
  812. Port = param.Port
  813. };
  814. FeederList.Add(feeder);
  815. _configService.AddOrUpdateFeeder(feeder);
  816. _feederService.CreateFeeder(feeder.Id, feeder.FeederNo, feeder.FeederName, feeder.IP, feeder.Port, feeder.FeederBrand);
  817. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  818. }
  819. });
  820. }
  821. void ExecuteRemoveFeederCommand()
  822. {
  823. if (MessageBox.Show(Lang.是否移除Feeder, " AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  824. {
  825. // 找到要删除的机器人
  826. var feederToRemove = FeederList.FirstOrDefault(r => r.Id == SelectFeeder.Id);
  827. if (feederToRemove != null)
  828. {
  829. _configService.RemoveFeeder(feederToRemove.Id);
  830. _feederService.RemoveFeeder(feederToRemove.Id);
  831. var root = _configService.GetAllFeeders();
  832. FeederList = new ObservableCollection<FeederInfo>(root);
  833. foreach (var item in FeederList)
  834. {
  835. _feederService.UpdateFeederNo(item.Id, item.FeederNo);
  836. }
  837. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  838. }
  839. }
  840. }
  841. async void ExecuteSaveFeedersCommand()
  842. {
  843. var view = new ShowMessage($"AAS", Lang.是否保存Feeder);
  844. //show the dialog
  845. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  846. if (result != null && result is bool)
  847. {
  848. if (((bool)result))
  849. {
  850. foreach (var item in FeederList)
  851. {
  852. _configService.AddOrUpdateFeeder(item);
  853. }
  854. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  855. }
  856. }
  857. }
  858. #endregion
  859. #region PLC
  860. /// <summary>
  861. /// 保存PLC
  862. /// </summary>
  863. async void ExecuteSavePlcsCommand()
  864. {
  865. var view = new ShowMessage($"AAS", Lang.是否保存PLC);
  866. //show the dialog
  867. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  868. if (result != null && result is bool)
  869. {
  870. if (((bool)result))
  871. {
  872. foreach (var item in PlcList)
  873. {
  874. _configService.AddOrUpdatePlc(item);
  875. }
  876. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  877. }
  878. }
  879. }
  880. /// <summary>
  881. /// 移除PLC
  882. /// </summary>
  883. void ExecuteRemovePlcCommand()
  884. {
  885. if (MessageBox.Show(Lang.是否移除PLC, $"AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  886. {
  887. // 找到要删除的plc
  888. var plcToRemove = PlcList.FirstOrDefault(r => r.Id == SelectPlc.Id);
  889. if (plcToRemove != null)
  890. {
  891. _configService.RemovePlc(plcToRemove.Id);
  892. _plcService.RemovePlc(plcToRemove.Id);
  893. var root = _configService.GetAllPlcs();
  894. PlcList = new ObservableCollection<PlcInfo>(root);
  895. foreach (var item in PlcList)
  896. {
  897. _plcService.UpdatePlcNumber(item.Id, item.Index);
  898. }
  899. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  900. }
  901. }
  902. }
  903. /// <summary>
  904. /// 增加PLC
  905. /// </summary>
  906. void ExecuteAddPlcCommand()
  907. {
  908. _dialogService.ShowDialog("AddPlc", rst =>
  909. {
  910. //对话框关闭之后的回调函数,可以在这解析结果。
  911. ButtonResult result1 = rst.Result;
  912. if (result1 == ButtonResult.OK)
  913. {
  914. var param = rst.Parameters.GetValue<PlcInfo>("PLC");
  915. var plc = new PlcInfo()
  916. {
  917. Id = param.Id,
  918. Name = param.Name,
  919. CommunicationType = param.CommunicationType,
  920. EndpointUrl = param.EndpointUrl,
  921. };
  922. PlcList.Add(plc);
  923. _configService.AddOrUpdatePlc(plc);
  924. _plcService.CreatePlc(plc.Id, plc);
  925. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  926. }
  927. });
  928. }
  929. #endregion
  930. #region Light handlers
  931. void ExecuteAddLightControllerCommand()
  932. {
  933. // open dialog to add light controller (similar to robots)
  934. _dialogService.ShowDialog("AddLightController", rst =>
  935. {
  936. if (rst.Result == ButtonResult.OK)
  937. {
  938. var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
  939. // assign id and defaults if needed
  940. if (param.Id == 0)
  941. param.Id = (LightControllerList?.Count ?? 0) + 1;
  942. LightControllerList.Add(param);
  943. _configService.AddOrUpdateLightController(param);
  944. SelectLightController = param;
  945. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  946. }
  947. });
  948. }
  949. void ExecuteRemoveLightControllerCommand()
  950. {
  951. if (SelectLightController == null) return;
  952. if (MessageBox.Show(Lang.是否移除光源控制器, "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  953. {
  954. _configService.RemoveLightController(SelectLightController.Id);
  955. LightControllerList.Remove(SelectLightController);
  956. SelectLightController = null;
  957. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  958. }
  959. }
  960. async void ExecuteSaveLightControllersCommand()
  961. {
  962. var view = new ShowMessage($"AAS", Lang.是否保存光源控制器配置);
  963. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  964. if (result != null && result is bool && (bool)result)
  965. {
  966. foreach (var item in LightControllerList)
  967. {
  968. _configService.AddOrUpdateLightController(item);
  969. }
  970. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  971. }
  972. }
  973. /// <summary>
  974. /// 光源型号改变
  975. /// </summary>
  976. void ExecuteLightModelChangedCommand(object obj)
  977. {
  978. try
  979. {
  980. if (obj == null)
  981. {
  982. return;
  983. }
  984. if (obj is LightControllerConfig lc)
  985. {
  986. lc.Init();
  987. }
  988. }
  989. catch (Exception)
  990. {
  991. }
  992. }
  993. #endregion
  994. #region 螺丝供料器
  995. /// <summary>
  996. /// 保存所有螺丝供料器
  997. /// </summary>
  998. async void ExecuteSaveScrewFeedersCommand()
  999. {
  1000. var view = new ShowMessage($"AAS", Lang.是否保存螺丝供料器);
  1001. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1002. if (result != null && result is bool && (bool)result)
  1003. {
  1004. if (ScrewFeederList != null)
  1005. {
  1006. foreach (var item in ScrewFeederList)
  1007. {
  1008. try
  1009. {
  1010. _configService.AddOrUpdateScrewFeeder(item);
  1011. }
  1012. catch (Exception ex)
  1013. {
  1014. // 记录或通知错误,但继续处理其它项
  1015. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1016. }
  1017. }
  1018. }
  1019. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1020. }
  1021. }
  1022. /// <summary>
  1023. /// 移除螺丝供料器
  1024. /// </summary>
  1025. void ExecuteRemoveScrewFeederCommand()
  1026. {
  1027. if (SelectScrewFeeder == null) return;
  1028. if (MessageBox.Show(Lang.是否移除螺丝供料器, "AAS", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  1029. {
  1030. try
  1031. {
  1032. var toRemove = ScrewFeederList?.FirstOrDefault(s => s.Id == SelectScrewFeeder.Id);
  1033. if (toRemove != null)
  1034. {
  1035. _configService.RemoveScrewFeeder(toRemove.Id);
  1036. // 重新加载列表以保持序号/配置一致(与其他类似实现一致)
  1037. var root = _configService.GetAllScrewFeeders();
  1038. ScrewFeederList = new ObservableCollection<ScrewFeederInfo>(root);
  1039. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.移除完成, Duration = 1 });
  1040. }
  1041. }
  1042. catch (Exception ex)
  1043. {
  1044. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1045. }
  1046. }
  1047. }
  1048. /// <summary>
  1049. /// 添加螺丝供料器
  1050. /// </summary>
  1051. void ExecuteAddScrewFeederCommand()
  1052. {
  1053. _dialogService.ShowDialog("AddScrewFeeder", rst =>
  1054. {
  1055. ButtonResult result1 = rst.Result;
  1056. if (result1 == ButtonResult.OK)
  1057. {
  1058. var param = rst.Parameters.GetValue<ScrewFeederInfo>("ScrewFeeder");
  1059. if (param != null)
  1060. {
  1061. if (ScrewFeederList == null)
  1062. {
  1063. ScrewFeederList = new ObservableCollection<ScrewFeederInfo>();
  1064. }
  1065. try
  1066. {
  1067. param = _configService.AddOrUpdateScrewFeeder(param);
  1068. // 直接添加对话框返回的对象(也可以根据需要映射字段)
  1069. ScrewFeederList.Add(param);
  1070. }
  1071. catch (Exception ex)
  1072. {
  1073. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1074. }
  1075. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.添加完成, Duration = 1 });
  1076. }
  1077. }
  1078. });
  1079. }
  1080. #endregion
  1081. #region 通讯
  1082. async void ExecuteSaveCommunicateCommand(string parm)
  1083. {
  1084. if (parm == "TCPIP")
  1085. {
  1086. var view = new ShowMessage($"AAS", Lang.是否保存后台TCP通讯配置);
  1087. //show the dialog
  1088. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1089. if (result != null && result is bool)
  1090. {
  1091. if (((bool)result))
  1092. {
  1093. _configService.SetBgTcp(BgTcp);
  1094. _configService.SaveBgTcp();
  1095. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1096. }
  1097. }
  1098. }
  1099. else if (parm == "ModbusTCP")
  1100. {
  1101. var view = new ShowMessage($"AAS", Lang.是否保存后台ModbusTCP通讯配置);
  1102. //show the dialog
  1103. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1104. if (result != null && result is bool)
  1105. {
  1106. if (((bool)result))
  1107. {
  1108. _configService.SetBgModbusTcp(BgModbus);
  1109. _configService.SaveBgModbusTcp();
  1110. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1111. }
  1112. }
  1113. }
  1114. else
  1115. {
  1116. return;
  1117. }
  1118. }
  1119. #endregion
  1120. #region 语言
  1121. void ExecuteSelectLanguageCommand(string language)
  1122. {
  1123. if (string.Equals(language, "ChineseSimplified"))
  1124. {
  1125. CurrentLanguage = Enums.Language.ChineseSimplified;
  1126. _configService.SetCurrentLanguage(CurrentLanguage);
  1127. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1128. }
  1129. else if (string.Equals(language, "ChineseTraditional"))
  1130. {
  1131. CurrentLanguage = Enums.Language.ChineseTraditional;
  1132. _configService.SetCurrentLanguage(CurrentLanguage);
  1133. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1134. }
  1135. else if (string.Equals(language, "English"))
  1136. {
  1137. CurrentLanguage = Enums.Language.English;
  1138. _configService.SetCurrentLanguage(CurrentLanguage);
  1139. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1140. }
  1141. else if (string.Equals(language, "Japanese"))
  1142. {
  1143. CurrentLanguage = Enums.Language.Japanese;
  1144. _configService.SetCurrentLanguage(CurrentLanguage);
  1145. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1146. }
  1147. else if (string.Equals(language, "Vietnamese"))
  1148. {
  1149. CurrentLanguage = Enums.Language.Vietnamese;
  1150. _configService.SetCurrentLanguage(CurrentLanguage);
  1151. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.5 });
  1152. }
  1153. }
  1154. #endregion
  1155. #region 生产排班
  1156. private void ExecuteSaveWorkShiftCommand()
  1157. {
  1158. try
  1159. {
  1160. FileHelper.WriteJsonFile(WorkShifts, FilePath.WorkShiftParamPath);
  1161. _eventAggregator.GetEvent<WorkShiftUpdateNotification>().Publish(WorkShifts);
  1162. }
  1163. catch (Exception)
  1164. { }
  1165. }
  1166. #endregion
  1167. private void OnLoad()
  1168. {
  1169. try
  1170. {
  1171. this.WorkShifts = FileHelper.ReadJsonFile<WorkShift>(FilePath.WorkShiftParamPath);
  1172. }
  1173. catch (Exception)
  1174. {
  1175. }
  1176. }
  1177. private void ExecuteCheckStatusCommandCommand()
  1178. {
  1179. _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
  1180. }
  1181. private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  1182. {
  1183. switch (e.PropertyName)
  1184. {
  1185. case "Title1":
  1186. Application.Current.Resources["Font.Size.Title1"] = Title1;
  1187. break;
  1188. case "Title2":
  1189. Application.Current.Resources["Font.Size.Title2"] = Title2;
  1190. break;
  1191. case "Title3":
  1192. Application.Current.Resources["Font.Size.Title3"] = Title3;
  1193. break;
  1194. case "Title4":
  1195. Application.Current.Resources["Font.Size.Title4"] = Title4;
  1196. break;
  1197. case "Body1":
  1198. Application.Current.Resources["Font.Size.Body1"] = Body1;
  1199. break;
  1200. case "Body2":
  1201. Application.Current.Resources["Font.Size.Body2"] = Body2;
  1202. break;
  1203. case "Body3":
  1204. Application.Current.Resources["Font.Size.Body3"] = Body3;
  1205. break;
  1206. case "Body4":
  1207. Application.Current.Resources["Font.Size.Body4"] = Body4;
  1208. break;
  1209. case "Captions1":
  1210. Application.Current.Resources["Font.Size.Captions1"] = Captions1;
  1211. break;
  1212. case "Captions2":
  1213. Application.Current.Resources["Font.Size.Captions2"] = Captions2;
  1214. break;
  1215. case "Captions3":
  1216. Application.Current.Resources["Font.Size.Captions3"] = Captions3;
  1217. break;
  1218. case "Captions4":
  1219. Application.Current.Resources["Font.Size.Captions4"] = Captions4;
  1220. break;
  1221. default:
  1222. break;
  1223. }
  1224. }
  1225. #endregion
  1226. #region 继承
  1227. /// <summary>
  1228. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  1229. /// </summary>
  1230. /// <param name="navigationContext"></param>
  1231. /// <param name="continuationCallback"></param>
  1232. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  1233. {
  1234. continuationCallback(true);
  1235. }
  1236. /// <summary>
  1237. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  1238. /// </summary>
  1239. /// <param name="navigationContext"></param>
  1240. /// <exception cref="NotImplementedException"></exception>
  1241. public async void OnNavigatedTo(NavigationContext navigationContext)
  1242. {
  1243. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  1244. {
  1245. IsAllowEdit = false;
  1246. }
  1247. else
  1248. {
  1249. IsAllowEdit = true;
  1250. }
  1251. if (RobotList == null)
  1252. {
  1253. RobotList = new ObservableCollection<RobotInfo>();
  1254. var robots = _configService.GetAllRobots();
  1255. foreach (var robot in robots)
  1256. {
  1257. RobotList.Add(robot);
  1258. }
  1259. }
  1260. if (CameraList == null)
  1261. {
  1262. CameraList = new ObservableCollection<CameraInfo>();
  1263. var cameras = _configService.GetAllCameras();
  1264. foreach (var camera in cameras)
  1265. {
  1266. CameraList.Add(camera);
  1267. }
  1268. }
  1269. if (FeederList == null)
  1270. {
  1271. FeederList = new ObservableCollection<FeederInfo>();
  1272. var feeders = _configService.GetAllFeeders();
  1273. foreach (var feeder in feeders)
  1274. {
  1275. FeederList.Add(feeder);
  1276. }
  1277. }
  1278. if (PlcList == null)
  1279. {
  1280. PlcList = new ObservableCollection<PlcInfo>();
  1281. var plcs = _configService.GetAllPlcs();
  1282. foreach (var plc in plcs)
  1283. {
  1284. PlcList.Add(plc);
  1285. }
  1286. }
  1287. // load light controllers
  1288. if (LightControllerList == null)
  1289. {
  1290. LightControllerList = new ObservableCollection<LightControllerConfig>();
  1291. var controllers = _configService.GetAllLightControllers();
  1292. foreach (var ctrl in controllers)
  1293. {
  1294. LightControllerList.Add(ctrl);
  1295. }
  1296. }
  1297. if (BgTcp == null)
  1298. {
  1299. BgTcp = _configService.GetBgTcp();
  1300. }
  1301. if (BgModbus == null)
  1302. {
  1303. BgModbus = _configService.GetBgModbusTcp();
  1304. }
  1305. if (DeviceInfoList == null || DeviceInfoList.Count == 0)
  1306. {
  1307. // load device info list (支持多设备)
  1308. var devices = _configService.GetAllDeviceInfos();
  1309. DeviceInfoList = new ObservableCollection<DeviceInfo>(devices);
  1310. // 默认选中第一个设备
  1311. if (DeviceInfoList.Count > 0)
  1312. {
  1313. SelectDeviceInfo = DeviceInfoList[0];
  1314. }
  1315. }
  1316. if (ScrewFeederList == null)
  1317. {
  1318. var screwFeeders = _configService.GetAllScrewFeeders();
  1319. ScrewFeederList = new ObservableCollection<ScrewFeederInfo>(screwFeeders);
  1320. }
  1321. if (CardReaderConfig == null)
  1322. {
  1323. // load card reader config
  1324. CardReaderConfig = _configService.GetCardReaderConfig();
  1325. }
  1326. if (TorqueReadConfig == null)
  1327. {
  1328. TorqueReadConfig = _configService.GetTorqueReaderConfig();
  1329. }
  1330. CurrentLanguage = _configService.GetSystemConfiguration().CurrentLanguage;
  1331. // load system parameters into UI
  1332. var sys = _configService.GetSystemConfiguration();
  1333. if (sys != null)
  1334. {
  1335. WorkMode = sys.WorkMode;
  1336. PickPointNum = sys.PickPointNum;
  1337. DowmCameraNum = sys.DowmCameraNum;
  1338. WorkMode = sys.WorkMode;
  1339. PickPointNum = sys.PickPointNum;
  1340. JumpLimitZ= sys.JumpLimitZ;
  1341. DowmCameraNum = sys.DowmCameraNum;
  1342. UpCameraPickNum = sys.UpCameraPickNum;
  1343. UpCameraPutNum = sys.UpCameraPutNum;
  1344. UPCameracheckNum = sys.UPCameracheckNum;
  1345. FixedCameraPickNum = sys.FixedCameraPickNum;
  1346. FixedCameraPutNum = sys.FixedCameraPutNum;
  1347. FixedCameracheckNum = sys.FixedCameracheckNum;
  1348. ScrewTeachNum = sys.ScrewTeachNum;
  1349. IsSaveScrewCurve = sys.IsSaveScrewCurve;
  1350. ScrewCurvePath = sys.ScrewCurvePath;
  1351. IsBasePartCodeGetSN = sys.IsBasePartCodeGetSN;
  1352. IsBasePartCodeChooseScrew = sys.IsBasePartCodeChooseScrew;
  1353. IsBasePartOpenLight = sys.IsBasePartOpenLight;
  1354. IsBasePartOpenLightKB = sys.IsBasePartOpenLightKB;
  1355. ChooseScrewModel = sys.ChooseScrewModel;
  1356. }
  1357. if (isFirstLoad)
  1358. {
  1359. Title1 = (double)Application.Current.Resources["Font.Size.Title1"];
  1360. Title2 = (double)Application.Current.Resources["Font.Size.Title2"];
  1361. Title3 = (double)Application.Current.Resources["Font.Size.Title3"];
  1362. Title4 = (double)Application.Current.Resources["Font.Size.Title4"];
  1363. Body1 = (double)Application.Current.Resources["Font.Size.Body1"];
  1364. Body2 = (double)Application.Current.Resources["Font.Size.Body2"];
  1365. Body3 = (double)Application.Current.Resources["Font.Size.Body3"];
  1366. Body4 = (double)Application.Current.Resources["Font.Size.Body4"];
  1367. Captions1 = (double)Application.Current.Resources["Font.Size.Captions1"];
  1368. Captions2 = (double)Application.Current.Resources["Font.Size.Captions2"];
  1369. Captions3 = (double)Application.Current.Resources["Font.Size.Captions3"];
  1370. Captions4 = (double)Application.Current.Resources["Font.Size.Captions4"];
  1371. this.PropertyChanged += OnPropertyChanged;
  1372. isFirstLoad = false;
  1373. }
  1374. try
  1375. {
  1376. ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
  1377. }
  1378. catch (Exception ex)
  1379. {
  1380. LogHelper.WriteLogError("加载产品列表时出错", ex);
  1381. }
  1382. }
  1383. /// <summary>
  1384. /// 是否允许导航到此视图模型。
  1385. /// </summary>
  1386. /// <param name="navigationContext"></param>
  1387. /// <returns></returns>
  1388. public bool IsNavigationTarget(NavigationContext navigationContext)
  1389. {
  1390. return true;
  1391. }
  1392. /// <summary>
  1393. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1394. /// </summary>
  1395. /// <param name="navigationContext"></param>
  1396. public void OnNavigatedFrom(NavigationContext navigationContext)
  1397. {
  1398. }
  1399. #endregion
  1400. private bool _IsAllowEdit = false;
  1401. public bool IsAllowEdit
  1402. {
  1403. get { return _IsAllowEdit; }
  1404. set { SetProperty(ref _IsAllowEdit, value); }
  1405. }
  1406. private void LoginChange(Models.User user)
  1407. {
  1408. if (user.userPart == Enums.UserPart.Operator)
  1409. {
  1410. IsAllowEdit = false;
  1411. }
  1412. else
  1413. {
  1414. IsAllowEdit = true;
  1415. }
  1416. }
  1417. #region 系统参数
  1418. private bool _IsBasePartCodeGetSN;
  1419. /// <summary>
  1420. /// 是否基于零件码获取流程码
  1421. /// </summary>
  1422. public bool IsBasePartCodeGetSN
  1423. {
  1424. get { return _IsBasePartCodeGetSN; }
  1425. set { SetProperty(ref _IsBasePartCodeGetSN, value); }
  1426. }
  1427. private bool _IsBasePartOpenLight;
  1428. /// <summary>
  1429. /// 是否启用最后一次拍照关闭光源
  1430. /// </summary>
  1431. public bool IsBasePartOpenLight
  1432. {
  1433. get { return _IsBasePartOpenLight; }
  1434. set { SetProperty(ref _IsBasePartOpenLight, value); }
  1435. }
  1436. private bool _IsBasePartOpenLightKB;
  1437. /// <summary>
  1438. /// 是否启用KB复检
  1439. /// </summary>
  1440. public bool IsBasePartOpenLightKB
  1441. {
  1442. get { return _IsBasePartOpenLightKB; }
  1443. set { SetProperty(ref _IsBasePartOpenLightKB, value); }
  1444. }
  1445. private bool _IsBasePartCodeChooseScrew;
  1446. /// <summary>
  1447. /// 是否通过零件码判断螺丝型号
  1448. /// </summary>
  1449. public bool IsBasePartCodeChooseScrew
  1450. {
  1451. get { return _IsBasePartCodeChooseScrew; }
  1452. set { SetProperty(ref _IsBasePartCodeChooseScrew, value); }
  1453. }
  1454. private string _ChooseScrewModel;
  1455. /// <summary>
  1456. /// 螺丝型号判断,如******123**,*为忽略字符
  1457. /// </summary>
  1458. public string ChooseScrewModel
  1459. {
  1460. get { return _ChooseScrewModel; }
  1461. set { SetProperty(ref _ChooseScrewModel, value); }
  1462. }
  1463. private Int16 _WorkMode = 0;
  1464. /// <summary>
  1465. /// 工作模式 =1 拍1打1, =2 拍1打所有,=3:先拍1打1打3颗再拍2打所有
  1466. /// </summary>
  1467. public Int16 WorkMode
  1468. {
  1469. get { return _WorkMode; }
  1470. set { SetProperty(ref _WorkMode, value); }
  1471. }
  1472. private Int16 _PickPointNum = 0;
  1473. /// <summary>
  1474. /// 取料位置 =0 不需要取料 =1 需要取料
  1475. /// </summary>
  1476. public Int16 PickPointNum
  1477. {
  1478. get { return _PickPointNum; }
  1479. set { SetProperty(ref _PickPointNum, value); }
  1480. }
  1481. private double _JumpLimitZ = 0;
  1482. /// <summary>
  1483. /// 取料位置 =0 不需要取料 =1 需要取料
  1484. /// </summary>
  1485. public double JumpLimitZ
  1486. {
  1487. get { return _JumpLimitZ; }
  1488. set { SetProperty(ref _JumpLimitZ, value); }
  1489. }
  1490. private Int16 _DowmCameraNum = 0;
  1491. /// <summary>
  1492. /// 下相机拍照次数
  1493. /// </summary>
  1494. public Int16 DowmCameraNum
  1495. {
  1496. get => _DowmCameraNum;
  1497. set => SetProperty(ref _DowmCameraNum, value);
  1498. }
  1499. private Int16 _UpCameraPickNum = 0;
  1500. /// <summary>
  1501. /// 上相机取料拍照次数
  1502. /// </summary>
  1503. public Int16 UpCameraPickNum
  1504. {
  1505. get => _UpCameraPickNum;
  1506. set => SetProperty(ref _UpCameraPickNum, value);
  1507. }
  1508. private Int16 _UpCameraPutNum = 0;
  1509. /// <summary>
  1510. /// 上相机放料拍照次数
  1511. /// </summary>
  1512. public Int16 UpCameraPutNum
  1513. {
  1514. get => _UpCameraPutNum;
  1515. set => SetProperty(ref _UpCameraPutNum, value);
  1516. }
  1517. private Int16 _UPCameracheckNum = 0;
  1518. /// <summary>
  1519. /// 上相机锁附/组装次数
  1520. /// </summary>
  1521. public Int16 UPCameracheckNum
  1522. {
  1523. get => _UPCameracheckNum;
  1524. set => SetProperty(ref _UPCameracheckNum, value);
  1525. }
  1526. private Int16 _FixedCameraPickNum = 0;
  1527. /// <summary>
  1528. /// 取料固定位置拍产品相机数量
  1529. /// </summary>
  1530. public Int16 FixedCameraPickNum
  1531. {
  1532. get => _FixedCameraPickNum;
  1533. set => SetProperty(ref _FixedCameraPickNum, value);
  1534. }
  1535. private Int16 _FixedCameraPutNum = 0;
  1536. /// <summary>
  1537. /// 锁附/组装固定位置拍产品相机数量
  1538. /// </summary>
  1539. public Int16 FixedCameraPutNum
  1540. {
  1541. get => _FixedCameraPutNum;
  1542. set => SetProperty(ref _FixedCameraPutNum, value);
  1543. }
  1544. private Int16 _FixedCameracheckNum = 0;
  1545. /// <summary>
  1546. /// 固定相机检测锁附/组装次数
  1547. /// </summary>
  1548. public Int16 FixedCameracheckNum
  1549. {
  1550. get => _FixedCameracheckNum;
  1551. set => SetProperty(ref _FixedCameracheckNum, value);
  1552. }
  1553. private Int16 _ScrewTeachNum = 0;
  1554. /// <summary>
  1555. /// 披头矫正的模式,1:初始化时矫正,2:每个产品矫正一次,3:每颗螺丝矫正一次
  1556. /// </summary>
  1557. public Int16 ScrewTeachNum
  1558. {
  1559. get => _ScrewTeachNum;
  1560. set => SetProperty(ref _ScrewTeachNum, value);
  1561. }
  1562. private bool _IsSaveScrewCurve;
  1563. /// <summary>
  1564. /// 是否保存锁付曲线图
  1565. /// </summary>
  1566. public bool IsSaveScrewCurve
  1567. {
  1568. get { return _IsSaveScrewCurve; }
  1569. set { SetProperty(ref _IsSaveScrewCurve, value); }
  1570. }
  1571. private string _ScrewCurvePath;
  1572. /// <summary>
  1573. /// 锁付曲线图保存路径
  1574. /// </summary>
  1575. public string ScrewCurvePath
  1576. {
  1577. get { return _ScrewCurvePath; }
  1578. set { SetProperty(ref _ScrewCurvePath, value); }
  1579. }
  1580. /// <summary>
  1581. /// 选择锁付曲线图保存路径
  1582. /// </summary>
  1583. void ExecuteBrowseScrewCurvePathCommand()
  1584. {
  1585. try
  1586. {
  1587. using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
  1588. {
  1589. dlg.Description = "选择锁付曲线图保存路径";
  1590. dlg.ShowNewFolderButton = true;
  1591. if (!string.IsNullOrEmpty(ScrewCurvePath)) dlg.SelectedPath = ScrewCurvePath;
  1592. var result = dlg.ShowDialog();
  1593. if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
  1594. {
  1595. ScrewCurvePath = dlg.SelectedPath;
  1596. }
  1597. }
  1598. }
  1599. catch (Exception ex)
  1600. {
  1601. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 2 });
  1602. }
  1603. }
  1604. /// <summary>
  1605. /// 保存系统参数
  1606. /// </summary>
  1607. async void ExecuteSaveSystemParametersCommand()
  1608. {
  1609. var view = new ShowMessage($"AAS", Lang.是否保存系统参数);
  1610. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  1611. if (result != null && result is bool && (bool)result)
  1612. {
  1613. try
  1614. {
  1615. var sysConfig = _configService.GetSystemConfiguration();
  1616. sysConfig.WorkMode = WorkMode;
  1617. sysConfig.PickPointNum = PickPointNum;
  1618. sysConfig.JumpLimitZ= JumpLimitZ;
  1619. sysConfig.DowmCameraNum = DowmCameraNum;
  1620. sysConfig.UpCameraPickNum = UpCameraPickNum;
  1621. sysConfig.UpCameraPutNum = UpCameraPutNum;
  1622. sysConfig.UPCameracheckNum = UPCameracheckNum;
  1623. sysConfig.FixedCameraPickNum = FixedCameraPickNum;
  1624. sysConfig.FixedCameraPutNum = FixedCameraPutNum;
  1625. sysConfig.FixedCameracheckNum = FixedCameracheckNum;
  1626. sysConfig.ScrewTeachNum = ScrewTeachNum;
  1627. sysConfig.IsSaveScrewCurve = IsSaveScrewCurve;
  1628. sysConfig.ScrewCurvePath = ScrewCurvePath;
  1629. sysConfig.IsBasePartCodeGetSN = IsBasePartCodeGetSN;
  1630. sysConfig.IsBasePartCodeChooseScrew = IsBasePartCodeChooseScrew;
  1631. sysConfig.IsBasePartOpenLightKB = IsBasePartOpenLightKB;
  1632. sysConfig.IsBasePartOpenLight = IsBasePartOpenLight;
  1633. sysConfig.ChooseScrewModel = ChooseScrewModel;
  1634. _configService.SaveSystemConfiguration(sysConfig);
  1635. await management.WriteSystemParameterToPlcAsync(sysConfig);
  1636. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1637. _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
  1638. }
  1639. catch (Exception ex)
  1640. {
  1641. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1642. _eventAggregator.GetEvent<CurrentStatusNotification>().Publish();
  1643. }
  1644. }
  1645. }
  1646. /// <summary>
  1647. /// 保存读卡器配置
  1648. /// </summary>
  1649. void ExecuteSaveCardReaderConfigCommand()
  1650. {
  1651. try
  1652. {
  1653. _configService.SaveCardReaderConfig(CardReaderConfig);
  1654. }
  1655. catch (Exception ex)
  1656. {
  1657. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1658. }
  1659. }
  1660. void ExecuteSaveTorqueReaderConfigCommand()
  1661. {
  1662. try
  1663. {
  1664. _configService.SaveTorqueReaderConfig(TorqueReadConfig);
  1665. }
  1666. catch (Exception ex)
  1667. {
  1668. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1669. }
  1670. }
  1671. #endregion
  1672. #region 设备信息
  1673. /// <summary>
  1674. /// 保存当前选中的设备信息
  1675. /// </summary>
  1676. void ExecuteSaveDeviceInfoCommand()
  1677. {
  1678. try
  1679. {
  1680. if (DeviceInfoList != null && DeviceInfoList.Count > 0)
  1681. {
  1682. // 保存所有设备信息
  1683. _configService.SaveAllDeviceInfos(DeviceInfoList);
  1684. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1685. }
  1686. }
  1687. catch (Exception ex)
  1688. {
  1689. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1690. }
  1691. }
  1692. /// <summary>
  1693. /// 添加新设备
  1694. /// </summary>
  1695. void ExecuteAddDeviceInfoCommand()
  1696. {
  1697. try
  1698. {
  1699. var newDevice = _configService.AddDeviceInfo();
  1700. if (DeviceInfoList == null)
  1701. {
  1702. DeviceInfoList = new ObservableCollection<DeviceInfo>();
  1703. }
  1704. DeviceInfoList.Add(newDevice);
  1705. SelectDeviceInfo = newDevice;
  1706. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1707. }
  1708. catch (Exception ex)
  1709. {
  1710. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1711. }
  1712. }
  1713. /// <summary>
  1714. /// 删除当前选中的设备
  1715. /// </summary>
  1716. void ExecuteRemoveDeviceInfoCommand()
  1717. {
  1718. try
  1719. {
  1720. if (SelectDeviceInfo != null && DeviceInfoList != null && DeviceInfoList.Count > 1)
  1721. {
  1722. var deviceNo = SelectDeviceInfo.DeviceNo;
  1723. if (_configService.RemoveDeviceInfo(deviceNo))
  1724. {
  1725. DeviceInfoList.Remove(SelectDeviceInfo);
  1726. SelectDeviceInfo = DeviceInfoList.FirstOrDefault();
  1727. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1728. }
  1729. }
  1730. else
  1731. {
  1732. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "至少保留一个设备", Duration = 2 });
  1733. }
  1734. }
  1735. catch (Exception ex)
  1736. {
  1737. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1738. }
  1739. }
  1740. /// <summary>
  1741. /// 选择CSV存储路径
  1742. /// </summary>
  1743. void ExecuteSelectSaveImagePathCommand()
  1744. {
  1745. if (SelectDeviceInfo == null)
  1746. {
  1747. return;
  1748. }
  1749. using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog())
  1750. {
  1751. // Optional: set the initial directory
  1752. //dialog.SelectedPath = @"C:\";
  1753. // Show the folder browser dialog
  1754. System.Windows.Forms.DialogResult result = dialog.ShowDialog();
  1755. if (result == System.Windows.Forms.DialogResult.OK)
  1756. {
  1757. SelectDeviceInfo.SaveCsvPath = dialog.SelectedPath;
  1758. }
  1759. }
  1760. }
  1761. #endregion
  1762. #region 产品与mes绑定
  1763. private async void ExecuteGetProWithMesCommand()
  1764. {
  1765. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1766. if (v == null)
  1767. {
  1768. ProMesInfo.ProductCode = "";
  1769. ProMesInfo.ProductColor = "";
  1770. ProMesInfo.ProductLoadMode = 0;
  1771. }
  1772. else
  1773. {
  1774. ProMesInfo.ProductCode = v.ProductCode;
  1775. ProMesInfo.ProductColor = v.ProductColor;
  1776. ProMesInfo.ProductLoadMode = v.ProductLoadMode;
  1777. }
  1778. }
  1779. private async void ExecuteDeleteProWithMesCommand()
  1780. {
  1781. var v = await _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
  1782. if (v > 0)
  1783. {
  1784. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "删除成功", Duration = 1 });
  1785. var F = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1786. if (F == null)
  1787. {
  1788. ProMesInfo.ProductCode = "";
  1789. ProMesInfo.ProductColor = "";
  1790. ProMesInfo.ProductLoadMode = 0;
  1791. }
  1792. }
  1793. }
  1794. private async void ExecuteSaveProWithMesCommandAsync()
  1795. {
  1796. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1797. if (v == null)
  1798. {
  1799. await _systemDatabaseService.InsertProWithMesAsync(ProMesInfo, SelectProduct);
  1800. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加成功", Duration = 1 });
  1801. }
  1802. else
  1803. {
  1804. var n = await _systemDatabaseService.UpdateProductWithMesAsync(ProMesInfo, SelectProduct);
  1805. if (n > 0)
  1806. {
  1807. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "更新成功", Duration = 1 });
  1808. }
  1809. }
  1810. }
  1811. #endregion
  1812. private DelegateCommand _testCommand;
  1813. public DelegateCommand testCommand =>
  1814. _testCommand ?? (_testCommand = new DelegateCommand(Execute_testCommand));
  1815. private async void Execute_testCommand()
  1816. {
  1817. }
  1818. }
  1819. }