TorqueCheckViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. using MathNet.Numerics;
  2. using NPOI.OpenXml4Net.OPC.Internal;
  3. using NPOI.SS.Formula.Functions;
  4. using OxyPlot;
  5. using Prism.Commands;
  6. using Prism.Events;
  7. using Prism.Ioc;
  8. using Prism.Mvvm;
  9. using Prism.Services.Dialogs;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using TeamAAS_VP.Controls;
  20. using TeamAAS_VP.Core;
  21. using TeamAAS_VP.Core.PLCs;
  22. using TeamAAS_VP.Core.ScrewDriver;
  23. using TeamAAS_VP.Data;
  24. using TeamAAS_VP.Enums;
  25. using TeamAAS_VP.Events;
  26. using TeamAAS_VP.Interfaces;
  27. using TeamAAS_VP.Models;
  28. using TeamAAS_VP.Models.PLC;
  29. using TeamAAS_VP.Models.Torque;
  30. using TeamAAS_VP.Resources.Languages;
  31. using TeamAAS_VP.Services;
  32. using FileHelper = TeamAAS_VP.Core.FileHelper;
  33. namespace TeamAAS_VP.ViewModels.Home
  34. {
  35. public class TorqueCheckViewModel : BindableBase, IDialogAware
  36. {
  37. // 点检扭矩参数存放日志地址
  38. public static readonly string CheckTorqueConfigurationPath = "..//Log//ScrewFeedersConfiguration.cfg";
  39. IEventAggregator _eventAggregator;
  40. IConfigService _configService;
  41. IContainerProvider _container;
  42. IRobotService _robotService;
  43. IPlcService _plcService;
  44. TorqueService _torqueService;
  45. float Value { get; set; } = 0;
  46. #region 属性
  47. private Management _management;
  48. public Management management
  49. {
  50. get { return _management; }
  51. set { SetProperty(ref _management, value); }
  52. }
  53. private bool CanExecute
  54. {
  55. get
  56. {
  57. // 命令可执行仅当机器人可执行且已选择点位
  58. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  59. {
  60. return true;
  61. }
  62. return false;
  63. }
  64. }
  65. private IRobot _Robot;
  66. public IRobot Robot
  67. {
  68. get { return _Robot; }
  69. set { SetProperty(ref _Robot, value); }
  70. }
  71. private double _Distance = 1;
  72. public double Distance
  73. {
  74. get { return _Distance; }
  75. set
  76. {
  77. SetProperty(ref _Distance, value);
  78. try
  79. {
  80. if (Robot == null)
  81. {
  82. return;
  83. }
  84. _configService.UpdateRobotStepDistance(Robot.Id, value);
  85. }
  86. catch (Exception)
  87. {
  88. }
  89. }
  90. }
  91. private float _Z_Distance;
  92. public float Z_Distance
  93. {
  94. get { return _Z_Distance; }
  95. set { SetProperty(ref _Z_Distance, value); }
  96. }
  97. private float _torqueValue;
  98. public float TorqueValue
  99. {
  100. get { return _torqueValue; }
  101. set { SetProperty(ref _torqueValue, value); }
  102. }
  103. private string _TValue;
  104. public string TValue
  105. {
  106. get { return _TValue; }
  107. set
  108. {
  109. SetProperty(ref _TValue, value);
  110. }
  111. }
  112. private string _PValue;
  113. public string PValue
  114. {
  115. get { return _PValue; }
  116. set
  117. {
  118. SetProperty(ref _PValue, value);
  119. }
  120. }
  121. private string _SubValue;
  122. public string SubValue
  123. {
  124. get { return _SubValue; }
  125. set { SetProperty(ref _SubValue, value); }
  126. }
  127. private string _Result;
  128. public string Result
  129. {
  130. get { return _Result; }
  131. set { SetProperty(ref _Result, value); }
  132. }
  133. private string _FontColor;
  134. public string FontColor
  135. {
  136. get { return _FontColor; }
  137. set { SetProperty(ref _FontColor, value); }
  138. }
  139. private int _SelectedIndex;
  140. public int SelectedIndex
  141. {
  142. get { return _SelectedIndex; }
  143. set { SetProperty(ref _SelectedIndex, value); }
  144. }
  145. private ObservableCollection<PlcPoint_Torque> _Points = new ObservableCollection<PlcPoint_Torque>();
  146. /// <summary>
  147. /// 点位集合
  148. /// </summary>
  149. public ObservableCollection<PlcPoint_Torque> Points
  150. {
  151. get { return _Points; }
  152. set { SetProperty(ref _Points, value); }
  153. }
  154. private TorqueProduceModel _AllProductParameter = new TorqueProduceModel();
  155. /// <summary>
  156. /// 所有产品的参数信息
  157. /// </summary>
  158. public TorqueProduceModel AllProductParameter
  159. {
  160. get { return _AllProductParameter; }
  161. set { SetProperty(ref _AllProductParameter, value); }
  162. }
  163. private PlcPoint_Torque _selectedPointInDataGrid;
  164. public PlcPoint_Torque SelectedPointInDataGrid
  165. {
  166. get { return _selectedPointInDataGrid; }
  167. set
  168. {
  169. SetProperty(ref _selectedPointInDataGrid, value);
  170. // 可以同步到 SelectPoint 属性
  171. SelectedPoint = value;
  172. AllProductParameter.TorquePoints = _Points;
  173. }
  174. }
  175. private PlcPoint_Torque _SelectedPoint;
  176. public PlcPoint_Torque SelectedPoint
  177. {
  178. get { return _SelectedPoint; }
  179. set { SetProperty(ref _SelectedPoint, value); }
  180. }
  181. #endregion
  182. #region 命令
  183. private DelegateCommand _CancelCommand;
  184. public DelegateCommand CancelCommand =>
  185. _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  186. private DelegateCommand _LoadedCommand;
  187. public DelegateCommand LoadedCommand =>
  188. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  189. private DelegateCommand _ConfirmCommand;
  190. public DelegateCommand ConfirmCommand =>
  191. _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
  192. private DelegateCommand<string> _MotorCommand;
  193. public DelegateCommand<string> MotorCommand =>
  194. _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  195. private DelegateCommand<object> _JogCommand;
  196. public DelegateCommand<object> JogCommand =>
  197. _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  198. private DelegateCommand _TechPointCommand;
  199. public DelegateCommand TechPointCommand =>
  200. _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand));
  201. private DelegateCommand _ModifyCommand;
  202. public DelegateCommand ModifyCommand =>
  203. _ModifyCommand ?? (_ModifyCommand = new DelegateCommand(ExecuteModifyCommand));
  204. private DelegateCommand _WorkCommand;
  205. public DelegateCommand WorkCommand =>
  206. _WorkCommand ?? (_WorkCommand = new DelegateCommand(ExecuteWorkCommand));
  207. private DelegateCommand _AddPointCommand;
  208. public DelegateCommand AddPointCommand =>
  209. _AddPointCommand ?? (_AddPointCommand = new DelegateCommand(ExecuteAddPointCommand));
  210. private DelegateCommand _SavePointsCommand;
  211. public DelegateCommand SavePointsCommand =>
  212. _SavePointsCommand ?? (_SavePointsCommand = new DelegateCommand(ExecuteSavePointsCommand));
  213. private DelegateCommand _DeletePointCommand;
  214. public DelegateCommand DeletePointCommand =>
  215. _DeletePointCommand ?? (_DeletePointCommand = new DelegateCommand(ExecuteDeletePointCommand, CanExecuteDeletePointCommand).ObservesProperty(() => SelectedPointInDataGrid));
  216. #endregion
  217. #region 方法
  218. public TorqueCheckViewModel(IEventAggregator ea, IConfigService configService, TorqueService torqueService,
  219. IContainerProvider container, IRobotService robotService, IPlcService plcService)
  220. {
  221. _eventAggregator = ea;
  222. _configService = configService;
  223. _container = container;
  224. _robotService = robotService;
  225. _plcService = plcService;
  226. _torqueService = torqueService;
  227. management = _container.Resolve<Management>();
  228. }
  229. bool CanExecuteDeletePointCommand()
  230. {
  231. return SelectedPointInDataGrid != null;
  232. }
  233. void ExecuteCancelCommand()
  234. {
  235. IDialogParameters parameters = new DialogParameters();
  236. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
  237. }
  238. void ExecuteConfirmCommand()
  239. {
  240. IDialogParameters parameters = new DialogParameters();
  241. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
  242. }
  243. /// <summary>
  244. /// 电机
  245. /// </summary>
  246. /// <param name="obj"></param>
  247. private async void ExecuteMotorCommand(string obj)
  248. {
  249. if (Robot == null || !Robot.IsConnected) return;
  250. try
  251. {
  252. await Robot.MotorAsync(Convert.ToBoolean(obj));
  253. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  254. }
  255. catch (Exception ex)
  256. {
  257. LogHelper.WriteLogError("机器人点击操作时出错!", ex);
  258. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  259. }
  260. }
  261. /// <summary>
  262. /// 点动
  263. /// </summary>
  264. /// <param name="obj"></param>
  265. private async void ExecuteJogCommand(object obj)
  266. {
  267. if (Robot == null || !Robot.IsConnected) return;
  268. try
  269. {
  270. var items = ((string)obj).Split(':');
  271. //如果移动距离大于10mm,则提示用户确认
  272. double distance = double.Parse(items[1]);
  273. if (Math.Abs(distance) >= 10)
  274. {
  275. if (MessageBox.Show($"确认要点动距离 {distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  276. {
  277. return;
  278. }
  279. }
  280. Robot.Timeout = 6000000;
  281. switch (items[0])
  282. {
  283. case "X+":
  284. await Robot.JogAsync("X", distance);
  285. break;
  286. case "X-":
  287. await Robot.JogAsync("X", -distance);
  288. break;
  289. case "Y+":
  290. await Robot.JogAsync("Y", distance);
  291. break;
  292. case "Y-":
  293. await Robot.JogAsync("Y", -distance);
  294. break;
  295. case "Z+":
  296. await Robot.JogAsync("Z", distance);
  297. break;
  298. case "Z-":
  299. await Robot.JogAsync("Z", -distance);
  300. break;
  301. case "U+":
  302. await Robot.JogAsync("U", distance);
  303. break;
  304. case "U-":
  305. await Robot.JogAsync("U", -distance);
  306. break;
  307. case "V+":
  308. await Robot.JogAsync("V", distance);
  309. break;
  310. case "V-":
  311. await Robot.JogAsync("V", -distance);
  312. break;
  313. case "W+":
  314. await Robot.JogAsync("W", distance);
  315. break;
  316. case "W-":
  317. await Robot.JogAsync("W", -distance);
  318. break;
  319. default:
  320. break;
  321. }
  322. Robot.Timeout = 5000;
  323. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  324. }
  325. catch (Exception ex)
  326. {
  327. LogHelper.WriteLogError("机器人点位-机器人点动时出错", ex);
  328. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  329. }
  330. }
  331. /// <summary>
  332. /// 示教点位
  333. /// </summary>
  334. async void ExecuteTechPointCommand()
  335. {
  336. //弹窗用户是否确认要示教该点位
  337. if (MessageBox.Show($"确认要示教点位吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  338. {
  339. return;
  340. }
  341. if (SelectedPoint == null)
  342. {
  343. MessageBox.Show("请选择示教点位");
  344. return;
  345. }
  346. var curpos = await Robot.GetRobotPosAsync();
  347. SelectedPoint.X_Position = curpos.X;
  348. SelectedPoint.Y_Position = curpos.Y;
  349. SelectedPoint.Z_Position_Start = curpos.Z;
  350. //SelectedPoint.Z_Position_Stop = curpos.Z - (float)this.Z_Distance;
  351. SelectedPoint.Z_Position_Stop = 0;
  352. AllProductParameter.TorqueValue = this.TorqueValue;
  353. AllProductParameter.TorquePoints = Points;
  354. FileHelper.WriteJsonFile(AllProductParameter, FilePath.TorqueCheckPath);
  355. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  356. }
  357. /// <summary>
  358. /// 修改
  359. /// </summary>
  360. async void ExecuteModifyCommand()
  361. {
  362. if (MessageBox.Show($"确认要修改扭力阈值吗?", "修改", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  363. {
  364. return;
  365. }
  366. var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
  367. res.TorqueValue = this.TorqueValue;
  368. FileHelper.WriteJsonFile(res, FilePath.TorqueCheckPath);
  369. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.4 });
  370. }
  371. async void ExecuteWorkCommand()
  372. {
  373. if (!File.Exists(FilePath.TorqueCheckPath))
  374. {
  375. MessageBox.Show("还未示教,请先示教");
  376. return;
  377. }
  378. if (Robot == null || !Robot.IsConnected)
  379. {
  380. return;
  381. }
  382. if (MessageBox.Show($"确认要进行点检吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  383. {
  384. return;
  385. }
  386. try
  387. {
  388. if (await MoveRobot())
  389. {
  390. }
  391. }
  392. catch (Exception ex)
  393. {
  394. LogHelper.WriteLogError("执行点检时出错!", ex);
  395. }
  396. }
  397. /// <summary>
  398. /// 点检扭矩总体流程
  399. /// </summary>
  400. /// <returns></returns>
  401. public async Task<bool> MoveRobot()
  402. {
  403. var Plc_Point = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
  404. PlcAddressConfig addressConfig = _configService.GetPlcAddresses();
  405. OpcUaClientPLC plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
  406. try
  407. {
  408. if (Plc_Point == null || addressConfig == null || plc == null)
  409. {
  410. return false;
  411. }
  412. //切换手动模式
  413. if (await plc.WriteNodeAsync<bool>(addressConfig.OP_AutoManual.Address, false))
  414. {
  415. //回设置的零点
  416. if (await _torqueService.Safety_Position_Async(Robot, plc, addressConfig, Plc_Point))
  417. {
  418. //执行抛螺丝动作
  419. if (await _torqueService.Throw_Screw_Async(Robot, plc, addressConfig, Plc_Point))
  420. {
  421. //执行取螺丝动作
  422. if (await _torqueService.Pick_Screw_Async(Robot, plc, addressConfig, Plc_Point))
  423. {
  424. //执行锁螺丝点位操作
  425. if (await _torqueService.Screw_Torque_Async(Robot, plc, addressConfig, Plc_Point))
  426. {
  427. //获取电批结果并显示曲线
  428. if (await WatchAsync(plc, addressConfig))
  429. {
  430. await DisplayResult();
  431. return true;
  432. }
  433. MessageBox.Show("未获取到电批结果"); return false;
  434. }
  435. MessageBox.Show("执行锁螺丝点位操作失败"); return false;
  436. }
  437. MessageBox.Show("执行取螺丝动作失败"); return false;
  438. }
  439. MessageBox.Show("执行抛螺丝动作失败"); return false;
  440. }
  441. MessageBox.Show("执行回安全点失败"); return false;
  442. }
  443. MessageBox.Show("点检失败");return false;
  444. }
  445. catch (Exception ex)
  446. {
  447. LogHelper.WriteLogError("执行点检移动时出错!", ex);
  448. return false;
  449. }
  450. finally
  451. {
  452. await _torqueService.Safety_Position_Async(Robot, plc, addressConfig, Plc_Point);
  453. }
  454. }
  455. public async Task DisplayResult()
  456. {
  457. try
  458. {
  459. Thread.Sleep(100);
  460. TValue = management.SignalValue;
  461. double tvalue = double.Parse(TValue.Split(' ')[0]);
  462. double pvalue = Value;
  463. PValue = $"{Math.Round(pvalue, 3)} kgf.cm";
  464. SubValue = $"{Math.Round(Math.Abs(tvalue - pvalue), 3)} kgf.cm";
  465. double sub = Math.Abs(tvalue - pvalue);
  466. var res = FileHelper.ReadJsonFile<TorqueTest>(FilePath.TorqueCheckPath);
  467. if (res != null)
  468. {
  469. if (sub <= res.TorqueValue)
  470. {
  471. FontColor = "Green";
  472. Result = "OK";
  473. }
  474. else
  475. {
  476. FontColor = "Red";
  477. Result = "NG";
  478. }
  479. }
  480. else
  481. {
  482. if (sub <= TorqueValue)
  483. {
  484. FontColor = "Green";
  485. Result = "OK";
  486. }
  487. else
  488. {
  489. FontColor = "Red";
  490. Result = "NG";
  491. }
  492. }
  493. }
  494. catch (Exception ex)
  495. {
  496. LogHelper.WriteLogError("执行点检显示时出错!", ex);
  497. }
  498. }
  499. public void Save_Torque_Parameter()
  500. {
  501. }
  502. public async Task<bool> WatchAsync(OpcUaClientPLC plc, PlcAddressConfig addressConfig)
  503. {
  504. Thread.Sleep(100);
  505. object oking = null;
  506. object nging = null;
  507. int count = 0;
  508. while (count++ < 10)
  509. {
  510. oking = plc.ReadNode(addressConfig.Screw_OK.Address);
  511. nging = plc.ReadNode(addressConfig.Screw_NG.Address);
  512. if (oking != null && nging != null)
  513. {
  514. bool okin = (bool)oking; bool ngin = (bool)nging;
  515. //电批OKNG
  516. if (okin || ngin)
  517. {
  518. //获取电批结果
  519. bool isSucced = management.ScrewDriver.GetData();
  520. LockResult lockResult = new LockResult();
  521. lockResult.LockTurns = (float)management.ScrewDriver.Truns;
  522. lockResult.LockTorque = (float)management.ScrewDriver.TorqueValue;
  523. lockResult.WaveDatas = management.ScrewDriver.WaveDatas;
  524. App.Current.Dispatcher.Invoke(() =>
  525. {
  526. _eventAggregator.GetEvent<LockFinishNotification>().Publish(lockResult);
  527. });
  528. //await _systemDatabaseService.RecordLockResultAsync(lockResult);
  529. await plc.WriteNodeAsync(addressConfig.In_WorkDone.Address, (Int16)0);
  530. Value = lockResult.LockTorque;
  531. await plc.WriteNodeAsync(addressConfig.Check_ScrewTorque.Address, false);
  532. return true;
  533. }
  534. }
  535. }
  536. return false;
  537. }
  538. #endregion
  539. public string Title { get; set; } = "扭力点检";
  540. public event Action<IDialogResult> RequestClose;
  541. public bool CanCloseDialog()
  542. {
  543. return true;
  544. }
  545. public void OnDialogClosed()
  546. {
  547. }
  548. public void OnDialogOpened(IDialogParameters parameters)
  549. {
  550. try
  551. {
  552. var res = FileHelper.ReadJsonFile<TorqueTest>(FilePath.TorqueCheckPath);
  553. if (res != null)
  554. {
  555. res.TorqueValue = TorqueValue;
  556. }
  557. else
  558. {
  559. MessageBox.Show("还未示教,请先示教");
  560. }
  561. }
  562. catch (Exception)
  563. {
  564. MessageBox.Show("还未示教,请先示教");
  565. }
  566. if (Robot == null)
  567. {
  568. Robot = _robotService.GetRobotByNumber(1);
  569. }
  570. if (Robot != null && Robot.IsConnected)
  571. {
  572. this.Distance = _configService.GetRobotStepDistance(Robot.Id);
  573. Robot.EnterDebugMode = true;
  574. }
  575. else if (Robot != null)
  576. {
  577. Robot.EnterDebugMode = true;
  578. }
  579. }
  580. private void ExecuteLoadedCommand()
  581. {
  582. var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
  583. this.Points = res.TorquePoints;
  584. this.TorqueValue = res.TorqueValue;
  585. }
  586. #region 添加点位与删除点位
  587. /// <summary>
  588. /// 增加点位
  589. /// </summary>
  590. private void ExecuteAddPointCommand()
  591. {
  592. //添加点位
  593. Points.Add(new PlcPoint_Torque()
  594. {
  595. Number = Points.Count + 1,
  596. });
  597. }
  598. /// <summary>
  599. /// 移除点位
  600. /// </summary>
  601. private void ExecuteDeletePointCommand()
  602. {
  603. if (SelectedPoint == null)
  604. {
  605. return;
  606. }
  607. // 确认删除
  608. if (MessageBox.Show(Lang.确认要删除选中的点位吗, Lang.删除点位, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  609. {
  610. return;
  611. }
  612. int removedIndex = Points.IndexOf(SelectedPoint);
  613. Points.Remove(SelectedPoint);
  614. //重新编号
  615. for (int i = 0; i < Points.Count; i++)
  616. {
  617. Points[i].Number = i + 1;
  618. }
  619. // adjust selection
  620. if (Points.Count > 0)
  621. {
  622. int newIndex = Math.Min(removedIndex, Points.Count - 1);
  623. SelectedPointInDataGrid = Points[newIndex];
  624. }
  625. else
  626. {
  627. SelectedPointInDataGrid = null;
  628. }
  629. }
  630. #endregion
  631. private void ExecuteSavePointsCommand()
  632. {
  633. AllProductParameter.TorqueValue = this.TorqueValue;
  634. AllProductParameter.TorquePoints = Points;
  635. FileHelper.WriteJsonFile(AllProductParameter, FilePath.TorqueCheckPath);
  636. MessageBox.Show("参数保存成功");
  637. }
  638. }
  639. }