SettingViewModel.cs 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  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. }
  1723. private async void ExecuteDeleteProWithMesCommand()
  1724. {
  1725. var v = await _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
  1726. if (v > 0)
  1727. {
  1728. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "删除成功", Duration = 1 });
  1729. var F = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1730. if (F == null)
  1731. {
  1732. ProMesInfo.ProductCode = "";
  1733. ProMesInfo.ProductColor = "";
  1734. }
  1735. }
  1736. }
  1737. private async void ExecuteSaveProWithMesCommandAsync()
  1738. {
  1739. var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
  1740. if (v == null)
  1741. {
  1742. await _systemDatabaseService.InsertProWithMesAsync(ProMesInfo, SelectProduct);
  1743. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加成功", Duration = 1 });
  1744. }
  1745. else
  1746. {
  1747. var n = await _systemDatabaseService.UpdateProductWithMesAsync(ProMesInfo, SelectProduct);
  1748. if (n > 0)
  1749. {
  1750. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "更新成功", Duration = 1 });
  1751. }
  1752. }
  1753. }
  1754. #endregion
  1755. private DelegateCommand _testCommand;
  1756. public DelegateCommand testCommand =>
  1757. _testCommand ?? (_testCommand = new DelegateCommand(Execute_testCommand));
  1758. public FtpUploader ftpService { get; set; } = new FtpUploader();
  1759. private async void Execute_testCommand()
  1760. {
  1761. //var stationConfig = _configService.GetDeviceInfo(0);
  1762. //ftpService.UploadToFtp(stationConfig.SaveCsvPath);
  1763. var currentproduct = _productService.GetCurrentProduct();
  1764. string sn = $"CN0D0NDYCKJ006260336X02";
  1765. string zippath = await ftpService.CompressionImage(sn, currentproduct.Name);
  1766. ftpService.UploadToFtp(zippath);
  1767. }
  1768. }
  1769. }