DropMonitorViewModel.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. using System;
  2. using LiveCharts;
  3. using Prism.Mvvm;
  4. using Prism.Commands;
  5. using System.Linq;
  6. using SHJX.Service.Common.ReadXML;
  7. using SHJX.Service.Common.Logging;
  8. using Microsoft.Extensions.Logging;
  9. using System.Collections.Generic;
  10. using System.Windows.Controls;
  11. using SHJX.Service.Control.Route.RouteController;
  12. using SHJX.Service.Common.UserDelegate;
  13. using System.Windows;
  14. using Prism.Events;
  15. using System.Threading;
  16. namespace SHJX.Service.ModelView
  17. {
  18. public class DropMonitorViewModel : BindableBase
  19. {
  20. private static readonly ILogger logger = LogFactory.BuildLogger(typeof(DropMonitorViewModel));
  21. public ChartValues<double> SeriesCollection { get; set; }
  22. public readonly static List<double> GraberValues = new();
  23. public IEventAggregator eventAggregator;
  24. public DropMonitorViewModel( ReadConfigUtil config)
  25. {
  26. eventAggregator = new EventAggregator();
  27. PublicMessage();
  28. SeriesCollection = new ChartValues<double>();
  29. YuZhiValue = "30";
  30. DengDaiTimeValue = "15";
  31. CheckTimeValue = "30";
  32. MaxTiJiValue = "28";
  33. DropAmount1Value = "0.0668";
  34. FastDidingValue = "10";
  35. BrightData = "100";
  36. IfFastDidingValue = false;
  37. ExcuteEnable = true;
  38. NongDuChoose = new List<ComboBoxItem>();
  39. NongDuChoose.Add(
  40. new ComboBoxItem()
  41. {
  42. Content = "低"
  43. }
  44. );
  45. NongDuChoose.Add(
  46. new ComboBoxItem()
  47. {
  48. Content = "高"
  49. }
  50. );
  51. NongDuValue = NongDuChoose.FirstOrDefault();
  52. eventAggregator.GetEvent<GraberValueEvent>().Subscribe((lists) =>
  53. {
  54. SeriesCollection.Clear();
  55. SeriesCollection.AddRange(lists);
  56. });
  57. eventAggregator.GetEvent<TitrationValueEvent>().Subscribe((value) =>
  58. {
  59. DropCountValue = value.ToString();
  60. });
  61. }
  62. public void PublicMessage()
  63. {
  64. Messager.Register("DropValue", DropValueExecute);
  65. Messager.Register("DropDoing", DropDoingExecute);
  66. Messager.Register("DropEnd", DropEndExecute);
  67. Messager.Register("DropEndWindows", DropEndWindowsExecute);
  68. }
  69. public void DropValueExecute(object obj)
  70. {
  71. if (obj is null) return;
  72. var dropValue = obj as Dictionary<string, double>;
  73. Application.Current.Dispatcher.Invoke(() =>
  74. {
  75. DropCountValue = dropValue["Count"].ToString();
  76. DropAmountValue = dropValue["Amount"].ToString("F3");
  77. DropBlueValue = dropValue["BlueValue"].ToString("F3");
  78. });
  79. }
  80. public void DropDoingExecute(object obj)
  81. {
  82. ExcuteEnable = false;
  83. GraberValues.Add(Convert.ToDouble(obj));
  84. eventAggregator.GetEvent<GraberValueEvent>().Publish(GraberValues);
  85. //if (obj is null) return;
  86. //var value = Convert.ToDouble(obj);
  87. //SeriesCollection.Add(value);
  88. }
  89. public void DropEndExecute(object obj)
  90. {
  91. ExcuteEnable = true;
  92. SeriesCollection.Clear();
  93. }
  94. public void DropEndWindowsExecute(object obj)
  95. {
  96. MessageBox.Show("手动滴定结束!");
  97. }
  98. #region Command
  99. private DelegateCommand<object> _manualDiding_Click;
  100. public DelegateCommand<object> ManualDiding_Click => _manualDiding_Click ?? new DelegateCommand<object>(ManualDidingAsync);
  101. private DelegateCommand<object> _checkCamera_Click;
  102. public DelegateCommand<object> CheckCamera_Click => _checkCamera_Click ?? new DelegateCommand<object>(CheckCameraAsync);
  103. private void ManualDidingAsync(object sender)
  104. {
  105. try
  106. {
  107. ExcuteEnable = false;
  108. Dictionary<string, string> myDictionary = new Dictionary<string, string>();
  109. myDictionary.Add("YuZhiValue", YuZhiValue);
  110. myDictionary.Add("DengDaiTimeValue", DengDaiTimeValue);
  111. myDictionary.Add("CheckTimeValue", CheckTimeValue);
  112. myDictionary.Add("MaxTiJiValue", MaxTiJiValue);
  113. myDictionary.Add("DropAmountValue", DropAmount1Value);
  114. myDictionary.Add("FastDidingValue", FastDidingValue);
  115. myDictionary.Add("IfFastDiding", IfFastDidingValue.ToString());
  116. myDictionary.Add("NongDuValue", NongDuValue.Content.ToString());
  117. Thread thread = new Thread(new ParameterizedThreadStart(threadFunction));
  118. thread.Start((object)myDictionary);
  119. }
  120. catch (Exception ex)
  121. {
  122. logger.LogError(ex.ToString());
  123. }
  124. }
  125. private void CheckCameraAsync(object sender)
  126. {
  127. try
  128. {
  129. TitrationOperate manual = new TitrationOperate();
  130. manual.CheckCamera(NongDuValue.Content.ToString(), BrightData.ToString());
  131. }
  132. catch (Exception ex)
  133. {
  134. logger.LogError(ex.ToString());
  135. }
  136. }
  137. private void threadFunction(object myDictionary)
  138. {
  139. TitrationOperate manual = new TitrationOperate();
  140. manual.ManualSampleDropLiquid((Dictionary<string, string>)myDictionary);
  141. }
  142. public List<ComboBoxItem> NongDuChoose { get; set; }
  143. private string _dropCountValue;
  144. public string DropCountValue
  145. {
  146. get => _dropCountValue;
  147. set
  148. {
  149. _dropCountValue = value;
  150. RaisePropertyChanged(nameof(DropCountValue));
  151. }
  152. }
  153. private string _dropAmountValue;
  154. public string DropAmountValue
  155. {
  156. get => _dropAmountValue;
  157. set
  158. {
  159. _dropAmountValue = value;
  160. RaisePropertyChanged(nameof(DropAmountValue));
  161. }
  162. }
  163. private string _dropBlueValue;
  164. public string DropBlueValue
  165. {
  166. get => _dropBlueValue;
  167. set
  168. {
  169. _dropBlueValue = value;
  170. RaisePropertyChanged(nameof(DropBlueValue));
  171. }
  172. }
  173. private string _yuZhiValue;
  174. public string YuZhiValue
  175. {
  176. get => _yuZhiValue;
  177. set
  178. {
  179. _yuZhiValue = value;
  180. RaisePropertyChanged(nameof(YuZhiValue));
  181. }
  182. }
  183. private string _dengDaiTimeValue;
  184. public string DengDaiTimeValue
  185. {
  186. get => _dengDaiTimeValue;
  187. set
  188. {
  189. _dengDaiTimeValue = value;
  190. RaisePropertyChanged(nameof(DengDaiTimeValue));
  191. }
  192. }
  193. private string _checkTimeValue;
  194. public string CheckTimeValue
  195. {
  196. get => _checkTimeValue;
  197. set
  198. {
  199. _checkTimeValue = value;
  200. RaisePropertyChanged(nameof(CheckTimeValue));
  201. }
  202. }
  203. private string _maxTiJiValue;
  204. public string MaxTiJiValue
  205. {
  206. get => _maxTiJiValue;
  207. set
  208. {
  209. _maxTiJiValue = value;
  210. RaisePropertyChanged(nameof(MaxTiJiValue));
  211. }
  212. }
  213. private string _dropAmount1Value;
  214. public string DropAmount1Value
  215. {
  216. get => _dropAmount1Value;
  217. set
  218. {
  219. _dropAmount1Value = value;
  220. RaisePropertyChanged(nameof(DropAmount1Value));
  221. }
  222. }
  223. private string _fastDidingValue;
  224. public string FastDidingValue
  225. {
  226. get => _fastDidingValue;
  227. set
  228. {
  229. _fastDidingValue = value;
  230. RaisePropertyChanged(nameof(FastDidingValue));
  231. }
  232. }
  233. private string _brightData;
  234. public string BrightData
  235. {
  236. get => _brightData;
  237. set
  238. {
  239. _brightData = value;
  240. RaisePropertyChanged(nameof(BrightData));
  241. }
  242. }
  243. private ComboBoxItem _nongDuValue;
  244. public ComboBoxItem NongDuValue
  245. {
  246. get => _nongDuValue;
  247. set
  248. {
  249. _nongDuValue = value;
  250. RaisePropertyChanged(nameof(NongDuValue));
  251. }
  252. }
  253. private bool _excuteEnable;
  254. public bool ExcuteEnable
  255. {
  256. get => _excuteEnable;
  257. set
  258. {
  259. _excuteEnable = value;
  260. RaisePropertyChanged(nameof(ExcuteEnable));
  261. }
  262. }
  263. private bool _ifFastDidingValue;
  264. public bool IfFastDidingValue
  265. {
  266. get => _ifFastDidingValue;
  267. set
  268. {
  269. _ifFastDidingValue = value;
  270. RaisePropertyChanged(nameof(IfFastDidingValue));
  271. }
  272. }
  273. #endregion
  274. }
  275. public class GraberValueEvent : PubSubEvent<List<double>> { }
  276. public class TitrationValueEvent : PubSubEvent<List<double>> { }
  277. }