ShakerControlViewModel.cs 24 KB

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