SettingViewModel.cs 75 KB

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