| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- using System;
- using LiveCharts;
- using Prism.Mvvm;
- using Prism.Commands;
- using System.Linq;
- using SHJX.Service.Common.ReadXML;
- using SHJX.Service.Common.Logging;
- using Microsoft.Extensions.Logging;
- using System.Collections.Generic;
- using System.Windows.Controls;
- using SHJX.Service.Control.Route.RouteController;
- using SHJX.Service.Common.UserDelegate;
- using System.Windows;
- using Prism.Events;
- using System.Threading;
- namespace SHJX.Service.ModelView
- {
- public class DropMonitorViewModel : BindableBase
- {
- private static readonly ILogger logger = LogFactory.BuildLogger(typeof(DropMonitorViewModel));
- public ChartValues<double> SeriesCollection { get; set; }
- public readonly static List<double> GraberValues = new();
- public IEventAggregator eventAggregator;
-
- public DropMonitorViewModel( ReadConfigUtil config)
- {
- eventAggregator = new EventAggregator();
- PublicMessage();
- SeriesCollection = new ChartValues<double>();
- YuZhiValue = "30";
- DengDaiTimeValue = "15";
- CheckTimeValue = "30";
- MaxTiJiValue = "28";
- DropAmount1Value = "0.0668";
- FastDidingValue = "10";
- BrightData = "100";
- IfFastDidingValue = false;
- ExcuteEnable = true;
- NongDuChoose = new List<ComboBoxItem>();
- NongDuChoose.Add(
- new ComboBoxItem()
- {
- Content = "低"
- }
- );
- NongDuChoose.Add(
- new ComboBoxItem()
- {
- Content = "高"
- }
- );
-
-
- NongDuValue = NongDuChoose.FirstOrDefault();
- eventAggregator.GetEvent<GraberValueEvent>().Subscribe((lists) =>
- {
- SeriesCollection.Clear();
- SeriesCollection.AddRange(lists);
- });
- eventAggregator.GetEvent<TitrationValueEvent>().Subscribe((value) =>
- {
- DropCountValue = value.ToString();
- });
- }
- public void PublicMessage()
- {
- Messager.Register("DropValue", DropValueExecute);
- Messager.Register("DropDoing", DropDoingExecute);
- Messager.Register("DropEnd", DropEndExecute);
- Messager.Register("DropEndWindows", DropEndWindowsExecute);
- }
- public void DropValueExecute(object obj)
- {
- if (obj is null) return;
- var dropValue = obj as Dictionary<string, double>;
- Application.Current.Dispatcher.Invoke(() =>
- {
- DropCountValue = dropValue["Count"].ToString();
- DropAmountValue = dropValue["Amount"].ToString("F3");
- DropBlueValue = dropValue["BlueValue"].ToString("F3");
- });
- }
- public void DropDoingExecute(object obj)
- {
- ExcuteEnable = false;
- GraberValues.Add(Convert.ToDouble(obj));
- eventAggregator.GetEvent<GraberValueEvent>().Publish(GraberValues);
- //if (obj is null) return;
- //var value = Convert.ToDouble(obj);
- //SeriesCollection.Add(value);
- }
- public void DropEndExecute(object obj)
- {
- ExcuteEnable = true;
- SeriesCollection.Clear();
- }
- public void DropEndWindowsExecute(object obj)
- {
- MessageBox.Show("手动滴定结束!");
- }
- #region Command
- private DelegateCommand<object> _manualDiding_Click;
- public DelegateCommand<object> ManualDiding_Click => _manualDiding_Click ?? new DelegateCommand<object>(ManualDidingAsync);
- private DelegateCommand<object> _checkCamera_Click;
- public DelegateCommand<object> CheckCamera_Click => _checkCamera_Click ?? new DelegateCommand<object>(CheckCameraAsync);
- private void ManualDidingAsync(object sender)
- {
- try
- {
- ExcuteEnable = false;
- Dictionary<string, string> myDictionary = new Dictionary<string, string>();
- myDictionary.Add("YuZhiValue", YuZhiValue);
- myDictionary.Add("DengDaiTimeValue", DengDaiTimeValue);
- myDictionary.Add("CheckTimeValue", CheckTimeValue);
- myDictionary.Add("MaxTiJiValue", MaxTiJiValue);
- myDictionary.Add("DropAmountValue", DropAmount1Value);
- myDictionary.Add("FastDidingValue", FastDidingValue);
- myDictionary.Add("IfFastDiding", IfFastDidingValue.ToString());
- myDictionary.Add("NongDuValue", NongDuValue.Content.ToString());
- Thread thread = new Thread(new ParameterizedThreadStart(threadFunction));
- thread.Start((object)myDictionary);
- }
- catch (Exception ex)
- {
- logger.LogError(ex.ToString());
- }
- }
- private void CheckCameraAsync(object sender)
- {
- try
- {
- TitrationOperate manual = new TitrationOperate();
- manual.CheckCamera(NongDuValue.Content.ToString(), BrightData.ToString());
- }
- catch (Exception ex)
- {
- logger.LogError(ex.ToString());
- }
- }
- private void threadFunction(object myDictionary)
- {
- TitrationOperate manual = new TitrationOperate();
- manual.ManualSampleDropLiquid((Dictionary<string, string>)myDictionary);
- }
- public List<ComboBoxItem> NongDuChoose { get; set; }
- private string _dropCountValue;
- public string DropCountValue
- {
- get => _dropCountValue;
- set
- {
- _dropCountValue = value;
- RaisePropertyChanged(nameof(DropCountValue));
- }
- }
- private string _dropAmountValue;
- public string DropAmountValue
- {
- get => _dropAmountValue;
- set
- {
- _dropAmountValue = value;
- RaisePropertyChanged(nameof(DropAmountValue));
- }
- }
- private string _dropBlueValue;
- public string DropBlueValue
- {
- get => _dropBlueValue;
- set
- {
- _dropBlueValue = value;
- RaisePropertyChanged(nameof(DropBlueValue));
- }
- }
- private string _yuZhiValue;
- public string YuZhiValue
- {
- get => _yuZhiValue;
- set
- {
- _yuZhiValue = value;
- RaisePropertyChanged(nameof(YuZhiValue));
- }
- }
- private string _dengDaiTimeValue;
- public string DengDaiTimeValue
- {
- get => _dengDaiTimeValue;
- set
- {
- _dengDaiTimeValue = value;
- RaisePropertyChanged(nameof(DengDaiTimeValue));
- }
- }
- private string _checkTimeValue;
- public string CheckTimeValue
- {
- get => _checkTimeValue;
- set
- {
- _checkTimeValue = value;
- RaisePropertyChanged(nameof(CheckTimeValue));
- }
- }
- private string _maxTiJiValue;
- public string MaxTiJiValue
- {
- get => _maxTiJiValue;
- set
- {
- _maxTiJiValue = value;
- RaisePropertyChanged(nameof(MaxTiJiValue));
- }
- }
- private string _dropAmount1Value;
- public string DropAmount1Value
- {
- get => _dropAmount1Value;
- set
- {
- _dropAmount1Value = value;
- RaisePropertyChanged(nameof(DropAmount1Value));
- }
- }
- private string _fastDidingValue;
- public string FastDidingValue
- {
- get => _fastDidingValue;
- set
- {
- _fastDidingValue = value;
- RaisePropertyChanged(nameof(FastDidingValue));
- }
- }
- private string _brightData;
- public string BrightData
- {
- get => _brightData;
- set
- {
- _brightData = value;
- RaisePropertyChanged(nameof(BrightData));
- }
- }
- private ComboBoxItem _nongDuValue;
- public ComboBoxItem NongDuValue
- {
- get => _nongDuValue;
- set
- {
- _nongDuValue = value;
- RaisePropertyChanged(nameof(NongDuValue));
- }
- }
- private bool _excuteEnable;
- public bool ExcuteEnable
- {
- get => _excuteEnable;
- set
- {
- _excuteEnable = value;
- RaisePropertyChanged(nameof(ExcuteEnable));
- }
- }
- private bool _ifFastDidingValue;
- public bool IfFastDidingValue
- {
- get => _ifFastDidingValue;
- set
- {
- _ifFastDidingValue = value;
- RaisePropertyChanged(nameof(IfFastDidingValue));
- }
- }
- #endregion
- }
-
- public class GraberValueEvent : PubSubEvent<List<double>> { }
- public class TitrationValueEvent : PubSubEvent<List<double>> { }
- }
|