ShakerControlViewModel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. using HandyControl.Interactivity.Commands;
  2. using OxyPlot;
  3. using Shaker.Model;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.ComponentModel.DataAnnotations;
  8. using System.Diagnostics.CodeAnalysis;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. namespace ShakerManger.ViewModel
  16. {
  17. internal class ShakerControlViewModel:Shaker.ViewModel.DisplayViewModel<Shaker.Model.ShakerControlModel>
  18. {
  19. public string ClientID { get => Model.ClientID; set => UpdateProperty(ref Model.ClientID, value); }
  20. public int MaxItemCount => 1000;
  21. private ObservableCollection<DataMangerItemViewModel> Items { get; } = new ObservableCollection<DataMangerItemViewModel>();
  22. private List<OxyPlot.Series.LineSeries> _LineSeries = new List<OxyPlot.Series.LineSeries>();
  23. public string[] PropertiyNames { get; }= new string[]
  24. {
  25. nameof(DataMangerItemModel.OperatingStatus),
  26. nameof(DataMangerItemModel.OutputCurrent),
  27. nameof(DataMangerItemModel.OutputVoltage),
  28. nameof(DataMangerItemModel.ExcitationCurrent),
  29. nameof(DataMangerItemModel.ExcitationVoltage),
  30. nameof(DataMangerItemModel.ThreePhaseVoltage),
  31. nameof(DataMangerItemModel.AbutmentTemperature0),
  32. nameof(DataMangerItemModel.AbutmentTemperature1),
  33. nameof(DataMangerItemModel.DCVoltage1),
  34. nameof(DataMangerItemModel.DCVoltage2),
  35. nameof(DataMangerItemModel.DCVoltage3),
  36. nameof(DataMangerItemModel.DCVoltage4),
  37. nameof(DataMangerItemModel.Gain),
  38. };
  39. public ICommand DisConnectCommand=> new DelegateCommand(DisConnect);
  40. private void DisConnect()
  41. {
  42. PromptViewModel.Default.Init();
  43. PromptViewModel.Default.IconType = IconType.Ask;
  44. PromptViewModel.Default.Message = "是否断开功放连接?";
  45. PromptViewModel.Default.YesAction = async ()=>
  46. {
  47. var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new SysControl()
  48. {
  49. Cmd = SysCmd.DisConnect,
  50. }, Properties);
  51. if (result == null ||!result.Success)
  52. {
  53. PromptViewModel.Default.Init();
  54. PromptViewModel.Default.IconType = IconType.Error;
  55. PromptViewModel.Default.Message = result == null? "通信超时" : result.Message;
  56. PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
  57. PromptViewModel.Default.IsOpen = true;
  58. }
  59. };
  60. PromptViewModel.Default.IsOpen = true;
  61. }
  62. public ICommand ConnectCommand => new DelegateCommand(Connect);
  63. private async void Connect()
  64. {
  65. var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new SysControl()
  66. {
  67. Cmd = SysCmd.Connect,
  68. },Properties);
  69. if(result == null || !result.Success)
  70. {
  71. PromptViewModel.Default.Init();
  72. PromptViewModel.Default.IconType = IconType.Error;
  73. PromptViewModel.Default.Message = result == null?"通信超时": result.Message;
  74. PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
  75. PromptViewModel.Default.IsOpen= true;
  76. }
  77. }
  78. public bool IsOnline { get => isOnline; set =>UpdateProperty(ref isOnline, value); }
  79. public DataMangerItemViewModel CurrentData { get => currentData; set =>UpdateProperty(ref currentData, value); }
  80. public Boolean SetPlotConfigIsOpen
  81. {
  82. get => setPlotConfigIsOpen;
  83. set
  84. {
  85. UpdateProperty(ref setPlotConfigIsOpen, value);
  86. if(value)
  87. {
  88. foreach(var item in PlotConfig)
  89. {
  90. item.Init();
  91. }
  92. }
  93. }
  94. }
  95. public bool IsConnected { get => isConnected; set =>UpdateProperty(ref isConnected, value); }
  96. public string[] AnalogNames { get; } = new string[12];
  97. public string[] Units { get; } = new string[12];
  98. private Dictionary<string, string> Properties { get; init; } = new Dictionary<string, string>();
  99. public ObservableCollection<PlotConfigViewModel> PlotConfig { get; } = new ObservableCollection<PlotConfigViewModel>();
  100. public ShakerControlViewModel(Shaker.Model.ShakerControlModel model)
  101. {
  102. Model = model;
  103. CurrentData = new DataMangerItemViewModel(new DataMangerItemModel());
  104. Properties[Shaker.Model.GlobalVariable.ShakerIDKey] = model.Id;
  105. AnalogNames[0] = Model.OperatingStatus.Name;
  106. AnalogNames[1] = Model.OutputCurrent.Name;
  107. AnalogNames[2] = Model.OutputVoltage.Name;
  108. AnalogNames[3] = Model.ExcitationCurrent.Name;
  109. AnalogNames[4] = Model.ExcitationVoltage.Name;
  110. AnalogNames[5] = Model.ThreePhaseVoltage.Name;
  111. Units[0] = Model.OperatingStatus.Unit;
  112. Units[1] = Model.OutputCurrent.Unit;
  113. Units[2] = Model.OutputVoltage.Unit;
  114. Units[3] = Model.ExcitationCurrent.Unit;
  115. Units[4] = Model.ExcitationVoltage.Unit;
  116. Units[5] = Model.ThreePhaseVoltage.Unit;
  117. if (!string.IsNullOrEmpty(model.AbutmentTemperature0.Name))
  118. {
  119. AnalogNames[6] = Model.AbutmentTemperature0.Name;
  120. Units[6] = Model.AbutmentTemperature0.Unit;
  121. }
  122. if (!string.IsNullOrEmpty(model.AbutmentTemperature1.Name))
  123. {
  124. AnalogNames[7] = Model.AbutmentTemperature1.Name;
  125. Units[7] = Model.AbutmentTemperature1.Unit;
  126. }
  127. if (!string.IsNullOrEmpty(model.DCVoltage1.Name))
  128. {
  129. AnalogNames[8] = Model.DCVoltage1.Name;
  130. Units[8] = Model.DCVoltage1.Unit;
  131. }
  132. if (!string.IsNullOrEmpty(model.DCVoltage2.Name))
  133. {
  134. AnalogNames[9] = Model.DCVoltage2.Name;
  135. Units[9] = Model.DCVoltage2.Unit;
  136. }
  137. if (!string.IsNullOrEmpty(model.DCVoltage3.Name))
  138. {
  139. AnalogNames[10] = Model.DCVoltage3.Name;
  140. Units[10] = Model.DCVoltage3.Unit;
  141. }
  142. if (!string.IsNullOrEmpty(model.DCVoltage4.Name))
  143. {
  144. AnalogNames[11] = Model.DCVoltage4.Name;
  145. Units[11] = Model.DCVoltage4.Unit;
  146. }
  147. PlotModel.TextColor = OxyColors.White;
  148. PlotModel.TitleColor = OxyColors.White;
  149. PlotModel.PlotAreaBorderColor = OxyColors.White;
  150. PlotModel.Axes.Add(new OxyPlot.Axes.DateTimeAxis()
  151. {
  152. Title = "时间",
  153. Position = OxyPlot.Axes.AxisPosition.Bottom,
  154. Key = "X",
  155. MaximumPadding = 0,
  156. MajorGridlineColor = OxyPlot.OxyColors.Gray,
  157. MajorGridlineStyle = LineStyle.Dot,
  158. MajorGridlineThickness = 1,
  159. MinimumPadding = 0,
  160. ExtraGridlineColor = OxyPlot.OxyColors.White,
  161. TextColor = OxyColors.White,
  162. TitleColor = OxyColors.White,
  163. AxislineColor = OxyColors.White,
  164. TicklineColor = OxyColors.White,
  165. });
  166. PlotModel.Axes.Add(new OxyPlot.Axes.LinearAxis()
  167. {
  168. Title = "值",
  169. Position = OxyPlot.Axes.AxisPosition.Left,
  170. Key = "Y",
  171. MajorGridlineStyle = LineStyle.Dot,
  172. MajorGridlineColor = OxyPlot.OxyColors.Gray,
  173. MajorGridlineThickness = 1,
  174. ExtraGridlineColor = OxyPlot.OxyColors.White,
  175. TextColor = OxyColors.White,
  176. TitleColor = OxyColors.White,
  177. AxislineColor = OxyColors.White,
  178. TicklineColor = OxyColors.White,
  179. });
  180. for (int i = 0; i < AnalogNames.Length; i++)
  181. {
  182. if (string.IsNullOrEmpty(AnalogNames[i]) || i == 0) continue;
  183. OxyPlot.Series.LineSeries lineSeries = new OxyPlot.Series.LineSeries();
  184. lineSeries.Title = AnalogNames[i];
  185. lineSeries.StrokeThickness = 1;
  186. lineSeries.XAxisKey = "X";
  187. lineSeries.YAxisKey = "Y";
  188. lineSeries.TrackerFormatString = "{1}:{2}\n{0}:{4}" + Units[i];
  189. lineSeries.CanTrackerInterpolatePoints = false;
  190. lineSeries.DataFieldX = nameof(DataMangerItemModel.Time);
  191. lineSeries.DataFieldY = PropertiyNames[i];
  192. _LineSeries.Add(lineSeries);
  193. PlotModel.Series.Add(lineSeries);
  194. PlotConfig.Add(new PlotConfigViewModel(lineSeries));
  195. PlotConfig[^1].PropertyChanged += (_, _) =>
  196. {
  197. PlotModel.InvalidatePlot(false);
  198. PlotModel.InvalidatePlot(true);
  199. };
  200. }
  201. {
  202. OxyPlot.Series.LineSeries lineSeries = new OxyPlot.Series.LineSeries();
  203. lineSeries.Title = "增益";
  204. lineSeries.XAxisKey = "X";
  205. lineSeries.YAxisKey = "Y";
  206. lineSeries.StrokeThickness = 1;
  207. lineSeries.TrackerFormatString = "{1}:{2}\n{0}:{4}%";
  208. lineSeries.CanTrackerInterpolatePoints = false;
  209. lineSeries.DataFieldX = nameof(DataMangerItemModel.Time);
  210. lineSeries.DataFieldY = PropertiyNames[^1];
  211. _LineSeries.Add(lineSeries);
  212. PlotModel.Series.Add(lineSeries);
  213. PlotConfig.Add(new PlotConfigViewModel(lineSeries));
  214. PlotConfig[^1].PropertyChanged += (_, _) =>
  215. {
  216. PlotModel.InvalidatePlot(false);
  217. PlotModel.InvalidatePlot(true);
  218. };
  219. }
  220. PlotModel.Legends.Add(new OxyPlot.Legends.Legend()
  221. {
  222. IsLegendVisible = true,
  223. ShowInvisibleSeries = true,
  224. });
  225. BusManger.Defaut.Bus.PubSub.Subscribe<Shaker.Model.ShakerConnectState>((data, _) =>
  226. {
  227. if (Thread.CurrentThread == Application.Current?.Dispatcher?.Thread)
  228. {
  229. IsConnected = data.IsConnected;
  230. }
  231. else
  232. {
  233. App.Current?.Dispatcher?.BeginInvoke(() =>
  234. {
  235. IsConnected = data.IsConnected;
  236. });
  237. }
  238. }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
  239. BusManger.Defaut.Bus.PubSub.Subscribe<Shaker.Model.ShakerStatusModel>((data, _) =>
  240. {
  241. if (Thread.CurrentThread == Application.Current?.Dispatcher?.Thread)
  242. {
  243. GainSwich = data.GainSwich;
  244. }
  245. else
  246. {
  247. App.Current?.Dispatcher?.BeginInvoke(() =>
  248. {
  249. GainSwich = data.GainSwich;
  250. });
  251. }
  252. }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
  253. BusManger.Defaut.Bus.PubSub.Subscribe<Shaker.Model.ClientExitModel>((data, _) =>
  254. {
  255. if (Thread.CurrentThread == Application.Current?.Dispatcher?.Thread)
  256. {
  257. IsOnline = data.Online;
  258. }
  259. else
  260. {
  261. App.Current?.Dispatcher?.BeginInvoke(() =>
  262. {
  263. IsOnline = data.Online;
  264. });
  265. }
  266. }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
  267. BusManger.Defaut.Bus.PubSub.Subscribe<DataMangerItemModel>((model, property) =>
  268. {
  269. if(MainWindowViewModel.Default.IsSaveData) Sql.Default.Insert(model, Model.Id);
  270. if (Thread.CurrentThread == Application.Current?.Dispatcher?.Thread)
  271. {
  272. if(CurrentData==null)
  273. {
  274. CurrentData = new DataMangerItemViewModel(model);
  275. }
  276. else
  277. {
  278. CurrentData.UpDateModel(model);
  279. }
  280. Items.Add(new DataMangerItemViewModel(model));
  281. if (Items.Count > MaxItemCount) Items.RemoveAt(0);
  282. PlotModel.InvalidatePlot(false);
  283. _LineSeries.ForEach(x => x.ItemsSource = Items);
  284. PlotModel.InvalidatePlot(true);
  285. }
  286. else
  287. {
  288. App.Current?.Dispatcher?.BeginInvoke(() =>
  289. {
  290. if (CurrentData == null)
  291. {
  292. CurrentData = new DataMangerItemViewModel(model);
  293. }
  294. else
  295. {
  296. CurrentData.UpDateModel(model);
  297. }
  298. Items.Add(new DataMangerItemViewModel(model));
  299. if (Items.Count > MaxItemCount) Items.RemoveAt(0);
  300. PlotModel.InvalidatePlot(false);
  301. _LineSeries.ForEach(x => x.ItemsSource = Items);
  302. PlotModel.InvalidatePlot(true);
  303. });
  304. }
  305. }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
  306. BusManger.Defaut.Bus.PubSub.Subscribe<Shaker.Model.AllowRemoteControl>((model, property) =>
  307. {
  308. if (Thread.CurrentThread == Application.Current?.Dispatcher?.Thread)
  309. {
  310. IsRemoteControl = model == AllowRemoteControl.Remote;
  311. }
  312. else
  313. {
  314. App.Current?.Dispatcher?.BeginInvoke(() =>
  315. {
  316. IsRemoteControl = model == AllowRemoteControl.Remote;
  317. });
  318. }
  319. }, $"{Shaker.Model.GlobalVariable.ShakerIDKey}='{Model.Id}'");
  320. }
  321. public View.ShakerView Content { get; } = new View.ShakerView();
  322. public bool GainSwich { get => gainSwich; set =>UpdateProperty(ref gainSwich, value); }
  323. public override Type View { get; } = typeof(View.ShakerView);
  324. public ICommand OpenCommand => new DelegateCommand(Open);
  325. public ICommand CloseCommand => new DelegateCommand(Close);
  326. public ICommand StartCommand => new DelegateCommand(Start);
  327. public ICommand StopCommand => new DelegateCommand(Stop);
  328. public ICommand ResetCommand => new DelegateCommand(Reset);
  329. private bool isOpen = false;
  330. public bool ShakerControlIsOpen { get => shakerControlIsOpen; set => UpdateProperty(ref shakerControlIsOpen, value); }
  331. public OxyPlot.PlotModel PlotModel { get; } = new OxyPlot.PlotModel();
  332. public bool IsOpen { get => isOpen; set => UpdateProperty(ref isOpen, value); }
  333. private async void Close()
  334. {
  335. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}关闭功放"));
  336. var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
  337. {
  338. Cmd = Shaker.Model.SysCmd.CloseGain,
  339. }, Properties);
  340. if(result == null || !result.Success)
  341. {
  342. PromptViewModel.Default.Init();
  343. PromptViewModel.Default.IconType = IconType.Error;
  344. PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
  345. PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
  346. PromptViewModel.Default.IsOpen = true;
  347. }
  348. }
  349. private async void SetGain(short gain)
  350. {
  351. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}设置功放增益为{Gain}%"));
  352. var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SetGain,Shaker.Model.Result>(new Shaker.Model.SetGain()
  353. {
  354. Gain = gain,
  355. }, Properties);
  356. if (result == null || !result.Success)
  357. {
  358. PromptViewModel.Default.Init();
  359. PromptViewModel.Default.IconType = IconType.Error;
  360. PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
  361. PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
  362. PromptViewModel.Default.IsOpen = true;
  363. }
  364. }
  365. public bool GainSwitchEnabled => CurrentData?.OperatingStatus == OperatingStatus.Run;
  366. public bool GainEnabled=>CurrentData?.OperatingStatus == OperatingStatus.Run && CurrentData?.
  367. private async void Start()
  368. {
  369. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}功放开始"));
  370. var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
  371. {
  372. Cmd = Shaker.Model.SysCmd.Start,
  373. }, Properties);
  374. if (result == null || !result.Success)
  375. {
  376. PromptViewModel.Default.Init();
  377. PromptViewModel.Default.IconType = IconType.Error;
  378. PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
  379. PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
  380. PromptViewModel.Default.IsOpen = true;
  381. }
  382. }
  383. private async void Stop()
  384. {
  385. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}停止功放"));
  386. var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
  387. {
  388. Cmd = Shaker.Model.SysCmd.Stop,
  389. }, Properties);
  390. }
  391. private async void Reset()
  392. {
  393. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}功放复位"));
  394. var result= await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
  395. {
  396. Cmd = Shaker.Model.SysCmd.Reset,
  397. }, Properties);
  398. if (result == null || !result.Success)
  399. {
  400. PromptViewModel.Default.Init();
  401. PromptViewModel.Default.IconType = IconType.Error;
  402. PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
  403. PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
  404. PromptViewModel.Default.IsOpen = true;
  405. }
  406. }
  407. private async void Open()
  408. {
  409. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}打开功放"));
  410. var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl,Shaker.Model.Result>(new Shaker.Model.SysControl()
  411. {
  412. Cmd = Shaker.Model.SysCmd.OpenGain,
  413. }, Properties);
  414. if (result == null || !result.Success)
  415. {
  416. PromptViewModel.Default.Init();
  417. PromptViewModel.Default.IconType = IconType.Error;
  418. PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
  419. PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
  420. PromptViewModel.Default.IsOpen = true;
  421. }
  422. }
  423. private short gain;
  424. private bool shakerControlIsOpen = false;
  425. private bool setPlotConfigIsOpen = false;
  426. [AllowNull]
  427. private DataMangerItemViewModel currentData;
  428. private bool isConnected = false;
  429. private bool isRemoteControl = false;
  430. private bool isOnline = false;
  431. private bool gainSwich = false;
  432. public string Title => string.IsNullOrEmpty(Description) ? Name : Description;
  433. public string Name
  434. {
  435. get => Model.Name;
  436. set
  437. {
  438. UpdateProperty(ref Model.Name, value);
  439. OnPropertyChanged(nameof(Title));
  440. }
  441. }
  442. public string Description
  443. {
  444. get => Model.Description;
  445. set
  446. {
  447. if (value == Model.Description) return;
  448. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}别名修改为{value}"));
  449. UpdateProperty(ref Model.Description, value);
  450. Sql.Default.UpDate<Shaker.Model.ShakerControlModel, string, string>(p => p.Id, Model.Id, p => p.Description, Model.Description);
  451. OnPropertyChanged(nameof(Title));
  452. }
  453. }
  454. public byte SlaveID { get=>Model.SlaveID; set=>UpdateProperty(ref Model.SlaveID, value); }
  455. public string IPAddress
  456. {
  457. get => Model.IPAddress;
  458. set
  459. {
  460. if (Model.Id == value) return;
  461. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}功放IP地址修改为{value}"));
  462. UpdateProperty(ref Model.IPAddress, value);
  463. Sql.Default.UpDate<Shaker.Model.ShakerControlModel, string, string>(p => p.Id, Model.Id, p => p.IPAddress, Model.IPAddress);
  464. }
  465. }
  466. public int Port
  467. {
  468. get => Model.Port;
  469. set
  470. {
  471. if (value != Model.Port)
  472. {
  473. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"振动台{Name}功放端口号修改为{value}"));
  474. UpdateProperty(ref Model.Port, value);
  475. Sql.Default.UpDate<Shaker.Model.ShakerControlModel, string, int>(p => p.Id, Model.Id, p => p.Port, Model.Port);
  476. }
  477. }
  478. }
  479. public ICommand RequestPermissionsCommand => new DelegateCommand(RequestPermissions);
  480. private async void RequestPermissions()
  481. {
  482. if (IsRemoteControl) return;
  483. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"申请振动台{Name}功放控制权限"));
  484. var result = await BusManger.Defaut.Bus.RPC.RequestAsync<Shaker.Model.SysControl, Shaker.Model.Result>(new Shaker.Model.SysControl()
  485. {
  486. Cmd = Shaker.Model.SysCmd.ApplicationControl,
  487. }, Properties,CancellationToken.None,MainWindowViewModel.Default.SystemConfig.SystemPage.RequestPermissionsTimeout);
  488. if (result == null || !result.Success)
  489. {
  490. PromptViewModel.Default.Init();
  491. PromptViewModel.Default.IconType = IconType.Error;
  492. PromptViewModel.Default.Message = result == null ? "通信超时" : result.Message;
  493. PromptViewModel.Default.NoVisibility = Visibility.Collapsed;
  494. PromptViewModel.Default.IsOpen = true;
  495. }
  496. }
  497. public short Gain
  498. {
  499. get => gain;
  500. set
  501. {
  502. if (gain == value) return;
  503. UpdateProperty(ref gain, value);
  504. SetGain(value);
  505. }
  506. }
  507. public bool IsRemoteControl { get => isRemoteControl; set =>UpdateProperty(ref isRemoteControl, value); }
  508. public ICommand SaveCommand => new DelegateCommand(() => Save());
  509. public ICommand CancelCommand => new DelegateCommand(() => Cancel());
  510. private void Save()
  511. {
  512. GetEvent<Shaker.Model.LogModel>().Publish(this, new Shaker.Model.LogModel($"修改了振动台{Name}配置参数"));
  513. Sql.Default.Replace(p => p.Id, Model.Id, Model);
  514. }
  515. private void Cancel()
  516. {
  517. Model = Sql.Default.FindFirst<Shaker.Model.ShakerControlModel>(p => p.Id == Model.Id)!;
  518. RefreshUI();
  519. }
  520. public bool IsMax { get; set; }
  521. public bool IsSelected { get; set; }
  522. }
  523. }